Skip to content

Commit

Permalink
Merge branch 'develop' into networking-fixes/tcp-listener-2
Browse files Browse the repository at this point in the history
# Conflicts:
#	nano/node/transport/socket.cpp
#	nano/node/transport/socket.hpp
  • Loading branch information
pwojcikdev committed Apr 9, 2024
2 parents 4064223 + 68496af commit 560f3b4
Show file tree
Hide file tree
Showing 68 changed files with 1,491 additions and 744 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/code_sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ jobs:
- { name: UBSAN, ignore_errors: false }
- { name: ASAN, ignore_errors: false, leak_check: false }
- { name: ASAN_INT, ignore_errors: true, leak_check: false }
- { name: TSAN, ignore_errors: true }
- { name: TSAN, ignore_errors: false }
- { name: LEAK, ignore_errors: true, leak_check: true }
exclude:
# Bug when running with TSAN: "ThreadSanitizer: CHECK failed: sanitizer_deadlock_detector"
- BACKEND: rocksdb
SANITIZER: { name: TSAN }
runs-on: ubuntu-22.04
env:
COMPILER: ${{ matrix.COMPILER }}
Expand Down Expand Up @@ -72,7 +76,7 @@ jobs:
SANITIZER:
- { name: UBSAN, ignore_errors: false }
- { name: ASAN, ignore_errors: false }
- { name: TSAN, ignore_errors: true }
- { name: TSAN, ignore_errors: false }
runs-on: macos-14
env:
COMPILER: ${{ matrix.COMPILER }}
Expand Down
1 change: 1 addition & 0 deletions nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_executable(
election_scheduler.cpp
enums.cpp
epochs.cpp
fair_queue.cpp
frontiers_confirmation.cpp
ipc.cpp
ledger.cpp
Expand Down
22 changes: 11 additions & 11 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TEST (active_transactions, confirm_frontier)
std::shared_ptr<nano::election> election2;
ASSERT_TIMELY (5s, election2 = node2.active.election (send->qualified_root ()));
ASSERT_TIMELY (5s, nano::test::confirmed (node2, { send }));
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.cemented_count, 2);
ASSERT_TIMELY_EQ (5s, node2.ledger.cemented_count (), 2);
ASSERT_TIMELY (5s, node2.active.empty ());
ASSERT_GT (election2->confirmation_request_count, 0u);
}
Expand Down Expand Up @@ -486,9 +486,9 @@ TEST (inactive_votes_cache, election_start)
ASSERT_EQ (nano::block_status::progress, node.process (send2));
ASSERT_EQ (nano::block_status::progress, node.process (open1));
ASSERT_EQ (nano::block_status::progress, node.process (open2));
ASSERT_TIMELY_EQ (5s, 5, node.ledger.cache.block_count);
ASSERT_TIMELY_EQ (5s, 5, node.ledger.block_count ());
ASSERT_TRUE (node.active.empty ());
ASSERT_EQ (1, node.ledger.cache.cemented_count);
ASSERT_EQ (1, node.ledger.cemented_count ());
// These blocks will be processed later
auto send3 = send_block_builder.make_block ()
.previous (send2->hash ())
Expand All @@ -510,7 +510,7 @@ TEST (inactive_votes_cache, election_start)
node.vote_processor.vote (vote1, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, node.vote_cache.size (), 3);
ASSERT_TRUE (node.active.empty ());
ASSERT_EQ (1, node.ledger.cache.cemented_count);
ASSERT_EQ (1, node.ledger.cemented_count ());

// 2 votes are required to start election (dev network)
auto vote2 = nano::test::make_vote (key2, { open1, open2, send4 });
Expand All @@ -523,7 +523,7 @@ TEST (inactive_votes_cache, election_start)
auto vote0 = nano::test::make_final_vote (nano::dev::genesis_key, { open1, open2, send4 });
node.vote_processor.vote (vote0, std::make_shared<nano::transport::inproc::channel> (node, node));
ASSERT_TIMELY_EQ (5s, 0, node.active.size ());
ASSERT_TIMELY_EQ (5s, 5, node.ledger.cache.cemented_count);
ASSERT_TIMELY_EQ (5s, 5, node.ledger.cemented_count ());
ASSERT_TRUE (nano::test::confirmed (node, { send1, send2, open1, open2 }));

// A late block arrival also checks the inactive votes cache
Expand All @@ -536,7 +536,7 @@ TEST (inactive_votes_cache, election_start)
// 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));
node.process_active (send4);
ASSERT_TIMELY_EQ (5s, 7, node.ledger.cache.cemented_count);
ASSERT_TIMELY_EQ (5s, 7, node.ledger.cemented_count ());
}

namespace nano
Expand Down Expand Up @@ -829,8 +829,8 @@ TEST (active_transactions, fork_filter_cleanup)
// how about node1 picking up "send1" from node2? we know it does because we assert at
// the end that it is within node1's AEC, but why node1.block_count doesn't increase?
//
ASSERT_TIMELY_EQ (5s, node2.ledger.cache.block_count, 2);
ASSERT_TIMELY_EQ (5s, node1.ledger.cache.block_count, 2);
ASSERT_TIMELY_EQ (5s, node2.ledger.block_count (), 2);
ASSERT_TIMELY_EQ (5s, node1.ledger.block_count (), 2);

// Block is erased from the duplicate filter
ASSERT_TIMELY (5s, node1.network.publish_filter.apply (send_block_bytes.data (), send_block_bytes.size ()));
Expand Down Expand Up @@ -890,7 +890,7 @@ TEST (active_transactions, fork_replacement_tally)
auto vote = nano::test::make_final_vote (nano::dev::genesis_key, { send, open });
node1.vote_processor.vote (vote, std::make_shared<nano::transport::inproc::channel> (node1, node1));
}
ASSERT_TIMELY_EQ (5s, node1.ledger.cache.cemented_count, 1 + 2 * reps_count);
ASSERT_TIMELY_EQ (5s, node1.ledger.cemented_count (), 1 + 2 * reps_count);

nano::keypair key;
auto send_last = builder.make_block ()
Expand Down Expand Up @@ -1050,8 +1050,8 @@ TEST (active_transactions, confirm_new)
// Let node2 know about the block
ASSERT_TIMELY (5s, node2.block (send->hash ()));
// Wait confirmation
ASSERT_TIMELY (5s, node1.ledger.cache.cemented_count == 2);
ASSERT_TIMELY (5s, node2.ledger.cache.cemented_count == 2);
ASSERT_TIMELY (5s, node1.ledger.cemented_count () == 2);
ASSERT_TIMELY (5s, node2.ledger.cemented_count () == 2);
}

// Ensures votes are tallied on election::publish even if no vote is inserted through inactive_votes_cache
Expand Down
15 changes: 4 additions & 11 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ TEST (block_store, frontier_retrieval)
nano::account account1{};
nano::account_info info1 (0, 0, 0, 0, 0, 0, nano::epoch::epoch_0);
auto transaction (store->tx_begin_write ());
store->confirmation_height.put (transaction, account1, { 0, nano::block_hash (0) });
store->account.put (transaction, account1, info1);
nano::account_info info2;
store->account.get (transaction, account1, info2);
Expand Down Expand Up @@ -604,10 +603,6 @@ TEST (block_store, latest_find)
nano::account account2 (3);
nano::block_hash hash2 (4);
auto transaction (store->tx_begin_write ());
store->confirmation_height.put (transaction, account1, { 0, nano::block_hash (0) });
store->account.put (transaction, account1, { hash1, account1, hash1, 100, 0, 300, nano::epoch::epoch_0 });
store->confirmation_height.put (transaction, account2, { 0, nano::block_hash (0) });
store->account.put (transaction, account2, { hash2, account2, hash2, 200, 0, 400, nano::epoch::epoch_0 });
auto first (store->account.begin (transaction));
auto second (store->account.begin (transaction));
++second;
Expand Down Expand Up @@ -768,7 +763,6 @@ TEST (block_store, latest_exists)
nano::account two (2);
nano::account_info info;
auto transaction (store->tx_begin_write ());
store->confirmation_height.put (transaction, two, { 0, nano::block_hash (0) });
store->account.put (transaction, two, info);
nano::account one (1);
ASSERT_FALSE (store->account.exists (transaction, one));
Expand All @@ -786,7 +780,6 @@ TEST (block_store, large_iteration)
nano::account account;
nano::random_pool::generate_block (account.bytes.data (), account.bytes.size ());
accounts1.insert (account);
store->confirmation_height.put (transaction, account, { 0, nano::block_hash (0) });
store->account.put (transaction, account, nano::account_info ());
}
std::unordered_set<nano::account> accounts2;
Expand Down Expand Up @@ -889,7 +882,6 @@ TEST (block_store, account_count)
auto transaction (store->tx_begin_write ());
ASSERT_EQ (0, store->account.count (transaction));
nano::account account (200);
store->confirmation_height.put (transaction, account, { 0, nano::block_hash (0) });
store->account.put (transaction, account, nano::account_info ());
}
auto transaction (store->tx_begin_read ());
Expand All @@ -902,9 +894,10 @@ TEST (block_store, cemented_count_cache)
auto store = nano::make_store (logger, nano::unique_path (), nano::dev::constants);
ASSERT_TRUE (!store->init_error ());
auto transaction (store->tx_begin_write ());
nano::ledger_cache ledger_cache{ store->rep_weight };
store->initialize (transaction, ledger_cache, nano::dev::constants);
ASSERT_EQ (1, ledger_cache.cemented_count);
nano::stats stats;
nano::ledger ledger (*store, stats, nano::dev::constants);
store->initialize (transaction, ledger.cache, nano::dev::constants);
ASSERT_EQ (1, ledger.cemented_count ());
}

TEST (block_store, block_random)
Expand Down
45 changes: 23 additions & 22 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ TEST (bootstrap_processor, push_diamond_pruning)

{
auto transaction (node1->store.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));
ASSERT_TRUE (node1->ledger.block_exists (transaction, nano::dev::genesis->hash ()));
Expand All @@ -661,8 +662,8 @@ TEST (bootstrap_processor, push_diamond_pruning)
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_EQ (2, node1->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (2, node1->ledger.pruned_count ());
ASSERT_EQ (5, node1->ledger.block_count ());
}

// 2nd bootstrap
Expand Down Expand Up @@ -973,22 +974,22 @@ TEST (bootstrap_processor, lazy_hash_pruning)
ASSERT_TIMELY (5s, node1->block_confirmed (change1->hash ()));
ASSERT_TIMELY (5s, node1->block_confirmed (change2->hash ()));
ASSERT_TIMELY (5s, node1->active.empty ());
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_EQ (5, node1->ledger.cemented_count ());

// Pruning action
node1->ledger_pruning (2, false);
ASSERT_EQ (9, node0->ledger.cache.block_count);
ASSERT_EQ (0, node0->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (3, node1->ledger.cache.pruned_count);
ASSERT_EQ (9, node0->ledger.block_count ());
ASSERT_EQ (0, node0->ledger.pruned_count ());
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_EQ (3, node1->ledger.pruned_count ());

// Start lazy bootstrap with last block in chain known
nano::test::establish_tcp (system, *node1, node0->network.endpoint ());
node1->bootstrap_initiator.bootstrap_lazy (receive3->hash (), true);

// Check processed blocks
ASSERT_TIMELY_EQ (5s, node1->ledger.cache.block_count, 9);
ASSERT_TIMELY_EQ (5s, node1->ledger.block_count (), 9);
ASSERT_TIMELY (5s, node1->balance (key2.pub) != 0);
ASSERT_TIMELY (5s, !node1->bootstrap_initiator.in_progress ());
}
Expand Down Expand Up @@ -1369,14 +1370,14 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
// Confirm last block to prune previous
ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1, send2, open, state_open }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node1, { send2, open, state_open }));
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (5, node1->ledger.cache.cemented_count);
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_EQ (5, node1->ledger.cemented_count ());

// Pruning action, send1 should get pruned
ASSERT_EQ (0, node1->ledger.cache.pruned_count);
ASSERT_EQ (0, node1->ledger.pruned_count ());
node1->ledger_pruning (2, false);
ASSERT_EQ (1, node1->ledger.cache.pruned_count);
ASSERT_EQ (5, node1->ledger.cache.block_count);
ASSERT_EQ (1, node1->ledger.pruned_count ());
ASSERT_EQ (5, node1->ledger.block_count ());
ASSERT_TRUE (node1->ledger.store.pruned.exists (node1->ledger.store.tx_begin_read (), send1->hash ()));
ASSERT_TRUE (nano::test::exists (*node1, { send2, open, state_open }));

Expand All @@ -1392,7 +1393,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)
ASSERT_TIMELY (5s, lazy_attempt->stopped || lazy_attempt->requeued_pulls >= 4);

// Some blocks cannot be retrieved from pruned node
ASSERT_EQ (1, node2->ledger.cache.block_count);
ASSERT_EQ (1, node2->ledger.block_count ());
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (*node2, { send1, send2, open, state_open }));
{
auto transaction (node2->store.tx_begin_read ());
Expand All @@ -1401,7 +1402,7 @@ TEST (bootstrap_processor, lazy_pruning_missing_block)

// Insert missing block
node2->process_active (send1);
ASSERT_TIMELY_EQ (5s, 3, node2->ledger.cache.block_count);
ASSERT_TIMELY_EQ (5s, 3, node2->ledger.block_count ());
ASSERT_TIMELY (5s, nano::test::exists (*node2, { send1, send2 }));
ASSERT_TRUE (nano::test::block_or_pruned_none_exists (*node2, { open, state_open }));
}
Expand Down Expand Up @@ -2050,18 +2051,18 @@ TEST (bulk, genesis_pruning)

ASSERT_TRUE (nano::test::start_elections (system, *node1, { send1 }, true));
ASSERT_TIMELY (5s, node1->active.active (send2->qualified_root ()));
ASSERT_EQ (0, node1->ledger.cache.pruned_count);
ASSERT_EQ (0, node1->ledger.pruned_count ());

ASSERT_TRUE (nano::test::start_elections (system, *node1, { send2 }, true));
ASSERT_TIMELY (5s, node1->active.active (send3->qualified_root ()));
ASSERT_EQ (0, node1->ledger.cache.pruned_count);
ASSERT_EQ (0, node1->ledger.pruned_count ());

ASSERT_TRUE (nano::test::start_elections (system, *node1, { send3 }, true));
ASSERT_TIMELY (5s, nano::test::confirmed (*node1, { send3 }));

node1->ledger_pruning (2, false);
ASSERT_EQ (2, node1->ledger.cache.pruned_count);
ASSERT_EQ (4, node1->ledger.cache.block_count);
ASSERT_EQ (2, node1->ledger.pruned_count ());
ASSERT_EQ (4, node1->ledger.block_count ());
ASSERT_TRUE (node1->ledger.store.pruned.exists (node1->ledger.store.tx_begin_read (), send1->hash ()));
ASSERT_FALSE (nano::test::exists (*node1, { send1 }));
ASSERT_TRUE (node1->ledger.store.pruned.exists (node1->ledger.store.tx_begin_read (), send2->hash ()));
Expand All @@ -2077,7 +2078,7 @@ TEST (bulk, genesis_pruning)
ASSERT_TIMELY (5s, !node2->bootstrap_initiator.in_progress ());

// node2 still missing blocks
ASSERT_EQ (1, node2->ledger.cache.block_count);
ASSERT_EQ (1, node2->ledger.block_count ());
{
auto transaction (node2->store.tx_begin_write ());
node2->unchecked.clear ();
Expand All @@ -2086,7 +2087,7 @@ TEST (bulk, genesis_pruning)
// Insert pruned blocks
node2->process_active (send1);
node2->process_active (send2);
ASSERT_TIMELY_EQ (5s, 3, node2->ledger.cache.block_count);
ASSERT_TIMELY_EQ (5s, 3, node2->ledger.block_count ());

// New bootstrap to sync up everything
ASSERT_TIMELY_EQ (5s, node2->bootstrap_initiator.connections->connections_count, 0);
Expand Down
Loading

0 comments on commit 560f3b4

Please sign in to comment.