Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ledger confirmed_set/any_set classes to separate confirmed-only and confirmed/unconfirmed operations on the ledger #4486

Merged
merged 19 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
f49ef4e
Creating ledger set classes for confirmed/any
clemahieu Mar 10, 2024
5ae8674
Move ledger::account_info on to ledger sets
clemahieu Mar 12, 2024
c3f09c1
Replace ledger::block_confirmed with equivalent queries if the block …
clemahieu Mar 11, 2024
174c37e
Remove ledger::block_exists and replace usages with ledger set exists
clemahieu Mar 11, 2024
fb68988
Removing ledger::block and replacing callers with ledger set get.
clemahieu Mar 11, 2024
062cbff
Move ledger::balance on to ledger sets.
clemahieu Mar 11, 2024
cafaadf
Move ledger::latest on to ledger set head
clemahieu Mar 11, 2024
fb06e4e
Removing ledger::head_block and replacing with using ledger set calls.
clemahieu Mar 11, 2024
a670fa1
Moving ledger::account on to ledger sets
clemahieu Mar 11, 2024
01e73d7
Move ledger::amount on to ledger sets.
clemahieu Mar 11, 2024
8ce6e4a
Move ledger::height on to ledger sets.
clemahieu Mar 11, 2024
0b47ae0
Move ledger::account_balance to ledger set balance
clemahieu Mar 11, 2024
a48adc2
Move ledger::pending_info on to ledger set get
clemahieu Mar 12, 2024
69a872a
Move ledger::successor on to ledger set successor
clemahieu Mar 12, 2024
1455d49
Move ledger receivable functions on to ledger set.
clemahieu Mar 17, 2024
82527f4
Move ledger::receivable_any on to ledger set receivable_exists
clemahieu Mar 18, 2024
9512140
Rewrite optimistic scheduler in terms of ledger sets and add ledger s…
clemahieu Mar 21, 2024
433f341
Rewrite priority scheduler in terms of ledger sets.
clemahieu Mar 21, 2024
0853108
Add ledger account iterator for the unconfirmed ledger set.
clemahieu Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <nano/node/scheduler/priority.hpp>
#include <nano/node/transport/inproc.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_any.hpp>
#include <nano/secure/ledger_set_confirmed.hpp>
#include <nano/test_common/chains.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand Down Expand Up @@ -253,7 +255,7 @@ TEST (inactive_votes_cache, basic)
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 1);
node.process_active (send);
ASSERT_TIMELY (5s, node.ledger.block_confirmed (node.ledger.tx_begin_read (), send->hash ()));
ASSERT_TIMELY (5s, node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), send->hash ()));
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

Expand Down Expand Up @@ -1014,7 +1016,7 @@ TEST (active_transactions, confirmation_consistency)
auto block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, nano::public_key (), node.config.receive_minimum.number ()));
ASSERT_NE (nullptr, block);
system.deadline_set (5s);
while (!node.ledger.block_confirmed (node.ledger.tx_begin_read (), block->hash ()))
while (!node.ledger.confirmed.block_exists_or_pruned (node.ledger.tx_begin_read (), block->hash ()))
{
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
ASSERT_NO_ERROR (system.poll (5ms));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/backlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST (backlog, population)
nano::test::system system{};
auto & node = *system.add_node ();

node.backlog.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account, nano::account_info const & account_info, nano::confirmation_height_info const & conf_info) {
node.backlog.activate_callback.add ([&] (nano::secure::transaction const & transaction, nano::account const & account) {
nano::lock_guard<nano::mutex> lock{ mutex };

activated.insert (account);
Expand Down
25 changes: 13 additions & 12 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <nano/node/make_store.hpp>
#include <nano/secure/common.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_any.hpp>
#include <nano/secure/utility.hpp>
#include <nano/store/account.hpp>
#include <nano/store/block.hpp>
Expand Down Expand Up @@ -1116,29 +1117,29 @@ TEST (mdb_block_store, sideband_height)
.work (*pool.generate (key3.pub))
.build ();
ASSERT_EQ (nano::block_status::progress, ledger.process (transaction, open));
auto block1 = ledger.block (transaction, nano::dev::genesis->hash ());
auto block1 = ledger.any.block_get (transaction, nano::dev::genesis->hash ());
ASSERT_EQ (block1->sideband ().height, 1);
auto block2 = ledger.block (transaction, send->hash ());
auto block2 = ledger.any.block_get (transaction, send->hash ());
ASSERT_EQ (block2->sideband ().height, 2);
auto block3 = ledger.block (transaction, receive->hash ());
auto block3 = ledger.any.block_get (transaction, receive->hash ());
ASSERT_EQ (block3->sideband ().height, 3);
auto block4 = ledger.block (transaction, change->hash ());
auto block4 = ledger.any.block_get (transaction, change->hash ());
ASSERT_EQ (block4->sideband ().height, 4);
auto block5 = ledger.block (transaction, state_send1->hash ());
auto block5 = ledger.any.block_get (transaction, state_send1->hash ());
ASSERT_EQ (block5->sideband ().height, 5);
auto block6 = ledger.block (transaction, state_send2->hash ());
auto block6 = ledger.any.block_get (transaction, state_send2->hash ());
ASSERT_EQ (block6->sideband ().height, 6);
auto block7 = ledger.block (transaction, state_send3->hash ());
auto block7 = ledger.any.block_get (transaction, state_send3->hash ());
ASSERT_EQ (block7->sideband ().height, 7);
auto block8 = ledger.block (transaction, state_open->hash ());
auto block8 = ledger.any.block_get (transaction, state_open->hash ());
ASSERT_EQ (block8->sideband ().height, 1);
auto block9 = ledger.block (transaction, epoch->hash ());
auto block9 = ledger.any.block_get (transaction, epoch->hash ());
ASSERT_EQ (block9->sideband ().height, 2);
auto block10 = ledger.block (transaction, epoch_open->hash ());
auto block10 = ledger.any.block_get (transaction, epoch_open->hash ());
ASSERT_EQ (block10->sideband ().height, 1);
auto block11 = ledger.block (transaction, state_receive->hash ());
auto block11 = ledger.any.block_get (transaction, state_receive->hash ());
ASSERT_EQ (block11->sideband ().height, 2);
auto block12 = ledger.block (transaction, open->hash ());
auto block12 = ledger.any.block_get (transaction, open->hash ());
ASSERT_EQ (block12->sideband ().height, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ TEST (block_processor, broadcast_block_on_arrival)
// awakes process_block() -> process_batch() -> process_one() -> process_live()
node1->process_active (send1);
// Checks whether the block was broadcast.
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send1->hash ()));
}
23 changes: 12 additions & 11 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nano/node/bootstrap/bootstrap_frontier.hpp>
#include <nano/node/bootstrap/bootstrap_lazy.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_any.hpp>
#include <nano/test_common/network.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand Down Expand Up @@ -655,13 +656,13 @@ TEST (bootstrap_processor, push_diamond_pruning)
node1->ledger.confirm (transaction, open->hash ());
ASSERT_EQ (1, node1->ledger.pruning_action (transaction, send1->hash (), 2));
ASSERT_EQ (1, node1->ledger.pruning_action (transaction, open->hash (), 1));
ASSERT_TRUE (node1->ledger.block_exists (transaction, nano::dev::genesis->hash ()));
ASSERT_FALSE (node1->ledger.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1->ledger.any.block_exists (transaction, nano::dev::genesis->hash ()));
ASSERT_FALSE (node1->ledger.any.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1->store.pruned.exists (transaction, send1->hash ()));
ASSERT_FALSE (node1->ledger.block_exists (transaction, open->hash ()));
ASSERT_FALSE (node1->ledger.any.block_exists (transaction, open->hash ()));
ASSERT_TRUE (node1->store.pruned.exists (transaction, open->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1->ledger.block_exists (transaction, receive->hash ()));
ASSERT_TRUE (node1->ledger.any.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1->ledger.any.block_exists (transaction, receive->hash ()));
ASSERT_EQ (2, node1->ledger.pruned_count ());
ASSERT_EQ (5, node1->ledger.block_count ());
}
Expand Down Expand Up @@ -1293,10 +1294,10 @@ TEST (bootstrap_processor, lazy_destinations)

// Check processed blocks
ASSERT_TIMELY (5s, !node2->bootstrap_initiator.in_progress ());
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send1->hash ()));
ASSERT_TIMELY (5s, node2->ledger.block_or_pruned_exists (send2->hash ()));
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (open->hash ()));
ASSERT_FALSE (node2->ledger.block_or_pruned_exists (state_open->hash ()));
ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send1->hash ()));
ASSERT_TIMELY (5s, node2->block_or_pruned_exists (send2->hash ()));
ASSERT_FALSE (node2->block_or_pruned_exists (open->hash ()));
ASSERT_FALSE (node2->block_or_pruned_exists (state_open->hash ()));
}

TEST (bootstrap_processor, lazy_pruning_missing_block)
Expand Down Expand Up @@ -1517,7 +1518,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier)
ASSERT_EQ (key2.pub.to_account (), wallet_attempt->id);
}
// Check processed blocks
ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (receive2->hash ()));
ASSERT_TIMELY (10s, node1->block_or_pruned_exists (receive2->hash ()));
}

TEST (bootstrap_processor, wallet_lazy_pending)
Expand Down Expand Up @@ -1581,7 +1582,7 @@ TEST (bootstrap_processor, wallet_lazy_pending)
wallet->insert_adhoc (key2.prv);
node1->bootstrap_wallet ();
// Check processed blocks
ASSERT_TIMELY (10s, node1->ledger.block_or_pruned_exists (send2->hash ()));
ASSERT_TIMELY (10s, node1->block_or_pruned_exists (send2->hash ()));
}

TEST (bootstrap_processor, multiple_attempts)
Expand Down
3 changes: 2 additions & 1 deletion nano/core_test/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <nano/node/bootstrap_ascending/service.hpp>
#include <nano/node/make_store.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_any.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>

Expand Down Expand Up @@ -252,7 +253,7 @@ TEST (bootstrap_ascending, trace_base)
// std::cerr << "--------------- Start ---------------\n";
ASSERT_EQ (nano::block_status::progress, node0.process (send1));
ASSERT_EQ (nano::block_status::progress, node0.process (receive1));
ASSERT_EQ (node1.ledger.receivable_end (), node1.ledger.receivable_upper_bound (node1.ledger.tx_begin_read (), key.pub, 0));
ASSERT_EQ (node1.ledger.any.receivable_end (), node1.ledger.any.receivable_upper_bound (node1.ledger.tx_begin_read (), key.pub, 0));
// std::cerr << "node0: " << node0.network.endpoint () << std::endl;
// std::cerr << "node1: " << node1.network.endpoint () << std::endl;
ASSERT_TIMELY (10s, node1.block (receive1->hash ()) != nullptr);
Expand Down
5 changes: 3 additions & 2 deletions nano/core_test/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <nano/node/election.hpp>
#include <nano/node/make_store.hpp>
#include <nano/secure/ledger.hpp>
#include <nano/secure/ledger_set_confirmed.hpp>
#include <nano/test_common/ledger.hpp>
#include <nano/test_common/system.hpp>
#include <nano/test_common/testutil.hpp>
Expand Down Expand Up @@ -160,7 +161,7 @@ TEST (confirmation_callback, confirmed_history)
ASSERT_TRUE (node->active.empty ());

auto transaction = node->ledger.tx_begin_read ();
ASSERT_FALSE (node->ledger.block_confirmed (transaction, send->hash ()));
ASSERT_FALSE (node->ledger.confirmed.block_exists (transaction, send->hash ()));

ASSERT_TIMELY (10s, node->store.write_queue.contains (nano::store::writer::confirmation_height));

Expand All @@ -171,7 +172,7 @@ TEST (confirmation_callback, confirmed_history)
ASSERT_TIMELY (10s, !node->store.write_queue.contains (nano::store::writer::confirmation_height));

auto transaction = node->ledger.tx_begin_read ();
ASSERT_TRUE (node->ledger.block_confirmed (transaction, send->hash ()));
ASSERT_TRUE (node->ledger.confirmed.block_exists (transaction, send->hash ()));

ASSERT_TIMELY_EQ (10s, node->active.size (), 0);
ASSERT_TIMELY_EQ (10s, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out), 1);
Expand Down
Loading
Loading