consensus: remove caching functionality from block import pipeline (#13551)

* consensus: remove caching functionality from block import pipeline

* client: update docs on Verifier::verify

* node: fix block production benchmark
This commit is contained in:
André Silva
2023-03-07 11:19:19 +00:00
committed by GitHub
parent d86a32630b
commit 13b0f24abd
29 changed files with 103 additions and 214 deletions
+9 -16
View File
@@ -67,7 +67,7 @@
#![warn(missing_docs)]
use std::{
collections::{HashMap, HashSet},
collections::HashSet,
future::Future,
pin::Pin,
sync::Arc,
@@ -114,9 +114,7 @@ use sp_blockchain::{
Backend as _, BlockStatus, Error as ClientError, ForkBackend, HeaderBackend, HeaderMetadata,
Result as ClientResult,
};
use sp_consensus::{
BlockOrigin, CacheKeyId, Environment, Error as ConsensusError, Proposer, SelectChain,
};
use sp_consensus::{BlockOrigin, Environment, Error as ConsensusError, Proposer, SelectChain};
use sp_consensus_babe::inherents::BabeInherentData;
use sp_consensus_slots::Slot;
use sp_core::{crypto::ByteArray, ExecutionContext};
@@ -1131,9 +1129,6 @@ where
}
}
type BlockVerificationResult<Block> =
Result<(BlockImportParams<Block, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String>;
#[async_trait::async_trait]
impl<Block, Client, SelectChain, CIDP> Verifier<Block>
for BabeVerifier<Block, Client, SelectChain, CIDP>
@@ -1153,7 +1148,7 @@ where
async fn verify(
&mut self,
mut block: BlockImportParams<Block, ()>,
) -> BlockVerificationResult<Block> {
) -> Result<BlockImportParams<Block, ()>, String> {
trace!(
target: LOG_TARGET,
"Verifying origin: {:?} header: {:?} justification(s): {:?} body: {:?}",
@@ -1177,7 +1172,7 @@ where
// read it from the state after import. We also skip all verifications
// because there's no parent state and we trust the sync module to verify
// that the state is correct and finalized.
return Ok((block, Default::default()))
return Ok(block)
}
debug!(
@@ -1296,7 +1291,7 @@ where
);
block.post_hash = Some(hash);
Ok((block, Default::default()))
Ok(block)
},
CheckedHeader::Deferred(a, b) => {
debug!(target: LOG_TARGET, "Checking {:?} failed; {:?}, {:?}.", hash, a, b);
@@ -1368,7 +1363,6 @@ where
async fn import_state(
&mut self,
mut block: BlockImportParams<Block, sp_api::TransactionFor<Client, Block>>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, ConsensusError> {
let hash = block.post_hash();
let parent_hash = *block.header.parent_hash();
@@ -1383,7 +1377,7 @@ where
});
// First make the client import the state.
let import_result = self.inner.import_block(block, new_cache).await;
let import_result = self.inner.import_block(block).await;
let aux = match import_result {
Ok(ImportResult::Imported(aux)) => aux,
Ok(r) =>
@@ -1433,7 +1427,6 @@ where
async fn import_block(
&mut self,
mut block: BlockImportParams<Block, Self::Transaction>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
let hash = block.post_hash();
let number = *block.header.number();
@@ -1454,11 +1447,11 @@ where
// In case of initial sync intermediates should not be present...
let _ = block.remove_intermediate::<BabeIntermediate<Block>>(INTERMEDIATE_KEY);
block.fork_choice = Some(ForkChoiceStrategy::Custom(false));
return self.inner.import_block(block, new_cache).await.map_err(Into::into)
return self.inner.import_block(block).await.map_err(Into::into)
}
if block.with_state() {
return self.import_state(block, new_cache).await
return self.import_state(block).await
}
let pre_digest = find_pre_digest::<Block>(&block.header).expect(
@@ -1694,7 +1687,7 @@ where
epoch_changes.release_mutex()
};
let import_result = self.inner.import_block(block, new_cache).await;
let import_result = self.inner.import_block(block).await;
// revert to the original epoch changes in case there's an error
// importing the block
+3 -4
View File
@@ -209,9 +209,8 @@ where
async fn import_block(
&mut self,
block: BlockImportParams<TestBlock, Self::Transaction>,
new_cache: HashMap<CacheKeyId, Vec<u8>>,
) -> Result<ImportResult, Self::Error> {
Ok(self.0.import_block(block, new_cache).await.expect("importing block failed"))
Ok(self.0.import_block(block).await.expect("importing block failed"))
}
async fn check_block(
@@ -258,7 +257,7 @@ impl Verifier<TestBlock> for TestVerifier {
async fn verify(
&mut self,
mut block: BlockImportParams<TestBlock, ()>,
) -> Result<(BlockImportParams<TestBlock, ()>, Option<Vec<(CacheKeyId, Vec<u8>)>>), String> {
) -> Result<BlockImportParams<TestBlock, ()>, String> {
// apply post-sealing mutations (i.e. stripping seal, if desired).
(self.mutator)(&mut block.header, Stage::PostSeal);
self.inner.verify(block).await
@@ -743,7 +742,7 @@ async fn propose_and_import_block<Transaction: Send + 'static>(
import
.insert_intermediate(INTERMEDIATE_KEY, BabeIntermediate::<TestBlock> { epoch_descriptor });
import.fork_choice = Some(ForkChoiceStrategy::LongestChain);
let import_result = block_import.import_block(import, Default::default()).await.unwrap();
let import_result = block_import.import_block(import).await.unwrap();
match import_result {
ImportResult::Imported(_) => {},