From 5c3c9797985d86cfd8983e180575639cad735c11 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Thu, 5 Mar 2020 16:59:59 +0100 Subject: [PATCH] ethcore: cleanup after #11531 (#11546) * ethcore: cleanup after #11531 * fix verification benches * ethcore: remove enact_verified * ethcore: replace PreverifiedBlock with a tuple * ethcore: more descriptive Vec type alias --- ethcore/src/client/client.rs | 8 +------ ethcore/types/src/block.rs | 5 ++-- ethcore/verification/benches/verification.rs | 2 +- ethcore/verification/src/queue/kind.rs | 14 ++++++------ ethcore/verification/src/verification.rs | 24 ++++++++++++-------- 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index bc5079584..c51a13b09 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -296,7 +296,7 @@ impl Importer { trace_time!("import_verified_blocks"); let start = Instant::now(); - for mut block in blocks { + for (block, block_bytes) in blocks { let hash = block.header.hash(); let is_invalid = invalid_blocks.contains(block.header.parent_hash()); @@ -305,12 +305,6 @@ impl Importer { continue; } - // -------------------------------------------------------- - // NOTE: this will remove the RLP bytes from the - // `PreverifiedBlock` so be careful not to use the bytes - // anywhere after this, it will be an empty `Vec`. - // -------------------------------------------------------- - let block_bytes = std::mem::take(&mut block.bytes); match self.check_and_lock_block(block, client) { Ok((locked_block, pending)) => { imported_blocks.push(hash); diff --git a/ethcore/types/src/block.rs b/ethcore/types/src/block.rs index f6a8ab688..b4f92bce2 100644 --- a/ethcore/types/src/block.rs +++ b/ethcore/types/src/block.rs @@ -76,10 +76,11 @@ pub struct PreverifiedBlock { pub transactions: Vec, /// Populated block uncles pub uncles: Vec
, - /// Block bytes - pub bytes: Bytes, } +/// The RLP representation of a block. +pub type BlockRlpRepresentation = Vec; + /// Brief info about inserted block. #[derive(Clone)] pub struct BlockInfo { diff --git a/ethcore/verification/benches/verification.rs b/ethcore/verification/benches/verification.rs index 4e0d3abe8..f5fdc580f 100644 --- a/ethcore/verification/benches/verification.rs +++ b/ethcore/verification/benches/verification.rs @@ -119,7 +119,7 @@ fn block_verification(c: &mut Criterion) { // Phase 3 verification let block = Unverified::from_rlp(rlp_8481476.clone()).expect(PROOF); - let preverified = verification::verify_block_unordered(block, ðash, true).expect(PROOF); + let preverified = verification::verify_block_unordered(block, ðash, true).expect(PROOF).0; let parent = Unverified::from_rlp(rlp_8481475.clone()).expect(PROOF); let mut block_provider = TestBlockChain::new(); diff --git a/ethcore/verification/src/queue/kind.rs b/ethcore/verification/src/queue/kind.rs index 19a82a717..19a89677a 100644 --- a/ethcore/verification/src/queue/kind.rs +++ b/ethcore/verification/src/queue/kind.rs @@ -81,7 +81,7 @@ pub mod blocks { use engine::Engine; use common_types::{ - block::PreverifiedBlock, + block::{BlockRlpRepresentation, PreverifiedBlock}, errors::{EthcoreError as Error, BlockError}, verification::Unverified, }; @@ -96,7 +96,7 @@ pub mod blocks { impl Kind for Blocks { type Input = Unverified; type Unverified = Unverified; - type Verified = PreverifiedBlock; + type Verified = (PreverifiedBlock, BlockRlpRepresentation); fn create( input: Self::Input, @@ -146,21 +146,21 @@ pub mod blocks { } } - impl BlockLike for PreverifiedBlock { + impl BlockLike for (PreverifiedBlock, BlockRlpRepresentation) { fn hash(&self) -> H256 { - self.header.hash() + self.0.header.hash() } fn raw_hash(&self) -> H256 { - keccak_hash::keccak(&self.bytes) + keccak_hash::keccak(&self.1) } fn parent_hash(&self) -> H256 { - *self.header.parent_hash() + *self.0.header.parent_hash() } fn difficulty(&self) -> U256 { - *self.header.difficulty() + *self.0.header.difficulty() } } } diff --git a/ethcore/verification/src/verification.rs b/ethcore/verification/src/verification.rs index bc3844b24..9802159aa 100644 --- a/ethcore/verification/src/verification.rs +++ b/ethcore/verification/src/verification.rs @@ -38,7 +38,7 @@ use common_types::{ header::Header, errors::{EthcoreError as Error, BlockError}, engines::MAX_UNCLE_AGE, - block::PreverifiedBlock, + block::{BlockRlpRepresentation, PreverifiedBlock}, verification::Unverified, }; @@ -78,8 +78,12 @@ pub fn verify_block_basic(block: &Unverified, engine: &dyn Engine, check_seal: b /// Phase 2 verification. Perform costly checks such as transaction signatures and block nonce for ethash. /// Still operates on a individual block -/// Returns a `PreverifiedBlock` structure populated with transactions -pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal: bool) -> Result { +/// Returns a `PreverifiedBlock` structure populated with transactions along with the RLP representation of the block. +pub fn verify_block_unordered( + block: Unverified, + engine: &dyn Engine, + check_seal: bool, +) -> Result<(PreverifiedBlock, BlockRlpRepresentation), Error> { let header = block.header; if check_seal { engine.verify_block_unordered(&header)?; @@ -107,12 +111,13 @@ pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal }) .collect::, Error>>()?; - Ok(PreverifiedBlock { - header, - transactions, - uncles: block.uncles, - bytes: block.bytes, - }) + Ok((PreverifiedBlock { + header, + transactions, + uncles: block.uncles, + }, + block.bytes, + )) } /// Parameters for full verification of block family @@ -502,7 +507,6 @@ mod tests { header, transactions, uncles: block.uncles, - bytes: bytes.to_vec(), }; let full_params = FullFamilyParams {