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

Make Warp/Light sync and custom sync protocols work by design rather than by accident #5366

Open
2 tasks done
nazar-pc opened this issue Aug 14, 2024 · 0 comments
Open
2 tasks done
Labels
I5-enhancement An additional feature request.

Comments

@nazar-pc
Copy link
Contributor

nazar-pc commented Aug 14, 2024

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

Unless using SyncMode::LightState or SyncMode::Warp when attempting to insert a block significantly higher than the tip it will fail here:

} else if self.last_canonicalized.is_some() {
if number < front_block_number || number > front_block_number + self.levels.len() as u64
{
trace!(
target: LOG_TARGET,
"Failed to insert block {}, current is {} .. {})",
number,
front_block_number,
front_block_number + self.levels.len() as u64,
);
return Err(StateDbError::InvalidBlockNumber)
}

The reason it works in those cases is because of this awkwardness:

/// Returns true if the genesis state writing will be skipped while initializing the genesis
/// block.
pub fn no_genesis(&self) -> bool {
matches!(self.network.sync_mode, SyncMode::LightState { .. } | SyncMode::Warp { .. })
}

Which essentially says we will generate, but not store genesis state on disk, which in turns allows to bypass previous snippet because suddenly when the first block is inserted self.last_canonicalized.is_some() == false.

This whole thing if basically working by accident as far as I'm concerned. There is no fundamental reason why it should be this way and in fact I'd like to have a sync mechanism that can make those jumps at a later time as well, not just after genesis.

Imagine chain has 10M blocks and current database has 1M blocks only, why shouldn't it be possible to Warp sync close to 10M in this case without wiping the whole database first?

This is one of the issues leading to #4407

cc @shamil-gadelshin

Request

I'm not sure what I'm requesting exactly, but I'm looking for some refactoring that would decouple these things and ideally make it possible to insert blocks much higher than current tip if there is a need for that in the protocol.

Solution

Could be as simple as another boolean to bypass mentioned check, but I'm not sure about expected invariants, so things might be more complex than that. Open for suggestions.

Are you willing to help with this request?

Yes!

@nazar-pc nazar-pc added the I5-enhancement An additional feature request. label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I5-enhancement An additional feature request.
Projects
None yet
Development

No branches or pull requests

1 participant