From ea1d14ddb095485e487b65c9555339cb198dca70 Mon Sep 17 00:00:00 2001 From: j01tz <47043188+j01tz@users.noreply.github.com> Date: Sat, 3 Aug 2019 01:07:01 -0700 Subject: [PATCH] Improve validation when processing orphan blocks (#2981) --- chain/src/pipe.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index cf4c242e..c3fb6af5 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -53,6 +53,23 @@ fn check_known(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(), E Ok(()) } +// Validate only the proof of work in a block header. +// Used to cheaply validate orphans in process_block before adding them to OrphanBlockPool. +fn validate_pow_only(header: &BlockHeader, ctx: &mut BlockContext<'_>) -> Result<(), Error> { + if !header.pow.is_primary() && !header.pow.is_secondary() { + return Err(ErrorKind::LowEdgebits.into()); + } + let edge_bits = header.pow.edge_bits(); + if !(ctx.pow_verifier)(header).is_ok() { + error!( + "pipe: error validating header with cuckoo edge_bits {}", + edge_bits + ); + return Err(ErrorKind::InvalidPow.into()); + } + Ok(()) +} + /// Runs the block processing pipeline, including validation and finding a /// place for the new block in the chain. /// Returns new head if chain head updated. @@ -79,6 +96,10 @@ pub fn process_block(b: &Block, ctx: &mut BlockContext<'_>) -> Result