-
Notifications
You must be signed in to change notification settings - Fork 246
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
Add MMR-sync to consensus chain snap sync. #3206
Conversation
Cherry-picked #3208 for easier testing |
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.
Just some questions to make sure I understand what the code is doing.
|
||
starting_position += 1; | ||
|
||
if u64::from(*position) >= target_position { |
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 took me a while to understand the logic here. I don’t think there’s an actual bug, but maybe the loop conditions could be rewritten to be clearer?
- we check
position != starting_position
and only get to this code if they’re equal, then add one tostarting_position
, then compareposition >= target_position
, which guaranteestarget_position <= starting_position
below (because that was true when they were equal, before we added one). Is there a simpler way to express this condition that makes this relationship clearer? Maybe a booleanreached_target
flag or something? - this condition is
position >= target_position
, but the one below istarget_position <= starting_position
. A consistent order would make it easier to see they’re the same condition.
Totally up to you, but it might also be clearer to split one or more of the inner loops into their own function.
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.
I'm not sure I understand your comments. There are several nested loops, and they have different conditions. I added a couple of code comments to clarify the conditions you mentioned.
There is definitely a bug here, it results in an attempt to query block number that was not yet imported during verification:
|
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.
The last commit fixes the bug. The bug was a branch from the early PoC that wasn't removed and related to the default target_block when we didn't provide the correct value. Domain sync always provided the correct target block and the incorrect code branch was never detected during the test.
|
||
starting_position += 1; | ||
|
||
if u64::from(*position) >= target_position { |
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.
I'm not sure I understand your comments. There are several nested loops, and they have different conditions. I added a couple of code comments to clarify the conditions you mentioned.
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.
Couple of non-critical issues that could be handled with TODOs for now so we can merge this, but should be fixed shortly afterwards.
Tested, it works now.
if let Some(offchain_storage) = offchain_storage { | ||
mmr_sync( | ||
fork_id.map(|v| v.into()), | ||
client.clone(), | ||
network_request, | ||
sync_service.clone(), | ||
offchain_storage, | ||
mmr_target_block, | ||
) | ||
.await?; | ||
} |
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.
This is not the right level to check this at. It should be checked at higher level outside of Snap sync or else it is possible for Snap sync to start, being interrupted in the middle and MMR sync to never actually happen.
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.
If I understood your comment correctly, "your_claim == true" even I move this check elsewhere because we don't have transactional operations in this context.
9059d07
to
f15e6d5
Compare
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.
Rebased on main
without any other changes and changed merge target to main
GitHub didn't want to trigger CI, so I just merged it directly |
This PR adds MMR-sync as part of the consensus snap sync. It will simplify future domain snap sync because the consensus chain network will contain proper local MMR data storage.
Code contributor checklist: