fix(sync): address a couple suboptimalities #3099
Merged
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.
A couple substandard issues that caused nodes to get stuck during sync:
reset_data_pre_state_sync
, we garbage collect all data up to sync block, but this makes no sense. Let's say we are just joining the network and the head is at genesis and the head of the network is more than 2 million blocks ahead. At this point, we don't actually have any data other than the headers that are just synced during header sync. However, inreset_data_pre_state_sync
, we will go through all those 2 million heights, trying to garbage collect the data we just synced.check_state_needed
, we always try to find the hashes of the blocks that we need to sync first, even if we do not need them and should sync state instead. This means that if we are at genesis and the network is 2 million blocks ahead of us, we will always walk through those 2 million blocks after head sync only to realize we don't need them and should just do state sync instead.Test plan
Apply this patch on a betanet node that got stuck in syncing before and make sure that it syncs now.