quick check for block_exists in adapters (#3068)

This commit is contained in:
Antioch Peverell 2019-10-07 09:08:55 +01:00 committed by GitHub
parent eefd87aa2e
commit 95e74c7b4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -120,6 +120,9 @@ impl p2p::ChainAdapter for NetToChainAdapter {
peer_info: &PeerInfo, peer_info: &PeerInfo,
was_requested: bool, was_requested: bool,
) -> Result<bool, chain::Error> { ) -> Result<bool, chain::Error> {
if self.chain().block_exists(b.hash())? {
return Ok(true);
}
debug!( debug!(
"Received block {} at {} from {} [in/out/kern: {}/{}/{}] going to process.", "Received block {} at {} from {} [in/out/kern: {}/{}/{}] going to process.",
b.hash(), b.hash(),
@ -137,6 +140,10 @@ impl p2p::ChainAdapter for NetToChainAdapter {
cb: core::CompactBlock, cb: core::CompactBlock,
peer_info: &PeerInfo, peer_info: &PeerInfo,
) -> Result<bool, chain::Error> { ) -> Result<bool, chain::Error> {
// 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(); let bhash = cb.hash();
debug!( debug!(
"Received compact_block {} at {} from {} [out/kern/kern_ids: {}/{}/{}] going to process.", "Received compact_block {} at {} from {} [out/kern/kern_ids: {}/{}/{}] going to process.",
@ -236,6 +243,10 @@ impl p2p::ChainAdapter for NetToChainAdapter {
bh: core::BlockHeader, bh: core::BlockHeader,
peer_info: &PeerInfo, peer_info: &PeerInfo,
) -> Result<bool, chain::Error> { ) -> Result<bool, chain::Error> {
// 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() { if !self.sync_state.is_syncing() {
for hook in &self.hooks { for hook in &self.hooks {
hook.on_header_received(&bh, &peer_info.addr); hook.on_header_received(&bh, &peer_info.addr);