Skip to content

Commit

Permalink
fix synchronizer (#1635)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <turuslan.devbox@gmail.com>
  • Loading branch information
turuslan authored May 30, 2023
1 parent 5ddd567 commit ff56b74
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions core/network/impl/synchronizer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ namespace kagome::network {
bool SynchronizerImpl::subscribeToBlock(
const primitives::BlockInfo &block_info, SyncResultHandler &&handler) {
// Check if block is already in tree
if (block_tree_->hasBlockHeader(block_info.hash)) {
auto has = block_tree_->hasBlockHeader(block_info.hash);
if (has and has.value()) {
scheduler_->schedule(
[handler = std::move(handler), block_info] { handler(block_info); });
return false;
}

auto last_finalized_block = block_tree_->getLastFinalized();
// Check if block from discarded side-chain
if (last_finalized_block.number <= block_info.number) {
if (last_finalized_block.number >= block_info.number) {
scheduler_->schedule(
[handler = std::move(handler)] { handler(Error::DISCARDED_BLOCK); });
return false;
Expand Down Expand Up @@ -1205,9 +1206,8 @@ namespace kagome::network {
}
}

auto node = known_blocks_.extract(hash);
if (node) {
auto &block_data = node.mapped().data;
if (auto it = known_blocks_.find(hash); it != known_blocks_.end()) {
auto &block_data = it->second.data;
BOOST_ASSERT(block_data.header.has_value());
const BlockInfo block_info(block_data.header->number, block_data.hash);

Expand Down Expand Up @@ -1302,7 +1302,6 @@ namespace kagome::network {
if (not block_addition_result.has_value()) {
if (block_addition_result
!= outcome::failure(blockchain::BlockTreeError::BLOCK_EXISTS)) {
notifySubscribers(block_info, block_addition_result.as_failure());
auto n = discardBlock(block_data.hash);
SL_WARN(log_,
"Block {} {} been discarded: {}",
Expand Down

0 comments on commit ff56b74

Please sign in to comment.