Fix TSAN warning in node.no_voting & wallet.update_work_action (#1894)
* Pass in enable_voting to system constructor * Update system class to make adding nodes with different configurations more easily * Make node_config a const ref * Fix build after merge * Fix TSAN error with wallet.update_work_action
This commit is contained in:
parent
05239813ee
commit
6197774375
7 changed files with 96 additions and 62 deletions
|
@ -1454,7 +1454,9 @@ TEST (confirmation_height, single)
|
|||
TEST (confirmation_height, multiple_accounts)
|
||||
{
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 2, delay_frontier_confirmation_height_updating);
|
||||
nano::system system;
|
||||
system.add_node (nano::node_config (24001, system.logging), delay_frontier_confirmation_height_updating);
|
||||
system.add_node (nano::node_config (24002, system.logging), delay_frontier_confirmation_height_updating);
|
||||
nano::keypair key1;
|
||||
nano::keypair key2;
|
||||
nano::keypair key3;
|
||||
|
@ -1638,7 +1640,9 @@ TEST (confirmation_height, gap_bootstrap)
|
|||
TEST (confirmation_height, gap_live)
|
||||
{
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 2, delay_frontier_confirmation_height_updating);
|
||||
nano::system system;
|
||||
system.add_node (nano::node_config (24001, system.logging), delay_frontier_confirmation_height_updating);
|
||||
system.add_node (nano::node_config (24002, system.logging), delay_frontier_confirmation_height_updating);
|
||||
nano::keypair destination;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (1)->insert_adhoc (destination.prv);
|
||||
|
@ -1711,8 +1715,8 @@ TEST (confirmation_height, gap_live)
|
|||
TEST (confirmation_height, send_receive_between_2_accounts)
|
||||
{
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 1, delay_frontier_confirmation_height_updating);
|
||||
auto node = system.nodes.front ();
|
||||
nano::system system;
|
||||
auto node = system.add_node (nano::node_config (24000, system.logging), delay_frontier_confirmation_height_updating);
|
||||
nano::keypair key1;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::block_hash latest (node->latest (nano::test_genesis_key.pub));
|
||||
|
@ -1784,8 +1788,8 @@ TEST (confirmation_height, send_receive_between_2_accounts)
|
|||
TEST (confirmation_height, send_receive_self)
|
||||
{
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 1, delay_frontier_confirmation_height_updating);
|
||||
auto node = system.nodes.front ();
|
||||
nano::system system;
|
||||
auto node = system.add_node (nano::node_config (24000, system.logging), delay_frontier_confirmation_height_updating);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::block_hash latest (node->latest (nano::test_genesis_key.pub));
|
||||
|
||||
|
@ -1837,8 +1841,8 @@ TEST (confirmation_height, send_receive_self)
|
|||
TEST (confirmation_height, all_block_types)
|
||||
{
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 1, delay_frontier_confirmation_height_updating);
|
||||
auto node = system.nodes.front ();
|
||||
nano::system system;
|
||||
auto node = system.add_node (nano::node_config (24000, system.logging), delay_frontier_confirmation_height_updating);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::block_hash latest (node->latest (nano::test_genesis_key.pub));
|
||||
nano::keypair key1;
|
||||
|
|
|
@ -1726,24 +1726,26 @@ TEST (node, rep_weight)
|
|||
// Test that nodes can disable representative voting
|
||||
TEST (node, no_voting)
|
||||
{
|
||||
nano::system system (24000, 2);
|
||||
nano::system system (24000, 1);
|
||||
auto & node0 (*system.nodes[0]);
|
||||
auto & node1 (*system.nodes[1]);
|
||||
nano::node_config node_config (24001, system.logging);
|
||||
node_config.enable_voting = false;
|
||||
auto & node1 = *system.add_node (node_config);
|
||||
|
||||
auto wallet0 (system.wallet (0));
|
||||
auto wallet1 (system.wallet (1));
|
||||
node0.config.enable_voting = false;
|
||||
// Node0 has a rep
|
||||
wallet0->insert_adhoc (nano::test_genesis_key.prv);
|
||||
// Node1 has a rep
|
||||
wallet1->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key1;
|
||||
wallet1->insert_adhoc (key1.prv);
|
||||
// Broadcast a confirm so others should know this is a rep node
|
||||
wallet0->send_action (nano::test_genesis_key.pub, key1.pub, nano::Mxrb_ratio);
|
||||
wallet1->send_action (nano::test_genesis_key.pub, key1.pub, nano::Mxrb_ratio);
|
||||
system.deadline_set (10s);
|
||||
while (!node1.active.empty ())
|
||||
while (!node0.active.empty ())
|
||||
{
|
||||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
ASSERT_EQ (0, node1.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in));
|
||||
ASSERT_EQ (0, node0.stats.count (nano::stat::type::message, nano::stat::detail::confirm_ack, nano::stat::dir::in));
|
||||
}
|
||||
|
||||
TEST (node, send_callback)
|
||||
|
|
|
@ -1041,9 +1041,10 @@ TEST (wallet, deterministic_restore)
|
|||
|
||||
TEST (wallet, update_work_action)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
auto & node (*system.nodes[0]);
|
||||
node.config.enable_voting = false;
|
||||
nano::system system;
|
||||
nano::node_config node_config (24000, system.logging);
|
||||
node_config.enable_voting = false;
|
||||
auto & node = *system.add_node (node_config);
|
||||
auto & wallet (*system.wallet (0));
|
||||
wallet.insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key;
|
||||
|
|
|
@ -20,9 +20,61 @@ std::string nano::error_system_messages::message (int ev) const
|
|||
return "Invalid error code";
|
||||
}
|
||||
|
||||
nano::system::system (uint16_t port_a, uint16_t count_a, boost::optional<bool> delay_frontier_confirmation_height_updating_a) :
|
||||
alarm (io_ctx),
|
||||
work (1)
|
||||
/** Returns the node added. */
|
||||
std::shared_ptr<nano::node> nano::system::add_node (nano::node_config const & node_config_a, bool delay_frontier_confirmation_height_updating_a)
|
||||
{
|
||||
nano::node_init init;
|
||||
auto node (std::make_shared<nano::node> (init, io_ctx, nano::unique_path (), alarm, node_config_a, work, node_flags (), delay_frontier_confirmation_height_updating_a));
|
||||
assert (!init.error ());
|
||||
node->start ();
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node->wallets.create (wallet);
|
||||
nodes.reserve (nodes.size () + 1);
|
||||
nodes.push_back (node);
|
||||
if (nodes.size () > 1)
|
||||
{
|
||||
auto begin = nodes.end () - 2;
|
||||
for (auto i (begin), j (begin + 1), n (nodes.end ()); j != n; ++i, ++j)
|
||||
{
|
||||
auto node1 (*i);
|
||||
auto node2 (*j);
|
||||
auto starting1 (node1->network.size ());
|
||||
decltype (starting1) new1;
|
||||
auto starting2 (node2->network.size ());
|
||||
decltype (starting2) new2;
|
||||
nano::transport::channel_udp channel ((*j)->network.udp_channels, (*i)->network.endpoint ());
|
||||
(*j)->network.send_keepalive (channel);
|
||||
do
|
||||
{
|
||||
poll ();
|
||||
new1 = node1->network.size ();
|
||||
new2 = node2->network.size ();
|
||||
} while (new1 == starting1 || new2 == starting2);
|
||||
}
|
||||
auto iterations1 (0);
|
||||
while (std::any_of (begin, nodes.end (), [](std::shared_ptr<nano::node> const & node_a) { return node_a->bootstrap_initiator.in_progress (); }))
|
||||
{
|
||||
poll ();
|
||||
++iterations1;
|
||||
assert (iterations1 < 10000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto iterations1 (0);
|
||||
while (node->bootstrap_initiator.in_progress ())
|
||||
{
|
||||
poll ();
|
||||
++iterations1;
|
||||
assert (iterations1 < 10000);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
nano::system::system ()
|
||||
{
|
||||
auto scale_str = std::getenv ("DEADLINE_SCALE_FACTOR");
|
||||
if (scale_str)
|
||||
|
@ -30,43 +82,16 @@ work (1)
|
|||
deadline_scaling_factor = std::stod (scale_str);
|
||||
}
|
||||
logging.init (nano::unique_path ());
|
||||
}
|
||||
|
||||
nano::system::system (uint16_t port_a, uint16_t count_a) :
|
||||
system ()
|
||||
{
|
||||
nodes.reserve (count_a);
|
||||
for (uint16_t i (0); i < count_a; ++i)
|
||||
{
|
||||
nano::node_init init;
|
||||
nano::node_config config (port_a + i, logging);
|
||||
bool delay_frontier_confirmation_height_updating = delay_frontier_confirmation_height_updating_a ? *delay_frontier_confirmation_height_updating_a : false;
|
||||
auto node (std::make_shared<nano::node> (init, io_ctx, nano::unique_path (), alarm, config, work, nano::node_flags (), delay_frontier_confirmation_height_updating));
|
||||
assert (!init.error ());
|
||||
node->start ();
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node->wallets.create (wallet);
|
||||
nodes.push_back (node);
|
||||
}
|
||||
for (auto i (nodes.begin ()), j (nodes.begin () + 1), n (nodes.end ()); j != n; ++i, ++j)
|
||||
{
|
||||
auto node1 (*i);
|
||||
auto node2 (*j);
|
||||
auto starting1 (node1->network.size ());
|
||||
decltype (starting1) new1;
|
||||
auto starting2 (node2->network.size ());
|
||||
decltype (starting2) new2;
|
||||
nano::transport::channel_udp channel ((*j)->network.udp_channels, (*i)->network.endpoint ());
|
||||
(*j)->network.send_keepalive (channel);
|
||||
do
|
||||
{
|
||||
poll ();
|
||||
new1 = node1->network.size ();
|
||||
new2 = node2->network.size ();
|
||||
} while (new1 == starting1 || new2 == starting2);
|
||||
}
|
||||
auto iterations1 (0);
|
||||
while (std::any_of (nodes.begin (), nodes.end (), [](std::shared_ptr<nano::node> const & node_a) { return node_a->bootstrap_initiator.in_progress (); }))
|
||||
{
|
||||
poll ();
|
||||
++iterations1;
|
||||
assert (iterations1 < 10000);
|
||||
nano::system::add_node (config, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ enum class error_system
|
|||
class system final
|
||||
{
|
||||
public:
|
||||
system (uint16_t, uint16_t, boost::optional<bool> delay_frontier_confirmation_height_updating_a = boost::none);
|
||||
system ();
|
||||
system (uint16_t, uint16_t);
|
||||
~system ();
|
||||
void generate_activity (nano::node &, std::vector<nano::account> &);
|
||||
void generate_mass_activity (uint32_t, nano::node &);
|
||||
|
@ -38,11 +39,12 @@ public:
|
|||
std::error_code poll (const std::chrono::nanoseconds & sleep_time = std::chrono::milliseconds (50));
|
||||
void stop ();
|
||||
void deadline_set (const std::chrono::duration<double, std::nano> & delta);
|
||||
std::shared_ptr<nano::node> add_node (nano::node_config const &, bool = false);
|
||||
boost::asio::io_context io_ctx;
|
||||
nano::alarm alarm;
|
||||
nano::alarm alarm{ io_ctx };
|
||||
std::vector<std::shared_ptr<nano::node>> nodes;
|
||||
nano::logging logging;
|
||||
nano::work_pool work;
|
||||
nano::work_pool work{ 1 };
|
||||
std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<double>> deadline{ std::chrono::steady_clock::time_point::max () };
|
||||
double deadline_scaling_factor{ 1.0 };
|
||||
};
|
||||
|
|
|
@ -5358,8 +5358,8 @@ TEST (rpc, confirmation_height_currently_processing)
|
|||
{
|
||||
// The chains should be longer than the batch_write_size to test the amount of blocks confirmed is correct.
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 1, delay_frontier_confirmation_height_updating);
|
||||
auto node = system.nodes.front ();
|
||||
nano::system system;
|
||||
auto node = system.add_node (nano::node_config (24000, system.logging), delay_frontier_confirmation_height_updating);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
|
||||
// Do enough blocks to reliably call RPC before the confirmation height has finished
|
||||
|
|
|
@ -448,8 +448,8 @@ TEST (confirmation_height, long_chains)
|
|||
{
|
||||
// The chains should be longer than the batch_write_size to test the amount of blocks confirmed is correct.
|
||||
bool delay_frontier_confirmation_height_updating = true;
|
||||
nano::system system (24000, 1, delay_frontier_confirmation_height_updating);
|
||||
auto node = system.nodes.front ();
|
||||
nano::system system;
|
||||
auto node = system.add_node (nano::node_config (24000, system.logging), delay_frontier_confirmation_height_updating);
|
||||
nano::keypair key1;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::block_hash latest (node->latest (nano::test_genesis_key.pub));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue