diff --git a/banano/core_test/node.cpp b/banano/core_test/node.cpp index 85fb4a917f..007eb88eec 100755 --- a/banano/core_test/node.cpp +++ b/banano/core_test/node.cpp @@ -1445,7 +1445,7 @@ TEST (node, bootstrap_connection_scaling) rai::system system (24000, 1); auto & node1 (*system.nodes[0]); node1.bootstrap_initiator.bootstrap (); - auto & attempt = node1.bootstrap_initiator.attempt; + auto attempt (node1.bootstrap_initiator.current_attempt ()); ASSERT_EQ (34, attempt->target_connections (25000)); ASSERT_EQ (4, attempt->target_connections (0)); ASSERT_EQ (64, attempt->target_connections (50000)); diff --git a/banano/node/bootstrap.cpp b/banano/node/bootstrap.cpp index e1c394cc19..1a0f0e4f58 100755 --- a/banano/node/bootstrap.cpp +++ b/banano/node/bootstrap.cpp @@ -524,14 +524,6 @@ void rai::bulk_pull_client::request () { std::unique_lock lock (connection->attempt->mutex); BOOST_LOG (connection->node->log) << boost::str (boost::format ("%1% accounts in pull queue") % connection->attempt->pulls.size ()); - if (connection->attempt->forks_in_progress.size () > 0) - { - BOOST_LOG (connection->node->log) << boost::str (boost::format ("Forks being resolved (roots):")); - for (auto i (connection->attempt->forks_in_progress.begin ()), n (connection->attempt->forks_in_progress.end ()); i != n; ++i) - { - BOOST_LOG (connection->node->log) << boost::str (boost::format ("%1%") % i->to_string ()); - } - } } auto this_l (shared_from_this ()); connection->start_timeout (); @@ -946,8 +938,7 @@ bool rai::bootstrap_attempt::still_pulling () auto running (!stopped); auto more_pulls (!pulls.empty ()); auto still_pulling (pulling > 0); - auto more_forks (!forks_in_progress.empty ()); - return running && (more_pulls || still_pulling || more_forks); + return running && (more_pulls || still_pulling); } void rai::bootstrap_attempt::run () @@ -1032,38 +1023,32 @@ void rai::bootstrap_attempt::process_fork (MDB_txn * transaction_a, std::shared_ { std::lock_guard lock (mutex); auto root (block_a->root ()); - if (forks_attempted.find (root) == forks_attempted.end ()) - { - if (!node->store.block_exists (transaction_a, block_a->hash ()) && (node->store.block_exists (transaction_a, root) || node->store.account_exists (transaction_a, root))) - { - 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, root) || node->store.account_exists (transaction_a, root))) + { + std::shared_ptr ledger_block (node->ledger.forked_block (transaction_a, *block_a)); + if (ledger_block) + { + std::weak_ptr this_w (shared_from_this ()); + if (!node->active.start (transaction_a, std::make_pair (ledger_block, block_a), [this_w, root](std::shared_ptr, bool resolved) { + if (auto this_l = this_w.lock ()) + { + if (resolved) + { + rai::transaction transaction (this_l->node->store.environment, nullptr, false); + auto account (this_l->node->ledger.store.frontier_get (transaction, root)); + if (!account.is_zero ()) + { + this_l->requeue_pull (rai::pull_info (account, root, root)); + } + else if (this_l->node->ledger.store.account_exists (transaction, root)) + { + this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0))); + } + } + } + })) { BOOST_LOG (node->log) << boost::str (boost::format ("Resolving fork between our block: %1% and block %2% both with root %3%") % ledger_block->hash ().to_string () % block_a->hash ().to_string () % block_a->root ().to_string ()); - forks_in_progress.insert (root); - forks_attempted.insert (root); - std::weak_ptr this_w (shared_from_this ()); - node->active.start (transaction_a, std::make_pair (ledger_block, block_a), [this_w, root](std::shared_ptr, bool resolved) { - if (auto this_l = this_w.lock ()) - { - if (resolved) - { - rai::transaction transaction (this_l->node->store.environment, nullptr, false); - auto account (this_l->node->ledger.store.frontier_get (transaction, root)); - if (!account.is_zero ()) - { - this_l->requeue_pull (rai::pull_info (account, root, root)); - } - else if (this_l->node->ledger.store.account_exists (transaction, root)) - { - this_l->requeue_pull (rai::pull_info (root, rai::block_hash (0), rai::block_hash (0))); - } - } - std::lock_guard lock (this_l->mutex); - this_l->forks_in_progress.erase (root); - this_l->condition.notify_all (); - } - }); node->network.broadcast_confirm_req (ledger_block); node->network.broadcast_confirm_req (block_a); } @@ -1351,9 +1336,14 @@ void rai::bootstrap_initiator::add_observer (std::function const & o } bool rai::bootstrap_initiator::in_progress () +{ + return current_attempt () != nullptr; +} + +std::shared_ptr rai::bootstrap_initiator::current_attempt () { std::lock_guard lock (mutex); - return attempt != nullptr; + return attempt; } void rai::bootstrap_initiator::stop () diff --git a/banano/node/bootstrap.hpp b/banano/node/bootstrap.hpp index 540633bd10..5b0df626bb 100755 --- a/banano/node/bootstrap.hpp +++ b/banano/node/bootstrap.hpp @@ -92,8 +92,6 @@ class bootstrap_attempt : public std::enable_shared_from_this unsigned target_connections (size_t pulls_remaining); bool should_log (); std::chrono::steady_clock::time_point next_log; - std::unordered_set forks_attempted; - std::unordered_set forks_in_progress; std::deque> clients; std::weak_ptr connection_frontier_request; std::weak_ptr frontiers; @@ -191,13 +189,14 @@ class bootstrap_initiator void notify_listeners (bool); void add_observer (std::function const &); bool in_progress (); + std::shared_ptr current_attempt (); void process_fork (MDB_txn *, std::shared_ptr); void stop (); + +private: rai::node & node; std::shared_ptr attempt; bool stopped; - -private: std::mutex mutex; std::condition_variable condition; std::vector> observers; diff --git a/banano/node/rpc.cpp b/banano/node/rpc.cpp index bc652a6788..cdeb5d5ba6 100755 --- a/banano/node/rpc.cpp +++ b/banano/node/rpc.cpp @@ -1238,7 +1238,7 @@ void rai::rpc_handler::block_create () } if (type == "state") { - if (previous_text.is_initialized () && !representative.is_zero () && !balance.is_zero () && (!link.is_zero () || link_text.is_initialized ())) + if (previous_text.is_initialized () && !representative.is_zero () && (!link.is_zero () || link_text.is_initialized ())) { if (work == 0) { @@ -1731,7 +1731,7 @@ class history_visitor : public rai::block_visitor { tree.put ("type", "send"); } - tree.put ("account", block_a.hashables.account.to_account ()); + tree.put ("account", block_a.hashables.link.to_account ()); tree.put ("amount", (previous_balance - balance).convert_to ()); } else