Removing duplicate roots from the same vote and adjusting tests to accommodate. (#3072)

This commit is contained in:
clemahieu 2020-12-17 12:22:02 +00:00 committed by GitHub
commit 583cd4834d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 5 deletions

View file

@ -2833,6 +2833,36 @@ TEST (node, vote_by_hash_bundle)
// Keep max_hashes above system to ensure it is kept in scope as votes can be added during system destruction
std::atomic<size_t> max_hashes{ 0 };
nano::system system (1);
auto & node = *system.nodes[0];
nano::state_block_builder builder;
std::vector<std::shared_ptr<nano::state_block>> blocks;
auto block = builder.make_block ()
.account (nano::dev_genesis_key.pub)
.previous (nano::genesis_hash)
.representative (nano::dev_genesis_key.pub)
.balance (nano::genesis_amount - 1)
.link (nano::dev_genesis_key.pub)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (nano::genesis_hash))
.build_shared ();
blocks.push_back (block);
ASSERT_EQ (nano::process_result::progress, node.ledger.process (node.store.tx_begin_write (), *blocks.back ()).code);
for (auto i = 2; i < 200; ++i)
{
auto block = builder.make_block ()
.from (*blocks.back ())
.previous (blocks.back ()->hash ())
.balance (nano::genesis_amount - i)
.sign (nano::dev_genesis_key.prv, nano::dev_genesis_key.pub)
.work (*system.work.generate (blocks.back ()->hash ()))
.build_shared ();
blocks.push_back (block);
ASSERT_EQ (nano::process_result::progress, node.ledger.process (node.store.tx_begin_write (), *blocks.back ()).code);
}
auto election_insertion_result = node.active.insert (blocks.back ());
ASSERT_TRUE (election_insertion_result.inserted);
ASSERT_NE (nullptr, election_insertion_result.election);
election_insertion_result.election->force_confirm ();
system.wallet (0)->insert_adhoc (nano::dev_genesis_key.prv);
nano::keypair key1;
system.wallet (0)->insert_adhoc (key1.prv);
@ -2844,9 +2874,9 @@ TEST (node, vote_by_hash_bundle)
}
});
for (int i = 1; i <= 200; i++)
for (auto const & block : blocks)
{
system.nodes[0]->active.generator.add (nano::genesis_account, nano::genesis_hash);
system.nodes[0]->active.generator.add (block->root (), block->hash ());
}
// Verify that bundling occurs. While reaching 12 should be common on most hardware in release mode,

View file

@ -371,7 +371,7 @@ TEST (request_aggregator, cannot_vote)
ASSERT_EQ (3, node.stats.count (nano::stat::type::aggregator, nano::stat::detail::aggregator_accepted));
ASSERT_EQ (0, node.stats.count (nano::stat::type::aggregator, nano::stat::detail::aggregator_dropped));
ASSERT_EQ (4, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_cannot_vote));
ASSERT_TIMELY (3s, 2 == node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_hashes));
ASSERT_TIMELY (3s, 1 == node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_hashes));
ASSERT_TIMELY (3s, 1 == node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_generated_votes));
ASSERT_EQ (0, node.stats.count (nano::stat::type::requests, nano::stat::detail::requests_unknown));
ASSERT_TIMELY (3s, 1 <= node.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::out));

View file

@ -216,7 +216,7 @@ void nano::vote_generator::broadcast (nano::unique_lock<std::mutex> & lock_a)
broadcast_action (cached_vote);
}
}
if (cached_votes.empty ())
if (cached_votes.empty () && std::find (roots.begin (), roots.end (), root) == roots.end ())
{
roots.push_back (root);
hashes.push_back (hash);
@ -258,7 +258,7 @@ void nano::vote_generator::reply (nano::unique_lock<std::mutex> & lock_a, reques
reply_action (cached_vote, request_a.second);
}
}
if (cached_votes.empty ())
if (cached_votes.empty () && std::find (roots.begin (), roots.end (), root) == roots.end ())
{
roots.push_back (i->first);
hashes.push_back (i->second);