Refer to empty/null accounts as nano::account{nullptr} (#3388)

* Introduce null accounts as nano::account{nullptr}

* Fix formatting

* Default nano::account constructor to nano::account{0}

* Fix formatting

* Introduce nano::public_key::null() method instead of std::nullptr_t constructor

* Fix formatting

* Address code review #3

* Last code review addressing

* Fix formatting

* Address code review #4
This commit is contained in:
theohax 2021-10-06 19:34:48 +03:00 committed by GitHub
commit 1eefcaf70d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 195 additions and 123 deletions

View file

@ -50,7 +50,7 @@ TEST (active_transactions, confirm_active)
nano::lock_guard<nano::mutex> 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 ());
}
}

View file

@ -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{};
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{};
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<nano::account> accounts2;
nano::account previous (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,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{};
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);

View file

@ -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<unsigned>::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{}, 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);

View file

@ -797,7 +797,7 @@ TEST (tcp_listener, tcp_node_id_handshake)
ASSERT_TIMELY (5s, write_done);
boost::optional<std::pair<nano::account, nano::signature>> response_zero (std::make_pair (nano::account (0), nano::signature (0)));
boost::optional<std::pair<nano::account, nano::signature>> 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<bool> done (false);

View file

@ -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);

View file

@ -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{};
{
auto transaction (node1.wallets.tx_begin_read ());
auto iterator2 (system.wallet (0)->store.begin (transaction));

View file

@ -335,7 +335,7 @@ TEST (wallet, rekey)
TEST (account, encode_zero)
{
nano::account number0 (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 (0);
nano::account number0{};
std::string str0;
number0.encode_account (str0);
str0[16] ^= 1;

View file

@ -3,6 +3,7 @@
#include <nano/lib/memory.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/threading.hpp>
#include <nano/secure/common.hpp>
#include <crypto/cryptopp/words.h>
@ -151,8 +152,8 @@ bool nano::block::has_sideband () const
nano::account const & nano::block::representative () const
{
static nano::account rep{ 0 };
return rep;
static nano::account representative{};
return representative;
}
nano::block_hash const & nano::block::source () const
@ -163,7 +164,7 @@ nano::block_hash const & nano::block::source () const
nano::account const & nano::block::destination () const
{
static nano::account destination{ 0 };
static nano::account destination{};
return destination;
}
@ -175,7 +176,7 @@ nano::link const & nano::block::link () const
nano::account const & nano::block::account () const
{
static nano::account account{ 0 };
static nano::account account{};
return account;
}
@ -363,6 +364,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 +527,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 +795,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 +1070,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 +1519,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) :

View file

@ -64,7 +64,7 @@ public:
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{};
nano::amount balance{ 0 };
uint64_t height{ 0 };
uint64_t timestamp{ 0 };

View file

@ -3,6 +3,7 @@
#include <nano/crypto_lib/secure_memory.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/utility.hpp>
#include <nano/secure/common.hpp>
#include <crypto/cryptopp/aes.h>
#include <crypto/cryptopp/modes.h>
@ -61,6 +62,16 @@ std::string nano::public_key::to_account () const
return result;
}
nano::public_key::public_key () :
uint256_union{ 0 }
{
}
const nano::public_key & nano::public_key::null ()
{
return nano::hardened_constants::get ().not_an_account;
}
std::string nano::public_key::to_node_id () const
{
return to_account ().replace (0, 4, "node");
@ -781,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)
{
@ -939,6 +955,16 @@ nano::public_key::operator nano::hash_or_account const & () const
return reinterpret_cast<nano::hash_or_account const &> (*this);
}
bool nano::public_key::operator== (std::nullptr_t) const
{
return bytes == null ().bytes;
}
bool nano::public_key::operator!= (std::nullptr_t) const
{
return !(*this == nullptr);
}
nano::block_hash::operator nano::link const & () const
{
return reinterpret_cast<nano::link const &> (*this);

View file

@ -115,6 +115,10 @@ class public_key final : public uint256_union
public:
using uint256_union::uint256_union;
public_key ();
static const public_key & null ();
std::string to_node_id () const;
bool decode_node_id (std::string const & source_a);
void encode_account (std::string &) const;
@ -124,6 +128,10 @@ public:
operator nano::link const & () const;
operator nano::root const & () const;
operator nano::hash_or_account const & () const;
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
@ -137,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;

View file

@ -19,6 +19,6 @@ public:
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{};
};
}

View file

@ -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{};
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{};
bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ());
if (previous_pruned)
{

View file

@ -180,11 +180,11 @@ void nano::active_transactions::block_cemented_callback (std::shared_ptr<nano::b
{
if (election_status_type == nano::election_status_type::inactive_confirmation_height)
{
nano::account account (0);
nano::account account{};
nano::uint128_t amount (0);
bool is_state_send (false);
bool is_state_epoch (false);
nano::account pending_account (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::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()), std::chrono::duration_values<std::chrono::milliseconds>::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_ptr<nano::b
add_recently_cemented (status_l);
auto destination (block_a->link ().is_zero () ? block_a->destination () : block_a->link ().as_account ());
node.receive_confirmed (transaction, hash, destination);
nano::account account (0);
nano::account account{};
nano::uint128_t amount (0);
bool is_state_send (false);
bool is_state_epoch (false);
nano::account pending_account (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;

View file

@ -279,7 +279,7 @@ private:
void confirm_expired_frontiers_pessimistically (nano::transaction const &, uint64_t, uint64_t &);
void frontiers_confirmation (nano::unique_lock<nano::mutex> &);
bool insert_election_from_frontiers_confirmation (std::shared_ptr<nano::block> const &, nano::account const &, nano::uint128_t, nano::election_behavior);
nano::account next_frontier_account{ 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;

View file

@ -82,7 +82,7 @@ public:
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<uint32_t>::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<uint32_t>::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<nano::account> &);
void run_bootstrap ();

View file

@ -23,9 +23,9 @@ nano::bootstrap_attempt::bootstrap_attempt (std::shared_ptr<nano::node> 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)

View file

@ -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<nano::bootstrap_client> const & connection_a, std::shared_ptr<nano::bootstrap_attempt> const & attempt_a, nano::pull_info const & pull_a) :
connection (connection_a),
attempt (attempt_a),
known_account (0),
known_account{},
pull (pull_a),
pull_blocks (0),
unexpected_count (0)

View file

@ -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{}, 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{}, nano::block_hash (0));
}
}
// Retrieving accounts from deque

View file

@ -33,7 +33,7 @@ public:
std::weak_ptr<nano::bulk_push_client> push;
std::deque<nano::pull_info> frontier_pulls;
std::vector<std::pair<nano::block_hash, nano::block_hash>> bulk_push_targets;
nano::account start_account{ 0 };
nano::account start_account{};
std::atomic<unsigned> account_count{ 0 };
uint32_t frontiers_age;
};

View file

@ -66,7 +66,7 @@ public:
std::atomic<bool> 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{};
std::chrono::steady_clock::time_point last_telemetry_req{ std::chrono::steady_clock::time_point () };
};
}

View file

@ -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));

View file

@ -354,7 +354,7 @@ class telemetry_data
{
public:
nano::signature signature{ 0 };
nano::account node_id{ 0 };
nano::account node_id{};
uint64_t block_count{ 0 };
uint64_t cemented_count{ 0 };
uint64_t unchecked_count{ 0 };

View file

@ -28,7 +28,7 @@ nano::election::election (nano::node & node_a, std::shared_ptr<nano::block> 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::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 != node.network_params.random.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::vote_with_weight_info> 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 != 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 };

View file

@ -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{};
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);

View file

@ -144,7 +144,8 @@ void nano::ipc::broker::broadcast (std::shared_ptr<nanoapi::EventConfirmationT>
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{};
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;

View file

@ -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{};
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{};
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{}, 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<std::string> ());
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{};
boost::optional<std::string> account_text (request.get_optional<std::string> ("account"));
if (!ec && account_text.is_initialized ())
{
account = account_impl (account_text.get ());
}
nano::account representative (0);
nano::account representative{};
boost::optional<std::string> representative_text (request.get_optional<std::string> ("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{};
boost::optional<std::string> destination_text (request.get_optional<std::string> ("destination"));
if (!ec && destination_text.is_initialized ())
{
@ -1739,7 +1739,7 @@ void nano::json_handler::bootstrap_any ()
const bool force = request.get<bool> ("force", false);
if (!node.flags.disable_legacy_bootstrap)
{
nano::account start_account (0);
nano::account start_account{};
boost::optional<std::string> account_text (request.get_optional<std::string> ("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<std::string> ("start"));
nano::account start_account (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 (0);
nano::account start{};
boost::optional<std::string> account_text (request.get_optional<std::string> ("account"));
if (account_text.is_initialized ())
{

View file

@ -1481,7 +1481,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{};
uint64_t modified{ 0 };
};
class account_tag

View file

@ -248,7 +248,7 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml)
{
preconfigured_representatives.clear ();
toml.array_entries_required<std::string> ("preconfigured_representatives", [this, &toml] (std::string entry) {
nano::account representative (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<std::string> ([this, &json] (std::string entry) {
nano::account representative (0);
nano::account representative{};
if (representative.decode_account (entry))
{
json.get_error ().set ("Invalid representative account: " + entry);

View file

@ -41,7 +41,7 @@ public:
{
return account == other_a.account;
}
nano::account account{ 0 };
nano::account account{};
nano::amount weight{ 0 };
std::shared_ptr<nano::transport::channel> channel;
std::chrono::steady_clock::time_point last_request{ std::chrono::steady_clock::time_point () };

View file

@ -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{};
// 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{};
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{};
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{};
auto transaction (wallets.tx_begin_write ());
if (store.valid_password (transaction))
{

View file

@ -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{};
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{};
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;
@ -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{};
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{};
if (!result_l.decode_account (representative_l.second.data ()))
{
// Do not insert the given raw data to keep old prefix support

View file

@ -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{}.to_account ());
request.put ("amount", (nano::dev::constants.genesis_amount - (nano::dev::constants.genesis_amount / 4)).convert_to<std::string> ());
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{};
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{}.to_account ());
request.put ("count", std::to_string (std::numeric_limits<uint64_t>::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{}.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));

View file

@ -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<nano::block> 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<nano::uint128_t>::max () },
burn_account (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),
@ -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 ());

View file

@ -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 @@ public:
};
/**
* Latest information about an account
*/
* Latest information about an account
*/
class account_info final
{
public:
@ -99,7 +99,7 @@ public:
size_t db_size () const;
nano::epoch epoch () const;
nano::block_hash head{ 0 };
nano::account representative{ 0 };
nano::account representative{};
nano::block_hash open_block{ 0 };
nano::amount balance{ 0 };
/** Seconds since posix epoch */
@ -109,8 +109,8 @@ public:
};
/**
* Information on an uncollected send
*/
* Information on an uncollected send
*/
class pending_info final
{
public:
@ -119,7 +119,7 @@ public:
size_t db_size () const;
bool deserialize (nano::stream &);
bool operator== (nano::pending_info const &) const;
nano::account source{ 0 };
nano::account source{};
nano::amount amount{ 0 };
nano::epoch epoch{ nano::epoch::epoch_0 };
};
@ -131,7 +131,7 @@ public:
bool deserialize (nano::stream &);
bool operator== (nano::pending_key const &) const;
nano::account const & key () const;
nano::account account{ 0 };
nano::account account{};
nano::block_hash hash{ 0 };
};
@ -141,19 +141,19 @@ public:
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<uint8_t, 16> & 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<uint8_t, 16> & 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 @@ public:
};
/**
* 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 @@ public:
void serialize (nano::stream &) const;
bool deserialize (nano::stream &);
std::shared_ptr<nano::block> block;
nano::account account{ 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{ 0 };
nano::account account{};
nano::amount balance{ 0 };
};
@ -275,8 +275,8 @@ public:
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<nano::block> & 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 */
@ -442,7 +446,6 @@ public:
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;
@ -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:

View file

@ -116,7 +116,7 @@ public:
}
auto balance (ledger.balance (transaction, block_a.hashables.previous));
auto is_send (block_a.hashables.balance < balance);
nano::account representative{ 0 };
nano::account representative{};
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::account::null ();
}
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);

View file

@ -40,7 +40,7 @@ public:
nano::db_val<Val> value;
auto status (store.get (transaction_a, tables::frontiers, nano::db_val<Val> (block_a), value));
release_assert (store.success (status) || store.not_found (status));
nano::account result (0);
nano::account result{};
if (store.success (status))
{
result = static_cast<nano::account> (value);

View file

@ -15,7 +15,7 @@ public:
size_t db_size () const;
bool deserialize (nano::stream &);
bool operator== (nano::pending_info_v14 const &) const;
nano::account source{ 0 };
nano::account source{};
nano::amount amount{ 0 };
nano::epoch epoch{ nano::epoch::epoch_0 };
};
@ -44,7 +44,7 @@ public:
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{};
nano::amount balance{ 0 };
uint64_t height{ 0 };
uint64_t timestamp{ 0 };
@ -65,7 +65,7 @@ public:
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{};
nano::amount balance{ 0 };
uint64_t height{ 0 };
uint64_t timestamp{ 0 };