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>; 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. /// 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(()) } 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. /// 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(()) } 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. /// 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; type Verified: Sized + Send + BlockLike + HeapSizeOf;
/// Attempt to create the `Unverified` item from the input. /// 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. /// Attempt to verify the `Unverified` item using the given engine.
fn verify(unverified: Self::Unverified, engine: &EthEngine, check_seal: bool) -> Result<Self::Verified, Error>; 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 Unverified = Unverified;
type Verified = PreverifiedBlock; type Verified = PreverifiedBlock;
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> {
match verify_block_basic(&input, engine) { match verify_block_basic(&input, engine, check_seal) {
Ok(()) => Ok(input), Ok(()) => Ok(input),
Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => { Err(Error(ErrorKind::Block(BlockError::TemporarilyInvalid(oob)), _)) => {
debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob); debug!(target: "client", "Block received too early {}: {:?}", input.hash(), oob);
@ -209,7 +209,7 @@ pub mod headers {
type Unverified = Header; type Unverified = Header;
type Verified = 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) 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) => { Ok(item) => {
self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst); self.verification.sizes.unverified.fetch_add(item.heap_size_of_children(), AtomicOrdering::SeqCst);

View File

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