Skip to content

Commit 584af7f

Browse files
committed
chore: resolved failing NodeManager tests
chore: resolved failing Discovery tests chore: resolved failing Nodes tests
1 parent 54a74b7 commit 584af7f

File tree

11 files changed

+143
-209
lines changed

11 files changed

+143
-209
lines changed

src/discovery/Discovery.ts

Lines changed: 14 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,11 @@ class Discovery {
153153
parent: GestaltIdEncoded | null,
154154
) => {
155155
try {
156-
this.logger.error('out here 1')
157156
await this.processVertex(
158157
vertex,
159158
lastProcessedCutoffTime ?? undefined,
160159
ctx,
161160
);
162-
this.logger.error('out here 2')
163161
this.dispatchEvent(
164162
new discoveryEvents.EventDiscoveryVertexProcessed({
165163
detail: {
@@ -171,23 +169,18 @@ class Discovery {
171169
} catch (e) {
172170
// We need to reschedule if the task was cancelled due to discovery domain stopping
173171
if (e === discoveryStoppingTaskReason) {
174-
this.logger.error('out here 3')
175172
// We need to recreate the task for the vertex
176173
const vertexId = gestaltsUtils.decodeGestaltId(vertex);
177174
if (vertexId == null) {
178175
never(`failed to decode vertex GestaltId "${vertex}"`);
179176
}
180-
this.logger.error('out here 4')
181177
await this.scheduleDiscoveryForVertex(
182178
vertexId,
183179
undefined,
184180
undefined,
185181
gestaltsUtils.decodeGestaltId(parent ?? undefined),
186182
true,
187-
undefined,
188-
ctx,
189183
);
190-
this.logger.error('out here 5')
191184
return;
192185
}
193186
// Aborting a duplicate task is not an error
@@ -213,7 +206,9 @@ class Discovery {
213206
/**
214207
* This handler is run periodically to check if nodes are ready to be rediscovered
215208
*/
216-
protected checkRediscoveryHandler: TaskHandler = async (ctx: ContextTimed) => {
209+
protected checkRediscoveryHandler: TaskHandler = async (
210+
ctx: ContextTimed,
211+
) => {
217212
await this.checkRediscovery(
218213
Date.now() - this.rediscoverVertexThresholdTime,
219214
undefined,
@@ -337,55 +332,32 @@ class Discovery {
337332
/**
338333
* Queues a node for discovery. Internally calls `pushKeyToDiscoveryQueue`.
339334
*/
340-
public async queueDiscoveryByNode(
341-
nodeId: NodeId,
342-
lastProcessedCutoffTime?: number,
343-
ctx?: Partial<ContextTimedInput>,
344-
): Promise<void>;
345335
@ready(new discoveryErrors.ErrorDiscoveryNotRunning())
346-
@timedCancellable(true)
347336
public async queueDiscoveryByNode(
348337
nodeId: NodeId,
349-
lastProcessedCutoffTime: number | undefined,
350-
@context ctx: ContextTimed,
338+
lastProcessedCutoffTime?: number,
351339
): Promise<void> {
352340
await this.scheduleDiscoveryForVertex(
353341
['node', nodeId],
354342
undefined,
355343
lastProcessedCutoffTime,
356-
undefined,
357-
undefined,
358-
undefined,
359-
ctx,
360344
);
361345
}
362346

363347
/**
364348
* Queues an identity for discovery. Internally calls
365349
* `pushKeyToDiscoveryQueue`.
366350
*/
367-
public async queueDiscoveryByIdentity(
368-
providerId: ProviderId,
369-
identityId: IdentityId,
370-
lastProcessedCutoffTime?: number,
371-
ctx?: Partial<ContextTimedInput>
372-
): Promise<void>;
373351
@ready(new discoveryErrors.ErrorDiscoveryNotRunning())
374-
@timedCancellable(true)
375352
public async queueDiscoveryByIdentity(
376353
providerId: ProviderId,
377354
identityId: IdentityId,
378-
lastProcessedCutoffTime: number | undefined,
379-
@context ctx: ContextTimed,
355+
lastProcessedCutoffTime?: number,
380356
): Promise<void> {
381357
await this.scheduleDiscoveryForVertex(
382358
['identity', [providerId, identityId]],
383359
undefined,
384360
lastProcessedCutoffTime,
385-
undefined,
386-
undefined,
387-
undefined,
388-
ctx,
389361
);
390362
}
391363

@@ -439,17 +411,9 @@ class Discovery {
439411
const [type, id] = vertexId;
440412
switch (type) {
441413
case 'node':
442-
this.logger.error('processnode before')
443-
// return await this.processNode(id, lastProcessedCutoffTime, ctx);
444-
const val1 = await this.processNode(id, lastProcessedCutoffTime, ctx);
445-
this.logger.error('processnode after')
446-
return val1
414+
return await this.processNode(id, lastProcessedCutoffTime, ctx);
447415
case 'identity':
448-
this.logger.error('processidentity before')
449-
// return await this.processIdentity(id, lastProcessedCutoffTime, ctx);
450-
const val2 = await this.processIdentity(id, lastProcessedCutoffTime, ctx);
451-
this.logger.error('processidentity after')
452-
return val2
416+
return await this.processIdentity(id, lastProcessedCutoffTime, ctx);
453417
default:
454418
never(`type must be either "node" or "identity" got "${type}"`);
455419
}
@@ -466,34 +430,26 @@ class Discovery {
466430
if (nodeId.equals(this.keyRing.getNodeId())) {
467431
// Skip our own nodeId, we actively add this information when it changes,
468432
// so there is no need to scan it.
469-
this.logger.error('before processed tiem')
470433
await this.gestaltGraph.setVertexProcessedTime(
471434
gestaltNodeId,
472435
processedTime,
473436
);
474-
this.logger.error('after processed tiem')
475437
return;
476438
}
477-
this.logger.error('before claim')
478439
const newestClaimId = await this.gestaltGraph.getClaimIdNewest(nodeId);
479-
this.logger.error('after claim')
480440
// The sigChain data of the vertex (containing all cryptolinks)
481441
let vertexChainData: Record<ClaimIdEncoded, SignedClaim> = {};
482442
try {
483-
this.logger.error('before chain')
484443
vertexChainData = await this.nodeManager.requestChainData(
485444
nodeId,
486445
newestClaimId,
487446
ctx,
488447
);
489-
this.logger.error('after chain')
490448
} catch (e) {
491-
this.logger.error('before chain time error')
492449
await this.gestaltGraph.setVertexProcessedTime(
493450
gestaltNodeId,
494451
processedTime,
495452
);
496-
this.logger.error('after chain time error')
497453
// Not strictly an error in this case, we can fail to connect
498454
this.logger.info(
499455
`Failed to discover ${nodesUtils.encodeNodeId(
@@ -504,52 +460,42 @@ class Discovery {
504460
}
505461
// Iterate over each of the claims in the chain (already verified).
506462
for (const signedClaim of Object.values(vertexChainData)) {
507-
ctx.signal.throwIfAborted();
508463
switch (signedClaim.payload.typ) {
509464
case 'ClaimLinkNode':
510-
this.logger.error('claimlinknode before')
511465
await this.processClaimLinkNode(
512466
signedClaim as SignedClaim<ClaimLinkNode>,
513467
nodeId,
514468
lastProcessedCutoffTime,
515-
ctx,
516469
);
517-
this.logger.error('claimlinknode after')
518470
break;
519471
case 'ClaimLinkIdentity':
520-
this.logger.error('claimlinkidentity before')
521472
await this.processClaimLinkIdentity(
522473
signedClaim as SignedClaim<ClaimLinkIdentity>,
523474
nodeId,
524475
lastProcessedCutoffTime,
525476
ctx,
526477
);
527-
this.logger.error('claimlinkidentity after')
528478
break;
529479
default:
530480
never(
531481
`signedClaim.payload.typ must be "ClaimLinkNode" or "ClaimLinkIdentity" got "${signedClaim.payload.typ}"`,
532482
);
533483
}
534484
}
535-
this.logger.error('setvertex time before')
536485
await this.gestaltGraph.setVertexProcessedTime(
537486
gestaltNodeId,
538487
processedTime,
539488
);
540-
this.logger.error('setvertex time after')
541489
}
542490

543491
protected async processClaimLinkNode(
544492
signedClaim: SignedClaim<ClaimLinkNode>,
545493
nodeId: NodeId,
546494
lastProcessedCutoffTime = Date.now() - this.rediscoverSkipTime,
547-
ctx: ContextTimed,
548495
): Promise<void> {
549496
// Get the chain data of the linked node
550497
// Could be node1 or node2 in the claim so get the one that's
551498
// not equal to nodeId from above
552-
this.logger.error('processClaimLinkNode 1')
553499
const node1Id = nodesUtils.decodeNodeId(signedClaim.payload.iss);
554500
if (node1Id == null) {
555501
never(`failed to decode issuer NodeId "${signedClaim.payload.iss}"`);
@@ -558,7 +504,6 @@ class Discovery {
558504
if (node2Id == null) {
559505
never(`failed to decode subject NodeId "${signedClaim.payload.sub}"`);
560506
}
561-
this.logger.error('processClaimLinkNode 2')
562507
// Verify the claim
563508
const node1PublicKey = keysUtils.publicKeyFromNodeId(node1Id);
564509
const node2PublicKey = keysUtils.publicKeyFromNodeId(node2Id);
@@ -572,12 +517,10 @@ class Discovery {
572517
);
573518
return;
574519
}
575-
this.logger.error('processClaimLinkNode 3')
576520
const linkedNodeId = node1Id.equals(nodeId) ? node2Id : node1Id;
577521
const linkedVertexNodeInfo: GestaltNodeInfo = {
578522
nodeId: linkedNodeId,
579523
};
580-
this.logger.error('processClaimLinkNode 4')
581524
await this.gestaltGraph.linkNodeAndNode(
582525
{
583526
nodeId,
@@ -588,7 +531,6 @@ class Discovery {
588531
meta: {},
589532
},
590533
);
591-
this.logger.error('processClaimLinkNode 5')
592534
const claimId = decodeClaimId(signedClaim.payload.jti);
593535
if (claimId == null) {
594536
never(`failed to decode claimId "${signedClaim.payload.jti}"`);
@@ -602,15 +544,11 @@ class Discovery {
602544
lastProcessedCutoffTime,
603545
))
604546
) {
605-
this.logger.error('processClaimLinkNode 7')
606547
await this.scheduleDiscoveryForVertex(
607548
linkedGestaltId,
608549
undefined,
609550
lastProcessedCutoffTime,
610551
['node', nodeId],
611-
undefined,
612-
undefined,
613-
ctx,
614552
);
615553
}
616554
}
@@ -714,9 +652,6 @@ class Discovery {
714652
undefined,
715653
lastProcessedCutoffTime,
716654
['node', nodeId],
717-
undefined,
718-
undefined,
719-
ctx,
720655
);
721656
}
722657
}
@@ -793,9 +728,6 @@ class Discovery {
793728
undefined,
794729
lastProcessedCutoffTime,
795730
['identity', providerIdentityId],
796-
undefined,
797-
undefined,
798-
ctx,
799731
);
800732
}
801733
}
@@ -855,13 +787,12 @@ class Discovery {
855787
*/
856788
protected async scheduleDiscoveryForVertex(
857789
vertex: GestaltId,
858-
delay: number | undefined,
859-
lastProcessedCutoffTime: number | undefined,
860-
parent: GestaltId | undefined,
790+
delay?: number,
791+
lastProcessedCutoffTime?: number,
792+
parent?: GestaltId,
861793
ignoreActive: boolean = false,
862-
tran: DBTransaction | undefined,
863-
ctx: ContextTimed,
864-
) {
794+
tran?: DBTransaction,
795+
): Promise<void> {
865796
if (tran == null) {
866797
return this.db.withTransactionF((tran) =>
867798
this.scheduleDiscoveryForVertex(
@@ -871,7 +802,6 @@ class Discovery {
871802
parent,
872803
ignoreActive,
873804
tran,
874-
ctx,
875805
),
876806
);
877807
}
@@ -884,25 +814,20 @@ class Discovery {
884814
gestaltIdEncoded,
885815
].join(''),
886816
);
887-
this.logger.error('here1')
888817
// Check if task exists
889818
let taskExisting: Task | null = null;
890819
for await (const task of this.taskManager.getTasks(
891820
'asc',
892821
true,
893822
[this.constructor.name, this.discoverVertexHandlerId, gestaltIdEncoded],
894823
tran,
895-
ctx,
896824
)) {
897-
ctx.signal.throwIfAborted();
898-
this.logger.error('here2')
899825
// Ignore active tasks
900826
if (ignoreActive && task.status === 'active') continue;
901827
if (taskExisting == null) {
902828
taskExisting = task;
903829
continue;
904830
}
905-
this.logger.error('here3')
906831
// Any extra tasks should be cancelled, this shouldn't normally happen
907832
task.cancel(abortSingletonTaskReason);
908833
this.dispatchEvent(
@@ -914,13 +839,11 @@ class Discovery {
914839
}),
915840
);
916841
}
917-
this.logger.error('here4')
918842
// Only create if it doesn't exist
919843
if (taskExisting != null) return;
920844
this.logger.info(
921845
`Scheduling new discovery for vertex with gestaltId ${gestaltIdEncoded}`,
922846
);
923-
this.logger.error('here5')
924847
await this.taskManager.scheduleTask(
925848
{
926849
handlerId: this.discoverVertexHandlerId,
@@ -936,7 +859,6 @@ class Discovery {
936859
},
937860
tran,
938861
);
939-
this.logger.error('here6')
940862
this.dispatchEvent(
941863
new discoveryEvents.EventDiscoveryVertexQueued({
942864
detail: {
@@ -1087,12 +1009,10 @@ class Discovery {
10871009
}
10881010
// Refresh timer in preparation for request
10891011
ctx.timer.refresh();
1090-
this.logger.error('verifyIdentityClaim before getClaim')
10911012
const identitySignedClaim = await provider.getClaim(
10921013
authIdentityId,
10931014
claimId,
10941015
);
1095-
this.logger.error('verifyIdentityClaim after getClaim')
10961016
if (identitySignedClaim == null) {
10971017
continue;
10981018
}
@@ -1119,10 +1039,11 @@ class Discovery {
11191039
tran?: DBTransaction,
11201040
ctx?: Partial<ContextTimedInput>,
11211041
): Promise<void>;
1042+
@timedCancellable(true)
11221043
public async checkRediscovery(
11231044
lastProcessedCutoffTime: number,
11241045
tran: DBTransaction | undefined,
1125-
ctx: ContextTimed,
1046+
@context ctx: ContextTimed,
11261047
): Promise<void> {
11271048
if (tran == null) {
11281049
return this.db.withTransactionF((tran) =>

0 commit comments

Comments
 (0)