Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 5c3c979

Browse files
author
Andronik Ordian
authored
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<u8> type alias
1 parent 3ccfe73 commit 5c3c979

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

ethcore/src/client/client.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl Importer {
296296
trace_time!("import_verified_blocks");
297297
let start = Instant::now();
298298

299-
for mut block in blocks {
299+
for (block, block_bytes) in blocks {
300300
let hash = block.header.hash();
301301

302302
let is_invalid = invalid_blocks.contains(block.header.parent_hash());
@@ -305,12 +305,6 @@ impl Importer {
305305
continue;
306306
}
307307

308-
// --------------------------------------------------------
309-
// NOTE: this will remove the RLP bytes from the
310-
// `PreverifiedBlock` so be careful not to use the bytes
311-
// anywhere after this, it will be an empty `Vec`.
312-
// --------------------------------------------------------
313-
let block_bytes = std::mem::take(&mut block.bytes);
314308
match self.check_and_lock_block(block, client) {
315309
Ok((locked_block, pending)) => {
316310
imported_blocks.push(hash);

ethcore/types/src/block.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ pub struct PreverifiedBlock {
7676
pub transactions: Vec<SignedTransaction>,
7777
/// Populated block uncles
7878
pub uncles: Vec<Header>,
79-
/// Block bytes
80-
pub bytes: Bytes,
8179
}
8280

81+
/// The RLP representation of a block.
82+
pub type BlockRlpRepresentation = Vec<u8>;
83+
8384
/// Brief info about inserted block.
8485
#[derive(Clone)]
8586
pub struct BlockInfo {

ethcore/verification/benches/verification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn block_verification(c: &mut Criterion) {
119119

120120
// Phase 3 verification
121121
let block = Unverified::from_rlp(rlp_8481476.clone()).expect(PROOF);
122-
let preverified = verification::verify_block_unordered(block, &ethash, true).expect(PROOF);
122+
let preverified = verification::verify_block_unordered(block, &ethash, true).expect(PROOF).0;
123123
let parent = Unverified::from_rlp(rlp_8481475.clone()).expect(PROOF);
124124

125125
let mut block_provider = TestBlockChain::new();

ethcore/verification/src/queue/kind.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub mod blocks {
8181

8282
use engine::Engine;
8383
use common_types::{
84-
block::PreverifiedBlock,
84+
block::{BlockRlpRepresentation, PreverifiedBlock},
8585
errors::{EthcoreError as Error, BlockError},
8686
verification::Unverified,
8787
};
@@ -96,7 +96,7 @@ pub mod blocks {
9696
impl Kind for Blocks {
9797
type Input = Unverified;
9898
type Unverified = Unverified;
99-
type Verified = PreverifiedBlock;
99+
type Verified = (PreverifiedBlock, BlockRlpRepresentation);
100100

101101
fn create(
102102
input: Self::Input,
@@ -146,21 +146,21 @@ pub mod blocks {
146146
}
147147
}
148148

149-
impl BlockLike for PreverifiedBlock {
149+
impl BlockLike for (PreverifiedBlock, BlockRlpRepresentation) {
150150
fn hash(&self) -> H256 {
151-
self.header.hash()
151+
self.0.header.hash()
152152
}
153153

154154
fn raw_hash(&self) -> H256 {
155-
keccak_hash::keccak(&self.bytes)
155+
keccak_hash::keccak(&self.1)
156156
}
157157

158158
fn parent_hash(&self) -> H256 {
159-
*self.header.parent_hash()
159+
*self.0.header.parent_hash()
160160
}
161161

162162
fn difficulty(&self) -> U256 {
163-
*self.header.difficulty()
163+
*self.0.header.difficulty()
164164
}
165165
}
166166
}

ethcore/verification/src/verification.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use common_types::{
3838
header::Header,
3939
errors::{EthcoreError as Error, BlockError},
4040
engines::MAX_UNCLE_AGE,
41-
block::PreverifiedBlock,
41+
block::{BlockRlpRepresentation, PreverifiedBlock},
4242
verification::Unverified,
4343
};
4444

@@ -78,8 +78,12 @@ pub fn verify_block_basic(block: &Unverified, engine: &dyn Engine, check_seal: b
7878

7979
/// Phase 2 verification. Perform costly checks such as transaction signatures and block nonce for ethash.
8080
/// Still operates on a individual block
81-
/// Returns a `PreverifiedBlock` structure populated with transactions
82-
pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal: bool) -> Result<PreverifiedBlock, Error> {
81+
/// Returns a `PreverifiedBlock` structure populated with transactions along with the RLP representation of the block.
82+
pub fn verify_block_unordered(
83+
block: Unverified,
84+
engine: &dyn Engine,
85+
check_seal: bool,
86+
) -> Result<(PreverifiedBlock, BlockRlpRepresentation), Error> {
8387
let header = block.header;
8488
if check_seal {
8589
engine.verify_block_unordered(&header)?;
@@ -107,12 +111,13 @@ pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal
107111
})
108112
.collect::<Result<Vec<_>, Error>>()?;
109113

110-
Ok(PreverifiedBlock {
111-
header,
112-
transactions,
113-
uncles: block.uncles,
114-
bytes: block.bytes,
115-
})
114+
Ok((PreverifiedBlock {
115+
header,
116+
transactions,
117+
uncles: block.uncles,
118+
},
119+
block.bytes,
120+
))
116121
}
117122

118123
/// Parameters for full verification of block family
@@ -502,7 +507,6 @@ mod tests {
502507
header,
503508
transactions,
504509
uncles: block.uncles,
505-
bytes: bytes.to_vec(),
506510
};
507511

508512
let full_params = FullFamilyParams {

0 commit comments

Comments
 (0)