Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable vote generator delay and bundling test #2028

Merged
merged 1 commit into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ TEST (node_config, v16_v17_upgrade)
ASSERT_FALSE (tree.get_optional_child ("external_address"));
ASSERT_FALSE (tree.get_optional_child ("external_port"));
ASSERT_FALSE (tree.get_optional_child ("tcp_incoming_connections_max"));
ASSERT_FALSE (tree.get_optional_child ("vote_generator_delay"));
ASSERT_FALSE (tree.get_optional_child ("diagnostics"));

config.deserialize_json (upgraded, tree);
Expand All @@ -714,6 +715,7 @@ TEST (node_config, v16_v17_upgrade)
ASSERT_TRUE (!!tree.get_optional_child ("external_address"));
ASSERT_TRUE (!!tree.get_optional_child ("external_port"));
ASSERT_TRUE (!!tree.get_optional_child ("tcp_incoming_connections_max"));
ASSERT_TRUE (!!tree.get_optional_child ("vote_generator_delay"));
ASSERT_TRUE (!!tree.get_optional_child ("diagnostics"));

ASSERT_TRUE (upgraded);
Expand All @@ -740,6 +742,7 @@ TEST (node_config, v17_values)
tree.put ("external_address", "::1");
tree.put ("external_port", 0);
tree.put ("tcp_incoming_connections_max", 1);
tree.put ("vote_generator_delay", 50);
nano::jsonconfig txn_tracking_l;
txn_tracking_l.put ("enable", false);
txn_tracking_l.put ("min_read_txn_time", 0);
Expand Down Expand Up @@ -768,6 +771,7 @@ TEST (node_config, v17_values)
tree.put ("external_address", "::ffff:192.168.1.1");
tree.put ("external_port", std::numeric_limits<uint16_t>::max () - 1);
tree.put ("tcp_incoming_connections_max", std::numeric_limits<unsigned>::max ());
tree.put ("vote_generator_delay", std::numeric_limits<unsigned long>::max () - 100);
nano::jsonconfig txn_tracking_l;
txn_tracking_l.put ("enable", true);
txn_tracking_l.put ("min_read_txn_time", 1234);
Expand All @@ -785,6 +789,7 @@ TEST (node_config, v17_values)
ASSERT_EQ (config.external_address, boost::asio::ip::address_v6::from_string ("::ffff:192.168.1.1"));
ASSERT_EQ (config.external_port, std::numeric_limits<uint16_t>::max () - 1);
ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ());
ASSERT_EQ (config.vote_generator_delay.count (), std::numeric_limits<unsigned long>::max () - 100);
ASSERT_TRUE (config.diagnostics_config.txn_tracking.enable);
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_read_txn_time.count (), 1234);
ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ());
Expand Down Expand Up @@ -2182,6 +2187,37 @@ TEST (node, vote_republish)
}
}

TEST (node, vote_by_hash_bundle)
{
nano::system system (24000, 1);
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
nano::keypair key1;
system.wallet (0)->insert_adhoc (key1.prv);

std::atomic<size_t> max_hashes{ 0 };
system.nodes[0]->observers.vote.add ([&max_hashes](nano::transaction const & transaction, std::shared_ptr<nano::vote> vote_a, std::shared_ptr<nano::transport::channel> channel_a) {
if (vote_a->blocks.size () > max_hashes)
{
max_hashes = vote_a->blocks.size ();
}
});

nano::genesis genesis;
for (int i = 1; i <= 200; i++)
{
auto send (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, std::numeric_limits<nano::uint128_t>::max () - (system.nodes[0]->config.receive_minimum.number () * i), nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (genesis.hash ())));
system.nodes[0]->block_confirm (send);
}

// Verify bundling. We're content with 8 hashes for the test, although
// reaching 12 should be common on most hardware.
system.deadline_set (10s);
while (max_hashes.load () < 8)
{
ASSERT_NO_ERROR (system.poll ());
}
}

TEST (node, vote_by_hash_republish)
{
std::vector<nano::transport::transport_type> types{ nano::transport::transport_type::tcp, nano::transport::transport_type::udp };
Expand Down
5 changes: 5 additions & 0 deletions nano/node/nodeconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ nano::error nano::node_config::serialize_json (nano::jsonconfig & json) const
json.put ("block_processor_batch_max_time", block_processor_batch_max_time.count ());
json.put ("allow_local_peers", allow_local_peers);
json.put ("vote_minimum", vote_minimum.to_string_dec ());
json.put ("vote_generator_delay", vote_generator_delay.count ());
json.put ("unchecked_cutoff_time", unchecked_cutoff_time.count ());
json.put ("tcp_io_timeout", tcp_io_timeout.count ());
json.put ("pow_sleep_interval", pow_sleep_interval.count ());
Expand Down Expand Up @@ -243,6 +244,7 @@ bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & jso
json.put ("external_address", external_address.to_string ());
json.put ("external_port", external_port);
json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max);
json.put ("vote_generator_delay", vote_generator_delay.count ());
}
case 17:
break;
Expand Down Expand Up @@ -338,6 +340,9 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco
json.get_error ().set ("vote_minimum contains an invalid decimal amount");
}

auto vote_generator_delay_l (json.get<unsigned long> ("vote_generator_delay"));
vote_generator_delay = std::chrono::milliseconds (vote_generator_delay_l);

auto block_processor_batch_max_time_l (json.get<unsigned long> ("block_processor_batch_max_time"));
block_processor_batch_max_time = std::chrono::milliseconds (block_processor_batch_max_time_l);
auto unchecked_cutoff_time_l = static_cast<unsigned long> (unchecked_cutoff_time.count ());
Expand Down
1 change: 1 addition & 0 deletions nano/node/nodeconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class node_config
unsigned bootstrap_fraction_numerator{ 1 };
nano::amount receive_minimum{ nano::xrb_ratio };
nano::amount vote_minimum{ nano::Gxrb_ratio };
std::chrono::milliseconds vote_generator_delay{ std::chrono::milliseconds (50) };
nano::amount online_weight_minimum{ 60000 * nano::Gxrb_ratio };
unsigned online_weight_quorum{ 50 };
unsigned password_fanout{ 1024 };
Expand Down
28 changes: 25 additions & 3 deletions nano/node/voting.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <nano/node/node.hpp>
#include <nano/node/voting.hpp>

#include <chrono>

nano::vote_generator::vote_generator (nano::node & node_a) :
node (node_a),
stopped (false),
Expand Down Expand Up @@ -66,15 +68,35 @@ void nano::vote_generator::run ()
lock.unlock ();
condition.notify_all ();
lock.lock ();
auto min (std::numeric_limits<std::chrono::steady_clock::time_point>::min ());
auto cutoff (min);
while (!stopped)
{
if (!hashes.empty ())
auto now (std::chrono::steady_clock::now ());
if (hashes.size () >= 12)
{
send (lock);
}
else
else if (cutoff == min) // && hashes.size () < 12
{
cutoff = now + node.config.vote_generator_delay;
condition.wait_until (lock, cutoff);
}
else if (now < cutoff) // && hashes.size () < 12
{
condition.wait_until (lock, cutoff);
}
else // now >= cutoff && hashes.size () < 12
{
condition.wait (lock);
cutoff = min;
if (!hashes.empty ())
{
send (lock);
}
else
{
condition.wait (lock);
}
}
}
}
Expand Down