From add068f10de409e7fb970c1f1c6cc3c2e833913d Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Wed, 28 Nov 2018 17:46:15 +0000 Subject: [PATCH] ust iterate over the locator... (#2031) --- servers/src/common/adapters.rs | 36 +++++++--------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index 96e9dc2e..efed5823 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -408,40 +408,18 @@ impl NetToChainAdapter { .expect("Failed to upgrade weak ref to our chain.") } - // recursively go back through the locator vector and stop when we find - // a header that we recognize this will be a header shared in common - // between us and the peer + // Find the first locator hash that refers to a known header on our main chain. fn find_common_header(&self, locator: Vec) -> Option { - if locator.len() == 0 { - return None; - } - - let known = self.chain().get_block_header(&locator[0]); - - match known { - Ok(header) => { - // even if we know the block, it may not be on our winning chain - let known_winning = self.chain().get_header_by_height(header.height); - if let Ok(known_winning) = known_winning { - if known_winning.hash() != header.hash() { - self.find_common_header(locator[1..].to_vec()) - } else { - Some(header) + for hash in locator { + if let Ok(header) = self.chain().get_block_header(&hash) { + if let Ok(header_at_height) = self.chain().get_header_by_height(header.height) { + if header.hash() == header_at_height.hash() { + return Some(header); } - } else { - self.find_common_header(locator[1..].to_vec()) } } - Err(e) => match e.kind() { - chain::ErrorKind::StoreErr(store::Error::NotFoundErr(_), _) => { - self.find_common_header(locator[1..].to_vec()) - } - _ => { - error!("Could not build header locator: {:?}", e); - None - } - }, } + None } // pushing the new block through the chain pipeline