From 95e74c7b4bc545d083e949d05962b0517ac5b885 Mon Sep 17 00:00:00 2001 From: Antioch Peverell Date: Mon, 7 Oct 2019 09:08:55 +0100 Subject: [PATCH] quick check for block_exists in adapters (#3068) --- servers/src/common/adapters.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index d2735c606..1f51c4f05 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -120,6 +120,9 @@ impl p2p::ChainAdapter for NetToChainAdapter { peer_info: &PeerInfo, was_requested: bool, ) -> Result { + if self.chain().block_exists(b.hash())? { + return Ok(true); + } debug!( "Received block {} at {} from {} [in/out/kern: {}/{}/{}] going to process.", b.hash(), @@ -137,6 +140,10 @@ impl p2p::ChainAdapter for NetToChainAdapter { cb: core::CompactBlock, peer_info: &PeerInfo, ) -> Result { + // No need to process this compact block if we have previously accepted the _full block_. + if self.chain().block_exists(cb.hash())? { + return Ok(true); + } let bhash = cb.hash(); debug!( "Received compact_block {} at {} from {} [out/kern/kern_ids: {}/{}/{}] going to process.", @@ -236,6 +243,10 @@ impl p2p::ChainAdapter for NetToChainAdapter { bh: core::BlockHeader, peer_info: &PeerInfo, ) -> Result { + // No need to process this header if we have previously accepted the _full block_. + if self.chain().block_exists(bh.hash())? { + return Ok(true); + } if !self.sync_state.is_syncing() { for hook in &self.hooks { hook.on_header_received(&bh, &peer_info.addr);