mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
quick check for block_exists in adapters (#3068)
This commit is contained in:
parent
eefd87aa2e
commit
95e74c7b4b
1 changed files with 11 additions and 0 deletions
|
@ -120,6 +120,9 @@ impl p2p::ChainAdapter for NetToChainAdapter {
|
|||
peer_info: &PeerInfo,
|
||||
was_requested: bool,
|
||||
) -> Result<bool, chain::Error> {
|
||||
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<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();
|
||||
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<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() {
|
||||
for hook in &self.hooks {
|
||||
hook.on_header_received(&bh, &peer_info.addr);
|
||||
|
|
Loading…
Reference in a new issue