Skip to content

Commit

Permalink
Pending to receivable renames (#3753)
Browse files Browse the repository at this point in the history
* Copy accounts_pending to accounts_receivable and deprecate the former

* Copy wallet_pending to wallet_receivable and deprecate the former

* Copy search_pending_all to search_receivable_all and deprecate the former

* Copy search_pending to search_receivable and deprecate the former

* account_info rpc: introduce receivable option and confirmed_receivable reply

Introduce new option called receivable to replace pending option.
Currently both are supported and do the same job.
However, if both are set, receivable has priority.

Also added confirmed_receivable reply when include_confirmed is set.

* Rename nano::ledger::account_pending to nano::ledger::account_receivable

* Convert RPC blocks_info to use receivable rather than pending

Pending is still supported but deprecated

* Add support for receivable option to ledger RPC command

The ledger RPC command only supported pending option.
Now, it supports both with receivable having priority, if both are set.

* Add support for receivable option to wallet_ledger RPC command

* Add deprecated field in RPC response of pending and pending_exists

The RPC commands did not return "deprecated=true", now they do.
Also renamed underlying handling functions from pending to receivable.
  • Loading branch information
dsiganos authored Mar 28, 2022
1 parent 9a19ec6 commit a37a148
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 107 deletions.
12 changes: 6 additions & 6 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ TEST (ledger, process_send)
ASSERT_EQ (nano::process_result::progress, return1.code);
ASSERT_EQ (nano::dev::genesis_key.pub, store->block.account_calculated (send));
ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_receivable (transaction, key2.pub));
nano::account_info info2;
ASSERT_FALSE (store->account.get (transaction, nano::dev::genesis_key.pub, info2));
ASSERT_EQ (2, info2.block_count);
Expand All @@ -131,7 +131,7 @@ TEST (ledger, process_send)
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.amount (transaction, hash2));
ASSERT_EQ (key2.pub, store->frontier.get (transaction, hash2));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub));
ASSERT_EQ (0, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key2.pub));
nano::account_info info3;
Expand All @@ -157,7 +157,7 @@ TEST (ledger, process_send)
ASSERT_EQ (nano::dev::genesis_key.pub, pending1.source);
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, pending1.amount.number ());
ASSERT_EQ (0, ledger.account_balance (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (50, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (50, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.weight (key2.pub));
Expand All @@ -175,7 +175,7 @@ TEST (ledger, process_send)
nano::pending_info pending2;
ASSERT_TRUE (ledger.store.pending.get (transaction, nano::pending_key (key2.pub, hash1), pending2));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (store->account.count (transaction), ledger.cache.account_count);
}

Expand Down Expand Up @@ -223,15 +223,15 @@ TEST (ledger, process_receive)
ASSERT_EQ (key2.pub, store->block.account_calculated (receive));
ASSERT_EQ (hash4, ledger.latest (transaction, key2.pub));
ASSERT_EQ (25, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (0, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (0, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.account_balance (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 25, ledger.weight (key3.pub));
ASSERT_FALSE (ledger.rollback (transaction, hash4));
ASSERT_TRUE (store->block.successor (transaction, hash2).is_zero ());
ASSERT_EQ (key2.pub, store->frontier.get (transaction, hash2));
ASSERT_TRUE (store->frontier.get (transaction, hash4).is_zero ());
ASSERT_EQ (25, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (25, ledger.account_pending (transaction, key2.pub));
ASSERT_EQ (25, ledger.account_receivable (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.account_balance (transaction, key2.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount - 50, ledger.weight (key3.pub));
ASSERT_EQ (hash2, ledger.latest (transaction, key2.pub));
Expand Down
20 changes: 10 additions & 10 deletions nano/core_test/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,19 +381,19 @@ TEST (node, merge_peers)
ASSERT_EQ (0, system.nodes[0]->network.size ());
}

TEST (node, search_pending)
TEST (node, search_receivable)
{
nano::system system (1);
auto node (system.nodes[0]);
nano::keypair key2;
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_FALSE (system.wallet (0)->search_pending (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_FALSE (system.wallet (0)->search_receivable (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_TIMELY (10s, !node->balance (key2.pub).is_zero ());
}

TEST (node, search_pending_same)
TEST (node, search_receivable_same)
{
nano::system system (1);
auto node (system.nodes[0]);
Expand All @@ -402,11 +402,11 @@ TEST (node, search_pending_same)
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_FALSE (system.wallet (0)->search_pending (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_FALSE (system.wallet (0)->search_receivable (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ());
}

TEST (node, search_pending_multiple)
TEST (node, search_receivable_multiple)
{
nano::system system (1);
auto node (system.nodes[0]);
Expand All @@ -419,11 +419,11 @@ TEST (node, search_pending_multiple)
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::dev::genesis_key.pub, key2.pub, node->config.receive_minimum.number ()));
ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, node->config.receive_minimum.number ()));
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_FALSE (system.wallet (0)->search_pending (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_FALSE (system.wallet (0)->search_receivable (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ());
}

TEST (node, search_pending_confirmed)
TEST (node, search_receivable_confirmed)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
Expand All @@ -449,7 +449,7 @@ TEST (node, search_pending_confirmed)
system.wallet (0)->store.erase (transaction, nano::dev::genesis_key.pub);
}
system.wallet (0)->insert_adhoc (key2.prv);
ASSERT_FALSE (system.wallet (0)->search_pending (system.wallet (0)->wallets.tx_begin_read ()));
ASSERT_FALSE (system.wallet (0)->search_receivable (system.wallet (0)->wallets.tx_begin_read ()));
{
nano::lock_guard<nano::mutex> guard (node->active.mutex);
auto existing1 (node->active.blocks.find (send1->hash ()));
Expand All @@ -460,7 +460,7 @@ TEST (node, search_pending_confirmed)
ASSERT_TIMELY (10s, node->balance (key2.pub) == 2 * node->config.receive_minimum.number ());
}

TEST (node, search_pending_pruned)
TEST (node, search_receivable_pruned)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
Expand Down Expand Up @@ -494,7 +494,7 @@ TEST (node, search_pending_pruned)

// Receive pruned block
system.wallet (1)->insert_adhoc (key2.prv);
ASSERT_FALSE (system.wallet (1)->search_pending (system.wallet (1)->wallets.tx_begin_read ()));
ASSERT_FALSE (system.wallet (1)->search_receivable (system.wallet (1)->wallets.tx_begin_read ()));
ASSERT_TIMELY (10s, node2->balance (key2.pub) == 2 * node2->config.receive_minimum.number ());
}

Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ TEST (wallet, foreach_representative_deadlock)
ASSERT_TRUE (set);
}

TEST (wallet, search_pending)
TEST (wallet, search_receivable)
{
nano::system system;
nano::node_config config (nano::get_available_port (), system.logging);
Expand All @@ -1178,7 +1178,7 @@ TEST (wallet, search_pending)

// Pending search should start an election
ASSERT_TRUE (node.active.empty ());
ASSERT_FALSE (wallet.search_pending (wallet.wallets.tx_begin_read ()));
ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ()));
auto election = node.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election);

Expand All @@ -1195,7 +1195,7 @@ TEST (wallet, search_pending)

// Pending search should create the receive block
ASSERT_EQ (2, node.ledger.cache.block_count);
ASSERT_FALSE (wallet.search_pending (wallet.wallets.tx_begin_read ()));
ASSERT_FALSE (wallet.search_receivable (wallet.wallets.tx_begin_read ()));
ASSERT_TIMELY (3s, node.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ());
auto receive = node.block (receive_hash);
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/wallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TEST (wallets, exists)
}
}

TEST (wallets, search_pending)
TEST (wallets, search_receivable)
{
for (auto search_all : { false, true })
{
Expand Down Expand Up @@ -179,11 +179,11 @@ TEST (wallets, search_pending)
ASSERT_TRUE (node.active.empty ());
if (search_all)
{
node.wallets.search_pending_all ();
node.wallets.search_receivable_all ();
}
else
{
node.wallets.search_pending (wallet_id);
node.wallets.search_receivable (wallet_id);
}
auto election = node.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election);
Expand All @@ -203,11 +203,11 @@ TEST (wallets, search_pending)
ASSERT_EQ (2, node.ledger.cache.block_count);
if (search_all)
{
node.wallets.search_pending_all ();
node.wallets.search_receivable_all ();
}
else
{
node.wallets.search_pending (wallet_id);
node.wallets.search_receivable (wallet_id);
}
ASSERT_TIMELY (3s, node.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount);
auto receive_hash = node.ledger.latest (node.store.tx_begin_read (), nano::dev::genesis->account ());
Expand Down
Loading

0 comments on commit a37a148

Please sign in to comment.