From b3e224b4394513bbf13a683ffe1504457a5968ae Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Thu, 27 Jul 2017 23:47:33 +0000 Subject: [PATCH] Minor fixes to orphan handling Fixed sync pathway in validation pipeline not returning the proper orphan error. Reduced chain head lock span to prevent deadlock on reentrancy. --- chain/src/chain.rs | 6 ++++-- chain/src/pipe.rs | 5 +---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 18321d96c..c860264d1 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -125,8 +125,10 @@ impl Chain { Ok(Some(ref tip)) => { // block got accepted and extended the head, updating our head let chain_head = self.head.clone(); - let mut head = chain_head.lock().unwrap(); - *head = tip.clone(); + { + let mut head = chain_head.lock().unwrap(); + *head = tip.clone(); + } self.check_orphans(); } diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 818ea9ff4..3f7382de6 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -164,10 +164,7 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), E /// Fully validate the block content. fn validate_block(b: &Block, ctx: &mut BlockContext) -> Result<(), Error> { if b.header.height > ctx.head.height + 1 { - // check orphan again, an orphan coming out of order from sync will have - // bypassed header checks - // TODO actually handle orphans and add them to a size-limited set - return Err(Error::Unfit("orphan".to_string())); + return Err(Error::Orphan); } let curve = secp::Secp256k1::with_caps(secp::ContextFlag::Commit);