Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into lock_cleanup
Browse files Browse the repository at this point in the history
# Conflicts:
#	nano/core_test/node.cpp
  • Loading branch information
clemahieu committed Jan 15, 2020
2 parents 196ffda + eb2beac commit 06dfafc
Show file tree
Hide file tree
Showing 30 changed files with 1,161 additions and 1,001 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ jobs:
- name: Run Tests
run: ci/build-travis.sh "/tmp/qt/lib/cmake/Qt5";

clang_format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@50fbc62
- name: Get Clang 9
env:
DEBIAN_FRONTEND: noninteractive
run: |
APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' -y
sudo apt-get update -y
sudo apt-get install clang-tools-9 clang-format-9
sudo ln -s /usr/bin/clang-format-9 /usr/bin/clang-format
- name: Clang Format
run: ci/check-commit-format.sh

gcc_test:
runs-on: ubuntu-18.04
steps:
Expand Down
3 changes: 3 additions & 0 deletions ci/check-commit-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ if [ "$RESULT" != "no modified files to format" ] && [ "$RESULT" != "clang-forma
echo
echo "Code formatting differs from expected - please run ci/clang-format-all.sh"
exit 1
else
echo "clang-format passed"
exit 0
fi
166 changes: 72 additions & 94 deletions nano/core_test/active_transactions.cpp

Large diffs are not rendered by default.

58 changes: 30 additions & 28 deletions nano/core_test/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,17 +784,17 @@ TEST (frontier_req, end)
TEST (frontier_req, count)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
auto node1 = system.nodes[0];
nano::genesis genesis;
// Public key FB93... after genesis in accounts table
nano::keypair key1 ("ED5AE0A6505B14B67435C29FD9FEEBC26F597D147BC92F6D795FFAD7AFD3D967");
nano::state_block send1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
node1.work_generate_blocking (send1);
ASSERT_EQ (nano::process_result::progress, node1.process (send1).code);
node1->work_generate_blocking (send1);
ASSERT_EQ (nano::process_result::progress, node1->process (send1).code);
nano::state_block receive1 (key1.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, send1.hash (), key1.prv, key1.pub, 0);
node1.work_generate_blocking (receive1);
ASSERT_EQ (nano::process_result::progress, node1.process (receive1).code);
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, system.nodes[0]));
node1->work_generate_blocking (receive1);
ASSERT_EQ (nano::process_result::progress, node1->process (receive1).code);
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, node1));
auto req = std::make_unique<nano::frontier_req> ();
req->start.clear ();
req->age = std::numeric_limits<decltype (req->age)>::max ();
Expand Down Expand Up @@ -857,63 +857,65 @@ TEST (bulk, genesis)
{
nano::system system (1);
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (node1->init_error ());
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
nano::block_hash latest2 (node1->latest (nano::test_genesis_key.pub));
auto node1 = system.nodes[0];
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (node2->init_error ());
nano::block_hash latest1 (node1->latest (nano::test_genesis_key.pub));
nano::block_hash latest2 (node2->latest (nano::test_genesis_key.pub));
ASSERT_EQ (latest1, latest2);
nano::keypair key2;
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, 100));
nano::block_hash latest3 (system.nodes[0]->latest (nano::test_genesis_key.pub));
nano::block_hash latest3 (node1->latest (nano::test_genesis_key.pub));
ASSERT_NE (latest1, latest3);
node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ());
node2->bootstrap_initiator.bootstrap (node1->network.endpoint ());
system.deadline_set (10s);
while (node1->latest (nano::test_genesis_key.pub) != system.nodes[0]->latest (nano::test_genesis_key.pub))
while (node2->latest (nano::test_genesis_key.pub) != node1->latest (nano::test_genesis_key.pub))
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (node1->latest (nano::test_genesis_key.pub), system.nodes[0]->latest (nano::test_genesis_key.pub));
node1->stop ();
ASSERT_EQ (node2->latest (nano::test_genesis_key.pub), node1->latest (nano::test_genesis_key.pub));
node2->stop ();
}

TEST (bulk, offline_send)
{
nano::system system (1);
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (node1->init_error ());
node1->start ();
system.nodes.push_back (node1);
auto node1 = system.nodes[0];
auto node2 (std::make_shared<nano::node> (system.io_ctx, nano::get_available_port (), nano::unique_path (), system.alarm, system.logging, system.work));
ASSERT_FALSE (node2->init_error ());
node2->start ();
system.nodes.push_back (node2);
nano::keypair key2;
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
auto wallet (node2->wallets.create (nano::random_wallet_id ()));
wallet->insert_adhoc (key2.prv);
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
ASSERT_NE (std::numeric_limits<nano::uint256_t>::max (), system.nodes[0]->balance (nano::test_genesis_key.pub));
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, node1->config.receive_minimum.number ()));
ASSERT_NE (std::numeric_limits<nano::uint256_t>::max (), node1->balance (nano::test_genesis_key.pub));
// Wait to finish election background tasks
system.deadline_set (10s);
while (!system.nodes[0]->active.empty ())
while (!node1->active.empty ())
{
ASSERT_NO_ERROR (system.poll ());
}
// Initiate bootstrap
node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ());
node2->bootstrap_initiator.bootstrap (node1->network.endpoint ());
// Nodes should find each other
do
{
ASSERT_NO_ERROR (system.poll ());
} while (system.nodes[0]->network.empty () || node1->network.empty ());
} while (node1->network.empty () || node2->network.empty ());
// Send block arrival via bootstrap
while (node1->balance (nano::test_genesis_key.pub) == std::numeric_limits<nano::uint256_t>::max ())
while (node2->balance (nano::test_genesis_key.pub) == std::numeric_limits<nano::uint256_t>::max ())
{
ASSERT_NO_ERROR (system.poll ());
}
// Receiving send block
system.deadline_set (20s);
while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ())
while (node2->balance (key2.pub) != node1->config.receive_minimum.number ())
{
ASSERT_NO_ERROR (system.poll ());
}
node1->stop ();
node2->stop ();
}

TEST (bulk_pull_account, basics)
Expand Down
86 changes: 40 additions & 46 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ TEST (confirmation_height, gap_live)
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
system.add_node (node_config);
auto node1 = system.add_node (node_config);
node_config.peering_port = nano::get_available_port ();
system.add_node (node_config);
nano::keypair destination;
Expand All @@ -280,18 +280,18 @@ TEST (confirmation_height, gap_live)

nano::genesis genesis;
auto send1 (std::make_shared<nano::state_block> (nano::genesis_account, genesis.hash (), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
system.nodes[0]->work_generate_blocking (*send1);
node1->work_generate_blocking (*send1);
auto send2 (std::make_shared<nano::state_block> (nano::genesis_account, send1->hash (), nano::genesis_account, nano::genesis_amount - 2 * nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
system.nodes[0]->work_generate_blocking (*send2);
node1->work_generate_blocking (*send2);
auto send3 (std::make_shared<nano::state_block> (nano::genesis_account, send2->hash (), nano::genesis_account, nano::genesis_amount - 3 * nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
system.nodes[0]->work_generate_blocking (*send3);
node1->work_generate_blocking (*send3);

auto open1 (std::make_shared<nano::open_block> (send1->hash (), destination.pub, destination.pub, destination.prv, destination.pub, 0));
system.nodes[0]->work_generate_blocking (*open1);
node1->work_generate_blocking (*open1);
auto receive1 (std::make_shared<nano::receive_block> (open1->hash (), send2->hash (), destination.prv, destination.pub, 0));
system.nodes[0]->work_generate_blocking (*receive1);
node1->work_generate_blocking (*receive1);
auto receive2 (std::make_shared<nano::receive_block> (receive1->hash (), send3->hash (), destination.prv, destination.pub, 0));
system.nodes[0]->work_generate_blocking (*receive2);
node1->work_generate_blocking (*receive2);

for (auto & node : system.nodes)
{
Expand Down Expand Up @@ -600,46 +600,46 @@ TEST (confirmation_height, conflict_rollback_cemented)
sb.open (nano::stringstream_mt_sink{});
nano::boost_log_cerr_redirect redirect_cerr (&sb);
nano::system system (2);
auto & node1 (*system.nodes[0]);
auto & node2 (*system.nodes[1]);
ASSERT_EQ (1, node1.network.size ());
auto node1 (system.nodes[0]);
auto node2 (system.nodes[1]);
ASSERT_EQ (1, node1->network.size ());
nano::keypair key1;
nano::genesis genesis;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
nano::publish publish1 (send1);
nano::keypair key2;
auto send2 (std::make_shared<nano::send_block> (genesis.hash (), key2.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
nano::publish publish2 (send2);
auto channel1 (node1.network.udp_channels.create (node1.network.endpoint ()));
node1.network.process_message (publish1, channel1);
node1.block_processor.flush ();
auto channel2 (node2.network.udp_channels.create (node1.network.endpoint ()));
node2.network.process_message (publish2, channel2);
node2.block_processor.flush ();
ASSERT_EQ (1, node1.active.size ());
ASSERT_EQ (1, node2.active.size ());
auto channel1 (node1->network.udp_channels.create (node1->network.endpoint ()));
node1->network.process_message (publish1, channel1);
node1->block_processor.flush ();
auto channel2 (node2->network.udp_channels.create (node1->network.endpoint ()));
node2->network.process_message (publish2, channel2);
node2->block_processor.flush ();
ASSERT_EQ (1, node1->active.size ());
ASSERT_EQ (1, node2->active.size ());
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
node1.network.process_message (publish2, channel1);
node1.block_processor.flush ();
node2.network.process_message (publish1, channel2);
node2.block_processor.flush ();
nano::unique_lock<std::mutex> lock (node2.active.mutex);
auto conflict (node2.active.roots.find (nano::qualified_root (genesis.hash (), genesis.hash ())));
ASSERT_NE (node2.active.roots.end (), conflict);
node1->network.process_message (publish2, channel1);
node1->block_processor.flush ();
node2->network.process_message (publish1, channel2);
node2->block_processor.flush ();
nano::unique_lock<std::mutex> lock (node2->active.mutex);
auto conflict (node2->active.roots.find (nano::qualified_root (genesis.hash (), genesis.hash ())));
ASSERT_NE (node2->active.roots.end (), conflict);
auto votes1 (conflict->election);
ASSERT_NE (nullptr, votes1);
ASSERT_EQ (1, votes1->last_votes.size ());
lock.unlock ();
// Force blocks to be cemented on both nodes
{
auto transaction (system.nodes[0]->store.tx_begin_write ());
ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ()));
node1.store.confirmation_height_put (transaction, nano::genesis_account, 2);
auto transaction (node1->store.tx_begin_write ());
ASSERT_TRUE (node1->store.block_exists (transaction, publish1.block->hash ()));
node1->store.confirmation_height_put (transaction, nano::genesis_account, 2);
}
{
auto transaction (system.nodes[1]->store.tx_begin_write ());
ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ()));
node2.store.confirmation_height_put (transaction, nano::genesis_account, 2);
auto transaction (node2->store.tx_begin_write ());
ASSERT_TRUE (node2->store.block_exists (transaction, publish2.block->hash ()));
node2->store.confirmation_height_put (transaction, nano::genesis_account, 2);
}

auto rollback_log_entry = boost::str (boost::format ("Failed to roll back %1%") % send2->hash ().to_string ());
Expand All @@ -650,15 +650,15 @@ TEST (confirmation_height, conflict_rollback_cemented)
ASSERT_NO_ERROR (system.poll ());
done = (sb.component ()->str ().find (rollback_log_entry) != std::string::npos);
}
auto transaction1 (system.nodes[0]->store.tx_begin_read ());
auto transaction2 (system.nodes[1]->store.tx_begin_read ());
auto transaction1 (node1->store.tx_begin_read ());
auto transaction2 (node2->store.tx_begin_read ());
lock.lock ();
auto winner (*votes1->tally ().begin ());
ASSERT_EQ (*publish1.block, *winner.second);
ASSERT_EQ (nano::genesis_amount - 100, winner.first);
ASSERT_TRUE (node1.store.block_exists (transaction1, publish1.block->hash ()));
ASSERT_TRUE (node2.store.block_exists (transaction2, publish2.block->hash ()));
ASSERT_FALSE (node2.store.block_exists (transaction2, publish1.block->hash ()));
ASSERT_TRUE (node1->store.block_exists (transaction1, publish1.block->hash ()));
ASSERT_TRUE (node2->store.block_exists (transaction2, publish2.block->hash ()));
ASSERT_FALSE (node2->store.block_exists (transaction2, publish1.block->hash ()));
}

TEST (confirmation_height, observers)
Expand Down Expand Up @@ -757,22 +757,16 @@ TEST (confirmation_height, pending_observer_callbacks)
break;
}
}
// Can have timing issues.
node->confirmation_height_processor.add (send.hash ());
system.deadline_set (5s);
while (node->ledger.cache.cemented_count < 3)
{
nano::unique_lock<std::mutex> lk (node->pending_confirmation_height.mutex);
while (!node->pending_confirmation_height.current_hash.is_zero ())
{
lk.unlock ();
std::this_thread::yield ();
lk.lock ();
}
ASSERT_NO_ERROR (system.poll ());
}

// Confirm the callback is not called under this circumstance
ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (0, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (3, node->ledger.cache.cemented_count);
}

TEST (confirmation_height, prioritize_frontiers)
Expand All @@ -787,7 +781,7 @@ TEST (confirmation_height, prioritize_frontiers)
nano::keypair key2;
nano::keypair key3;
nano::keypair key4;
nano::block_hash latest1 (system.nodes[0]->latest (nano::test_genesis_key.pub));
nano::block_hash latest1 (node->latest (nano::test_genesis_key.pub));

// Send different numbers of blocks all accounts
nano::send_block send1 (latest1, key1.pub, node->config.online_weight_minimum.number () + 10000, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest1));
Expand Down
51 changes: 27 additions & 24 deletions nano/core_test/gap_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,31 @@ TEST (gap_cache, comparison)
TEST (gap_cache, gap_bootstrap)
{
nano::system system (2);
nano::block_hash latest (system.nodes[0]->latest (nano::test_genesis_key.pub));
auto & node1 (*system.nodes[0]);
auto & node2 (*system.nodes[1]);
nano::block_hash latest (node1.latest (nano::test_genesis_key.pub));
nano::keypair key;
auto send (std::make_shared<nano::send_block> (latest, key.pub, nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest)));
{
auto transaction (system.nodes[0]->store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->block_processor.process_one (transaction, send).code);
auto transaction (node1.store.tx_begin_write ());
ASSERT_EQ (nano::process_result::progress, node1.block_processor.process_one (transaction, send).code);
}
ASSERT_EQ (nano::genesis_amount - 100, system.nodes[0]->balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount, system.nodes[1]->balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount - 100, node1.balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount, node2.balance (nano::genesis_account));
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
system.wallet (0)->insert_adhoc (key.prv);
auto latest_block (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, 100));
ASSERT_NE (nullptr, latest_block);
ASSERT_EQ (nano::genesis_amount - 200, system.nodes[0]->balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount, system.nodes[1]->balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount - 200, node1.balance (nano::genesis_account));
ASSERT_EQ (nano::genesis_amount, node2.balance (nano::genesis_account));
system.deadline_set (10s);
{
// The separate publish and vote system doesn't work very well here because it's instantly confirmed.
// We help it get the block and vote out here.
auto transaction (system.nodes[0]->store.tx_begin_read ());
system.nodes[0]->network.flood_block (latest_block);
auto transaction (node1.store.tx_begin_read ());
node1.network.flood_block (latest_block);
}
while (system.nodes[1]->balance (nano::genesis_account) != nano::genesis_amount - 200)
while (node2.balance (nano::genesis_account) != nano::genesis_amount - 200)
{
ASSERT_NO_ERROR (system.poll ());
}
Expand All @@ -97,23 +99,24 @@ TEST (gap_cache, gap_bootstrap)
TEST (gap_cache, two_dependencies)
{
nano::system system (1);
auto & node1 (*system.nodes[0]);
nano::keypair key;
nano::genesis genesis;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key.pub, 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
auto send2 (std::make_shared<nano::send_block> (send1->hash (), key.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
auto open (std::make_shared<nano::open_block> (send1->hash (), key.pub, key.pub, key.prv, key.pub, *system.work.generate (key.pub)));
ASSERT_EQ (0, system.nodes[0]->gap_cache.size ());
system.nodes[0]->block_processor.add (send2, nano::seconds_since_epoch ());
system.nodes[0]->block_processor.flush ();
ASSERT_EQ (1, system.nodes[0]->gap_cache.size ());
system.nodes[0]->block_processor.add (open, nano::seconds_since_epoch ());
system.nodes[0]->block_processor.flush ();
ASSERT_EQ (2, system.nodes[0]->gap_cache.size ());
system.nodes[0]->block_processor.add (send1, nano::seconds_since_epoch ());
system.nodes[0]->block_processor.flush ();
ASSERT_EQ (0, system.nodes[0]->gap_cache.size ());
auto transaction (system.nodes[0]->store.tx_begin_read ());
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, open->hash ()));
ASSERT_EQ (0, node1.gap_cache.size ());
node1.block_processor.add (send2, nano::seconds_since_epoch ());
node1.block_processor.flush ();
ASSERT_EQ (1, node1.gap_cache.size ());
node1.block_processor.add (open, nano::seconds_since_epoch ());
node1.block_processor.flush ();
ASSERT_EQ (2, node1.gap_cache.size ());
node1.block_processor.add (send1, nano::seconds_since_epoch ());
node1.block_processor.flush ();
ASSERT_EQ (0, node1.gap_cache.size ());
auto transaction (node1.store.tx_begin_read ());
ASSERT_TRUE (node1.store.block_exists (transaction, send1->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, send2->hash ()));
ASSERT_TRUE (node1.store.block_exists (transaction, open->hash ()));
}
Loading

0 comments on commit 06dfafc

Please sign in to comment.