Skip to content

Commit

Permalink
fix new_block_received got duplicate block
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Aug 31, 2023
1 parent 3aeda1d commit 4fbb0e3
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,26 +1307,32 @@ impl SyncShared {

// Return true when the block is that we have requested and received first time.
pub fn new_block_received(&self, block: &core::BlockView) -> bool {
if self
if !self
.state()
.write_inflight_blocks()
.remove_by_block((block.number(), block.hash()).into())
{
{
let status = self.shared().get_block_status(&block.hash());
debug!(
"new_block_received {}-{}, status: {:?}",
block.number(),
block.hash(),
status
);
}
self.shared()
.insert_block_status(block.hash(), BlockStatus::BLOCK_RECEIVED);
true
} else {
false
return false;
}

let status = self.shared().get_block_status(&block.hash());
debug!(
"new_block_received {}-{}, status: {:?}",
block.number(),
block.hash(),
status
);
if BlockStatus::HEADER_VALID.eq(&status) {
return false;
}

if let dashmap::mapref::entry::Entry::Vacant(status) =
self.shared().block_status_map().entry(block.hash())
{
status.insert(BlockStatus::BLOCK_RECEIVED);
return true;
}
false
}
}

Expand Down

0 comments on commit 4fbb0e3

Please sign in to comment.