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

Removing static initialization of nano::network_params #3413

Merged
merged 17 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4dede6d
Removing unused variable.
clemahieu Aug 1, 2021
e2cd9c7
Removing unnecessary is_dev_network checks and removing unused refere…
clemahieu Aug 1, 2021
02d8673
Removing unused usages of nano::network_params
clemahieu Aug 1, 2021
49d6615
Removing unnecessary checks for is_dev_network in confirmation height…
clemahieu Aug 3, 2021
2068e04
Rewrite reset_confirmation_heights to use a reference to ledger_const…
clemahieu Aug 3, 2021
4a737c4
Converting node_id_handshake from unnecessarily using channel::send_b…
clemahieu Aug 3, 2021
fe97b2e
Removing the version_min_m member from nano::message_header as unnece…
clemahieu Aug 3, 2021
7b7a105
Passing nano::protocol_constants in to message_parser rather than ref…
clemahieu Aug 3, 2021
abdfe15
Sending message via nano::channel::send rather than directly via send…
clemahieu Aug 3, 2021
240b1f8
Moving message header version assignment to nano::channel::send rathe…
clemahieu Aug 3, 2021
5ece01a
Removing unused variables.
clemahieu Aug 3, 2021
0f2c738
Removing unused references to nano::network_params and replacing a st…
clemahieu Aug 3, 2021
624674a
Replacing static network_params with a default inactive node.
clemahieu Aug 3, 2021
0d4f505
Threading is_state_epoch through block callbacks and removing static …
clemahieu Aug 4, 2021
20828e6
Removing default constructor for nano::network_params that uses stati…
clemahieu Aug 4, 2021
7230b1f
Merging protocol_constants in to network_constants.
clemahieu Aug 5, 2021
8460306
Initializing message_header version and network fields from nano::net…
clemahieu Aug 5, 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
13 changes: 5 additions & 8 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,9 @@ TEST (mdb_block_store, upgrade_v14_v15)
}
// Extract confirmation height to a separate database
auto path (nano::unique_path ());
nano::network_params network_params;
nano::work_pool pool (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, 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 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 ()));
{
nano::logger_mt logger;
Expand Down Expand Up @@ -1483,20 +1482,19 @@ TEST (mdb_block_store, upgrade_v17_v18)
nano::keypair key1;
nano::keypair key2;
nano::keypair key3;
nano::network_params network_params;
nano::work_pool pool (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, 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 ()));
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 ()));
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, nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (epoch.hash ()));
nano::state_block state_receive (nano::dev::genesis_key.pub, state_send.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, state_send.hash (), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_send.hash ()));
nano::state_block state_change (nano::dev::genesis_key.pub, state_receive.hash (), nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, 0, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_receive.hash ()));
nano::state_block state_send_change (nano::dev::genesis_key.pub, state_change.hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, key1.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_change.hash ()));
nano::state_block epoch_first (key1.pub, 0, 0, 0, network_params.ledger.epochs.link (nano::epoch::epoch_2), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (key1.pub));
nano::state_block epoch_first (key1.pub, 0, 0, 0, nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (key1.pub));
nano::state_block state_receive2 (key1.pub, epoch_first.hash (), key1.pub, nano::Gxrb_ratio, state_send_change.hash (), key1.prv, key1.pub, *pool.generate (epoch_first.hash ()));
nano::state_block state_send2 (nano::dev::genesis_key.pub, state_send_change.hash (), key1.pub, nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, key2.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_send_change.hash ()));
nano::state_block state_open (key2.pub, 0, key2.pub, nano::Gxrb_ratio, state_send2.hash (), key2.prv, key2.pub, *pool.generate (key2.pub));
nano::state_block state_send_epoch_link (key2.pub, state_open.hash (), key2.pub, 0, network_params.ledger.epochs.link (nano::epoch::epoch_2), key2.prv, key2.pub, *pool.generate (state_open.hash ()));
nano::state_block state_send_epoch_link (key2.pub, state_open.hash (), key2.pub, 0, nano::dev::network_params.ledger.epochs.link (nano::epoch::epoch_2), key2.prv, key2.pub, *pool.generate (state_open.hash ()));
{
nano::logger_mt logger;
nano::mdb_store store (logger, path, nano::dev::constants);
Expand Down Expand Up @@ -1685,11 +1683,10 @@ 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::network_params network_params;
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 ()));
nano::state_block state_epoch (nano::dev::genesis_key.pub, change.hash (), 0, nano::dev::constants.genesis_amount, network_params.ledger.epochs.link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (change.hash ()));
nano::state_block state_epoch (nano::dev::genesis_key.pub, change.hash (), 0, 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 (change.hash ()));
nano::state_block state_send (nano::dev::genesis_key.pub, state_epoch.hash (), 0, nano::dev::constants.genesis_amount - nano::Gxrb_ratio, key1.pub, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (state_epoch.hash ()));
nano::state_block state_open (key1.pub, 0, 0, nano::Gxrb_ratio, state_send.hash (), key1.prv, key1.pub, *pool.generate (key1.pub));

Expand Down
1 change: 0 additions & 1 deletion nano/core_test/fakes/work_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne
work_pool.generate (version, hash, request_difficulty, [this_l, hash] (boost::optional<uint64_t> work_a) {
auto result = work_a.value_or (0);
auto result_difficulty (nano::work_difficulty (this_l->version, hash, result));
static nano::network_params params;
ptree::ptree message_l;
message_l.put ("work", nano::to_string_hex (result));
message_l.put ("difficulty", nano::to_string_hex (result_difficulty));
Expand Down
16 changes: 9 additions & 7 deletions nano/core_test/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ TEST (message, keepalive_deserialize)

TEST (message, publish_serialization)
{
nano::network_params params;
nano::publish publish (std::make_shared<nano::send_block> (0, 1, 2, nano::keypair ().prv, 4, 5));
publish.header.network = nano::networks::nano_dev_network;
publish.header.version_max = 6;
publish.header.version_using = 5;
publish.header.version_min = 4;
ASSERT_EQ (nano::block_type::send, publish.header.block_type ());
std::vector<uint8_t> bytes;
{
Expand All @@ -56,19 +58,19 @@ TEST (message, publish_serialization)
ASSERT_EQ (8, bytes.size ());
ASSERT_EQ (0x52, bytes[0]);
ASSERT_EQ (0x41, bytes[1]);
ASSERT_EQ (params.protocol.protocol_version, bytes[2]);
ASSERT_EQ (params.protocol.protocol_version, bytes[3]);
ASSERT_EQ (params.protocol.protocol_version_min (), bytes[4]);
ASSERT_EQ (6, bytes[2]);
ASSERT_EQ (5, bytes[3]);
ASSERT_EQ (4, bytes[4]);
ASSERT_EQ (static_cast<uint8_t> (nano::message_type::publish), bytes[5]);
ASSERT_EQ (0x00, bytes[6]); // extensions
ASSERT_EQ (static_cast<uint8_t> (nano::block_type::send), bytes[7]);
nano::bufferstream stream (bytes.data (), bytes.size ());
auto error (false);
nano::message_header header (error, stream);
ASSERT_FALSE (error);
ASSERT_EQ (params.protocol.protocol_version_min (), header.version_min ());
ASSERT_EQ (params.protocol.protocol_version, header.version_using);
ASSERT_EQ (params.protocol.protocol_version, header.version_max);
ASSERT_EQ (4, header.version_min);
ASSERT_EQ (5, header.version_using);
ASSERT_EQ (6, header.version_max);
ASSERT_EQ (nano::message_type::publish, header.type);
}

Expand Down
15 changes: 10 additions & 5 deletions nano/core_test/message_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ TEST (message_parser, exact_confirm_ack_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
auto vote (std::make_shared<nano::vote> (0, nano::keypair ().prv, 0, std::move (block)));
nano::confirm_ack message (vote);
Expand Down Expand Up @@ -101,7 +102,8 @@ TEST (message_parser, exact_confirm_req_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
nano::confirm_req message (std::move (block));
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -134,7 +136,8 @@ TEST (message_parser, exact_confirm_req_hash_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::send_block block (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1)));
nano::confirm_req message (block.hash (), block.root ());
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -167,7 +170,8 @@ TEST (message_parser, exact_publish_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, *system.work.generate (nano::root (1))));
nano::publish message (std::move (block));
std::vector<uint8_t> bytes;
Expand Down Expand Up @@ -200,7 +204,8 @@ TEST (message_parser, exact_keepalive_size)
nano::network_filter filter (1);
nano::block_uniquer block_uniquer;
nano::vote_uniquer vote_uniquer (block_uniquer);
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work);
nano::protocol_constants protocol;
nano::message_parser parser (filter, block_uniquer, vote_uniquer, visitor, system.work, protocol);
nano::keepalive message;
std::vector<uint8_t> bytes;
{
Expand Down
7 changes: 3 additions & 4 deletions nano/core_test/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,11 @@ TEST (tcp_listener, tcp_listener_timeout_node_id_handshake)
auto socket (std::make_shared<nano::socket> (*node0));
auto cookie (node0->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (node0->bootstrap.endpoint ())));
nano::node_id_handshake node_id_handshake (cookie, boost::none);
auto input (node_id_handshake.to_shared_const_buffer ());
socket->async_connect (node0->bootstrap.endpoint (), [&input, socket] (boost::system::error_code const & ec) {
auto channel = std::make_shared<nano::transport::channel_tcp> (*node0, socket);
socket->async_connect (node0->bootstrap.endpoint (), [&node_id_handshake, channel] (boost::system::error_code const & ec) {
ASSERT_FALSE (ec);
socket->async_write (input, [&input] (boost::system::error_code const & ec, size_t size_a) {
channel->send (node_id_handshake, [] (boost::system::error_code const & ec, size_t size_a) {
ASSERT_FALSE (ec);
ASSERT_EQ (input.size (), size_a);
});
});
ASSERT_TIMELY (5s, node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake) != 0);
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ TEST (telemetry, remove_peer_different_genesis)

ASSERT_TIMELY (1s, 0 == node0->network.size ());
ASSERT_TIMELY (1s, 0 == node1->network.size ());
ASSERT_EQ (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::out), 1);
ASSERT_EQ (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::out), 1);
ASSERT_GE (node0->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::out), 1);
ASSERT_GE (node1->stats.count (nano::stat::type::message, nano::stat::detail::node_id_handshake, nano::stat::dir::out), 1);

nano::lock_guard<nano::mutex> guard (node0->network.excluded_peers.mutex);
ASSERT_EQ (1, node0->network.excluded_peers.peers.get<nano::peer_exclusion::tag_endpoint> ().count (node1->network.endpoint ().address ()));
Expand Down
3 changes: 1 addition & 2 deletions nano/core_test/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace nano
{
TEST (local_vote_history, basic)
{
nano::network_params params;
nano::local_vote_history history{ params.voting };
nano::local_vote_history history{ nano::dev::network_params.voting };
ASSERT_FALSE (history.exists (1));
ASSERT_FALSE (history.exists (2));
ASSERT_TRUE (history.votes (1).empty ());
Expand Down
1 change: 0 additions & 1 deletion nano/lib/lmdbconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ nano::error nano::lmdb_config::serialize_toml (nano::tomlconfig & toml) const

nano::error nano::lmdb_config::deserialize_toml (nano::tomlconfig & toml)
{
static nano::network_params params;
auto default_max_databases = max_databases;
toml.get_optional<uint32_t> ("max_databases", max_databases);
toml.get_optional<size_t> ("map_size", map_size);
Expand Down
3 changes: 3 additions & 0 deletions nano/node/bootstrap/bootstrap_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class request_response_visitor : public nano::message_visitor
debug_assert (!nano::validate_message (response->first, *message_a.query, response->second));
auto cookie (connection->node->network.syn_cookies.assign (nano::transport::map_tcp_to_endpoint (connection->remote_endpoint)));
nano::node_id_handshake response_message (cookie, response);
response_message.header.version_max = connection->node->network_params.protocol.protocol_version;
response_message.header.version_using = connection->node->network_params.protocol.protocol_version;
response_message.header.version_min = connection->node->network_params.protocol.protocol_version_min ();
auto shared_const_buffer = response_message.to_shared_const_buffer ();
connection->socket->async_write (shared_const_buffer, [connection = std::weak_ptr<nano::bootstrap_server> (connection)] (boost::system::error_code const & ec, size_t size_a) {
if (auto connection_l = connection.lock ())
Expand Down
11 changes: 5 additions & 6 deletions nano/node/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace
{
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::store & store);
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::ledger_constants & constants, nano::store & store);
bool is_using_rocksdb (boost::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec);
}

Expand Down Expand Up @@ -236,7 +236,7 @@ bool copy_database (boost::filesystem::path const & data_path, boost::program_op
}
if (vm.count ("confirmation_height_clear"))
{
reset_confirmation_heights (store.tx_begin_write (), store);
reset_confirmation_heights (store.tx_begin_write (), node.node->network_params.ledger, store);
}
if (vm.count ("final_vote_clear"))
{
Expand Down Expand Up @@ -601,7 +601,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
else
{
auto transaction (node.node->store.tx_begin_write ());
reset_confirmation_heights (transaction, node.node->store);
reset_confirmation_heights (transaction, node.node->network_params.ledger, node.node->store);
std::cout << "Confirmation heights of all accounts (except genesis which is set to 1) are set to 0" << std::endl;
}
}
Expand Down Expand Up @@ -1300,14 +1300,13 @@ std::unique_ptr<nano::inactive_node> nano::default_inactive_node (boost::filesys

namespace
{
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::store & store)
void reset_confirmation_heights (nano::write_transaction const & transaction, nano::ledger_constants & constants, nano::store & store)
{
// First do a clean sweep
store.confirmation_height.clear (transaction);

// Then make sure the confirmation height of the genesis account open block is 1
nano::network_params network_params;
store.confirmation_height.put (transaction, network_params.ledger.genesis->account (), { 1, network_params.ledger.genesis->hash () });
store.confirmation_height.put (transaction, constants.genesis->account (), { 1, constants.genesis->hash () });
}

bool is_using_rocksdb (boost::filesystem::path const & data_path, boost::program_options::variables_map const & vm, std::error_code & ec)
Expand Down
Loading