ethcore: don't validate difficulty when ignoring seal check (#9470)

* ethcore: don't validate difficulty when ignoring seal check

* ethcore: fix block verification test

* ethcore: document skipped verifications when check_seal is disabled
This commit is contained in:
André Silva 2018-09-06 03:37:41 +01:00 committed by Afri Schoedon
parent dca88ff85c
commit 39a12622ae
4 changed files with 16 additions and 9 deletions

View File

@ -297,9 +297,11 @@ pub trait Engine<M: Machine>: Sync + Send {
fn verify_local_seal(&self, header: &M::Header) -> Result<(), M::Error>;
/// Phase 1 quick block verification. Only does checks that are cheap. Returns either a null `Ok` or a general error detailing the problem with import.
/// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called.
fn verify_block_basic(&self, _header: &M::Header) -> Result<(), M::Error> { Ok(()) }
/// Phase 2 verification. Perform costly checks such as transaction signatures. Returns either a null `Ok` or a general error detailing the problem with import.
/// The verification module can optionally avoid checking the seal (`check_seal`), if seal verification is disabled this method won't be called.
fn verify_block_unordered(&self, _header: &M::Header) -> Result<(), M::Error> { Ok(()) }
/// Phase 3 verification. Check block information against parent. Returns either a null `Ok` or a general error detailing the problem with import.

View File

@ -58,7 +58,7 @@ pub trait Kind: 'static + Sized + Send + Sync {
type Verified: Sized + Send + BlockLike + HeapSizeOf;
/// Attempt to create the `Unverified` item from the input.
fn create(input: Self::Input, engine: &EthEngine) -> Result<Self::Unverified, Error>;
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, Error>;
/// Attempt to verify the `Unverified` item using the given engine.
fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error>;
@ -86,8 +86,8 @@ pub mod blocks {
type Unverified = Unverified;
type Verified = PreverifiedBlock;
fn create(input: Self::Input, engine: &EthEngine) -> Result<Self::Unverified, Error> {
match verify_block_basic(&input, engine) {
fn create(input: Self::Input, engine: &EthEngine, check_seal: bool) -> Result<Self::Unverified, Error> {
match verify_block_basic(&input, engine, check_seal) {
Ok(()) => Ok(input),
Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => {
debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob);
@ -209,7 +209,7 @@ pub mod headers {
type Unverified = Header;
type Verified = Header;
fn create(input: Self::Input, engine: &EthEngine) -> Result<Self::Unverified, Error> {
fn create(input: Self::Input, engine: &EthEngine, _check_seal: bool) -> Result<Self::Unverified, Error> {
verify_header_params(&input, engine, true).map(|_| input)
}

View File

@ -482,7 +482,7 @@ impl<K: Kind> VerificationQueue<K> {
}
}
match K::create(input, &*self.engine) {
match K::create(input, &*self.engine, self.verification.check_seal) {
Ok(item) => {
self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst);

View File

@ -60,15 +60,20 @@ impl HeapSizeOf for PreverifiedBlock {
}
/// Phase 1 quick block verification. Only does checks that are cheap. Operates on a single block
pub fn verify_block_basic(block: &Unverified, engine: &EthEngine) -> Result<(), Error> {
pub fn verify_block_basic(block: &Unverified, engine: &EthEngine, check_seal: bool) -> Result<(), Error> {
verify_header_params(&block.header, engine, true)?;
verify_block_integrity(block)?;
if check_seal {
engine.verify_block_basic(&block.header)?;
}
for uncle in &block.uncles {
verify_header_params(uncle, engine, false)?;
if check_seal {
engine.verify_block_basic(uncle)?;
}
}
for t in &block.transactions {
engine.verify_transaction_basic(t, &block.header)?;
@ -496,7 +501,7 @@ mod tests {
fn basic_test(bytes: &[u8], engine: &EthEngine) -> Result<(), Error> {
let unverified = Unverified::from_rlp(bytes.to_vec())?;
verify_block_basic(&unverified, engine)
verify_block_basic(&unverified, engine, true)
}
fn family_test<BC>(bytes: &[u8], engine: &EthEngine, bc: &BC) -> Result<(), Error> where BC: BlockProvider {