From 923639cd2a3d000fcd79fe06412f03d647588f7b Mon Sep 17 00:00:00 2001 From: clemahieu Date: Wed, 7 Mar 2018 18:12:50 -0600 Subject: [PATCH] Checking ledger::forked_block preconditions which were asserting. --- rai/node/bootstrap.cpp | 83 ++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index 0882cf1f..8d885b07 100644 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -967,55 +967,58 @@ void rai::bootstrap_attempt::process_fork (MDB_txn * transaction_a, std::shared_ void rai::bootstrap_attempt::try_resolve_fork (MDB_txn * transaction_a, std::shared_ptr block_a, bool from_processor) { std::weak_ptr this_w (shared_from_this ()); - std::shared_ptr ledger_block (node->ledger.forked_block (transaction_a, *block_a)); - if (ledger_block) + if (!node->store.block_exists (transaction_a, block_a->hash ()) && node->store.block_exists (transaction_a, block_a->root ())) { - node->active.start (transaction_a, ledger_block, [this_w, block_a](std::shared_ptr, bool resolved) { - if (auto this_l = this_w.lock ()) - { - if (resolved) + std::shared_ptr ledger_block (node->ledger.forked_block (transaction_a, *block_a)); + if (ledger_block) + { + node->active.start (transaction_a, ledger_block, [this_w, block_a](std::shared_ptr, bool resolved) { + if (auto this_l = this_w.lock ()) { + if (resolved) { - std::unique_lock lock (this_l->mutex); - this_l->unresolved_forks.erase (block_a->hash ()); - this_l->condition.notify_all (); - } - rai::transaction transaction (this_l->node->store.environment, nullptr, false); - auto account (this_l->node->ledger.store.frontier_get (transaction, block_a->root ())); - if (!account.is_zero ()) - { - this_l->requeue_pull (rai::pull_info (account, block_a->root (), block_a->root ())); - } - else if (this_l->node->ledger.store.account_exists (transaction, block_a->root ())) - { - this_l->requeue_pull (rai::pull_info (block_a->root (), rai::block_hash (0), rai::block_hash (0))); + { + std::unique_lock lock (this_l->mutex); + this_l->unresolved_forks.erase (block_a->hash ()); + this_l->condition.notify_all (); + } + rai::transaction transaction (this_l->node->store.environment, nullptr, false); + auto account (this_l->node->ledger.store.frontier_get (transaction, block_a->root ())); + if (!account.is_zero ()) + { + this_l->requeue_pull (rai::pull_info (account, block_a->root (), block_a->root ())); + } + else if (this_l->node->ledger.store.account_exists (transaction, block_a->root ())) + { + this_l->requeue_pull (rai::pull_info (block_a->root (), rai::block_hash (0), rai::block_hash (0))); + } } } - } - }); + }); + + auto hash = block_a->hash (); + bool exists = true; + if (from_processor) + { + // Only add the block to the unresolved fork tracker if it's the first time we've seen it (i.e. this call came from the block processor). + std::unique_lock lock (mutex); + exists = unresolved_forks.find (hash) != unresolved_forks.end (); + if (!exists) + { + unresolved_forks[hash] = block_a; + } + } - auto hash = block_a->hash (); - bool exists = true; - if (from_processor) - { - // Only add the block to the unresolved fork tracker if it's the first time we've seen it (i.e. this call came from the block processor). - std::unique_lock lock (mutex); - exists = unresolved_forks.find (hash) != unresolved_forks.end (); if (!exists) { - unresolved_forks[hash] = block_a; + BOOST_LOG (node->log) << boost::str (boost::format ("While bootstrappping, fork between our block: %1% and block %2% both with root %3%") % ledger_block->hash ().to_string () % hash.to_string () % block_a->root ().to_string ()); + } + if (!exists || !from_processor) + { + // Only broadcast if it's a new fork, or if the request is coming from the retry loop. + node->network.broadcast_confirm_req (ledger_block); + node->network.broadcast_confirm_req (block_a); } - } - - if (!exists) - { - BOOST_LOG (node->log) << boost::str (boost::format ("While bootstrappping, fork between our block: %1% and block %2% both with root %3%") % ledger_block->hash ().to_string () % hash.to_string () % block_a->root ().to_string ()); - } - if (!exists || !from_processor) - { - // Only broadcast if it's a new fork, or if the request is coming from the retry loop. - node->network.broadcast_confirm_req (ledger_block); - node->network.broadcast_confirm_req (block_a); } } }