diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp index b63d42cb..d86df8f0 100755 --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -604,12 +604,14 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec { auto node_l (attempt_l->node); std::shared_ptr block (node_l->ledger.forked_block (transaction_a, *block_a)); - node_l->active.start (transaction_a, block); - node_l->network.broadcast_confirm_req (block_a); - node_l->network.broadcast_confirm_req (block); - auto hash (block_a->hash ()); - attempt_l->requeue_pull (rai::pull_info (pull_l.account, hash, hash)); - BOOST_LOG (node_l->log) << boost::str (boost::format ("While bootstrappping, fork between our block: %2% and block %1% both with root %3%") % block_a->hash ().to_string () % block->hash ().to_string () % block_a->root ().to_string ()); + if (!node_l->active.start (transaction_a, block)) + { + node_l->network.broadcast_confirm_req (block_a); + node_l->network.broadcast_confirm_req (block); + auto hash (block_a->hash ()); + attempt_l->requeue_pull (rai::pull_info (pull_l.account, hash, hash)); + BOOST_LOG (node_l->log) << boost::str (boost::format ("While bootstrappping, fork between our block: %2% and block %1% both with root %3%") % block_a->hash ().to_string () % block->hash ().to_string () % block_a->root ().to_string ()); + } break; } default: diff --git a/rai/node/node.cpp b/rai/node/node.cpp index dc2a5138..291286ec 100755 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -753,7 +753,7 @@ password_fanout (1024), io_threads (std::max (4, std::thread::hardware_concurrency ())), work_threads (std::max (4, std::thread::hardware_concurrency ())), enable_voting (true), -bootstrap_connections (16), +bootstrap_connections (4), callback_port (0) { switch (rai::rai_network) @@ -2877,16 +2877,17 @@ void rai::active_transactions::stop () roots.clear (); } -void rai::active_transactions::start (MDB_txn * transaction_a, std::shared_ptr block_a, std::function )> const & confirmation_action_a) +bool rai::active_transactions::start (MDB_txn * transaction_a, std::shared_ptr block_a, std::function )> const & confirmation_action_a) { - std::lock_guard lock (mutex); - auto root (block_a->root ()); - auto existing (roots.find (root)); - if (existing == roots.end ()) - { - auto election (std::make_shared (transaction_a, node, block_a, confirmation_action_a)); - roots.insert (rai::conflict_info {root, election, 0}); - } + std::lock_guard lock (mutex); + auto root (block_a->root ()); + auto existing (roots.find (root)); + if (existing == roots.end ()) + { + auto election (std::make_shared (transaction_a, node, block_a, confirmation_action_a)); + roots.insert (rai::conflict_info {root, election, 0}); + } + return existing != roots.end (); } // Validate a vote and apply it to the current election if one exists @@ -2904,7 +2905,7 @@ void rai::active_transactions::vote (std::shared_ptr vote_a) } if (election) { - election->vote (vote_a); + election->vote (vote_a); } } diff --git a/rai/node/node.hpp b/rai/node/node.hpp index 35642a23..fc831f7b 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -75,16 +75,16 @@ public: class active_transactions { public: - active_transactions (rai::node &); + active_transactions (rai::node &); // Start an election for a block // Call action with confirmed block, may be different than what we started with - void start (MDB_txn *, std::shared_ptr , std::function )> const & = [] (std::shared_ptr ) {}); - void vote (std::shared_ptr ); + bool start (MDB_txn *, std::shared_ptr , std::function )> const & = [] (std::shared_ptr ) {}); + void vote (std::shared_ptr ); // Is the root of this block in the roots container bool active (rai::block const &); void announce_votes (); void stop (); - boost::multi_index_container + boost::multi_index_container < rai::conflict_info, boost::multi_index::indexed_by @@ -92,8 +92,8 @@ public: boost::multi_index::ordered_unique > > > roots; - rai::node & node; - std::mutex mutex; + rai::node & node; + std::mutex mutex; // Maximum number of conflicts to vote on per interval, lowest root hash first static unsigned constexpr announcements_per_interval = 32; // After this many successive vote announcements, block is confirmed