From 522f05cdf13fae567bdb0286dcd135581b85123f Mon Sep 17 00:00:00 2001 From: gr0vity-dev <85646666+gr0vity-dev@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:52:25 +0100 Subject: [PATCH 01/22] Fix type to log ipc session_id (#4448) Co-authored-by: gr0vity-dev --- nano/node/ipc/ipc_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/ipc/ipc_server.cpp b/nano/node/ipc/ipc_server.cpp index 3b65534468..781f4051ac 100644 --- a/nano/node/ipc/ipc_server.cpp +++ b/nano/node/ipc/ipc_server.cpp @@ -36,7 +36,7 @@ class session final : public nano::ipc::socket_base, public std::enable_shared_f server (server_a), node (server_a.node), session_id (server_a.id_dispenser.fetch_add (1)), io_ctx (io_ctx_a), strand (io_ctx_a.get_executor ()), socket (io_ctx_a), config_transport (config_transport_a) { - node.logger.debug (nano::log::type::ipc, "Creating session with id: ", session_id.load ()); + node.logger.debug (nano::log::type::ipc, "Creating session with id: {}", session_id.load ()); } ~session () From 0ce830f5d6f4496aeb3a5823b5fc9e12eaf04dd9 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Mon, 4 Mar 2024 11:31:56 +0000 Subject: [PATCH 02/22] Process connection attempts in a round-robin fashion in order to load-balance connection attempts. # Conflicts: # nano/node/network.cpp --- nano/lib/config.hpp | 4 ++ nano/node/network.cpp | 2 - nano/node/transport/channel.hpp | 2 +- nano/node/transport/tcp.cpp | 72 ++++++++++++++++++++++++++++++ nano/node/transport/tcp.hpp | 2 + nano/node/transport/tcp_server.cpp | 10 +++++ nano/node/transport/tcp_server.hpp | 2 + 7 files changed, 91 insertions(+), 3 deletions(-) diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index a68b02c1b0..bddfa29cf9 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -202,6 +202,7 @@ class network_constants default_websocket_port (47000), aec_loop_interval_ms (300), // Update AEC ~3 times per second cleanup_period (default_cleanup_period), + merge_period (std::chrono::milliseconds (250)), keepalive_period (std::chrono::seconds (15)), idle_timeout (default_cleanup_period * 2), silent_connection_tolerance_time (std::chrono::seconds (120)), @@ -239,6 +240,7 @@ class network_constants { aec_loop_interval_ms = 20; cleanup_period = std::chrono::seconds (1); + merge_period = std::chrono::milliseconds (10); keepalive_period = std::chrono::seconds (1); idle_timeout = cleanup_period * 15; max_peers_per_ip = 20; @@ -277,6 +279,8 @@ class network_constants { return cleanup_period * 5; } + /** How often to connect to other peers */ + std::chrono::milliseconds merge_period; /** How often to send keepalive messages */ std::chrono::seconds keepalive_period; /** Default maximum idle time for a socket before it's automatically closed */ diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 4d47533be6..0c9cf2268c 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -239,8 +239,6 @@ class network_message_visitor : public nano::message_visitor void keepalive (nano::keepalive const & message_a) override { - node.network.merge_peers (message_a.peers); - // Check for special node port data auto peer0 (message_a.peers[0]); if (peer0.address () == boost::asio::ip::address_v6{} && peer0.port () != 0) diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index a16ee0e2ee..bede756ce3 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -187,4 +187,4 @@ struct hash> return hash (channel_a.get ()); } }; -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp.cpp b/nano/node/transport/tcp.cpp index a085dbfc39..e6ddca6120 100644 --- a/nano/node/transport/tcp.cpp +++ b/nano/node/transport/tcp.cpp @@ -357,6 +357,7 @@ void nano::transport::tcp_channels::process_message (nano::message const & messa void nano::transport::tcp_channels::start () { ongoing_keepalive (); + ongoing_merge (0); } void nano::transport::tcp_channels::stop () @@ -509,6 +510,77 @@ void nano::transport::tcp_channels::ongoing_keepalive () }); } +void nano::transport::tcp_channels::ongoing_merge (size_t channel_index) +{ + nano::unique_lock lock{ mutex }; + std::optional keepalive; + size_t count = 0; + while (!keepalive && channels.size () > 0 && count++ < channels.size ()) + { + ++channel_index; + if (channels.size () <= channel_index) + { + channel_index = 0; + } + auto server = channels.get ()[channel_index].response_server; + if (server && server->last_keepalive) + { + keepalive = std::move (server->last_keepalive); + server->last_keepalive = std::nullopt; + } + } + lock.unlock (); + if (keepalive) + { + ongoing_merge (channel_index, *keepalive, 1); + } + else + { + std::weak_ptr node_w = node.shared (); + node.workers.add_timed_task (std::chrono::steady_clock::now () + node.network_params.network.merge_period, [node_w, channel_index] () { + if (auto node_l = node_w.lock ()) + { + if (!node_l->network.tcp_channels.stopped) + { + node_l->network.tcp_channels.ongoing_merge (channel_index); + } + } + }); + } +} + +void nano::transport::tcp_channels::ongoing_merge (size_t channel_index, nano::keepalive keepalive, size_t peer_index) +{ + debug_assert (peer_index < keepalive.peers.size ()); + node.network.merge_peer (keepalive.peers[peer_index++]); + if (peer_index < keepalive.peers.size ()) + { + std::weak_ptr node_w = node.shared (); + node.workers.add_timed_task (std::chrono::steady_clock::now () + node.network_params.network.merge_period, [node_w, channel_index, keepalive, peer_index] () { + if (auto node_l = node_w.lock ()) + { + if (!node_l->network.tcp_channels.stopped) + { + node_l->network.tcp_channels.ongoing_merge (channel_index, keepalive, peer_index); + } + } + }); + } + else + { + std::weak_ptr node_w = node.shared (); + node.workers.add_timed_task (std::chrono::steady_clock::now () + node.network_params.network.merge_period, [node_w, channel_index] () { + if (auto node_l = node_w.lock ()) + { + if (!node_l->network.tcp_channels.stopped) + { + node_l->network.tcp_channels.ongoing_merge (channel_index); + } + } + }); + } +} + void nano::transport::tcp_channels::list (std::deque> & deque_a, uint8_t minimum_version_a, bool include_temporary_channels_a) { nano::lock_guard lock{ mutex }; diff --git a/nano/node/transport/tcp.hpp b/nano/node/transport/tcp.hpp index 7b6efd9420..0f65b3bd0e 100644 --- a/nano/node/transport/tcp.hpp +++ b/nano/node/transport/tcp.hpp @@ -128,6 +128,8 @@ namespace transport std::unique_ptr collect_container_info (std::string const &); void purge (std::chrono::steady_clock::time_point const &); void ongoing_keepalive (); + void ongoing_merge (size_t channel_index); + void ongoing_merge (size_t channel_index, nano::keepalive keepalive, size_t peer_index); void list (std::deque> &, uint8_t = 0, bool = true); void modify (std::shared_ptr const &, std::function const &)>); void update (nano::tcp_endpoint const &); diff --git a/nano/node/transport/tcp_server.cpp b/nano/node/transport/tcp_server.cpp index 7cfee60243..7e37ef97bc 100644 --- a/nano/node/transport/tcp_server.cpp +++ b/nano/node/transport/tcp_server.cpp @@ -623,6 +623,7 @@ nano::transport::tcp_server::realtime_message_visitor::realtime_message_visitor void nano::transport::tcp_server::realtime_message_visitor::keepalive (const nano::keepalive & message) { process = true; + server.set_last_keepalive (message); } void nano::transport::tcp_server::realtime_message_visitor::publish (const nano::publish & message) @@ -786,6 +787,15 @@ void nano::transport::tcp_server::timeout () } } +void nano::transport::tcp_server::set_last_keepalive (nano::keepalive const & message) +{ + std::lock_guard lock{ mutex }; + if (!last_keepalive) + { + last_keepalive = message; + } +} + bool nano::transport::tcp_server::to_bootstrap_connection () { auto node = this->node.lock (); diff --git a/nano/node/transport/tcp_server.hpp b/nano/node/transport/tcp_server.hpp index e011c50630..5369258545 100644 --- a/nano/node/transport/tcp_server.hpp +++ b/nano/node/transport/tcp_server.hpp @@ -62,6 +62,7 @@ class tcp_server final : public std::enable_shared_from_this void stop (); void timeout (); + void set_last_keepalive (nano::keepalive const & message); std::shared_ptr const socket; std::weak_ptr const node; @@ -72,6 +73,7 @@ class tcp_server final : public std::enable_shared_from_this nano::tcp_endpoint remote_endpoint{ boost::asio::ip::address_v6::any (), 0 }; nano::account remote_node_id{}; std::chrono::steady_clock::time_point last_telemetry_req{}; + std::optional last_keepalive; private: void send_handshake_response (nano::node_id_handshake::query_payload const & query, bool v2); From 1b1bac07ab06241aa164ae12b54da4e5dfe4784d Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 26 Feb 2024 10:52:19 +0000 Subject: [PATCH 03/22] Increasing block processing timeout default from 15 to 300 seconds. --- nano/node/nodeconfig.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/nodeconfig.hpp b/nano/node/nodeconfig.hpp index 8f7580534a..55b14db049 100644 --- a/nano/node/nodeconfig.hpp +++ b/nano/node/nodeconfig.hpp @@ -88,7 +88,7 @@ class node_config uint16_t external_port{ 0 }; std::chrono::milliseconds block_processor_batch_max_time{ std::chrono::milliseconds (500) }; /** Time to wait for block processing result */ - std::chrono::seconds block_process_timeout{ 15 }; + std::chrono::seconds block_process_timeout{ 300 }; std::chrono::seconds unchecked_cutoff_time{ std::chrono::seconds (4 * 60 * 60) }; // 4 hours /** Timeout for initiated async operations */ std::chrono::seconds tcp_io_timeout{ (network_params.network.is_dev_network () && !is_sanitizer_build ()) ? std::chrono::seconds (5) : std::chrono::seconds (15) }; From 69db556656d8e024f97e03018f36dec07c631fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:44:05 +0100 Subject: [PATCH 04/22] Use start/stop pattern in `vote_processor` (#4455) --- nano/node/node.cpp | 1 + nano/node/vote_processor.cpp | 69 ++++++++++++++++++------------------ nano/node/vote_processor.hpp | 28 +++++++++------ 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 834cabbd9f..ac5f56b2c9 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -646,6 +646,7 @@ void nano::node::start () port_mapping.start (); } wallets.start (); + vote_processor.start (); active.start (); generator.start (); final_generator.start (); diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index 524dbdc8ee..9c094abf45 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -13,6 +12,7 @@ #include #include + using namespace std::chrono_literals; nano::vote_processor::vote_processor (nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger & logger_a, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a) : @@ -25,33 +25,45 @@ nano::vote_processor::vote_processor (nano::active_transactions & active_a, nano rep_crawler (rep_crawler_a), ledger (ledger_a), network_params (network_params_a), - max_votes (flags_a.vote_processor_capacity), - started (false), - stopped (false), - thread ([this] () { + max_votes (flags_a.vote_processor_capacity) +{ +} + +nano::vote_processor::~vote_processor () +{ + // Thread must be stopped before destruction + debug_assert (!thread.joinable ()); +} + +void nano::vote_processor::start () +{ + debug_assert (!thread.joinable ()); + + thread = std::thread{ [this] () { nano::thread_role::set (nano::thread_role::name::vote_processing); - process_loop (); - nano::unique_lock lock{ mutex }; - votes.clear (); - condition.notify_all (); - }) + run (); + } }; +} + +void nano::vote_processor::stop () { - nano::unique_lock lock{ mutex }; - condition.wait (lock, [&started = started] { return started; }); + { + nano::lock_guard lock{ mutex }; + stopped = true; + } + condition.notify_all (); + if (thread.joinable ()) + { + thread.join (); + } } -void nano::vote_processor::process_loop () +void nano::vote_processor::run () { nano::timer elapsed; bool log_this_iteration; nano::unique_lock lock{ mutex }; - started = true; - - lock.unlock (); - condition.notify_all (); - lock.lock (); - while (!stopped) { if (!votes.empty ()) @@ -181,19 +193,6 @@ nano::vote_code nano::vote_processor::vote_blocking (std::shared_ptr return result; } -void nano::vote_processor::stop () -{ - { - nano::lock_guard lock{ mutex }; - stopped = true; - } - condition.notify_all (); - if (thread.joinable ()) - { - thread.join (); - } -} - void nano::vote_processor::flush () { nano::unique_lock lock{ mutex }; @@ -208,19 +207,19 @@ void nano::vote_processor::flush () } } -std::size_t nano::vote_processor::size () +std::size_t nano::vote_processor::size () const { nano::lock_guard guard{ mutex }; return votes.size (); } -bool nano::vote_processor::empty () +bool nano::vote_processor::empty () const { nano::lock_guard guard{ mutex }; return votes.empty (); } -bool nano::vote_processor::half_full () +bool nano::vote_processor::half_full () const { return size () >= max_votes / 2; } diff --git a/nano/node/vote_processor.hpp b/nano/node/vote_processor.hpp index dbcacc41c3..4591c5ee71 100644 --- a/nano/node/vote_processor.hpp +++ b/nano/node/vote_processor.hpp @@ -37,6 +37,10 @@ class vote_processor final { public: vote_processor (nano::active_transactions & active_a, nano::node_observers & observers_a, nano::stats & stats_a, nano::node_config & config_a, nano::node_flags & flags_a, nano::logger &, nano::online_reps & online_reps_a, nano::rep_crawler & rep_crawler_a, nano::ledger & ledger_a, nano::network_params & network_params_a); + ~vote_processor (); + + void start (); + void stop (); /** Returns false if the vote was processed */ bool vote (std::shared_ptr const &, std::shared_ptr const &); @@ -46,16 +50,14 @@ class vote_processor final /** Function blocks until either the current queue size (a established flush boundary as it'll continue to increase) * is processed or the queue is empty (end condition or cutoff's guard, as it is positioned ahead) */ void flush (); - std::size_t size (); - bool empty (); - bool half_full (); + std::size_t size () const; + bool empty () const; + bool half_full () const; void calculate_weights (); - void stop (); - std::atomic total_processed{ 0 }; -private: - void process_loop (); + std::atomic total_processed{ 0 }; +private: // Dependencies nano::active_transactions & active; nano::node_observers & observers; nano::stats & stats; @@ -65,16 +67,22 @@ class vote_processor final nano::rep_crawler & rep_crawler; nano::ledger & ledger; nano::network_params & network_params; + +private: + void run (); + std::size_t const max_votes; std::deque, std::shared_ptr>> votes; + /** Representatives levels for random early detection */ std::unordered_set representatives_1; std::unordered_set representatives_2; std::unordered_set representatives_3; + +private: + bool stopped{ false }; nano::condition_variable condition; - nano::mutex mutex{ mutex_identifier (mutexes::vote_processor) }; - bool started; - bool stopped; + mutable nano::mutex mutex{ mutex_identifier (mutexes::vote_processor) }; std::thread thread; friend std::unique_ptr collect_container_info (vote_processor & vote_processor, std::string const & name); From 65de6fe3e5546e78b0fae482314c178fd4d940d1 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Tue, 5 Mar 2024 12:02:17 +0000 Subject: [PATCH 05/22] Remove unused ledger::could_fit (#4457) --- nano/core_test/ledger.cpp | 142 -------------------------------------- nano/secure/ledger.cpp | 8 --- nano/secure/ledger.hpp | 1 - 3 files changed, 151 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 821d1d4994..9f6aee9416 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -4158,148 +4158,6 @@ TEST (ledger, block_hash_account_conflict) ASSERT_EQ (*open_epoch1, *winner4); } -TEST (ledger, could_fit) -{ - nano::logger logger; - auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants); - ASSERT_TRUE (!store->init_error ()); - nano::stats stats; - nano::ledger ledger (*store, stats, nano::dev::constants); - auto transaction (store->tx_begin_write ()); - store->initialize (transaction, ledger.cache, ledger.constants); - nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits::max () }; - nano::keypair destination; - // Test legacy and state change blocks could_fit - nano::block_builder builder; - auto change1 = builder - .change () - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) - .build (); - auto change2 = builder - .state () - .account (nano::dev::genesis->account ()) - .previous (nano::dev::genesis->hash ()) - .representative (nano::dev::genesis->account ()) - .balance (nano::dev::constants.genesis_amount) - .link (0) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (nano::dev::genesis->hash ())) - .build (); - ASSERT_TRUE (ledger.could_fit (transaction, *change1)); - ASSERT_TRUE (ledger.could_fit (transaction, *change2)); - // Test legacy and state send - nano::keypair key1; - auto send1 = builder - .send () - .previous (change1->hash ()) - .destination (key1.pub) - .balance (nano::dev::constants.genesis_amount - 1) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (change1->hash ())) - .build (); - auto send2 = builder - .state () - .account (nano::dev::genesis->account ()) - .previous (change1->hash ()) - .representative (nano::dev::genesis->account ()) - .balance (nano::dev::constants.genesis_amount - 1) - .link (key1.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (change1->hash ())) - .build (); - ASSERT_FALSE (ledger.could_fit (transaction, *send1)); - ASSERT_FALSE (ledger.could_fit (transaction, *send2)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); - ASSERT_TRUE (ledger.could_fit (transaction, *change1)); - ASSERT_TRUE (ledger.could_fit (transaction, *change2)); - ASSERT_TRUE (ledger.could_fit (transaction, *send1)); - ASSERT_TRUE (ledger.could_fit (transaction, *send2)); - // Test legacy and state open - auto open1 = builder - .open () - .source (send2->hash ()) - .representative (nano::dev::genesis->account ()) - .account (key1.pub) - .sign (key1.prv, key1.pub) - .work (*pool.generate (key1.pub)) - .build (); - auto open2 = builder - .state () - .account (key1.pub) - .previous (0) - .representative (nano::dev::genesis->account ()) - .balance (1) - .link (send2->hash ()) - .sign (key1.prv, key1.pub) - .work (*pool.generate (key1.pub)) - .build (); - ASSERT_FALSE (ledger.could_fit (transaction, *open1)); - ASSERT_FALSE (ledger.could_fit (transaction, *open2)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2)); - ASSERT_TRUE (ledger.could_fit (transaction, *send1)); - ASSERT_TRUE (ledger.could_fit (transaction, *send2)); - ASSERT_TRUE (ledger.could_fit (transaction, *open1)); - ASSERT_TRUE (ledger.could_fit (transaction, *open2)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); - ASSERT_TRUE (ledger.could_fit (transaction, *open1)); - ASSERT_TRUE (ledger.could_fit (transaction, *open2)); - // Create another send to receive - auto send3 = builder - .state () - .account (nano::dev::genesis->account ()) - .previous (send2->hash ()) - .representative (nano::dev::genesis->account ()) - .balance (nano::dev::constants.genesis_amount - 2) - .link (key1.pub) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (send2->hash ())) - .build (); - // Test legacy and state receive - auto receive1 = builder - .receive () - .previous (open1->hash ()) - .source (send3->hash ()) - .sign (key1.prv, key1.pub) - .work (*pool.generate (open1->hash ())) - .build (); - auto receive2 = builder - .state () - .account (key1.pub) - .previous (open1->hash ()) - .representative (nano::dev::genesis->account ()) - .balance (2) - .link (send3->hash ()) - .sign (key1.prv, key1.pub) - .work (*pool.generate (open1->hash ())) - .build (); - ASSERT_FALSE (ledger.could_fit (transaction, *receive1)); - ASSERT_FALSE (ledger.could_fit (transaction, *receive2)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send3)); - ASSERT_TRUE (ledger.could_fit (transaction, *receive1)); - ASSERT_TRUE (ledger.could_fit (transaction, *receive2)); - // Test epoch (state) - auto epoch1 = builder - .state () - .account (key1.pub) - .previous (receive1->hash ()) - .representative (nano::dev::genesis->account ()) - .balance (2) - .link (ledger.epoch_link (nano::epoch::epoch_1)) - .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) - .work (*pool.generate (receive1->hash ())) - .build (); - ASSERT_FALSE (ledger.could_fit (transaction, *epoch1)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (ledger.could_fit (transaction, *receive1)); - ASSERT_TRUE (ledger.could_fit (transaction, *receive2)); - ASSERT_TRUE (ledger.could_fit (transaction, *epoch1)); - ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, epoch1)); - ASSERT_TRUE (ledger.could_fit (transaction, *epoch1)); -} - TEST (ledger, unchecked_epoch) { nano::test::system system (1); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index c23ffc73b4..dc2651b89a 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1244,14 +1244,6 @@ void nano::ledger::dump_account_chain (nano::account const & account_a, std::ost } } -bool nano::ledger::could_fit (store::transaction const & transaction_a, nano::block const & block_a) const -{ - auto dependencies (dependent_blocks (transaction_a, block_a)); - return std::all_of (dependencies.begin (), dependencies.end (), [this, &transaction_a] (nano::block_hash const & hash_a) { - return hash_a.is_zero () || store.block.exists (transaction_a, hash_a); - }); -} - bool nano::ledger::dependents_confirmed (store::transaction const & transaction_a, nano::block const & block_a) const { auto dependencies (dependent_blocks (transaction_a, block_a)); diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 935f57e2cb..ac6206e6ea 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -78,7 +78,6 @@ class ledger final void update_account (store::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &); uint64_t pruning_action (store::write_transaction &, nano::block_hash const &, uint64_t const); void dump_account_chain (nano::account const &, std::ostream & = std::cout); - bool could_fit (store::transaction const &, nano::block const &) const; bool dependents_confirmed (store::transaction const &, nano::block const &) const; bool is_epoch_link (nano::link const &) const; std::array dependent_blocks (store::transaction const &, nano::block const &) const; From 665296acfaf376fb8449fd4813a08ddc1459a668 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 5 Mar 2024 14:02:33 +0000 Subject: [PATCH 06/22] Reduce coupling to store.block.get by using ledger::block interface. --- nano/core_test/block_store.cpp | 24 ++--- nano/core_test/ledger.cpp | 38 +++---- nano/core_test/wallet.cpp | 4 +- nano/nano_node/entry.cpp | 14 +-- nano/node/bootstrap/bootstrap_server.cpp | 6 +- nano/node/confirmation_height_bounded.cpp | 14 +-- nano/node/confirmation_height_unbounded.cpp | 4 +- nano/node/json_handler.cpp | 52 ++++----- nano/node/node.cpp | 7 +- nano/node/request_aggregator.cpp | 8 +- nano/node/scheduler/hinted.cpp | 4 +- nano/node/scheduler/priority.cpp | 2 +- nano/node/voting.cpp | 2 +- nano/node/wallet.cpp | 4 +- nano/qt/qt.cpp | 10 +- nano/rpc_test/rpc.cpp | 6 +- nano/secure/ledger.cpp | 113 ++++++++++---------- nano/secure/ledger.hpp | 1 + nano/slow_test/node.cpp | 4 +- nano/test_common/system.cpp | 2 +- 20 files changed, 162 insertions(+), 157 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 6f010ee266..56f1c838f5 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1126,29 +1126,29 @@ TEST (mdb_block_store, sideband_height) .work (*pool.generate (key3.pub)) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open)); - auto block1 (store.block.get (transaction, nano::dev::genesis->hash ())); + auto block1 = ledger.block (transaction, nano::dev::genesis->hash ()); ASSERT_EQ (block1->sideband ().height, 1); - auto block2 (store.block.get (transaction, send->hash ())); + auto block2 = ledger.block (transaction, send->hash ()); ASSERT_EQ (block2->sideband ().height, 2); - auto block3 (store.block.get (transaction, receive->hash ())); + auto block3 = ledger.block (transaction, receive->hash ()); ASSERT_EQ (block3->sideband ().height, 3); - auto block4 (store.block.get (transaction, change->hash ())); + auto block4 = ledger.block (transaction, change->hash ()); ASSERT_EQ (block4->sideband ().height, 4); - auto block5 (store.block.get (transaction, state_send1->hash ())); + auto block5 = ledger.block (transaction, state_send1->hash ()); ASSERT_EQ (block5->sideband ().height, 5); - auto block6 (store.block.get (transaction, state_send2->hash ())); + auto block6 = ledger.block (transaction, state_send2->hash ()); ASSERT_EQ (block6->sideband ().height, 6); - auto block7 (store.block.get (transaction, state_send3->hash ())); + auto block7 = ledger.block (transaction, state_send3->hash ()); ASSERT_EQ (block7->sideband ().height, 7); - auto block8 (store.block.get (transaction, state_open->hash ())); + auto block8 = ledger.block (transaction, state_open->hash ()); ASSERT_EQ (block8->sideband ().height, 1); - auto block9 (store.block.get (transaction, epoch->hash ())); + auto block9 = ledger.block (transaction, epoch->hash ()); ASSERT_EQ (block9->sideband ().height, 2); - auto block10 (store.block.get (transaction, epoch_open->hash ())); + auto block10 = ledger.block (transaction, epoch_open->hash ()); ASSERT_EQ (block10->sideband ().height, 1); - auto block11 (store.block.get (transaction, state_receive->hash ())); + auto block11 = ledger.block (transaction, state_receive->hash ()); ASSERT_EQ (block11->sideband ().height, 2); - auto block12 (store.block.get (transaction, open->hash ())); + auto block12 = ledger.block (transaction, open->hash ()); ASSERT_EQ (block12->sideband ().height, 1); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 9f6aee9416..1436e3006f 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -78,7 +78,7 @@ TEST (ledger, process_modifies_sideband) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (store.tx_begin_write (), send1)); - ASSERT_EQ (send1->sideband ().timestamp, store.block.get (store.tx_begin_read (), send1->hash ())->sideband ().timestamp); + ASSERT_EQ (send1->sideband ().timestamp, ledger.block (store.tx_begin_read (), send1->hash ())->sideband ().timestamp); } // Create a send block and publish it. @@ -118,7 +118,7 @@ TEST (ledger, process_send) auto info2 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_EQ (2, info2->block_count); - auto latest6 = store.block.get (transaction, info2->head); + auto latest6 = ledger.block (transaction, info2->head); ASSERT_NE (nullptr, latest6); auto latest7 = dynamic_cast (latest6.get ()); ASSERT_NE (nullptr, latest7); @@ -150,14 +150,14 @@ TEST (ledger, process_send) ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key2.pub)); auto info3 = ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info3); - auto latest2 = store.block.get (transaction, info3->head); + auto latest2 = ledger.block (transaction, info3->head); ASSERT_NE (nullptr, latest2); auto latest3 = dynamic_cast (latest2.get ()); ASSERT_NE (nullptr, latest3); ASSERT_EQ (*send, *latest3); auto info4 = ledger.account_info (transaction, key2.pub); ASSERT_TRUE (info4); - auto latest4 = store.block.get (transaction, info4->head); + auto latest4 = ledger.block (transaction, info4->head); ASSERT_NE (nullptr, latest4); auto latest5 = dynamic_cast (latest4.get ()); ASSERT_NE (nullptr, latest5); @@ -2383,7 +2383,7 @@ TEST (ledger, state_send_receive) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2406,7 +2406,7 @@ TEST (ledger, state_send_receive) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); - auto receive2 = store.block.get (transaction, receive1->hash ()); + auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); @@ -2438,7 +2438,7 @@ TEST (ledger, state_receive) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2456,7 +2456,7 @@ TEST (ledger, state_receive) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); - auto receive2 = store.block.get (transaction, receive1->hash ()); + auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); @@ -2489,7 +2489,7 @@ TEST (ledger, state_rep_change) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); ASSERT_TRUE (store.block.exists (transaction, change1->hash ())); - auto change2 = store.block.get (transaction, change1->hash ()); + auto change2 = ledger.block (transaction, change1->hash ()); ASSERT_NE (nullptr, change2); ASSERT_EQ (*change1, *change2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, change1->hash ())); @@ -2523,7 +2523,7 @@ TEST (ledger, state_open) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2543,7 +2543,7 @@ TEST (ledger, state_open) ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (destination.pub, send1->hash ()))); ASSERT_TRUE (store.block.exists (transaction, open1->hash ())); - auto open2 = store.block.get (transaction, open1->hash ()); + auto open2 = ledger.block (transaction, open1->hash ()); ASSERT_NE (nullptr, open2); ASSERT_EQ (*open1, *open2); ASSERT_EQ (nano::Gxrb_ratio, ledger.balance (transaction, open1->hash ())); @@ -2666,7 +2666,7 @@ TEST (ledger, state_unreceivable_fail) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2703,7 +2703,7 @@ TEST (ledger, state_receive_bad_amount_fail) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2775,7 +2775,7 @@ TEST (ledger, state_receive_wrong_account_fail) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -2969,7 +2969,7 @@ TEST (ledger, state_send_change) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -3002,7 +3002,7 @@ TEST (ledger, state_receive_change) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ())); @@ -3021,7 +3021,7 @@ TEST (ledger, state_receive_change) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); - auto receive2 = store.block.get (transaction, receive1->hash ()); + auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ())); @@ -3141,7 +3141,7 @@ TEST (ledger, state_rollback_send) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); - auto send2 = store.block.get (transaction, send1->hash ()); + auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); @@ -4291,7 +4291,7 @@ TEST (ledger, unchecked_epoch_invalid) auto info = node1.ledger.account_info (transaction, destination.pub); ASSERT_TRUE (info); ASSERT_NE (info->epoch (), nano::epoch::epoch_1); - auto epoch2_store = node1.store.block.get (transaction, epoch2->hash ()); + auto epoch2_store = node1.ledger.block (transaction, epoch2->hash ()); ASSERT_NE (nullptr, epoch2_store); ASSERT_EQ (nano::epoch::epoch_0, epoch2_store->sideband ().details.epoch); ASSERT_TRUE (epoch2_store->sideband ().details.is_send); diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index c6fec45f5f..cbfa73eb9d 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -181,7 +181,7 @@ TEST (wallet, spend_all_one) auto transaction (node1.store.tx_begin_read ()); auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_NE (latest1, info2->head); - auto block (node1.store.block.get (transaction, info2->head)); + auto block = node1.ledger.block (transaction, info2->head); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); ASSERT_TRUE (info2->balance.is_zero ()); @@ -216,7 +216,7 @@ TEST (wallet, spend) auto info2 = node1.ledger.account_info (transaction, nano::dev::genesis_key.pub); ASSERT_TRUE (info2); ASSERT_NE (latest1, info2->head); - auto block (node1.store.block.get (transaction, info2->head)); + auto block = node1.ledger.block (transaction, info2->head); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); ASSERT_TRUE (info2->balance.is_zero ()); diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 534c368adc..744df8d63b 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1411,17 +1411,17 @@ int main (int argc, char * const * argv) auto hash (info.open_block); nano::block_hash calculated_hash (0); - auto block (node->store.block.get (transaction, hash)); // Block data + auto block = node->ledger.block (transaction, hash); // Block data uint64_t height (0); if (node->ledger.pruning && confirmation_height_info.height != 0) { hash = confirmation_height_info.frontier; - block = node->store.block.get (transaction, hash); + block = node->ledger.block (transaction, hash); // Iteration until pruned block bool pruned_block (false); while (!pruned_block && !block->previous ().is_zero ()) { - auto previous_block (node->store.block.get (transaction, block->previous ())); + auto previous_block = node->ledger.block (transaction, block->previous ()); if (previous_block != nullptr) { hash = previous_block->hash (); @@ -1591,7 +1591,7 @@ int main (int argc, char * const * argv) // Retrieving block data if (!hash.is_zero ()) { - block = node->store.block.get (transaction, hash); + block = node->ledger.block (transaction, hash); } } // Check if required block exists @@ -1676,7 +1676,7 @@ int main (int argc, char * const * argv) std::cout << boost::str (boost::format ("%1% pending blocks validated\n") % count); } // Check block existance - auto block (node->store.block.get (transaction, key.hash)); + auto block = node->ledger.block (transaction, key.hash); bool pruned (false); if (block == nullptr) { @@ -1693,7 +1693,7 @@ int main (int argc, char * const * argv) bool previous_pruned = node->ledger.pruning && node->store.pruned.exists (transaction, block->previous ()); if (previous_pruned) { - block = node->store.block.get (transaction, key.hash); + block = node->ledger.block (transaction, key.hash); } if (auto state = dynamic_cast (block.get ())) { @@ -1800,7 +1800,7 @@ int main (int argc, char * const * argv) while (!hash.is_zero ()) { // Retrieving block data - auto block (source_node->store.block.get (transaction, hash)); + auto block = source_node->ledger.block (transaction, hash); if (block != nullptr) { ++count; diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 8fda11587c..258eb4e883 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -253,13 +253,13 @@ std::vector> nano::bootstrap_server::prepare_blocks std::vector> result; if (!start_block.is_zero ()) { - std::shared_ptr current = store.block.get (transaction, start_block); + std::shared_ptr current = ledger.block (transaction, start_block); while (current && result.size () < count) { result.push_back (current); auto successor = current->sideband ().successor; - current = store.block.get (transaction, successor); + current = ledger.block (transaction, successor); } } return result; @@ -337,4 +337,4 @@ nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & t response.payload = response_payload; response.update_header (); return response; -} \ No newline at end of file +} diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 9136dc7c5d..f2ed6623ac 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -83,7 +83,7 @@ void nano::confirmation_height_bounded::process (std::shared_ptr or } else { - block = ledger.store.block.get (transaction, current); + block = ledger.block (transaction, current); } if (!block) @@ -227,7 +227,7 @@ nano::block_hash nano::confirmation_height_bounded::get_least_unconfirmed_hash_f { if (block_height_a > confirmation_height_info_a.height) { - auto block (ledger.store.block.get (transaction_a, confirmation_height_info_a.frontier)); + auto block = ledger.block (transaction_a, confirmation_height_info_a.frontier); release_assert (block != nullptr); least_unconfirmed_hash = block->sideband ().successor; block_height_a = block->sideband ().height + 1; @@ -255,7 +255,7 @@ bool nano::confirmation_height_bounded::iterate (store::read_transaction const & // Keep iterating upwards until we either reach the desired block or the second receive. // Once a receive is cemented, we can cement all blocks above it until the next receive, so store those details for later. ++num_blocks; - auto block = ledger.store.block.get (transaction_a, hash); + auto block = ledger.block (transaction_a, hash); auto source (block->source ()); if (source.is_zero ()) { @@ -384,7 +384,7 @@ void nano::confirmation_height_bounded::cement_blocks (nano::write_guard & scope // Extra debug checks nano::confirmation_height_info confirmation_height_info; ledger.store.confirmation_height.get (transaction, account, confirmation_height_info); - auto block (ledger.store.block.get (transaction, confirmed_frontier)); + auto block = ledger.block (transaction, confirmed_frontier); debug_assert (block != nullptr); debug_assert (block->sideband ().height == confirmation_height_info.height + num_blocks_cemented); #endif @@ -414,14 +414,14 @@ void nano::confirmation_height_bounded::cement_blocks (nano::write_guard & scope } else { - auto block = ledger.store.block.get (transaction, confirmation_height_info.frontier); + auto block = ledger.block (transaction, confirmation_height_info.frontier); new_cemented_frontier = block->sideband ().successor; num_blocks_confirmed = pending.top_height - confirmation_height_info.height; start_height = confirmation_height_info.height + 1; } auto total_blocks_cemented = 0; - auto block = ledger.store.block.get (transaction, new_cemented_frontier); + auto block = ledger.block (transaction, new_cemented_frontier); // Cementing starts from the bottom of the chain and works upwards. This is because chains can have effectively // an infinite number of send/change blocks in a row. We don't want to hold the write transaction open for too long. @@ -480,7 +480,7 @@ void nano::confirmation_height_bounded::cement_blocks (nano::write_guard & scope if (!last_iteration) { new_cemented_frontier = block->sideband ().successor; - block = ledger.store.block.get (transaction, new_cemented_frontier); + block = ledger.block (transaction, new_cemented_frontier); } else { diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 8f50f39dcb..e99766d1ba 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -376,7 +376,7 @@ void nano::confirmation_height_unbounded::cement_blocks (nano::write_guard & sco auto confirmation_height = confirmation_height_info.height; if (pending.height > confirmation_height) { - auto block = ledger.store.block.get (transaction, pending.hash); + auto block = ledger.block (transaction, pending.hash); debug_assert (ledger.pruning || block != nullptr); debug_assert (ledger.pruning || block->sideband ().height == pending.height); @@ -438,7 +438,7 @@ std::shared_ptr nano::confirmation_height_unbounded::get_block_and_ } else { - auto block (ledger.store.block.get (transaction_a, hash_a)); + auto block = ledger.block (transaction_a, hash_a); block_cache.emplace (hash_a, block); return block; } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index c84a257b14..d50bacdd16 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -397,7 +397,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) auto previous (block_a.previous ()); if (!previous.is_zero ()) { - block_previous = node.store.block.get (transaction, previous); + block_previous = node.ledger.block (transaction, previous); } // Send check if (block_previous != nullptr) @@ -413,7 +413,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a) auto link (block_a.link ()); if (!link.is_zero () && !details.is_send) { - auto block_link (node.store.block.get (transaction, link.as_block_hash ())); + auto block_link = node.ledger.block (transaction, link.as_block_hash ()); if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (block_a.account (), link.as_block_hash ()))) { details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch); @@ -672,7 +672,7 @@ void nano::json_handler::account_info () std::shared_ptr confirmed_frontier_block; if (include_confirmed && confirmation_height_info.height > 0) { - confirmed_frontier_block = node.store.block.get (transaction, confirmation_height_info.frontier); + confirmed_frontier_block = node.ledger.block (transaction, confirmation_height_info.frontier); } if (representative) @@ -686,7 +686,7 @@ void nano::json_handler::account_info () confirmed_representative = confirmed_frontier_block->representative (); if (confirmed_representative.is_zero ()) { - confirmed_representative = node.store.block.get (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative (); + confirmed_representative = node.ledger.block (transaction, node.ledger.representative (transaction, confirmation_height_info.frontier))->representative (); } } @@ -1145,7 +1145,7 @@ void nano::json_handler::block_info () if (!ec) { auto transaction (node.store.tx_begin_read ()); - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); if (block != nullptr) { nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); @@ -1197,7 +1197,7 @@ void nano::json_handler::block_confirm () if (!ec) { auto transaction (node.store.tx_begin_read ()); - auto block_l (node.store.block.get (transaction, hash)); + auto block_l = node.ledger.block (transaction, hash); if (block_l != nullptr) { if (!node.ledger.block_confirmed (transaction, hash)) @@ -1252,7 +1252,7 @@ void nano::json_handler::blocks () nano::block_hash hash; if (!hash.decode_hex (hash_text)) { - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); if (block != nullptr) { if (json_block_l) @@ -1303,7 +1303,7 @@ void nano::json_handler::blocks_info () nano::block_hash hash; if (!hash.decode_hex (hash_text)) { - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); if (block != nullptr) { boost::property_tree::ptree entry; @@ -1385,7 +1385,7 @@ void nano::json_handler::blocks_info () if (source) { nano::block_hash source_hash (node.ledger.block_source (transaction, *block)); - auto block_a (node.store.block.get (transaction, source_hash)); + auto block_a = node.ledger.block (transaction, source_hash); if (block_a != nullptr) { auto source_account (node.ledger.account (transaction, source_hash)); @@ -1945,7 +1945,7 @@ void nano::json_handler::chain (bool successors) auto transaction (node.store.tx_begin_read ()); while (!hash.is_zero () && blocks.size () < count) { - auto block_l (node.store.block.get (transaction, hash)); + auto block_l = node.ledger.block (transaction, hash); if (block_l != nullptr) { if (offset > 0) @@ -2643,7 +2643,7 @@ void nano::json_handler::account_history () boost::property_tree::ptree history; bool output_raw (request.get_optional ("raw") == true); response_l.put ("account", account.to_account ()); - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); while (block != nullptr && count > 0) { if (offset > 0) @@ -2671,7 +2671,7 @@ void nano::json_handler::account_history () } } hash = reverse ? node.store.block.successor (transaction, hash) : block->previous (); - block = node.store.block.get (transaction, hash); + block = node.ledger.block (transaction, hash); } response_l.add_child ("history", history); if (!hash.is_zero ()) @@ -3164,7 +3164,7 @@ void nano::json_handler::receivable_exists () if (!ec) { auto transaction (node.store.tx_begin_read ()); - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); if (block != nullptr) { auto exists (false); @@ -3638,28 +3638,28 @@ void nano::json_handler::republish () { boost::property_tree::ptree blocks; auto transaction (node.store.tx_begin_read ()); - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); if (block != nullptr) { std::deque> republish_bundle; for (auto i (0); !hash.is_zero () && i < count; ++i) { - block = node.store.block.get (transaction, hash); + block = node.ledger.block (transaction, hash); if (sources != 0) // Republish source chain { nano::block_hash source (node.ledger.block_source (transaction, *block)); - auto block_a (node.store.block.get (transaction, source)); + auto block_a = node.ledger.block (transaction, source); std::vector hashes; while (block_a != nullptr && hashes.size () < sources) { hashes.push_back (source); source = block_a->previous (); - block_a = node.store.block.get (transaction, source); + block_a = node.ledger.block (transaction, source); } std::reverse (hashes.begin (), hashes.end ()); for (auto & hash_l : hashes) { - block_a = node.store.block.get (transaction, hash_l); + block_a = node.ledger.block (transaction, hash_l); republish_bundle.push_back (std::move (block_a)); boost::property_tree::ptree entry_l; entry_l.put ("", hash_l.to_string ()); @@ -3672,14 +3672,14 @@ void nano::json_handler::republish () blocks.push_back (std::make_pair ("", entry)); if (destinations != 0) // Republish destination chain { - auto block_b (node.store.block.get (transaction, hash)); + auto block_b = node.ledger.block (transaction, hash); auto destination (node.ledger.block_destination (transaction, *block_b)); if (!destination.is_zero ()) { if (!node.store.pending.exists (transaction, nano::pending_key (destination, hash))) { nano::block_hash previous (node.ledger.latest (transaction, destination)); - auto block_d (node.store.block.get (transaction, previous)); + auto block_d = node.ledger.block (transaction, previous); nano::block_hash source; std::vector hashes; while (block_d != nullptr && hash != source) @@ -3687,7 +3687,7 @@ void nano::json_handler::republish () hashes.push_back (previous); source = node.ledger.block_source (transaction, *block_d); previous = block_d->previous (); - block_d = node.store.block.get (transaction, previous); + block_d = node.ledger.block (transaction, previous); } std::reverse (hashes.begin (), hashes.end ()); if (hashes.size () > destinations) @@ -3696,7 +3696,7 @@ void nano::json_handler::republish () } for (auto & hash_l : hashes) { - block_d = node.store.block.get (transaction, hash_l); + block_d = node.ledger.block (transaction, hash_l); republish_bundle.push_back (std::move (block_d)); boost::property_tree::ptree entry_l; entry_l.put ("", hash_l.to_string ()); @@ -4658,7 +4658,7 @@ void nano::json_handler::wallet_history () auto hash (info->head); while (timestamp >= modified_since && !hash.is_zero ()) { - auto block (node.store.block.get (block_transaction, hash)); + auto block = node.ledger.block (block_transaction, hash); timestamp = block->sideband ().timestamp; if (block != nullptr && timestamp >= modified_since) { @@ -4932,7 +4932,7 @@ void nano::json_handler::wallet_republish () while (!latest.is_zero () && hashes.size () < count) { hashes.push_back (latest); - block = node.store.block.get (block_transaction, latest); + block = node.ledger.block (block_transaction, latest); if (block != nullptr) { latest = block->previous (); @@ -4945,7 +4945,7 @@ void nano::json_handler::wallet_republish () std::reverse (hashes.begin (), hashes.end ()); for (auto & hash : hashes) { - block = node.store.block.get (block_transaction, hash); + block = node.ledger.block (block_transaction, hash); republish_bundle.push_back (std::move (block)); boost::property_tree::ptree entry; entry.put ("", hash.to_string ()); @@ -5463,7 +5463,7 @@ bool block_confirmed (nano::node & node, nano::store::transaction & transaction, // This just checks it's not currently undergoing an active transaction else if (!include_only_confirmed) { - auto block (node.store.block.get (transaction, hash)); + auto block = node.ledger.block (transaction, hash); is_confirmed = (block != nullptr && !node.active.active (*block)); } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index ac5f56b2c9..b3da87e61a 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -727,8 +727,7 @@ nano::uint128_t nano::node::balance (nano::account const & account_a) std::shared_ptr nano::node::block (nano::block_hash const & hash_a) { - auto const transaction (store.tx_begin_read ()); - return store.block.get (transaction, hash_a); + return ledger.block (store.tx_begin_read (), hash_a); } std::pair nano::node::balance_pending (nano::account const & account_a, bool only_confirmed_a) @@ -921,7 +920,7 @@ bool nano::node::collect_ledger_pruning_targets (std::deque & uint64_t depth (0); while (!hash.is_zero () && depth < max_depth_a) { - auto block (store.block.get (transaction, hash)); + auto block = ledger.block (transaction, hash); if (block != nullptr) { if (block->sideband ().timestamp > cutoff_time_a || depth == 0) @@ -1271,7 +1270,7 @@ void nano::node::process_confirmed (nano::election_status const & status_a, uint { auto hash (status_a.winner->hash ()); decltype (iteration_a) const num_iters = (config.block_processor_batch_max_time / network_params.node.process_confirmed_interval) * 4; - if (auto block_l = ledger.store.block.get (ledger.store.tx_begin_read (), hash)) + if (auto block_l = ledger.block (ledger.store.tx_begin_read (), hash)) { logger.trace (nano::log::type::node, nano::log::detail::process_confirmed, nano::log::arg{ "block", block_l }); diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index bb60519824..452f0e0ba0 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -204,12 +204,12 @@ std::pair>, std::vector 1) { to_generate_final.push_back (block); - block = ledger.store.block.get (transaction, final_vote_hashes[1]); + block = ledger.block (transaction, final_vote_hashes[1]); debug_assert (final_vote_hashes.size () == 2); } } @@ -223,7 +223,7 @@ std::pair>, std::vector>, std::vectorhead); auto hash = conf_info.height == 0 ? info->open_block : node.store.block.successor (transaction, conf_info.frontier); - auto block = node.store.block.get (transaction, hash); + auto block = node.ledger.block (transaction, hash); debug_assert (block != nullptr); if (node.ledger.dependents_confirmed (transaction, *block)) { diff --git a/nano/node/voting.cpp b/nano/node/voting.cpp index b238f38538..9ea31745d8 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting.cpp @@ -186,7 +186,7 @@ nano::vote_generator::~vote_generator () bool nano::vote_generator::should_vote (store::write_transaction const & transaction, nano::root const & root_a, nano::block_hash const & hash_a) { - auto block = ledger.store.block.get (transaction, hash_a); + auto block = ledger.block (transaction, hash_a); bool should_vote = false; if (is_final) { diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 7dd08665d1..e1c2d7a834 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -955,7 +955,7 @@ std::shared_ptr nano::wallet::send_action (nano::account const & so if (status == 0) { nano::block_hash hash (result); - block = wallets.node.store.block.get (block_transaction, hash); + block = wallets.node.ledger.block (block_transaction, hash); if (block != nullptr) { cached_block = true; @@ -1199,7 +1199,7 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact } else if (!wallets.node.confirmation_height_processor.is_processing_block (hash)) { - auto block (wallets.node.store.block.get (block_transaction, hash)); + auto block = wallets.node.ledger.block (block_transaction, hash); if (block) { // Request confirmation for block which is not being processed yet diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 2b83d7d61a..99e47a3eb7 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -622,7 +622,7 @@ void nano_qt::history::refresh () for (auto i (0), n (tx_count->value ()); i < n && !hash.is_zero (); ++i) { QList items; - auto block (ledger.store.block.get (transaction, hash)); + auto block (ledger.block (transaction, hash)); if (block != nullptr) { block->visit (visitor); @@ -671,7 +671,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : if (!hash_l.decode_hex (hash->text ().toStdString ())) { auto transaction (this->wallet.node.store.tx_begin_read ()); - auto block_l (this->wallet.node.store.block.get (transaction, hash_l)); + auto block_l (this->wallet.node.ledger.block (transaction, hash_l)); if (block_l != nullptr) { std::string contents; @@ -717,7 +717,7 @@ void nano_qt::block_viewer::rebroadcast_action (nano::block_hash const & hash_a) { auto done (true); auto transaction (wallet.node.ledger.store.tx_begin_read ()); - auto block (wallet.node.store.block.get (transaction, hash_a)); + auto block (wallet.node.ledger.block (transaction, hash_a)); if (block != nullptr) { wallet.node.network.flood_block (block); @@ -2299,7 +2299,7 @@ void nano_qt::block_creation::create_receive () { auto transaction (wallet.node.wallets.tx_begin_read ()); auto block_transaction (wallet.node.store.tx_begin_read ()); - auto block_l (wallet.node.store.block.get (block_transaction, source_l)); + auto block_l (wallet.node.ledger.block (block_transaction, source_l)); if (block_l != nullptr) { auto const & destination (wallet.node.ledger.block_destination (block_transaction, *block_l)); @@ -2464,7 +2464,7 @@ void nano_qt::block_creation::create_open () { auto transaction (wallet.node.wallets.tx_begin_read ()); auto block_transaction (wallet.node.store.tx_begin_read ()); - auto block_l (wallet.node.store.block.get (block_transaction, source_l)); + auto block_l (wallet.node.ledger.block (block_transaction, source_l)); if (block_l != nullptr) { auto const & destination (wallet.node.ledger.block_destination (block_transaction, *block_l)); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 4f1c158f98..569cdd8841 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2395,7 +2395,7 @@ TEST (rpc, account_representative_set) wallet.insert_adhoc (key2.prv); auto key2_open_block_hash = wallet.send_sync (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()); ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), key2_open_block_hash)); - auto key2_open_block = node->store.block.get (node->store.tx_begin_read (), key2_open_block_hash); + auto key2_open_block = node->ledger.block (node->store.tx_begin_read (), key2_open_block_hash); ASSERT_EQ (nano::dev::genesis_key.pub, key2_open_block->representative ()); // now change the representative of key2 to be genesis @@ -2412,7 +2412,7 @@ TEST (rpc, account_representative_set) nano::block_hash hash; ASSERT_FALSE (hash.decode_hex (block_text1)); ASSERT_FALSE (hash.is_zero ()); - auto block = node->store.block.get (node->store.tx_begin_read (), hash); + auto block = node->ledger.block (node->store.tx_begin_read (), hash); ASSERT_NE (block, nullptr); ASSERT_TIMELY (5s, node->ledger.block_confirmed (node->store.tx_begin_read (), hash)); ASSERT_EQ (key2.pub, block->representative ()); @@ -5228,7 +5228,7 @@ TEST (rpc, confirmation_height_currently_processing) std::shared_ptr frontier; { auto transaction = node->store.tx_begin_read (); - frontier = node->store.block.get (transaction, previous_genesis_chain_hash); + frontier = node->ledger.block (transaction, previous_genesis_chain_hash); } boost::property_tree::ptree request; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index dc2651b89a..a381a7a258 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -695,7 +695,7 @@ ledger_processor::ledger_processor (nano::ledger & ledger_a, nano::store::write_ class representative_visitor final : public nano::block_visitor { public: - representative_visitor (nano::store::transaction const & transaction_a, nano::store::component & store_a); + representative_visitor (nano::store::transaction const & transaction_a, nano::ledger & ledger); ~representative_visitor () = default; void compute (nano::block_hash const & hash_a); void send_block (nano::send_block const & block_a) override; @@ -704,15 +704,15 @@ class representative_visitor final : public nano::block_visitor void change_block (nano::change_block const & block_a) override; void state_block (nano::state_block const & block_a) override; nano::store::transaction const & transaction; - nano::store::component & store; + nano::ledger & ledger; nano::block_hash current; nano::block_hash result; }; -representative_visitor::representative_visitor (nano::store::transaction const & transaction_a, nano::store::component & store_a) : - transaction (transaction_a), - store (store_a), - result (0) +representative_visitor::representative_visitor (nano::store::transaction const & transaction_a, nano::ledger & ledger) : + transaction{ transaction_a }, + ledger{ ledger }, + result{ 0 } { } @@ -721,9 +721,9 @@ void representative_visitor::compute (nano::block_hash const & hash_a) current = hash_a; while (result.is_zero ()) { - auto block (store.block.get (transaction, current)); - debug_assert (block != nullptr); - block->visit (*this); + auto block_l = ledger.block (transaction, current); + debug_assert (block_l != nullptr); + block_l->visit (*this); } } @@ -840,9 +840,9 @@ nano::uint128_t nano::ledger::balance (store::transaction const & transaction, n { return 0; } - auto block = store.block.get (transaction, hash); - debug_assert (block != nullptr); - return balance (*block); + auto block_l = block (transaction, hash); + debug_assert (block_l != nullptr); + return balance (*block_l); } nano::uint128_t nano::ledger::balance_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const @@ -860,6 +860,11 @@ nano::uint128_t nano::ledger::balance_safe (store::transaction const & transacti return result; } +std::shared_ptr nano::ledger::block (store::transaction const & transaction, nano::block_hash const & hash) const +{ + return store.block.get (transaction, hash); +} + // Balance for an account by account number nano::uint128_t nano::ledger::account_balance (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { @@ -936,7 +941,7 @@ nano::block_hash nano::ledger::representative (store::transaction const & transa nano::block_hash nano::ledger::representative_calculated (store::transaction const & transaction_a, nano::block_hash const & hash_a) { - representative_visitor visitor (transaction_a, store); + representative_visitor visitor (transaction_a, *this); visitor.compute (hash_a); return visitor.result; } @@ -969,10 +974,10 @@ std::string nano::ledger::block_text (nano::block_hash const & hash_a) { std::string result; auto transaction (store.tx_begin_read ()); - auto block (store.block.get (transaction, hash_a)); - if (block != nullptr) + auto block_l = block (transaction, hash_a); + if (block_l != nullptr) { - block->serialize_json (result); + block_l->serialize_json (result); } return result; } @@ -1111,9 +1116,9 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan { auto info = account_info (transaction_a, account_l); debug_assert (info); - auto block (store.block.get (transaction_a, info->head)); - list_a.push_back (block); - block->visit (rollback); + auto block_l = block (transaction_a, info->head); + list_a.push_back (block_l); + block_l->visit (rollback); error = rollback.error; if (!error) { @@ -1148,9 +1153,9 @@ nano::account nano::ledger::account (nano::block const & block) const nano::account nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const { - auto block = store.block.get (transaction, hash); - debug_assert (block != nullptr); - return account (*block); + auto block_l = block (transaction, hash); + debug_assert (block_l != nullptr); + return account (*block_l); } nano::account nano::ledger::account_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const @@ -1161,10 +1166,10 @@ nano::account nano::ledger::account_safe (store::transaction const & transaction } else { - auto block (store.block.get (transaction_a, hash_a)); - if (block != nullptr) + auto block_l = block (transaction_a, hash_a); + if (block_l != nullptr) { - return account (*block); + return account (*block_l); } else { @@ -1176,10 +1181,10 @@ nano::account nano::ledger::account_safe (store::transaction const & transaction nano::account nano::ledger::account_safe (store::transaction const & transaction, nano::block_hash const & hash) const { - auto block = store.block.get (transaction, hash); - if (block) + auto block_l = block (transaction, hash); + if (block_l) { - return account (*block); + return account (*block_l); } else { @@ -1194,18 +1199,18 @@ std::optional nano::ledger::account_info (store::transaction nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) { - auto block (store.block.get (transaction_a, hash_a)); + auto block_l = block (transaction_a, hash_a); auto block_balance (balance (transaction_a, hash_a)); - auto previous_balance (balance (transaction_a, block->previous ())); + auto previous_balance (balance (transaction_a, block_l->previous ())); return block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; } nano::uint128_t nano::ledger::amount_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { - auto block (store.block.get (transaction_a, hash_a)); - debug_assert (block); + auto block_l = block (transaction_a, hash_a); + debug_assert (block_l); auto block_balance (balance (transaction_a, hash_a)); - auto previous_balance (balance_safe (transaction_a, block->previous (), error_a)); + auto previous_balance (balance_safe (transaction_a, block_l->previous (), error_a)); return error_a ? 0 : block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; } @@ -1237,10 +1242,10 @@ void nano::ledger::dump_account_chain (nano::account const & account_a, std::ost auto hash (latest (transaction, account_a)); while (!hash.is_zero ()) { - auto block (store.block.get (transaction, hash)); - debug_assert (block != nullptr); + auto block_l = block (transaction, hash); + debug_assert (block_l != nullptr); stream << hash.to_string () << std::endl; - hash = block->previous (); + hash = block_l->previous (); } } @@ -1328,7 +1333,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (stor { return nullptr; } - auto possible_receive_block = store.block.get (transaction, info.frontier); + auto possible_receive_block = block (transaction, info.frontier); // walk down the chain until the source field of a receive block matches the send block hash while (possible_receive_block != nullptr) @@ -1355,7 +1360,7 @@ std::shared_ptr nano::ledger::find_receive_block_by_send_hash (stor break; } - possible_receive_block = store.block.get (transaction, possible_receive_block->previous ()); + possible_receive_block = block (transaction, possible_receive_block->previous ()); } return result; @@ -1423,7 +1428,7 @@ std::shared_ptr nano::ledger::successor (store::transaction const & std::shared_ptr result; if (!successor.is_zero ()) { - result = store.block.get (transaction_a, successor); + result = block (transaction_a, successor); } debug_assert (successor.is_zero () || result != nullptr); return result; @@ -1434,12 +1439,12 @@ std::shared_ptr nano::ledger::forked_block (store::transaction cons debug_assert (!store.block.exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); debug_assert (store.block.exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); - auto result (store.block.get (transaction_a, store.block.successor (transaction_a, root.as_block_hash ()))); + auto result = block (transaction_a, store.block.successor (transaction_a, root.as_block_hash ())); if (result == nullptr) { auto info = account_info (transaction_a, root.as_account ()); debug_assert (info); - result = store.block.get (transaction_a, info->open_block); + result = block (transaction_a, info->open_block); debug_assert (result != nullptr); } return result; @@ -1450,7 +1455,7 @@ std::shared_ptr nano::ledger::head_block (store::transaction const auto info = store.account.get (transaction, account); if (info) { - return store.block.get (transaction, info->head); + return block (transaction, info->head); } return nullptr; } @@ -1461,12 +1466,12 @@ bool nano::ledger::block_confirmed (store::transaction const & transaction_a, na { return true; } - auto block = store.block.get (transaction_a, hash_a); - if (block) + auto block_l = block (transaction_a, hash_a); + if (block_l) { nano::confirmation_height_info confirmation_height_info; - store.confirmation_height.get (transaction_a, block->account ().is_zero () ? block->sideband ().account : block->account (), confirmation_height_info); - auto confirmed (confirmation_height_info.height >= block->sideband ().height); + store.confirmation_height.get (transaction_a, block_l->account ().is_zero () ? block_l->sideband ().account : block_l->account (), confirmation_height_info); + auto confirmed (confirmation_height_info.height >= block_l->sideband ().height); return confirmed; } return false; @@ -1478,12 +1483,12 @@ uint64_t nano::ledger::pruning_action (store::write_transaction & transaction_a, nano::block_hash hash (hash_a); while (!hash.is_zero () && hash != constants.genesis->hash ()) { - auto block (store.block.get (transaction_a, hash)); - if (block != nullptr) + auto block_l = block (transaction_a, hash); + if (block_l != nullptr) { store.block.del (transaction_a, hash); store.pruned.put (transaction_a, hash); - hash = block->previous (); + hash = block_l->previous (); ++pruned_count; ++cache.pruned_count; if (pruned_count % batch_size_a == 0) @@ -1685,18 +1690,18 @@ nano::epoch nano::ledger::version (nano::block const & block) nano::epoch nano::ledger::version (store::transaction const & transaction, nano::block_hash const & hash) const { - auto block = store.block.get (transaction, hash); - if (block == nullptr) + auto block_l = block (transaction, hash); + if (block_l == nullptr) { return nano::epoch::epoch_0; } - return version (*block); + return version (*block_l); } uint64_t nano::ledger::height (store::transaction const & transaction, nano::block_hash const & hash) const { - auto block = store.block.get (transaction, hash); - return block->sideband ().height; + auto block_l = block (transaction, hash); + return block_l->sideband ().height; } nano::uncemented_info::uncemented_info (nano::block_hash const & cemented_frontier, nano::block_hash const & frontier, nano::account const & account) : diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index ac6206e6ea..d0d56ebb2f 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -51,6 +51,7 @@ class ledger final static nano::uint128_t balance (nano::block const & block); nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const; nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const; + std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); nano::uint128_t weight (nano::account const &); diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 1dd982e004..b9b8e4ed40 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -100,7 +100,7 @@ TEST (system, receive_while_synchronizing) node1->workers.add_timed_task (std::chrono::steady_clock::now () + std::chrono::milliseconds (200), ([&system, &key] () { auto hash (system.wallet (0)->send_sync (nano::dev::genesis_key.pub, key.pub, system.nodes[0]->config.receive_minimum.number ())); auto transaction (system.nodes[0]->store.tx_begin_read ()); - auto block (system.nodes[0]->store.block.get (transaction, hash)); + auto block = system.nodes[0]->ledger.block (transaction, hash); std::string block_text; block->serialize_json (block_text); })); @@ -2162,7 +2162,7 @@ TEST (node, wallet_create_block_confirm_conflicts) // Call block confirm on the top level send block which will confirm everything underneath on both accounts. { - auto block = node->store.block.get (node->store.tx_begin_read (), latest); + auto block = node->ledger.block (node->store.tx_begin_read (), latest); node->scheduler.manual.push (block); std::shared_ptr election; ASSERT_TIMELY (10s, (election = node->active.election (block->qualified_root ())) != nullptr); diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 37e1376253..3ba0ce0009 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -416,7 +416,7 @@ void nano::test::system::generate_receive (nano::node & node_a) if (i != node_a.store.pending.end ()) { nano::pending_key const & send_hash (i->first); - send_block = node_a.store.block.get (transaction, send_hash.hash); + send_block = node_a.ledger.block (transaction, send_hash.hash); } } if (send_block != nullptr) From d68da31abc288c5c39a412568cbbcadbb7c4a641 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 5 Mar 2024 14:31:14 +0000 Subject: [PATCH 07/22] Reduce coupling to store.block.exists by using ledger::block_exists interface. --- nano/core_test/bootstrap.cpp | 10 ++-- nano/core_test/ledger.cpp | 54 ++++++++++----------- nano/core_test/node.cpp | 16 +++--- nano/core_test/wallet.cpp | 2 +- nano/node/bootstrap/bootstrap_bulk_pull.cpp | 4 +- nano/node/bootstrap/bootstrap_server.cpp | 2 +- nano/node/confirmation_height_bounded.cpp | 2 +- nano/node/confirmation_height_unbounded.cpp | 2 +- nano/node/json_handler.cpp | 10 ++-- nano/qt/qt.cpp | 2 +- nano/qt_test/qt.cpp | 2 +- nano/rpc_test/rpc.cpp | 14 +++--- nano/secure/ledger.cpp | 27 ++++++----- nano/secure/ledger.hpp | 1 + 14 files changed, 77 insertions(+), 71 deletions(-) diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index bf1045d118..d1fbbb375a 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -659,13 +659,13 @@ TEST (bootstrap_processor, push_diamond_pruning) auto transaction (node1->store.tx_begin_write ()); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 2)); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, open->hash (), 1)); - ASSERT_TRUE (node1->store.block.exists (transaction, nano::dev::genesis->hash ())); - ASSERT_FALSE (node1->store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (node1->ledger.block_exists (transaction, nano::dev::genesis->hash ())); + ASSERT_FALSE (node1->ledger.block_exists (transaction, send1->hash ())); ASSERT_TRUE (node1->store.pruned.exists (transaction, send1->hash ())); - ASSERT_FALSE (node1->store.block.exists (transaction, open->hash ())); + ASSERT_FALSE (node1->ledger.block_exists (transaction, open->hash ())); ASSERT_TRUE (node1->store.pruned.exists (transaction, open->hash ())); - ASSERT_TRUE (node1->store.block.exists (transaction, send2->hash ())); - ASSERT_TRUE (node1->store.block.exists (transaction, receive->hash ())); + ASSERT_TRUE (node1->ledger.block_exists (transaction, send2->hash ())); + ASSERT_TRUE (node1->ledger.block_exists (transaction, receive->hash ())); ASSERT_EQ (2, node1->ledger.cache.pruned_count); ASSERT_EQ (5, node1->ledger.cache.block_count); } diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 1436e3006f..eb29e207d6 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2382,7 +2382,7 @@ TEST (ledger, state_send_receive) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2405,7 +2405,7 @@ TEST (ledger, state_send_receive) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); @@ -2437,7 +2437,7 @@ TEST (ledger, state_receive) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2455,7 +2455,7 @@ TEST (ledger, state_receive) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); @@ -2488,7 +2488,7 @@ TEST (ledger, state_rep_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); - ASSERT_TRUE (store.block.exists (transaction, change1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, change1->hash ())); auto change2 = ledger.block (transaction, change1->hash ()); ASSERT_NE (nullptr, change2); ASSERT_EQ (*change1, *change2); @@ -2522,7 +2522,7 @@ TEST (ledger, state_open) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2542,7 +2542,7 @@ TEST (ledger, state_open) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (destination.pub, send1->hash ()))); - ASSERT_TRUE (store.block.exists (transaction, open1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, open1->hash ())); auto open2 = ledger.block (transaction, open1->hash ()); ASSERT_NE (nullptr, open2); ASSERT_EQ (*open1, *open2); @@ -2665,7 +2665,7 @@ TEST (ledger, state_unreceivable_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2702,7 +2702,7 @@ TEST (ledger, state_receive_bad_amount_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2774,7 +2774,7 @@ TEST (ledger, state_receive_wrong_account_fail) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -2968,7 +2968,7 @@ TEST (ledger, state_send_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -3001,7 +3001,7 @@ TEST (ledger, state_receive_change) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -3020,7 +3020,7 @@ TEST (ledger, state_receive_change) .work (*pool.generate (send1->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); - ASSERT_TRUE (store.block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, receive1->hash ())); auto receive2 = ledger.block (transaction, receive1->hash ()); ASSERT_NE (nullptr, receive2); ASSERT_EQ (*receive1, *receive2); @@ -3140,7 +3140,7 @@ TEST (ledger, state_rollback_send) .work (*pool.generate (nano::dev::genesis->hash ())) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); - ASSERT_TRUE (store.block.exists (transaction, send1->hash ())); + ASSERT_TRUE (ledger.block_exists (transaction, send1->hash ())); auto send2 = ledger.block (transaction, send1->hash ()); ASSERT_NE (nullptr, send2); ASSERT_EQ (*send1, *send2); @@ -3151,7 +3151,7 @@ TEST (ledger, state_rollback_send) ASSERT_EQ (nano::dev::genesis->account (), info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); @@ -3195,7 +3195,7 @@ TEST (ledger, state_rollback_receive) ASSERT_TRUE (info); ASSERT_EQ (nano::dev::genesis->account (), info->source); ASSERT_EQ (nano::Gxrb_ratio, info->amount.number ()); - ASSERT_FALSE (store.block.exists (transaction, receive1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count); @@ -3235,8 +3235,8 @@ TEST (ledger, state_rollback_received_send) ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), receive1->hash ()))); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis->account (), send1->hash ()))); - ASSERT_FALSE (store.block.exists (transaction, send1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, receive1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); ASSERT_EQ (0, ledger.account_balance (transaction, key.pub)); @@ -3265,7 +3265,7 @@ TEST (ledger, state_rep_change_rollback) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, change1)); ASSERT_FALSE (ledger.rollback (transaction, change1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, change1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, change1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); ASSERT_EQ (0, ledger.weight (rep.pub)); @@ -3303,7 +3303,7 @@ TEST (ledger, state_open_rollback) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1)); ASSERT_FALSE (ledger.rollback (transaction, open1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, open1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, open1->hash ())); ASSERT_EQ (0, ledger.account_balance (transaction, destination.pub)); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); auto info = ledger.pending_info (transaction, nano::pending_key (destination.pub, send1->hash ())); @@ -3334,7 +3334,7 @@ TEST (ledger, state_send_change_rollback) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1)); ASSERT_FALSE (ledger.rollback (transaction, send1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, send1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis->account ())); ASSERT_EQ (0, ledger.weight (rep.pub)); @@ -3373,7 +3373,7 @@ TEST (ledger, state_receive_change_rollback) .build (); ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1)); ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ())); - ASSERT_FALSE (store.block.exists (transaction, receive1->hash ())); + ASSERT_FALSE (ledger.block_exists (transaction, receive1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.account_balance (transaction, nano::dev::genesis->account ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis->account ())); ASSERT_EQ (0, ledger.weight (rep.pub)); @@ -4206,7 +4206,7 @@ TEST (ledger, unchecked_epoch) } node1.block_processor.add (send1); node1.block_processor.add (open1); - ASSERT_TIMELY (5s, node1.store.block.exists (node1.store.tx_begin_read (), epoch1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.tx_begin_read (), epoch1->hash ())); { // Waits for the last blocks to pass through block_processor and unchecked.put queues ASSERT_TIMELY_EQ (10s, 0, node1.unchecked.count ()); @@ -4281,10 +4281,10 @@ TEST (ledger, unchecked_epoch_invalid) node1.block_processor.add (send1); node1.block_processor.add (open1); // Waits for the last blocks to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (10s, node1.store.block.exists (node1.store.tx_begin_read (), epoch2->hash ())); + ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), epoch2->hash ())); { auto transaction = node1.store.tx_begin_read (); - ASSERT_FALSE (node1.store.block.exists (transaction, epoch1->hash ())); + ASSERT_FALSE (node1.ledger.block_exists (transaction, epoch1->hash ())); auto unchecked_count = node1.unchecked.count (); ASSERT_EQ (unchecked_count, 0); ASSERT_EQ (unchecked_count, node1.unchecked.count ()); @@ -4348,7 +4348,7 @@ TEST (ledger, unchecked_open) } node1.block_processor.add (send1); // Waits for the send1 block to pass through block_processor and unchecked.put queues - ASSERT_TIMELY (5s, node1.store.block.exists (node1.store.tx_begin_read (), open1->hash ())); + ASSERT_TIMELY (5s, node1.ledger.block_exists (node1.store.tx_begin_read (), open1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } @@ -4419,7 +4419,7 @@ TEST (ledger, unchecked_receive) ASSERT_EQ (blocks.size (), 1); } node1.block_processor.add (send2); - ASSERT_TIMELY (10s, node1.store.block.exists (node1.store.tx_begin_read (), receive1->hash ())); + ASSERT_TIMELY (10s, node1.ledger.block_exists (node1.store.tx_begin_read (), receive1->hash ())); ASSERT_EQ (0, node1.unchecked.count ()); } diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 35c06a9cfa..fa999b31bc 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -668,8 +668,8 @@ TEST (node, fork_keep) auto winner (*election1->tally ().begin ()); ASSERT_EQ (*send1, *winner.second); ASSERT_EQ (nano::dev::constants.genesis_amount - 100, winner.first); - ASSERT_TRUE (node1.store.block.exists (transaction0, send1->hash ())); - ASSERT_TRUE (node2.store.block.exists (transaction1, send1->hash ())); + ASSERT_TRUE (node1.ledger.block_exists (transaction0, send1->hash ())); + ASSERT_TRUE (node2.ledger.block_exists (transaction1, send1->hash ())); } TEST (node, fork_flip) @@ -811,7 +811,7 @@ TEST (node, fork_bootstrap_flip) // Insert but don't rebroadcast, simulating settled blocks ASSERT_EQ (nano::block_status::progress, node1.ledger.process (node1.store.tx_begin_write (), send1)); ASSERT_EQ (nano::block_status::progress, node2.ledger.process (node2.store.tx_begin_write (), send2)); - ASSERT_TRUE (node2.store.block.exists (node2.store.tx_begin_read (), send2->hash ())); + ASSERT_TRUE (node2.ledger.block_exists (node2.store.tx_begin_read (), send2->hash ())); node2.bootstrap_initiator.bootstrap (node1.network.endpoint ()); // Additionally add new peer to confirm & replace bootstrap block auto again (true); system0.deadline_set (50s); @@ -820,7 +820,7 @@ TEST (node, fork_bootstrap_flip) { ASSERT_NO_ERROR (system0.poll ()); ASSERT_NO_ERROR (system1.poll ()); - again = !node2.store.block.exists (node2.store.tx_begin_read (), send1->hash ()); + again = !node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ()); } } @@ -972,9 +972,9 @@ TEST (node, fork_open_flip) // check the correct blocks are in the ledgers auto transaction1 (node1.store.tx_begin_read ()); auto transaction2 (node2.store.tx_begin_read ()); - ASSERT_TRUE (node1.store.block.exists (transaction1, open1->hash ())); - ASSERT_TRUE (node2.store.block.exists (transaction2, open1->hash ())); - ASSERT_FALSE (node2.store.block.exists (transaction2, open2->hash ())); + ASSERT_TRUE (node1.ledger.block_exists (transaction1, open1->hash ())); + ASSERT_TRUE (node2.ledger.block_exists (transaction2, open1->hash ())); + ASSERT_FALSE (node2.ledger.block_exists (transaction2, open2->hash ())); } TEST (node, coherent_observer) @@ -983,7 +983,7 @@ TEST (node, coherent_observer) auto & node1 (*system.nodes[0]); node1.observers.blocks.add ([&node1] (nano::election_status const & status_a, std::vector const &, nano::account const &, nano::uint128_t const &, bool, bool) { auto transaction (node1.store.tx_begin_read ()); - ASSERT_TRUE (node1.store.block.exists (transaction, status_a.winner->hash ())); + ASSERT_TRUE (node1.ledger.block_exists (transaction, status_a.winner->hash ())); }); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); nano::keypair key; diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index cbfa73eb9d..3c9802c633 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -1223,7 +1223,7 @@ TEST (wallet, receive_pruned) } ASSERT_EQ (1, node2.ledger.cache.pruned_count); ASSERT_TRUE (node2.ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2.store.block.exists (node2.store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node2.ledger.block_exists (node2.store.tx_begin_read (), send1->hash ())); wallet2.insert_adhoc (key.prv, false); diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 2fcd9653a2..276e64418c 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -363,14 +363,14 @@ void nano::bulk_pull_server::set_current_end () include_start = false; debug_assert (request != nullptr); auto transaction (node->store.tx_begin_read ()); - if (!node->store.block.exists (transaction, request->end)) + if (!node->ledger.block_exists (transaction, request->end)) { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull end block doesn't exist: {}, sending everything", request->end.to_string ()); request->end.clear (); } - if (node->store.block.exists (transaction, request->start.as_block_hash ())) + if (node->ledger.block_exists (transaction, request->start.as_block_hash ())) { node->logger.debug (nano::log::type::bulk_pull_server, "Bulk pull request for block hash: {}", request->start.to_string ()); diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 258eb4e883..5585212fd8 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -192,7 +192,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (store::transaction const & t { case asc_pull_req::hash_type::block: { - if (store.block.exists (transaction, request.start.as_block_hash ())) + if (ledger.block_exists (transaction, request.start.as_block_hash ())) { return prepare_response (transaction, id, request.start.as_block_hash (), count); } diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index f2ed6623ac..26cc21b42c 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -262,7 +262,7 @@ bool nano::confirmation_height_bounded::iterate (store::read_transaction const & source = block->link ().as_block_hash (); } - if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block.exists (transaction_a, source)) + if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { hit_receive = true; reached_target = true; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index e99766d1ba..18c1e0dc28 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -221,7 +221,7 @@ void nano::confirmation_height_unbounded::collect_unconfirmed_receive_and_source source = block->link ().as_block_hash (); } - if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.store.block.exists (transaction_a, source)) + if (!source.is_zero () && !ledger.is_epoch_link (source) && ledger.block_exists (transaction_a, source)) { if (!hit_receive && !block_callback_data_a.empty ()) { diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index d50bacdd16..3ef09287ad 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1432,7 +1432,7 @@ void nano::json_handler::block_account () if (!ec) { auto transaction (node.store.tx_begin_read ()); - if (node.store.block.exists (transaction, hash)) + if (node.ledger.block_exists (transaction, hash)) { auto account (node.ledger.account (transaction, hash)); response_l.put ("account", account.to_account ()); @@ -1652,7 +1652,7 @@ void nano::json_handler::block_create () else if (previous_text.is_initialized () && balance_text.is_initialized () && type == "send") { auto transaction (node.store.tx_begin_read ()); - if (node.store.block.exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ()) + if (node.ledger.block_exists (transaction, previous) && node.ledger.balance (transaction, previous) != balance.number ()) { ec = nano::error_rpc::block_create_balance_mismatch; } @@ -2605,7 +2605,7 @@ void nano::json_handler::account_history () { if (!hash.decode_hex (*head_str)) { - if (node.store.block.exists (transaction, hash)) + if (node.ledger.block_exists (transaction, hash)) { account = node.ledger.account (transaction, hash); } @@ -3198,7 +3198,7 @@ void nano::json_handler::process () { std::shared_ptr block_state (std::static_pointer_cast (block)); auto transaction (rpc_l->node.store.tx_begin_read ()); - if (!block_state->hashables.previous.is_zero () && !rpc_l->node.store.block.exists (transaction, block_state->hashables.previous)) + if (!block_state->hashables.previous.is_zero () && !rpc_l->node.ledger.block_exists (transaction, block_state->hashables.previous)) { rpc_l->ec = nano::error_process::gap_previous; } @@ -5093,7 +5093,7 @@ void nano::json_handler::work_generate () { // Fetch account from block if not given auto transaction_l (node.store.tx_begin_read ()); - if (node.store.block.exists (transaction_l, hash)) + if (node.ledger.block_exists (transaction_l, hash)) { account = node.ledger.account (transaction_l, hash); } diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 99e47a3eb7..efd112cd7b 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -696,7 +696,7 @@ nano_qt::block_viewer::block_viewer (nano_qt::wallet & wallet_a) : if (!error) { auto transaction (this->wallet.node.store.tx_begin_read ()); - if (this->wallet.node.store.block.exists (transaction, block)) + if (this->wallet.node.ledger.block_exists (transaction, block)) { rebroadcast->setEnabled (false); this->wallet.node.background ([this, block] () { diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 3a6d9b4dc1..3f1972bd16 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -389,7 +389,7 @@ TEST (wallet, DISABLED_process_block) { auto transaction (system.nodes[0]->store.tx_begin_read ()); system.deadline_set (10s); - while (system.nodes[0]->store.block.exists (transaction, send.hash ())) + while (system.nodes[0]->ledger.block_exists (transaction, send.hash ())) { ASSERT_NO_ERROR (system.poll ()); } diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 569cdd8841..32e8a12d35 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -4292,7 +4292,7 @@ TEST (rpc, block_info_pruning) { auto transaction (node1->store.tx_begin_write ()); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_TRUE (node1->store.block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); } auto const rpc_ctx = add_rpc (system, node1); // Pruned block @@ -4358,7 +4358,7 @@ TEST (rpc, pruned_exists) { auto transaction (node1->store.tx_begin_write ()); ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 1)); - ASSERT_TRUE (node1->store.block.exists (transaction, receive1->hash ())); + ASSERT_TRUE (node1->ledger.block_exists (transaction, receive1->hash ())); } auto const rpc_ctx = add_rpc (system, node1); // Pruned block @@ -6558,7 +6558,7 @@ TEST (rpc, receive_unopened) auto send1 (wallet->send_action (nano::dev::genesis_key.pub, key1.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (nano::dev::genesis->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); // should not auto receive, amount sent was lower than minimum auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6582,7 +6582,7 @@ TEST (rpc, receive_unopened) auto send2 (wallet->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number () - 1, *node->work_generate_blocking (send1->hash ()))); ASSERT_TIMELY (5s, !node->balance (nano::dev::genesis_key.pub) != prev_amount); ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key2.pub)); - ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send2->hash ())); + ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send2->hash ())); nano::public_key rep; wallet->store.representative_set (node->wallets.tx_begin_write (), rep); wallet->insert_adhoc (key2.prv); // should not auto receive, amount sent was lower than minimum @@ -6617,7 +6617,7 @@ TEST (rpc, receive_work_disabled) ASSERT_NE (send1, nullptr); ASSERT_TIMELY (5s, node->balance (nano::dev::genesis_key.pub) != nano::dev::constants.genesis_amount); ASSERT_FALSE (node->store.account.exists (node->store.tx_begin_read (), key1.pub)); - ASSERT_TRUE (node->store.block.exists (node->store.tx_begin_read (), send1->hash ())); + ASSERT_TRUE (node->ledger.block_exists (node->store.tx_begin_read (), send1->hash ())); wallet->insert_adhoc (key1.prv); auto const rpc_ctx = add_rpc (system, node); boost::property_tree::ptree request; @@ -6662,9 +6662,9 @@ TEST (rpc, receive_pruned) } ASSERT_EQ (2, node2->ledger.cache.pruned_count); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ())); - ASSERT_FALSE (node2->store.block.exists (node2->store.tx_begin_read (), send1->hash ())); + ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send1->hash ())); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send2->hash ())); - ASSERT_FALSE (node2->store.block.exists (node2->store.tx_begin_read (), send2->hash ())); + ASSERT_FALSE (node2->ledger.block_exists (node2->store.tx_begin_read (), send2->hash ())); ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send3->hash ())); auto const rpc_ctx = add_rpc (system, node2); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index a381a7a258..d7464f4e07 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -848,7 +848,7 @@ nano::uint128_t nano::ledger::balance (store::transaction const & transaction, n nano::uint128_t nano::ledger::balance_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { nano::uint128_t result (0); - if (pruning && !hash_a.is_zero () && !store.block.exists (transaction_a, hash_a)) + if (pruning && !hash_a.is_zero () && !block_exists (transaction_a, hash_a)) { error_a = true; result = 0; @@ -865,6 +865,11 @@ std::shared_ptr nano::ledger::block (store::transaction const & tra return store.block.get (transaction, hash); } +bool nano::ledger::block_exists (store::transaction const & transaction, nano::block_hash const & hash) const +{ + return store.block.exists (transaction, hash); +} + // Balance for an account by account number nano::uint128_t nano::ledger::account_balance (store::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { @@ -935,7 +940,7 @@ nano::block_status nano::ledger::process (store::write_transaction const & trans nano::block_hash nano::ledger::representative (store::transaction const & transaction_a, nano::block_hash const & hash_a) { auto result (representative_calculated (transaction_a, hash_a)); - debug_assert (result.is_zero () || store.block.exists (transaction_a, result)); + debug_assert (result.is_zero () || block_exists (transaction_a, result)); return result; } @@ -957,12 +962,12 @@ bool nano::ledger::block_or_pruned_exists (store::transaction const & transactio { return true; } - return store.block.exists (transaction_a, hash_a); + return block_exists (transaction_a, hash_a); } bool nano::ledger::root_exists (store::transaction const & transaction_a, nano::root const & root_a) { - return store.block.exists (transaction_a, root_a.as_block_hash ()) || store.account.exists (transaction_a, root_a.as_account ()); + return block_exists (transaction_a, root_a.as_block_hash ()) || store.account.exists (transaction_a, root_a.as_account ()); } std::string nano::ledger::block_text (char const * hash_a) @@ -994,7 +999,7 @@ bool nano::ledger::is_send (store::transaction const & transaction_a, nano::bloc * requires that the previous block exists in the database. * This is because it must retrieve the balance of the previous block. */ - debug_assert (block_a.has_sideband () || previous.is_zero () || store.block.exists (transaction_a, previous)); + debug_assert (block_a.has_sideband () || previous.is_zero () || block_exists (transaction_a, previous)); bool result (false); if (block_a.has_sideband ()) @@ -1037,7 +1042,7 @@ nano::block_hash nano::ledger::block_source (store::transaction const & transact * passed in exist in the database. This is because it will try * to check account balances to determine if it is a send block. */ - debug_assert (block_a.previous ().is_zero () || store.block.exists (transaction_a, block_a.previous ())); + debug_assert (block_a.previous ().is_zero () || block_exists (transaction_a, block_a.previous ())); // If block_a.source () is nonzero, then we have our source. // However, universal blocks will always return zero. @@ -1103,12 +1108,12 @@ nano::uint128_t nano::ledger::weight (nano::account const & account_a) // Rollback blocks until `block_a' doesn't exist or it tries to penetrate the confirmation height bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) { - debug_assert (store.block.exists (transaction_a, block_a)); + debug_assert (block_exists (transaction_a, block_a)); auto account_l (account (transaction_a, block_a)); auto block_account_height (height (transaction_a, block_a)); rollback_visitor rollback (transaction_a, *this, list_a); auto error (false); - while (!error && store.block.exists (transaction_a, block_a)) + while (!error && block_exists (transaction_a, block_a)) { nano::confirmation_height_info confirmation_height_info; store.confirmation_height.get (transaction_a, account_l, confirmation_height_info); @@ -1301,7 +1306,7 @@ class dependent_block_visitor : public nano::block_visitor result[0] = block_a.hashables.previous; result[1] = block_a.hashables.link.as_block_hash (); // ledger.is_send will check the sideband first, if block_a has a loaded sideband the check that previous block exists can be skipped - if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.store.block.exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a))) + if (ledger.is_epoch_link (block_a.hashables.link) || ((block_a.has_sideband () || ledger.block_exists (transaction, block_a.hashables.previous)) && ledger.is_send (transaction, block_a))) { result[1].clear (); } @@ -1436,9 +1441,9 @@ std::shared_ptr nano::ledger::successor (store::transaction const & std::shared_ptr nano::ledger::forked_block (store::transaction const & transaction_a, nano::block const & block_a) { - debug_assert (!store.block.exists (transaction_a, block_a.hash ())); + debug_assert (!block_exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); - debug_assert (store.block.exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); + debug_assert (block_exists (transaction_a, root.as_block_hash ()) || store.account.exists (transaction_a, root.as_account ())); auto result = block (transaction_a, store.block.successor (transaction_a, root.as_block_hash ())); if (result == nullptr) { diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index d0d56ebb2f..52accb506c 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -52,6 +52,7 @@ class ledger final nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const; nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const; std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; + bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const; nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); nano::uint128_t account_receivable (store::transaction const &, nano::account const &, bool = false); nano::uint128_t weight (nano::account const &); From 5f28f1a8b84c4d9c85c42428cef96407e19feb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:42:20 +0100 Subject: [PATCH 08/22] Local block broadcaster (#4454) * Add rolled back event * Local block broadcaster * Rate limit block broadcasting * Rename to `local_block_broadcaster` * Node initialization order * Fix tests * Bump local block queue size to 8k elements --- nano/lib/stats_enums.hpp | 8 ++ nano/lib/thread_roles.cpp | 3 + nano/lib/thread_roles.hpp | 1 + nano/node/CMakeLists.txt | 4 +- nano/node/block_broadcast.cpp | 51 -------- nano/node/block_broadcast.hpp | 28 ----- nano/node/blockprocessor.cpp | 4 + nano/node/blockprocessor.hpp | 1 + nano/node/local_block_broadcaster.cpp | 170 ++++++++++++++++++++++++++ nano/node/local_block_broadcaster.hpp | 106 ++++++++++++++++ nano/node/node.cpp | 10 +- nano/node/node.hpp | 4 +- nano/rpc_test/rpc.cpp | 4 +- 13 files changed, 305 insertions(+), 89 deletions(-) delete mode 100644 nano/node/block_broadcast.cpp delete mode 100644 nano/node/block_broadcast.hpp create mode 100644 nano/node/local_block_broadcaster.cpp create mode 100644 nano/node/local_block_broadcaster.hpp diff --git a/nano/lib/stats_enums.hpp b/nano/lib/stats_enums.hpp index 63c90bddc5..5150d7dec0 100644 --- a/nano/lib/stats_enums.hpp +++ b/nano/lib/stats_enums.hpp @@ -49,6 +49,7 @@ enum class type : uint8_t election_scheduler, optimistic_scheduler, handshake, + local_block_broadcaster, bootstrap_ascending, bootstrap_ascending_accounts, @@ -102,6 +103,7 @@ enum class detail : uint8_t old, gap_previous, gap_source, + rollback, rollback_failed, progress, bad_signature, @@ -328,6 +330,12 @@ enum class detail : uint8_t deprioritize, deprioritize_failed, + // block broadcaster + broadcast_normal, + broadcast_aggressive, + erase_old, + erase_confirmed, + _last // Must be the last enum }; diff --git a/nano/lib/thread_roles.cpp b/nano/lib/thread_roles.cpp index 0824d23733..99caa097fe 100644 --- a/nano/lib/thread_roles.cpp +++ b/nano/lib/thread_roles.cpp @@ -100,6 +100,9 @@ std::string nano::thread_role::get_string (nano::thread_role::name role) case nano::thread_role::name::scheduler_priority: thread_role_name_string = "Sched Priority"; break; + case nano::thread_role::name::local_block_broadcasting: + thread_role_name_string = "Local broadcast"; + break; default: debug_assert (false && "nano::thread_role::get_string unhandled thread role"); } diff --git a/nano/lib/thread_roles.hpp b/nano/lib/thread_roles.hpp index 311ae58d1b..56848761ce 100644 --- a/nano/lib/thread_roles.hpp +++ b/nano/lib/thread_roles.hpp @@ -42,6 +42,7 @@ enum class name scheduler_manual, scheduler_optimistic, scheduler_priority, + local_block_broadcasting, }; /* diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 4452df575c..d25585ff44 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -20,8 +20,6 @@ add_library( backlog_population.cpp bandwidth_limiter.hpp bandwidth_limiter.cpp - block_broadcast.cpp - block_broadcast.hpp blockprocessor.hpp blockprocessor.cpp bootstrap/block_deserializer.hpp @@ -100,6 +98,8 @@ add_library( ipc/ipc_server.cpp json_handler.hpp json_handler.cpp + local_block_broadcaster.cpp + local_block_broadcaster.hpp make_store.hpp make_store.cpp network.hpp diff --git a/nano/node/block_broadcast.cpp b/nano/node/block_broadcast.cpp deleted file mode 100644 index 898a607f23..0000000000 --- a/nano/node/block_broadcast.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include - -nano::block_broadcast::block_broadcast (nano::network & network, bool enabled) : - network{ network }, - enabled{ enabled } -{ -} - -void nano::block_broadcast::connect (nano::block_processor & block_processor) -{ - if (!enabled) - { - return; - } - block_processor.block_processed.add ([this] (auto const & result, auto const & context) { - switch (result) - { - case nano::block_status::progress: - observe (context); - break; - default: - break; - } - }); -} - -void nano::block_broadcast::observe (nano::block_processor::context const & context) -{ - auto const & block = context.block; - if (context.source == nano::block_source::local) - { - // Block created on this node - // Perform more agressive initial flooding - network.flood_block_initial (block); - } - else - { - if (context.source != nano::block_source::bootstrap && context.source != nano::block_source::bootstrap_legacy) - { - // Block arrived from realtime traffic, do normal gossip. - network.flood_block (block, nano::transport::buffer_drop_policy::limiter); - } - else - { - // Block arrived from bootstrap - // Don't broadcast blocks we're bootstrapping - } - } -} diff --git a/nano/node/block_broadcast.hpp b/nano/node/block_broadcast.hpp deleted file mode 100644 index 0f0ee62ff2..0000000000 --- a/nano/node/block_broadcast.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -#include -#include - -namespace nano -{ -class network; - -// This class tracks blocks that originated from this node. -class block_broadcast -{ -public: - block_broadcast (nano::network & network, bool enabled = false); - // Add batch_processed observer to block_processor if enabled - void connect (nano::block_processor & block_processor); - -private: - // Block_processor observer - void observe (nano::block_processor::context const &); - - nano::network & network; - bool enabled; -}; -} diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index f9e2430e02..24ed806777 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -152,11 +152,15 @@ void nano::block_processor::rollback_competitor (store::write_transaction const } else { + node.stats.inc (nano::stat::type::ledger, nano::stat::detail::rollback); node.logger.debug (nano::log::type::blockprocessor, "Blocks rolled back: {}", rollback_list.size ()); } + // Deleting from votes cache, stop active transaction for (auto & i : rollback_list) { + rolled_back.notify (i); + node.history.erase (i->root ()); // Stop all rolled back active transactions except initial if (i->hash () != successor->hash ()) diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index ee5f4219d0..3cc7663c21 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -86,6 +86,7 @@ class block_processor final // The batch observer feeds the processed observer nano::observer_set block_processed; nano::observer_set batch_processed; + nano::observer_set const &> rolled_back; private: // Roll back block in the ledger that conflicts with 'block' diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp new file mode 100644 index 0000000000..0e5097e59e --- /dev/null +++ b/nano/node/local_block_broadcaster.cpp @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include +#include + +nano::local_block_broadcaster::local_block_broadcaster (nano::node & node_a, nano::block_processor & block_processor_a, nano::network & network_a, nano::stats & stats_a, bool enabled_a) : + node{ node_a }, + block_processor{ block_processor_a }, + network{ network_a }, + stats{ stats_a }, + enabled{ enabled_a } +{ + if (!enabled) + { + return; + } + + block_processor.batch_processed.add ([this] (auto const & batch) { + bool should_notify = false; + for (auto const & [result, context] : batch) + { + // Only rebroadcast local blocks that were successfully processed (no forks or gaps) + if (result == nano::block_status::progress && context.source == nano::block_source::local) + { + nano::lock_guard guard{ mutex }; + local_blocks.emplace_back (local_entry{ context.block, std::chrono::steady_clock::now () }); + stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::insert); + should_notify = true; + } + } + if (should_notify) + { + condition.notify_all (); + } + }); + + block_processor.rolled_back.add ([this] (auto const & block) { + nano::lock_guard guard{ mutex }; + auto erased = local_blocks.get ().erase (block->hash ()); + stats.add (nano::stat::type::local_block_broadcaster, nano::stat::detail::rollback, nano::stat::dir::in, erased); + }); +} + +nano::local_block_broadcaster::~local_block_broadcaster () +{ + // Thread must be stopped before destruction + debug_assert (!thread.joinable ()); +} + +void nano::local_block_broadcaster::start () +{ + if (!enabled) + { + return; + } + + debug_assert (!thread.joinable ()); + + thread = std::thread{ [this] () { + nano::thread_role::set (nano::thread_role::name::local_block_broadcasting); + run (); + } }; +} + +void nano::local_block_broadcaster::stop () +{ + { + nano::lock_guard lock{ mutex }; + stopped = true; + } + condition.notify_all (); + nano::join_or_pass (thread); +} + +void nano::local_block_broadcaster::run () +{ + nano::unique_lock lock{ mutex }; + while (!stopped) + { + stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::loop); + + condition.wait_for (lock, check_interval); + debug_assert ((std::this_thread::yield (), true)); // Introduce some random delay in debug builds + + if (!stopped) + { + cleanup (); + run_broadcasts (lock); + debug_assert (lock.owns_lock ()); + } + } +} + +void nano::local_block_broadcaster::run_broadcasts (nano::unique_lock & lock) +{ + debug_assert (lock.owns_lock ()); + + std::vector> to_broadcast; + + auto const now = std::chrono::steady_clock::now (); + for (auto & entry : local_blocks) + { + if (elapsed (entry.last_broadcast, broadcast_interval, now)) + { + entry.last_broadcast = now; + to_broadcast.push_back (entry.block); + } + } + + lock.unlock (); + + for (auto const & block : to_broadcast) + { + while (!limiter.should_pass (1)) + { + std::this_thread::sleep_for (std::chrono::milliseconds{ 100 }); + if (stopped) + { + return; + } + } + + stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::broadcast, nano::stat::dir::out); + + network.flood_block_initial (block); + } + + lock.lock (); +} + +void nano::local_block_broadcaster::cleanup () +{ + debug_assert (!mutex.try_lock ()); + + // Erase oldest blocks if the queue gets too big + while (local_blocks.size () > max_size) + { + stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::erase_oldest); + local_blocks.pop_front (); + } + + // TODO: Mutex is held during IO, but it should be fine since it's not performance critical + auto transaction = node.store.tx_begin_read (); + erase_if (local_blocks, [this, &transaction] (auto const & entry) { + transaction.refresh_if_needed (); + + if (entry.last_broadcast == std::chrono::steady_clock::time_point{}) + { + // This block has never been broadcasted, keep it so it's broadcasted at least once + return false; + } + if (node.block_confirmed_or_being_confirmed (transaction, entry.block->hash ())) + { + stats.inc (nano::stat::type::local_block_broadcaster, nano::stat::detail::erase_confirmed); + return true; + } + return false; + }); +} + +std::unique_ptr nano::local_block_broadcaster::collect_container_info (const std::string & name) const +{ + nano::lock_guard guard{ mutex }; + + auto composite = std::make_unique (name); + composite->add_component (std::make_unique (container_info{ "local", local_blocks.size (), sizeof (decltype (local_blocks)::value_type) })); + return composite; +} \ No newline at end of file diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp new file mode 100644 index 0000000000..486fe85512 --- /dev/null +++ b/nano/node/local_block_broadcaster.hpp @@ -0,0 +1,106 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace mi = boost::multi_index; + +namespace nano +{ +class node; +class network; +} + +namespace nano +{ +/** + * Broadcasts blocks to the network + * Tracks local blocks for more aggressive propagation + */ +class local_block_broadcaster +{ + enum class broadcast_strategy + { + normal, + aggressive, + }; + +public: + local_block_broadcaster (nano::node &, nano::block_processor &, nano::network &, nano::stats &, bool enabled = false); + ~local_block_broadcaster (); + + void start (); + void stop (); + + std::unique_ptr collect_container_info (std::string const & name) const; + +private: + void run (); + void run_broadcasts (nano::unique_lock &); + void cleanup (); + +private: // Dependencies + nano::node & node; + nano::block_processor & block_processor; + nano::network & network; + nano::stats & stats; + +private: + struct local_entry + { + std::shared_ptr const block; + std::chrono::steady_clock::time_point const arrival; + mutable std::chrono::steady_clock::time_point last_broadcast{}; // Not part of any index + + nano::block_hash hash () const + { + return block->hash (); + } + }; + + // clang-format off + class tag_sequenced {}; + class tag_hash {}; + + using ordered_locals = boost::multi_index_container>, + mi::hashed_unique, + mi::const_mem_fun> + >>; + // clang-format on + + ordered_locals local_blocks; + +private: + bool enabled{ false }; + + nano::bandwidth_limiter limiter{ broadcast_rate_limit, broadcast_rate_burst_ratio }; + + std::atomic stopped{ false }; + nano::condition_variable condition; + mutable nano::mutex mutex; + std::thread thread; + + // TODO: Make these configurable + static std::size_t constexpr max_size{ 1024 * 8 }; + static std::chrono::seconds constexpr check_interval{ 30 }; + static std::chrono::seconds constexpr broadcast_interval{ 60 }; + static std::size_t constexpr broadcast_rate_limit{ 32 }; + static double constexpr broadcast_rate_burst_ratio{ 3 }; +}; +} diff --git a/nano/node/node.cpp b/nano/node/node.cpp index ac5f56b2c9..a76d010e3b 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -195,14 +195,13 @@ nano::node::node (boost::asio::io_context & io_ctx_a, std::filesystem::path cons ascendboot{ config, block_processor, ledger, network, stats }, websocket{ config.websocket_config, observers, wallets, ledger, io_ctx, logger }, epoch_upgrader{ *this, ledger, store, network_params, logger }, + local_block_broadcaster{ *this, block_processor, network, stats, !flags.disable_block_processor_republishing }, + process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket }, startup_time (std::chrono::steady_clock::now ()), - node_seq (seq), - block_broadcast{ network, !flags.disable_block_processor_republishing }, - process_live_dispatcher{ ledger, scheduler.priority, vote_cache, websocket } + node_seq (seq) { logger.debug (nano::log::type::node, "Constructing node..."); - block_broadcast.connect (block_processor); process_live_dispatcher.connect (block_processor); unchecked.satisfied.add ([this] (nano::unchecked_info const & info) { @@ -551,6 +550,7 @@ std::unique_ptr nano::collect_container_info (no composite->add_component (collect_container_info (node.final_generator, "vote_generator_final")); composite->add_component (node.ascendboot.collect_container_info ("bootstrap_ascending")); composite->add_component (node.unchecked.collect_container_info ("unchecked")); + composite->add_component (node.local_block_broadcaster.collect_container_info ("local_block_broadcaster")); return composite; } @@ -659,6 +659,7 @@ void nano::node::start () } websocket.start (); telemetry.start (); + local_block_broadcaster.start (); } void nano::node::stop () @@ -699,6 +700,7 @@ void nano::node::stop () stats.stop (); epoch_upgrader.stop (); workers.stop (); + local_block_broadcaster.stop (); // work pool is not stopped on purpose due to testing setup } diff --git a/nano/node/node.hpp b/nano/node/node.hpp index abd7b3651b..0776b72850 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -186,7 +186,7 @@ class node final : public std::enable_shared_from_this nano::bootstrap_ascending::service ascendboot; nano::websocket_server websocket; nano::epoch_upgrader epoch_upgrader; - nano::block_broadcast block_broadcast; + nano::local_block_broadcaster local_block_broadcaster; nano::process_live_dispatcher process_live_dispatcher; std::chrono::steady_clock::time_point const startup_time; diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 4f1c158f98..75970d6ada 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2228,7 +2228,7 @@ TEST (rpc, block_count_pruning) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node1->work_generate_blocking (latest)) .build (); - node1->process_active (send1); + node1->process_local (send1); auto receive1 = builder .receive () .previous (send1->hash ()) @@ -2236,7 +2236,7 @@ TEST (rpc, block_count_pruning) .sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub) .work (*node1->work_generate_blocking (send1->hash ())) .build (); - node1->process_active (receive1); + node1->process_local (receive1); system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv); ASSERT_TIMELY (5s, node1->block_confirmed (receive1->hash ())); // Pruning action From 42544be68ee053909ca0d1de70d9bfc224d34917 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Tue, 5 Mar 2024 18:34:20 +0000 Subject: [PATCH 09/22] Do not return node_id private key in RPC call (#4459) It could become a problem one day. This is breaking a debug API, that nobody should be using for serious tasks. So it should not cause any problems. --- nano/node/json_handler.cpp | 1 - nano/rpc_test/rpc.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 3ef09287ad..ec02593e0e 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -2922,7 +2922,6 @@ void nano::json_handler::node_id () { if (!ec) { - response_l.put ("private", node.node_id.prv.to_string ()); response_l.put ("public", node.node_id.pub.to_string ()); response_l.put ("as_account", node.node_id.pub.to_account ()); response_l.put ("node_id", node.node_id.pub.to_node_id ()); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 6dc67ff267..da0b1af1ae 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -5406,7 +5406,6 @@ TEST (rpc, node_id) boost::property_tree::ptree request; request.put ("action", "node_id"); auto response (wait_response (system, rpc_ctx, request)); - ASSERT_EQ (node->node_id.prv.to_string (), response.get ("private")); ASSERT_EQ (node->node_id.pub.to_account (), response.get ("as_account")); ASSERT_EQ (node->node_id.pub.to_node_id (), response.get ("node_id")); } From d2052cec80d76540776e2f519d25bfe0e0b79c52 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 27 Feb 2024 11:37:04 +0000 Subject: [PATCH 10/22] Make use of ledger::account overload taking a block when block is already available. --- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/json_handler.cpp | 2 +- nano/secure/ledger.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 1ab1362849..5f072a231a 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -132,7 +132,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, { case nano::block_status::progress: { - const auto account = ledger.account (tx, hash); + const auto account = ledger.account (block); const auto is_send = ledger.is_send (tx, block); // If we've inserted any block in to an account, unmark it as blocked diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 3ef09287ad..3c2d4dd30b 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1214,7 +1214,7 @@ void nano::json_handler::block_confirm () nano::election_status status{ block_l, 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::active_confirmation_height }; node.active.recently_cemented.put (status); // Trigger callback for confirmed block - auto account (node.ledger.account (transaction, hash)); + auto account = node.ledger.account (*block_l); bool error_or_pruned (false); auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); bool is_state_send (false); diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d7464f4e07..979a4a3bab 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -63,7 +63,7 @@ class rollback_visitor : public nano::block_visitor { auto hash (block_a.hash ()); auto amount (ledger.amount (transaction, hash)); - auto destination_account (ledger.account (transaction, hash)); + auto destination_account = ledger.account (block_a); // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing [[maybe_unused]] bool is_pruned (false); auto source_account (ledger.account_safe (transaction, block_a.hashables.source, is_pruned)); @@ -83,7 +83,7 @@ class rollback_visitor : public nano::block_visitor { auto hash (block_a.hash ()); auto amount (ledger.amount (transaction, hash)); - auto destination_account (ledger.account (transaction, hash)); + auto destination_account = ledger.account (block_a); // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing [[maybe_unused]] bool is_pruned (false); auto source_account (ledger.account_safe (transaction, block_a.hashables.source, is_pruned)); @@ -99,7 +99,7 @@ class rollback_visitor : public nano::block_visitor { auto hash (block_a.hash ()); auto rep_block (ledger.representative (transaction, block_a.hashables.previous)); - auto account (ledger.account (transaction, block_a.hashables.previous)); + auto account = ledger.account (block_a); auto info = ledger.account_info (transaction, account); debug_assert (info); auto balance (ledger.balance (transaction, block_a.hashables.previous)); From f4dc825763f5f88f8e065546653374d6bd43de49 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 5 Mar 2024 19:07:43 +0000 Subject: [PATCH 11/22] Merge the ledger::account and ledger::account_safe functions in to a single function returning an optional value. This simplifies the ledger interface and uses safer std::optional to signal no value rather than a sentinel 0 value. --- nano/core_test/ledger.cpp | 7 +-- nano/node/bootstrap/bootstrap_server.cpp | 2 +- nano/node/bootstrap_ascending/service.cpp | 2 +- nano/node/json_handler.cpp | 32 ++++++------ nano/qt/qt.cpp | 28 ++++++++--- nano/secure/ledger.cpp | 59 +++++------------------ nano/secure/ledger.hpp | 15 ++---- 7 files changed, 57 insertions(+), 88 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index eb29e207d6..5ae86a07a0 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5371,11 +5371,8 @@ TEST (ledger, pruning_safe_functions) ASSERT_EQ (0, ledger.amount_safe (transaction, send2->hash (), error)); ASSERT_TRUE (error); error = false; - ASSERT_TRUE (ledger.account_safe (transaction, send1->hash (), error).is_zero ()); - ASSERT_TRUE (error); - error = false; - ASSERT_EQ (nano::dev::genesis->account (), ledger.account_safe (transaction, send2->hash (), error)); - ASSERT_FALSE (error); + ASSERT_FALSE (ledger.account (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::genesis->account (), ledger.account (transaction, send2->hash ()).value ()); } TEST (ledger, hash_root_random) diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 5585212fd8..078d374d40 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -286,7 +286,7 @@ nano::asc_pull_ack nano::bootstrap_server::process (const store::transaction & t case asc_pull_req::hash_type::block: { // Try to lookup account assuming target is block hash - target = ledger.account_safe (transaction, request.target.as_block_hash ()); + target = ledger.account (transaction, request.target.as_block_hash ()).value_or (0); } break; } diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 5f072a231a..0b6c85b7a0 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -166,7 +166,7 @@ void nano::bootstrap_ascending::service::inspect (store::transaction const & tx, break; case nano::block_status::gap_source: { - const auto account = block.previous ().is_zero () ? block.account () : ledger.account (tx, block.previous ()); + const auto account = block.previous ().is_zero () ? block.account () : ledger.account (tx, block.previous ()).value (); const auto source = block.source ().is_zero () ? block.link ().as_block_hash () : block.source (); // Mark account as blocked because it is missing the source block diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 3c2d4dd30b..c74d158303 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1388,7 +1388,7 @@ void nano::json_handler::blocks_info () auto block_a = node.ledger.block (transaction, source_hash); if (block_a != nullptr) { - auto source_account (node.ledger.account (transaction, source_hash)); + auto source_account (node.ledger.account (*block_a)); entry.put ("source_account", source_account.to_account ()); } else @@ -1432,10 +1432,10 @@ void nano::json_handler::block_account () if (!ec) { auto transaction (node.store.tx_begin_read ()); - if (node.ledger.block_exists (transaction, hash)) + auto block = node.ledger.block (transaction, hash); + if (block) { - auto account (node.ledger.account (transaction, hash)); - response_l.put ("account", account.to_account ()); + response_l.put ("account", node.ledger.account (*block).to_account ()); } else { @@ -2415,10 +2415,10 @@ class history_visitor : public nano::block_visitor auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); if (!error_or_pruned) { - auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); - if (!error_or_pruned) + auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); + if (source_account) { - tree.put ("account", source_account.to_account ()); + tree.put ("account", source_account.value ().to_account ()); } tree.put ("amount", amount); } @@ -2448,10 +2448,10 @@ class history_visitor : public nano::block_visitor auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); if (!error_or_pruned) { - auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned)); - if (!error_or_pruned) + auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); + if (source_account) { - tree.put ("account", source_account.to_account ()); + tree.put ("account", source_account.value ().to_account ()); } tree.put ("amount", amount); } @@ -2532,8 +2532,8 @@ class history_visitor : public nano::block_visitor } else { - auto source_account (handler.node.ledger.account_safe (transaction, block_a.hashables.link.as_block_hash (), error_or_pruned)); - if (!error_or_pruned && should_ignore_account (source_account)) + auto source_account = handler.node.ledger.account (transaction, block_a.hashables.link.as_block_hash ()); + if (source_account && should_ignore_account (source_account.value ())) { tree.clear (); return; @@ -2546,9 +2546,9 @@ class history_visitor : public nano::block_visitor { tree.put ("type", "receive"); } - if (!error_or_pruned) + if (source_account) { - tree.put ("account", source_account.to_account ()); + tree.put ("account", source_account.value ().to_account ()); } tree.put ("amount", (balance - previous_balance).convert_to ()); } @@ -2607,7 +2607,7 @@ void nano::json_handler::account_history () { if (node.ledger.block_exists (transaction, hash)) { - account = node.ledger.account (transaction, hash); + account = node.ledger.account (transaction, hash).value (); } else { @@ -5095,7 +5095,7 @@ void nano::json_handler::work_generate () auto transaction_l (node.store.tx_begin_read ()); if (node.ledger.block_exists (transaction_l, hash)) { - account = node.ledger.account (transaction_l, hash); + account = node.ledger.account (transaction_l, hash).value (); } } auto secondary_work_peers_l (request.get ("secondary_work_peers", false)); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index efd112cd7b..253b3ed679 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -531,13 +531,17 @@ class short_text_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) { type = "Receive"; - bool error_or_pruned (false); - account = ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned); + auto account_l = ledger.account (transaction, block_a.hashables.source); + bool error_or_pruned = false; amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (error_or_pruned) + if (!account_l || error_or_pruned) { type = "Receive (pruned)"; } + else + { + account = account_l.value (); + } } void open_block (nano::open_block const & block_a) { @@ -545,12 +549,16 @@ class short_text_visitor : public nano::block_visitor if (block_a.hashables.source != ledger.constants.genesis->account ()) { bool error_or_pruned (false); - account = ledger.account_safe (transaction, block_a.hashables.source, error_or_pruned); + auto account_l = ledger.account (transaction, block_a.hashables.source); amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (error_or_pruned) + if (!account_l || error_or_pruned) { type = "Receive (pruned)"; } + else + { + account = account_l.value (); + } } else { @@ -596,11 +604,15 @@ class short_text_visitor : public nano::block_visitor else { type = "Receive"; - account = ledger.account_safe (transaction, block_a.hashables.link.as_block_hash (), error_or_pruned); - if (error_or_pruned) + auto account_l = ledger.account (transaction, block_a.hashables.link.as_block_hash ()); + if (!account_l) { type = "Receive (pruned)"; } + else + { + account = account_l.value (); + } } amount = balance - previous_balance; } @@ -609,7 +621,7 @@ class short_text_visitor : public nano::block_visitor nano::ledger & ledger; std::string type; nano::uint128_t amount; - nano::account account; + nano::account account{ 0 }; }; } diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 979a4a3bab..7d0bd4d573 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -65,15 +65,14 @@ class rollback_visitor : public nano::block_visitor auto amount (ledger.amount (transaction, hash)); auto destination_account = ledger.account (block_a); // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing - [[maybe_unused]] bool is_pruned (false); - auto source_account (ledger.account_safe (transaction, block_a.hashables.source, is_pruned)); + auto source_account = ledger.account (transaction, block_a.hashables.source); auto info = ledger.account_info (transaction, destination_account); debug_assert (info); ledger.cache.rep_weights.representation_add (info->representative, 0 - amount); nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, destination_account, *info, new_info); ledger.store.block.del (transaction, hash); - ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account, amount, nano::epoch::epoch_0 }); + ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); ledger.store.frontier.del (transaction, hash); ledger.store.frontier.put (transaction, block_a.hashables.previous, destination_account); ledger.store.block.successor_clear (transaction, block_a.hashables.previous); @@ -84,14 +83,12 @@ class rollback_visitor : public nano::block_visitor auto hash (block_a.hash ()); auto amount (ledger.amount (transaction, hash)); auto destination_account = ledger.account (block_a); - // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing - [[maybe_unused]] bool is_pruned (false); - auto source_account (ledger.account_safe (transaction, block_a.hashables.source, is_pruned)); + auto source_account = ledger.account (transaction, block_a.hashables.source); ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - amount); nano::account_info new_info; ledger.update_account (transaction, destination_account, new_info, new_info); ledger.store.block.del (transaction, hash); - ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account, amount, nano::epoch::epoch_0 }); + ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); ledger.store.frontier.del (transaction, hash); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::open); } @@ -156,9 +153,8 @@ class rollback_visitor : public nano::block_visitor else if (!block_a.hashables.link.is_zero () && !ledger.is_epoch_link (block_a.hashables.link)) { // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing - [[maybe_unused]] bool is_pruned (false); - auto source_account (ledger.account_safe (transaction, block_a.hashables.link.as_block_hash (), is_pruned)); - nano::pending_info pending_info (source_account, block_a.hashables.balance.number () - balance, block_a.sideband ().source_epoch); + auto source_account = ledger.account (transaction, block_a.hashables.link.as_block_hash ()); + nano::pending_info pending_info (source_account.value_or (0), block_a.hashables.balance.number () - balance, block_a.sideband ().source_epoch); ledger.store.pending.put (transaction, nano::pending_key (block_a.hashables.account, block_a.hashables.link.as_block_hash ()), pending_info); ledger.stats.inc (nano::stat::type::rollback, nano::stat::detail::receive); } @@ -1109,7 +1105,7 @@ nano::uint128_t nano::ledger::weight (nano::account const & account_a) bool nano::ledger::rollback (store::write_transaction const & transaction_a, nano::block_hash const & block_a, std::vector> & list_a) { debug_assert (block_exists (transaction_a, block_a)); - auto account_l (account (transaction_a, block_a)); + auto account_l = account (transaction_a, block_a).value (); auto block_account_height (height (transaction_a, block_a)); rollback_visitor rollback (transaction_a, *this, list_a); auto error (false); @@ -1144,7 +1140,7 @@ bool nano::ledger::rollback (store::write_transaction const & transaction_a, nan return rollback (transaction_a, block_a, rollback_list); } -nano::account nano::ledger::account (nano::block const & block) const +nano::account nano::ledger::account (nano::block const & block) { debug_assert (block.has_sideband ()); nano::account result (block.account ()); @@ -1156,45 +1152,14 @@ nano::account nano::ledger::account (nano::block const & block) const return result; } -nano::account nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const +std::optional nano::ledger::account (store::transaction const & transaction, nano::block_hash const & hash) const { auto block_l = block (transaction, hash); - debug_assert (block_l != nullptr); - return account (*block_l); -} - -nano::account nano::ledger::account_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const -{ - if (!pruning) + if (!block_l) { - return account (transaction_a, hash_a); - } - else - { - auto block_l = block (transaction_a, hash_a); - if (block_l != nullptr) - { - return account (*block_l); - } - else - { - error_a = true; - return 0; - } - } -} - -nano::account nano::ledger::account_safe (store::transaction const & transaction, nano::block_hash const & hash) const -{ - auto block_l = block (transaction, hash); - if (block_l) - { - return account (*block_l); - } - else - { - return { 0 }; + return std::nullopt; } + return account (*block_l); } std::optional nano::ledger::account_info (store::transaction const & transaction, nano::account const & account) const diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 52accb506c..b606d1b729 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -33,18 +33,13 @@ class ledger final /** * Return account containing hash, expects that block hash exists in ledger */ - nano::account account (nano::block const & block) const; - nano::account account (store::transaction const &, nano::block_hash const &) const; - std::optional account_info (store::transaction const & transaction, nano::account const & account) const; - /** - * For non-prunning nodes same as `ledger::account()` - * For prunning nodes ensures that block hash exists, otherwise returns zero account - */ - nano::account account_safe (store::transaction const &, nano::block_hash const &, bool &) const; + static nano::account account (nano::block const & block); /** - * Return account containing hash, returns zero account if account can not be found + * Returns the account for a given hash + * Returns std::nullopt if the block doesn't exist or has been pruned */ - nano::account account_safe (store::transaction const &, nano::block_hash const &) const; + std::optional account (store::transaction const &, nano::block_hash const &) const; + std::optional account_info (store::transaction const & transaction, nano::account const & account) const; nano::uint128_t amount (store::transaction const &, nano::block_hash const &); /** Safe for previous block, but block hash_a must exist */ nano::uint128_t amount_safe (store::transaction const &, nano::block_hash const & hash_a, bool &) const; From 3ce52fc49af80dbb73187fe903da1e7b3c0a719d Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Mar 2024 11:58:46 +0000 Subject: [PATCH 12/22] ledger::amount will no longer query for the previous block's balance if the previous hash is zero. This removes a dependency on the behaviour of ledger::balance to return a sentinel value of 0 if the block hash cannot be found. --- nano/secure/ledger.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 7d0bd4d573..2d367990f8 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1171,6 +1171,10 @@ nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, { auto block_l = block (transaction_a, hash_a); auto block_balance (balance (transaction_a, hash_a)); + if (block_l->previous ().is_zero ()) + { + return block_balance; + } auto previous_balance (balance (transaction_a, block_l->previous ())); return block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; } @@ -1180,6 +1184,10 @@ nano::uint128_t nano::ledger::amount_safe (store::transaction const & transactio auto block_l = block (transaction_a, hash_a); debug_assert (block_l); auto block_balance (balance (transaction_a, hash_a)); + if (block_l->previous ().is_zero ()) + { + return block_balance; + } auto previous_balance (balance_safe (transaction_a, block_l->previous (), error_a)); return error_a ? 0 : block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; From 4bac9419795f8a2789c240e25fae8fad55c3b671 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 27 Feb 2024 15:43:55 +0000 Subject: [PATCH 13/22] Merging ledger::balance_safe with ledger::balance and returning value as an std::optional. --- nano/core_test/ledger.cpp | 8 +--- nano/nano_node/entry.cpp | 11 +++--- nano/node/bootstrap/bootstrap_lazy.cpp | 14 +++---- nano/node/json_handler.cpp | 17 ++++----- nano/node/node.cpp | 7 ++-- nano/node/scheduler/priority.cpp | 4 +- nano/qt/qt.cpp | 9 ++--- nano/secure/ledger.cpp | 53 ++++++++++---------------- nano/secure/ledger.hpp | 3 +- 9 files changed, 52 insertions(+), 74 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 5ae86a07a0..0cce4c94c3 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5361,13 +5361,9 @@ TEST (ledger, pruning_safe_functions) ASSERT_TRUE (store->block.exists (transaction, nano::dev::genesis->hash ())); ASSERT_TRUE (store->block.exists (transaction, send2->hash ())); // Safe ledger actions + ASSERT_FALSE (ledger.balance (transaction, send1->hash ())); + ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.balance (transaction, send2->hash ()).value ()); bool error (false); - ASSERT_EQ (0, ledger.balance_safe (transaction, send1->hash (), error)); - ASSERT_TRUE (error); - error = false; - ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.balance_safe (transaction, send2->hash (), error)); - ASSERT_FALSE (error); - error = false; ASSERT_EQ (0, ledger.amount_safe (transaction, send2->hash (), error)); ASSERT_TRUE (error); error = false; diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 744df8d63b..25b17af5e2 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1494,7 +1494,7 @@ int main (int argc, char * const * argv) bool error_or_pruned (false); if (!state_block.hashables.previous.is_zero ()) { - prev_balance = node->ledger.balance_safe (transaction, state_block.hashables.previous, error_or_pruned); + prev_balance = node->ledger.balance (transaction, state_block.hashables.previous).value_or (0); } if (node->ledger.is_epoch_link (state_block.hashables.link)) { @@ -1518,11 +1518,10 @@ int main (int argc, char * const * argv) } else { - bool error_or_pruned (false); - auto prev_balance (node->ledger.balance_safe (transaction, block->previous (), error_or_pruned)); - if (!node->ledger.pruning || !error_or_pruned) + auto prev_balance = node->ledger.balance (transaction, block->previous ()); + if (!node->ledger.pruning || prev_balance) { - if (block->balance () < prev_balance) + if (block->balance () < prev_balance.value ()) { // State send block_details_error = !sideband.details.is_send || sideband.details.is_receive || sideband.details.is_epoch; @@ -1534,7 +1533,7 @@ int main (int argc, char * const * argv) // State change block_details_error = sideband.details.is_send || sideband.details.is_receive || sideband.details.is_epoch; } - else if (block->balance () == prev_balance && node->ledger.is_epoch_link (block->link ())) + else if (block->balance () == prev_balance.value () && node->ledger.is_epoch_link (block->link ())) { // State epoch block_details_error = !sideband.details.is_epoch || sideband.details.is_send || sideband.details.is_receive; diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index d69916a9c9..49cd39c03e 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -346,11 +346,10 @@ void nano::bootstrap_attempt_lazy::lazy_block_state (std::shared_ptrledger.block_or_pruned_exists (transaction, previous)) { - bool error_or_pruned (false); - auto previous_balance (node->ledger.balance_safe (transaction, previous, error_or_pruned)); - if (!error_or_pruned) + auto previous_balance = node->ledger.balance (transaction, previous); + if (previous_balance) { - if (previous_balance <= balance) + if (previous_balance.value () <= balance) { lazy_add (link, retry_limit); } @@ -423,11 +422,10 @@ void nano::bootstrap_attempt_lazy::lazy_backlog_cleanup () if (node->ledger.block_or_pruned_exists (transaction, it->first)) { auto next_block (it->second); - bool error_or_pruned (false); - auto balance (node->ledger.balance_safe (transaction, it->first, error_or_pruned)); - if (!error_or_pruned) + auto balance = node->ledger.balance (transaction, it->first); + if (balance) { - if (balance <= next_block.balance) // balance + if (balance.value () <= next_block.balance) // balance { lazy_add (next_block.link, next_block.retry_limit); // link } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index c74d158303..f113b5923d 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -641,7 +641,7 @@ void nano::json_handler::account_info () { if (info.block_count != confirmation_height_info.height) { - confirmed_balance_l = node.ledger.balance (transaction, confirmation_height_info.frontier); + confirmed_balance_l = node.ledger.balance (transaction, confirmation_height_info.frontier).value_or (0); } else { @@ -1156,7 +1156,7 @@ void nano::json_handler::block_info () { response_l.put ("amount", amount.convert_to ()); } - auto balance (node.ledger.balance (transaction, hash)); + auto balance = node.ledger.balance (*block); response_l.put ("balance", balance.convert_to ()); response_l.put ("height", std::to_string (block->sideband ().height)); response_l.put ("local_timestamp", std::to_string (block->sideband ().timestamp)); @@ -1315,7 +1315,7 @@ void nano::json_handler::blocks_info () { entry.put ("amount", amount.convert_to ()); } - auto balance (node.ledger.balance (transaction, hash)); + auto balance = node.ledger.balance (*block); entry.put ("balance", balance.convert_to ()); entry.put ("height", std::to_string (block->sideband ().height)); entry.put ("local_timestamp", std::to_string (block->sideband ().timestamp)); @@ -2482,9 +2482,8 @@ class history_visitor : public nano::block_visitor tree.put ("previous", block_a.hashables.previous.to_string ()); } auto balance (block_a.hashables.balance.number ()); - bool error_or_pruned (false); - auto previous_balance (handler.node.ledger.balance_safe (transaction, block_a.hashables.previous, error_or_pruned)); - if (error_or_pruned) + auto previous_balance = handler.node.ledger.balance (transaction, block_a.hashables.previous); + if (!previous_balance) { if (raw) { @@ -2495,7 +2494,7 @@ class history_visitor : public nano::block_visitor tree.put ("type", "unknown"); } } - else if (balance < previous_balance) + else if (balance < previous_balance.value ()) { if (should_ignore_account (block_a.hashables.link.as_account ())) { @@ -2511,7 +2510,7 @@ class history_visitor : public nano::block_visitor tree.put ("type", "send"); } tree.put ("account", block_a.hashables.link.to_account ()); - tree.put ("amount", (previous_balance - balance).convert_to ()); + tree.put ("amount", (previous_balance.value () - balance).convert_to ()); } else { @@ -2550,7 +2549,7 @@ class history_visitor : public nano::block_visitor { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", (balance - previous_balance).convert_to ()); + tree.put ("amount", (balance - previous_balance.value ()).convert_to ()); } } } diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b202b8b018..4ed49e6e3f 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1232,14 +1232,13 @@ void nano::node::process_confirmed_data (store::transaction const & transaction_ } // Faster amount calculation auto previous (block_a->previous ()); - bool error (false); - auto previous_balance (ledger.balance_safe (transaction_a, previous, error)); + auto previous_balance = ledger.balance (transaction_a, previous); auto block_balance = ledger.balance (*block_a); if (hash_a != ledger.constants.genesis->account ()) { - if (!error) + if (previous_balance) { - amount_a = block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; + amount_a = block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; } else { diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index c503601a93..649502c189 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -51,8 +51,8 @@ bool nano::scheduler::priority::activate (nano::account const & account_a, store debug_assert (block != nullptr); if (node.ledger.dependents_confirmed (transaction, *block)) { - auto const balance = node.ledger.balance (transaction, hash); - auto const previous_balance = node.ledger.balance (transaction, conf_info.frontier); + auto const balance = node.ledger.balance (transaction, hash).value (); + auto const previous_balance = node.ledger.balance (transaction, conf_info.frontier).value_or (0); auto const balance_priority = std::max (balance, previous_balance); node.stats.inc (nano::stat::type::election_scheduler, nano::stat::detail::activated); diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 253b3ed679..2f0c27ba31 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -575,9 +575,8 @@ class short_text_visitor : public nano::block_visitor void state_block (nano::state_block const & block_a) { auto balance (block_a.hashables.balance.number ()); - bool error_or_pruned (false); - auto previous_balance (ledger.balance_safe (transaction, block_a.hashables.previous, error_or_pruned)); - if (error_or_pruned) + auto previous_balance = ledger.balance (transaction, block_a.hashables.previous); + if (!previous_balance) { type = "Unknown (pruned)"; amount = 0; @@ -586,7 +585,7 @@ class short_text_visitor : public nano::block_visitor else if (balance < previous_balance) { type = "Send"; - amount = previous_balance - balance; + amount = previous_balance.value () - balance; account = block_a.hashables.link.as_account (); } else @@ -614,7 +613,7 @@ class short_text_visitor : public nano::block_visitor account = account_l.value (); } } - amount = balance - previous_balance; + amount = balance - previous_balance.value (); } } nano::store::transaction const & transaction; diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 2d367990f8..c4da525c96 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -50,7 +50,7 @@ class rollback_visitor : public nano::block_visitor debug_assert (info); ledger.store.pending.del (transaction, key); ledger.cache.rep_weights.representation_add (info->representative, pending.amount.number ()); - nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); + nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, pending.source, *info, new_info); ledger.store.block.del (transaction, hash); ledger.store.frontier.del (transaction, hash); @@ -69,7 +69,7 @@ class rollback_visitor : public nano::block_visitor auto info = ledger.account_info (transaction, destination_account); debug_assert (info); ledger.cache.rep_weights.representation_add (info->representative, 0 - amount); - nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); + nano::account_info new_info (block_a.hashables.previous, info->representative, info->open_block, ledger.balance (transaction, block_a.hashables.previous).value (), nano::seconds_since_epoch (), info->block_count - 1, nano::epoch::epoch_0); ledger.update_account (transaction, destination_account, *info, new_info); ledger.store.block.del (transaction, hash); ledger.store.pending.put (transaction, nano::pending_key (destination_account, block_a.hashables.source), { source_account.value_or (0), amount, nano::epoch::epoch_0 }); @@ -99,7 +99,7 @@ class rollback_visitor : public nano::block_visitor auto account = ledger.account (block_a); auto info = ledger.account_info (transaction, account); debug_assert (info); - auto balance (ledger.balance (transaction, block_a.hashables.previous)); + auto balance = ledger.balance (transaction, block_a.hashables.previous).value (); auto block = ledger.store.block.get (transaction, rep_block); release_assert (block != nullptr); auto representative = block->representative (); @@ -120,7 +120,7 @@ class rollback_visitor : public nano::block_visitor { rep_block_hash = ledger.representative (transaction, block_a.hashables.previous); } - auto balance (ledger.balance (transaction, block_a.hashables.previous)); + nano::uint128_t balance = ledger.balance (transaction, block_a.hashables.previous).value_or (0); auto is_send (block_a.hashables.balance < balance); nano::account representative{}; if (!rep_block_hash.is_zero ()) @@ -215,7 +215,7 @@ bool ledger_processor::validate_epoch_block (nano::state_block const & block_a) result = ledger.store.block.exists (transaction, block_a.hashables.previous) ? nano::block_status::progress : nano::block_status::gap_previous; if (result == nano::block_status::progress) { - prev_balance = ledger.balance (transaction, block_a.hashables.previous); + prev_balance = ledger.balance (transaction, block_a.hashables.previous).value (); } else { @@ -479,7 +479,7 @@ void ledger_processor::change_block (nano::change_block & block_a) debug_assert (!validate_message (account, hash, block_a.signature)); block_a.sideband_set (nano::block_sideband (account, 0, info->balance, info->block_count + 1, nano::seconds_since_epoch (), block_details, nano::epoch::epoch_0 /* unused */)); ledger.store.block.put (transaction, hash, block_a); - auto balance (ledger.balance (transaction, block_a.hashables.previous)); + auto balance = ledger.balance (*previous); ledger.cache.rep_weights.representation_add_dual (block_a.representative (), balance, info->representative, 0 - balance); nano::account_info new_info (hash, block_a.representative (), info->open_block, info->balance, nano::seconds_since_epoch (), info->block_count + 1, nano::epoch::epoch_0); ledger.update_account (transaction, account, *info, new_info); @@ -830,30 +830,18 @@ nano::uint128_t nano::ledger::balance (nano::block const & block) } // Balance for account containing hash -nano::uint128_t nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const +std::optional nano::ledger::balance (store::transaction const & transaction, nano::block_hash const & hash) const { if (hash.is_zero ()) { - return 0; - } - auto block_l = block (transaction, hash); - debug_assert (block_l != nullptr); - return balance (*block_l); -} - -nano::uint128_t nano::ledger::balance_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const -{ - nano::uint128_t result (0); - if (pruning && !hash_a.is_zero () && !block_exists (transaction_a, hash_a)) - { - error_a = true; - result = 0; + return std::nullopt; } - else + auto block = store.block.get (transaction, hash); + if (!block) { - result = balance (transaction_a, hash_a); + return std::nullopt; } - return result; + return balance (*block); } std::shared_ptr nano::ledger::block (store::transaction const & transaction, nano::block_hash const & hash) const @@ -875,7 +863,7 @@ nano::uint128_t nano::ledger::account_balance (store::transaction const & transa nano::confirmation_height_info info; if (!store.confirmation_height.get (transaction_a, account_a, info)) { - result = balance (transaction_a, info.frontier); + result = balance (transaction_a, info.frontier).value (); } } else @@ -1170,27 +1158,28 @@ std::optional nano::ledger::account_info (store::transaction nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) { auto block_l = block (transaction_a, hash_a); - auto block_balance (balance (transaction_a, hash_a)); + auto block_balance = balance (*block_l); if (block_l->previous ().is_zero ()) { return block_balance; } - auto previous_balance (balance (transaction_a, block_l->previous ())); - return block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance; + auto previous_balance = balance (transaction_a, block_l->previous ()); + return block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; } nano::uint128_t nano::ledger::amount_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const { auto block_l = block (transaction_a, hash_a); debug_assert (block_l); - auto block_balance (balance (transaction_a, hash_a)); + auto block_balance = balance (*block_l); if (block_l->previous ().is_zero ()) { return block_balance; } - auto previous_balance (balance_safe (transaction_a, block_l->previous (), error_a)); - return error_a ? 0 : block_balance > previous_balance ? block_balance - previous_balance - : previous_balance - block_balance; + auto previous_balance = balance (transaction_a, block_l->previous ()); + error_a = !previous_balance; + return error_a ? 0 : block_balance > previous_balance.value () ? block_balance - previous_balance.value () + : previous_balance.value () - block_balance; } // Return latest block for account diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index b606d1b729..0d025bcc2d 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -44,8 +44,7 @@ class ledger final /** Safe for previous block, but block hash_a must exist */ nano::uint128_t amount_safe (store::transaction const &, nano::block_hash const & hash_a, bool &) const; static nano::uint128_t balance (nano::block const & block); - nano::uint128_t balance (store::transaction const &, nano::block_hash const &) const; - nano::uint128_t balance_safe (store::transaction const &, nano::block_hash const &, bool &) const; + std::optional balance (store::transaction const &, nano::block_hash const &) const; std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; bool block_exists (store::transaction const & transaction, nano::block_hash const & hash) const; nano::uint128_t account_balance (store::transaction const &, nano::account const &, bool = false); From 2810e4cc5ff511590685c1bd80c97017ff5622aa Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 27 Feb 2024 16:12:06 +0000 Subject: [PATCH 14/22] Merge ledger::amount_safe in to ledger::amount and change return value to std::optional --- nano/core_test/ledger.cpp | 5 +---- nano/node/json_handler.cpp | 43 +++++++++++++++++--------------------- nano/qt/qt.cpp | 21 +++++++++++-------- nano/secure/ledger.cpp | 27 +++++++++--------------- nano/secure/ledger.hpp | 4 +--- 5 files changed, 43 insertions(+), 57 deletions(-) diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 0cce4c94c3..b8c827a9f9 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -5363,10 +5363,7 @@ TEST (ledger, pruning_safe_functions) // Safe ledger actions ASSERT_FALSE (ledger.balance (transaction, send1->hash ())); ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio * 2, ledger.balance (transaction, send2->hash ()).value ()); - bool error (false); - ASSERT_EQ (0, ledger.amount_safe (transaction, send2->hash (), error)); - ASSERT_TRUE (error); - error = false; + ASSERT_FALSE (ledger.amount (transaction, send2->hash ())); ASSERT_FALSE (ledger.account (transaction, send1->hash ())); ASSERT_EQ (nano::dev::genesis->account (), ledger.account (transaction, send2->hash ()).value ()); } diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index f113b5923d..cba140a7f2 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1150,11 +1150,10 @@ void nano::json_handler::block_info () { nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); response_l.put ("block_account", account.to_account ()); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); - if (!error_or_pruned) + auto amount = node.ledger.amount (transaction, hash); + if (amount) { - response_l.put ("amount", amount.convert_to ()); + response_l.put ("amount", amount.value ().convert_to ()); } auto balance = node.ledger.balance (*block); response_l.put ("balance", balance.convert_to ()); @@ -1215,19 +1214,18 @@ void nano::json_handler::block_confirm () node.active.recently_cemented.put (status); // Trigger callback for confirmed block auto account = node.ledger.account (*block_l); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); + auto amount = node.ledger.amount (transaction, hash); bool is_state_send (false); bool is_state_epoch (false); - if (!error_or_pruned) + if (amount) { if (auto state = dynamic_cast (block_l.get ())) { is_state_send = node.ledger.is_send (transaction, *state); - is_state_epoch = amount == 0 && node.ledger.is_epoch_link (state->link ()); + is_state_epoch = amount.value () == 0 && node.ledger.is_epoch_link (state->link ()); } } - node.observers.blocks.notify (status, {}, account, amount, is_state_send, is_state_epoch); + node.observers.blocks.notify (status, {}, account, amount ? amount.value () : 0, is_state_send, is_state_epoch); } response_l.put ("started", "1"); } @@ -1309,11 +1307,10 @@ void nano::json_handler::blocks_info () boost::property_tree::ptree entry; nano::account account (block->account ().is_zero () ? block->sideband ().account : block->account ()); entry.put ("block_account", account.to_account ()); - bool error_or_pruned (false); - auto amount (node.ledger.amount_safe (transaction, hash, error_or_pruned)); - if (!error_or_pruned) + auto amount = node.ledger.amount (transaction, hash); + if (amount) { - entry.put ("amount", amount.convert_to ()); + entry.put ("amount", amount.value ().convert_to ()); } auto balance = node.ledger.balance (*block); entry.put ("balance", balance.convert_to ()); @@ -2395,11 +2392,10 @@ class history_visitor : public nano::block_visitor tree.put ("type", "send"); auto account (block_a.hashables.destination.to_account ()); tree.put ("account", account); - bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); - if (!error_or_pruned) + auto amount = handler.node.ledger.amount (transaction, hash); + if (amount) { - tree.put ("amount", amount); + tree.put ("amount", amount.value ().convert_to ()); } if (raw) { @@ -2411,16 +2407,15 @@ class history_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) { tree.put ("type", "receive"); - bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); - if (!error_or_pruned) + auto amount = handler.node.ledger.amount (transaction, hash); + if (amount) { auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); if (source_account) { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", amount); + tree.put ("amount", amount.value ().convert_to ()); } if (raw) { @@ -2445,15 +2440,15 @@ class history_visitor : public nano::block_visitor if (block_a.hashables.source != handler.node.ledger.constants.genesis->account ()) { bool error_or_pruned (false); - auto amount (handler.node.ledger.amount_safe (transaction, hash, error_or_pruned).convert_to ()); - if (!error_or_pruned) + auto amount = handler.node.ledger.amount (transaction, hash); + if (amount) { auto source_account = handler.node.ledger.account (transaction, block_a.hashables.source); if (source_account) { tree.put ("account", source_account.value ().to_account ()); } - tree.put ("amount", amount); + tree.put ("amount", amount.value ().convert_to ()); } } else diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 2f0c27ba31..73f719bfdc 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -521,26 +521,29 @@ class short_text_visitor : public nano::block_visitor { type = "Send"; account = block_a.hashables.destination; - bool error_or_pruned (false); - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (error_or_pruned) + auto amount_l = ledger.amount (transaction, block_a.hash ()); + if (!amount_l) { type = "Send (pruned)"; } + else + { + amount = amount_l.value (); + } } void receive_block (nano::receive_block const & block_a) { type = "Receive"; auto account_l = ledger.account (transaction, block_a.hashables.source); - bool error_or_pruned = false; - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (!account_l || error_or_pruned) + auto amount_l = ledger.amount (transaction, block_a.hash ()); + if (!account_l || !amount_l) { type = "Receive (pruned)"; } else { account = account_l.value (); + amount = amount_l.value (); } } void open_block (nano::open_block const & block_a) @@ -548,16 +551,16 @@ class short_text_visitor : public nano::block_visitor type = "Receive"; if (block_a.hashables.source != ledger.constants.genesis->account ()) { - bool error_or_pruned (false); auto account_l = ledger.account (transaction, block_a.hashables.source); - amount = ledger.amount_safe (transaction, block_a.hash (), error_or_pruned); - if (!account_l || error_or_pruned) + auto amount_l = ledger.amount (transaction, block_a.hash ()); + if (!account_l || !amount_l) { type = "Receive (pruned)"; } else { account = account_l.value (); + amount = amount_l.value (); } } else diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index c4da525c96..c27abacb63 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -62,7 +62,7 @@ class rollback_visitor : public nano::block_visitor void receive_block (nano::receive_block const & block_a) override { auto hash (block_a.hash ()); - auto amount (ledger.amount (transaction, hash)); + auto amount = ledger.amount (transaction, hash).value (); auto destination_account = ledger.account (block_a); // Pending account entry can be incorrect if source block was pruned. But it's not affecting correct ledger processing auto source_account = ledger.account (transaction, block_a.hashables.source); @@ -81,7 +81,7 @@ class rollback_visitor : public nano::block_visitor void open_block (nano::open_block const & block_a) override { auto hash (block_a.hash ()); - auto amount (ledger.amount (transaction, hash)); + auto amount = ledger.amount (transaction, hash).value (); auto destination_account = ledger.account (block_a); auto source_account = ledger.account (transaction, block_a.hashables.source); ledger.cache.rep_weights.representation_add (block_a.representative (), 0 - amount); @@ -1155,31 +1155,24 @@ std::optional nano::ledger::account_info (store::transaction return store.account.get (transaction, account); } -nano::uint128_t nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) +std::optional nano::ledger::amount (store::transaction const & transaction_a, nano::block_hash const & hash_a) { auto block_l = block (transaction_a, hash_a); - auto block_balance = balance (*block_l); - if (block_l->previous ().is_zero ()) + if (!block_l) { - return block_balance; + return std::nullopt; } - auto previous_balance = balance (transaction_a, block_l->previous ()); - return block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; -} - -nano::uint128_t nano::ledger::amount_safe (store::transaction const & transaction_a, nano::block_hash const & hash_a, bool & error_a) const -{ - auto block_l = block (transaction_a, hash_a); - debug_assert (block_l); auto block_balance = balance (*block_l); if (block_l->previous ().is_zero ()) { return block_balance; } auto previous_balance = balance (transaction_a, block_l->previous ()); - error_a = !previous_balance; - return error_a ? 0 : block_balance > previous_balance.value () ? block_balance - previous_balance.value () - : previous_balance.value () - block_balance; + if (!previous_balance) + { + return std::nullopt; + } + return block_balance > previous_balance.value () ? block_balance - previous_balance.value () : previous_balance.value () - block_balance; } // Return latest block for account diff --git a/nano/secure/ledger.hpp b/nano/secure/ledger.hpp index 0d025bcc2d..6b3eddd698 100644 --- a/nano/secure/ledger.hpp +++ b/nano/secure/ledger.hpp @@ -40,9 +40,7 @@ class ledger final */ std::optional account (store::transaction const &, nano::block_hash const &) const; std::optional account_info (store::transaction const & transaction, nano::account const & account) const; - nano::uint128_t amount (store::transaction const &, nano::block_hash const &); - /** Safe for previous block, but block hash_a must exist */ - nano::uint128_t amount_safe (store::transaction const &, nano::block_hash const & hash_a, bool &) const; + std::optional amount (store::transaction const &, nano::block_hash const &); static nano::uint128_t balance (nano::block const & block); std::optional balance (store::transaction const &, nano::block_hash const &) const; std::shared_ptr block (store::transaction const & transaction, nano::block_hash const & hash) const; From ece1cfd6db9fa630bc591ca2b43f1b31764ab610 Mon Sep 17 00:00:00 2001 From: clemahieu Date: Wed, 6 Mar 2024 17:40:18 +0000 Subject: [PATCH 15/22] Update minimum OSX deployment target to 13.3 which is required by the OSX 14.4 SDK. (#4464) Fixes error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/include/c++/v1/__format/formatter_floating_point.h:66:32: error: 'to_chars' is unavailable: introduced in macOS 13.3 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0123485cdf..c411cee10e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ endif() # OSX compatibility needs to be set before project is declared set(CMAKE_OSX_DEPLOYMENT_TARGET - 12 + 13.3 CACHE STRING "") project(nano-node) From d4cbf1eaf3b1f95629761976debdf0d65006f78d Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 00:32:00 +0000 Subject: [PATCH 16/22] Move nano::block_sideband and nano::block_type in to their own files. --- nano/lib/CMakeLists.txt | 4 +++ nano/lib/block_sideband.cpp | 0 nano/lib/block_sideband.hpp | 68 ++++++++++++++++++++++++++++++++++++ nano/lib/block_type.cpp | 13 +++++++ nano/lib/block_type.hpp | 26 ++++++++++++++ nano/lib/blocks.cpp | 10 ------ nano/lib/blocks.hpp | 69 +------------------------------------ nano/store/block.hpp | 1 + 8 files changed, 113 insertions(+), 78 deletions(-) create mode 100644 nano/lib/block_sideband.cpp create mode 100644 nano/lib/block_sideband.hpp create mode 100644 nano/lib/block_type.cpp create mode 100644 nano/lib/block_type.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 271091dcef..9612fdf804 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -21,6 +21,10 @@ add_library( ${platform_sources} asio.hpp asio.cpp + block_sideband.hpp + block_sideband.cpp + block_type.hpp + block_type.cpp blockbuilders.hpp blockbuilders.cpp blocks.hpp diff --git a/nano/lib/block_sideband.cpp b/nano/lib/block_sideband.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nano/lib/block_sideband.hpp b/nano/lib/block_sideband.hpp new file mode 100644 index 0000000000..dc7e8a428e --- /dev/null +++ b/nano/lib/block_sideband.hpp @@ -0,0 +1,68 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace nano +{ +class object_stream; +} + +namespace nano +{ +class block_details +{ + static_assert (std::is_same::type, uint8_t> (), "Epoch enum is not the proper type"); + static_assert (static_cast (nano::epoch::max) < (1 << 5), "Epoch max is too large for the sideband"); + +public: + block_details () = default; + block_details (nano::epoch const epoch_a, bool const is_send_a, bool const is_receive_a, bool const is_epoch_a); + static constexpr size_t size () + { + return 1; + } + bool operator== (block_details const & other_a) const; + void serialize (nano::stream &) const; + bool deserialize (nano::stream &); + nano::epoch epoch{ nano::epoch::epoch_0 }; + bool is_send{ false }; + bool is_receive{ false }; + bool is_epoch{ false }; + +private: + uint8_t packed () const; + void unpack (uint8_t); + +public: // Logging + void operator() (nano::object_stream &) const; +}; + +std::string state_subtype (nano::block_details const); + +class block_sideband final +{ +public: + block_sideband () = default; + block_sideband (nano::account const &, nano::block_hash const &, nano::amount const &, uint64_t const, nano::seconds_t const local_timestamp, nano::block_details const &, nano::epoch const source_epoch_a); + block_sideband (nano::account const &, nano::block_hash const &, nano::amount const &, uint64_t const, nano::seconds_t const local_timestamp, nano::epoch const epoch_a, bool const is_send, bool const is_receive, bool const is_epoch, nano::epoch const source_epoch_a); + void serialize (nano::stream &, nano::block_type) const; + bool deserialize (nano::stream &, nano::block_type); + static size_t size (nano::block_type); + nano::block_hash successor{ 0 }; + nano::account account{}; + nano::amount balance{ 0 }; + uint64_t height{ 0 }; + uint64_t timestamp{ 0 }; + nano::block_details details; + nano::epoch source_epoch{ nano::epoch::epoch_0 }; + +public: // Logging + void operator() (nano::object_stream &) const; +}; +} // namespace nano diff --git a/nano/lib/block_type.cpp b/nano/lib/block_type.cpp new file mode 100644 index 0000000000..4afb9b0fdb --- /dev/null +++ b/nano/lib/block_type.cpp @@ -0,0 +1,13 @@ +#include + +#include + +std::string_view nano::to_string (nano::block_type type) +{ + return magic_enum::enum_name (type); +} + +void nano::serialize_block_type (nano::stream & stream, const nano::block_type & type) +{ + nano::write (stream, type); +} diff --git a/nano/lib/block_type.hpp b/nano/lib/block_type.hpp new file mode 100644 index 0000000000..020722e315 --- /dev/null +++ b/nano/lib/block_type.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include +#include + +namespace nano +{ +enum class block_type : uint8_t +{ + invalid = 0, + not_a_block = 1, + send = 2, + receive = 3, + open = 4, + change = 5, + state = 6 +}; + +std::string_view to_string (block_type); +/** + * Serialize block type as an 8-bit value + */ +void serialize_block_type (nano::stream &, nano::block_type const &); +} // namespace nano diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 3a13bb3868..0ad893339d 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -1443,11 +1443,6 @@ std::shared_ptr nano::deserialize_block_json (boost::property_tree: return result; } -void nano::serialize_block_type (nano::stream & stream, const nano::block_type & type) -{ - nano::write (stream, type); -} - void nano::serialize_block (nano::stream & stream_a, nano::block const & block_a) { nano::serialize_block_type (stream_a, block_a.type ()); @@ -1986,8 +1981,3 @@ void nano::block_sideband::operator() (nano::object_stream & obs) const obs.write ("source_epoch", source_epoch); obs.write ("details", details); } - -std::string_view nano::to_string (nano::block_type type) -{ - return magic_enum::enum_name (type); -} diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 19c31d95eb..0fb5aee4ae 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -21,70 +22,6 @@ namespace nano class block_visitor; class mutable_block_visitor; -enum class block_type : uint8_t -{ - invalid = 0, - not_a_block = 1, - send = 2, - receive = 3, - open = 4, - change = 5, - state = 6 -}; - -std::string_view to_string (block_type); - -class block_details -{ - static_assert (std::is_same::type, uint8_t> (), "Epoch enum is not the proper type"); - static_assert (static_cast (nano::epoch::max) < (1 << 5), "Epoch max is too large for the sideband"); - -public: - block_details () = default; - block_details (nano::epoch const epoch_a, bool const is_send_a, bool const is_receive_a, bool const is_epoch_a); - static constexpr size_t size () - { - return 1; - } - bool operator== (block_details const & other_a) const; - void serialize (nano::stream &) const; - bool deserialize (nano::stream &); - nano::epoch epoch{ nano::epoch::epoch_0 }; - bool is_send{ false }; - bool is_receive{ false }; - bool is_epoch{ false }; - -private: - uint8_t packed () const; - void unpack (uint8_t); - -public: // Logging - void operator() (nano::object_stream &) const; -}; - -std::string state_subtype (nano::block_details const); - -class block_sideband final -{ -public: - block_sideband () = default; - block_sideband (nano::account const &, nano::block_hash const &, nano::amount const &, uint64_t const, nano::seconds_t const local_timestamp, nano::block_details const &, nano::epoch const source_epoch_a); - block_sideband (nano::account const &, nano::block_hash const &, nano::amount const &, uint64_t const, nano::seconds_t const local_timestamp, nano::epoch const epoch_a, bool const is_send, bool const is_receive, bool const is_epoch, nano::epoch const source_epoch_a); - void serialize (nano::stream &, nano::block_type) const; - bool deserialize (nano::stream &, nano::block_type); - static size_t size (nano::block_type); - nano::block_hash successor{ 0 }; - nano::account account{}; - nano::amount balance{ 0 }; - uint64_t height{ 0 }; - uint64_t timestamp{ 0 }; - nano::block_details details; - nano::epoch source_epoch{ nano::epoch::epoch_0 }; - -public: // Logging - void operator() (nano::object_stream &) const; -}; - class block { public: @@ -446,10 +383,6 @@ using block_uniquer = nano::uniquer; std::shared_ptr deserialize_block (nano::stream &); std::shared_ptr deserialize_block (nano::stream &, nano::block_type, nano::block_uniquer * = nullptr); std::shared_ptr deserialize_block_json (boost::property_tree::ptree const &, nano::block_uniquer * = nullptr); -/** - * Serialize block type as an 8-bit value - */ -void serialize_block_type (nano::stream &, nano::block_type const &); /** * Serialize a block prefixed with an 8-bit typecode */ diff --git a/nano/store/block.hpp b/nano/store/block.hpp index 826aafc41c..c0d252a65a 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include From 15979e856ebfab415051aa1176ed66f43028cdb2 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 03:13:22 +0000 Subject: [PATCH 17/22] Splitting block_uniquer in to its own file --- nano/lib/CMakeLists.txt | 1 + nano/lib/block_uniquer.hpp | 10 ++++++++++ nano/lib/blocks.hpp | 4 +--- nano/node/messages.hpp | 1 + nano/node/node.hpp | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 nano/lib/block_uniquer.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 9612fdf804..c7029af764 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -25,6 +25,7 @@ add_library( block_sideband.cpp block_type.hpp block_type.cpp + block_uniquer.hpp blockbuilders.hpp blockbuilders.cpp blocks.hpp diff --git a/nano/lib/block_uniquer.hpp b/nano/lib/block_uniquer.hpp new file mode 100644 index 0000000000..d39bb3afc4 --- /dev/null +++ b/nano/lib/block_uniquer.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace nano +{ +class block; +using block_uniquer = nano::uniquer; +} diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 0fb5aee4ae..514adedfad 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -9,7 +10,6 @@ #include #include #include -#include #include #include @@ -378,8 +378,6 @@ class mutable_block_visitor virtual ~mutable_block_visitor () = default; }; -using block_uniquer = nano::uniquer; - std::shared_ptr deserialize_block (nano::stream &); std::shared_ptr deserialize_block (nano::stream &, nano::block_type, nano::block_uniquer * = nullptr); std::shared_ptr deserialize_block_json (boost::property_tree::ptree const &, nano::block_uniquer * = nullptr); diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 68d5d4247a..4e9401af20 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 0776b72850..d4105e61e4 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include From 6f36c9790b185f684dc7e916ce9e85360acd3bba Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 02:16:01 +0000 Subject: [PATCH 18/22] Splitting db_val implementation for blocks in to its own template implementation file. --- nano/store/CMakeLists.txt | 1 + nano/store/db_val.hpp | 33 ++++++++------------------------- nano/store/db_val_impl.hpp | 33 +++++++++++++++++++++++++++++++++ nano/store/lmdb/block.cpp | 1 + nano/store/rocksdb/block.cpp | 1 + 5 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 nano/store/db_val_impl.hpp diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index a992ba59bc..bf79b03e34 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -5,6 +5,7 @@ add_library( component.hpp confirmation_height.hpp db_val.hpp + db_val_impl.hpp iterator.hpp iterator_impl.hpp final.hpp diff --git a/nano/store/db_val.hpp b/nano/store/db_val.hpp index 957492e23e..a9fc4cc8d8 100644 --- a/nano/store/db_val.hpp +++ b/nano/store/db_val.hpp @@ -9,6 +9,11 @@ #include +namespace nano +{ +class block; +} + namespace nano::store { /** @@ -92,15 +97,7 @@ class db_val static_assert (std::is_standard_layout::value, "Standard layout is required"); } - db_val (std::shared_ptr const & val_a) : - buffer (std::make_shared> ()) - { - { - nano::vectorstream stream (*buffer); - nano::serialize_block (stream, *val_a); - } - convert_buffer_to_value (); - } + db_val (std::shared_ptr const & val_a); db_val (uint64_t val_a) : buffer (std::make_shared> ()) @@ -209,16 +206,7 @@ class db_val return result; } - explicit operator block_w_sideband () const - { - nano::bufferstream stream (reinterpret_cast (data ()), size ()); - nano::store::block_w_sideband block_w_sideband; - block_w_sideband.block = (nano::deserialize_block (stream)); - auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ()); - release_assert (!error); - block_w_sideband.block->sideband_set (block_w_sideband.sideband); - return block_w_sideband; - } + explicit operator block_w_sideband () const; explicit operator std::nullptr_t () const { @@ -230,12 +218,7 @@ class db_val return no_value::dummy; } - explicit operator std::shared_ptr () const - { - nano::bufferstream stream (reinterpret_cast (data ()), size ()); - std::shared_ptr result (nano::deserialize_block (stream)); - return result; - } + explicit operator std::shared_ptr () const; template std::shared_ptr convert_to_block () const diff --git a/nano/store/db_val_impl.hpp b/nano/store/db_val_impl.hpp new file mode 100644 index 0000000000..a8de6f0079 --- /dev/null +++ b/nano/store/db_val_impl.hpp @@ -0,0 +1,33 @@ +#include +#include + +template +nano::store::db_val::db_val (std::shared_ptr const & val_a) : + buffer (std::make_shared> ()) +{ + { + nano::vectorstream stream (*buffer); + nano::serialize_block (stream, *val_a); + } + convert_buffer_to_value (); +} + +template +nano::store::db_val::operator std::shared_ptr () const +{ + nano::bufferstream stream (reinterpret_cast (data ()), size ()); + std::shared_ptr result (nano::deserialize_block (stream)); + return result; +} + +template +nano::store::db_val::operator nano::store::block_w_sideband () const +{ + nano::bufferstream stream (reinterpret_cast (data ()), size ()); + nano::store::block_w_sideband block_w_sideband; + block_w_sideband.block = (nano::deserialize_block (stream)); + auto error = block_w_sideband.sideband.deserialize (stream, block_w_sideband.block->type ()); + release_assert (!error); + block_w_sideband.block->sideband_set (block_w_sideband.sideband); + return block_w_sideband; +} diff --git a/nano/store/lmdb/block.cpp b/nano/store/lmdb/block.cpp index ff6113f089..38e695ba66 100644 --- a/nano/store/lmdb/block.cpp +++ b/nano/store/lmdb/block.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/nano/store/rocksdb/block.cpp b/nano/store/rocksdb/block.cpp index 2fe5365e86..a910e0cc73 100644 --- a/nano/store/rocksdb/block.cpp +++ b/nano/store/rocksdb/block.cpp @@ -1,4 +1,5 @@ #include +#include #include #include From 08f70e9db5991e6ca046af510208ec5b0a481fbd Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 03:17:09 +0000 Subject: [PATCH 19/22] Forward declaring block and removing blocks.hpp includes from other headers. --- nano/core_test/active_transactions.cpp | 1 + nano/core_test/backlog.cpp | 1 + nano/core_test/block.cpp | 1 + nano/core_test/block_store.cpp | 1 + nano/core_test/blockprocessor.cpp | 1 + nano/core_test/bootstrap.cpp | 1 + nano/core_test/bootstrap_ascending.cpp | 1 + nano/core_test/bootstrap_server.cpp | 1 + nano/core_test/confirmation_height.cpp | 1 + nano/core_test/confirmation_solicitor.cpp | 1 + nano/core_test/conflicts.cpp | 2 +- nano/core_test/election.cpp | 1 + nano/core_test/election_scheduler.cpp | 1 + nano/core_test/frontiers_confirmation.cpp | 1 + nano/core_test/ledger.cpp | 1 + nano/core_test/memory_pool.cpp | 1 + nano/core_test/message.cpp | 1 + nano/core_test/message_deserializer.cpp | 1 + nano/core_test/network.cpp | 1 + nano/core_test/network_filter.cpp | 1 + nano/core_test/node.cpp | 1 + nano/core_test/optimistic_scheduler.cpp | 1 + nano/core_test/processor_service.cpp | 1 + nano/core_test/request_aggregator.cpp | 1 + nano/core_test/scheduler_buckets.cpp | 1 + nano/core_test/system.cpp | 1 + nano/core_test/unchecked_map.cpp | 1 + nano/core_test/vote_processor.cpp | 1 + nano/core_test/voting.cpp | 1 + nano/core_test/wallet.cpp | 1 + nano/core_test/wallets.cpp | 1 + nano/core_test/websocket.cpp | 1 + nano/lib/block_sideband.hpp | 1 + nano/lib/blockbuilders.cpp | 3 +++ nano/lib/blockbuilders.hpp | 11 ++++++++++- nano/lib/blocks.cpp | 6 ++++++ nano/lib/blocks.hpp | 2 -- nano/load_test/entry.cpp | 1 + nano/nano_node/entry.cpp | 1 + nano/node/active_transactions.cpp | 1 + nano/node/blockprocessor.cpp | 1 + nano/node/blockprocessor.hpp | 10 +++++++--- nano/node/bootstrap/block_deserializer.hpp | 4 +++- nano/node/bootstrap/bootstrap_attempt.cpp | 1 + nano/node/bootstrap/bootstrap_bulk_pull.cpp | 1 + nano/node/bootstrap/bootstrap_bulk_push.cpp | 1 + nano/node/bootstrap/bootstrap_frontier.hpp | 3 +++ nano/node/bootstrap/bootstrap_lazy.cpp | 1 + nano/node/bootstrap/bootstrap_server.cpp | 1 + nano/node/bootstrap_ascending/service.cpp | 1 + nano/node/cli.cpp | 1 + nano/node/confirmation_height_bounded.cpp | 1 + nano/node/confirmation_height_processor.cpp | 6 ++++++ nano/node/confirmation_height_processor.hpp | 5 +---- nano/node/confirmation_height_unbounded.cpp | 1 + nano/node/confirmation_solicitor.cpp | 1 + nano/node/election.cpp | 3 ++- nano/node/epoch_upgrader.cpp | 1 + nano/node/json_handler.cpp | 1 + nano/node/local_block_broadcaster.cpp | 8 +++++++- nano/node/local_block_broadcaster.hpp | 6 +----- nano/node/messages.hpp | 1 - nano/node/network.cpp | 1 + nano/node/node.cpp | 1 + nano/node/nodeconfig.cpp | 3 ++- nano/node/request_aggregator.cpp | 1 + nano/node/scheduler/optimistic.cpp | 1 + nano/node/scheduler/priority.cpp | 1 + nano/node/telemetry.cpp | 3 ++- nano/node/unchecked_map.cpp | 1 + nano/node/voting.cpp | 1 + nano/node/wallet.cpp | 1 + nano/node/websocket.cpp | 3 ++- nano/node/websocket.hpp | 2 +- nano/qt/qt.cpp | 1 + nano/qt_test/qt.cpp | 1 + nano/rpc_test/receivable.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/secure/common.cpp | 7 +------ nano/secure/common.hpp | 1 - nano/secure/ledger.cpp | 1 + nano/secure/network_filter.cpp | 1 + nano/secure/utility.cpp | 2 ++ nano/slow_test/node.cpp | 1 + nano/slow_test/vote_cache.cpp | 1 + nano/slow_test/vote_processor.cpp | 1 + nano/store/block.hpp | 2 +- nano/store/component.cpp | 1 + nano/store/lmdb/lmdb_env.cpp | 2 ++ nano/store/rocksdb/rocksdb.cpp | 1 + nano/store/versioning.hpp | 1 - nano/test_common/chains.cpp | 1 + nano/test_common/chains.hpp | 5 +++++ nano/test_common/ledger.cpp | 1 + nano/test_common/system.cpp | 1 + nano/test_common/testutil.cpp | 1 + 96 files changed, 139 insertions(+), 33 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index dc59f954f5..2b1bc50d0e 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/backlog.cpp b/nano/core_test/backlog.cpp index facbf0b538..fa58f702c6 100644 --- a/nano/core_test/backlog.cpp +++ b/nano/core_test/backlog.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 2b66920826..b187f63bbe 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 56f1c838f5..2b96b65b20 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/blockprocessor.cpp b/nano/core_test/blockprocessor.cpp index 38ccdc65b4..381cd1a915 100644 --- a/nano/core_test/blockprocessor.cpp +++ b/nano/core_test/blockprocessor.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index d1fbbb375a..27c78bb203 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/bootstrap_ascending.cpp b/nano/core_test/bootstrap_ascending.cpp index a9ca258454..257b35c60f 100644 --- a/nano/core_test/bootstrap_ascending.cpp +++ b/nano/core_test/bootstrap_ascending.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/bootstrap_server.cpp b/nano/core_test/bootstrap_server.cpp index 9be0f8eb94..80abdd8001 100644 --- a/nano/core_test/bootstrap_server.cpp +++ b/nano/core_test/bootstrap_server.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 906c6bc2d2..b0d3c4169d 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/confirmation_solicitor.cpp b/nano/core_test/confirmation_solicitor.cpp index c47ae54e88..6cad122134 100644 --- a/nano/core_test/confirmation_solicitor.cpp +++ b/nano/core_test/confirmation_solicitor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index 644388bdba..65ff27d1fd 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -1,4 +1,4 @@ - +#include #include #include #include diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index fc193cc659..d008489f12 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index af028dd996..b2af2740ba 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/frontiers_confirmation.cpp b/nano/core_test/frontiers_confirmation.cpp index 76812a6bc7..9d476ed357 100644 --- a/nano/core_test/frontiers_confirmation.cpp +++ b/nano/core_test/frontiers_confirmation.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index eb29e207d6..616324a6ab 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/memory_pool.cpp b/nano/core_test/memory_pool.cpp index 3e5049bc0c..1d9c1fc1b8 100644 --- a/nano/core_test/memory_pool.cpp +++ b/nano/core_test/memory_pool.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index 102af44db8..3053bbf04c 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/message_deserializer.cpp b/nano/core_test/message_deserializer.cpp index 271330491e..44e9fa06df 100644 --- a/nano/core_test/message_deserializer.cpp +++ b/nano/core_test/message_deserializer.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index e6a514b9ad..2e15d5ef9d 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/network_filter.cpp b/nano/core_test/network_filter.cpp index ae7f47e836..a886ae9564 100644 --- a/nano/core_test/network_filter.cpp +++ b/nano/core_test/network_filter.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index fa999b31bc..28dcae3dd9 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/optimistic_scheduler.cpp b/nano/core_test/optimistic_scheduler.cpp index 0f03c04fce..789eb66b3c 100644 --- a/nano/core_test/optimistic_scheduler.cpp +++ b/nano/core_test/optimistic_scheduler.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/processor_service.cpp b/nano/core_test/processor_service.cpp index 9a9f33b10d..959495d1db 100644 --- a/nano/core_test/processor_service.cpp +++ b/nano/core_test/processor_service.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index dff3215527..94f6d8c1b0 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/scheduler_buckets.cpp b/nano/core_test/scheduler_buckets.cpp index 0b3aff2381..43912e29b9 100644 --- a/nano/core_test/scheduler_buckets.cpp +++ b/nano/core_test/scheduler_buckets.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index 8ac65cc76b..b89524e8d2 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/unchecked_map.cpp b/nano/core_test/unchecked_map.cpp index 3688b6f5e0..105ee31318 100644 --- a/nano/core_test/unchecked_map.cpp +++ b/nano/core_test/unchecked_map.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index c19a895347..1da68596e8 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index cc95dd8461..cf210e3a1d 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index 3c9802c633..079eb007c4 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/wallets.cpp b/nano/core_test/wallets.cpp index 38009cdb19..f624f70dea 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 317d999e74..0735b5e4d6 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/lib/block_sideband.hpp b/nano/lib/block_sideband.hpp index dc7e8a428e..871f9bfcfc 100644 --- a/nano/lib/block_sideband.hpp +++ b/nano/lib/block_sideband.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace nano { diff --git a/nano/lib/blockbuilders.cpp b/nano/lib/blockbuilders.cpp index 69b375eb11..d8fa600f8f 100644 --- a/nano/lib/blockbuilders.cpp +++ b/nano/lib/blockbuilders.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include diff --git a/nano/lib/blockbuilders.hpp b/nano/lib/blockbuilders.hpp index 077d584019..1471c9bb20 100644 --- a/nano/lib/blockbuilders.hpp +++ b/nano/lib/blockbuilders.hpp @@ -1,9 +1,18 @@ #pragma once -#include +#include #include +namespace nano +{ +class change_block; +class send_block; +class state_block; +class open_block; +class receive_block; +} + namespace nano { /** Flags to track builder state */ diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 0ad893339d..688e614d13 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -13,6 +13,12 @@ #include #include +size_t constexpr nano::send_block::size; +size_t constexpr nano::receive_block::size; +size_t constexpr nano::open_block::size; +size_t constexpr nano::change_block::size; +size_t constexpr nano::state_block::size; + /** Compare blocks, first by type, then content. This is an optimization over dynamic_cast, which is very slow on some platforms. */ namespace { diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 514adedfad..0cb6969ca0 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -83,8 +83,6 @@ class block virtual void operator() (nano::object_stream &) const; }; -using block_list_t = std::vector>; - class send_hashables { public: diff --git a/nano/load_test/entry.cpp b/nano/load_test/entry.cpp index e41e376abc..13f56e38c0 100644 --- a/nano/load_test/entry.cpp +++ b/nano/load_test/entry.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 744df8d63b..42a79a8a2a 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 585bb4280b..2545c5d41d 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 24ed806777..731a000f76 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/blockprocessor.hpp b/nano/node/blockprocessor.hpp index 3cc7663c21..f0dae027c5 100644 --- a/nano/node/blockprocessor.hpp +++ b/nano/node/blockprocessor.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -10,6 +9,13 @@ #include #include +namespace nano +{ +class block; +class node; +class write_database_queue; +} + namespace nano::store { class write_transaction; @@ -17,8 +23,6 @@ class write_transaction; namespace nano { -class node; -class write_database_queue; enum class block_source { diff --git a/nano/node/bootstrap/block_deserializer.hpp b/nano/node/bootstrap/block_deserializer.hpp index 9e53aa7903..98499200de 100644 --- a/nano/node/bootstrap/block_deserializer.hpp +++ b/nano/node/bootstrap/block_deserializer.hpp @@ -1,6 +1,8 @@ #pragma once -#include +#include + +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_attempt.cpp b/nano/node/bootstrap/bootstrap_attempt.cpp index 4057dd8e0e..390d502674 100644 --- a/nano/node/bootstrap/bootstrap_attempt.cpp +++ b/nano/node/bootstrap/bootstrap_attempt.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap/bootstrap_bulk_pull.cpp b/nano/node/bootstrap/bootstrap_bulk_pull.cpp index 276e64418c..cad42863be 100644 --- a/nano/node/bootstrap/bootstrap_bulk_pull.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_pull.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap/bootstrap_bulk_push.cpp b/nano/node/bootstrap/bootstrap_bulk_push.cpp index 5ff069ba12..8a1e81118d 100644 --- a/nano/node/bootstrap/bootstrap_bulk_push.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_push.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap/bootstrap_frontier.hpp b/nano/node/bootstrap/bootstrap_frontier.hpp index 1f6575cd0f..75ee9c1ab9 100644 --- a/nano/node/bootstrap/bootstrap_frontier.hpp +++ b/nano/node/bootstrap/bootstrap_frontier.hpp @@ -1,7 +1,10 @@ #pragma once +#include + #include #include +#include namespace nano { diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index d69916a9c9..2c524c3f65 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap/bootstrap_server.cpp b/nano/node/bootstrap/bootstrap_server.cpp index 5585212fd8..91ba1838bd 100644 --- a/nano/node/bootstrap/bootstrap_server.cpp +++ b/nano/node/bootstrap/bootstrap_server.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 1ab1362849..909d643a29 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index bc829fcbb5..984f1656f4 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/confirmation_height_bounded.cpp b/nano/node/confirmation_height_bounded.cpp index 26cc21b42c..53c3ffbf30 100644 --- a/nano/node/confirmation_height_bounded.cpp +++ b/nano/node/confirmation_height_bounded.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/confirmation_height_processor.cpp b/nano/node/confirmation_height_processor.cpp index 4b9d9d82a6..e60816444a 100644 --- a/nano/node/confirmation_height_processor.cpp +++ b/nano/node/confirmation_height_processor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -239,3 +240,8 @@ nano::block_hash nano::confirmation_height_processor::current () const nano::lock_guard lk (mutex); return original_block ? original_block->hash () : 0; } + +std::reference_wrapper nano::confirmation_height_processor::block_wrapper::hash () const +{ + return block->hash (); +} diff --git a/nano/node/confirmation_height_processor.hpp b/nano/node/confirmation_height_processor.hpp index d31267833f..828a616111 100644 --- a/nano/node/confirmation_height_processor.hpp +++ b/nano/node/confirmation_height_processor.hpp @@ -65,10 +65,7 @@ class confirmation_height_processor final { } - std::reference_wrapper hash () const - { - return block->hash (); - } + std::reference_wrapper hash () const; std::shared_ptr block; }; diff --git a/nano/node/confirmation_height_unbounded.cpp b/nano/node/confirmation_height_unbounded.cpp index 18c1e0dc28..03c4c42a24 100644 --- a/nano/node/confirmation_height_unbounded.cpp +++ b/nano/node/confirmation_height_unbounded.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/confirmation_solicitor.cpp b/nano/node/confirmation_solicitor.cpp index cece99c530..feb782453a 100644 --- a/nano/node/confirmation_solicitor.cpp +++ b/nano/node/confirmation_solicitor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/election.cpp b/nano/node/election.cpp index d967201d27..d01d3718bd 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -801,4 +802,4 @@ void nano::election_extended_status::operator() (nano::object_stream & obs) cons obs.write ("hash", block->hash ().to_string ()); obs.write ("amount", amount); }); -} \ No newline at end of file +} diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index 9072b53291..48007b3559 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index ec02593e0e..16344c4cb7 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp index 0e5097e59e..59c0e4dffd 100644 --- a/nano/node/local_block_broadcaster.cpp +++ b/nano/node/local_block_broadcaster.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -167,4 +168,9 @@ std::unique_ptr nano::local_block_broadcaster::c auto composite = std::make_unique (name); composite->add_component (std::make_unique (container_info{ "local", local_blocks.size (), sizeof (decltype (local_blocks)::value_type) })); return composite; -} \ No newline at end of file +} + +nano::block_hash nano::local_block_broadcaster::local_entry::hash () const +{ + return block->hash (); +} diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp index 486fe85512..b4e7093dd6 100644 --- a/nano/node/local_block_broadcaster.hpp +++ b/nano/node/local_block_broadcaster.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -66,10 +65,7 @@ class local_block_broadcaster std::chrono::steady_clock::time_point const arrival; mutable std::chrono::steady_clock::time_point last_broadcast{}; // Not part of any index - nano::block_hash hash () const - { - return block->hash (); - } + nano::block_hash hash () const; }; // clang-format off diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 4e9401af20..11d96d6bad 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 0c9cf2268c..5da1940e00 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b202b8b018..77651c6b52 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index 175d78477b..beb93cb4f4 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -560,4 +561,4 @@ nano::account nano::node_config::random_representative () const std::size_t index (nano::random_pool::generate_word32 (0, static_cast (preconfigured_representatives.size () - 1))); auto result (preconfigured_representatives[index]); return result; -} \ No newline at end of file +} diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 452f0e0ba0..f822ace915 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index bd5247957f..8672d976e1 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index c503601a93..f5525895a0 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index e1fe6ece98..5e5b15fd2f 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -439,4 +440,4 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector (version_fragments[4]); return consolidated_data; -} \ No newline at end of file +} diff --git a/nano/node/unchecked_map.cpp b/nano/node/unchecked_map.cpp index b20651d793..4d65a40d2f 100644 --- a/nano/node/unchecked_map.cpp +++ b/nano/node/unchecked_map.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/voting.cpp b/nano/node/voting.cpp index 9ea31745d8..9967f7edb5 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index e1c2d7a834..53380f4b39 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index c2b3af2f98..dbd16637ab 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -1078,4 +1079,4 @@ void nano::websocket_server::stop () { server->stop (); } -} \ No newline at end of file +} diff --git a/nano/node/websocket.hpp b/nano/node/websocket.hpp index 6bb7426a0b..4b58bae7f2 100644 --- a/nano/node/websocket.hpp +++ b/nano/node/websocket.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -20,6 +19,7 @@ namespace nano { +class block; class wallets; class logger; class vote; diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index efd112cd7b..e189c58555 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index 3f1972bd16..6ff9e931f6 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/rpc_test/receivable.cpp b/nano/rpc_test/receivable.cpp index 81563180d0..6582161694 100644 --- a/nano/rpc_test/receivable.cpp +++ b/nano/rpc_test/receivable.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index da0b1af1ae..f6fe1b0651 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index d34f9daf07..091e45fcc4 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -17,12 +18,6 @@ #include #include -size_t constexpr nano::send_block::size; -size_t constexpr nano::receive_block::size; -size_t constexpr nano::open_block::size; -size_t constexpr nano::change_block::size; -size_t constexpr nano::state_block::size; - nano::networks nano::network_constants::active_network = nano::networks::ACTIVE_NETWORK; namespace diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 2e183267d4..9ce6858258 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d7464f4e07..92f76a4055 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/secure/network_filter.cpp b/nano/secure/network_filter.cpp index 059cddb30e..c60a111749 100644 --- a/nano/secure/network_filter.cpp +++ b/nano/secure/network_filter.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/secure/utility.cpp b/nano/secure/utility.cpp index d7e263d81f..07d6472462 100644 --- a/nano/secure/utility.cpp +++ b/nano/secure/utility.cpp @@ -2,6 +2,8 @@ #include #include +#include + #include static std::vector all_unique_paths; diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index b9b8e4ed40..7aa3a4d34d 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/slow_test/vote_cache.cpp b/nano/slow_test/vote_cache.cpp index 3c4a7ccb40..1e0b4abae8 100644 --- a/nano/slow_test/vote_cache.cpp +++ b/nano/slow_test/vote_cache.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/slow_test/vote_processor.cpp b/nano/slow_test/vote_processor.cpp index ff1ae1f52d..4dc3c09992 100644 --- a/nano/slow_test/vote_processor.cpp +++ b/nano/slow_test/vote_processor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/store/block.hpp b/nano/store/block.hpp index c0d252a65a..ad1fd55916 100644 --- a/nano/store/block.hpp +++ b/nano/store/block.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -10,6 +9,7 @@ namespace nano { +class block; class block_hash; } namespace nano::store diff --git a/nano/store/component.cpp b/nano/store/component.cpp index cd68dc2a09..67826f6345 100644 --- a/nano/store/component.cpp +++ b/nano/store/component.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/store/lmdb/lmdb_env.cpp b/nano/store/lmdb/lmdb_env.cpp index e66511da4c..cd1897c80a 100644 --- a/nano/store/lmdb/lmdb_env.cpp +++ b/nano/store/lmdb/lmdb_env.cpp @@ -1,6 +1,8 @@ #include #include +#include + nano::store::lmdb::env::env (bool & error_a, std::filesystem::path const & path_a, nano::store::lmdb::env::options options_a) { init (error_a, path_a, options_a); diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index 099972583c..43b82f2b4c 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/store/versioning.hpp b/nano/store/versioning.hpp index 0160535345..b165eef7dc 100644 --- a/nano/store/versioning.hpp +++ b/nano/store/versioning.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include struct MDB_val; diff --git a/nano/test_common/chains.cpp b/nano/test_common/chains.cpp index e7a745a33f..9bc2fa99ed 100644 --- a/nano/test_common/chains.cpp +++ b/nano/test_common/chains.cpp @@ -1,3 +1,4 @@ +#include #include using namespace std::chrono_literals; diff --git a/nano/test_common/chains.hpp b/nano/test_common/chains.hpp index 2004159cac..f8fd4229df 100644 --- a/nano/test_common/chains.hpp +++ b/nano/test_common/chains.hpp @@ -8,6 +8,11 @@ #include #include +namespace nano +{ +using block_list_t = std::vector>; +} + /* * Helper functions to deal with common chain setup scenarios */ diff --git a/nano/test_common/ledger.cpp b/nano/test_common/ledger.cpp index 063000f33e..a4c91533d2 100644 --- a/nano/test_common/ledger.cpp +++ b/nano/test_common/ledger.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 3ba0ce0009..efbd13dd44 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 9d6d5bb76e..ac01bdf0e7 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include From 4ad900ec31abf5245a50da65f30038742479fb27 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Thu, 7 Mar 2024 03:11:40 +0000 Subject: [PATCH 20/22] Reduce header files within blocks.hpp --- nano/lib/blocks.hpp | 9 +++------ nano/lib/config.cpp | 1 + nano/lib/work.cpp | 1 + 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 0cb6969ca0..e89f2dddba 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -1,26 +1,23 @@ #pragma once -#include #include #include +#include #include #include #include -#include #include #include -#include -#include -#include #include -#include +typedef struct blake2b_state__ blake2b_state; namespace nano { class block_visitor; class mutable_block_visitor; +class object_stream; class block { diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index 7f40e3b039..1839d7412e 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/lib/work.cpp b/nano/lib/work.cpp index 480dba578c..90a74095ae 100644 --- a/nano/lib/work.cpp +++ b/nano/lib/work.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From 950c1848f3ccc03088eed83bf957234c7e3ab306 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Thu, 7 Mar 2024 12:35:07 +0000 Subject: [PATCH 21/22] Minor unused test code bugfix (nano::test::account_height) (#4466) No test is currently using this function but it is useful function --- nano/test_common/testutil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 9d6d5bb76e..fcdd79e6d0 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -289,7 +289,7 @@ uint64_t nano::test::account_height (nano::node const & node, nano::account cons { auto const tx = node.ledger.store.tx_begin_read (); nano::confirmation_height_info height_info; - if (!node.ledger.store.confirmation_height.get (tx, acc, height_info)) + if (node.ledger.store.confirmation_height.get (tx, acc, height_info)) { return 0; } From 254aa88dc14bdccfe303f9d819d609ab844e26ec Mon Sep 17 00:00:00 2001 From: cuinix <65650185+cuinix@users.noreply.github.com> Date: Thu, 7 Mar 2024 23:38:50 +0800 Subject: [PATCH 22/22] fix some typos in docs (#4467) Signed-off-by: cuinix <915115094@qq.com> --- CL/cl2.hpp | 6 +++--- boost_checkout_lite.sh | 4 ++-- nano/core_test/confirmation_height.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CL/cl2.hpp b/CL/cl2.hpp index 534c486988..d4f1b51b64 100644 --- a/CL/cl2.hpp +++ b/CL/cl2.hpp @@ -3571,19 +3571,19 @@ cl::pointer>> allocate_svm(const cl } #endif // #if !defined(CL_HPP_NO_STD_UNIQUE_PTR) -/*! \brief Vector alias to simplify contruction of coarse-grained SVM containers. +/*! \brief Vector alias to simplify construction of coarse-grained SVM containers. * */ template < class T > using coarse_svm_vector = vector>>; -/*! \brief Vector alias to simplify contruction of fine-grained SVM containers. +/*! \brief Vector alias to simplify construction of fine-grained SVM containers. * */ template < class T > using fine_svm_vector = vector>>; -/*! \brief Vector alias to simplify contruction of fine-grained SVM containers that support platform atomics. +/*! \brief Vector alias to simplify construction of fine-grained SVM containers that support platform atomics. * */ template < class T > diff --git a/boost_checkout_lite.sh b/boost_checkout_lite.sh index 6e650ce7ab..18fe59588f 100755 --- a/boost_checkout_lite.sh +++ b/boost_checkout_lite.sh @@ -9,11 +9,11 @@ git submodule init boost cd boost # deactivate all boost submodules git submodule foreach 'git config submodule.$sm_path.active false' -# selectivly activate required dependencies +# selectively activate required dependencies for i in ${dependencies[@]} do git config submodule.$i.active true done cd .. -# Update all submodules recursivly. Deactivated modules will be skipped by --recursive +# Update all submodules recursively. Deactivated modules will be skipped by --recursive git submodule update --jobs 16 --recursive --recommend-shallow --single-branch diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index b0d3c4169d..52723aaebd 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1279,7 +1279,7 @@ TEST (confirmation_heightDeathTest, modified_chain) ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); { - // This reads the blocks in the account, but prevents any writes from occuring yet + // This reads the blocks in the account, but prevents any writes from occurring yet auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); bounded_processor.process (send); } @@ -1298,7 +1298,7 @@ TEST (confirmation_heightDeathTest, modified_chain) ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); { - // This reads the blocks in the account, but prevents any writes from occuring yet + // This reads the blocks in the account, but prevents any writes from occurring yet auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); unbounded_processor.process (send); } @@ -1367,7 +1367,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); { - // This reads the blocks in the account, but prevents any writes from occuring yet + // This reads the blocks in the account, but prevents any writes from occurring yet auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); unbounded_processor.process (open); } @@ -1387,7 +1387,7 @@ TEST (confirmation_heightDeathTest, modified_chain_account_removed) ledger, write_database_queue, 10ms, logger, stopped, batch_write_size, [] (auto const &) {}, [] (auto const &) {}, [] () { return 0; }); { - // This reads the blocks in the account, but prevents any writes from occuring yet + // This reads the blocks in the account, but prevents any writes from occurring yet auto scoped_write_guard = write_database_queue.wait (nano::writer::testing); bounded_processor.process (open); }