Skip to content

Commit

Permalink
Merge branch 'develop' into block_pipeline2
Browse files Browse the repository at this point in the history
  • Loading branch information
clemahieu committed Feb 8, 2023
2 parents 2d5ba7a + 997e1f9 commit 35e81c8
Show file tree
Hide file tree
Showing 46 changed files with 1,020 additions and 1,253 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

windows_test:
name: Windows Unit Tests [TEST_USE_ROCKSDB=${{ matrix.TEST_USE_ROCKSDB }}]
timeout-minutes: 120
timeout-minutes: 150
strategy:
fail-fast: false
matrix:
Expand Down
38 changes: 19 additions & 19 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,33 @@ TEST (active_transactions, inactive_votes_cache)
ASSERT_EQ (1, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached));
}

/**
* This test case confirms that a non final vote cannot cause an election to become confirmed
*/
TEST (active_transactions, inactive_votes_cache_non_final)
{
nano::test::system system (1);
auto & node = *system.nodes[0];
nano::block_hash latest (node.latest (nano::dev::genesis_key.pub));
nano::keypair key;

auto send = nano::send_block_builder ()
.previous (latest)
.destination (key.pub)
.previous (nano::dev::genesis->hash ())
.destination (nano::keypair{}.pub)
.balance (nano::dev::constants.genesis_amount - 100)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.work (*system.work.generate (latest))
.work (*system.work.generate (nano::dev::genesis->hash ()))
.build_shared ();
auto vote (std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send->hash ()))); // Non-final vote

// Non-final vote
auto vote = std::make_shared<nano::vote> (nano::dev::genesis_key.pub, nano::dev::genesis_key.prv, 0, 0, std::vector<nano::block_hash> (1, send->hash ()));
node.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY (5s, node.inactive_vote_cache.cache_size () == 1);

node.process_active (send);
node.block_processor.flush ();
ASSERT_TIMELY (5s, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached) == 1);
auto election = node.active.election (send->qualified_root ());
ASSERT_NE (nullptr, election);
std::shared_ptr<nano::election> election;
ASSERT_TIMELY (5s, election = node.active.election (send->qualified_root ()));
ASSERT_TIMELY_EQ (5s, node.stats.count (nano::stat::type::election, nano::stat::detail::vote_cached), 1);
ASSERT_TIMELY_EQ (5s, nano::dev::constants.genesis_amount - 100, election->tally ().begin ()->first);
ASSERT_FALSE (election->confirmed ());
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, election->tally ().begin ()->first);
}

TEST (active_transactions, inactive_votes_cache_fork)
Expand Down Expand Up @@ -628,9 +632,7 @@ TEST (active_transactions, dropped_cleanup)
ASSERT_FALSE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));

node.block_confirm (nano::dev::genesis);
ASSERT_TIMELY (5s, node.active.election (nano::dev::genesis->qualified_root ()));
auto election = node.active.election (nano::dev::genesis->qualified_root ());
auto election = nano::test::start_election (system, node, nano::dev::genesis);
ASSERT_NE (nullptr, election);

// Not yet removed
Expand All @@ -652,9 +654,8 @@ TEST (active_transactions, dropped_cleanup)

// Repeat test for a confirmed election
ASSERT_TRUE (node.network.publish_filter.apply (block_bytes.data (), block_bytes.size ()));
node.block_confirm (nano::dev::genesis);
ASSERT_TIMELY (5s, node.active.election (nano::dev::genesis->qualified_root ()));
election = node.active.election (nano::dev::genesis->qualified_root ());

election = nano::test::start_election (system, node, nano::dev::genesis);
ASSERT_NE (nullptr, election);
election->force_confirm ();
ASSERT_TRUE (election->confirmed ());
Expand Down Expand Up @@ -1220,8 +1221,7 @@ TEST (active_transactions, activate_inactive)
ASSERT_EQ (nano::process_result::progress, node.process (*send2).code);
ASSERT_EQ (nano::process_result::progress, node.process (*open).code);

node.block_confirm (send2);
auto election = node.active.election (send2->qualified_root ());
auto election = nano::test::start_election (system, node, send2);
ASSERT_NE (nullptr, election);
election->force_confirm ();

Expand Down
18 changes: 9 additions & 9 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ TEST (bootstrap_processor, lazy_hash_pruning)
node0->block_processor.add (receive2);
node0->block_processor.add (send3);
node0->block_processor.add (receive3);
ASSERT_TIMELY (1s, 9 == node0->ledger.cache.block_count);
ASSERT_TIMELY_EQ (5s, 9, node0->ledger.cache.block_count);
// Processing chain to prune for node1
config.peering_port = nano::test::get_available_port ();
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), config, system.work, node_flags, 1));
Expand All @@ -937,10 +937,10 @@ TEST (bootstrap_processor, lazy_hash_pruning)
node1->process_active (receive1);
node1->process_active (change1);
node1->process_active (change2);
ASSERT_TIMELY (1s, node1->block (change2->hash ()) != nullptr);
ASSERT_TIMELY (5s, node1->block (change2->hash ()) != nullptr);
// Confirm last block to prune previous
nano::test::blocks_confirm (*node1, { send1, receive1, change1, change2 }, true);
ASSERT_TIMELY (10s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()) && node1->block_confirmed (change1->hash ()) && node1->block_confirmed (change2->hash ()) && node1->active.empty ());
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (receive1->hash ()) && node1->block_confirmed (change1->hash ()) && node1->block_confirmed (change2->hash ()) && node1->active.empty ());
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
// Pruning action
Expand All @@ -953,9 +953,9 @@ TEST (bootstrap_processor, lazy_hash_pruning)
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (receive3->hash (), true);
// Check processed blocks
ASSERT_TIMELY (10s, node1->ledger.cache.block_count == 9);
ASSERT_TIMELY (10s, node1->balance (key2.pub) != 0);
ASSERT_TIMELY (10s, !node1->bootstrap_initiator.in_progress ());
ASSERT_TIMELY (5s, node1->ledger.cache.block_count == 9);
ASSERT_TIMELY (5s, node1->balance (key2.pub) != 0);
ASSERT_TIMELY (5s, !node1->bootstrap_initiator.in_progress ());
node1->stop ();
}

Expand Down Expand Up @@ -1319,10 +1319,10 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
.build_shared ();

node1->process_active (state_open);
ASSERT_TIMELY (1s, node1->block (state_open->hash ()) != nullptr);
ASSERT_TIMELY (5s, node1->block (state_open->hash ()) != nullptr);
// Confirm last block to prune previous
nano::test::blocks_confirm (*node1, { send1, send2, open, state_open }, true);
ASSERT_TIMELY (10s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (send2->hash ()) && node1->block_confirmed (open->hash ()) && node1->block_confirmed (state_open->hash ()) && node1->active.empty ());
ASSERT_TIMELY (5s, node1->block_confirmed (send1->hash ()) && node1->block_confirmed (send2->hash ()) && node1->block_confirmed (open->hash ()) && node1->block_confirmed (state_open->hash ()) && node1->active.empty ());
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
// Pruning action
Expand Down Expand Up @@ -1356,7 +1356,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
// Insert missing block
node2->process_active (send1);
node2->block_processor.flush ();
ASSERT_TIMELY (10s, !node2->bootstrap_initiator.in_progress ());
ASSERT_TIMELY (5s, !node2->bootstrap_initiator.in_progress ());
node2->block_processor.flush ();
ASSERT_EQ (3, node2->ledger.cache.block_count);
ASSERT_TRUE (node2->ledger.block_or_pruned_exists (send1->hash ()));
Expand Down
46 changes: 18 additions & 28 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ TEST (confirmation_height, multiple_accounts)
.work (*system.work.generate (open3->hash ()))
.build_shared ();
node->process_active (receive3);
node->block_processor.flush ();
node->block_confirm (receive3);
auto election = node->active.election (receive3->qualified_root ());
auto election = nano::test::start_election (system, *node, receive3);
ASSERT_NE (nullptr, election);
election->force_confirm ();

Expand Down Expand Up @@ -386,7 +384,7 @@ TEST (confirmation_height, gap_bootstrap)
node1.block_processor.add (send2);
node1.block_processor.add (send3);
node1.block_processor.add (receive1);
ASSERT_TIMELY (1s, node1.block (send3->hash ()) != nullptr);
ASSERT_TIMELY (5s, node1.block (send3->hash ()) != nullptr);

add_callback_stats (node1);

Expand All @@ -396,7 +394,7 @@ TEST (confirmation_height, gap_bootstrap)
auto check_block_is_listed = [&] (nano::transaction const & transaction_a, nano::block_hash const & block_hash_a) {
return !node1.unchecked.get (transaction_a, block_hash_a).empty ();
};
ASSERT_TIMELY (15s, check_block_is_listed (node1.store.tx_begin_read (), receive2->previous ()));
ASSERT_TIMELY (5s, check_block_is_listed (node1.store.tx_begin_read (), receive2->previous ()));

// Confirmation heights should not be updated
{
Expand All @@ -413,7 +411,7 @@ TEST (confirmation_height, gap_bootstrap)
// Now complete the chain where the block comes in on the bootstrap network.
node1.block_processor.add (open1);

ASSERT_TIMELY (10s, node1.unchecked.count (node1.store.tx_begin_read ()) == 0);
ASSERT_TIMELY (5s, node1.unchecked.count (node1.store.tx_begin_read ()) == 0);
// Confirmation height should be unchanged and unchecked should now be 0
{
auto transaction = node1.store.tx_begin_read ();
Expand Down Expand Up @@ -536,7 +534,7 @@ TEST (confirmation_height, gap_live)
}

// Vote and confirm all existing blocks
node->block_confirm (send1);
nano::test::start_election (system, *node, send1);
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3);

// Now complete the chain where the block comes in on the live network
Expand Down Expand Up @@ -691,9 +689,7 @@ TEST (confirmation_height, send_receive_between_2_accounts)
add_callback_stats (*node);

node->process_active (receive4);
node->block_processor.flush ();
node->block_confirm (receive4);
auto election = node->active.election (receive4->qualified_root ());
auto election = nano::test::start_election (system, *node, receive4);
ASSERT_NE (nullptr, election);
election->force_confirm ();

Expand Down Expand Up @@ -810,12 +806,11 @@ TEST (confirmation_height, send_receive_self)

add_callback_stats (*node);

node->block_confirm (receive3);
auto election = node->active.election (receive3->qualified_root ());
auto election = nano::test::start_election (system, *node, receive3);
ASSERT_NE (nullptr, election);
election->force_confirm ();

ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);

auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->ledger.block_confirmed (transaction, receive3->hash ()));
Expand Down Expand Up @@ -1056,12 +1051,11 @@ TEST (confirmation_height, all_block_types)
}

add_callback_stats (*node);
node->block_confirm (state_send2);
auto election = node->active.election (state_send2->qualified_root ());
auto election = nano::test::start_election (system, *node, state_send2);
ASSERT_NE (nullptr, election);
election->force_confirm ();

ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 15);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 15);

auto transaction (node->store.tx_begin_read ());
ASSERT_TRUE (node->ledger.block_confirmed (transaction, state_send2->hash ()));
Expand Down Expand Up @@ -1553,8 +1547,7 @@ TEST (confirmation_height, callback_confirmed_history)
add_callback_stats (*node);

node->process_active (send1);
node->block_processor.flush ();
node->block_confirm (send1);
ASSERT_NE (nano::test::start_election (system, *node, send1), nullptr);
{
node->process_active (send);
node->block_processor.flush ();
Expand Down Expand Up @@ -1655,14 +1648,13 @@ TEST (confirmation_height, dependent_election)
add_callback_stats (*node);

// This election should be confirmed as active_conf_height
node->block_confirm (send1);
ASSERT_TRUE (nano::test::start_election (system, *node, send1));
// Start an election and confirm it
node->block_confirm (send2);
auto election = node->active.election (send2->qualified_root ());
auto election = nano::test::start_election (system, *node, send2);
ASSERT_NE (nullptr, election);
election->force_confirm ();

ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 3);

ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_quorum, nano::stat::dir::out));
ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::active_conf_height, nano::stat::dir::out));
Expand Down Expand Up @@ -1812,11 +1804,10 @@ TEST (confirmation_height, cemented_gap_below_receive)
nano::mutex mutex;
add_callback_stats (*node, &observer_order, &mutex);

node->block_confirm (open1);
auto election = node->active.election (open1->qualified_root ());
auto election = nano::test::start_election (system, *node, open1);
ASSERT_NE (nullptr, election);
election->force_confirm ();
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 10);

auto transaction = node->store.tx_begin_read ();
ASSERT_TRUE (node->ledger.block_confirmed (transaction, open1->hash ()));
Expand Down Expand Up @@ -1978,11 +1969,10 @@ TEST (confirmation_height, cemented_gap_below_no_cache)

add_callback_stats (*node);

node->block_confirm (open1);
auto election = node->active.election (open1->qualified_root ());
auto election = nano::test::start_election (system, *node, open1);
ASSERT_NE (nullptr, election);
election->force_confirm ();
ASSERT_TIMELY (10s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) == 6);

auto transaction = node->store.tx_begin_read ();
ASSERT_TRUE (node->ledger.block_confirmed (transaction, open1->hash ()));
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 @@ -212,7 +212,7 @@ TEST (election, quorum_minimum_update_weight_before_quorum_checks)
.work (*system.work.generate (latest))
.build_shared ();
node1.process_active (send1);
ASSERT_TIMELY (1s, node1.block (send1->hash ()) != nullptr);
ASSERT_TIMELY (5s, node1.block (send1->hash ()) != nullptr);

auto const open1 = nano::open_block_builder{}.make_block ().account (key1.pub).source (send1->hash ()).representative (key1.pub).sign (key1.prv, key1.pub).work (*system.work.generate (key1.pub)).build_shared ();
ASSERT_EQ (nano::process_result::progress, node1.process (*open1).code);
Expand Down
7 changes: 3 additions & 4 deletions nano/core_test/gap_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ TEST (gap_cache, gap_bootstrap)
ASSERT_EQ (nano::dev::constants.genesis_amount - 100, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
// Confirm send block, allowing voting on the upcoming block
node1.block_confirm (send);
auto election = node1.active.election (send->qualified_root ());
auto election = nano::test::start_election (system, node1, send);
ASSERT_NE (nullptr, election);
election->force_confirm ();
ASSERT_TIMELY (2s, node1.block_confirmed (send->hash ()));
ASSERT_TIMELY (5s, node1.block_confirmed (send->hash ()));
node1.active.erase (*send);
system.wallet (0)->insert_adhoc (nano::dev::genesis_key.prv);
auto latest_block (system.wallet (0)->send_action (nano::dev::genesis_key.pub, key.pub, 100));
ASSERT_NE (nullptr, latest_block);
ASSERT_EQ (nano::dev::constants.genesis_amount - 200, node1.balance (nano::dev::genesis->account ()));
ASSERT_EQ (nano::dev::constants.genesis_amount, node2.balance (nano::dev::genesis->account ()));
ASSERT_TIMELY (10s, node2.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount - 200);
ASSERT_TIMELY (5s, node2.balance (nano::dev::genesis->account ()) == nano::dev::constants.genesis_amount - 200);
}

TEST (gap_cache, two_dependencies)
Expand Down
10 changes: 4 additions & 6 deletions nano/core_test/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4430,20 +4430,18 @@ TEST (ledger, unchecked_open)
.build_shared ();
node1.work_generate_blocking (*open2);
open2->signature.bytes[0] ^= 1;
// Insert open2 first
node1.block_processor.add (open2);
node1.block_processor.add (open2); // Insert open2 in to the queue before open1
node1.block_processor.add (open1);
{
// Waits for the last blocks to pass through block_processor and unchecked.put queues
size_t count = 0;
ASSERT_TIMELY (10s, 1 == (count = node1.unchecked.count (node1.store.tx_begin_read ())));
// Existence of open1 in unchecked implies open2 has been processed and rejected due to signature check failure
ASSERT_TIMELY (5s, 1 == node1.unchecked.count (node1.store.tx_begin_read ()));
// When open1 existists in unchecked, we know open2 has been processed.
auto blocks = node1.unchecked.get (node1.store.tx_begin_read (), open1->source ());
ASSERT_EQ (blocks.size (), 1);
}
node1.block_processor.add (send1);
// Waits for the send1 block to pass through block_processor and unchecked.put queues
ASSERT_TIMELY (10s, node1.store.block.exists (node1.store.tx_begin_read (), open1->hash ()));
ASSERT_TIMELY (5s, node1.store.block.exists (node1.store.tx_begin_read (), open1->hash ()));
ASSERT_EQ (0, node1.unchecked.count (node1.store.tx_begin_read ()));
}

Expand Down
Loading

0 comments on commit 35e81c8

Please sign in to comment.