Warp sync part I (#9227)

* Started warp sync

* BABE & GRANDPA recovery

* Warp sync protocol

* Sync warp proofs first

* Added basic documentation

* Apply suggestions from code review

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Style changes

* Apply suggestions from code review

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* fmt

* Apply suggestions from code review

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

* Fixed chage trie pruning wrt missing blocks

* Restore parent finalization

* fmt

* fmt

* Revert pwasm-utils bump

* Change error type & check API version

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Build fix

* Fixed target block check

* Formatting

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-08-02 10:27:18 +02:00
committed by GitHub
parent fa8c6274ac
commit f56232602f
51 changed files with 1308 additions and 448 deletions
@@ -39,7 +39,7 @@ use std::{
use sc_consensus::{BlockImportParams, ForkChoiceStrategy, Verifier};
use sp_api::{ProvideRuntimeApi, TransactionFor};
use sp_blockchain::{HeaderBackend, HeaderMetadata};
use sp_consensus::{BlockOrigin, CacheKeyId};
use sp_consensus::CacheKeyId;
use sp_consensus_babe::{
digests::{NextEpochDescriptor, PreDigest, SecondaryPlainPreDigest},
inherents::BabeInherentData,
@@ -50,7 +50,6 @@ use sp_inherents::{InherentData, InherentDataProvider, InherentIdentifier};
use sp_runtime::{
generic::{BlockId, Digest},
traits::{Block as BlockT, DigestFor, DigestItemFor, Header, Zero},
Justifications,
};
use sp_timestamp::{InherentType, TimestampInherentData, INHERENT_IDENTIFIER};
@@ -98,20 +97,14 @@ where
{
async fn verify(
&mut self,
origin: BlockOrigin,
header: B::Header,
justifications: Option<Justifications>,
body: Option<Vec<B::Extrinsic>>,
mut import_params: BlockImportParams<B, ()>,
) -> Result<(BlockImportParams<B, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
let mut import_params = BlockImportParams::new(origin, header.clone());
import_params.justifications = justifications;
import_params.body = body;
import_params.finalized = false;
import_params.fork_choice = Some(ForkChoiceStrategy::LongestChain);
let pre_digest = find_pre_digest::<B>(&header)?;
let pre_digest = find_pre_digest::<B>(&import_params.header)?;
let parent_hash = header.parent_hash();
let parent_hash = import_params.header.parent_hash();
let parent = self
.client
.header(BlockId::Hash(*parent_hash))
@@ -27,9 +27,9 @@ use sc_consensus::{
import_queue::{BasicQueue, BoxBlockImport, Verifier},
};
use sp_blockchain::HeaderBackend;
use sp_consensus::{BlockOrigin, CacheKeyId, Environment, Proposer, SelectChain};
use sp_consensus::{CacheKeyId, Environment, Proposer, SelectChain};
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId, Justifications};
use sp_runtime::{traits::Block as BlockT, ConsensusEngineId};
use std::{marker::PhantomData, sync::Arc};
mod error;
@@ -59,18 +59,11 @@ struct ManualSealVerifier;
impl<B: BlockT> Verifier<B> for ManualSealVerifier {
async fn verify(
&mut self,
origin: BlockOrigin,
header: B::Header,
justifications: Option<Justifications>,
body: Option<Vec<B::Extrinsic>>,
mut block: BlockImportParams<B, ()>,
) -> Result<(BlockImportParams<B, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
let mut import_params = BlockImportParams::new(origin, header);
import_params.justifications = justifications;
import_params.body = body;
import_params.finalized = false;
import_params.fork_choice = Some(ForkChoiceStrategy::LongestChain);
Ok((import_params, None))
block.finalized = false;
block.fork_choice = Some(ForkChoiceStrategy::LongestChain);
Ok((block, None))
}
}