mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 01:01:04 +00:00
Header-only sync for old forks (#3942)
* Header-only sync for old forks * Simplified blocks-count * Update core/consensus/common/src/block_import.rs Co-Authored-By: Marcio Diaz <marcio.diaz@gmail.com>
This commit is contained in:
committed by
Gavin Wood
parent
279391f9c1
commit
172359adad
@@ -35,11 +35,15 @@ pub enum ImportResult {
|
||||
KnownBad,
|
||||
/// Block parent is not in the chain.
|
||||
UnknownParent,
|
||||
/// Parent state is missing.
|
||||
MissingState,
|
||||
}
|
||||
|
||||
/// Auxiliary data associated with an imported block result.
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct ImportedAux {
|
||||
/// Only the header has been imported. Block body verification was skipped.
|
||||
pub header_only: bool,
|
||||
/// Clear all pending justification requests.
|
||||
pub clear_justification_requests: bool,
|
||||
/// Request a justification for the given block.
|
||||
@@ -98,6 +102,8 @@ pub struct BlockCheckParams<Block: BlockT> {
|
||||
pub number: NumberFor<Block>,
|
||||
/// Parent hash of the block that we verify.
|
||||
pub parent_hash: Block::Hash,
|
||||
/// Don't check state availability
|
||||
pub header_only: bool,
|
||||
}
|
||||
|
||||
/// Data required to import a Block.
|
||||
|
||||
@@ -203,6 +203,10 @@ pub fn import_single_block<B: BlockT, V: Verifier<B>>(
|
||||
Ok(BlockImportResult::ImportedKnown(number))
|
||||
},
|
||||
Ok(ImportResult::Imported(aux)) => Ok(BlockImportResult::ImportedUnknown(number, aux, peer.clone())),
|
||||
Ok(ImportResult::MissingState) => {
|
||||
debug!(target: "sync", "Parent state is missing for {}: {:?}, parent: {:?}", number, hash, parent_hash);
|
||||
Err(BlockImportError::UnknownParent)
|
||||
},
|
||||
Ok(ImportResult::UnknownParent) => {
|
||||
debug!(target: "sync", "Block with unknown parent {}: {:?}, parent: {:?}", number, hash, parent_hash);
|
||||
Err(BlockImportError::UnknownParent)
|
||||
@@ -217,7 +221,12 @@ pub fn import_single_block<B: BlockT, V: Verifier<B>>(
|
||||
}
|
||||
}
|
||||
};
|
||||
match import_error(import_handle.check_block(BlockCheckParams { hash, number, parent_hash }))? {
|
||||
match import_error(import_handle.check_block(BlockCheckParams {
|
||||
hash,
|
||||
number,
|
||||
parent_hash,
|
||||
header_only: block.body.is_none(),
|
||||
}))? {
|
||||
BlockImportResult::ImportedUnknown { .. } => (),
|
||||
r => return Ok(r), // Any other successful result means that the block is already imported.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user