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

Remove static instantiation of network_constants #3420

Merged
merged 30 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bf53120
Passing nano::network_constants by ref in to work_pool rather than in…
clemahieu Aug 7, 2021
4a51d0c
Using object reference to network_constants rather than static instan…
clemahieu Aug 7, 2021
68f07fa
Referencing network_constants by reference within websocket_config.
clemahieu Aug 8, 2021
9fea509
Removing static instances of nano::network_constants within unit tests.
clemahieu Aug 8, 2021
238ae67
Moving work_threshold constants on to work_threshold class where they…
clemahieu Aug 8, 2021
cad65ee
Pulling nano::network_constants reference through ipc_config_tcp_sock…
clemahieu Aug 8, 2021
210f725
Pulling network_constants reference through rpc_config rather than in…
clemahieu Aug 8, 2021
c2f19a3
Passing nano::networks enum in to working_path rather than statically…
clemahieu Aug 8, 2021
7520bbe
Converting upgrade logging message that was writing to cerr to a stan…
clemahieu Aug 8, 2021
a1598c9
Removing workaround for coroutines in combination with sanitizers as …
clemahieu Aug 8, 2021
0e8b7cd
Moving threshold classes from free-functions with static network_para…
clemahieu Aug 8, 2021
442fb1e
Moving ::value function on to nano::work_thresholds where it belongs.
clemahieu Aug 8, 2021
aef5020
Moving work_v1::value function on to work_thresholds where it belongs.
clemahieu Aug 8, 2021
49aaac7
Moving threshold function on to work_thresholds class where it belongs.
clemahieu Aug 8, 2021
8e53b14
Moving multiplier normalization from being a free function in to work…
clemahieu Aug 8, 2021
3d71605
Moving work_threshold_base from a free function to a member of work_t…
clemahieu Aug 8, 2021
243a4d9
Moving work_difficulty free function on to work_thresholds class.
clemahieu Aug 8, 2021
868ec86
Moving work_validate from a free function to a member of nano::work_t…
clemahieu Aug 8, 2021
4dead4c
Moving valide_entry from a free function to a method of work_thresholds.
clemahieu Aug 8, 2021
0096d20
Passing work_thresholds in to ledger_constants and removing static re…
clemahieu Aug 9, 2021
e4e2220
Removing check for is_dev_network within using_rocksdb_in_tests as it…
clemahieu Aug 9, 2021
9d47208
Removing unnecessary check for running within unit test context and a…
clemahieu Aug 9, 2021
013104c
This removes debug checks for is_dev_network in several places that d…
clemahieu Aug 9, 2021
2a94a3b
Constifying work_threshold functions.
clemahieu Aug 9, 2021
c3ac780
Moving nano::block::difficulty on to nano::work_thresholds. This move…
clemahieu Aug 9, 2021
ebcf70e
Pulling a work_thresholds reference through opencl_work class so it d…
clemahieu Aug 10, 2021
a56a8d1
Removing empty constructor from network_constants.
clemahieu Aug 10, 2021
a8db7e7
Changing node_config from holding a copy of nano::network_params to h…
clemahieu Aug 10, 2021
7d4bc91
Rewriting how telemetry tests are run so their modifications don't al…
clemahieu Aug 10, 2021
54fb102
Moving work_thresholds in to their own object within network_params a…
clemahieu Aug 10, 2021
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
2 changes: 1 addition & 1 deletion nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ TEST (block, publish_req_serialization)
TEST (block, difficulty)
{
nano::send_block block (0, 1, 2, nano::keypair ().prv, 4, 5);
ASSERT_EQ (block.difficulty (), nano::work_difficulty (block.work_version (), block.root (), block.block_work ()));
ASSERT_EQ (nano::dev::network_params.work.difficulty (block), nano::dev::network_params.work.difficulty (block.work_version (), block.root (), block.block_work ()));
}

TEST (state_block, serialization)
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ TEST (mdb_block_store, sideband_height)
nano::ledger ledger (store, stat, nano::dev::constants);
auto transaction (store.tx_begin_write ());
store.initialize (transaction, ledger.cache);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::send_block send (nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send).code);
nano::receive_block receive (send.hash (), send.hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (send.hash ()));
Expand Down Expand Up @@ -1262,7 +1262,7 @@ TEST (mdb_block_store, upgrade_v14_v15)
}
// Extract confirmation height to a separate database
auto path (nano::unique_path ());
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::send_block send (nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
nano::state_block epoch (nano::dev::genesis_key.pub, send.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (send.hash ()));
nano::state_block state_send (nano::dev::genesis_key.pub, epoch.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (epoch.hash ()));
Expand Down Expand Up @@ -1416,7 +1416,7 @@ TEST (mdb_block_store, upgrade_v16_v17)
// Don't test this in rocksdb mode
return;
}
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::state_block block1 (nano::dev::genesis_key.pub, nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
nano::state_block block2 (nano::dev::genesis_key.pub, block1.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 1, nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (block1.hash ()));
nano::state_block block3 (nano::dev::genesis_key.pub, block2.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio - 2, nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (block2.hash ()));
Expand Down Expand Up @@ -1482,7 +1482,7 @@ TEST (mdb_block_store, upgrade_v17_v18)
nano::keypair key1;
nano::keypair key2;
nano::keypair key3;
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::send_block send_zero (nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
nano::state_block state_receive_zero (nano::dev::genesis_key.pub, send_zero.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, send_zero.hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (send_zero.hash ()));
nano::state_block epoch (nano::dev::genesis_key.pub, state_receive_zero.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_receive_zero.hash ()));
Expand Down Expand Up @@ -1682,7 +1682,7 @@ TEST (mdb_block_store, upgrade_v18_v19)
}
auto path (nano::unique_path ());
nano::keypair key1;
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::send_block send (nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
nano::receive_block receive (send.hash (), send.hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (send.hash ()));
nano::change_block change (receive.hash (), 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (receive.hash ()));
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ TEST (confirmation_heightDeathTest, rollback_added_block)
nano::stat stats;
nano::ledger ledger (*store, stats, nano::dev::constants);
nano::write_database_queue write_database_queue (false);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1;
auto send = std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
{
Expand Down Expand Up @@ -799,7 +799,7 @@ TEST (confirmation_heightDeathTest, modified_chain)
nano::stat stats;
nano::ledger ledger (*store, stats, nano::dev::constants);
nano::write_database_queue write_database_queue (false);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1;
auto send = std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
{
Expand Down Expand Up @@ -869,7 +869,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed)
nano::stat stats;
nano::ledger ledger (*store, stats, nano::dev::constants);
nano::write_database_queue write_database_queue (false);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1;
auto send = std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
auto open = std::make_shared<nano::state_block> (key1.pub, 0, 0, nano::Gxrb_ratio, send->hash (), key1.prv, key1.pub, *pool.generate (key1.pub));
Expand Down Expand Up @@ -1362,7 +1362,7 @@ TEST (confirmation_height, unbounded_block_cache_iteration)
nano::ledger ledger (*store, stats, nano::dev::constants);
nano::write_database_queue write_database_queue (false);
boost::latch initialized_latch{ 0 };
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::logging logging;
nano::keypair key1;
auto send = std::make_shared<nano::send_block> (nano::dev::genesis->hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
Expand Down Expand Up @@ -1412,7 +1412,7 @@ TEST (confirmation_height, pruned_source)
nano::ledger ledger (*store, stats, nano::dev::constants);
ledger.pruning = true;
nano::write_database_queue write_database_queue (false);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
nano::keypair key1, key2;
auto send1 = std::make_shared<nano::state_block> (nano::dev::genesis_key.pub, nano::dev::genesis->hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount - 100, key1.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ()));
auto open1 = std::make_shared<nano::state_block> (key1.pub, 0, key1.pub, 100, send1->hash (), key1.prv, key1.pub, *pool.generate (key1.pub));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/core_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include <nano/node/common.hpp>
#include <nano/node/logging.hpp>
#include <nano/secure/utility.hpp>

#include <boost/filesystem/path.hpp>

namespace nano
{
void cleanup_dev_directories_on_exit ();
void force_nano_dev_network ();
boost::filesystem::path unique_path ();
}

GTEST_API_ int main (int argc, char ** argv)
Expand Down
36 changes: 18 additions & 18 deletions nano/core_test/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <nano/lib/epoch.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/work.hpp>
#include <nano/secure/common.hpp>
#include <nano/test_common/testutil.hpp>

#include <gtest/gtest.h>
Expand Down Expand Up @@ -106,10 +107,9 @@ TEST (difficulty, zero)

TEST (difficulty, network_constants)
{
nano::network_constants constants;
auto & full_thresholds = constants.publish_full;
auto & beta_thresholds = constants.publish_beta;
auto & dev_thresholds = constants.publish_dev;
auto & full_thresholds = nano::work_thresholds::publish_full;
auto & beta_thresholds = nano::work_thresholds::publish_beta;
auto & dev_thresholds = nano::work_thresholds::publish_dev;

ASSERT_NEAR (8., nano::difficulty::to_multiplier (full_thresholds.epoch_2, full_thresholds.epoch_1), 1e-10);
ASSERT_NEAR (1 / 8., nano::difficulty::to_multiplier (full_thresholds.epoch_2_receive, full_thresholds.epoch_1), 1e-10);
Expand All @@ -128,23 +128,23 @@ TEST (difficulty, network_constants)
ASSERT_NEAR (1., nano::difficulty::to_multiplier (dev_thresholds.epoch_2, dev_thresholds.base), 1e-10);

nano::work_version version{ nano::work_version::work_1 };
ASSERT_EQ (constants.publish_thresholds.base, constants.publish_thresholds.epoch_2);
ASSERT_EQ (constants.publish_thresholds.base, nano::work_threshold_base (version));
ASSERT_EQ (constants.publish_thresholds.entry, nano::work_threshold_entry (version, nano::block_type::state));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::send));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::receive));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::open));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold_entry (version, nano::block_type::change));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_0, false, false, false)));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false)));
ASSERT_EQ (constants.publish_thresholds.epoch_1, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false)));
ASSERT_EQ (nano::dev::network_params.work.base, nano::dev::network_params.work.epoch_2);
ASSERT_EQ (nano::dev::network_params.work.base, nano::dev::network_params.work.threshold_base (version));
ASSERT_EQ (nano::dev::network_params.work.entry, nano::dev::network_params.work.threshold_entry (version, nano::block_type::state));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold_entry (version, nano::block_type::send));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold_entry (version, nano::block_type::receive));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold_entry (version, nano::block_type::open));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold_entry (version, nano::block_type::change));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_0, false, false, false)));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false)));
ASSERT_EQ (nano::dev::network_params.work.epoch_1, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_1, false, false, false)));

// Send [+ change]
ASSERT_EQ (constants.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, true, false, false)));
ASSERT_EQ (nano::dev::network_params.work.epoch_2, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_2, true, false, false)));
// Change
ASSERT_EQ (constants.publish_thresholds.epoch_2, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, false)));
ASSERT_EQ (nano::dev::network_params.work.epoch_2, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, false)));
// Receive [+ change] / Open
ASSERT_EQ (constants.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, true, false)));
ASSERT_EQ (nano::dev::network_params.work.epoch_2_receive, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_2, false, true, false)));
// Epoch
ASSERT_EQ (constants.publish_thresholds.epoch_2_receive, nano::work_threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, true)));
ASSERT_EQ (nano::dev::network_params.work.epoch_2_receive, nano::dev::network_params.work.threshold (version, nano::block_details (nano::epoch::epoch_2, false, false, true)));
}
Loading