Don't make another request for confirmation if one is already active.

This commit is contained in:
clemahieu 2018-01-02 00:38:04 -06:00
commit f208551504
3 changed files with 26 additions and 23 deletions

View file

@ -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 <rai::block> 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:

View file

@ -753,7 +753,7 @@ password_fanout (1024),
io_threads (std::max <unsigned> (4, std::thread::hardware_concurrency ())),
work_threads (std::max <unsigned> (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 <rai::block> block_a, std::function <void (std::shared_ptr <rai::block>)> const & confirmation_action_a)
bool rai::active_transactions::start (MDB_txn * transaction_a, std::shared_ptr <rai::block> block_a, std::function <void (std::shared_ptr <rai::block>)> const & confirmation_action_a)
{
std::lock_guard <std::mutex> lock (mutex);
auto root (block_a->root ());
auto existing (roots.find (root));
if (existing == roots.end ())
{
auto election (std::make_shared <rai::election> (transaction_a, node, block_a, confirmation_action_a));
roots.insert (rai::conflict_info {root, election, 0});
}
std::lock_guard <std::mutex> lock (mutex);
auto root (block_a->root ());
auto existing (roots.find (root));
if (existing == roots.end ())
{
auto election (std::make_shared <rai::election> (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 <rai::vote> vote_a)
}
if (election)
{
election->vote (vote_a);
election->vote (vote_a);
}
}

View file

@ -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 <rai::block>, std::function <void (std::shared_ptr <rai::block>)> const & = [] (std::shared_ptr <rai::block>) {});
void vote (std::shared_ptr <rai::vote>);
bool start (MDB_txn *, std::shared_ptr <rai::block>, std::function <void (std::shared_ptr <rai::block>)> const & = [] (std::shared_ptr <rai::block>) {});
void vote (std::shared_ptr <rai::vote>);
// 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 <boost::multi_index::member <rai::conflict_info, rai::block_hash, &rai::conflict_info::root>>
>
> 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