From 36adbad5e4d119d713ddee22e10d55c1a720bad0 Mon Sep 17 00:00:00 2001 From: theohax Date: Tue, 3 Aug 2021 22:34:00 +0300 Subject: [PATCH 01/10] Introduce null accounts as nano::account{nullptr} --- nano/core_test/block_store.cpp | 12 +-- nano/core_test/ledger.cpp | 6 +- nano/core_test/network.cpp | 4 +- nano/core_test/system.cpp | 2 +- nano/core_test/wallet.cpp | 4 +- nano/lib/blocks.cpp | 31 ++++++-- nano/lib/blocks.hpp | 2 +- nano/lib/numbers.cpp | 22 ++++++ nano/lib/numbers.hpp | 8 ++ nano/lib/walletconfig.hpp | 2 +- nano/nano_node/entry.cpp | 4 +- nano/node/active_transactions.cpp | 18 ++--- nano/node/active_transactions.hpp | 2 +- nano/node/bootstrap/bootstrap.hpp | 2 +- nano/node/bootstrap/bootstrap_attempt.cpp | 4 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/node/bootstrap/bootstrap_frontier.cpp | 12 +-- nano/node/bootstrap/bootstrap_legacy.hpp | 2 +- nano/node/bootstrap/bootstrap_server.hpp | 2 +- nano/node/common.cpp | 3 +- nano/node/common.hpp | 2 +- nano/node/election.cpp | 6 +- nano/node/ipc/action_handler.cpp | 3 +- nano/node/ipc/ipc_broker.cpp | 3 +- nano/node/json_handler.cpp | 18 ++--- nano/node/node.cpp | 2 +- nano/node/nodeconfig.cpp | 4 +- nano/node/repcrawler.hpp | 2 +- nano/node/wallet.cpp | 8 +- nano/node/websocket.cpp | 9 ++- nano/rpc_test/rpc.cpp | 13 ++-- nano/secure/common.cpp | 20 +++-- nano/secure/common.hpp | 77 ++++++++++---------- nano/secure/ledger.cpp | 8 +- nano/secure/store/frontier_store_partial.hpp | 2 +- nano/secure/versioning.hpp | 6 +- 36 files changed, 195 insertions(+), 132 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 0e4411b665..1bd187b093 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -523,7 +523,7 @@ TEST (block_store, frontier_retrieval) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account1 (0); + nano::account account1{ static_cast (0) }; nano::account_info info1 (0, 0, 0, 0, 0, 0, nano::epoch::epoch_0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account1, { 0, nano::block_hash (0) }); @@ -538,7 +538,7 @@ TEST (block_store, one_account) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account (0); + nano::account account{ static_cast (0) }; nano::block_hash hash (0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account, { 20, nano::block_hash (15) }); @@ -783,7 +783,7 @@ TEST (block_store, large_iteration) store->account.put (transaction, account, nano::account_info ()); } std::unordered_set accounts2; - nano::account previous (0); + nano::account previous{ static_cast (0) }; auto transaction (store->tx_begin_read ()); for (auto i (store->account.begin (transaction, 0)), n (store->account.end ()); i != n; ++i) { @@ -1874,9 +1874,9 @@ TEST (block_store, confirmation_height) nano::logger_mt logger; auto store = nano::make_store (logger, path, nano::dev::constants); - nano::account account1 (0); - nano::account account2 (1); - nano::account account3 (2); + nano::account account1{ static_cast (0) }; + nano::account account2{ 1 }; + nano::account account3{ 2 }; nano::block_hash cemented_frontier1 (3); nano::block_hash cemented_frontier2 (4); nano::block_hash cemented_frontier3 (5); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 6cb0bdd8a6..0485f775b6 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -1525,13 +1525,13 @@ TEST (ledger, block_destination_source) ASSERT_TRUE (ledger.block_source (transaction, block1).is_zero ()); ASSERT_EQ (nano::dev::genesis->account (), ledger.block_destination (transaction, block2)); ASSERT_TRUE (ledger.block_source (transaction, block2).is_zero ()); - ASSERT_TRUE (ledger.block_destination (transaction, block3).is_zero ()); + ASSERT_TRUE (ledger.block_destination (transaction, block3) == nullptr); ASSERT_EQ (block2.hash (), ledger.block_source (transaction, block3)); ASSERT_EQ (dest.pub, ledger.block_destination (transaction, block4)); ASSERT_TRUE (ledger.block_source (transaction, block4).is_zero ()); ASSERT_EQ (nano::dev::genesis->account (), ledger.block_destination (transaction, block5)); ASSERT_TRUE (ledger.block_source (transaction, block5).is_zero ()); - ASSERT_TRUE (ledger.block_destination (transaction, block6).is_zero ()); + ASSERT_TRUE (ledger.block_destination (transaction, block6) == nullptr); ASSERT_EQ (block5.hash (), ledger.block_source (transaction, block6)); } @@ -2411,7 +2411,7 @@ TEST (ledger, epoch_blocks_fork) store->initialize (transaction, ledger.cache); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair destination; - nano::send_block send1 (nano::dev::genesis->hash (), nano::account (0), nano::dev::constants.genesis_amount, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); + nano::send_block send1 (nano::dev::genesis->hash (), nano::account{ static_cast (0) }, nano::dev::constants.genesis_amount, 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, send1).code); nano::state_block epoch1 (nano::dev::genesis->account (), nano::dev::genesis->hash (), nano::dev::genesis->account (), nano::dev::constants.genesis_amount, ledger.epoch_link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); ASSERT_EQ (nano::process_result::fork, ledger.process (transaction, epoch1).code); diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 5d6040f300..ddf2a9114d 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -797,8 +797,8 @@ TEST (tcp_listener, tcp_node_id_handshake) ASSERT_TIMELY (5s, write_done); - boost::optional> response_zero (std::make_pair (nano::account (0), nano::signature (0))); - nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; + boost::optional> response_zero (std::make_pair (nano::account{ static_cast (0) }, nano::signature (0))); + nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; auto output (node_id_handshake_response.to_bytes ()); std::atomic done (false); socket->async_read (output, output->size (), [&output, &done] (boost::system::error_code const & ec, size_t size_a) { diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index fd129c8904..2030c26667 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -106,7 +106,7 @@ TEST (system, DISABLED_generate_send_new) // This indirectly waits for online weight to stabilize, required to prevent intermittent failures ASSERT_TIMELY (5s, node1.wallets.reps ().voting > 0); system.generate_send_new (node1, accounts); - nano::account new_account (0); + nano::account new_account{ static_cast (0) }; { auto transaction (node1.wallets.tx_begin_read ()); auto iterator2 (system.wallet (0)->store.begin (transaction)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 295e02624b..1b46a9bdf5 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -335,7 +335,7 @@ TEST (wallet, rekey) TEST (account, encode_zero) { - nano::account number0 (0); + nano::account number0{ static_cast (0) }; std::string str0; number0.encode_account (str0); @@ -367,7 +367,7 @@ TEST (account, encode_all) TEST (account, encode_fail) { - nano::account number0 (0); + nano::account number0{ static_cast (0) }; std::string str0; number0.encode_account (str0); str0[16] ^= 1; diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 8b6d319c6b..38464e987f 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -151,8 +152,10 @@ bool nano::block::has_sideband () const nano::account const & nano::block::representative () const { - static nano::account rep{ 0 }; - return rep; + /* return nano::hardened_constants::get ().not_an_account; */ + + static nano::account representative{ static_cast (0) }; + return representative; } nano::block_hash const & nano::block::source () const @@ -163,7 +166,9 @@ nano::block_hash const & nano::block::source () const nano::account const & nano::block::destination () const { - static nano::account destination{ 0 }; + /* return nano::hardened_constants::get ().not_an_account; */ + + static nano::account destination{ static_cast (0) }; return destination; } @@ -175,7 +180,9 @@ nano::link const & nano::block::link () const nano::account const & nano::block::account () const { - static nano::account account{ 0 }; + /* return nano::hardened_constants::get ().not_an_account; */ + + static nano::account account{ static_cast (0) }; return account; } @@ -363,6 +370,8 @@ nano::send_block::send_block (nano::block_hash const & previous_a, nano::account signature (nano::sign_message (prv_a, pub_a, hash ())), work (work_a) { + debug_assert (destination_a != nullptr); + debug_assert (pub_a != nullptr); } nano::send_block::send_block (bool & error_a, nano::stream & stream_a) : @@ -524,13 +533,18 @@ nano::open_block::open_block (nano::block_hash const & source_a, nano::account c signature (nano::sign_message (prv_a, pub_a, hash ())), work (work_a) { - debug_assert (!representative_a.is_zero ()); + debug_assert (representative_a != nullptr); + debug_assert (account_a != nullptr); + debug_assert (pub_a != nullptr); } nano::open_block::open_block (nano::block_hash const & source_a, nano::account const & representative_a, nano::account const & account_a, std::nullptr_t) : hashables (source_a, representative_a, account_a), work (0) { + debug_assert (representative_a != nullptr); + debug_assert (account_a != nullptr); + signature.clear (); } @@ -787,6 +801,8 @@ nano::change_block::change_block (nano::block_hash const & previous_a, nano::acc signature (nano::sign_message (prv_a, pub_a, hash ())), work (work_a) { + debug_assert (representative_a != nullptr); + debug_assert (pub_a != nullptr); } nano::change_block::change_block (bool & error_a, nano::stream & stream_a) : @@ -1060,6 +1076,10 @@ nano::state_block::state_block (nano::account const & account_a, nano::block_has signature (nano::sign_message (prv_a, pub_a, hash ())), work (work_a) { + debug_assert (account_a != nullptr); + debug_assert (representative_a != nullptr); + debug_assert (link_a.as_account () != nullptr); + debug_assert (pub_a != nullptr); } nano::state_block::state_block (bool & error_a, nano::stream & stream_a) : @@ -1505,6 +1525,7 @@ nano::receive_block::receive_block (nano::block_hash const & previous_a, nano::b signature (nano::sign_message (prv_a, pub_a, hash ())), work (work_a) { + debug_assert (pub_a != nullptr); } nano::receive_block::receive_block (bool & error_a, nano::stream & stream_a) : diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index b3412f479d..336f158335 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -64,7 +64,7 @@ class block_sideband final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 2798cc96be..ffa3f0abd9 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,11 @@ std::string nano::public_key::to_account () const return result; } +nano::public_key::public_key (std::nullptr_t) : + uint256_union{ nano::hardened_constants::get ().not_an_account } +{ +} + std::string nano::public_key::to_node_id () const { return to_account ().replace (0, 4, "node"); @@ -939,6 +945,22 @@ nano::public_key::operator nano::hash_or_account const & () const return reinterpret_cast (*this); } +nano::public_key & nano::public_key::operator= (std::nullptr_t) +{ + bytes = nano::hardened_constants::get ().not_an_account.bytes; + return *this; +} + +bool nano::public_key::operator== (std::nullptr_t) const +{ + return bytes == nano::hardened_constants::get ().not_an_account.bytes; +} + +bool nano::public_key::operator!= (std::nullptr_t) const +{ + return !(*this == nullptr); +} + nano::block_hash::operator nano::link const & () const { return reinterpret_cast (*this); diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 3e2e64eb0c..211f21d8c6 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -115,6 +115,9 @@ class public_key final : public uint256_union public: using uint256_union::uint256_union; + public_key () = default; + explicit public_key (std::nullptr_t); + std::string to_node_id () const; bool decode_node_id (std::string const & source_a); void encode_account (std::string &) const; @@ -124,6 +127,11 @@ class public_key final : public uint256_union operator nano::link const & () const; operator nano::root const & () const; operator nano::hash_or_account const & () const; + public_key & operator= (std::nullptr_t); + bool operator== (std::nullptr_t) const; + bool operator!= (std::nullptr_t) const; + using uint256_union::operator== ; + using uint256_union::operator!= ; }; class wallet_id : public uint256_union diff --git a/nano/lib/walletconfig.hpp b/nano/lib/walletconfig.hpp index 68f9fcc1df..361c79042c 100644 --- a/nano/lib/walletconfig.hpp +++ b/nano/lib/walletconfig.hpp @@ -19,6 +19,6 @@ class wallet_config final nano::error serialize_toml (nano::tomlconfig & toml_a) const; nano::error deserialize_toml (nano::tomlconfig & toml_a); nano::wallet_id wallet; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; }; } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 143667299f..1c6eae8b33 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1459,7 +1459,7 @@ int main (int argc, char * const * argv) } } uint64_t previous_timestamp (0); - nano::account calculated_representative (0); + nano::account calculated_representative{ static_cast (0) }; while (!hash.is_zero () && block != nullptr) { ++block_count; @@ -1704,7 +1704,7 @@ int main (int argc, char * const * argv) else { // Check if pending destination is correct - nano::account destination (0); + nano::account destination{ static_cast (0) }; bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index a2e83e36f6..d83e984f1b 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -180,13 +180,13 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr (0) }; nano::uint128_t amount (0); bool is_state_send (false); - bool is_state_epoch (false); - nano::account pending_account (0); - node.process_confirmed_data (transaction, block_a, block_a->hash (), account, amount, is_state_send, is_state_epoch, pending_account); - node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); + bool is_state_epoch (false); + nano::account pending_account{ static_cast (0) }; + node.process_confirmed_data (transaction, block_a, block_a->hash (), account, amount, is_state_send, is_state_epoch, pending_account); + node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); } else { @@ -206,12 +206,12 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptrlink ().is_zero () ? block_a->destination () : block_a->link ().as_account ()); node.receive_confirmed (transaction, hash, destination); - nano::account account (0); + nano::account account{ static_cast (0) }; nano::uint128_t amount (0); bool is_state_send (false); - bool is_state_epoch (false); - nano::account pending_account (0); - node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); + bool is_state_epoch (false); + nano::account pending_account{ static_cast (0) }; + node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); election_lk.lock (); election->status.type = *election_status_type; election->status.confirmation_request_count = election->confirmation_request_count; diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index e4432b3afa..dedfbfa29e 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -279,7 +279,7 @@ class active_transactions final void confirm_expired_frontiers_pessimistically (nano::transaction const &, uint64_t, uint64_t &); void frontiers_confirmation (nano::unique_lock &); bool insert_election_from_frontiers_confirmation (std::shared_ptr const &, nano::account const &, nano::uint128_t, nano::election_behavior); - nano::account next_frontier_account{ 0 }; + nano::account next_frontier_account{ static_cast (0) }; std::chrono::steady_clock::time_point next_frontier_check{ std::chrono::steady_clock::now () }; constexpr static size_t max_active_elections_frontier_insertion{ 1000 }; prioritize_num_uncemented priority_wallet_cementable_frontiers; diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 4d70bab086..8a2046349b 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -82,7 +82,7 @@ class bootstrap_initiator final explicit bootstrap_initiator (nano::node &); ~bootstrap_initiator (); void bootstrap (nano::endpoint const &, bool add_to_peers = true, std::string id_a = ""); - void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account (0)); + void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account (static_cast (0))); bool bootstrap_lazy (nano::hash_or_account const &, bool force = false, bool confirmed = true, std::string id_a = ""); void bootstrap_wallet (std::deque &); void run_bootstrap (); diff --git a/nano/node/bootstrap/bootstrap_attempt.cpp b/nano/node/bootstrap/bootstrap_attempt.cpp index eac672c1d3..801c7f0a8e 100644 --- a/nano/node/bootstrap/bootstrap_attempt.cpp +++ b/nano/node/bootstrap/bootstrap_attempt.cpp @@ -23,9 +23,9 @@ nano::bootstrap_attempt::bootstrap_attempt (std::shared_ptr const & { if (id.empty ()) { - nano::random_constants constants; - id = constants.random_128.to_string (); + id = nano::hardened_constants::get ().random_128.to_string (); } + node->logger.always_log (boost::str (boost::format ("Starting %1% bootstrap attempt with ID %2%") % mode_text () % id)); node->bootstrap_initiator.notify_listeners (true); if (node->websocket_server) diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 9f6178d3f7..fa5f039995 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -21,7 +21,7 @@ nano::pull_info::pull_info (nano::hash_or_account const & account_or_head_a, nan nano::bulk_pull_client::bulk_pull_client (std::shared_ptr const & connection_a, std::shared_ptr const & attempt_a, nano::pull_info const & pull_a) : connection (connection_a), attempt (attempt_a), - known_account (0), + known_account{ static_cast (0) }, pull (pull_a), pull_blocks (0), unexpected_count (0) diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index c15d791348..0c5b5ae391 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -224,11 +224,11 @@ void nano::frontier_req_client::next () nano::account const & account (i->first); accounts.emplace_back (account, info.head); } - /* If loop breaks before max_size, then accounts_end () is reached - Add empty record */ + + /* If loop breaks before max_size, then accounts_end () is reached. Add empty record */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account (0), nano::block_hash (0)); + accounts.emplace_back (nano::account{ static_cast (0) }, nano::block_hash (0)); } } // Retrieving accounts from deque @@ -360,11 +360,11 @@ void nano::frontier_req_server::next () } } } - /* If loop breaks before max_size, then accounts_end () is reached - Add empty record to finish frontier_req_server */ + + /* If loop breaks before max_size, then accounts_end () is reached. Add empty record to finish frontier_req_server */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account (0), nano::block_hash (0)); + accounts.emplace_back (nano::account{ static_cast (0) }, nano::block_hash (0)); } } // Retrieving accounts from deque diff --git a/nano/node/bootstrap/bootstrap_legacy.hpp b/nano/node/bootstrap/bootstrap_legacy.hpp index 0abe0f901c..6f83aede49 100644 --- a/nano/node/bootstrap/bootstrap_legacy.hpp +++ b/nano/node/bootstrap/bootstrap_legacy.hpp @@ -33,7 +33,7 @@ class bootstrap_attempt_legacy : public bootstrap_attempt std::weak_ptr push; std::deque frontier_pulls; std::vector> bulk_push_targets; - nano::account start_account{ 0 }; + nano::account start_account{ static_cast (0) }; std::atomic account_count{ 0 }; uint32_t frontiers_age; }; diff --git a/nano/node/bootstrap/bootstrap_server.hpp b/nano/node/bootstrap/bootstrap_server.hpp index 1b6b4a3e2f..17c230ff05 100644 --- a/nano/node/bootstrap/bootstrap_server.hpp +++ b/nano/node/bootstrap/bootstrap_server.hpp @@ -66,7 +66,7 @@ class bootstrap_server final : public std::enable_shared_from_this stopped{ false }; // Remote enpoint used to remove response channel even after socket closing nano::tcp_endpoint remote_endpoint{ boost::asio::ip::address_v6::any (), 0 }; - nano::account remote_node_id{ 0 }; + nano::account remote_node_id{ static_cast (0) }; std::chrono::steady_clock::time_point last_telemetry_req{ std::chrono::steady_clock::time_point () }; }; } diff --git a/nano/node/common.cpp b/nano/node/common.cpp index 11358d1bfd..4dda2bed4d 100644 --- a/nano/node/common.cpp +++ b/nano/node/common.cpp @@ -23,14 +23,13 @@ std::chrono::seconds constexpr nano::telemetry_cache_cutoffs::live; uint64_t nano::ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint16_t port) { - static nano::random_constants constants; debug_assert (ip_a.is_v6 ()); uint64_t result; nano::uint128_union address; address.bytes = ip_a.to_v6 ().to_bytes (); blake2b_state state; blake2b_init (&state, sizeof (result)); - blake2b_update (&state, constants.random_128.bytes.data (), constants.random_128.bytes.size ()); + blake2b_update (&state, nano::hardened_constants::get ().random_128.bytes.data (), nano::hardened_constants::get ().random_128.bytes.size ()); if (port != 0) { blake2b_update (&state, &port, sizeof (port)); diff --git a/nano/node/common.hpp b/nano/node/common.hpp index d3b5627e92..cf97a635b5 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -354,7 +354,7 @@ class telemetry_data { public: nano::signature signature{ 0 }; - nano::account node_id{ 0 }; + nano::account node_id{ static_cast (0) }; uint64_t block_count{ 0 }; uint64_t cemented_count{ 0 }; uint64_t unchecked_count{ 0 }; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index e730f15796..dd4069b5bb 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -28,7 +28,7 @@ nano::election::election (nano::node & node_a, std::shared_ptr cons root (block_a->root ()), qualified_root (block_a->qualified_root ()) { - last_votes.emplace (node.network_params.random.not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }); + last_votes.emplace (nano::hardened_constants::get ().not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }); last_blocks.emplace (block_a->hash (), block_a); if (node.config.enable_voting && node.wallets.reps ().voting > 0) { @@ -319,7 +319,7 @@ void nano::election::log_votes (nano::tally_t const & tally_a, std::string const } for (auto i (last_votes.begin ()), n (last_votes.end ()); i != n; ++i) { - if (i->first != node.network_params.random.not_an_account) + if (i->first != nano::hardened_constants::get ().not_an_account) { tally << boost::str (boost::format ("%1%%2% %3% %4%") % line_end % i->first.to_account () % std::to_string (i->second.timestamp) % i->second.hash.to_string ()); } @@ -629,7 +629,7 @@ std::vector nano::election::votes_with_weight () co auto votes_l (votes ()); for (auto const & vote_l : votes_l) { - if (vote_l.first != node.network_params.random.not_an_account) + if (vote_l.first != nano::hardened_constants::get ().not_an_account) { auto amount (node.ledger.cache.rep_weights.representation_get (vote_l.first)); nano::vote_with_weight_info vote_info{ vote_l.first, vote_l.second.time, vote_l.second.timestamp, vote_l.second.hash, amount }; diff --git a/nano/node/ipc/action_handler.cpp b/nano/node/ipc/action_handler.cpp index 76086e737c..c9a020c007 100644 --- a/nano/node/ipc/action_handler.cpp +++ b/nano/node/ipc/action_handler.cpp @@ -11,11 +11,12 @@ namespace { nano::account parse_account (std::string const & account, bool & out_is_deprecated_format) { - nano::account result (0); + nano::account result{ static_cast (0) }; if (account.empty ()) { throw nano::error (nano::error_common::bad_account_number); } + if (result.decode_account (account)) { throw nano::error (nano::error_common::bad_account_number); diff --git a/nano/node/ipc/ipc_broker.cpp b/nano/node/ipc/ipc_broker.cpp index 77712bfc0a..5b935b378c 100644 --- a/nano/node/ipc/ipc_broker.cpp +++ b/nano/node/ipc/ipc_broker.cpp @@ -144,7 +144,8 @@ void nano::ipc::broker::broadcast (std::shared_ptr if (itr->topic->options->all_local_accounts) { auto transaction_l (this->node.wallets.tx_begin_read ()); - nano::account source_l (0), destination_l (0); + nano::account source_l{ static_cast (0) }; + nano::account destination_l{ static_cast (0) }; auto decode_source_ok_l (!source_l.decode_account (state->account)); auto decode_destination_ok_l (!destination_l.decode_account (state->link_as_account)); (void)decode_source_ok_l; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 2e2e03cdcf..eecece84d0 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -235,7 +235,7 @@ bool nano::json_handler::wallet_account_impl (nano::transaction const & transact nano::account nano::json_handler::account_impl (std::string account_text, std::error_code ec_a) { - nano::account result (0); + nano::account result{ static_cast (0) }; if (!ec) { if (account_text.empty ()) @@ -671,7 +671,7 @@ void nano::json_handler::account_info () response_l.put ("representative", info.representative.to_account ()); if (include_confirmed) { - nano::account confirmed_representative{ 0 }; + nano::account confirmed_representative{ static_cast (0) }; if (confirmed_frontier_block) { confirmed_representative = confirmed_frontier_block->representative (); @@ -1053,7 +1053,7 @@ void nano::json_handler::available_supply () auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ())); // Cold storage genesis auto landing_balance (node.balance (nano::account ("059F68AAB29DE0D3A27443625C7EA9CDDB6517A8B76FE37727EF6A4D76832AD5"))); // Active unavailable account auto faucet_balance (node.balance (nano::account ("8E319CE6F3025E5B2DF66DA7AB1467FE48F1679C13DD43BFDB29FA2E9FC40D3B"))); // Faucet account - auto burned_balance ((node.balance_pending (nano::account (0), false)).second); // Burning 0 account + auto burned_balance ((node.balance_pending (nano::account{ static_cast (0) }, false)).second); // Burning 0 account auto available (nano::dev::constants.genesis_amount - genesis_balance - landing_balance - faucet_balance - burned_balance); response_l.put ("available", available.convert_to ()); response_errors (); @@ -1360,19 +1360,19 @@ void nano::json_handler::block_create () ec = nano::error_common::bad_wallet_number; } } - nano::account account (0); + nano::account account (static_cast (0)); boost::optional account_text (request.get_optional ("account")); if (!ec && account_text.is_initialized ()) { account = account_impl (account_text.get ()); } - nano::account representative (0); + nano::account representative (static_cast (0)); boost::optional representative_text (request.get_optional ("representative")); if (!ec && representative_text.is_initialized ()) { representative = account_impl (representative_text.get (), nano::error_rpc::bad_representative_number); } - nano::account destination (0); + nano::account destination (static_cast (0)); boost::optional destination_text (request.get_optional ("destination")); if (!ec && destination_text.is_initialized ()) { @@ -1739,7 +1739,7 @@ void nano::json_handler::bootstrap_any () const bool force = request.get ("force", false); if (!node.flags.disable_legacy_bootstrap) { - nano::account start_account (0); + nano::account start_account (static_cast (0)); boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { @@ -2095,7 +2095,7 @@ void nano::json_handler::delegators () auto threshold (threshold_optional_impl ()); auto start_account_text (request.get_optional ("start")); - nano::account start_account (0); + nano::account start_account (static_cast (0)); if (!ec && start_account_text.is_initialized ()) { start_account = account_impl (start_account_text.get ()); @@ -2622,7 +2622,7 @@ void nano::json_handler::ledger () auto threshold (threshold_optional_impl ()); if (!ec) { - nano::account start (0); + nano::account start (static_cast (0)); boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { diff --git a/nano/node/node.cpp b/nano/node/node.cpp index aeefd89ee9..cb830f0de5 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1496,7 +1496,7 @@ void nano::node::epoch_upgrader_impl (nano::raw_key const & prv_a, nano::epoch e class account_upgrade_item final { public: - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; uint64_t modified{ 0 }; }; class account_tag diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 2d26bb83ba..c26b46a1a6 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -248,7 +248,7 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) { preconfigured_representatives.clear (); toml.array_entries_required ("preconfigured_representatives", [this, &toml] (std::string entry) { - nano::account representative (0); + nano::account representative{ static_cast (0) }; if (representative.decode_account (entry)) { toml.get_error ().set ("Invalid representative account: " + entry); @@ -583,7 +583,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco auto preconfigured_representatives_l (json.get_required_child ("preconfigured_representatives")); preconfigured_representatives.clear (); preconfigured_representatives_l.array_entries ([this, &json] (std::string entry) { - nano::account representative (0); + nano::account representative{ static_cast (0) }; if (representative.decode_account (entry)) { json.get_error ().set ("Invalid representative account: " + entry); diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index cfe7fb9821..40ee23b29a 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -41,7 +41,7 @@ class representative { return account == other_a.account; } - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::amount weight{ 0 }; std::shared_ptr channel; std::chrono::steady_clock::time_point last_request{ std::chrono::steady_clock::time_point () }; diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 2c4f36f773..0436600a03 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -238,7 +238,7 @@ void nano::fan::value_set (nano::raw_key const & value_a) } // Wallet version number -nano::account const nano::wallet_store::version_special (0); +nano::account const nano::wallet_store::version_special (static_cast (0)); // Random number used to salt private key encryption nano::account const nano::wallet_store::salt_special (1); // Key used to encrypt wallet keys, encrypted itself by the user password @@ -714,7 +714,7 @@ bool nano::wallet::enter_password (nano::transaction const & transaction_a, std: nano::public_key nano::wallet::deterministic_insert (nano::transaction const & transaction_a, bool generate_work_a) { - nano::public_key key (0); + nano::public_key key{ static_cast (0) }; if (store.valid_password (transaction_a)) { key = store.deterministic_insert (transaction_a); @@ -735,7 +735,7 @@ nano::public_key nano::wallet::deterministic_insert (nano::transaction const & t nano::public_key nano::wallet::deterministic_insert (uint32_t const index, bool generate_work_a) { auto transaction (wallets.tx_begin_write ()); - nano::public_key key (0); + nano::public_key key{ static_cast (0) }; if (store.valid_password (transaction)) { key = store.deterministic_insert (transaction, index); @@ -756,7 +756,7 @@ nano::public_key nano::wallet::deterministic_insert (bool generate_work_a) nano::public_key nano::wallet::insert_adhoc (nano::raw_key const & key_a, bool generate_work_a) { - nano::public_key key (0); + nano::public_key key{ static_cast (0) }; auto transaction (wallets.tx_begin_write ()); if (store.valid_password (transaction)) { diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 9f25f94432..51df45202c 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -68,7 +68,7 @@ nano::websocket::confirmation_options::confirmation_options (boost::property_tre has_account_filtering_options = true; for (auto account_l : *accounts_l) { - nano::account result_l (0); + nano::account result_l{ static_cast (0) }; if (!result_l.decode_account (account_l.second.data ())) { // Do not insert the given raw data to keep old prefix support @@ -114,7 +114,8 @@ bool nano::websocket::confirmation_options::should_filter (nano::websocket::mess if (all_local_accounts) { auto transaction_l (wallets.tx_begin_read ()); - nano::account source_l (0), destination_l (0); + nano::account source_l{ static_cast (0) }; + nano::account destination_l{ static_cast (0) }; auto decode_source_ok_l (!source_l.decode_account (source_text_l)); auto decode_destination_ok_l (!destination_l.decode_account (destination_opt_l.get ())); (void)decode_source_ok_l; @@ -140,7 +141,7 @@ bool nano::websocket::confirmation_options::update (boost::property_tree::ptree this->has_account_filtering_options = true; for (auto const & account_l : accounts_text_a) { - nano::account result_l (0); + nano::account result_l{ static_cast (0) }; if (!result_l.decode_account (account_l.second.data ())) { // Re-encode to keep old prefix support @@ -197,7 +198,7 @@ nano::websocket::vote_options::vote_options (boost::property_tree::ptree const & { for (auto representative_l : *representatives_l) { - nano::account result_l (0); + nano::account result_l{ static_cast (0) }; if (!result_l.decode_account (representative_l.second.data ())) { // Do not insert the given raw data to keep old prefix support diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 536dcfc9b8..56696111c7 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -494,7 +494,7 @@ TEST (rpc, send_idempotent) request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); - request.put ("destination", nano::account (0).to_account ()); + request.put ("destination", nano::account{ static_cast (0) }.to_account ()); request.put ("amount", (nano::dev::constants.genesis_amount - (nano::dev::constants.genesis_amount / 4)).convert_to ()); request.put ("id", "123abc"); auto response (wait_response (system, rpc, request)); @@ -710,7 +710,7 @@ TEST (rpc, wallet_representative_set_force) auto transaction (node->wallets.tx_begin_read ()); ASSERT_EQ (key.pub, node->wallets.items.begin ()->second->store.representative (transaction)); } - nano::account representative (0); + nano::account representative{ static_cast (0) }; while (representative != key.pub) { auto transaction (node->store.tx_begin_read ()); @@ -1007,7 +1007,7 @@ TEST (rpc, frontier) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account (0).to_account ()); + request.put ("account", nano::account{ static_cast (0) }.to_account ()); request.put ("count", std::to_string (std::numeric_limits::max ())); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); @@ -1045,7 +1045,7 @@ TEST (rpc, frontier_limited) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account (0).to_account ()); + request.put ("account", nano::account{ static_cast (0) }.to_account ()); request.put ("count", std::to_string (100)); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); @@ -1859,16 +1859,15 @@ TEST (rpc, pending_burn) { nano::system system; auto node = add_ipc_enabled_node (system); - nano::account burn (0); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); - auto block1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, burn, 100)); + auto block1 (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::dev::constants.burn_account, 100)); auto [rpc, rpc_ctx] = add_rpc (system, node); node->scheduler.flush (); ASSERT_TIMELY (5s, !node->active.active (*block1)); ASSERT_TIMELY (5s, node->ledger.cache.cemented_count == 2 && node->confirmation_height_processor.current ().is_zero () && node->confirmation_height_processor.awaiting_processing_size () == 0); boost::property_tree::ptree request; request.put ("action", "pending"); - request.put ("account", burn.to_account ()); + request.put ("account", nano::dev::constants.burn_account.to_account ()); request.put ("count", "100"); { auto response (wait_response (system, rpc, request)); diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index b4391594bf..9b08b2d0d2 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -38,7 +38,7 @@ char const * dev_genesis_data = R"%%%({ "account": "xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", "work": "7b42a00ee91d5810", "signature": "ECDA914373A2F0CA1296475BAEE40500A7F0A7AD72A5A80C81D7FAB7F6C802B2CC7DB50F5DD0FB25B2EF11761FA7344A158DD5A700B21BD47DE5BD0F63153A02" - })%%%"; + })%%%"; char const * beta_genesis_data = R"%%%({ "type": "open", @@ -47,7 +47,7 @@ char const * beta_genesis_data = R"%%%({ "account": "nano_1betagoxpxwykx4kw86dnhosc8t3s7ix8eeentwkcg1hbpez1outjrcyg4n1", "work": "79d4e27dc873c6f2", "signature": "4BD7F96F9ED2721BCEE5EAED400EA50AD00524C629AE55E9AFF11220D2C1B00C3D4B3BB770BF67D4F8658023B677F91110193B6C101C2666931F57046A6DB806" - })%%%"; + })%%%"; char const * live_genesis_data = R"%%%({ "type": "open", @@ -56,7 +56,7 @@ char const * live_genesis_data = R"%%%({ "account": "xrb_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3", "work": "62f05417dd3fb691", "signature": "9F0C933C8ADE004D808EA1985FA746A7E95BA2A38F867640F53EC8F180BDFE9E2C1268DEAD7C2664F356E37ABA362BC58E46DBA03E523A7B5A19E4B6EB12BB02" - })%%%"; + })%%%"; std::string const test_genesis_data = nano::get_env_or_default ("NANO_TEST_GENESIS_BLOCK", R"%%%({ "type": "open", @@ -65,7 +65,7 @@ std::string const test_genesis_data = nano::get_env_or_default ("NANO_TEST_GENES "account": "nano_1jg8zygjg3pp5w644emqcbmjqpnzmubfni3kfe1s8pooeuxsw49fdq1mco9j", "work": "bc1ef279c1a34eb1", "signature": "15049467CAEE3EC768639E8E35792399B6078DA763DA4EBA8ECAD33B0EDC4AF2E7403893A5A602EB89B978DABEF1D6606BB00F3C0EE11449232B143B6E07170E" - })%%%"); + })%%%"); std::shared_ptr parse_block_from_genesis_data (std::string const & genesis_data_a) { @@ -115,7 +115,7 @@ nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::ne : network_a == nano::networks::nano_test_network ? nano_test_genesis : nano_live_genesis), genesis_amount{ std::numeric_limits::max () }, - burn_account (0), + burn_account{ static_cast (0) }, nano_dev_final_votes_canary_account (dev_public_key_data), nano_beta_final_votes_canary_account (beta_canary_public_key_data), nano_live_final_votes_canary_account (live_canary_public_key_data), @@ -153,7 +153,15 @@ nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::ne epochs.add (nano::epoch::epoch_2, epoch_v2_signer, epoch_link_v2); } -nano::random_constants::random_constants () +nano::hardened_constants & nano::hardened_constants::get () +{ + static hardened_constants instance{}; + return instance; +} + +nano::hardened_constants::hardened_constants () : + not_an_account{}, + random_128{} { nano::random_pool::generate_block (not_an_account.bytes.data (), not_an_account.bytes.size ()); nano::random_pool::generate_block (random_128.bytes.data (), random_128.bytes.size ()); diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 10c678c9d9..ec0b39b5da 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -72,9 +72,9 @@ struct hash<::nano::root> namespace nano { /** - * A key pair. The private key is generated from the random pool, or passed in - * as a hex string. The public key is derived using ed25519. - */ + * A key pair. The private key is generated from the random pool, or passed in + * as a hex string. The public key is derived using ed25519. + */ class keypair { public: @@ -86,8 +86,8 @@ class keypair }; /** - * Latest information about an account - */ + * Latest information about an account + */ class account_info final { public: @@ -99,7 +99,7 @@ class account_info final size_t db_size () const; nano::epoch epoch () const; nano::block_hash head{ 0 }; - nano::account representative{ 0 }; + nano::account representative{ static_cast (0) }; nano::block_hash open_block{ 0 }; nano::amount balance{ 0 }; /** Seconds since posix epoch */ @@ -109,8 +109,8 @@ class account_info final }; /** - * Information on an uncollected send - */ + * Information on an uncollected send + */ class pending_info final { public: @@ -119,7 +119,7 @@ class pending_info final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info const &) const; - nano::account source{ 0 }; + nano::account source{ static_cast (0) }; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -131,7 +131,7 @@ class pending_key final bool deserialize (nano::stream &); bool operator== (nano::pending_key const &) const; nano::account const & key () const; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::block_hash hash{ 0 }; }; @@ -141,19 +141,19 @@ class endpoint_key final endpoint_key () = default; /* - * @param address_a This should be in network byte order - * @param port_a This should be in host byte order - */ + * @param address_a This should be in network byte order + * @param port_a This should be in host byte order + */ endpoint_key (const std::array & address_a, uint16_t port_a); /* - * @return The ipv6 address in network byte order - */ + * @return The ipv6 address in network byte order + */ const std::array & address_bytes () const; /* - * @return The port in host byte order - */ + * @return The port in host byte order + */ uint16_t port () const; private: @@ -181,8 +181,8 @@ class unchecked_key final }; /** - * Tag for block signature verification result - */ + * Tag for block signature verification result + */ enum class signature_verification : uint8_t { unknown = 0, @@ -192,8 +192,8 @@ enum class signature_verification : uint8_t }; /** - * Information on an unchecked block - */ + * Information on an unchecked block + */ class unchecked_info final { public: @@ -202,7 +202,7 @@ class unchecked_info final void serialize (nano::stream &) const; bool deserialize (nano::stream &); std::shared_ptr block; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; /** Seconds since posix epoch */ uint64_t modified{ 0 }; nano::signature_verification verified{ nano::signature_verification::unknown }; @@ -214,7 +214,7 @@ class block_info final public: block_info () = default; block_info (nano::account const &, nano::amount const &); - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::amount balance{ 0 }; }; @@ -275,8 +275,8 @@ class vote final static const std::string hash_prefix; }; /** - * This class serves to find and return unique variants of a vote in order to minimize memory usage - */ + * This class serves to find and return unique variants of a vote in order to minimize memory usage + */ class vote_uniquer final { public: @@ -374,13 +374,17 @@ namespace dev extern std::shared_ptr & genesis; } -/** Constants which depend on random values (this class should never be used globally due to CryptoPP globals potentially not being initialized) */ -class random_constants +/** Constants which depend on random values (always used as singleton) */ +class hardened_constants { public: - random_constants (); + static hardened_constants & get (); + nano::account not_an_account; nano::uint128_union random_128; + +private: + hardened_constants (); }; /** Node related constants whose value depends on the active network */ @@ -439,14 +443,13 @@ class network_params network_params (nano::networks network_a); unsigned kdf_work; - nano::work_thresholds work; - nano::network_constants network; - nano::ledger_constants ledger; - nano::random_constants random; - nano::voting_constants voting; - nano::node_constants node; - nano::portmapping_constants portmapping; - nano::bootstrap_constants bootstrap; + nano::work_thresholds work; + nano::network_constants network; + nano::ledger_constants ledger; + nano::voting_constants voting; + nano::node_constants node; + nano::portmapping_constants portmapping; + nano::bootstrap_constants bootstrap; }; enum class confirmation_height_mode @@ -457,7 +460,7 @@ enum class confirmation_height_mode }; /* Holds flags for various cacheable data. For most CLI operations caching is unnecessary - * (e.g getting the cemented block count) so it can be disabled for performance reasons. */ + * (e.g getting the cemented block count) so it can be disabled for performance reasons. */ class generate_cache { public: diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index eb97206d79..d7423125b4 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -116,7 +116,7 @@ class rollback_visitor : public nano::block_visitor } auto balance (ledger.balance (transaction, block_a.hashables.previous)); auto is_send (block_a.hashables.balance < balance); - nano::account representative{ 0 }; + nano::account representative{ static_cast (0) }; if (!rep_block_hash.is_zero ()) { // Move existing representation & add in amount delta @@ -958,8 +958,8 @@ nano::account const & nano::ledger::block_destination (nano::transaction const & { return state_block->hashables.link.as_account (); } - static nano::account result (0); - return result; + + return nano::hardened_constants::get ().not_an_account; } nano::block_hash nano::ledger::block_source (nano::transaction const & transaction_a, nano::block const & block_a) @@ -1533,7 +1533,7 @@ bool nano::ledger::migrate_lmdb_to_rocksdb (boost::filesystem::path const & data error |= rocksdb_store->account.get (rocksdb_transaction, account, account_info); // If confirmation height exists in the lmdb ledger for this account it should exist in the rocksdb ledger - nano::confirmation_height_info confirmation_height_info; + nano::confirmation_height_info confirmation_height_info{}; if (!store.confirmation_height.get (lmdb_transaction, account, confirmation_height_info)) { error |= rocksdb_store->confirmation_height.get (rocksdb_transaction, account, confirmation_height_info); diff --git a/nano/secure/store/frontier_store_partial.hpp b/nano/secure/store/frontier_store_partial.hpp index 9bec58444c..671f2255d5 100644 --- a/nano/secure/store/frontier_store_partial.hpp +++ b/nano/secure/store/frontier_store_partial.hpp @@ -40,7 +40,7 @@ class frontier_store_partial : public frontier_store nano::db_val value; auto status (store.get (transaction_a, tables::frontiers, nano::db_val (block_a), value)); release_assert (store.success (status) || store.not_found (status)); - nano::account result (0); + nano::account result{ static_cast (0) }; if (store.success (status)) { result = static_cast (value); diff --git a/nano/secure/versioning.hpp b/nano/secure/versioning.hpp index 953ab410b9..e9b113eb2a 100644 --- a/nano/secure/versioning.hpp +++ b/nano/secure/versioning.hpp @@ -15,7 +15,7 @@ class pending_info_v14 final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info_v14 const &) const; - nano::account source{ 0 }; + nano::account source{ static_cast (0) }; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -44,7 +44,7 @@ class block_sideband_v14 final static size_t size (nano::block_type); nano::block_type type{ nano::block_type::invalid }; nano::block_hash successor{ 0 }; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; @@ -65,7 +65,7 @@ class block_sideband_v18 final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ 0 }; + nano::account account{ static_cast (0) }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; From fa3bcaa54c94c20658622279c937f7055c80340f Mon Sep 17 00:00:00 2001 From: theohax Date: Wed, 22 Sep 2021 01:20:17 +0300 Subject: [PATCH 02/10] Fix formatting --- nano/core_test/network.cpp | 4 ++-- nano/lib/numbers.hpp | 4 ++-- nano/node/active_transactions.cpp | 14 +++++++------- nano/secure/common.hpp | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index ddf2a9114d..59544201c4 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -797,8 +797,8 @@ TEST (tcp_listener, tcp_node_id_handshake) ASSERT_TIMELY (5s, write_done); - boost::optional> response_zero (std::make_pair (nano::account{ static_cast (0) }, nano::signature (0))); - nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; + boost::optional> response_zero (std::make_pair (nano::account{ static_cast (0) }, nano::signature (0))); + nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; auto output (node_id_handshake_response.to_bytes ()); std::atomic done (false); socket->async_read (output, output->size (), [&output, &done] (boost::system::error_code const & ec, size_t size_a) { diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 211f21d8c6..76591c9ab9 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -130,8 +130,8 @@ class public_key final : public uint256_union public_key & operator= (std::nullptr_t); bool operator== (std::nullptr_t) const; bool operator!= (std::nullptr_t) const; - using uint256_union::operator== ; - using uint256_union::operator!= ; + using uint256_union::operator==; + using uint256_union::operator!=; }; class wallet_id : public uint256_union diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index d83e984f1b..0b2e6e3cbf 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -183,10 +183,10 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr (0) }; nano::uint128_t amount (0); bool is_state_send (false); - bool is_state_epoch (false); - nano::account pending_account{ static_cast (0) }; - node.process_confirmed_data (transaction, block_a, block_a->hash (), account, amount, is_state_send, is_state_epoch, pending_account); - node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); + bool is_state_epoch (false); + nano::account pending_account{ static_cast (0) }; + node.process_confirmed_data (transaction, block_a, block_a->hash (), account, amount, is_state_send, is_state_epoch, pending_account); + node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); } else { @@ -209,9 +209,9 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr (0) }; nano::uint128_t amount (0); bool is_state_send (false); - bool is_state_epoch (false); - nano::account pending_account{ static_cast (0) }; - node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); + bool is_state_epoch (false); + nano::account pending_account{ static_cast (0) }; + node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); election_lk.lock (); election->status.type = *election_status_type; election->status.confirmation_request_count = election->confirmation_request_count; diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index ec0b39b5da..ef1735987e 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -443,13 +443,13 @@ class network_params network_params (nano::networks network_a); unsigned kdf_work; - nano::work_thresholds work; - nano::network_constants network; - nano::ledger_constants ledger; - nano::voting_constants voting; - nano::node_constants node; - nano::portmapping_constants portmapping; - nano::bootstrap_constants bootstrap; + nano::work_thresholds work; + nano::network_constants network; + nano::ledger_constants ledger; + nano::voting_constants voting; + nano::node_constants node; + nano::portmapping_constants portmapping; + nano::bootstrap_constants bootstrap; }; enum class confirmation_height_mode From be6337eb4d40b8400602ec057a5aca1e0cf332c2 Mon Sep 17 00:00:00 2001 From: theohax Date: Tue, 28 Sep 2021 15:32:42 +0300 Subject: [PATCH 03/10] Default nano::account constructor to nano::account{0} --- nano/core_test/block_store.cpp | 8 ++++---- nano/core_test/ledger.cpp | 2 +- nano/core_test/network.cpp | 2 +- nano/core_test/system.cpp | 2 +- nano/core_test/wallet.cpp | 4 ++-- nano/lib/blocks.cpp | 6 +++--- nano/lib/blocks.hpp | 2 +- nano/lib/numbers.cpp | 10 ++++++++++ nano/lib/numbers.hpp | 4 ++-- nano/lib/walletconfig.hpp | 2 +- nano/nano_node/entry.cpp | 4 ++-- nano/node/active_transactions.cpp | 8 ++++---- nano/node/active_transactions.hpp | 2 +- nano/node/bootstrap/bootstrap.hpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/node/bootstrap/bootstrap_frontier.cpp | 4 ++-- nano/node/bootstrap/bootstrap_legacy.hpp | 2 +- nano/node/bootstrap/bootstrap_server.hpp | 2 +- nano/node/common.hpp | 2 +- nano/node/ipc/action_handler.cpp | 2 +- nano/node/ipc/ipc_broker.cpp | 4 ++-- nano/node/json_handler.cpp | 18 +++++++++--------- nano/node/node.cpp | 2 +- nano/node/nodeconfig.cpp | 4 ++-- nano/node/repcrawler.hpp | 2 +- nano/node/wallet.cpp | 8 ++++---- nano/node/websocket.cpp | 10 +++++----- nano/rpc_test/rpc.cpp | 8 ++++---- nano/secure/common.hpp | 8 ++++---- nano/secure/ledger.cpp | 2 +- nano/secure/store/frontier_store_partial.hpp | 2 +- nano/secure/versioning.hpp | 6 +++--- 32 files changed, 78 insertions(+), 68 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 1bd187b093..4e282b5d5c 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -523,7 +523,7 @@ TEST (block_store, frontier_retrieval) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account1{ static_cast (0) }; + nano::account account1{ }; nano::account_info info1 (0, 0, 0, 0, 0, 0, nano::epoch::epoch_0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account1, { 0, nano::block_hash (0) }); @@ -538,7 +538,7 @@ TEST (block_store, one_account) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::block_hash hash (0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account, { 20, nano::block_hash (15) }); @@ -783,7 +783,7 @@ TEST (block_store, large_iteration) store->account.put (transaction, account, nano::account_info ()); } std::unordered_set accounts2; - nano::account previous{ static_cast (0) }; + nano::account previous{ }; auto transaction (store->tx_begin_read ()); for (auto i (store->account.begin (transaction, 0)), n (store->account.end ()); i != n; ++i) { @@ -1874,7 +1874,7 @@ TEST (block_store, confirmation_height) nano::logger_mt logger; auto store = nano::make_store (logger, path, nano::dev::constants); - nano::account account1{ static_cast (0) }; + nano::account account1{ }; nano::account account2{ 1 }; nano::account account3{ 2 }; nano::block_hash cemented_frontier1 (3); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 0485f775b6..97561e6e86 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2411,7 +2411,7 @@ TEST (ledger, epoch_blocks_fork) store->initialize (transaction, ledger.cache); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair destination; - nano::send_block send1 (nano::dev::genesis->hash (), nano::account{ static_cast (0) }, nano::dev::constants.genesis_amount, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); + nano::send_block send1 (nano::dev::genesis->hash (), nano::account{ }, nano::dev::constants.genesis_amount, 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, send1).code); nano::state_block epoch1 (nano::dev::genesis->account (), nano::dev::genesis->hash (), nano::dev::genesis->account (), nano::dev::constants.genesis_amount, ledger.epoch_link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); ASSERT_EQ (nano::process_result::fork, ledger.process (transaction, epoch1).code); diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 59544201c4..312f6e1b2a 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -797,7 +797,7 @@ TEST (tcp_listener, tcp_node_id_handshake) ASSERT_TIMELY (5s, write_done); - boost::optional> response_zero (std::make_pair (nano::account{ static_cast (0) }, nano::signature (0))); + boost::optional> response_zero (std::make_pair (nano::account{ }, nano::signature (0))); nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; auto output (node_id_handshake_response.to_bytes ()); std::atomic done (false); diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index 2030c26667..eae58364c9 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -106,7 +106,7 @@ TEST (system, DISABLED_generate_send_new) // This indirectly waits for online weight to stabilize, required to prevent intermittent failures ASSERT_TIMELY (5s, node1.wallets.reps ().voting > 0); system.generate_send_new (node1, accounts); - nano::account new_account{ static_cast (0) }; + nano::account new_account{ }; { auto transaction (node1.wallets.tx_begin_read ()); auto iterator2 (system.wallet (0)->store.begin (transaction)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 1b46a9bdf5..5ce8fbd0b6 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -335,7 +335,7 @@ TEST (wallet, rekey) TEST (account, encode_zero) { - nano::account number0{ static_cast (0) }; + nano::account number0{ }; std::string str0; number0.encode_account (str0); @@ -367,7 +367,7 @@ TEST (account, encode_all) TEST (account, encode_fail) { - nano::account number0{ static_cast (0) }; + nano::account number0{ }; std::string str0; number0.encode_account (str0); str0[16] ^= 1; diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 38464e987f..714df37da0 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -154,7 +154,7 @@ nano::account const & nano::block::representative () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account representative{ static_cast (0) }; + static nano::account representative{ }; return representative; } @@ -168,7 +168,7 @@ nano::account const & nano::block::destination () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account destination{ static_cast (0) }; + static nano::account destination{ }; return destination; } @@ -182,7 +182,7 @@ nano::account const & nano::block::account () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account account{ static_cast (0) }; + static nano::account account{ }; return account; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 336f158335..01faadf964 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -64,7 +64,7 @@ class block_sideband final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index ffa3f0abd9..7e62b5cdca 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -62,6 +62,11 @@ std::string nano::public_key::to_account () const return result; } +nano::public_key::public_key () : + uint256_union{ 0 } +{ +} + nano::public_key::public_key (std::nullptr_t) : uint256_union{ nano::hardened_constants::get ().not_an_account } { @@ -787,6 +792,11 @@ std::string nano::uint128_union::to_string_dec () const return result; } +nano::hash_or_account::hash_or_account () : + account{} +{ +} + nano::hash_or_account::hash_or_account (uint64_t value_a) : raw (value_a) { diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 76591c9ab9..9260fabf74 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -115,7 +115,7 @@ class public_key final : public uint256_union public: using uint256_union::uint256_union; - public_key () = default; + public_key (); explicit public_key (std::nullptr_t); std::string to_node_id () const; @@ -145,7 +145,7 @@ using account = public_key; class hash_or_account { public: - hash_or_account () = default; + hash_or_account (); hash_or_account (uint64_t value_a); bool is_zero () const; diff --git a/nano/lib/walletconfig.hpp b/nano/lib/walletconfig.hpp index 361c79042c..71ebe25996 100644 --- a/nano/lib/walletconfig.hpp +++ b/nano/lib/walletconfig.hpp @@ -19,6 +19,6 @@ class wallet_config final nano::error serialize_toml (nano::tomlconfig & toml_a) const; nano::error deserialize_toml (nano::tomlconfig & toml_a); nano::wallet_id wallet; - nano::account account{ static_cast (0) }; + nano::account account{ }; }; } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 1c6eae8b33..34d2f40a50 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1459,7 +1459,7 @@ int main (int argc, char * const * argv) } } uint64_t previous_timestamp (0); - nano::account calculated_representative{ static_cast (0) }; + nano::account calculated_representative{ }; while (!hash.is_zero () && block != nullptr) { ++block_count; @@ -1704,7 +1704,7 @@ int main (int argc, char * const * argv) else { // Check if pending destination is correct - nano::account destination{ static_cast (0) }; + nano::account destination{ }; bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 0b2e6e3cbf..cb9f64e761 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -180,11 +180,11 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr (0) }; + nano::account account{ }; nano::uint128_t amount (0); bool is_state_send (false); bool is_state_epoch (false); - nano::account pending_account{ static_cast (0) }; + nano::account pending_account{ }; node.process_confirmed_data (transaction, block_a, block_a->hash (), account, amount, is_state_send, is_state_epoch, pending_account); node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); } @@ -206,11 +206,11 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptrlink ().is_zero () ? block_a->destination () : block_a->link ().as_account ()); node.receive_confirmed (transaction, hash, destination); - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::uint128_t amount (0); bool is_state_send (false); bool is_state_epoch (false); - nano::account pending_account{ static_cast (0) }; + nano::account pending_account{ }; node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); election_lk.lock (); election->status.type = *election_status_type; diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index dedfbfa29e..c62fc782d9 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -279,7 +279,7 @@ class active_transactions final void confirm_expired_frontiers_pessimistically (nano::transaction const &, uint64_t, uint64_t &); void frontiers_confirmation (nano::unique_lock &); bool insert_election_from_frontiers_confirmation (std::shared_ptr const &, nano::account const &, nano::uint128_t, nano::election_behavior); - nano::account next_frontier_account{ static_cast (0) }; + nano::account next_frontier_account{ }; std::chrono::steady_clock::time_point next_frontier_check{ std::chrono::steady_clock::now () }; constexpr static size_t max_active_elections_frontier_insertion{ 1000 }; prioritize_num_uncemented priority_wallet_cementable_frontiers; diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 8a2046349b..32656fdbe6 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -82,7 +82,7 @@ class bootstrap_initiator final explicit bootstrap_initiator (nano::node &); ~bootstrap_initiator (); void bootstrap (nano::endpoint const &, bool add_to_peers = true, std::string id_a = ""); - void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account (static_cast (0))); + void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account{ }); bool bootstrap_lazy (nano::hash_or_account const &, bool force = false, bool confirmed = true, std::string id_a = ""); void bootstrap_wallet (std::deque &); void run_bootstrap (); diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index fa5f039995..880c339e93 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -21,7 +21,7 @@ nano::pull_info::pull_info (nano::hash_or_account const & account_or_head_a, nan nano::bulk_pull_client::bulk_pull_client (std::shared_ptr const & connection_a, std::shared_ptr const & attempt_a, nano::pull_info const & pull_a) : connection (connection_a), attempt (attempt_a), - known_account{ static_cast (0) }, + known_account{ }, pull (pull_a), pull_blocks (0), unexpected_count (0) diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index 0c5b5ae391..efd54f68c9 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -228,7 +228,7 @@ void nano::frontier_req_client::next () /* If loop breaks before max_size, then accounts_end () is reached. Add empty record */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account{ static_cast (0) }, nano::block_hash (0)); + accounts.emplace_back (nano::account{ }, nano::block_hash (0)); } } // Retrieving accounts from deque @@ -364,7 +364,7 @@ void nano::frontier_req_server::next () /* If loop breaks before max_size, then accounts_end () is reached. Add empty record to finish frontier_req_server */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account{ static_cast (0) }, nano::block_hash (0)); + accounts.emplace_back (nano::account{ }, nano::block_hash (0)); } } // Retrieving accounts from deque diff --git a/nano/node/bootstrap/bootstrap_legacy.hpp b/nano/node/bootstrap/bootstrap_legacy.hpp index 6f83aede49..d386980f02 100644 --- a/nano/node/bootstrap/bootstrap_legacy.hpp +++ b/nano/node/bootstrap/bootstrap_legacy.hpp @@ -33,7 +33,7 @@ class bootstrap_attempt_legacy : public bootstrap_attempt std::weak_ptr push; std::deque frontier_pulls; std::vector> bulk_push_targets; - nano::account start_account{ static_cast (0) }; + nano::account start_account{ }; std::atomic account_count{ 0 }; uint32_t frontiers_age; }; diff --git a/nano/node/bootstrap/bootstrap_server.hpp b/nano/node/bootstrap/bootstrap_server.hpp index 17c230ff05..12da22c83a 100644 --- a/nano/node/bootstrap/bootstrap_server.hpp +++ b/nano/node/bootstrap/bootstrap_server.hpp @@ -66,7 +66,7 @@ class bootstrap_server final : public std::enable_shared_from_this stopped{ false }; // Remote enpoint used to remove response channel even after socket closing nano::tcp_endpoint remote_endpoint{ boost::asio::ip::address_v6::any (), 0 }; - nano::account remote_node_id{ static_cast (0) }; + nano::account remote_node_id{ }; std::chrono::steady_clock::time_point last_telemetry_req{ std::chrono::steady_clock::time_point () }; }; } diff --git a/nano/node/common.hpp b/nano/node/common.hpp index cf97a635b5..c4d12c6818 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -354,7 +354,7 @@ class telemetry_data { public: nano::signature signature{ 0 }; - nano::account node_id{ static_cast (0) }; + nano::account node_id{ }; uint64_t block_count{ 0 }; uint64_t cemented_count{ 0 }; uint64_t unchecked_count{ 0 }; diff --git a/nano/node/ipc/action_handler.cpp b/nano/node/ipc/action_handler.cpp index c9a020c007..e599fb4a94 100644 --- a/nano/node/ipc/action_handler.cpp +++ b/nano/node/ipc/action_handler.cpp @@ -11,7 +11,7 @@ namespace { nano::account parse_account (std::string const & account, bool & out_is_deprecated_format) { - nano::account result{ static_cast (0) }; + nano::account result{ }; if (account.empty ()) { throw nano::error (nano::error_common::bad_account_number); diff --git a/nano/node/ipc/ipc_broker.cpp b/nano/node/ipc/ipc_broker.cpp index 5b935b378c..5433c48b54 100644 --- a/nano/node/ipc/ipc_broker.cpp +++ b/nano/node/ipc/ipc_broker.cpp @@ -144,8 +144,8 @@ void nano::ipc::broker::broadcast (std::shared_ptr if (itr->topic->options->all_local_accounts) { auto transaction_l (this->node.wallets.tx_begin_read ()); - nano::account source_l{ static_cast (0) }; - nano::account destination_l{ static_cast (0) }; + nano::account source_l{ }; + nano::account destination_l{ }; auto decode_source_ok_l (!source_l.decode_account (state->account)); auto decode_destination_ok_l (!destination_l.decode_account (state->link_as_account)); (void)decode_source_ok_l; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index eecece84d0..96811bbdb5 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -235,7 +235,7 @@ bool nano::json_handler::wallet_account_impl (nano::transaction const & transact nano::account nano::json_handler::account_impl (std::string account_text, std::error_code ec_a) { - nano::account result{ static_cast (0) }; + nano::account result{ }; if (!ec) { if (account_text.empty ()) @@ -671,7 +671,7 @@ void nano::json_handler::account_info () response_l.put ("representative", info.representative.to_account ()); if (include_confirmed) { - nano::account confirmed_representative{ static_cast (0) }; + nano::account confirmed_representative{ }; if (confirmed_frontier_block) { confirmed_representative = confirmed_frontier_block->representative (); @@ -1053,7 +1053,7 @@ void nano::json_handler::available_supply () auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ())); // Cold storage genesis auto landing_balance (node.balance (nano::account ("059F68AAB29DE0D3A27443625C7EA9CDDB6517A8B76FE37727EF6A4D76832AD5"))); // Active unavailable account auto faucet_balance (node.balance (nano::account ("8E319CE6F3025E5B2DF66DA7AB1467FE48F1679C13DD43BFDB29FA2E9FC40D3B"))); // Faucet account - auto burned_balance ((node.balance_pending (nano::account{ static_cast (0) }, false)).second); // Burning 0 account + auto burned_balance ((node.balance_pending (nano::account{ }, false)).second); // Burning 0 account auto available (nano::dev::constants.genesis_amount - genesis_balance - landing_balance - faucet_balance - burned_balance); response_l.put ("available", available.convert_to ()); response_errors (); @@ -1360,19 +1360,19 @@ void nano::json_handler::block_create () ec = nano::error_common::bad_wallet_number; } } - nano::account account (static_cast (0)); + nano::account account{ }; boost::optional account_text (request.get_optional ("account")); if (!ec && account_text.is_initialized ()) { account = account_impl (account_text.get ()); } - nano::account representative (static_cast (0)); + nano::account representative{ }; boost::optional representative_text (request.get_optional ("representative")); if (!ec && representative_text.is_initialized ()) { representative = account_impl (representative_text.get (), nano::error_rpc::bad_representative_number); } - nano::account destination (static_cast (0)); + nano::account destination{ }; boost::optional destination_text (request.get_optional ("destination")); if (!ec && destination_text.is_initialized ()) { @@ -1739,7 +1739,7 @@ void nano::json_handler::bootstrap_any () const bool force = request.get ("force", false); if (!node.flags.disable_legacy_bootstrap) { - nano::account start_account (static_cast (0)); + nano::account start_account{ }; boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { @@ -2095,7 +2095,7 @@ void nano::json_handler::delegators () auto threshold (threshold_optional_impl ()); auto start_account_text (request.get_optional ("start")); - nano::account start_account (static_cast (0)); + nano::account start_account{ }; if (!ec && start_account_text.is_initialized ()) { start_account = account_impl (start_account_text.get ()); @@ -2622,7 +2622,7 @@ void nano::json_handler::ledger () auto threshold (threshold_optional_impl ()); if (!ec) { - nano::account start (static_cast (0)); + nano::account start{ }; boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { diff --git a/nano/node/node.cpp b/nano/node/node.cpp index cb830f0de5..bbc11ccfa6 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1496,7 +1496,7 @@ void nano::node::epoch_upgrader_impl (nano::raw_key const & prv_a, nano::epoch e class account_upgrade_item final { public: - nano::account account{ static_cast (0) }; + nano::account account{ }; uint64_t modified{ 0 }; }; class account_tag diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index c26b46a1a6..624141469d 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -248,7 +248,7 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) { preconfigured_representatives.clear (); toml.array_entries_required ("preconfigured_representatives", [this, &toml] (std::string entry) { - nano::account representative{ static_cast (0) }; + nano::account representative{ }; if (representative.decode_account (entry)) { toml.get_error ().set ("Invalid representative account: " + entry); @@ -583,7 +583,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco auto preconfigured_representatives_l (json.get_required_child ("preconfigured_representatives")); preconfigured_representatives.clear (); preconfigured_representatives_l.array_entries ([this, &json] (std::string entry) { - nano::account representative{ static_cast (0) }; + nano::account representative{ }; if (representative.decode_account (entry)) { json.get_error ().set ("Invalid representative account: " + entry); diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index 40ee23b29a..9f0a1ab25b 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -41,7 +41,7 @@ class representative { return account == other_a.account; } - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::amount weight{ 0 }; std::shared_ptr channel; std::chrono::steady_clock::time_point last_request{ std::chrono::steady_clock::time_point () }; diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 0436600a03..1b0fe2124e 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -238,7 +238,7 @@ void nano::fan::value_set (nano::raw_key const & value_a) } // Wallet version number -nano::account const nano::wallet_store::version_special (static_cast (0)); +nano::account const nano::wallet_store::version_special{ }; // Random number used to salt private key encryption nano::account const nano::wallet_store::salt_special (1); // Key used to encrypt wallet keys, encrypted itself by the user password @@ -714,7 +714,7 @@ bool nano::wallet::enter_password (nano::transaction const & transaction_a, std: nano::public_key nano::wallet::deterministic_insert (nano::transaction const & transaction_a, bool generate_work_a) { - nano::public_key key{ static_cast (0) }; + nano::public_key key{ }; if (store.valid_password (transaction_a)) { key = store.deterministic_insert (transaction_a); @@ -735,7 +735,7 @@ nano::public_key nano::wallet::deterministic_insert (nano::transaction const & t nano::public_key nano::wallet::deterministic_insert (uint32_t const index, bool generate_work_a) { auto transaction (wallets.tx_begin_write ()); - nano::public_key key{ static_cast (0) }; + nano::public_key key{ }; if (store.valid_password (transaction)) { key = store.deterministic_insert (transaction, index); @@ -756,7 +756,7 @@ nano::public_key nano::wallet::deterministic_insert (bool generate_work_a) nano::public_key nano::wallet::insert_adhoc (nano::raw_key const & key_a, bool generate_work_a) { - nano::public_key key{ static_cast (0) }; + nano::public_key key{ }; auto transaction (wallets.tx_begin_write ()); if (store.valid_password (transaction)) { diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 51df45202c..75bcc481fa 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -68,7 +68,7 @@ nano::websocket::confirmation_options::confirmation_options (boost::property_tre has_account_filtering_options = true; for (auto account_l : *accounts_l) { - nano::account result_l{ static_cast (0) }; + nano::account result_l{ }; if (!result_l.decode_account (account_l.second.data ())) { // Do not insert the given raw data to keep old prefix support @@ -114,8 +114,8 @@ bool nano::websocket::confirmation_options::should_filter (nano::websocket::mess if (all_local_accounts) { auto transaction_l (wallets.tx_begin_read ()); - nano::account source_l{ static_cast (0) }; - nano::account destination_l{ static_cast (0) }; + nano::account source_l{ }; + nano::account destination_l{ }; auto decode_source_ok_l (!source_l.decode_account (source_text_l)); auto decode_destination_ok_l (!destination_l.decode_account (destination_opt_l.get ())); (void)decode_source_ok_l; @@ -141,7 +141,7 @@ bool nano::websocket::confirmation_options::update (boost::property_tree::ptree this->has_account_filtering_options = true; for (auto const & account_l : accounts_text_a) { - nano::account result_l{ static_cast (0) }; + nano::account result_l{ }; if (!result_l.decode_account (account_l.second.data ())) { // Re-encode to keep old prefix support @@ -198,7 +198,7 @@ nano::websocket::vote_options::vote_options (boost::property_tree::ptree const & { for (auto representative_l : *representatives_l) { - nano::account result_l{ static_cast (0) }; + nano::account result_l{ }; if (!result_l.decode_account (representative_l.second.data ())) { // Do not insert the given raw data to keep old prefix support diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 56696111c7..fb7024620b 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -494,7 +494,7 @@ TEST (rpc, send_idempotent) request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); - request.put ("destination", nano::account{ static_cast (0) }.to_account ()); + request.put ("destination", nano::account{ }.to_account ()); request.put ("amount", (nano::dev::constants.genesis_amount - (nano::dev::constants.genesis_amount / 4)).convert_to ()); request.put ("id", "123abc"); auto response (wait_response (system, rpc, request)); @@ -710,7 +710,7 @@ TEST (rpc, wallet_representative_set_force) auto transaction (node->wallets.tx_begin_read ()); ASSERT_EQ (key.pub, node->wallets.items.begin ()->second->store.representative (transaction)); } - nano::account representative{ static_cast (0) }; + nano::account representative{ }; while (representative != key.pub) { auto transaction (node->store.tx_begin_read ()); @@ -1007,7 +1007,7 @@ TEST (rpc, frontier) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account{ static_cast (0) }.to_account ()); + request.put ("account", nano::account{ }.to_account ()); request.put ("count", std::to_string (std::numeric_limits::max ())); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); @@ -1045,7 +1045,7 @@ TEST (rpc, frontier_limited) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account{ static_cast (0) }.to_account ()); + request.put ("account", nano::account{ }.to_account ()); request.put ("count", std::to_string (100)); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index ef1735987e..b92d16da79 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -119,7 +119,7 @@ class pending_info final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info const &) const; - nano::account source{ static_cast (0) }; + nano::account source{ }; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -131,7 +131,7 @@ class pending_key final bool deserialize (nano::stream &); bool operator== (nano::pending_key const &) const; nano::account const & key () const; - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::block_hash hash{ 0 }; }; @@ -202,7 +202,7 @@ class unchecked_info final void serialize (nano::stream &) const; bool deserialize (nano::stream &); std::shared_ptr block; - nano::account account{ static_cast (0) }; + nano::account account{ }; /** Seconds since posix epoch */ uint64_t modified{ 0 }; nano::signature_verification verified{ nano::signature_verification::unknown }; @@ -214,7 +214,7 @@ class block_info final public: block_info () = default; block_info (nano::account const &, nano::amount const &); - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::amount balance{ 0 }; }; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d7423125b4..53f05d5d31 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -116,7 +116,7 @@ class rollback_visitor : public nano::block_visitor } auto balance (ledger.balance (transaction, block_a.hashables.previous)); auto is_send (block_a.hashables.balance < balance); - nano::account representative{ static_cast (0) }; + nano::account representative{ }; if (!rep_block_hash.is_zero ()) { // Move existing representation & add in amount delta diff --git a/nano/secure/store/frontier_store_partial.hpp b/nano/secure/store/frontier_store_partial.hpp index 671f2255d5..4f75283b2b 100644 --- a/nano/secure/store/frontier_store_partial.hpp +++ b/nano/secure/store/frontier_store_partial.hpp @@ -40,7 +40,7 @@ class frontier_store_partial : public frontier_store nano::db_val value; auto status (store.get (transaction_a, tables::frontiers, nano::db_val (block_a), value)); release_assert (store.success (status) || store.not_found (status)); - nano::account result{ static_cast (0) }; + nano::account result{ }; if (store.success (status)) { result = static_cast (value); diff --git a/nano/secure/versioning.hpp b/nano/secure/versioning.hpp index e9b113eb2a..b11b34495c 100644 --- a/nano/secure/versioning.hpp +++ b/nano/secure/versioning.hpp @@ -15,7 +15,7 @@ class pending_info_v14 final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info_v14 const &) const; - nano::account source{ static_cast (0) }; + nano::account source{ }; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -44,7 +44,7 @@ class block_sideband_v14 final static size_t size (nano::block_type); nano::block_type type{ nano::block_type::invalid }; nano::block_hash successor{ 0 }; - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; @@ -65,7 +65,7 @@ class block_sideband_v18 final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ static_cast (0) }; + nano::account account{ }; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; From 9477a8a379f7e87acfce0cafe2e344382ce79a12 Mon Sep 17 00:00:00 2001 From: theohax Date: Tue, 28 Sep 2021 15:33:05 +0300 Subject: [PATCH 04/10] Fix formatting --- nano/core_test/block_store.cpp | 8 ++++---- nano/core_test/ledger.cpp | 2 +- nano/core_test/network.cpp | 2 +- nano/core_test/system.cpp | 2 +- nano/core_test/wallet.cpp | 4 ++-- nano/lib/blocks.cpp | 6 +++--- nano/lib/blocks.hpp | 2 +- nano/lib/numbers.cpp | 4 ++-- nano/lib/walletconfig.hpp | 2 +- nano/nano_node/entry.cpp | 4 ++-- nano/node/active_transactions.cpp | 8 ++++---- nano/node/active_transactions.hpp | 2 +- nano/node/bootstrap/bootstrap.hpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 2 +- nano/node/bootstrap/bootstrap_frontier.cpp | 4 ++-- nano/node/bootstrap/bootstrap_legacy.hpp | 2 +- nano/node/bootstrap/bootstrap_server.hpp | 2 +- nano/node/common.hpp | 2 +- nano/node/ipc/action_handler.cpp | 2 +- nano/node/ipc/ipc_broker.cpp | 4 ++-- nano/node/json_handler.cpp | 18 +++++++++--------- nano/node/node.cpp | 2 +- nano/node/nodeconfig.cpp | 4 ++-- nano/node/repcrawler.hpp | 2 +- nano/node/wallet.cpp | 8 ++++---- nano/node/websocket.cpp | 10 +++++----- nano/rpc_test/rpc.cpp | 8 ++++---- nano/secure/common.hpp | 8 ++++---- nano/secure/ledger.cpp | 2 +- nano/secure/store/frontier_store_partial.hpp | 2 +- nano/secure/versioning.hpp | 6 +++--- 31 files changed, 68 insertions(+), 68 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 4e282b5d5c..f4529dc7db 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -523,7 +523,7 @@ TEST (block_store, frontier_retrieval) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account1{ }; + nano::account account1{}; nano::account_info info1 (0, 0, 0, 0, 0, 0, nano::epoch::epoch_0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account1, { 0, nano::block_hash (0) }); @@ -538,7 +538,7 @@ TEST (block_store, one_account) nano::logger_mt logger; auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); ASSERT_TRUE (!store->init_error ()); - nano::account account{ }; + nano::account account{}; nano::block_hash hash (0); auto transaction (store->tx_begin_write ()); store->confirmation_height.put (transaction, account, { 20, nano::block_hash (15) }); @@ -783,7 +783,7 @@ TEST (block_store, large_iteration) store->account.put (transaction, account, nano::account_info ()); } std::unordered_set accounts2; - nano::account previous{ }; + nano::account previous{}; auto transaction (store->tx_begin_read ()); for (auto i (store->account.begin (transaction, 0)), n (store->account.end ()); i != n; ++i) { @@ -1874,7 +1874,7 @@ TEST (block_store, confirmation_height) nano::logger_mt logger; auto store = nano::make_store (logger, path, nano::dev::constants); - nano::account account1{ }; + nano::account account1{}; nano::account account2{ 1 }; nano::account account3{ 2 }; nano::block_hash cemented_frontier1 (3); diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 97561e6e86..357249df54 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2411,7 +2411,7 @@ TEST (ledger, epoch_blocks_fork) store->initialize (transaction, ledger.cache); nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; nano::keypair destination; - nano::send_block send1 (nano::dev::genesis->hash (), nano::account{ }, nano::dev::constants.genesis_amount, nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); + nano::send_block send1 (nano::dev::genesis->hash (), nano::account{}, nano::dev::constants.genesis_amount, 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, send1).code); nano::state_block epoch1 (nano::dev::genesis->account (), nano::dev::genesis->hash (), nano::dev::genesis->account (), nano::dev::constants.genesis_amount, ledger.epoch_link (nano::epoch::epoch_1), nano::dev::genesis_key.prv, nano::dev::genesis_key.pub, *pool.generate (nano::dev::genesis->hash ())); ASSERT_EQ (nano::process_result::fork, ledger.process (transaction, epoch1).code); diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 312f6e1b2a..3fb8cad945 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -797,7 +797,7 @@ TEST (tcp_listener, tcp_node_id_handshake) ASSERT_TIMELY (5s, write_done); - boost::optional> response_zero (std::make_pair (nano::account{ }, nano::signature (0))); + boost::optional> response_zero (std::make_pair (nano::account{}, nano::signature (0))); nano::node_id_handshake node_id_handshake_response{ nano::dev::network_params.network, boost::none, response_zero }; auto output (node_id_handshake_response.to_bytes ()); std::atomic done (false); diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index eae58364c9..4854fbd73f 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -106,7 +106,7 @@ TEST (system, DISABLED_generate_send_new) // This indirectly waits for online weight to stabilize, required to prevent intermittent failures ASSERT_TIMELY (5s, node1.wallets.reps ().voting > 0); system.generate_send_new (node1, accounts); - nano::account new_account{ }; + nano::account new_account{}; { auto transaction (node1.wallets.tx_begin_read ()); auto iterator2 (system.wallet (0)->store.begin (transaction)); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 5ce8fbd0b6..010b135cbb 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -335,7 +335,7 @@ TEST (wallet, rekey) TEST (account, encode_zero) { - nano::account number0{ }; + nano::account number0{}; std::string str0; number0.encode_account (str0); @@ -367,7 +367,7 @@ TEST (account, encode_all) TEST (account, encode_fail) { - nano::account number0{ }; + nano::account number0{}; std::string str0; number0.encode_account (str0); str0[16] ^= 1; diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 714df37da0..09672d1798 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -154,7 +154,7 @@ nano::account const & nano::block::representative () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account representative{ }; + static nano::account representative{}; return representative; } @@ -168,7 +168,7 @@ nano::account const & nano::block::destination () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account destination{ }; + static nano::account destination{}; return destination; } @@ -182,7 +182,7 @@ nano::account const & nano::block::account () const { /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account account{ }; + static nano::account account{}; return account; } diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 01faadf964..5a5b875e84 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -64,7 +64,7 @@ class block_sideband final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ }; + nano::account account{}; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 7e62b5cdca..c963171613 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -63,7 +63,7 @@ std::string nano::public_key::to_account () const } nano::public_key::public_key () : - uint256_union{ 0 } + uint256_union{ 0 } { } @@ -793,7 +793,7 @@ std::string nano::uint128_union::to_string_dec () const } nano::hash_or_account::hash_or_account () : - account{} + account{} { } diff --git a/nano/lib/walletconfig.hpp b/nano/lib/walletconfig.hpp index 71ebe25996..6a04206a90 100644 --- a/nano/lib/walletconfig.hpp +++ b/nano/lib/walletconfig.hpp @@ -19,6 +19,6 @@ class wallet_config final nano::error serialize_toml (nano::tomlconfig & toml_a) const; nano::error deserialize_toml (nano::tomlconfig & toml_a); nano::wallet_id wallet; - nano::account account{ }; + nano::account account{}; }; } diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 34d2f40a50..593a68695c 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1459,7 +1459,7 @@ int main (int argc, char * const * argv) } } uint64_t previous_timestamp (0); - nano::account calculated_representative{ }; + nano::account calculated_representative{}; while (!hash.is_zero () && block != nullptr) { ++block_count; @@ -1704,7 +1704,7 @@ int main (int argc, char * const * argv) else { // Check if pending destination is correct - nano::account destination{ }; + nano::account destination{}; bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index cb9f64e761..b296c024b0 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -180,11 +180,11 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptrhash (), account, amount, is_state_send, is_state_epoch, pending_account); node.observers.blocks.notify (nano::election_status{ block_a, 0, 0, std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values::zero (), 0, 1, 0, nano::election_status_type::inactive_confirmation_height }, {}, account, amount, is_state_send, is_state_epoch); } @@ -206,11 +206,11 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptrlink ().is_zero () ? block_a->destination () : block_a->link ().as_account ()); node.receive_confirmed (transaction, hash, destination); - nano::account account{ }; + nano::account account{}; nano::uint128_t amount (0); bool is_state_send (false); bool is_state_epoch (false); - nano::account pending_account{ }; + nano::account pending_account{}; node.process_confirmed_data (transaction, block_a, hash, account, amount, is_state_send, is_state_epoch, pending_account); election_lk.lock (); election->status.type = *election_status_type; diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index c62fc782d9..4fe84eb34d 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -279,7 +279,7 @@ class active_transactions final void confirm_expired_frontiers_pessimistically (nano::transaction const &, uint64_t, uint64_t &); void frontiers_confirmation (nano::unique_lock &); bool insert_election_from_frontiers_confirmation (std::shared_ptr const &, nano::account const &, nano::uint128_t, nano::election_behavior); - nano::account next_frontier_account{ }; + nano::account next_frontier_account{}; std::chrono::steady_clock::time_point next_frontier_check{ std::chrono::steady_clock::now () }; constexpr static size_t max_active_elections_frontier_insertion{ 1000 }; prioritize_num_uncemented priority_wallet_cementable_frontiers; diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index 32656fdbe6..b26d55f98e 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -82,7 +82,7 @@ class bootstrap_initiator final explicit bootstrap_initiator (nano::node &); ~bootstrap_initiator (); void bootstrap (nano::endpoint const &, bool add_to_peers = true, std::string id_a = ""); - void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account{ }); + void bootstrap (bool force = false, std::string id_a = "", uint32_t const frontiers_age_a = std::numeric_limits::max (), nano::account const & start_account_a = nano::account{}); bool bootstrap_lazy (nano::hash_or_account const &, bool force = false, bool confirmed = true, std::string id_a = ""); void bootstrap_wallet (std::deque &); void run_bootstrap (); diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 880c339e93..0f87250f97 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -21,7 +21,7 @@ nano::pull_info::pull_info (nano::hash_or_account const & account_or_head_a, nan nano::bulk_pull_client::bulk_pull_client (std::shared_ptr const & connection_a, std::shared_ptr const & attempt_a, nano::pull_info const & pull_a) : connection (connection_a), attempt (attempt_a), - known_account{ }, + known_account{}, pull (pull_a), pull_blocks (0), unexpected_count (0) diff --git a/nano/node/bootstrap/bootstrap_frontier.cpp b/nano/node/bootstrap/bootstrap_frontier.cpp index efd54f68c9..277ef0da5a 100644 --- a/nano/node/bootstrap/bootstrap_frontier.cpp +++ b/nano/node/bootstrap/bootstrap_frontier.cpp @@ -228,7 +228,7 @@ void nano::frontier_req_client::next () /* If loop breaks before max_size, then accounts_end () is reached. Add empty record */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account{ }, nano::block_hash (0)); + accounts.emplace_back (nano::account{}, nano::block_hash (0)); } } // Retrieving accounts from deque @@ -364,7 +364,7 @@ void nano::frontier_req_server::next () /* If loop breaks before max_size, then accounts_end () is reached. Add empty record to finish frontier_req_server */ if (accounts.size () != max_size) { - accounts.emplace_back (nano::account{ }, nano::block_hash (0)); + accounts.emplace_back (nano::account{}, nano::block_hash (0)); } } // Retrieving accounts from deque diff --git a/nano/node/bootstrap/bootstrap_legacy.hpp b/nano/node/bootstrap/bootstrap_legacy.hpp index d386980f02..7387556e43 100644 --- a/nano/node/bootstrap/bootstrap_legacy.hpp +++ b/nano/node/bootstrap/bootstrap_legacy.hpp @@ -33,7 +33,7 @@ class bootstrap_attempt_legacy : public bootstrap_attempt std::weak_ptr push; std::deque frontier_pulls; std::vector> bulk_push_targets; - nano::account start_account{ }; + nano::account start_account{}; std::atomic account_count{ 0 }; uint32_t frontiers_age; }; diff --git a/nano/node/bootstrap/bootstrap_server.hpp b/nano/node/bootstrap/bootstrap_server.hpp index 12da22c83a..58ee8958a4 100644 --- a/nano/node/bootstrap/bootstrap_server.hpp +++ b/nano/node/bootstrap/bootstrap_server.hpp @@ -66,7 +66,7 @@ class bootstrap_server final : public std::enable_shared_from_this stopped{ false }; // Remote enpoint used to remove response channel even after socket closing nano::tcp_endpoint remote_endpoint{ boost::asio::ip::address_v6::any (), 0 }; - nano::account remote_node_id{ }; + nano::account remote_node_id{}; std::chrono::steady_clock::time_point last_telemetry_req{ std::chrono::steady_clock::time_point () }; }; } diff --git a/nano/node/common.hpp b/nano/node/common.hpp index c4d12c6818..1b2739cd59 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -354,7 +354,7 @@ class telemetry_data { public: nano::signature signature{ 0 }; - nano::account node_id{ }; + nano::account node_id{}; uint64_t block_count{ 0 }; uint64_t cemented_count{ 0 }; uint64_t unchecked_count{ 0 }; diff --git a/nano/node/ipc/action_handler.cpp b/nano/node/ipc/action_handler.cpp index e599fb4a94..db191f77b2 100644 --- a/nano/node/ipc/action_handler.cpp +++ b/nano/node/ipc/action_handler.cpp @@ -11,7 +11,7 @@ namespace { nano::account parse_account (std::string const & account, bool & out_is_deprecated_format) { - nano::account result{ }; + nano::account result{}; if (account.empty ()) { throw nano::error (nano::error_common::bad_account_number); diff --git a/nano/node/ipc/ipc_broker.cpp b/nano/node/ipc/ipc_broker.cpp index 5433c48b54..9b3477c25d 100644 --- a/nano/node/ipc/ipc_broker.cpp +++ b/nano/node/ipc/ipc_broker.cpp @@ -144,8 +144,8 @@ void nano::ipc::broker::broadcast (std::shared_ptr if (itr->topic->options->all_local_accounts) { auto transaction_l (this->node.wallets.tx_begin_read ()); - nano::account source_l{ }; - nano::account destination_l{ }; + nano::account source_l{}; + nano::account destination_l{}; auto decode_source_ok_l (!source_l.decode_account (state->account)); auto decode_destination_ok_l (!destination_l.decode_account (state->link_as_account)); (void)decode_source_ok_l; diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 96811bbdb5..4d6ac1c3ab 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -235,7 +235,7 @@ bool nano::json_handler::wallet_account_impl (nano::transaction const & transact nano::account nano::json_handler::account_impl (std::string account_text, std::error_code ec_a) { - nano::account result{ }; + nano::account result{}; if (!ec) { if (account_text.empty ()) @@ -671,7 +671,7 @@ void nano::json_handler::account_info () response_l.put ("representative", info.representative.to_account ()); if (include_confirmed) { - nano::account confirmed_representative{ }; + nano::account confirmed_representative{}; if (confirmed_frontier_block) { confirmed_representative = confirmed_frontier_block->representative (); @@ -1053,7 +1053,7 @@ void nano::json_handler::available_supply () auto genesis_balance (node.balance (node.network_params.ledger.genesis->account ())); // Cold storage genesis auto landing_balance (node.balance (nano::account ("059F68AAB29DE0D3A27443625C7EA9CDDB6517A8B76FE37727EF6A4D76832AD5"))); // Active unavailable account auto faucet_balance (node.balance (nano::account ("8E319CE6F3025E5B2DF66DA7AB1467FE48F1679C13DD43BFDB29FA2E9FC40D3B"))); // Faucet account - auto burned_balance ((node.balance_pending (nano::account{ }, false)).second); // Burning 0 account + auto burned_balance ((node.balance_pending (nano::account{}, false)).second); // Burning 0 account auto available (nano::dev::constants.genesis_amount - genesis_balance - landing_balance - faucet_balance - burned_balance); response_l.put ("available", available.convert_to ()); response_errors (); @@ -1360,19 +1360,19 @@ void nano::json_handler::block_create () ec = nano::error_common::bad_wallet_number; } } - nano::account account{ }; + nano::account account{}; boost::optional account_text (request.get_optional ("account")); if (!ec && account_text.is_initialized ()) { account = account_impl (account_text.get ()); } - nano::account representative{ }; + nano::account representative{}; boost::optional representative_text (request.get_optional ("representative")); if (!ec && representative_text.is_initialized ()) { representative = account_impl (representative_text.get (), nano::error_rpc::bad_representative_number); } - nano::account destination{ }; + nano::account destination{}; boost::optional destination_text (request.get_optional ("destination")); if (!ec && destination_text.is_initialized ()) { @@ -1739,7 +1739,7 @@ void nano::json_handler::bootstrap_any () const bool force = request.get ("force", false); if (!node.flags.disable_legacy_bootstrap) { - nano::account start_account{ }; + nano::account start_account{}; boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { @@ -2095,7 +2095,7 @@ void nano::json_handler::delegators () auto threshold (threshold_optional_impl ()); auto start_account_text (request.get_optional ("start")); - nano::account start_account{ }; + nano::account start_account{}; if (!ec && start_account_text.is_initialized ()) { start_account = account_impl (start_account_text.get ()); @@ -2622,7 +2622,7 @@ void nano::json_handler::ledger () auto threshold (threshold_optional_impl ()); if (!ec) { - nano::account start{ }; + nano::account start{}; boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { diff --git a/nano/node/node.cpp b/nano/node/node.cpp index bbc11ccfa6..0cbd75d94a 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1496,7 +1496,7 @@ void nano::node::epoch_upgrader_impl (nano::raw_key const & prv_a, nano::epoch e class account_upgrade_item final { public: - nano::account account{ }; + nano::account account{}; uint64_t modified{ 0 }; }; class account_tag diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 624141469d..aa68fa4aa2 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -248,7 +248,7 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) { preconfigured_representatives.clear (); toml.array_entries_required ("preconfigured_representatives", [this, &toml] (std::string entry) { - nano::account representative{ }; + nano::account representative{}; if (representative.decode_account (entry)) { toml.get_error ().set ("Invalid representative account: " + entry); @@ -583,7 +583,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco auto preconfigured_representatives_l (json.get_required_child ("preconfigured_representatives")); preconfigured_representatives.clear (); preconfigured_representatives_l.array_entries ([this, &json] (std::string entry) { - nano::account representative{ }; + nano::account representative{}; if (representative.decode_account (entry)) { json.get_error ().set ("Invalid representative account: " + entry); diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index 9f0a1ab25b..7586945a50 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -41,7 +41,7 @@ class representative { return account == other_a.account; } - nano::account account{ }; + nano::account account{}; nano::amount weight{ 0 }; std::shared_ptr channel; std::chrono::steady_clock::time_point last_request{ std::chrono::steady_clock::time_point () }; diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 1b0fe2124e..7924aa2557 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -238,7 +238,7 @@ void nano::fan::value_set (nano::raw_key const & value_a) } // Wallet version number -nano::account const nano::wallet_store::version_special{ }; +nano::account const nano::wallet_store::version_special{}; // Random number used to salt private key encryption nano::account const nano::wallet_store::salt_special (1); // Key used to encrypt wallet keys, encrypted itself by the user password @@ -714,7 +714,7 @@ bool nano::wallet::enter_password (nano::transaction const & transaction_a, std: nano::public_key nano::wallet::deterministic_insert (nano::transaction const & transaction_a, bool generate_work_a) { - nano::public_key key{ }; + nano::public_key key{}; if (store.valid_password (transaction_a)) { key = store.deterministic_insert (transaction_a); @@ -735,7 +735,7 @@ nano::public_key nano::wallet::deterministic_insert (nano::transaction const & t nano::public_key nano::wallet::deterministic_insert (uint32_t const index, bool generate_work_a) { auto transaction (wallets.tx_begin_write ()); - nano::public_key key{ }; + nano::public_key key{}; if (store.valid_password (transaction)) { key = store.deterministic_insert (transaction, index); @@ -756,7 +756,7 @@ nano::public_key nano::wallet::deterministic_insert (bool generate_work_a) nano::public_key nano::wallet::insert_adhoc (nano::raw_key const & key_a, bool generate_work_a) { - nano::public_key key{ }; + nano::public_key key{}; auto transaction (wallets.tx_begin_write ()); if (store.valid_password (transaction)) { diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 75bcc481fa..92b23cc857 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -68,7 +68,7 @@ nano::websocket::confirmation_options::confirmation_options (boost::property_tre has_account_filtering_options = true; for (auto account_l : *accounts_l) { - nano::account result_l{ }; + nano::account result_l{}; if (!result_l.decode_account (account_l.second.data ())) { // Do not insert the given raw data to keep old prefix support @@ -114,8 +114,8 @@ bool nano::websocket::confirmation_options::should_filter (nano::websocket::mess if (all_local_accounts) { auto transaction_l (wallets.tx_begin_read ()); - nano::account source_l{ }; - nano::account destination_l{ }; + nano::account source_l{}; + nano::account destination_l{}; auto decode_source_ok_l (!source_l.decode_account (source_text_l)); auto decode_destination_ok_l (!destination_l.decode_account (destination_opt_l.get ())); (void)decode_source_ok_l; @@ -141,7 +141,7 @@ bool nano::websocket::confirmation_options::update (boost::property_tree::ptree this->has_account_filtering_options = true; for (auto const & account_l : accounts_text_a) { - nano::account result_l{ }; + nano::account result_l{}; if (!result_l.decode_account (account_l.second.data ())) { // Re-encode to keep old prefix support @@ -198,7 +198,7 @@ nano::websocket::vote_options::vote_options (boost::property_tree::ptree const & { for (auto representative_l : *representatives_l) { - nano::account result_l{ }; + nano::account result_l{}; if (!result_l.decode_account (representative_l.second.data ())) { // Do not insert the given raw data to keep old prefix support diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index fb7024620b..2489782449 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -494,7 +494,7 @@ TEST (rpc, send_idempotent) request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", nano::dev::genesis_key.pub.to_account ()); - request.put ("destination", nano::account{ }.to_account ()); + request.put ("destination", nano::account{}.to_account ()); request.put ("amount", (nano::dev::constants.genesis_amount - (nano::dev::constants.genesis_amount / 4)).convert_to ()); request.put ("id", "123abc"); auto response (wait_response (system, rpc, request)); @@ -710,7 +710,7 @@ TEST (rpc, wallet_representative_set_force) auto transaction (node->wallets.tx_begin_read ()); ASSERT_EQ (key.pub, node->wallets.items.begin ()->second->store.representative (transaction)); } - nano::account representative{ }; + nano::account representative{}; while (representative != key.pub) { auto transaction (node->store.tx_begin_read ()); @@ -1007,7 +1007,7 @@ TEST (rpc, frontier) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account{ }.to_account ()); + request.put ("account", nano::account{}.to_account ()); request.put ("count", std::to_string (std::numeric_limits::max ())); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); @@ -1045,7 +1045,7 @@ TEST (rpc, frontier_limited) auto [rpc, rpc_ctx] = add_rpc (system, node); boost::property_tree::ptree request; request.put ("action", "frontiers"); - request.put ("account", nano::account{ }.to_account ()); + request.put ("account", nano::account{}.to_account ()); request.put ("count", std::to_string (100)); auto response (wait_response (system, rpc, request)); auto & frontiers_node (response.get_child ("frontiers")); diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index b92d16da79..7d597fc5c8 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -119,7 +119,7 @@ class pending_info final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info const &) const; - nano::account source{ }; + nano::account source{}; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -131,7 +131,7 @@ class pending_key final bool deserialize (nano::stream &); bool operator== (nano::pending_key const &) const; nano::account const & key () const; - nano::account account{ }; + nano::account account{}; nano::block_hash hash{ 0 }; }; @@ -202,7 +202,7 @@ class unchecked_info final void serialize (nano::stream &) const; bool deserialize (nano::stream &); std::shared_ptr block; - nano::account account{ }; + nano::account account{}; /** Seconds since posix epoch */ uint64_t modified{ 0 }; nano::signature_verification verified{ nano::signature_verification::unknown }; @@ -214,7 +214,7 @@ class block_info final public: block_info () = default; block_info (nano::account const &, nano::amount const &); - nano::account account{ }; + nano::account account{}; nano::amount balance{ 0 }; }; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 53f05d5d31..993e06d7a4 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -116,7 +116,7 @@ class rollback_visitor : public nano::block_visitor } auto balance (ledger.balance (transaction, block_a.hashables.previous)); auto is_send (block_a.hashables.balance < balance); - nano::account representative{ }; + nano::account representative{}; if (!rep_block_hash.is_zero ()) { // Move existing representation & add in amount delta diff --git a/nano/secure/store/frontier_store_partial.hpp b/nano/secure/store/frontier_store_partial.hpp index 4f75283b2b..66d05cbeae 100644 --- a/nano/secure/store/frontier_store_partial.hpp +++ b/nano/secure/store/frontier_store_partial.hpp @@ -40,7 +40,7 @@ class frontier_store_partial : public frontier_store nano::db_val value; auto status (store.get (transaction_a, tables::frontiers, nano::db_val (block_a), value)); release_assert (store.success (status) || store.not_found (status)); - nano::account result{ }; + nano::account result{}; if (store.success (status)) { result = static_cast (value); diff --git a/nano/secure/versioning.hpp b/nano/secure/versioning.hpp index b11b34495c..429de22d97 100644 --- a/nano/secure/versioning.hpp +++ b/nano/secure/versioning.hpp @@ -15,7 +15,7 @@ class pending_info_v14 final size_t db_size () const; bool deserialize (nano::stream &); bool operator== (nano::pending_info_v14 const &) const; - nano::account source{ }; + nano::account source{}; nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; @@ -44,7 +44,7 @@ class block_sideband_v14 final static size_t size (nano::block_type); nano::block_type type{ nano::block_type::invalid }; nano::block_hash successor{ 0 }; - nano::account account{ }; + nano::account account{}; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; @@ -65,7 +65,7 @@ class block_sideband_v18 final bool deserialize (nano::stream &, nano::block_type); static size_t size (nano::block_type); nano::block_hash successor{ 0 }; - nano::account account{ }; + nano::account account{}; nano::amount balance{ 0 }; uint64_t height{ 0 }; uint64_t timestamp{ 0 }; From 908a7ab10b968c04b4ed1f18fb27a22aab609626 Mon Sep 17 00:00:00 2001 From: theohax Date: Mon, 4 Oct 2021 02:30:55 +0300 Subject: [PATCH 05/10] Introduce nano::public_key::null() method instead of std::nullptr_t constructor --- nano/lib/blocks.cpp | 6 ------ nano/lib/numbers.cpp | 12 +++--------- nano/lib/numbers.hpp | 4 ++-- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 09672d1798..28996148a0 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -152,8 +152,6 @@ bool nano::block::has_sideband () const nano::account const & nano::block::representative () const { - /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account representative{}; return representative; } @@ -166,8 +164,6 @@ nano::block_hash const & nano::block::source () const nano::account const & nano::block::destination () const { - /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account destination{}; return destination; } @@ -180,8 +176,6 @@ nano::link const & nano::block::link () const nano::account const & nano::block::account () const { - /* return nano::hardened_constants::get ().not_an_account; */ - static nano::account account{}; return account; } diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index c963171613..c3d09168ff 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -67,9 +67,9 @@ nano::public_key::public_key () : { } -nano::public_key::public_key (std::nullptr_t) : - uint256_union{ nano::hardened_constants::get ().not_an_account } +const nano::public_key& nano::public_key::null () const { + return nano::hardened_constants::get ().not_an_account; } std::string nano::public_key::to_node_id () const @@ -955,15 +955,9 @@ nano::public_key::operator nano::hash_or_account const & () const return reinterpret_cast (*this); } -nano::public_key & nano::public_key::operator= (std::nullptr_t) -{ - bytes = nano::hardened_constants::get ().not_an_account.bytes; - return *this; -} - bool nano::public_key::operator== (std::nullptr_t) const { - return bytes == nano::hardened_constants::get ().not_an_account.bytes; + return bytes == null().bytes; } bool nano::public_key::operator!= (std::nullptr_t) const diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 9260fabf74..adfc4a2b31 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -116,7 +116,8 @@ class public_key final : public uint256_union using uint256_union::uint256_union; public_key (); - explicit public_key (std::nullptr_t); + + const public_key& null () const; std::string to_node_id () const; bool decode_node_id (std::string const & source_a); @@ -127,7 +128,6 @@ class public_key final : public uint256_union operator nano::link const & () const; operator nano::root const & () const; operator nano::hash_or_account const & () const; - public_key & operator= (std::nullptr_t); bool operator== (std::nullptr_t) const; bool operator!= (std::nullptr_t) const; using uint256_union::operator==; From f33d335c9223b4be849faa951029ed3ea7142f82 Mon Sep 17 00:00:00 2001 From: theohax Date: Mon, 4 Oct 2021 02:31:45 +0300 Subject: [PATCH 06/10] Fix formatting --- nano/lib/numbers.cpp | 6 +++--- nano/lib/numbers.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index c3d09168ff..5085eee9c2 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -67,9 +67,9 @@ nano::public_key::public_key () : { } -const nano::public_key& nano::public_key::null () const +const nano::public_key & nano::public_key::null () const { - return nano::hardened_constants::get ().not_an_account; + return nano::hardened_constants::get ().not_an_account; } std::string nano::public_key::to_node_id () const @@ -957,7 +957,7 @@ nano::public_key::operator nano::hash_or_account const & () const bool nano::public_key::operator== (std::nullptr_t) const { - return bytes == null().bytes; + return bytes == null ().bytes; } bool nano::public_key::operator!= (std::nullptr_t) const diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index adfc4a2b31..aad2526636 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -117,7 +117,7 @@ class public_key final : public uint256_union public_key (); - const public_key& null () const; + const public_key & null () const; std::string to_node_id () const; bool decode_node_id (std::string const & source_a); From 2afc710534ebcfddfe4a60a79cf66fe68a826215 Mon Sep 17 00:00:00 2001 From: theohax Date: Mon, 4 Oct 2021 20:28:26 +0300 Subject: [PATCH 07/10] Address code review #3 --- nano/lib/numbers.cpp | 4 ++-- nano/lib/numbers.hpp | 2 +- nano/secure/ledger.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 5085eee9c2..f2c3a2b88e 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -67,7 +67,7 @@ nano::public_key::public_key () : { } -const nano::public_key & nano::public_key::null () const +const nano::public_key & nano::public_key::null () { return nano::hardened_constants::get ().not_an_account; } @@ -148,7 +148,7 @@ nano::uint256_union::uint256_union (nano::uint256_t const & number_a) bool nano::uint256_union::operator== (nano::uint256_union const & other_a) const { - return bytes == other_a.bytes; + return this == &other_a; } // Construct a uint256_union = AES_ENC_CTR (cleartext, key, iv) diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index aad2526636..fc9542110a 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -117,7 +117,7 @@ class public_key final : public uint256_union public_key (); - const public_key & null () const; + static const public_key & null (); std::string to_node_id () const; bool decode_node_id (std::string const & source_a); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 993e06d7a4..8d96206ccc 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -959,7 +959,7 @@ nano::account const & nano::ledger::block_destination (nano::transaction const & return state_block->hashables.link.as_account (); } - return nano::hardened_constants::get ().not_an_account; + return nano::account::null (); } nano::block_hash nano::ledger::block_source (nano::transaction const & transaction_a, nano::block const & block_a) From 40cd4929e136bd1ce34e6ccdca8a9d828be6e164 Mon Sep 17 00:00:00 2001 From: theohax Date: Tue, 5 Oct 2021 15:55:20 +0300 Subject: [PATCH 08/10] Last code review addressing --- nano/core_test/node.cpp | 11 +++++++++++ nano/lib/numbers.cpp | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index bdf36925ad..731deefc62 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -20,6 +20,17 @@ namespace void add_required_children_node_config_tree (nano::jsonconfig & tree); } +TEST (node, null_account) +{ + const auto& null_account = nano::account::null(); + ASSERT_TRUE(null_account == nullptr); + ASSERT_FALSE(null_account != nullptr); + + nano::account default_account{}; + ASSERT_FALSE(default_account == nullptr); + ASSERT_TRUE(default_account != nullptr); +} + TEST (node, stop) { nano::system system (1); diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index f2c3a2b88e..47d1625098 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -148,7 +148,7 @@ nano::uint256_union::uint256_union (nano::uint256_t const & number_a) bool nano::uint256_union::operator== (nano::uint256_union const & other_a) const { - return this == &other_a; + return bytes == other_a.bytes; } // Construct a uint256_union = AES_ENC_CTR (cleartext, key, iv) @@ -957,7 +957,7 @@ nano::public_key::operator nano::hash_or_account const & () const bool nano::public_key::operator== (std::nullptr_t) const { - return bytes == null ().bytes; + return this == &null(); } bool nano::public_key::operator!= (std::nullptr_t) const From 5b0f47ba17cec2677b68cf5735d7a5159b29e760 Mon Sep 17 00:00:00 2001 From: theohax Date: Tue, 5 Oct 2021 16:17:37 +0300 Subject: [PATCH 09/10] Fix formatting --- nano/core_test/node.cpp | 12 ++++++------ nano/lib/numbers.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 731deefc62..5775f1abaf 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -22,13 +22,13 @@ void add_required_children_node_config_tree (nano::jsonconfig & tree); TEST (node, null_account) { - const auto& null_account = nano::account::null(); - ASSERT_TRUE(null_account == nullptr); - ASSERT_FALSE(null_account != nullptr); + const auto & null_account = nano::account::null (); + ASSERT_TRUE (null_account == nullptr); + ASSERT_FALSE (null_account != nullptr); - nano::account default_account{}; - ASSERT_FALSE(default_account == nullptr); - ASSERT_TRUE(default_account != nullptr); + nano::account default_account{}; + ASSERT_FALSE (default_account == nullptr); + ASSERT_TRUE (default_account != nullptr); } TEST (node, stop) diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index 47d1625098..baf78f1ea8 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -957,7 +957,7 @@ nano::public_key::operator nano::hash_or_account const & () const bool nano::public_key::operator== (std::nullptr_t) const { - return this == &null(); + return this == &null (); } bool nano::public_key::operator!= (std::nullptr_t) const From ab4d08b6c5029d07e39c7e1162ef78861fad4e34 Mon Sep 17 00:00:00 2001 From: theohax Date: Wed, 6 Oct 2021 18:02:25 +0300 Subject: [PATCH 10/10] Address code review #4 --- nano/core_test/active_transactions.cpp | 4 ++-- nano/lib/numbers.cpp | 2 +- nano/node/election.cpp | 8 ++++---- nano/secure/common.cpp | 2 +- nano/secure/common.hpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index 142da6b554..555cc9ab6e 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -50,7 +50,7 @@ TEST (active_transactions, confirm_active) nano::lock_guard guard (node2.rep_crawler.probable_reps_mutex); node2.rep_crawler.probable_reps.emplace (nano::dev::genesis_key.pub, nano::dev::constants.genesis_amount, *peers.begin ()); } - ASSERT_TIMELY (5s, election->votes ().size () != 1); // Votes were inserted (except for not_an_account) + ASSERT_TIMELY (5s, election->votes ().size () != 1); // Votes were inserted (except for the null account) auto confirm_req_count (election->confirmation_request_count.load ()); // At least one confirmation request ASSERT_GT (confirm_req_count, 0u); @@ -62,7 +62,7 @@ TEST (active_transactions, confirm_active) ASSERT_TIMELY (10s, node2.ledger.cache.cemented_count == 2 && node2.active.empty ()); // At least one more confirmation request ASSERT_GT (election->confirmation_request_count, confirm_req_count); - // Blocks were cleared (except for not_an_account) + // Blocks were cleared (except for the null account) ASSERT_EQ (1, election->blocks ().size ()); } } diff --git a/nano/lib/numbers.cpp b/nano/lib/numbers.cpp index baf78f1ea8..e6206aa512 100644 --- a/nano/lib/numbers.cpp +++ b/nano/lib/numbers.cpp @@ -957,7 +957,7 @@ nano::public_key::operator nano::hash_or_account const & () const bool nano::public_key::operator== (std::nullptr_t) const { - return this == &null (); + return bytes == null ().bytes; } bool nano::public_key::operator!= (std::nullptr_t) const diff --git a/nano/node/election.cpp b/nano/node/election.cpp index dd4069b5bb..22d3421baf 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -28,7 +28,7 @@ nano::election::election (nano::node & node_a, std::shared_ptr cons root (block_a->root ()), qualified_root (block_a->qualified_root ()) { - last_votes.emplace (nano::hardened_constants::get ().not_an_account, nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }); + last_votes.emplace (nano::account::null (), nano::vote_info{ std::chrono::steady_clock::now (), 0, block_a->hash () }); last_blocks.emplace (block_a->hash (), block_a); if (node.config.enable_voting && node.wallets.reps ().voting > 0) { @@ -319,7 +319,7 @@ void nano::election::log_votes (nano::tally_t const & tally_a, std::string const } for (auto i (last_votes.begin ()), n (last_votes.end ()); i != n; ++i) { - if (i->first != nano::hardened_constants::get ().not_an_account) + if (i->first != nullptr) { tally << boost::str (boost::format ("%1%%2% %3% %4%") % line_end % i->first.to_account () % std::to_string (i->second.timestamp) % i->second.hash.to_string ()); } @@ -459,7 +459,7 @@ size_t nano::election::insert_inactive_votes_cache (nano::inactive_cache_informa node.stats.add (nano::stat::type::election, nano::stat::detail::late_block_seconds, nano::stat::dir::in, delay.count (), true); } } - if (last_votes.size () > 1) // not_an_account + if (last_votes.size () > 1) // null account { // Even if no votes were in cache, they could be in the election confirm_if_quorum (lock); @@ -629,7 +629,7 @@ std::vector nano::election::votes_with_weight () co auto votes_l (votes ()); for (auto const & vote_l : votes_l) { - if (vote_l.first != nano::hardened_constants::get ().not_an_account) + if (vote_l.first != nullptr) { auto amount (node.ledger.cache.rep_weights.representation_get (vote_l.first)); nano::vote_with_weight_info vote_info{ vote_l.first, vote_l.second.time, vote_l.second.timestamp, vote_l.second.hash, amount }; diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 9b08b2d0d2..879c8925a7 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -115,7 +115,7 @@ nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::ne : network_a == nano::networks::nano_test_network ? nano_test_genesis : nano_live_genesis), genesis_amount{ std::numeric_limits::max () }, - burn_account{ static_cast (0) }, + burn_account{}, nano_dev_final_votes_canary_account (dev_public_key_data), nano_beta_final_votes_canary_account (beta_canary_public_key_data), nano_live_final_votes_canary_account (live_canary_public_key_data), diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 7d597fc5c8..d42d5d0f49 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -99,7 +99,7 @@ class account_info final size_t db_size () const; nano::epoch epoch () const; nano::block_hash head{ 0 }; - nano::account representative{ static_cast (0) }; + nano::account representative{}; nano::block_hash open_block{ 0 }; nano::amount balance{ 0 }; /** Seconds since posix epoch */