Skip to content

Commit

Permalink
Skip block import logic if duplicated blocks received that might happen
Browse files Browse the repository at this point in the history
during reconnection to SHiP.
  • Loading branch information
yarkinwho committed Jul 28, 2023
1 parent a1b1d03 commit af79548
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/block_conversion_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ class block_conversion_plugin_impl : std::enable_shared_from_this<block_conversi

SILK_WARN << "Can't link new block " << *new_block;

// Double check if it's duplicated ones.
// We do not need to import block again during reconnection if it's in this cache.
auto dup_block = std::find_if(native_blocks.begin(), native_blocks.end(), [&new_block](const auto& nb){ return nb.id == new_block->id; });
if( dup_block != native_blocks.end() ) {
SILK_WARN << "Receiving duplicated blocks " << new_block->id << " It's normal if it's caused by reconnection to SHiP.";
return;
}

// Find fork block
auto fork_block = std::find_if(native_blocks.begin(), native_blocks.end(), [&new_block](const auto& nb){ return nb.id == new_block->prev; });
if( fork_block == native_blocks.end() ) {
Expand Down

0 comments on commit af79548

Please sign in to comment.