Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, it makes it quite obvious what is going on.

let hash = block.header.hash();

let is_invalid = invalid_blocks.contains(block.header.parent_hash());
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions ethcore/types/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ pub struct PreverifiedBlock {
pub transactions: Vec<SignedTransaction>,
/// Populated block uncles
pub uncles: Vec<Header>,
/// Block bytes
pub bytes: Bytes,
}

/// The RLP representation of a block.
pub type BlockRlpRepresentation = Vec<u8>;

/// Brief info about inserted block.
#[derive(Clone)]
pub struct BlockInfo {
Expand Down
2 changes: 1 addition & 1 deletion ethcore/verification/benches/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &ethash, true).expect(PROOF);
let preverified = verification::verify_block_unordered(block, &ethash, true).expect(PROOF).0;
let parent = Unverified::from_rlp(rlp_8481475.clone()).expect(PROOF);

let mut block_provider = TestBlockChain::new();
Expand Down
14 changes: 7 additions & 7 deletions ethcore/verification/src/queue/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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()
}
}
}
Expand Down
24 changes: 14 additions & 10 deletions ethcore/verification/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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<PreverifiedBlock, Error> {
/// 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)?;
Expand Down Expand Up @@ -107,12 +111,13 @@ pub fn verify_block_unordered(block: Unverified, engine: &dyn Engine, check_seal
})
.collect::<Result<Vec<_>, 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
Expand Down Expand Up @@ -502,7 +507,6 @@ mod tests {
header,
transactions,
uncles: block.uncles,
bytes: bytes.to_vec(),
};

let full_params = FullFamilyParams {
Expand Down