Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race condition #1427

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 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,11 @@ export class Synchroniser {

protected async workNoteProcessorCatchUp(limit = 1, retryInterval = 1000): Promise<void> {
const noteProcessor = this.noteProcessorsToCatchUp[0];
if (this.synchedToBlock === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to make this more general i.e.

      if (noteProcessor.status.syncedToBlock === this.synchedToBlock) {
        // Note processor already synched, nothing to do
        this.noteProcessorsToCatchUp.shift();
        this.noteProcessors.push(noteProcessor);
        return;
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in cd3b19d. Thanks

// `work(...)` has not been called yet so the note processor has nothing to catch up to.
this.noteProcessors.push(this.noteProcessorsToCatchUp.shift()!);
}

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 +235,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