From dd8a810f2bec2a607755e3cf60187b89776a90e6 Mon Sep 17 00:00:00 2001 From: Wesley Shillingford Date: Tue, 26 Mar 2019 13:25:47 +0000 Subject: [PATCH] Various minor coding style updates (#1863) * Various coding style updates * Remove unnecessary change to blocks.cpp * Formatting * Re-add necessary node_config default constructor --- nano/lib/numbers.hpp | 12 ++--- nano/lib/plat/darwin/thread_role.cpp | 2 +- nano/lib/plat/freebsd/thread_role.cpp | 2 +- nano/lib/plat/linux/thread_role.cpp | 2 +- nano/lib/plat/windows/priority.cpp | 10 ++-- nano/lib/plat/windows/thread_role.cpp | 9 ++-- nano/lib/utility.cpp | 3 -- nano/lib/utility.hpp | 7 ++- nano/lib/work.hpp | 4 +- nano/node/blockprocessor.hpp | 4 +- nano/node/bootstrap.cpp | 11 +--- nano/node/bootstrap.hpp | 54 +++++++++---------- nano/node/common.hpp | 40 +++++++------- nano/node/node.cpp | 18 ++----- nano/node/node.hpp | 75 +++++++++++++-------------- nano/node/nodeconfig.cpp | 22 +------- nano/node/nodeconfig.hpp | 44 ++++++++-------- nano/node/stats.cpp | 7 +-- nano/node/stats.hpp | 17 +++--- nano/node/testing.cpp | 4 -- nano/node/testing.hpp | 8 +-- nano/node/transport/udp.hpp | 10 ++-- nano/node/voting.hpp | 6 +-- nano/node/wallet.hpp | 12 ++--- nano/node/websocketconfig.hpp | 3 +- nano/node/xorshift.hpp | 8 +-- nano/secure/blockstore.hpp | 14 ++--- nano/secure/common.hpp | 26 +++++----- nano/secure/ledger.hpp | 4 +- nano/secure/versioning.hpp | 14 ++--- 30 files changed, 190 insertions(+), 262 deletions(-) diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 737bfeee..218d7b9a 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -38,11 +38,9 @@ nano::uint128_t const Gxrb_ratio = nano::uint128_t ("100000000000000000000000000 nano::uint128_t const Mxrb_ratio = nano::uint128_t ("1000000000000000000000000000000"); // 10^30 nano::uint128_t const kxrb_ratio = nano::uint128_t ("1000000000000000000000000000"); // 10^27 nano::uint128_t const xrb_ratio = nano::uint128_t ("1000000000000000000000000"); // 10^24 -nano::uint128_t const mxrb_ratio = nano::uint128_t ("1000000000000000000000"); // 10^21 -nano::uint128_t const uxrb_ratio = nano::uint128_t ("1000000000000000000"); // 10^18 nano::uint128_t const raw_ratio = nano::uint128_t ("1"); // 10^0 -union uint128_union +union uint128_union final { public: uint128_union () = default; @@ -52,7 +50,6 @@ public: */ uint128_union (std::string const &); uint128_union (uint64_t); - uint128_union (nano::uint128_union const &) = default; uint128_union (nano::uint128_t const &); bool operator== (nano::uint128_union const &) const; bool operator!= (nano::uint128_union const &) const; @@ -77,7 +74,7 @@ public: // Balances are 128 bit. using amount = uint128_union; class raw_key; -union uint256_union +union uint256_union final { uint256_union () = default; /** @@ -116,17 +113,16 @@ using account = uint256_union; using public_key = uint256_union; using private_key = uint256_union; using secret_key = uint256_union; -class raw_key +class raw_key final { public: - raw_key () = default; ~raw_key (); void decrypt (nano::uint256_union const &, nano::raw_key const &, uint128_union const &); bool operator== (nano::raw_key const &) const; bool operator!= (nano::raw_key const &) const; nano::uint256_union data; }; -union uint512_union +union uint512_union final { uint512_union () = default; uint512_union (nano::uint256_union const &, nano::uint256_union const &); diff --git a/nano/lib/plat/darwin/thread_role.cpp b/nano/lib/plat/darwin/thread_role.cpp index 91ba4220..796bc823 100644 --- a/nano/lib/plat/darwin/thread_role.cpp +++ b/nano/lib/plat/darwin/thread_role.cpp @@ -1,7 +1,7 @@ #include #include -void nano::thread_role::set_os_name (std::string thread_name) +void nano::thread_role::set_os_name (std::string const & thread_name) { pthread_setname_np (thread_name.c_str ()); } diff --git a/nano/lib/plat/freebsd/thread_role.cpp b/nano/lib/plat/freebsd/thread_role.cpp index aca4cd09..c7602210 100644 --- a/nano/lib/plat/freebsd/thread_role.cpp +++ b/nano/lib/plat/freebsd/thread_role.cpp @@ -2,7 +2,7 @@ #include #include -void nano::thread_role::set_os_name (std::string thread_name) +void nano::thread_role::set_os_name (std::string const & thread_name) { pthread_set_name_np (pthread_self (), thread_name.c_str ()); } diff --git a/nano/lib/plat/linux/thread_role.cpp b/nano/lib/plat/linux/thread_role.cpp index 9e0c3958..d14d71e7 100644 --- a/nano/lib/plat/linux/thread_role.cpp +++ b/nano/lib/plat/linux/thread_role.cpp @@ -1,7 +1,7 @@ #include #include -void nano::thread_role::set_os_name (std::string thread_name) +void nano::thread_role::set_os_name (std::string const & thread_name) { pthread_setname_np (pthread_self (), thread_name.c_str ()); } diff --git a/nano/lib/plat/windows/priority.cpp b/nano/lib/plat/windows/priority.cpp index d081e9c6..e9945b0b 100644 --- a/nano/lib/plat/windows/priority.cpp +++ b/nano/lib/plat/windows/priority.cpp @@ -1,8 +1,8 @@ -#include - #include - -void nano::work_thread_reprioritize () +namespace nano { - auto SUCCESS (SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN)); +void work_thread_reprioritize () +{ + SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN); +} } diff --git a/nano/lib/plat/windows/thread_role.cpp b/nano/lib/plat/windows/thread_role.cpp index 9c5b145c..f0ed8187 100644 --- a/nano/lib/plat/windows/thread_role.cpp +++ b/nano/lib/plat/windows/thread_role.cpp @@ -3,13 +3,10 @@ #include #include -typedef HRESULT (*SetThreadDescription_t) (HANDLE, PCWSTR); - -void nano::thread_role::set_os_name (std::string thread_name) +void nano::thread_role::set_os_name (std::string const & thread_name) { - SetThreadDescription_t SetThreadDescription_local; - - SetThreadDescription_local = (SetThreadDescription_t)GetProcAddress (GetModuleHandle (TEXT ("kernel32.dll")), "SetThreadDescription"); + using SetThreadDescription_t = HRESULT (*) (HANDLE, PCWSTR); + SetThreadDescription_t SetThreadDescription_local = (SetThreadDescription_t)GetProcAddress (GetModuleHandle (TEXT ("kernel32.dll")), "SetThreadDescription"); if (SetThreadDescription_local) { std::wstring thread_name_wide (thread_name.begin (), thread_name.end ()); diff --git a/nano/lib/utility.cpp b/nano/lib/utility.cpp index 0b1b036f..64015f7a 100644 --- a/nano/lib/utility.cpp +++ b/nano/lib/utility.cpp @@ -96,9 +96,6 @@ namespace thread_role case nano::thread_role::name::signature_checking: thread_role_name_string = "Signature check"; break; - case nano::thread_role::name::slow_db_upgrade: - thread_role_name_string = "Slow db upgrade"; - break; } /* diff --git a/nano/lib/utility.hpp b/nano/lib/utility.hpp index 4e574861..86b3cf3d 100644 --- a/nano/lib/utility.hpp +++ b/nano/lib/utility.hpp @@ -84,8 +84,7 @@ namespace thread_role wallet_actions, bootstrap_initiator, voting, - signature_checking, - slow_db_upgrade, + signature_checking }; /* * Get/Set the identifier for the current thread @@ -101,7 +100,7 @@ namespace thread_role /* * Internal only, should not be called directly */ - void set_os_name (std::string); + void set_os_name (std::string const &); } namespace thread_attributes @@ -110,7 +109,7 @@ namespace thread_attributes } template -class observer_set +class observer_set final { public: void add (std::function const & observer_a) diff --git a/nano/lib/work.hpp b/nano/lib/work.hpp index 9a848181..524e4bcb 100644 --- a/nano/lib/work.hpp +++ b/nano/lib/work.hpp @@ -18,14 +18,14 @@ bool work_validate (nano::block_hash const &, uint64_t, uint64_t * = nullptr); bool work_validate (nano::block const &, uint64_t * = nullptr); uint64_t work_value (nano::block_hash const &, uint64_t); class opencl_work; -class work_item +class work_item final { public: nano::uint256_union item; std::function const &)> callback; uint64_t difficulty; }; -class work_pool +class work_pool final { public: work_pool (unsigned, std::function (nano::uint256_union const &, uint64_t)> = nullptr); diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index 8b822148..afca5be8 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -27,10 +27,10 @@ public: * Processing blocks is a potentially long IO operation. * This class isolates block insertion from other operations like servicing network operations */ -class block_processor +class block_processor final { public: - block_processor (nano::node &); + explicit block_processor (nano::node &); ~block_processor (); void stop (); void flush (); diff --git a/nano/node/bootstrap.cpp b/nano/node/bootstrap.cpp index 817faa9d..0b6e81f3 100644 --- a/nano/node/bootstrap.cpp +++ b/nano/node/bootstrap.cpp @@ -841,20 +841,11 @@ void nano::bulk_pull_account_client::receive_pending () }); } -nano::pull_info::pull_info () : -account (0), -end (0), -count (0), -attempts (0) -{ -} - nano::pull_info::pull_info (nano::account const & account_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a) : account (account_a), head (head_a), end (end_a), -count (count_a), -attempts (0) +count (count_a) { } diff --git a/nano/node/bootstrap.hpp b/nano/node/bootstrap.hpp index 0abdb56a..6993b450 100644 --- a/nano/node/bootstrap.hpp +++ b/nano/node/bootstrap.hpp @@ -28,10 +28,10 @@ enum class sync_result error, fork }; -class socket : public std::enable_shared_from_this +class socket final : public std::enable_shared_from_this { public: - socket (std::shared_ptr); + explicit socket (std::shared_ptr); void async_connect (nano::tcp_endpoint const &, std::function); void async_read (std::shared_ptr>, size_t, std::function); void async_write (std::shared_ptr>, std::function); @@ -53,14 +53,14 @@ class bootstrap_client; class pull_info { public: - typedef nano::bulk_pull::count_t count_t; - pull_info (); + using count_t = nano::bulk_pull::count_t; + pull_info () = default; pull_info (nano::account const &, nano::block_hash const &, nano::block_hash const &, count_t = 0); - nano::account account; - nano::block_hash head; - nano::block_hash end; - count_t count; - unsigned attempts; + nano::account account{ 0 }; + nano::block_hash head{ 0 }; + nano::block_hash end{ 0 }; + count_t count{ 0 }; + unsigned attempts{ 0 }; }; enum class bootstrap_mode { @@ -71,10 +71,10 @@ enum class bootstrap_mode class frontier_req_client; class bulk_push_client; class bulk_pull_account_client; -class bootstrap_attempt : public std::enable_shared_from_this +class bootstrap_attempt final : public std::enable_shared_from_this { public: - bootstrap_attempt (std::shared_ptr node_a); + explicit bootstrap_attempt (std::shared_ptr node_a); ~bootstrap_attempt (); void run (); std::shared_ptr connection (std::unique_lock &); @@ -135,10 +135,10 @@ public: // Wallet lazy bootstrap std::deque wallet_accounts; }; -class frontier_req_client : public std::enable_shared_from_this +class frontier_req_client final : public std::enable_shared_from_this { public: - frontier_req_client (std::shared_ptr); + explicit frontier_req_client (std::shared_ptr); ~frontier_req_client (); void run (); void receive_frontier (); @@ -158,7 +158,7 @@ public: std::deque> accounts; static size_t constexpr size_frontier = sizeof (nano::account) + sizeof (nano::block_hash); }; -class bulk_pull_client : public std::enable_shared_from_this +class bulk_pull_client final : public std::enable_shared_from_this { public: bulk_pull_client (std::shared_ptr, nano::pull_info const &); @@ -175,7 +175,7 @@ public: uint64_t total_blocks; uint64_t unexpected_count; }; -class bootstrap_client : public std::enable_shared_from_this +class bootstrap_client final : public std::enable_shared_from_this { public: bootstrap_client (std::shared_ptr, std::shared_ptr, std::shared_ptr); @@ -193,10 +193,10 @@ public: std::atomic pending_stop; std::atomic hard_stop; }; -class bulk_push_client : public std::enable_shared_from_this +class bulk_push_client final : public std::enable_shared_from_this { public: - bulk_push_client (std::shared_ptr const &); + explicit bulk_push_client (std::shared_ptr const &); ~bulk_push_client (); void start (); void push (nano::transaction const &); @@ -206,7 +206,7 @@ public: std::promise promise; std::pair current_target; }; -class bulk_pull_account_client : public std::enable_shared_from_this +class bulk_pull_account_client final : public std::enable_shared_from_this { public: bulk_pull_account_client (std::shared_ptr, nano::account const &); @@ -217,10 +217,10 @@ public: nano::account account; uint64_t total_blocks; }; -class bootstrap_initiator +class bootstrap_initiator final { public: - bootstrap_initiator (nano::node &); + explicit bootstrap_initiator (nano::node &); ~bootstrap_initiator (); void bootstrap (nano::endpoint const &, bool add_to_peers = true); void bootstrap (); @@ -248,7 +248,7 @@ private: std::unique_ptr collect_seq_con_info (bootstrap_initiator & bootstrap_initiator, const std::string & name); class bootstrap_server; -class bootstrap_listener +class bootstrap_listener final { public: bootstrap_listener (boost::asio::io_context &, uint16_t, nano::node &); @@ -272,7 +272,7 @@ private: std::unique_ptr collect_seq_con_info (bootstrap_listener & bootstrap_listener, const std::string & name); class message; -class bootstrap_server : public std::enable_shared_from_this +class bootstrap_server final : public std::enable_shared_from_this { public: bootstrap_server (std::shared_ptr, std::shared_ptr); @@ -294,7 +294,7 @@ public: std::queue> requests; }; class bulk_pull; -class bulk_pull_server : public std::enable_shared_from_this +class bulk_pull_server final : public std::enable_shared_from_this { public: bulk_pull_server (std::shared_ptr const &, std::unique_ptr); @@ -313,7 +313,7 @@ public: nano::bulk_pull::count_t sent_count; }; class bulk_pull_account; -class bulk_pull_account_server : public std::enable_shared_from_this +class bulk_pull_account_server final : public std::enable_shared_from_this { public: bulk_pull_account_server (std::shared_ptr const &, std::unique_ptr); @@ -333,10 +333,10 @@ public: bool pending_include_address; bool invalid_request; }; -class bulk_push_server : public std::enable_shared_from_this +class bulk_push_server final : public std::enable_shared_from_this { public: - bulk_push_server (std::shared_ptr const &); + explicit bulk_push_server (std::shared_ptr const &); void receive (); void received_type (); void received_block (boost::system::error_code const &, size_t, nano::block_type); @@ -344,7 +344,7 @@ public: std::shared_ptr connection; }; class frontier_req; -class frontier_req_server : public std::enable_shared_from_this +class frontier_req_server final : public std::enable_shared_from_this { public: frontier_req_server (std::shared_ptr const &, std::unique_ptr); diff --git a/nano/node/common.hpp b/nano/node/common.hpp index f61edd18..680e7fc3 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -186,10 +186,10 @@ enum class bulk_pull_account_flags : uint8_t pending_hash_amount_and_address = 0x2 }; class message_visitor; -class message_header +class message_header final { public: - message_header (nano::message_type); + explicit message_header (nano::message_type); message_header (bool &, nano::stream &); void serialize (nano::stream &) const; bool deserialize (nano::stream &); @@ -212,8 +212,8 @@ public: class message { public: - message (nano::message_type); - message (nano::message_header const &); + explicit message (nano::message_type); + explicit message (nano::message_header const &); virtual ~message () = default; virtual void serialize (nano::stream &) const = 0; virtual void visit (nano::message_visitor &) const = 0; @@ -227,7 +227,7 @@ public: nano::message_header header; }; class work_pool; -class message_parser +class message_parser final { public: enum class parse_status @@ -261,11 +261,11 @@ public: std::string status_string (); static const size_t max_safe_udp_message_size; }; -class keepalive : public message +class keepalive final : public message { public: - keepalive (bool &, nano::stream &, nano::message_header const &); keepalive (); + keepalive (bool &, nano::stream &, nano::message_header const &); void visit (nano::message_visitor &) const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &); @@ -273,22 +273,22 @@ public: std::array peers; static size_t constexpr size = 8 * (16 + 2); }; -class publish : public message +class publish final : public message { public: publish (bool &, nano::stream &, nano::message_header const &, nano::block_uniquer * = nullptr); - publish (std::shared_ptr); + explicit publish (std::shared_ptr); void visit (nano::message_visitor &) const override; void serialize (nano::stream &) const override; bool deserialize (nano::stream &, nano::block_uniquer * = nullptr); bool operator== (nano::publish const &) const; std::shared_ptr block; }; -class confirm_req : public message +class confirm_req final : public message { public: confirm_req (bool &, nano::stream &, nano::message_header const &, nano::block_uniquer * = nullptr); - confirm_req (std::shared_ptr); + explicit confirm_req (std::shared_ptr); confirm_req (std::vector> const &); confirm_req (nano::block_hash const &, nano::block_hash const &); void serialize (nano::stream &) const override; @@ -299,17 +299,17 @@ public: std::vector> roots_hashes; std::string roots_string () const; }; -class confirm_ack : public message +class confirm_ack final : public message { public: confirm_ack (bool &, nano::stream &, nano::message_header const &, nano::vote_uniquer * = nullptr); - confirm_ack (std::shared_ptr); + explicit confirm_ack (std::shared_ptr); void serialize (nano::stream &) const override; void visit (nano::message_visitor &) const override; bool operator== (nano::confirm_ack const &) const; std::shared_ptr vote; }; -class frontier_req : public message +class frontier_req final : public message { public: frontier_req (); @@ -323,10 +323,10 @@ public: uint32_t count; static size_t constexpr size = sizeof (start) + sizeof (age) + sizeof (count); }; -class bulk_pull : public message +class bulk_pull final : public message { public: - typedef uint32_t count_t; + using count_t = uint32_t; bulk_pull (); bulk_pull (bool &, nano::stream &, nano::message_header const &); void serialize (nano::stream &) const override; @@ -341,7 +341,7 @@ public: static size_t constexpr extended_parameters_size = 8; static size_t constexpr size = sizeof (start) + sizeof (end); }; -class bulk_pull_account : public message +class bulk_pull_account final : public message { public: bulk_pull_account (); @@ -354,16 +354,16 @@ public: bulk_pull_account_flags flags; static size_t constexpr size = sizeof (account) + sizeof (minimum_amount) + sizeof (bulk_pull_account_flags); }; -class bulk_push : public message +class bulk_push final : public message { public: bulk_push (); - bulk_push (nano::message_header const &); + explicit bulk_push (nano::message_header const &); void serialize (nano::stream &) const override; bool deserialize (nano::stream &); void visit (nano::message_visitor &) const override; }; -class node_id_handshake : public message +class node_id_handshake final : public message { public: node_id_handshake (bool &, nano::stream &, nano::message_header const &); diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 8f4544a6..acc667c7 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -623,13 +623,7 @@ std::unique_ptr collect_seq_con_info (alarm & alarm, con } } -nano::node_init::node_init () : -block_store_init (false), -wallet_init (false) -{ -} - -bool nano::node_init::error () +bool nano::node_init::error () const { return block_store_init || wallet_init || wallets_store_init; } @@ -2497,12 +2491,6 @@ std::shared_ptr nano::node::shared () return shared_from_this (); } -nano::election_vote_result::election_vote_result () : -replay (false), -processed (false) -{ -} - nano::election_vote_result::election_vote_result (bool replay_a, bool processed_a) { replay = replay_a; @@ -2555,7 +2543,7 @@ void nano::election::stop () stopped = true; } -bool nano::election::have_quorum (nano::tally_t const & tally_a, nano::uint128_t tally_sum) +bool nano::election::have_quorum (nano::tally_t const & tally_a, nano::uint128_t tally_sum) const { bool result = false; if (tally_sum >= node.config.online_weight_minimum.number ()) @@ -2620,7 +2608,7 @@ void nano::election::confirm_if_quorum (nano::transaction const & transaction_a) } } -void nano::election::log_votes (nano::tally_t const & tally_a) +void nano::election::log_votes (nano::tally_t const & tally_a) const { std::stringstream tally; tally << boost::str (boost::format ("\nVote tally for root %1%") % status.winner->root ().to_string ()); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 3008bf09..03d825c8 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -41,7 +41,7 @@ namespace nano { class channel; class node; -class election_status +class election_status final { public: std::shared_ptr winner; @@ -49,22 +49,22 @@ public: std::chrono::milliseconds election_end; std::chrono::milliseconds election_duration; }; -class vote_info +class vote_info final { public: std::chrono::steady_clock::time_point time; uint64_t sequence; nano::block_hash hash; }; -class election_vote_result +class election_vote_result final { public: - election_vote_result (); + election_vote_result () = default; election_vote_result (bool, bool); - bool replay; - bool processed; + bool replay{ false }; + bool processed{ false }; }; -class election : public std::enable_shared_from_this +class election final : public std::enable_shared_from_this { std::function)> confirmation_action; @@ -73,13 +73,13 @@ public: nano::election_vote_result vote (nano::account, uint64_t, nano::block_hash); nano::tally_t tally (nano::transaction const &); // Check if we have vote quorum - bool have_quorum (nano::tally_t const &, nano::uint128_t); + bool have_quorum (nano::tally_t const &, nano::uint128_t) const; // Change our winner to agree with the network void compute_rep_votes (nano::transaction const &); void confirm_once (); // Confirm this block if quorum is met void confirm_if_quorum (nano::transaction const &); - void log_votes (nano::tally_t const &); + void log_votes (nano::tally_t const &) const; bool publish (std::shared_ptr block_a); size_t last_votes_size (); void update_dependent (); @@ -95,7 +95,7 @@ public: unsigned announcements; std::unordered_set dependent_blocks; }; -class conflict_info +class conflict_info final { public: nano::qualified_root root; @@ -105,10 +105,10 @@ public: }; // Core class for determining consensus // Holds all active blocks i.e. recently added blocks that need confirmation -class active_transactions +class active_transactions final { public: - active_transactions (nano::node &); + explicit active_transactions (nano::node &); ~active_transactions (); // Start an election for a block // Call action with confirmed block, may be different than what we started with @@ -170,17 +170,17 @@ private: std::unique_ptr collect_seq_con_info (active_transactions & active_transactions, const std::string & name); -class operation +class operation final { public: bool operator> (nano::operation const &) const; std::chrono::steady_clock::time_point wakeup; std::function function; }; -class alarm +class alarm final { public: - alarm (boost::asio::io_context &); + explicit alarm (boost::asio::io_context &); ~alarm (); void add (std::chrono::steady_clock::time_point const &, std::function const &); void run (); @@ -193,17 +193,17 @@ public: std::unique_ptr collect_seq_con_info (alarm & alarm, const std::string & name); -class gap_information +class gap_information final { public: std::chrono::steady_clock::time_point arrival; nano::block_hash hash; std::unordered_set voters; }; -class gap_cache +class gap_cache final { public: - gap_cache (nano::node &); + explicit gap_cache (nano::node &); void add (nano::transaction const &, nano::block_hash const &, std::chrono::steady_clock::time_point = std::chrono::steady_clock::now ()); void vote (std::shared_ptr); nano::uint128_t bootstrap_threshold (nano::transaction const &); @@ -222,7 +222,7 @@ public: std::unique_ptr collect_seq_con_info (gap_cache & gap_cache, const std::string & name); class work_pool; -class block_arrival_info +class block_arrival_info final { public: std::chrono::steady_clock::time_point arrival; @@ -230,7 +230,7 @@ public: }; // This class tracks blocks that are probably live because they arrived in a UDP packet // This gives a fairly reliable way to differentiate between blocks being inserted via bootstrap or new, live blocks. -class block_arrival +class block_arrival final { public: // Return `true' to indicated an error if the block has already been inserted @@ -249,7 +249,7 @@ public: std::unique_ptr collect_seq_con_info (block_arrival & block_arrival, const std::string & name); -class online_reps +class online_reps final { public: online_reps (nano::node &, nano::uint128_t); @@ -271,11 +271,11 @@ private: std::unique_ptr collect_seq_con_info (online_reps & online_reps, const std::string & name); -class message_buffer +class message_buffer final { public: - uint8_t * buffer; - size_t size; + uint8_t * buffer{ nullptr }; + size_t size{ 0 }; nano::endpoint endpoint; }; /** @@ -286,7 +286,7 @@ public: * This container has a maximum space to hold N buffers of M size and will allocate them in round-robin order. * All public methods are thread-safe */ -class message_buffer_manager +class message_buffer_manager final { public: // Stats - Statistics @@ -320,7 +320,7 @@ private: std::vector entries; bool stopped; }; -class network +class network final { public: network (nano::node &, uint16_t); @@ -367,16 +367,15 @@ public: static size_t const confirm_req_hashes_max = 6; }; -class node_init +class node_init final { public: - node_init (); - bool error (); - bool block_store_init; - bool wallets_store_init; - bool wallet_init; + bool error () const; + bool block_store_init{ false }; + bool wallets_store_init{ false }; + bool wallet_init{ false }; }; -class node_observers +class node_observers final { public: nano::observer_set, nano::account const &, nano::uint128_t const &, bool> blocks; @@ -389,10 +388,10 @@ public: std::unique_ptr collect_seq_con_info (node_observers & node_observers, const std::string & name); -class vote_processor +class vote_processor final { public: - vote_processor (nano::node &); + explicit vote_processor (nano::node &); void vote (std::shared_ptr, std::shared_ptr); // node.active.mutex lock required nano::vote_code vote_blocking (nano::transaction const &, std::shared_ptr, std::shared_ptr, bool = false); @@ -423,7 +422,7 @@ std::unique_ptr collect_seq_con_info (vote_processor & v std::unique_ptr collect_seq_con_info (rep_crawler & rep_crawler, const std::string & name); std::unique_ptr collect_seq_con_info (block_processor & block_processor, const std::string & name); -class node : public std::enable_shared_from_this +class node final : public std::enable_shared_from_this { public: node (nano::node_init &, boost::asio::io_context &, uint16_t, boost::filesystem::path const &, nano::alarm &, nano::logging const &, nano::work_pool &); @@ -522,7 +521,7 @@ private: std::unique_ptr collect_seq_con_info (node & node, const std::string & name); -class thread_runner +class thread_runner final { public: thread_runner (boost::asio::io_context &, unsigned); @@ -530,7 +529,7 @@ public: void join (); std::vector threads; }; -class inactive_node +class inactive_node final { public: inactive_node (boost::filesystem::path const & path = nano::working_path (), uint16_t = 24000); diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 33580c9c..9c9fc73e 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -19,27 +19,7 @@ node_config (0, nano::logging ()) nano::node_config::node_config (uint16_t peering_port_a, nano::logging const & logging_a) : peering_port (peering_port_a), -logging (logging_a), -bootstrap_fraction_numerator (1), -receive_minimum (nano::xrb_ratio), -vote_minimum (nano::Gxrb_ratio), -online_weight_minimum (60000 * nano::Gxrb_ratio), -online_weight_quorum (50), -password_fanout (1024), -io_threads (std::max (4, boost::thread::hardware_concurrency ())), -network_threads (std::max (4, boost::thread::hardware_concurrency ())), -work_threads (std::max (4, boost::thread::hardware_concurrency ())), -signature_checker_threads ((boost::thread::hardware_concurrency () != 0) ? boost::thread::hardware_concurrency () - 1 : 0), /* The calling thread does checks as well so remove it from the number of threads used */ -enable_voting (false), -bootstrap_connections (4), -bootstrap_connections_max (64), -callback_port (0), -lmdb_max_dbs (128), -allow_local_peers (!network_params.is_live_network ()), // disable by default for live network -block_processor_batch_max_time (std::chrono::milliseconds (5000)), -unchecked_cutoff_time (std::chrono::seconds (4 * 60 * 60)), // 4 hours -tcp_client_timeout (std::chrono::seconds (5)), -tcp_server_timeout (std::chrono::seconds (30)) +logging (logging_a) { // The default constructor passes 0 to indicate we should use the default port, // which is determined at node startup based on active network. diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 830cd3db..d13d9049 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -26,38 +26,38 @@ public: bool upgrade_json (unsigned, nano::jsonconfig &); nano::account random_representative (); nano::network_params network_params; - uint16_t peering_port; + uint16_t peering_port{ 0 }; nano::logging logging; std::vector> work_peers; std::vector preconfigured_peers; std::vector preconfigured_representatives; - unsigned bootstrap_fraction_numerator; - nano::amount receive_minimum; - nano::amount vote_minimum; - nano::amount online_weight_minimum; - unsigned online_weight_quorum; - unsigned password_fanout; - unsigned io_threads; - unsigned network_threads; - unsigned work_threads; - unsigned signature_checker_threads; - bool enable_voting; - unsigned bootstrap_connections; - unsigned bootstrap_connections_max; + unsigned bootstrap_fraction_numerator{ 1 }; + nano::amount receive_minimum{ nano::xrb_ratio }; + nano::amount vote_minimum{ nano::Gxrb_ratio }; + nano::amount online_weight_minimum{ 60000 * nano::Gxrb_ratio }; + unsigned online_weight_quorum{ 50 }; + unsigned password_fanout{ 1024 }; + unsigned io_threads{ std::max (4, boost::thread::hardware_concurrency ()) }; + unsigned network_threads{ std::max (4, boost::thread::hardware_concurrency ()) }; + unsigned work_threads{ std::max (4, boost::thread::hardware_concurrency ()) }; + unsigned signature_checker_threads{ (boost::thread::hardware_concurrency () != 0) ? boost::thread::hardware_concurrency () - 1 : 0 }; /* The calling thread does checks as well so remove it from the number of threads used */ + bool enable_voting{ false }; + unsigned bootstrap_connections{ 4 }; + unsigned bootstrap_connections_max{ 64 }; nano::websocket::config websocket_config; std::string callback_address; - uint16_t callback_port; + uint16_t callback_port{ 0 }; std::string callback_target; - int lmdb_max_dbs; - bool allow_local_peers; + int lmdb_max_dbs{ 128 }; + bool allow_local_peers{ !network_params.is_live_network () }; // disable by default for live network nano::stat_config stat_config; nano::ipc::ipc_config ipc_config; nano::uint256_union epoch_block_link; nano::account epoch_block_signer; - std::chrono::milliseconds block_processor_batch_max_time; - std::chrono::seconds unchecked_cutoff_time; - std::chrono::seconds tcp_client_timeout; - std::chrono::seconds tcp_server_timeout; + std::chrono::milliseconds block_processor_batch_max_time{ std::chrono::milliseconds (5000) }; + std::chrono::seconds unchecked_cutoff_time{ std::chrono::seconds (4 * 60 * 60) }; // 4 hours + std::chrono::seconds tcp_client_timeout{ std::chrono::seconds (5) }; + std::chrono::seconds tcp_server_timeout{ std::chrono::seconds (30) }; static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60); static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5; static std::chrono::minutes constexpr wallet_backup_interval = std::chrono::minutes (5); @@ -67,7 +67,7 @@ public: } }; -class node_flags +class node_flags final { public: bool disable_backup{ false }; diff --git a/nano/node/stats.cpp b/nano/node/stats.cpp index 70b6cd36..38047b64 100644 --- a/nano/node/stats.cpp +++ b/nano/node/stats.cpp @@ -173,16 +173,11 @@ std::shared_ptr nano::stat::get_entry_impl (uint32_t key, size return res; } -std::unique_ptr nano::stat::log_sink_json () +std::unique_ptr nano::stat::log_sink_json () const { return std::make_unique (); } -std::unique_ptr log_sink_file (std::string filename) -{ - return std::make_unique (filename); -} - void nano::stat::log_counters (stat_log_sink & sink) { std::unique_lock lock (stat_mutex); diff --git a/nano/node/stats.hpp b/nano/node/stats.hpp index 366525c3..f355c486 100644 --- a/nano/node/stats.hpp +++ b/nano/node/stats.hpp @@ -22,7 +22,7 @@ class node; * All configuration values have defaults. In particular, file logging of statistics * is disabled by default. */ -class stat_config +class stat_config final { public: /** Reads the JSON statistics node */ @@ -57,7 +57,7 @@ public: }; /** Value and wall time of measurement */ -class stat_datapoint +class stat_datapoint final { public: stat_datapoint () = default; @@ -115,7 +115,7 @@ private: }; /** Bookkeeping of statistics for a specific type/detail/direction combination */ -class stat_entry +class stat_entry final { public: stat_entry (size_t capacity, size_t interval) : @@ -210,7 +210,7 @@ protected: * Stats can be queried and observed on a type level (such as message and ledger) as well as a more * specific detail level (such as send blocks) */ -class stat +class stat final { public: /** Primary statistics type */ @@ -306,9 +306,7 @@ public: }; /** Constructor using the default config values */ - stat () - { - } + stat () = default; /** * Initialize stats with a config. @@ -439,10 +437,7 @@ public: void log_samples (stat_log_sink & sink); /** Returns a new JSON log sink */ - std::unique_ptr log_sink_json (); - - /** Returns a new file log sink */ - std::unique_ptr log_sink_file (std::string filename); + std::unique_ptr log_sink_json () const; private: static std::string type_to_string (uint32_t key); diff --git a/nano/node/testing.cpp b/nano/node/testing.cpp index 3c890df5..c026cf60 100644 --- a/nano/node/testing.cpp +++ b/nano/node/testing.cpp @@ -362,10 +362,6 @@ void nano::system::stop () work.stop (); } -nano::landing_store::landing_store () -{ -} - nano::landing_store::landing_store (nano::account const & source_a, nano::account const & destination_a, uint64_t start_a, uint64_t last_a) : source (source_a), destination (destination_a), diff --git a/nano/node/testing.hpp b/nano/node/testing.hpp index ca57feae..2ba7f0fd 100644 --- a/nano/node/testing.hpp +++ b/nano/node/testing.hpp @@ -12,7 +12,7 @@ enum class error_system generic = 1, deadline_expired }; -class system +class system final { public: system (uint16_t, uint16_t); @@ -46,10 +46,10 @@ public: std::chrono::time_point> deadline{ std::chrono::steady_clock::time_point::max () }; double deadline_scaling_factor{ 1.0 }; }; -class landing_store +class landing_store final { public: - landing_store (); + landing_store () = default; landing_store (nano::account const &, nano::account const &, uint64_t, uint64_t); landing_store (bool &, std::istream &); nano::account source; @@ -60,7 +60,7 @@ public: bool deserialize (std::istream &); bool operator== (nano::landing_store const &) const; }; -class landing +class landing final { public: landing (nano::node &, std::shared_ptr, nano::landing_store &, boost::filesystem::path const &); diff --git a/nano/node/transport/udp.hpp b/nano/node/transport/udp.hpp index d5232f49..85a25ecd 100644 --- a/nano/node/transport/udp.hpp +++ b/nano/node/transport/udp.hpp @@ -10,7 +10,7 @@ class message_buffer; namespace transport { class udp_channels; - class channel_udp : public nano::transport::channel + class channel_udp final : public nano::transport::channel { friend class nano::transport::udp_channels; @@ -34,7 +34,7 @@ namespace transport private: nano::transport::udp_channels & channels; }; - class udp_channels + class udp_channels final { friend class nano::transport::channel_udp; @@ -97,7 +97,7 @@ namespace transport class last_tcp_attempt_tag { }; - class channel_udp_wrapper + class channel_udp_wrapper final { public: std::shared_ptr channel; @@ -118,13 +118,13 @@ namespace transport return endpoint ().address (); } }; - class endpoint_attempt + class endpoint_attempt final { public: nano::endpoint endpoint; std::chrono::steady_clock::time_point last_attempt; }; - class syn_cookie_info + class syn_cookie_info final { public: nano::uint256_union cookie; diff --git a/nano/node/voting.hpp b/nano/node/voting.hpp index 6e5f1adb..cce41383 100644 --- a/nano/node/voting.hpp +++ b/nano/node/voting.hpp @@ -19,7 +19,7 @@ namespace nano { class node; -class vote_generator +class vote_generator final { public: vote_generator (nano::node &); @@ -42,14 +42,14 @@ private: }; std::unique_ptr collect_seq_con_info (vote_generator & vote_generator, const std::string & name); -class cached_votes +class cached_votes final { public: std::chrono::steady_clock::time_point time; nano::block_hash hash; std::vector> votes; }; -class votes_cache +class votes_cache final { public: void add (std::shared_ptr const &); diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 9efc5df8..48fcf292 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -12,7 +12,7 @@ namespace nano { // The fan spreads a key out over the heap to decrease the likelihood of it being recovered by memory inspection -class fan +class fan final { public: fan (nano::uint256_union const &, size_t); @@ -25,7 +25,7 @@ private: void value_get (nano::raw_key &); }; class node_config; -class kdf +class kdf final { public: void phs (nano::raw_key &, std::string const &, nano::uint256_union const &); @@ -38,7 +38,7 @@ enum class key_type adhoc, deterministic }; -class wallet_store +class wallet_store final { public: wallet_store (bool &, nano::kdf &, nano::transaction &, nano::account, unsigned, std::string const &); @@ -113,7 +113,7 @@ private: }; class wallets; // A wallet is a set of account keys encrypted by a common encryption key -class wallet : public std::enable_shared_from_this +class wallet final : public std::enable_shared_from_this { public: std::shared_ptr change_action (nano::account const &, nano::account const &, uint64_t = 0, bool = true); @@ -163,7 +163,7 @@ class node; * The wallets set is all the wallets a node controls. * A node may contain multiple wallets independently encrypted and operated. */ -class wallets +class wallets final { public: wallets (bool &, nano::node &); @@ -222,7 +222,7 @@ class wallets_store public: virtual ~wallets_store () = default; }; -class mdb_wallets_store : public wallets_store +class mdb_wallets_store final : public wallets_store { public: mdb_wallets_store (bool &, boost::filesystem::path const &, int lmdb_max_dbs = 128); diff --git a/nano/node/websocketconfig.hpp b/nano/node/websocketconfig.hpp index 0f987b16..bd7071cf 100644 --- a/nano/node/websocketconfig.hpp +++ b/nano/node/websocketconfig.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace nano { @@ -10,7 +9,7 @@ class jsonconfig; namespace websocket { /** websocket configuration */ - class config + class config final { public: nano::error deserialize_json (nano::jsonconfig & json_a); diff --git a/nano/node/xorshift.hpp b/nano/node/xorshift.hpp index 3f0b7993..2653802d 100644 --- a/nano/node/xorshift.hpp +++ b/nano/node/xorshift.hpp @@ -3,15 +3,11 @@ namespace nano { -class xorshift1024star +class xorshift1024star final { public: - xorshift1024star () : - p (0) - { - } std::array s; - unsigned p; + unsigned p{ 0 }; uint64_t next () { auto p_l (p); diff --git a/nano/secure/blockstore.hpp b/nano/secure/blockstore.hpp index 4ef8b8a6..bc4f2e71 100644 --- a/nano/secure/blockstore.hpp +++ b/nano/secure/blockstore.hpp @@ -6,7 +6,7 @@ namespace nano { -class block_sideband +class block_sideband final { public: block_sideband () = default; @@ -30,7 +30,7 @@ class block_store; * between balance and amount visitors, but this leads to very deep stacks. Hence, the * summation visitor uses an iterative approach. */ -class summation_visitor : public nano::block_visitor +class summation_visitor final : public nano::block_visitor { enum summation_type { @@ -40,7 +40,7 @@ class summation_visitor : public nano::block_visitor }; /** Represents an invocation frame */ - class frame + class frame final { public: frame (summation_type type_a, nano::block_hash balance_hash_a, nano::block_hash amount_hash_a) : @@ -99,11 +99,11 @@ protected: /** * Determine the representative for this block */ -class representative_visitor : public nano::block_visitor +class representative_visitor final : public nano::block_visitor { public: representative_visitor (nano::transaction const & transaction_a, nano::block_store & store_a); - virtual ~representative_visitor () = default; + ~representative_visitor () = default; void compute (nano::block_hash const & hash_a); void send_block (nano::send_block const & block_a) override; void receive_block (nano::receive_block const & block_a) override; @@ -138,7 +138,7 @@ public: * Iterates the key/value pairs of a transaction */ template -class store_iterator +class store_iterator final { public: store_iterator (std::nullptr_t) @@ -196,7 +196,7 @@ public: * RAII wrapper of MDB_txn where the constructor starts the transaction * and the destructor commits it. */ -class transaction +class transaction final { public: std::unique_ptr impl; diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 7a912e49..1111aca1 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -74,7 +74,7 @@ enum class epoch : uint8_t /** * Latest information about an account */ -class account_info +class account_info final { public: account_info () = default; @@ -97,7 +97,7 @@ public: /** * Information on an uncollected send */ -class pending_info +class pending_info final { public: pending_info () = default; @@ -108,7 +108,7 @@ public: nano::amount amount{ 0 }; nano::epoch epoch{ nano::epoch::epoch_0 }; }; -class pending_key +class pending_key final { public: pending_key () = default; @@ -120,7 +120,7 @@ public: nano::block_hash hash{ 0 }; }; -class endpoint_key +class endpoint_key final { public: endpoint_key () = default; @@ -169,7 +169,7 @@ enum class signature_verification : uint8_t /** * Information on an unchecked block */ -class unchecked_info +class unchecked_info final { public: unchecked_info () = default; @@ -183,7 +183,7 @@ public: nano::signature_verification verified{ nano::signature_verification::unknown }; }; -class block_info +class block_info final { public: block_info () = default; @@ -191,7 +191,7 @@ public: nano::account account{ 0 }; nano::amount balance{ 0 }; }; -class block_counts +class block_counts final { public: size_t sum () const; @@ -202,14 +202,14 @@ public: size_t state_v0{ 0 }; size_t state_v1{ 0 }; }; -typedef std::vector, nano::block_hash>>::const_iterator vote_blocks_vec_iter; -class iterate_vote_blocks_as_hash +using vote_blocks_vec_iter = std::vector, nano::block_hash>>::const_iterator; +class iterate_vote_blocks_as_hash final { public: iterate_vote_blocks_as_hash () = default; nano::block_hash operator() (boost::variant, nano::block_hash> const & item) const; }; -class vote +class vote final { public: vote () = default; @@ -243,7 +243,7 @@ public: /** * This class serves to find and return unique variants of a vote in order to minimize memory usage */ -class vote_uniquer +class vote_uniquer final { public: using value_type = std::pair>; @@ -283,7 +283,7 @@ enum class process_result representative_mismatch, // Representative is changed when it is not allowed block_position // This block cannot follow the previous block }; -class process_return +class process_return final { public: nano::process_result code; @@ -300,7 +300,7 @@ enum class tally_result confirm }; -class genesis +class genesis final { public: genesis (); diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index dfdb6572..cbb8e2c9 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -8,14 +8,14 @@ namespace nano class block_store; class stat; -class shared_ptr_block_hash +class shared_ptr_block_hash final { public: size_t operator() (std::shared_ptr const &) const; bool operator() (std::shared_ptr const &, std::shared_ptr const &) const; }; using tally_t = std::map, std::greater>; -class ledger +class ledger final { public: ledger (nano::block_store &, nano::stat &, nano::uint256_union const & = 1, nano::account const & = 0); diff --git a/nano/secure/versioning.hpp b/nano/secure/versioning.hpp index 7fcf30de..782115b7 100644 --- a/nano/secure/versioning.hpp +++ b/nano/secure/versioning.hpp @@ -6,11 +6,11 @@ namespace nano { -class account_info_v1 +class account_info_v1 final { public: account_info_v1 () = default; - account_info_v1 (MDB_val const &); + explicit account_info_v1 (MDB_val const &); account_info_v1 (nano::block_hash const &, nano::block_hash const &, nano::amount const &, uint64_t); nano::mdb_val val () const; nano::block_hash head{ 0 }; @@ -18,22 +18,22 @@ public: nano::amount balance{ 0 }; uint64_t modified{ 0 }; }; -class pending_info_v3 +class pending_info_v3 final { public: pending_info_v3 () = default; - pending_info_v3 (MDB_val const &); + explicit pending_info_v3 (MDB_val const &); pending_info_v3 (nano::account const &, nano::amount const &, nano::account const &); nano::mdb_val val () const; nano::account source{ 0 }; nano::amount amount{ 0 }; nano::account destination{ 0 }; }; -class account_info_v5 +class account_info_v5 final { public: account_info_v5 () = default; - account_info_v5 (MDB_val const &); + explicit account_info_v5 (MDB_val const &); account_info_v5 (nano::block_hash const &, nano::block_hash const &, nano::block_hash const &, nano::amount const &, uint64_t); nano::mdb_val val () const; nano::block_hash head{ 0 }; @@ -42,7 +42,7 @@ public: nano::amount balance{ 0 }; uint64_t modified{ 0 }; }; -class account_info_v13 +class account_info_v13 final { public: account_info_v13 () = default;