From df2f06dc0685718fe0a1e08858d59bbf0c917a84 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 14:39:24 +0100 Subject: [PATCH 1/6] Revert "Rewrite wallet::search_receivable in terms of receivable iterators" This reverts commit 30a3cc2462a7083c710f7314dfdaed5c3915312d. # Conflicts: # nano/node/wallet.cpp --- nano/node/wallet.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index e8fc2473c8..764e3fea15 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1185,14 +1185,15 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact // Don't search pending for watch-only accounts if (!nano::wallet_value (i->second).key.is_zero ()) { - for (auto i = wallets.node.ledger.any.receivable_upper_bound (block_transaction, account, 0), n = wallets.node.ledger.any.receivable_end (); i != n; ++i) + for (auto j (wallets.node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), k (wallets.node.store.pending.end ()); j != k && nano::pending_key (j->first).account == account; ++j) { - auto const & [key, info] = *i; - auto hash = key.hash; - auto amount = info.amount.number (); + nano::pending_key key (j->first); + auto hash (key.hash); + nano::pending_info pending (j->second); + auto amount (pending.amount.number ()); if (wallets.node.config.receive_minimum.number () <= amount) { - wallets.node.logger.info (nano::log::type::wallet, "Found a receivable block {} for account {}", hash.to_string (), info.source.to_account ()); + wallets.node.logger.info (nano::log::type::wallet, "Found a receivable block {} for account {}", hash.to_string (), pending.source.to_account ()); if (wallets.node.ledger.confirmed.block_exists_or_pruned (block_transaction, hash)) { From 750b6ba65be9e676731ad5cafb370e60b900f768 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 16:06:29 +0100 Subject: [PATCH 2/6] Revert "Implement ledger::account_receivable in terms of receivable iterators" This reverts commit a5e150068088e3a36bd3128542cdf71518d2119d. # Conflicts: # nano/secure/ledger.cpp --- nano/secure/ledger.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index 52f819924d..e513bfb05c 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -792,11 +792,19 @@ void nano::ledger::initialize (nano::generate_cache_flags const & generate_cache nano::uint128_t nano::ledger::account_receivable (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a) { - nano::uint128_t result{ 0 }; - for (auto i = any.receivable_upper_bound (transaction_a, account_a, 0), n = any.receivable_end (); i != n; ++i) + nano::uint128_t result (0); + nano::account end (account_a.number () + 1); + for (auto i (store.pending.begin (transaction_a, nano::pending_key (account_a, 0))), n (store.pending.begin (transaction_a, nano::pending_key (end, 0))); i != n; ++i) { - auto const & [key, info] = *i; - if (!only_confirmed_a || confirmed.block_exists_or_pruned (transaction_a, key.hash)) + nano::pending_info const & info (i->second); + if (only_confirmed_a) + { + if (confirmed.block_exists_or_pruned (transaction_a, i->first.hash)) + { + result += info.amount.number (); + } + } + else { result += info.amount.number (); } From 52033c759f79cdb7a2f7c88bf20ae5a54812e22e Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 16:54:43 +0100 Subject: [PATCH 3/6] Revert "Reimplement json_handler::accounts_receivable in terms of receivable iterators." This reverts commit b08d6ff5228f71abed7785fdab187a6e8a5525cc. # Conflicts: # nano/node/json_handler.cpp --- nano/node/json_handler.cpp | 53 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index a75c63a4dd..e5f87a7c4f 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1054,34 +1054,35 @@ void nano::json_handler::accounts_receivable () if (!ec) { boost::property_tree::ptree peers_l; - for (auto current = node.ledger.any.receivable_upper_bound (transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && peers_l.size () < count; ++current) + for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end ()); i != n && nano::pending_key (i->first).account == account && peers_l.size () < count; ++i) { - auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash)) - { - continue; - } - if (simple) - { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - continue; - } - if (info.amount.number () < threshold.number ()) - { - continue; - } - if (source) - { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().template convert_to ()); - pending_tree.put ("source", info.source.to_account ()); - peers_l.add_child (key.hash.to_string (), pending_tree); - } - else + nano::pending_key const & key (i->first); + if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) { - peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to ()); + if (simple) + { + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); + } + else + { + nano::pending_info const & info (i->second); + if (info.amount.number () >= threshold.number ()) + { + if (source) + { + boost::property_tree::ptree pending_tree; + pending_tree.put ("amount", info.amount.number ().convert_to ()); + pending_tree.put ("source", info.source.to_account ()); + peers_l.add_child (key.hash.to_string (), pending_tree); + } + else + { + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + } + } + } } } if (sorting && !simple) From 67a1a4181e35f68ebc897154574f3b7bab0e10bb Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 17:43:32 +0100 Subject: [PATCH 4/6] Revert "Rewrite json_handler::receivable in terms of receivable iterators" This reverts commit 9d962e6e462c3ec1a2d26b9720b9f06d718d39a4. # Conflicts: # nano/node/json_handler.cpp --- nano/node/json_handler.cpp | 93 +++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index e5f87a7c4f..83f4323bdc 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -3110,61 +3110,62 @@ void nano::json_handler::receivable () // The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used. std::vector> hash_ptree_pairs; std::vector> hash_amount_pairs; - for (auto current = node.ledger.any.receivable_upper_bound (transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && (should_sort || peers_l.size () < count); ++current) + for (auto i (node.store.pending.begin (transaction, nano::pending_key (account, 0))), n (node.store.pending.end ()); i != n && nano::pending_key (i->first).account == account && (should_sort || peers_l.size () < count); ++i) { - auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash)) + nano::pending_key const & key (i->first); + if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed)) { - continue; - } - if (!should_sort && offset_counter > 0) - { - --offset_counter; - continue; - } - - if (simple) - { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - continue; - } - if (info.amount.number () < threshold.number ()) - { - continue; - } - if (source || min_version) - { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().template convert_to ()); - if (source) - { - pending_tree.put ("source", info.source.to_account ()); - } - if (min_version) + if (!should_sort && offset_counter > 0) { - pending_tree.put ("min_version", epoch_as_string (info.epoch)); + --offset_counter; + continue; } - if (should_sort) - { - hash_ptree_pairs.emplace_back (key.hash.to_string (), pending_tree); - } - else + if (simple) { - peers_l.add_child (key.hash.to_string (), pending_tree); - } - } - else - { - if (should_sort) - { - hash_amount_pairs.emplace_back (key.hash.to_string (), info.amount.number ()); + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); } else { - peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to ()); + nano::pending_info const & info (i->second); + if (info.amount.number () >= threshold.number ()) + { + if (source || min_version) + { + boost::property_tree::ptree pending_tree; + pending_tree.put ("amount", info.amount.number ().convert_to ()); + if (source) + { + pending_tree.put ("source", info.source.to_account ()); + } + if (min_version) + { + pending_tree.put ("min_version", epoch_as_string (info.epoch)); + } + + if (should_sort) + { + hash_ptree_pairs.emplace_back (key.hash.to_string (), pending_tree); + } + else + { + peers_l.add_child (key.hash.to_string (), pending_tree); + } + } + else + { + if (should_sort) + { + hash_amount_pairs.emplace_back (key.hash.to_string (), info.amount.number ()); + } + else + { + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + } + } + } } } } From 7079ea42dad5f2df9bdd113e588e8b8a8076070e Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 18:04:35 +0100 Subject: [PATCH 5/6] Revert "Reimplement json_handler::wallet_receivable in terms of receivable iterators" This reverts commit 873760f345bfb15b4b991fc1de4bd604ed0c5ee4. # Conflicts: # nano/node/json_handler.cpp --- nano/node/json_handler.cpp | 59 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 83f4323bdc..e426f5fc66 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -4839,41 +4839,42 @@ void nano::json_handler::wallet_receivable () { nano::account const & account (i->first); boost::property_tree::ptree peers_l; - for (auto current = node.ledger.any.receivable_upper_bound (block_transaction, account, 0), end = node.ledger.any.receivable_end (); current != end && (peers_l.size () < count); ++current) + for (auto ii (node.store.pending.begin (block_transaction, nano::pending_key (account, 0))), nn (node.store.pending.end ()); ii != nn && nano::pending_key (ii->first).account == account && peers_l.size () < count; ++ii) { - auto const & [key, info] = *current; - if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (block_transaction, key.hash)) + nano::pending_key key (ii->first); + if (block_confirmed (node, block_transaction, key.hash, include_active, include_only_confirmed)) { - continue; - } - if (threshold.is_zero () && !source) - { - boost::property_tree::ptree entry; - entry.put ("", key.hash.to_string ()); - peers_l.push_back (std::make_pair ("", entry)); - continue; - } - if (info.amount.number () < threshold.number ()) - { - continue; - } - if (source || min_version) - { - boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().template convert_to ()); - if (source) + if (threshold.is_zero () && !source) { - pending_tree.put ("source", info.source.to_account ()); + boost::property_tree::ptree entry; + entry.put ("", key.hash.to_string ()); + peers_l.push_back (std::make_pair ("", entry)); } - if (min_version) + else { - pending_tree.put ("min_version", epoch_as_string (info.epoch)); + nano::pending_info info (ii->second); + if (info.amount.number () >= threshold.number ()) + { + if (source || min_version) + { + boost::property_tree::ptree pending_tree; + pending_tree.put ("amount", info.amount.number ().convert_to ()); + if (source) + { + pending_tree.put ("source", info.source.to_account ()); + } + if (min_version) + { + pending_tree.put ("min_version", epoch_as_string (info.epoch)); + } + peers_l.add_child (key.hash.to_string (), pending_tree); + } + else + { + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + } + } } - peers_l.add_child (key.hash.to_string (), pending_tree); - } - else - { - peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to ()); } } if (!peers_l.empty ()) From fb077a022c6def2aeb26801bf0414e0f8ef46897 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 21 Aug 2024 22:06:06 +0100 Subject: [PATCH 6/6] Fix formatting. --- nano/rpc_test/rpc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 67a3e8d705..90b17c57c7 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -5580,7 +5580,7 @@ TEST (rpc, unopened) boost::property_tree::ptree request; request.put ("action", "unopened"); request.put ("count", "1"); - request.put ("account", account1.to_account()); + request.put ("account", account1.to_account ()); auto response (wait_response (system, rpc_ctx, request)); auto & accounts (response.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); @@ -5591,7 +5591,7 @@ TEST (rpc, unopened) boost::property_tree::ptree request; request.put ("action", "unopened"); request.put ("count", "1"); - request.put ("account", account2.to_account()); + request.put ("account", account2.to_account ()); auto response (wait_response (system, rpc_ctx, request)); auto & accounts (response.get_child ("accounts")); ASSERT_EQ (1, accounts.size ()); @@ -5626,7 +5626,7 @@ TEST (rpc, unopened_seek) boost::property_tree::ptree request; request.put ("action", "unopened"); request.put ("count", "1"); - request.put ("account", nano::dev::genesis_key.pub.to_account()); + request.put ("account", nano::dev::genesis_key.pub.to_account ()); auto response (wait_response (system, rpc_ctx, request)); auto & accounts (response.get_child ("accounts")); ASSERT_EQ (1, accounts.size ());