Merge pull request #4711 from clemahieu/revert_receivable_iterator
Partially revert receivable iterator
This commit is contained in:
commit
d84ffb7219
4 changed files with 125 additions and 113 deletions
|
|
@ -1054,34 +1054,35 @@ void nano::json_handler::accounts_receivable ()
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree peers_l;
|
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;
|
nano::pending_key const & key (i->first);
|
||||||
if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash))
|
if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed))
|
||||||
{
|
{
|
||||||
continue;
|
if (simple)
|
||||||
}
|
{
|
||||||
if (simple)
|
boost::property_tree::ptree entry;
|
||||||
{
|
entry.put ("", key.hash.to_string ());
|
||||||
boost::property_tree::ptree entry;
|
peers_l.push_back (std::make_pair ("", entry));
|
||||||
entry.put ("", key.hash.to_string ());
|
}
|
||||||
peers_l.push_back (std::make_pair ("", entry));
|
else
|
||||||
continue;
|
{
|
||||||
}
|
nano::pending_info const & info (i->second);
|
||||||
if (info.amount.number () < threshold.number ())
|
if (info.amount.number () >= threshold.number ())
|
||||||
{
|
{
|
||||||
continue;
|
if (source)
|
||||||
}
|
{
|
||||||
if (source)
|
boost::property_tree::ptree pending_tree;
|
||||||
{
|
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
|
||||||
boost::property_tree::ptree pending_tree;
|
pending_tree.put ("source", info.source.to_account ());
|
||||||
pending_tree.put ("amount", info.amount.number ().template convert_to<std::string> ());
|
peers_l.add_child (key.hash.to_string (), pending_tree);
|
||||||
pending_tree.put ("source", info.source.to_account ());
|
}
|
||||||
peers_l.add_child (key.hash.to_string (), pending_tree);
|
else
|
||||||
}
|
{
|
||||||
else
|
peers_l.put (key.hash.to_string (), info.amount.number ().convert_to<std::string> ());
|
||||||
{
|
}
|
||||||
peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to<std::string> ());
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sorting && !simple)
|
if (sorting && !simple)
|
||||||
|
|
@ -3109,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.
|
// The ptree container is used if there are any children nodes (e.g source/min_version) otherwise the amount container is used.
|
||||||
std::vector<std::pair<std::string, boost::property_tree::ptree>> hash_ptree_pairs;
|
std::vector<std::pair<std::string, boost::property_tree::ptree>> hash_ptree_pairs;
|
||||||
std::vector<std::pair<std::string, nano::uint128_t>> hash_amount_pairs;
|
std::vector<std::pair<std::string, nano::uint128_t>> 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;
|
nano::pending_key const & key (i->first);
|
||||||
if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (transaction, key.hash))
|
if (block_confirmed (node, transaction, key.hash, include_active, include_only_confirmed))
|
||||||
{
|
{
|
||||||
continue;
|
if (!should_sort && offset_counter > 0)
|
||||||
}
|
|
||||||
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<std::string> ());
|
|
||||||
if (source)
|
|
||||||
{
|
{
|
||||||
pending_tree.put ("source", info.source.to_account ());
|
--offset_counter;
|
||||||
}
|
continue;
|
||||||
if (min_version)
|
|
||||||
{
|
|
||||||
pending_tree.put ("min_version", epoch_as_string (info.epoch));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (should_sort)
|
if (simple)
|
||||||
{
|
{
|
||||||
hash_ptree_pairs.emplace_back (key.hash.to_string (), pending_tree);
|
boost::property_tree::ptree entry;
|
||||||
|
entry.put ("", key.hash.to_string ());
|
||||||
|
peers_l.push_back (std::make_pair ("", entry));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
peers_l.add_child (key.hash.to_string (), pending_tree);
|
nano::pending_info const & info (i->second);
|
||||||
}
|
if (info.amount.number () >= threshold.number ())
|
||||||
}
|
{
|
||||||
else
|
if (source || min_version)
|
||||||
{
|
{
|
||||||
if (should_sort)
|
boost::property_tree::ptree pending_tree;
|
||||||
{
|
pending_tree.put ("amount", info.amount.number ().convert_to<std::string> ());
|
||||||
hash_amount_pairs.emplace_back (key.hash.to_string (), info.amount.number ());
|
if (source)
|
||||||
}
|
{
|
||||||
else
|
pending_tree.put ("source", info.source.to_account ());
|
||||||
{
|
}
|
||||||
peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to<std::string> ());
|
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<std::string> ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4837,41 +4839,42 @@ void nano::json_handler::wallet_receivable ()
|
||||||
{
|
{
|
||||||
nano::account const & account (i->first);
|
nano::account const & account (i->first);
|
||||||
boost::property_tree::ptree peers_l;
|
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;
|
nano::pending_key key (ii->first);
|
||||||
if (include_only_confirmed && !node.ledger.confirmed.block_exists_or_pruned (block_transaction, key.hash))
|
if (block_confirmed (node, block_transaction, key.hash, include_active, include_only_confirmed))
|
||||||
{
|
{
|
||||||
continue;
|
if (threshold.is_zero () && !source)
|
||||||
}
|
|
||||||
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<std::string> ());
|
|
||||||
if (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<std::string> ());
|
||||||
|
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<std::string> ());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
peers_l.add_child (key.hash.to_string (), pending_tree);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
peers_l.put (key.hash.to_string (), info.amount.number ().template convert_to<std::string> ());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!peers_l.empty ())
|
if (!peers_l.empty ())
|
||||||
|
|
|
||||||
|
|
@ -1185,14 +1185,15 @@ bool nano::wallet::search_receivable (store::transaction const & wallet_transact
|
||||||
// Don't search pending for watch-only accounts
|
// Don't search pending for watch-only accounts
|
||||||
if (!nano::wallet_value (i->second).key.is_zero ())
|
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;
|
nano::pending_key key (j->first);
|
||||||
auto hash = key.hash;
|
auto hash (key.hash);
|
||||||
auto amount = info.amount.number ();
|
nano::pending_info pending (j->second);
|
||||||
|
auto amount (pending.amount.number ());
|
||||||
if (wallets.node.config.receive_minimum.number () <= amount)
|
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))
|
if (wallets.node.ledger.confirmed.block_exists_or_pruned (block_transaction, hash))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5580,7 +5580,7 @@ TEST (rpc, unopened)
|
||||||
boost::property_tree::ptree request;
|
boost::property_tree::ptree request;
|
||||||
request.put ("action", "unopened");
|
request.put ("action", "unopened");
|
||||||
request.put ("count", "1");
|
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 response (wait_response (system, rpc_ctx, request));
|
||||||
auto & accounts (response.get_child ("accounts"));
|
auto & accounts (response.get_child ("accounts"));
|
||||||
ASSERT_EQ (1, accounts.size ());
|
ASSERT_EQ (1, accounts.size ());
|
||||||
|
|
@ -5591,7 +5591,7 @@ TEST (rpc, unopened)
|
||||||
boost::property_tree::ptree request;
|
boost::property_tree::ptree request;
|
||||||
request.put ("action", "unopened");
|
request.put ("action", "unopened");
|
||||||
request.put ("count", "1");
|
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 response (wait_response (system, rpc_ctx, request));
|
||||||
auto & accounts (response.get_child ("accounts"));
|
auto & accounts (response.get_child ("accounts"));
|
||||||
ASSERT_EQ (1, accounts.size ());
|
ASSERT_EQ (1, accounts.size ());
|
||||||
|
|
@ -5626,7 +5626,7 @@ TEST (rpc, unopened_seek)
|
||||||
boost::property_tree::ptree request;
|
boost::property_tree::ptree request;
|
||||||
request.put ("action", "unopened");
|
request.put ("action", "unopened");
|
||||||
request.put ("count", "1");
|
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 response (wait_response (system, rpc_ctx, request));
|
||||||
auto & accounts (response.get_child ("accounts"));
|
auto & accounts (response.get_child ("accounts"));
|
||||||
ASSERT_EQ (1, accounts.size ());
|
ASSERT_EQ (1, accounts.size ());
|
||||||
|
|
|
||||||
|
|
@ -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 nano::ledger::account_receivable (secure::transaction const & transaction_a, nano::account const & account_a, bool only_confirmed_a)
|
||||||
{
|
{
|
||||||
nano::uint128_t result{ 0 };
|
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::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;
|
nano::pending_info const & info (i->second);
|
||||||
if (!only_confirmed_a || confirmed.block_exists_or_pruned (transaction_a, key.hash))
|
if (only_confirmed_a)
|
||||||
|
{
|
||||||
|
if (confirmed.block_exists_or_pruned (transaction_a, i->first.hash))
|
||||||
|
{
|
||||||
|
result += info.amount.number ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
result += info.amount.number ();
|
result += info.amount.number ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue