Skip to content

Commit

Permalink
Merge branch 'develop' into signature_verification
Browse files Browse the repository at this point in the history
  • Loading branch information
wezrule committed Feb 27, 2020
2 parents bf61be1 + 6db4625 commit 72519d9
Show file tree
Hide file tree
Showing 39 changed files with 320 additions and 436 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
#set(CMAKE_C_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 14)
set(NANO_SUPPORTED_CPP_STANDARD "17" CACHE STRING "Supported C++ standard (14 or 17)")
if (CI_BUILD OR CI_TEST)
set(NANO_SUPPORTED_CPP_STANDARD "14")
endif()
set(CMAKE_CXX_STANDARD ${NANO_SUPPORTED_CPP_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
68 changes: 0 additions & 68 deletions nano/core_test/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ TEST (active_transactions, keep_local)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (0, node.active.dropped_elections_cache_size ());
while (!node.active.empty ())
{
nano::lock_guard<std::mutex> active_guard (node.active.mutex);
Expand All @@ -276,7 +275,6 @@ TEST (active_transactions, keep_local)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (1, node.active.dropped_elections_cache_size ());
}

TEST (active_transactions, prioritize_chains)
Expand Down Expand Up @@ -571,72 +569,6 @@ TEST (active_transactions, update_difficulty)
}
}

TEST (active_transactions, restart_dropped)
{
nano::system system;
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.enable_voting = false;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node = *system.add_node (node_config);
nano::genesis genesis;
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::xrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
// Process only in ledger and emulate dropping the election
ASSERT_EQ (nano::process_result::progress, node.process (*send1).code);
{
nano::lock_guard<std::mutex> guard (node.active.mutex);
node.active.add_dropped_elections_cache (send1->qualified_root ());
}
uint64_t difficulty1 (0);
nano::work_validate (*send1, &difficulty1);
// Generate higher difficulty work
auto work2 (*system.work.generate (send1->root (), difficulty1));
uint64_t difficulty2 (0);
nano::work_validate (send1->root (), work2, &difficulty2);
ASSERT_GT (difficulty2, difficulty1);
// Process the same block with updated work
auto send2 (std::make_shared<nano::state_block> (*send1));
send2->block_work_set (work2);
node.process_active (send2);
// Wait until the block is in elections
system.deadline_set (5s);
bool done{ false };
while (!done)
{
{
nano::lock_guard<std::mutex> guard (node.active.mutex);
auto existing (node.active.roots.find (send2->qualified_root ()));
done = existing != node.active.roots.end ();
if (done)
{
ASSERT_EQ (difficulty2, existing->difficulty);
}
}
ASSERT_NO_ERROR (system.poll ());
}
std::shared_ptr<nano::block> block;
while (block == nullptr)
{
ASSERT_NO_ERROR (system.poll ());
block = node.store.block_get (node.store.tx_begin_read (), send1->hash ());
}
ASSERT_EQ (work2, block->block_work ());
// Drop election
node.active.erase (*send2);
// Try to restart election with the lower difficulty block, should not work since the block as lower work
node.process_active (send1);
system.deadline_set (5s);
while (node.block_processor.size () > 0)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_TRUE (node.active.empty ());
// Verify the block was not updated in the ledger
{
auto block (node.store.block_get (node.store.tx_begin_read (), send1->hash ()));
ASSERT_EQ (work2, block->block_work ());
}
}

TEST (active_transactions, vote_replays)
{
nano::system system;
Expand Down
9 changes: 9 additions & 0 deletions nano/core_test/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ TEST (state_block, hashing)
ASSERT_EQ (hash, block.hash ());
}

TEST (blocks, work_version)
{
ASSERT_EQ (nano::work_version::work_1, nano::send_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::receive_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::change_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::open_block ().work_version ());
ASSERT_EQ (nano::work_version::work_1, nano::state_block ().work_version ());
}

TEST (block_uniquer, null)
{
nano::block_uniquer uniquer;
Expand Down
20 changes: 7 additions & 13 deletions nano/core_test/confirmation_height.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,6 @@ TEST (confirmation_height, dependent_election)

add_callback_stats (*node);

// Prevent the confirmation height processor from doing any processing
node->confirmation_height_processor.pause ();

// Wait until it has been processed
node->block_confirm (send2);
system.deadline_set (10s);
Expand All @@ -1182,20 +1179,17 @@ TEST (confirmation_height, dependent_election)
ASSERT_NO_ERROR (system.poll ());
}

system.deadline_set (10s);
while (node->confirmation_height_processor.awaiting_processing_size () != 1)
{
ASSERT_NO_ERROR (system.poll ());
}

{
nano::lock_guard<std::mutex> guard (node->confirmation_height_processor.mutex);
ASSERT_EQ (*node->confirmation_height_processor.awaiting_processing.begin (), send2->hash ());
// The write guard prevents the confirmation height processor doing any writes.
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))
{
ASSERT_NO_ERROR (system.poll ());
}
}

// Now put the other block in active so it can be confirmed as a dependent election
node->block_confirm (send1);
node->confirmation_height_processor.unpause ();

system.deadline_set (10s);
while (node->stats.count (nano::stat::type::http_callback, nano::stat::detail::http_callback, nano::stat::dir::out) != 3)
Expand Down
12 changes: 7 additions & 5 deletions nano/core_test/confirmation_solicitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ TEST (confirmation_solicitor, batches)
nano::node_config node_config (nano::get_available_port (), system.logging);
node_config.enable_voting = false;
node_config.frontiers_confirmation = nano::frontiers_confirmation_mode::disabled;
auto & node1 = *system.add_node (node_config);
auto channel1 (node1.network.udp_channels.create (node1.network.endpoint ()));
// Solicitor will only solicit from this representative
nano::representative representative (nano::test_genesis_key.pub, nano::genesis_amount, channel1);
node_config.peering_port = nano::get_available_port ();
nano::node_flags node_flags;
node_flags.disable_udp = false;
auto & node1 = *system.add_node (node_config, node_flags);
node_config.peering_port = nano::get_available_port ();
// To prevent races on the solicitor
node_flags.disable_request_loop = true;
auto & node2 = *system.add_node (node_config, node_flags);
// Solicitor will only solicit from this representative
auto channel1 (node2.network.udp_channels.create (node1.network.endpoint ()));
nano::representative representative (nano::test_genesis_key.pub, nano::genesis_amount, channel1);
// Lock active_transactions which uses the solicitor
{
nano::lock_guard<std::mutex> active_guard (node2.active.mutex);
Expand All @@ -43,6 +44,7 @@ TEST (confirmation_solicitor, batches)
// Broadcasting should be immediate
ASSERT_EQ (0, node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::out));
ASSERT_FALSE (node2.active.solicitor.broadcast (*election));
system.deadline_set (5s);
while (node2.stats.count (nano::stat::type::message, nano::stat::detail::publish, nano::stat::dir::out) < 1)
{
ASSERT_NO_ERROR (system.poll ());
Expand Down
10 changes: 5 additions & 5 deletions nano/core_test/distributed_work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST (distributed_work, no_peers)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_FALSE (nano::work_validate (hash, *work));
ASSERT_FALSE (nano::work_validate (nano::work_version::work_1, hash, *work));
// should only be removed after cleanup
ASSERT_EQ (1, node->distributed_work.items.size ());
while (!node->distributed_work.items.empty ())
Expand Down Expand Up @@ -177,7 +177,7 @@ TEST (distributed_work, peer)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_FALSE (nano::work_validate (hash, *work));
ASSERT_FALSE (nano::work_validate (nano::work_version::work_1, hash, *work));
ASSERT_EQ (1, work_peer->generations_good);
ASSERT_EQ (0, work_peer->generations_bad);
ASSERT_NO_ERROR (system.poll ());
Expand Down Expand Up @@ -207,7 +207,7 @@ TEST (distributed_work, peer_malicious)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_FALSE (nano::work_validate (hash, *work));
ASSERT_FALSE (nano::work_validate (nano::work_version::work_1, hash, *work));
system.deadline_set (5s);
while (malicious_peer->generations_bad < 1)
{
Expand Down Expand Up @@ -265,7 +265,7 @@ TEST (distributed_work, peer_multi)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_FALSE (nano::work_validate (hash, *work));
ASSERT_FALSE (nano::work_validate (nano::work_version::work_1, hash, *work));
system.deadline_set (5s);
while (slow_peer->cancels < 1)
{
Expand Down Expand Up @@ -304,5 +304,5 @@ TEST (distributed_work, fail_resolve)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_FALSE (nano::work_validate (hash, *work));
ASSERT_FALSE (nano::work_validate (nano::work_version::work_1, hash, *work));
}
17 changes: 11 additions & 6 deletions nano/core_test/fakes/work_peer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne
const std::string empty_response = "Empty response";

public:
work_peer_connection (asio::io_context & ioc_a, work_peer_type const type_a, nano::work_pool & pool_a, std::function<void(bool const)> on_generation_a, std::function<void()> on_cancel_a) :
work_peer_connection (asio::io_context & ioc_a, work_peer_type const type_a, nano::work_version const version_a, nano::work_pool & pool_a, std::function<void(bool const)> on_generation_a, std::function<void()> on_cancel_a) :
socket (ioc_a),
type (type_a),
version (version_a),
work_pool (pool_a),
on_generation (on_generation_a),
on_cancel (on_cancel_a),
Expand All @@ -53,6 +54,7 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne

private:
work_peer_type type;
nano::work_version version;
nano::work_pool & work_pool;
beast::flat_buffer buffer{ 8192 };
http::request<http::string_body> request;
Expand Down Expand Up @@ -130,10 +132,10 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne
{
auto hash = hash_a;
auto this_l (shared_from_this ());
work_pool.generate (hash, [this_l, hash](boost::optional<uint64_t> work_a) {
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 (hash, result, &difficulty);
nano::work_validate (this_l->version, hash, result, &difficulty);
static nano::network_params params;
ptree::ptree message_l;
message_l.put ("work", nano::to_string_hex (result));
Expand Down Expand Up @@ -188,12 +190,14 @@ class work_peer_connection : public std::enable_shared_from_this<work_peer_conne
class fake_work_peer : public std::enable_shared_from_this<fake_work_peer>
{
public:
fake_work_peer (nano::work_pool & pool_a, asio::io_context & ioc_a, unsigned short port_a, work_peer_type const type_a) :
fake_work_peer () = delete;
fake_work_peer (nano::work_pool & pool_a, asio::io_context & ioc_a, unsigned short port_a, work_peer_type const type_a, nano::work_version const version_a = nano::work_version::work_1) :
pool (pool_a),
endpoint (tcp::v4 (), port_a),
ioc (ioc_a),
acceptor (ioc_a, endpoint),
type (type_a)
type (type_a),
version (version_a)
{
}
void start ()
Expand All @@ -213,7 +217,7 @@ class fake_work_peer : public std::enable_shared_from_this<fake_work_peer>
{
std::weak_ptr<fake_work_peer> this_w (shared_from_this ());
auto connection (std::make_shared<work_peer_connection> (
ioc, type, pool,
ioc, type, version, pool,
[this_w](bool const good_generation) {
if (auto this_l = this_w.lock ())
{
Expand Down Expand Up @@ -249,5 +253,6 @@ class fake_work_peer : public std::enable_shared_from_this<fake_work_peer>
asio::io_context & ioc;
tcp::acceptor acceptor;
work_peer_type const type;
nano::work_version version;
};
}
Loading

0 comments on commit 72519d9

Please sign in to comment.