Remove invalid uses of epoch_1 work threshold (#2733)

Was affecting websocket active_difficulty. Tests for it and RPC active_difficulty now pre-upgrade the node to epoch2 to ensure the output is correct.
This commit is contained in:
Guilherme Lawless 2020-04-25 00:11:29 +01:00 committed by GitHub
commit 774625907d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View file

@ -60,6 +60,9 @@ TEST (websocket, active_difficulty)
config.websocket_config.enabled = true;
config.websocket_config.port = nano::get_available_port ();
auto node1 (system.add_node (config));
// "Start" epoch 2
node1->ledger.cache.epoch_2_started = true;
ASSERT_EQ (node1->default_difficulty (nano::work_version::work_1), node1->network_params.network.publish_thresholds.epoch_2);
ASSERT_EQ (0, node1->websocket_server->subscriber_count (nano::websocket::topic::active_difficulty));
@ -104,14 +107,14 @@ TEST (websocket, active_difficulty)
auto message_contents = event.get_child ("message");
uint64_t network_minimum;
nano::from_string_hex (message_contents.get<std::string> ("network_minimum"), network_minimum);
ASSERT_EQ (network_minimum, node1->network_params.network.publish_thresholds.epoch_1);
ASSERT_EQ (network_minimum, node1->default_difficulty (nano::work_version::work_1));
uint64_t network_current;
nano::from_string_hex (message_contents.get<std::string> ("network_current"), network_current);
ASSERT_EQ (network_current, node1->active.active_difficulty ());
double multiplier = message_contents.get<double> ("multiplier");
ASSERT_NEAR (multiplier, nano::difficulty::to_multiplier (node1->active.active_difficulty (), node1->network_params.network.publish_thresholds.epoch_1), 1e-6);
ASSERT_NEAR (multiplier, nano::difficulty::to_multiplier (node1->active.active_difficulty (), node1->default_difficulty (nano::work_version::work_1)), 1e-6);
}
// Subscribes to block confirmations, confirms a block and then awaits websocket notification

View file

@ -863,7 +863,7 @@ void nano::active_transactions::update_active_multiplier (nano::unique_lock<std:
last_prioritized_multiplier = prioritized.back ();
}
}
debug_assert (multiplier >= nano::difficulty::to_multiplier (node.network_params.network.publish_thresholds.entry, node.network_params.network.publish_thresholds.epoch_1));
debug_assert (multiplier >= nano::difficulty::to_multiplier (node.network_params.network.publish_thresholds.entry, node.network_params.network.publish_thresholds.base));
multipliers_cb.push_front (multiplier);
auto sum (std::accumulate (multipliers_cb.begin (), multipliers_cb.end (), double(0)));
double avg_multiplier (sum / multipliers_cb.size ());

View file

@ -260,7 +260,7 @@ node_seq (seq)
if (this->websocket_server->any_subscriber (nano::websocket::topic::active_difficulty))
{
nano::websocket::message_builder builder;
auto msg (builder.difficulty_changed (network_params.network.publish_thresholds.epoch_1, active_difficulty));
auto msg (builder.difficulty_changed (this->default_difficulty (nano::work_version::work_1), active_difficulty));
this->websocket_server->broadcast (msg);
}
});

View file

@ -7675,6 +7675,9 @@ TEST (rpc, active_difficulty)
{
nano::system system;
auto node = add_ipc_enabled_node (system);
// "Start" epoch 2
node->ledger.cache.epoch_2_started = true;
ASSERT_EQ (node->default_difficulty (nano::work_version::work_1), node->network_params.network.publish_thresholds.epoch_2);
scoped_io_thread_name_change scoped_thread_name_io;
nano::node_rpc_config node_rpc_config;
nano::ipc::ipc_server ipc_server (*node, node_rpc_config);
@ -7705,13 +7708,13 @@ TEST (rpc, active_difficulty)
auto network_minimum_text (response.json.get<std::string> ("network_minimum"));
uint64_t network_minimum;
ASSERT_FALSE (nano::from_string_hex (network_minimum_text, network_minimum));
ASSERT_EQ (node->network_params.network.publish_thresholds.epoch_1, network_minimum);
ASSERT_EQ (node->default_difficulty (nano::work_version::work_1), network_minimum);
auto multiplier (response.json.get<double> ("multiplier"));
ASSERT_NEAR (expected_multiplier, multiplier, 1e-6);
auto network_current_text (response.json.get<std::string> ("network_current"));
uint64_t network_current;
ASSERT_FALSE (nano::from_string_hex (network_current_text, network_current));
ASSERT_EQ (nano::difficulty::from_multiplier (expected_multiplier, node->network_params.network.publish_thresholds.epoch_1), network_current);
ASSERT_EQ (nano::difficulty::from_multiplier (expected_multiplier, node->default_difficulty (nano::work_version::work_1)), network_current);
ASSERT_EQ (response.json.not_found (), response.json.find ("difficulty_trend"));
}
// Test include_trend optional