Skip to content

Commit

Permalink
Creating nano::secure::transaction type which is used by nano::ledger…
Browse files Browse the repository at this point in the history
… and can be expanded to include memory locking. (#4543)
  • Loading branch information
clemahieu authored Apr 16, 2024
1 parent e9eaaef commit 6596cef
Show file tree
Hide file tree
Showing 71 changed files with 771 additions and 623 deletions.
28 changes: 14 additions & 14 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,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.store.tx_begin_read (), send->hash ()));
ASSERT_TIMELY (5s, node.ledger.block_confirmed (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 @@ -430,7 +430,7 @@ TEST (inactive_votes_cache, multiple_votes)

ASSERT_TIMELY_EQ (5s, node.vote_cache.find (send1->hash ()).size (), 2);
ASSERT_EQ (1, node.vote_cache.size ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
std::shared_ptr<nano::election> election;
ASSERT_TIMELY (5s, election = node.active.election (send1->qualified_root ()));
ASSERT_EQ (3, election->votes ().size ()); // 2 votes and 1 default not_an_acount
Expand Down Expand Up @@ -534,7 +534,7 @@ TEST (inactive_votes_cache, election_start)
// An election is started for send6 but does not
ASSERT_FALSE (node.block_confirmed_or_being_confirmed (send3->hash ()));
// send7 cannot be voted on but an election should be started from inactive votes
ASSERT_FALSE (node.ledger.dependents_confirmed (node.store.tx_begin_read (), *send4));
ASSERT_FALSE (node.ledger.dependents_confirmed (node.ledger.tx_begin_read (), *send4));
node.process_active (send4);
ASSERT_TIMELY_EQ (5s, 7, node.ledger.cemented_count ());
}
Expand Down Expand Up @@ -1016,9 +1016,9 @@ 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.store.tx_begin_read (), block->hash ()))
while (!node.ledger.block_confirmed (node.ledger.tx_begin_read (), block->hash ()))
{
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
ASSERT_NO_ERROR (system.poll (5ms));
}
ASSERT_NO_ERROR (system.poll_until_true (1s, [&node, &block, i] {
Expand Down Expand Up @@ -1159,19 +1159,19 @@ TEST (active_transactions, activate_account_chain)
ASSERT_EQ (nano::block_status::progress, node.process (open));
ASSERT_EQ (nano::block_status::progress, node.process (receive));

node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
ASSERT_TIMELY (5s, node.active.election (send->qualified_root ()));
auto election1 = node.active.election (send->qualified_root ());
ASSERT_EQ (1, node.active.size ());
ASSERT_EQ (1, election1->blocks ().count (send->hash ()));
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
auto election2 = node.active.election (send->qualified_root ());
ASSERT_EQ (election2, election1);
election1->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (send->hash ()));
// On cementing, the next election is started
ASSERT_TIMELY (3s, node.active.active (send2->qualified_root ()));
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
auto election3 = node.active.election (send2->qualified_root ());
ASSERT_NE (nullptr, election3);
ASSERT_EQ (1, election3->blocks ().count (send2->hash ()));
Expand All @@ -1180,19 +1180,19 @@ TEST (active_transactions, activate_account_chain)
// On cementing, the next election is started
ASSERT_TIMELY (3s, node.active.active (open->qualified_root ()));
ASSERT_TIMELY (3s, node.active.active (send3->qualified_root ()));
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
auto election4 = node.active.election (send3->qualified_root ());
ASSERT_NE (nullptr, election4);
ASSERT_EQ (1, election4->blocks ().count (send3->hash ()));
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ());
auto election5 = node.active.election (open->qualified_root ());
ASSERT_NE (nullptr, election5);
ASSERT_EQ (1, election5->blocks ().count (open->hash ()));
election5->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (open->hash ()));
// Until send3 is also confirmed, the receive block should not activate
std::this_thread::sleep_for (200ms);
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ());
election4->force_confirm ();
ASSERT_TIMELY (3s, node.block_confirmed (send3->hash ()));
ASSERT_TIMELY (3s, node.active.active (receive->qualified_root ()));
Expand Down Expand Up @@ -1333,7 +1333,7 @@ TEST (active_transactions, vacancy)
ASSERT_EQ (nano::block_status::progress, node.process (send));
ASSERT_EQ (1, node.active.vacancy ());
ASSERT_EQ (0, node.active.size ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
ASSERT_TIMELY (1s, updated);
updated = false;
ASSERT_EQ (0, node.active.vacancy ());
Expand Down Expand Up @@ -1523,7 +1523,7 @@ TEST (active_transactions, allow_limited_overflow)
// Insert the first part of the blocks into normal election scheduler
for (auto const & block : blocks1)
{
node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ());
node.scheduler.priority.activate (block->account (), node.ledger.tx_begin_read ());
}

// Ensure number of active elections reaches AEC limit and there is no overfill
Expand Down Expand Up @@ -1585,7 +1585,7 @@ TEST (active_transactions, allow_limited_overflow_adapt)
// Insert the first part of the blocks into normal election scheduler
for (auto const & block : blocks1)
{
node.scheduler.priority.activate (block->account (), node.store.tx_begin_read ());
node.scheduler.priority.activate (block->account (), node.ledger.tx_begin_read ());
}

// Ensure number of active elections reaches AEC limit and there is no overfill
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::store::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::account_info const & account_info, nano::confirmation_height_info const & conf_info) {
nano::lock_guard<nano::mutex> lock{ mutex };

activated.insert (account);
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ TEST (mdb_block_store, sideband_height)
nano::stats stats;
nano::ledger ledger (store, stats, nano::dev::constants);
nano::block_builder builder;
auto transaction (store.tx_begin_write ());
auto transaction = ledger.tx_begin_write ();
store.initialize (transaction, ledger.cache, nano::dev::constants);
nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
auto send = builder
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ TEST (bootstrap_processor, push_diamond_pruning)
ASSERT_EQ (nano::block_status::progress, node1->process (receive));

{
auto transaction (node1->store.tx_begin_write ());
auto transaction = node1->ledger.tx_begin_write ();
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));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/bootstrap_ascending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,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.store.tx_begin_read (), key.pub, 0));
ASSERT_EQ (node1.ledger.receivable_end (), node1.ledger.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
10 changes: 5 additions & 5 deletions nano/core_test/confirming_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TEST (confirmation_callback, observer_callbacks)
.build ();

{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1));
}
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST (confirmation_callback, confirmed_history)
.work (*system.work.generate (latest))
.build ();
{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
}

Expand All @@ -159,7 +159,7 @@ TEST (confirmation_callback, confirmed_history)
ASSERT_EQ (0, node->active.recently_cemented.list ().size ());
ASSERT_TRUE (node->active.empty ());

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

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

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

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

ASSERT_TIMELY_EQ (10s, node->active.size (), 0);
Expand Down Expand Up @@ -226,7 +226,7 @@ TEST (confirmation_callback, dependent_election)
.work (*system.work.generate (send1->hash ()))
.build ();
{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send1));
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send2));
Expand Down
4 changes: 2 additions & 2 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST (conflicts, start_stop)
node1.work_generate_blocking (*send1);
ASSERT_EQ (nano::block_status::progress, node1.process (send1));
ASSERT_EQ (0, node1.active.size ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election1 = node1.active.election (send1->qualified_root ());
ASSERT_EQ (1, node1.active.size ());
Expand Down Expand Up @@ -64,7 +64,7 @@ TEST (conflicts, add_existing)
ASSERT_TIMELY (5s, node1.block (send1->hash ()));

// instruct the election scheduler to trigger an election for send1
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ());

// wait for election to be started before processing send2
ASSERT_TIMELY (5s, node1.active.active (*send1));
Expand Down
2 changes: 1 addition & 1 deletion nano/core_test/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST (election, quorum_minimum_confirm_success)
.build ();
node1.work_generate_blocking (*send1);
node1.process_active (send1);
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.store.tx_begin_read ());
node1.scheduler.priority.activate (nano::dev::genesis_key.pub, node1.ledger.tx_begin_read ());
ASSERT_TIMELY (5s, node1.active.election (send1->qualified_root ()));
auto election = node1.active.election (send1->qualified_root ());
ASSERT_NE (nullptr, election);
Expand Down
12 changes: 6 additions & 6 deletions nano/core_test/election_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ TEST (election_scheduler, activate_one_timely)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
system.nodes[0]->ledger.process (system.nodes[0]->ledger.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->ledger.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
}

Expand All @@ -49,8 +49,8 @@ TEST (election_scheduler, activate_one_flush)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build ();
system.nodes[0]->ledger.process (system.nodes[0]->store.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->store.tx_begin_read ());
system.nodes[0]->ledger.process (system.nodes[0]->ledger.tx_begin_write (), send1);
system.nodes[0]->scheduler.priority.activate (nano::dev::genesis_key.pub, system.nodes[0]->ledger.tx_begin_read ());
ASSERT_TIMELY (5s, system.nodes[0]->active.election (send1->qualified_root ()));
}

Expand Down Expand Up @@ -119,7 +119,7 @@ TEST (election_scheduler, no_vacancy)
ASSERT_EQ (nano::block_status::progress, node.process (block1));

// There is vacancy so it should be inserted
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (nano::dev::genesis_key.pub, node.ledger.tx_begin_read ());
std::shared_ptr<nano::election> election{};
ASSERT_TIMELY (5s, (election = node.active.election (block1->qualified_root ())) != nullptr);

Expand All @@ -135,7 +135,7 @@ TEST (election_scheduler, no_vacancy)
ASSERT_EQ (nano::block_status::progress, node.process (block2));

// There is no vacancy so it should stay queued
node.scheduler.priority.activate (key.pub, node.store.tx_begin_read ());
node.scheduler.priority.activate (key.pub, node.ledger.tx_begin_read ());
ASSERT_TIMELY_EQ (5s, node.scheduler.priority.size (), 1);
ASSERT_EQ (node.active.election (block2->qualified_root ()), nullptr);

Expand Down
6 changes: 3 additions & 3 deletions nano/core_test/frontiers_confirmation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST (frontiers_confirmation, mode)
.work (*node->work_generate_blocking (nano::dev::genesis->hash ()))
.build ();
{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
}
ASSERT_TIMELY_EQ (5s, node->active.size (), 1);
Expand All @@ -52,7 +52,7 @@ TEST (frontiers_confirmation, mode)
.work (*node->work_generate_blocking (nano::dev::genesis->hash ()))
.build ();
{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
}
ASSERT_TIMELY_EQ (5s, node->active.size (), 1);
Expand All @@ -74,7 +74,7 @@ TEST (frontiers_confirmation, mode)
.work (*node->work_generate_blocking (nano::dev::genesis->hash ()))
.build ();
{
auto transaction = node->store.tx_begin_write ();
auto transaction = node->ledger.tx_begin_write ();
ASSERT_EQ (nano::block_status::progress, node->ledger.process (transaction, send));
}
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
Expand Down
Loading

0 comments on commit 6596cef

Please sign in to comment.