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

simplify verification #11249

Merged
merged 4 commits into from
Nov 12, 2019
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
17 changes: 6 additions & 11 deletions ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ use types::{
verification::{Unverified, VerificationQueueInfo as BlockQueueInfo},
};
use types::data_format::DataFormat;
use verification::{BlockQueue, Verifier};
use verification;
use verification::{self, BlockQueue};
use verification::queue::kind::BlockLike;
use vm::{CreateContractAddress, EnvInfo, LastHashes};

Expand Down Expand Up @@ -162,9 +161,6 @@ struct Importer {
/// Lock used during block import
pub import_lock: Mutex<()>, // FIXME Maybe wrap the whole `Importer` instead?

/// Used to verify blocks
pub verifier: Box<dyn Verifier<Client>>,

/// Queue containing pending blocks
pub block_queue: BlockQueue<Client>,

Expand Down Expand Up @@ -271,7 +267,6 @@ impl Importer {

Ok(Importer {
import_lock: Mutex::new(()),
verifier: verification::new(config.verifier_type.clone()),
block_queue,
miner,
ancient_verifier: AncientVerifier::new(engine.clone()),
Expand Down Expand Up @@ -389,23 +384,23 @@ impl Importer {

let chain = client.chain.read();
// Verify Block Family
let verify_family_result = self.verifier.verify_block_family(
let verify_family_result = verification::verify_block_family(
&header,
&parent,
engine,
Some(verification::FullFamilyParams {
verification::FullFamilyParams {
block: &block,
block_provider: &**chain,
client
}),
},
);

if let Err(e) = verify_family_result {
warn!(target: "client", "Stage 3 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
return Err(e);
};

let verify_external_result = self.verifier.verify_block_external(&header, engine);
let verify_external_result = engine.verify_block_external(&header);
if let Err(e) = verify_external_result {
warn!(target: "client", "Stage 4 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
return Err(e.into());
Expand Down Expand Up @@ -446,7 +441,7 @@ impl Importer {
}

// Final Verification
if let Err(e) = self.verifier.verify_block_final(&header, &locked_block.header) {
if let Err(e) = verification::verify_block_final(&header, &locked_block.header) {
warn!(target: "client", "Stage 5 block verification failed for #{} ({})\nError: {:?}", header.number(), header.hash(), e);
return Err(e.into());
}
Expand Down
50 changes: 0 additions & 50 deletions ethcore/verification/src/canon_verifier.rs

This file was deleted.

24 changes: 2 additions & 22 deletions ethcore/verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,35 @@

//! Block verification utilities.

use call_contract::CallContract;
use client_traits::BlockInfo;
// The MallocSizeOf derive looks for this in the root
use parity_util_mem as malloc_size_of;

#[cfg(feature = "bench" )]
pub mod verification;
#[cfg(not(feature = "bench" ))]
mod verification;
mod verifier;
pub mod queue;
mod canon_verifier;
mod noop_verifier;
#[cfg(any(test, feature = "bench" ))]
pub mod test_helpers;

pub use self::verification::FullFamilyParams;
pub use self::verifier::Verifier;
pub use self::verification::{FullFamilyParams, verify_block_family, verify_block_final};
pub use self::queue::{BlockQueue, Config as QueueConfig};

use self::canon_verifier::CanonVerifier;
use self::noop_verifier::NoopVerifier;

/// Verifier type.
#[derive(Debug, PartialEq, Clone)]
pub enum VerifierType {
/// Verifies block normally.
Canon,
/// Verifies block normally, but skips seal verification.
CanonNoSeal,
/// Does not verify block at all.
/// Used in tests.
Noop,
}

/// Create a new verifier based on type.
pub fn new<C: BlockInfo + CallContract>(v: VerifierType) -> Box<dyn Verifier<C>> {
match v {
VerifierType::Canon | VerifierType::CanonNoSeal => Box::new(CanonVerifier),
VerifierType::Noop => Box::new(NoopVerifier),
}
}

impl VerifierType {
/// Check if seal verification is enabled for this verifier type.
pub fn verifying_seal(&self) -> bool {
match *self {
VerifierType::Canon => true,
VerifierType::Noop | VerifierType::CanonNoSeal => false,
VerifierType::CanonNoSeal => false,
}
}
}
50 changes: 0 additions & 50 deletions ethcore/verification/src/noop_verifier.rs

This file was deleted.

7 changes: 5 additions & 2 deletions ethcore/verification/src/queue/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub mod headers {
header::Header,
errors::EthcoreError as Error,
};
use crate::verification::verify_header_params;
use crate::verification::{verify_header_params, verify_header_time};

use ethereum_types::{H256, U256};

Expand All @@ -171,7 +171,10 @@ pub mod headers {
type Verified = Header;

fn create(input: Self::Input, engine: &dyn Engine, check_seal: bool) -> Result<Self::Unverified, (Self::Input, Error)> {
match verify_header_params(&input, engine, true, check_seal) {
let res = verify_header_params(&input, engine, check_seal)
.and_then(|_| verify_header_time(&input));

match res {
Ok(_) => Ok(input),
Err(err) => Err((input, err))
}
Expand Down
Loading