-
Notifications
You must be signed in to change notification settings - Fork 284
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
chore: catch up note processors could be synced more efficiently #3933
Merged
just-mitch
merged 3 commits into
master
from
3683-catch-up-note-processors-could-be-synced-more-efficiently
Jan 11, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,47 +91,76 @@ describe('Synchronizer', () => { | |
}); | ||
|
||
it('note processor successfully catches up', async () => { | ||
const block = L2Block.random(1, 4); | ||
const blocks = [L2Block.random(1, 4), L2Block.random(2, 4)]; | ||
|
||
aztecNode.getBlocks | ||
// called by synchronizer.work | ||
.mockResolvedValueOnce([L2Block.fromFields(omit(blocks[0], 'newEncryptedLogs', 'newUnencryptedLogs'))]) | ||
.mockResolvedValueOnce([L2Block.fromFields(omit(blocks[1], 'newEncryptedLogs', 'newUnencryptedLogs'))]) | ||
// called by synchronizer.workNoteProcessorCatchUp | ||
.mockResolvedValueOnce([L2Block.fromFields(omit(blocks[0], 'newEncryptedLogs', 'newUnencryptedLogs'))]) | ||
.mockResolvedValueOnce([L2Block.fromFields(omit(blocks[1], 'newEncryptedLogs', 'newUnencryptedLogs'))]); | ||
|
||
// getBlocks is called by both synchronizer.work and synchronizer.workNoteProcessorCatchUp | ||
aztecNode.getBlocks.mockResolvedValue([L2Block.fromFields(omit(block, 'newEncryptedLogs', 'newUnencryptedLogs'))]); | ||
aztecNode.getLogs | ||
.mockResolvedValueOnce([block.newEncryptedLogs!]) // called by synchronizer.work | ||
.mockResolvedValueOnce([block.newUnencryptedLogs!]) // called by synchronizer.work | ||
.mockResolvedValueOnce([block.newEncryptedLogs!]); // called by synchronizer.workNoteProcessorCatchUp | ||
// called by synchronizer.work | ||
.mockResolvedValueOnce([blocks[0].newEncryptedLogs!]) | ||
.mockResolvedValueOnce([blocks[0].newUnencryptedLogs!]) | ||
.mockResolvedValueOnce([blocks[1].newEncryptedLogs!]) | ||
.mockResolvedValueOnce([blocks[1].newUnencryptedLogs!]) | ||
// called by synchronizer.workNoteProcessorCatchUp | ||
.mockResolvedValueOnce([blocks[0].newEncryptedLogs!]) | ||
.mockResolvedValueOnce([blocks[1].newEncryptedLogs!]); | ||
|
||
// Sync the synchronizer so that note processor has something to catch up to | ||
await synchronizer.work(); | ||
aztecNode.getBlockNumber.mockResolvedValue(INITIAL_L2_BLOCK_NUM + 1); | ||
|
||
// Used in synchronizer.isAccountStateSynchronized | ||
aztecNode.getBlockNumber.mockResolvedValueOnce(1); | ||
// Sync the synchronizer so that note processor has something to catch up to | ||
// There are two blocks, and we have a limit of 1 block per work call | ||
await synchronizer.work(1); | ||
expect(await synchronizer.isGlobalStateSynchronized()).toBe(false); | ||
await synchronizer.work(1); | ||
expect(await synchronizer.isGlobalStateSynchronized()).toBe(true); | ||
|
||
// Manually adding account to database so that we can call synchronizer.isAccountStateSynchronized | ||
const keyStore = new TestKeyStore(new Grumpkin(), await AztecLmdbStore.create(EthAddress.random())); | ||
const privateKey = GrumpkinScalar.random(); | ||
await keyStore.addAccount(privateKey); | ||
const completeAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(privateKey, Fr.random()); | ||
await database.addCompleteAddress(completeAddress); | ||
const addAddress = async (startingBlockNum: number) => { | ||
const privateKey = GrumpkinScalar.random(); | ||
await keyStore.addAccount(privateKey); | ||
const completeAddress = CompleteAddress.fromPrivateKeyAndPartialAddress(privateKey, Fr.random()); | ||
await database.addCompleteAddress(completeAddress); | ||
synchronizer.addAccount(completeAddress.publicKey, keyStore, startingBlockNum); | ||
return completeAddress; | ||
}; | ||
|
||
const [completeAddressA, completeAddressB, completeAddressC] = await Promise.all([ | ||
addAddress(INITIAL_L2_BLOCK_NUM), | ||
addAddress(INITIAL_L2_BLOCK_NUM), | ||
addAddress(INITIAL_L2_BLOCK_NUM + 1), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the first block we catch up is not relevant to addressC |
||
]); | ||
|
||
await synchronizer.workNoteProcessorCatchUp(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after this, all processors need block 2. |
||
|
||
// Add the account which will add the note processor to the synchronizer | ||
synchronizer.addAccount(completeAddress.publicKey, keyStore, INITIAL_L2_BLOCK_NUM); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressA.address)).toBe(false); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressB.address)).toBe(false); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressC.address)).toBe(false); | ||
|
||
await synchronizer.workNoteProcessorCatchUp(); | ||
|
||
expect(await synchronizer.isAccountStateSynchronized(completeAddress.address)).toBe(true); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressA.address)).toBe(true); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressB.address)).toBe(true); | ||
expect(await synchronizer.isAccountStateSynchronized(completeAddressC.address)).toBe(true); | ||
}); | ||
}); | ||
|
||
class TestSynchronizer extends Synchronizer { | ||
public work() { | ||
return super.work(); | ||
public work(limit = 1) { | ||
return super.work(limit); | ||
} | ||
|
||
public initialSync(): Promise<void> { | ||
return super.initialSync(); | ||
} | ||
|
||
public workNoteProcessorCatchUp(): Promise<boolean> { | ||
return super.workNoteProcessorCatchUp(); | ||
public workNoteProcessorCatchUp(limit = 1): Promise<boolean> { | ||
return super.workNoteProcessorCatchUp(limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor unrelated cleanup so we don't need to keep running flags to avoid inserting to a flushing queue.