Skip to content

Commit

Permalink
fix: race condition (#1427)
Browse files Browse the repository at this point in the history
Fixes ugly race condition spotted by brilliant @spalladino
  • Loading branch information
benesjan authored Aug 4, 2023
1 parent d142181 commit cd78ec9
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions yarn-project/aztec-rpc/src/synchroniser/synchroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ export class Synchroniser {

protected async workNoteProcessorCatchUp(limit = 1, retryInterval = 1000): Promise<void> {
const noteProcessor = this.noteProcessorsToCatchUp[0];
if (noteProcessor.status.syncedToBlock === this.synchedToBlock) {
// Note processor already synched, nothing to do
this.noteProcessorsToCatchUp.shift();
this.noteProcessors.push(noteProcessor);
return;
}

const from = noteProcessor.status.syncedToBlock + 1;
// Ensuring that the note processor does not sync further than the main sync.
limit = Math.min(limit, this.synchedToBlock - from + 1);
Expand Down Expand Up @@ -230,14 +237,7 @@ export class Synchroniser {
return;
}

const noteProcessor = new NoteProcessor(publicKey, keyStore, this.db, this.node);
if (this.synchedToBlock === 0) {
// The main sync thread was never started before and for this reason the synchroniser does not have to catch up
this.noteProcessors.push(noteProcessor);
} else {
// The main sync thread was started before and for this reason the synchroniser has to catch up
this.noteProcessorsToCatchUp.push(noteProcessor);
}
this.noteProcessorsToCatchUp.push(new NoteProcessor(publicKey, keyStore, this.db, this.node));
}

/**
Expand Down

0 comments on commit cd78ec9

Please sign in to comment.