Skip to content

Commit

Permalink
Merge with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule committed Feb 27, 2020
2 parents 72519d9 + d3ed8e1 commit efd5131
Show file tree
Hide file tree
Showing 41 changed files with 489 additions and 271 deletions.
12 changes: 4 additions & 8 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,8 @@ TEST (active_transactions, prioritize_chains)
auto send5 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 20 * nano::xrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
auto send6 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send5->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 30 * nano::xrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send5->hash ())));
auto open2 (std::make_shared<nano::state_block> (key2.pub, 0, key2.pub, 10 * nano::xrb_ratio, send5->hash (), key2.prv, key2.pub, *system.work.generate (key2.pub, nano::difficulty::from_multiplier (50., node1.network_params.network.publish_threshold))));
uint64_t difficulty1 (0);
nano::work_validate (*open2, &difficulty1);
uint64_t difficulty2 (0);
nano::work_validate (*send6, &difficulty2);
auto difficulty1 (open2->difficulty ());
auto difficulty2 (send6->difficulty ());

node1.process_active (send1);
node1.process_active (open1);
Expand Down Expand Up @@ -517,11 +515,9 @@ TEST (active_transactions, update_difficulty)
nano::keypair key1;
// Generate blocks & start elections
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - 100, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
uint64_t difficulty1 (0);
nano::work_validate (*send1, &difficulty1);
auto difficulty1 (send1->difficulty ());
auto send2 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, send1->hash (), nano::test_genesis_key.pub, nano::genesis_amount - 200, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ())));
uint64_t difficulty2 (0);
nano::work_validate (*send2, &difficulty2);
auto difficulty2 (send2->difficulty ());
node1.process_active (send1);
node1.process_active (send2);
node1.block_processor.flush ();
Expand Down
6 changes: 6 additions & 0 deletions nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ TEST (block, publish_req_serialization)
ASSERT_EQ (*req.block, *req2.block);
}

TEST (block, difficulty)
{
nano::send_block block (0, 1, 2, nano::keypair ().prv, 4, 5);
ASSERT_EQ (block.difficulty (), nano::work_difficulty (block.work_version (), block.root (), block.block_work ()));
}

TEST (state_block, serialization)
{
nano::keypair key1;
Expand Down
39 changes: 33 additions & 6 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ TEST (confirmation_height, single)
ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (1, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));

ASSERT_EQ (0, node->active.election_winner_details_size ());
}
};

Expand Down Expand Up @@ -213,6 +215,8 @@ TEST (confirmation_height, multiple_accounts)
ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (10, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));

ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -288,6 +292,8 @@ TEST (confirmation_height, gap_bootstrap)
ASSERT_EQ (0, node1.stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (0, node1.stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (0, node1.stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));

ASSERT_EQ (0, node1.active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -374,6 +380,8 @@ TEST (confirmation_height, gap_live)
ASSERT_EQ (6, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (6, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (6, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));

ASSERT_EQ (0, node->active.election_winner_details_size ());
}
};

Expand Down Expand Up @@ -460,6 +468,8 @@ TEST (confirmation_height, send_receive_between_2_accounts)
ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (10, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (11, node->ledger.cache.cemented_count);

ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -524,6 +534,7 @@ TEST (confirmation_height, send_receive_self)
ASSERT_EQ (6, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (6, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (confirmation_height_info.height, node->ledger.cache.cemented_count);
ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -635,6 +646,8 @@ TEST (confirmation_height, all_block_types)
ASSERT_EQ (15, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (15, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (16, node->ledger.cache.cemented_count);

ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -743,6 +756,7 @@ TEST (confirmation_height, observers)
ASSERT_EQ (1, node1->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (1, node1->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (1, node1->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (0, node1->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -792,6 +806,7 @@ TEST (confirmation_height, modified_chain)
}

ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::invalid_block, nano::stat::dir::in));
ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -836,6 +851,7 @@ TEST (confirmation_height, pending_observer_callbacks)

ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (2, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (0, node->active.election_winner_details_size ());
};

test_mode (nano::confirmation_height_mode::bounded);
Expand Down Expand Up @@ -1181,6 +1197,7 @@ TEST (confirmation_height, dependent_election)

{
// The write guard prevents the confirmation height processor doing any writes.
// Note: This test could still fail intermittently due to thread scheduling between active and confirmation height.
system.deadline_set (10s);
auto write_guard = node->write_database_queue.wait (nano::writer::testing);
while (!node->write_database_queue.contains (nano::writer::confirmation_height))
Expand Down Expand Up @@ -1283,6 +1300,7 @@ TEST (confirmation_height, cemented_gap_below_receive)
ASSERT_EQ (9, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out));
ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (10, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
ASSERT_EQ (0, node->active.election_winner_details_size ());

// Check that the order of callbacks is correct
std::vector<nano::block_hash> expected_order = { send.hash (), open.hash (), send1.hash (), receive1.hash (), send2.hash (), dummy_send.hash (), receive2.hash (), dummy_send1.hash (), send3.hash (), open1->hash () };
Expand Down Expand Up @@ -1368,6 +1386,7 @@ TEST (confirmation_height, cemented_gap_below_no_cache)

auto transaction = node->store.tx_begin_read ();
ASSERT_TRUE (node->ledger.block_confirmed (transaction, open1->hash ()));
ASSERT_EQ (node->active.election_winner_details_size (), 0);
ASSERT_EQ (1, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_quorum, nano::stat::dir::out));
ASSERT_EQ (0, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_conf_height, nano::stat::dir::out));
ASSERT_EQ (5, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out));
Expand Down Expand Up @@ -1395,13 +1414,13 @@ TEST (confirmation_height, election_winner_details_clearing)
nano::keypair key1;
auto send = std::make_shared<nano::send_block> (latest, key1.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (latest));
auto send1 = std::make_shared<nano::send_block> (send->hash (), key1.pub, nano::genesis_amount - nano::Gxrb_ratio * 2, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send->hash ()));
nano::send_block send2 (send1->hash (), key1.pub, nano::genesis_amount - nano::Gxrb_ratio * 3, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ()));
auto send2 = std::make_shared<nano::send_block> (send1->hash (), key1.pub, nano::genesis_amount - nano::Gxrb_ratio * 3, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (send1->hash ()));

{
auto transaction = node->store.tx_begin_write ();
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, *send).code);
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, *send1).code);
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, send2).code);
ASSERT_EQ (nano::process_result::progress, node->ledger.process (transaction, *send2).code);
}

add_callback_stats (*node);
Expand Down Expand Up @@ -1442,8 +1461,16 @@ TEST (confirmation_height, election_winner_details_clearing)

ASSERT_EQ (1, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out));

// election_winner_details should get cleared during another batch of cementing, so add another block
node->confirmation_height_processor.add (send2.hash ());
node->block_confirm (send2);
system.deadline_set (10s);
while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 3)
{
ASSERT_NO_ERROR (system.poll ());
}

// Add an already cemented block with fake election details. It should get removed
node->active.add_election_winner_details (send2->hash (), nullptr);
node->confirmation_height_processor.add (send2->hash ());

system.deadline_set (10s);
while (node->active.election_winner_details_size () > 0)
Expand All @@ -1452,8 +1479,8 @@ TEST (confirmation_height, election_winner_details_clearing)
}

ASSERT_EQ (1, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_inactive, nano::stat::dir::out));
ASSERT_EQ (2, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (1, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_quorum, nano::stat::dir::out));
ASSERT_EQ (3, node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (2, node->stats.count (nano::stat::type::observer, nano::stat::detail::observer_confirmation_active_quorum, nano::stat::dir::out));
ASSERT_EQ (3, node->stats.count (nano::stat::type::confirmation_height, nano::stat::detail::blocks_confirmed, nano::stat::dir::in));
ASSERT_EQ (3, node->stats.count (nano::stat::type::confirmation_height, get_stats_detail (mode_a), nano::stat::dir::in));
};
Expand Down
10 changes: 3 additions & 7 deletions nano/core_test/conflicts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ TEST (conflicts, reprioritize)
nano::keypair key1;
auto send1 (std::make_shared<nano::send_block> (genesis.hash (), key1.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0));
node1.work_generate_blocking (*send1);
uint64_t difficulty1;
nano::work_validate (*send1, &difficulty1);
auto difficulty1 (send1->difficulty ());
nano::send_block send1_copy (*send1);
node1.process_active (send1);
node1.block_processor.flush ();
Expand All @@ -177,8 +176,7 @@ TEST (conflicts, reprioritize)
ASSERT_EQ (difficulty1, existing1->difficulty);
}
node1.work_generate_blocking (send1_copy, difficulty1);
uint64_t difficulty2;
nano::work_validate (send1_copy, &difficulty2);
auto difficulty2 (send1_copy.difficulty ());
node1.process_active (std::make_shared<nano::send_block> (send1_copy));
node1.block_processor.flush ();
{
Expand Down Expand Up @@ -277,9 +275,7 @@ TEST (conflicts, adjusted_difficulty)
// Independent elections can have higher difficulty than adjusted tree
nano::keypair key4;
auto open_epoch2 (std::make_shared<nano::state_block> (key4.pub, 0, 0, 0, node1.ledger.epoch_link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (key4.pub, adjusted_difficulties.find (send1->hash ())->second)));
uint64_t difficulty;
ASSERT_FALSE (nano::work_validate (*open_epoch2, &difficulty));
ASSERT_GT (difficulty, adjusted_difficulties.find (send1->hash ())->second);
ASSERT_GT (open_epoch2->difficulty (), adjusted_difficulties.find (send1->hash ())->second);
node1.process_active (open_epoch2);
node1.block_processor.flush ();
system.deadline_set (3s);
Expand Down
5 changes: 2 additions & 3 deletions nano/core_test/fakes/work_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne
auto this_l (shared_from_this ());
work_pool.generate (version, hash, [this_l, hash](boost::optional<uint64_t> work_a) {
auto result = work_a.value_or (0);
uint64_t difficulty;
nano::work_validate (this_l->version, hash, result, &difficulty);
auto difficulty (nano::work_difficulty (this_l->version, hash, result));
static nano::network_params params;
ptree::ptree message_l;
message_l.put ("work", nano::to_string_hex (result));
message_l.put ("difficulty", nano::to_string_hex (difficulty));
message_l.put ("multiplier", nano::to_string (nano::difficulty::to_multiplier (difficulty, params.network.publish_threshold)));
message_l.put ("multiplier", nano::to_string (nano::difficulty::to_multiplier (difficulty, nano::work_threshold (this_l->version))));
message_l.put ("hash", hash.to_string ());
std::stringstream ostream;
ptree::write_json (ostream, message_l);
Expand Down
Loading

0 comments on commit efd5131

Please sign in to comment.