Skip to content

Commit

Permalink
Merge pull request #4501 from clemahieu/receivable_abstraction
Browse files Browse the repository at this point in the history
Replace some additional direct usages of store.pending with calls to ledger::pending_info
  • Loading branch information
clemahieu authored Mar 18, 2024
2 parents 88d27d8 + aea4217 commit b0fe9b3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
44 changes: 22 additions & 22 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,7 @@ TEST (ledger, state_send_receive)
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ()));
ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_TRUE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (2, send2->sideband ().height);
ASSERT_TRUE (send2->is_send ());
ASSERT_FALSE (send2->is_receive ());
Expand All @@ -2396,7 +2396,7 @@ TEST (ledger, state_send_receive)
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.balance (transaction, receive1->hash ()));
ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, receive1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count);
ASSERT_EQ (3, receive2->sideband ().height);
ASSERT_FALSE (receive2->is_send ());
Expand Down Expand Up @@ -2513,7 +2513,7 @@ TEST (ledger, state_open)
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.balance (transaction, send1->hash ()));
ASSERT_EQ (nano::Gxrb_ratio, ledger.amount (transaction, send1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount - nano::Gxrb_ratio, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_TRUE (store.pending.exists (transaction, nano::pending_key (destination.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ destination.pub, send1->hash () }));
auto open1 = builder
.state ()
.account (destination.pub)
Expand All @@ -2525,7 +2525,7 @@ TEST (ledger, state_open)
.work (*pool.generate (destination.pub))
.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_FALSE (ledger.pending_info (transaction, nano::pending_key{ destination.pub, send1->hash () }));
ASSERT_TRUE (ledger.block_exists (transaction, open1->hash ()));
auto open2 = ledger.block (transaction, open1->hash ());
ASSERT_NE (nullptr, open2);
Expand Down Expand Up @@ -3138,7 +3138,7 @@ TEST (ledger, state_rollback_send)
ASSERT_FALSE (ledger.block_exists (transaction, send1->hash ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.account_balance (transaction, nano::dev::genesis_key.pub));
ASSERT_EQ (nano::dev::constants.genesis_amount, ledger.weight (nano::dev::genesis_key.pub));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_FALSE (ledger.successor (transaction, nano::dev::genesis->hash ()));
ASSERT_EQ (store.account.count (transaction), ledger.cache.account_count);
}
Expand Down Expand Up @@ -3173,7 +3173,7 @@ TEST (ledger, state_rollback_receive)
.work (*pool.generate (send1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, receive1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, receive1->hash () }));
ASSERT_FALSE (ledger.rollback (transaction, receive1->hash ()));
auto info = ledger.pending_info (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ()));
ASSERT_TRUE (info);
Expand Down Expand Up @@ -3216,9 +3216,9 @@ TEST (ledger, state_rollback_received_send)
.work (*pool.generate (key.pub))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, receive1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, receive1->hash () }));
ASSERT_FALSE (ledger.rollback (transaction, send1->hash ()));
ASSERT_FALSE (store.pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->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_key.pub));
Expand Down Expand Up @@ -4855,7 +4855,7 @@ TEST (ledger, pruning_action)
auto send1_stored (store->block.get (transaction, send1->hash ()));
ASSERT_NE (nullptr, send1_stored);
ASSERT_EQ (*send1, *send1_stored);
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
auto send2 = builder
.state ()
.account (nano::dev::genesis_key.pub)
Expand All @@ -4871,7 +4871,7 @@ TEST (ledger, pruning_action)
// Pruning action
ASSERT_EQ (1, ledger.pruning_action (transaction, send1->hash (), 1));
ASSERT_EQ (0, ledger.pruning_action (transaction, nano::dev::genesis->hash (), 1));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_FALSE (store->block.exists (transaction, send1->hash ()));
ASSERT_TRUE (ledger.block_or_pruned_exists (transaction, send1->hash ()));
// Pruned ledger start without proper flags emulation
Expand All @@ -4897,7 +4897,7 @@ TEST (ledger, pruning_action)
auto receive1_stored (store->block.get (transaction, receive1->hash ()));
ASSERT_NE (nullptr, receive1_stored);
ASSERT_EQ (*receive1, *receive1_stored);
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (4, receive1_stored->sideband ().height);
ASSERT_FALSE (receive1_stored->is_send ());
ASSERT_TRUE (receive1_stored->is_receive ());
Expand Down Expand Up @@ -5001,7 +5001,7 @@ TEST (ledger, pruning_source_rollback)
.work (*pool.generate (epoch1->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
auto send2 = builder
.state ()
.account (nano::dev::genesis_key.pub)
Expand Down Expand Up @@ -5038,7 +5038,7 @@ TEST (ledger, pruning_source_rollback)
.work (*pool.generate (send2->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (5, ledger.cache.block_count);
// Rollback receive block
Expand All @@ -5050,7 +5050,7 @@ TEST (ledger, pruning_source_rollback)
ASSERT_EQ (nano::epoch::epoch_1, info2->epoch);
// Process receive block again
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (5, ledger.cache.block_count);
}
Expand All @@ -5076,7 +5076,7 @@ TEST (ledger, pruning_source_rollback_legacy)
.work (*pool.generate (nano::dev::genesis->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
nano::keypair key1;
auto send2 = builder
.send ()
Expand All @@ -5088,7 +5088,7 @@ TEST (ledger, pruning_source_rollback_legacy)
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send2));
ASSERT_TRUE (store->block.exists (transaction, send2->hash ()));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (key1.pub, send2->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () }));
auto send3 = builder
.send ()
.previous (send2->hash ())
Expand All @@ -5099,7 +5099,7 @@ TEST (ledger, pruning_source_rollback_legacy)
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send3));
ASSERT_TRUE (store->block.exists (transaction, send3->hash ()));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send3->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send3->hash () }));
// Pruning action
ASSERT_EQ (2, ledger.pruning_action (transaction, send2->hash (), 1));
ASSERT_FALSE (store->block.exists (transaction, send2->hash ()));
Expand All @@ -5126,7 +5126,7 @@ TEST (ledger, pruning_source_rollback_legacy)
.work (*pool.generate (send3->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (5, ledger.cache.block_count);
// Rollback receive block
Expand All @@ -5138,7 +5138,7 @@ TEST (ledger, pruning_source_rollback_legacy)
ASSERT_EQ (nano::epoch::epoch_0, info3->epoch);
// Process receive block again
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, receive1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (5, ledger.cache.block_count);
// Receiving pruned block (open)
Expand All @@ -5151,7 +5151,7 @@ TEST (ledger, pruning_source_rollback_legacy)
.work (*pool.generate (key1.pub))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (key1.pub, send2->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (6, ledger.cache.block_count);
// Rollback open block
Expand All @@ -5163,7 +5163,7 @@ TEST (ledger, pruning_source_rollback_legacy)
ASSERT_EQ (nano::epoch::epoch_0, info4->epoch);
// Process open block again
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open1));
ASSERT_FALSE (store->pending.exists (transaction, nano::pending_key (key1.pub, send2->hash ())));
ASSERT_FALSE (ledger.pending_info (transaction, nano::pending_key{ key1.pub, send2->hash () }));
ASSERT_EQ (2, ledger.cache.pruned_count);
ASSERT_EQ (6, ledger.cache.block_count);
}
Expand Down Expand Up @@ -5237,7 +5237,7 @@ TEST (ledger, pruning_legacy_blocks)
.work (*pool.generate (nano::dev::genesis->hash ()))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, send1));
ASSERT_TRUE (store->pending.exists (transaction, nano::pending_key (nano::dev::genesis_key.pub, send1->hash ())));
ASSERT_TRUE (ledger.pending_info (transaction, nano::pending_key{ nano::dev::genesis_key.pub, send1->hash () }));
auto receive1 = builder
.receive ()
.previous (send1->hash ())
Expand Down
8 changes: 4 additions & 4 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ uint64_t nano::json_handler::difficulty_ledger (nano::block const & block_a)
{
auto block_link = node.ledger.block (transaction, link.value ().as_block_hash ());
auto account = block_a.account_field ().value (); // Link is non-zero therefore it's a state block and has an account field;
if (block_link != nullptr && node.store.pending.exists (transaction, nano::pending_key (account, link.value ().as_block_hash ())))
if (block_link != nullptr && node.ledger.pending_info (transaction, nano::pending_key{ account, link.value ().as_block_hash () }))
{
details.epoch = std::max (details.epoch, block_link->sideband ().details.epoch);
details.is_receive = true;
Expand Down Expand Up @@ -1353,7 +1353,7 @@ void nano::json_handler::blocks_info ()
entry.put ("receive_hash", nano::block_hash (0).to_string ());
}
}
else if (node.store.pending.exists (transaction, nano::pending_key (block->destination (), hash)))
else if (node.ledger.pending_info (transaction, nano::pending_key{ block->destination (), hash }))
{
if (receivable)
{
Expand Down Expand Up @@ -3162,7 +3162,7 @@ void nano::json_handler::receivable_exists ()
auto exists (false);
if (block->is_send ())
{
exists = node.store.pending.exists (transaction, nano::pending_key (block->destination (), hash));
exists = node.ledger.pending_info (transaction, nano::pending_key{ block->destination (), hash }).has_value ();
}
exists = exists && (block_confirmed (node, transaction, block->hash (), include_active, include_only_confirmed));
response_l.put ("exists", exists ? "1" : "0");
Expand Down Expand Up @@ -3667,7 +3667,7 @@ void nano::json_handler::republish ()
auto destination = block_b->destination ();
if (!destination.is_zero ())
{
if (!node.store.pending.exists (transaction, nano::pending_key (destination, hash)))
if (!node.ledger.pending_info (transaction, nano::pending_key{ destination, hash }))
{
nano::block_hash previous (node.ledger.latest (transaction, destination));
auto block_d = node.ledger.block (transaction, previous);
Expand Down
4 changes: 2 additions & 2 deletions nano/qt/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2322,7 +2322,7 @@ void nano_qt::block_creation::create_receive ()
if (!destination.is_zero ())
{
nano::pending_key pending_key (destination, source_l);
if (auto pending = wallet.node.store.pending.get (block_transaction, pending_key))
if (auto pending = wallet.node.ledger.pending_info (block_transaction, pending_key))
{
nano::account_info info;
auto error (wallet.node.store.account.get (block_transaction, pending_key.account, info));
Expand Down Expand Up @@ -2486,7 +2486,7 @@ void nano_qt::block_creation::create_open ()
if (!destination.is_zero ())
{
nano::pending_key pending_key (destination, source_l);
if (auto pending = wallet.node.store.pending.get (block_transaction, pending_key))
if (auto pending = wallet.node.ledger.pending_info (block_transaction, pending_key))
{
nano::account_info info;
auto error (wallet.node.store.account.get (block_transaction, pending_key.account, info));
Expand Down
2 changes: 1 addition & 1 deletion nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ TEST (rpc, pending_exists)
request.put ("hash", hash0.to_string ());
ASSERT_TRUE (pending_exists ("0"));

node->store.pending.exists (node->store.tx_begin_read (), nano::pending_key (nano::dev::genesis_key.pub, block1->hash ()));
node->ledger.pending_info (node->store.tx_begin_read (), nano::pending_key{ nano::dev::genesis_key.pub, block1->hash () });
request.put ("hash", block1->hash ().to_string ());
ASSERT_TRUE (pending_exists ("1"));

Expand Down
2 changes: 1 addition & 1 deletion nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class rollback_visitor : public nano::block_visitor
if (is_send)
{
nano::pending_key key (block_a.hashables.link.as_account (), hash);
while (!error && !ledger.store.pending.exists (transaction, key))
while (!error && !ledger.pending_info (transaction, key))
{
error = ledger.rollback (transaction, ledger.latest (transaction, block_a.hashables.link.as_account ()), list);
}
Expand Down

0 comments on commit b0fe9b3

Please sign in to comment.