-
Notifications
You must be signed in to change notification settings - Fork 267
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
feat(snap): add extra checks; update snap discovery #2860
base: snap-v4-final
Are you sure you want to change the base?
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
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.
praise:
Very good job! I can see that this was a very difficult feature change.
I have left some small comments and also some questions, I would like to have a call to discuss better the changes and understand all the additions.
generateChunkRequestTasks(state); | ||
startRequestingChunks(state); | ||
|
||
if (blocksVerified(state)) { |
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.
question:
What exactly means the method blocksVerified
? Does it mean that all blocks were verified?
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.
yes, correct - that the block headers were verified in reverse order till the latest connected block
state.setRemoteRootHash(lastBlock.getStateRoot()); | ||
state.setRemoteTrieSize(responseMessage.getTrieSize()); | ||
|
||
for (int i = 0; i < blocksFromResponse.size(); i++) { | ||
state.addBlock(new ImmutablePair<>(blocksFromResponse.get(i), difficultiesFromResponse.get(i))); | ||
if (!validateAndSaveBlocks(state, sender, blocksFromResponse, difficultiesFromResponse)) { |
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.
suggestion:
Would be interesting to have a log here to identify that it left the loop with invalid blocks? Or the ones inside the method are already enough?
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.
it's being logged inside that method
requestNextBlockHeadersChunk(state, sender); | ||
} | ||
|
||
private boolean validateBlockHeaders(SnapSyncState state, Peer sender, List<BlockHeader> blockHeaders) { |
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.
issue:
the sender parameter is never used
if (blocksVerified(state)) { | ||
logger.info("CLIENT - Finished Snap blocks request sending."); | ||
|
||
generateChunkRequestTasks(state); | ||
startRequestingChunks(state); | ||
} else if (nextChunk > lastRequiredBlock) { | ||
requestBlocksChunk(sender, nextChunk); | ||
} else { | ||
logger.info("CLIENT - Finished Snap blocks request sending."); | ||
|
||
generateChunkRequestTasks(state); | ||
startRequestingChunks(state); | ||
|
||
requestNextBlockHeadersChunk(state, sender); | ||
} |
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.
suggestion:
I see that the difference between the first if and the last else it's because we are requiring headers chunk if block is not verified. Maybe it could be simplified and avoid a bit of DRY:
if (blocksVerified(state)) { | |
logger.info("CLIENT - Finished Snap blocks request sending."); | |
generateChunkRequestTasks(state); | |
startRequestingChunks(state); | |
} else if (nextChunk > lastRequiredBlock) { | |
requestBlocksChunk(sender, nextChunk); | |
} else { | |
logger.info("CLIENT - Finished Snap blocks request sending."); | |
generateChunkRequestTasks(state); | |
startRequestingChunks(state); | |
requestNextBlockHeadersChunk(state, sender); | |
} | |
if (nextChunk > lastRequiredBlock) { | |
requestBlocksChunk(sender, nextChunk); | |
} else { | |
logger.info("CLIENT - Finished Snap blocks request sending."); | |
generateChunkRequestTasks(state); | |
startRequestingChunks(state); | |
if(!blocksVerified(state)) { | |
requestNextBlockHeadersChunk(state, sender); | |
} | |
} |
@@ -289,8 +289,8 @@ public void startBlockForwardSyncing(Peer peer) { | |||
} | |||
|
|||
@Override | |||
public void startSnapSync() { | |||
logger.info("Start Snap syncing"); | |||
public void startSnapSync(Peer peer) { |
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.
question:
Does it mean that we will accept the sync only with a single peer for now right? 🤔
I don't recall if it was possible to receive from multiple peers.
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.
yes, we start with one peer - we send SnapStatusRequestMessage
to get initial params for syncing, like state root hash, etc.
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.
suggestion:
The previous suggestions to use the any(Class<T>)
also applies here.
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.
suggestion:
The previous suggestions to use the any(Class<T>)
also applies here.
@@ -99,7 +99,7 @@ public BlockValidatorBuilder addBlockUnclesValidationRule(BlockStore blockStore) | |||
Mockito.when(validationRule.isValid(Mockito.any())).thenReturn(true); | |||
|
|||
BlockHeaderParentDependantValidationRule parentValidationRule = Mockito.mock(BlockHeaderParentDependantValidationRule.class); | |||
Mockito.when(parentValidationRule.isValid(Mockito.any(), Mockito.any())).thenReturn(true); | |||
Mockito.when(parentValidationRule.isValid(Mockito.any(), (Block) Mockito.any())).thenReturn(true); |
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.
suggestion:
I would use static import here to import Mockito.
@@ -288,7 +288,7 @@ void invalidPOWUncles() { | |||
store.saveBlock(uncle1a, TEST_DIFFICULTY, false); | |||
|
|||
BlockHeaderParentDependantValidationRule parentValidationRule = mock(BlockHeaderParentDependantValidationRule.class); | |||
when(parentValidationRule.isValid(Mockito.any(), Mockito.any())).thenReturn(true); | |||
when(parentValidationRule.isValid(Mockito.any(), (Block) Mockito.any())).thenReturn(true); |
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.
suggestion:
I would use static import here to import Mockito.
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.
praise:
It looks like the test stayed way simpler. Congrats on the refactor.
3e9075c
to
58edd8e
Compare
Quality Gate failedFailed conditions |
Description
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist: