Skip to content

Commit 77ba2d7

Browse files
committed
Use extended ledger index for receivable RPC when available
Use the account_receivables_by_amount extended ledger index to serve receivable RPC when the extended ledger is available.
1 parent 577ff56 commit 77ba2d7

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

nano/node/json_handler.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <nano/secure/ledger_set_cemented.hpp>
2424
#include <nano/secure/transaction.hpp>
2525
#include <nano/store/ext_ledger/account_delegators_by_weight.hpp>
26+
#include <nano/store/ext_ledger/account_receivables_by_amount.hpp>
2627
#include <nano/store/ext_ledger_store.hpp>
2728
#include <nano/store/ledger/account.hpp>
2829
#include <nano/store/ledger/block.hpp>
@@ -3265,6 +3266,86 @@ void nano::json_handler::receivable ()
32653266
response_errors ();
32663267
}
32673268

3269+
void nano::json_handler::receivable_ext ()
3270+
{
3271+
if (!node.store.ext.is_initialized ())
3272+
{
3273+
ec = nano::error_rpc::requires_ext_ledger;
3274+
}
3275+
3276+
auto account (account_impl ());
3277+
auto count (count_optional_impl ());
3278+
auto offset (offset_optional_impl (0));
3279+
auto threshold (threshold_optional_impl ());
3280+
bool const source = request.get<bool> ("source", false);
3281+
bool const min_version = request.get<bool> ("min_version", false);
3282+
bool const include_active = request.get<bool> ("include_active", false);
3283+
bool const include_only_confirmed = request.get<bool> ("include_only_confirmed", true);
3284+
auto simple (threshold.is_zero () && !source && !min_version); // if simple, response is a list of hashes
3285+
3286+
if (!ec)
3287+
{
3288+
auto transaction = node.ledger.tx_begin_read ();
3289+
boost::property_tree::ptree peers_l;
3290+
3291+
for (auto i = node.store.ext.account_receivables_by_amount.rupper_bound (transaction, account), n = node.store.ext.account_receivables_by_amount.rend (transaction); i != n && peers_l.size () < count; ++i)
3292+
{
3293+
nano::account_receivable_by_amount_key const & key = i->first;
3294+
nano::account_receivable_by_amount_info const & info = i->second;
3295+
3296+
if (key.account != account)
3297+
{
3298+
break;
3299+
}
3300+
3301+
if (key.amount.number () < threshold.number ())
3302+
{
3303+
break;
3304+
}
3305+
3306+
if (!block_confirmed (node, transaction, key.send_block_hash, include_active, include_only_confirmed))
3307+
{
3308+
continue;
3309+
}
3310+
3311+
if (offset > 0)
3312+
{
3313+
--offset;
3314+
continue;
3315+
}
3316+
3317+
if (simple)
3318+
{
3319+
boost::property_tree::ptree entry;
3320+
entry.put ("", key.send_block_hash.to_string ());
3321+
peers_l.push_back (std::make_pair ("", entry));
3322+
}
3323+
else if (source || min_version)
3324+
{
3325+
boost::property_tree::ptree entry;
3326+
entry.put ("amount", key.amount.to_string_dec ());
3327+
if (source)
3328+
{
3329+
entry.put ("source", info.source.to_account ());
3330+
}
3331+
if (min_version)
3332+
{
3333+
entry.put ("min_version", epoch_as_string (info.epoch));
3334+
}
3335+
peers_l.add_child (key.send_block_hash.to_string (), entry);
3336+
}
3337+
else
3338+
{
3339+
peers_l.put (key.send_block_hash.to_string (), key.amount.to_string_dec ());
3340+
}
3341+
}
3342+
3343+
response_l.add_child ("blocks", peers_l);
3344+
}
3345+
3346+
response_errors ();
3347+
}
3348+
32683349
void nano::json_handler::pending_exists ()
32693350
{
32703351
response_l.put ("deprecated", "1");
@@ -5433,6 +5514,7 @@ ipc_json_handler_no_arg_func_map create_ipc_json_handler_no_arg_func_map ()
54335514
no_arg_funcs.emplace ("pending", &nano::json_handler::pending);
54345515
no_arg_funcs.emplace ("pending_exists", &nano::json_handler::pending_exists);
54355516
no_arg_funcs.emplace ("receivable", &nano::json_handler::receivable);
5517+
no_arg_funcs.emplace ("receivable_ext", &nano::json_handler::receivable_ext);
54365518
no_arg_funcs.emplace ("receivable_exists", &nano::json_handler::receivable_exists);
54375519
no_arg_funcs.emplace ("process", &nano::json_handler::process);
54385520
no_arg_funcs.emplace ("pruned_exists", &nano::json_handler::pruned_exists);

nano/node/json_handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class json_handler : public std::enable_shared_from_this<nano::json_handler>
9595
void pending ();
9696
void pending_exists ();
9797
void receivable ();
98+
void receivable_ext ();
9899
void receivable_exists ();
99100
void populate_backlog ();
100101
void process ();

0 commit comments

Comments
 (0)