diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 92c996982..f0fdacfe8 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -61,7 +61,7 @@ use client::{ IoClient, BadBlocks, }; use client::bad_blocks; -use engines::{EthEngine, EpochTransition, ForkChoice, EngineError}; +use engines::{MAX_UNCLE_AGE, EthEngine, EpochTransition, ForkChoice, EngineError}; use engines::epoch::PendingTransition; use error::{ ImportErrorKind, ExecutionError, CallError, BlockError, @@ -1918,7 +1918,7 @@ impl BlockChainClient for Client { } fn find_uncles(&self, hash: &H256) -> Option> { - self.chain.read().find_uncle_hashes(hash, self.engine.maximum_uncle_age()) + self.chain.read().find_uncle_hashes(hash, MAX_UNCLE_AGE) } fn state_data(&self, hash: &H256) -> Option { @@ -2282,7 +2282,7 @@ impl ReopenBlock for Client { let h = chain.best_block_hash(); // Add new uncles let uncles = chain - .find_uncle_hashes(&h, engine.maximum_uncle_age()) + .find_uncle_hashes(&h, MAX_UNCLE_AGE) .unwrap_or_else(Vec::new); for h in uncles { @@ -2326,7 +2326,7 @@ impl PrepareOpenBlock for Client { // Add uncles chain - .find_uncle_headers(&h, engine.maximum_uncle_age()) + .find_uncle_headers(&h, MAX_UNCLE_AGE) .unwrap_or_else(Vec::new) .into_iter() .take(engine.maximum_uncle_count(open_block.header().number())) diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 5d83bf0a3..06e6b522b 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -59,6 +59,8 @@ use block::ExecutedBlock; /// Default EIP-210 contract code. /// As defined in https://github.com/ethereum/EIPs/pull/210 pub const DEFAULT_BLOCKHASH_CONTRACT: &'static str = "73fffffffffffffffffffffffffffffffffffffffe33141561006a5760014303600035610100820755610100810715156100455760003561010061010083050761010001555b6201000081071515610064576000356101006201000083050761020001555b5061013e565b4360003512151561008457600060405260206040f361013d565b61010060003543031315156100a857610100600035075460605260206060f361013c565b6101006000350715156100c55762010000600035430313156100c8565b60005b156100ea576101006101006000350507610100015460805260206080f361013b565b620100006000350715156101095763010000006000354303131561010c565b60005b1561012f57610100620100006000350507610200015460a052602060a0f361013a565b600060c052602060c0f35b5b5b5b5b"; +/// The number of generations back that uncles can be. +pub const MAX_UNCLE_AGE: usize = 6; /// Voting errors. #[derive(Debug)] @@ -242,9 +244,6 @@ pub trait Engine: Sync + Send { /// Maximum number of uncles a block is allowed to declare. fn maximum_uncle_count(&self, _block: BlockNumber) -> usize { 0 } - /// The number of generations back that uncles can be. - fn maximum_uncle_age(&self) -> usize { 6 } - /// Optional maximum gas limit. fn maximum_gas_limit(&self) -> Option { None } diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 2ce9f9de3..8a11f0ef4 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -34,7 +34,7 @@ use unexpected::{Mismatch, OutOfBounds}; use blockchain::*; use call_contract::CallContract; use client::BlockInfo; -use engines::EthEngine; +use engines::{EthEngine, MAX_UNCLE_AGE}; use error::{BlockError, Error}; use types::{BlockNumber, header::Header}; use types::transaction::SignedTransaction; @@ -192,7 +192,7 @@ fn verify_uncles(block: &PreverifiedBlock, bc: &BlockProvider, engine: &EthEngin excluded.insert(header.hash()); let mut hash = header.parent_hash().clone(); excluded.insert(hash.clone()); - for _ in 0..engine.maximum_uncle_age() { + for _ in 0..MAX_UNCLE_AGE { match bc.block_details(&hash) { Some(details) => { excluded.insert(details.parent); @@ -225,7 +225,7 @@ fn verify_uncles(block: &PreverifiedBlock, bc: &BlockProvider, engine: &EthEngin // (8 Invalid) let depth = if header.number() > uncle.number() { header.number() - uncle.number() } else { 0 }; - if depth > engine.maximum_uncle_age() as u64 { + if depth > MAX_UNCLE_AGE as u64 { return Err(From::from(BlockError::UncleTooOld(OutOfBounds { min: Some(header.number() - depth), max: Some(header.number() - 1), found: uncle.number() }))); } else if depth < 1 {