Commit db1ea1dc authored by Marek Kotewicz's avatar Marek Kotewicz Committed by Andronik Ordian

simplify verification (#11249)

* simplify verifier, remove NoopVerifier

* simplify verifier by removing Verifier trait and its only implementation

* remove unused imports

* fixed verification test failing to compile
parent 9d55f0b4
Pipeline #56813 failed with stages
in 52 minutes and 20 seconds
......@@ -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};
......@@ -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>,
......@@ -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()),
......@@ -389,15 +384,15 @@ 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 {
......@@ -405,7 +400,7 @@ impl Importer {
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());
......@@ -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());
}
......
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Canonical verifier.
use call_contract::CallContract;
use client_traits::BlockInfo;
use engine::Engine;
use common_types::{
header::Header,
errors::EthcoreError as Error,
};
use super::Verifier;
use super::verification;
/// A canonical verifier -- this does full verification.
pub struct CanonVerifier;
impl<C: BlockInfo + CallContract> Verifier<C> for CanonVerifier {
fn verify_block_family(
&self,
header: &Header,
parent: &Header,
engine: &dyn Engine,
do_full: Option<verification::FullFamilyParams<C>>,
) -> Result<(), Error> {
verification::verify_block_family(header, parent, engine, do_full)
}
fn verify_block_final(&self, expected: &Header, got: &Header) -> Result<(), Error> {
verification::verify_block_final(expected, got)
}
fn verify_block_external(&self, header: &Header, engine: &dyn Engine) -> Result<(), Error> {
engine.verify_block_external(header)
}
}
......@@ -16,8 +16,6 @@
//! 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;
......@@ -25,20 +23,13 @@ use parity_util_mem as malloc_size_of;
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 {
......@@ -46,17 +37,6 @@ pub enum VerifierType {
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 {
......@@ -64,7 +44,7 @@ impl VerifierType {
pub fn verifying_seal(&self) -> bool {
match *self {
VerifierType::Canon => true,
VerifierType::Noop | VerifierType::CanonNoSeal => false,
VerifierType::CanonNoSeal => false,
}
}
}
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! No-op verifier.
use call_contract::CallContract;
use client_traits::BlockInfo;
use common_types::{
header::Header,
errors::EthcoreError as Error
};
use engine::Engine;
use super::{verification, Verifier};
/// A no-op verifier -- this will verify everything it's given immediately.
#[allow(dead_code)]
pub struct NoopVerifier;
impl<C: BlockInfo + CallContract> Verifier<C> for NoopVerifier {
fn verify_block_family(
&self,
_: &Header,
_t: &Header,
_: &dyn Engine,
_: Option<verification::FullFamilyParams<C>>
) -> Result<(), Error> {
Ok(())
}
fn verify_block_final(&self, _expected: &Header, _got: &Header) -> Result<(), Error> {
Ok(())
}
fn verify_block_external(&self, _header: &Header, _engine: &dyn Engine) -> Result<(), Error> {
Ok(())
}
}
......@@ -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};
......@@ -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))
}
......
This diff is collapsed.
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity Ethereum.
// Parity Ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity Ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! A generic verifier trait.
use call_contract::CallContract;
use client_traits::BlockInfo;
use common_types::{
header::Header,
errors::EthcoreError as Error,
};
use engine::Engine;
use super::verification;
/// Should be used to verify blocks.
pub trait Verifier<C>: Send + Sync
where C: BlockInfo + CallContract
{
/// Verify a block relative to its parent and uncles.
fn verify_block_family(
&self,
header: &Header,
parent: &Header,
engine: &dyn Engine,
do_full: Option<verification::FullFamilyParams<C>>
) -> Result<(), Error>;
/// Do a final verification check for an enacted header vs its expected counterpart.
fn verify_block_final(&self, expected: &Header, got: &Header) -> Result<(), Error>;
/// Verify a block, inspecting external state.
fn verify_block_external(&self, header: &Header, engine: &dyn Engine) -> Result<(), Error>;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment