Skip to content

Commit

Permalink
Ensuring confirmed elections are not returned in RPC confirmation_info
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermelawless committed Mar 2, 2020
1 parent 18b6bf0 commit f684f03
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 2 additions & 4 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1842,11 +1842,9 @@ void nano::json_handler::confirmation_info ()
nano::qualified_root root;
if (!root.decode_hex (root_text))
{
nano::lock_guard<std::mutex> lock (node.active.mutex);
auto conflict_info (node.active.roots.find (root));
if (conflict_info != node.active.roots.end ())
auto election (node.active.election (root));
if (election != nullptr && !election->confirmed ())
{
auto election (conflict_info->election);
response_l.put ("announcements", std::to_string (election->confirmation_request_count));
response_l.put ("voters", std::to_string (election->last_votes.size ()));
response_l.put ("last_winner", election->status.winner->hash ().to_string ());
Expand Down
43 changes: 43 additions & 0 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8151,3 +8151,46 @@ TEST (rpc, node_telemetry_self)
ASSERT_EQ (std::error_code (nano::error_rpc::peer_not_found).message (), response.json.get<std::string> ("error"));
}
}

TEST (rpc, confirmation_info)
{
nano::system system;
auto & node1 = *add_ipc_enabled_node (system);
scoped_io_thread_name_change scoped_thread_name_io;
nano::node_rpc_config node_rpc_config;
nano::ipc::ipc_server ipc_server (node1, node_rpc_config);
nano::rpc_config rpc_config (nano::get_available_port (), true);
rpc_config.rpc_process.ipc_port = node1.config.ipc_config.transport_tcp.port;
nano::ipc_rpc_processor ipc_rpc_processor (system.io_ctx, rpc_config);
nano::rpc rpc (system.io_ctx, rpc_config, ipc_rpc_processor);
rpc.start ();

nano::genesis genesis;
auto send (std::make_shared<nano::send_block> (genesis.hash (), nano::public_key (), nano::genesis_amount - 100, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.work.generate (genesis.hash ())));
node1.process_active (send);
node1.block_processor.flush ();
ASSERT_FALSE (node1.active.empty ());

boost::property_tree::ptree request;
request.put ("action", "confirmation_info");
request.put ("root", send->qualified_root ().to_string ());
request.put ("representatives", "true");
request.put ("json_block", "true");
{
test_response response (request, rpc.config.port, system.io_ctx);
system.deadline_set (5s);
while (response.status == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (200, response.status);
ASSERT_EQ (1, response.json.count ("announcements"));
ASSERT_EQ (1, response.json.get<unsigned> ("voters"));
ASSERT_EQ (send->hash ().to_string (), response.json.get<std::string> ("last_winner"));
auto & blocks (response.json.get_child ("blocks"));
ASSERT_EQ (1, blocks.size ());
auto & representatives (blocks.front ().second.get_child ("representatives"));
ASSERT_EQ (1, representatives.size ());
ASSERT_EQ (0, response.json.get<unsigned> ("total_tally"));
}
}

0 comments on commit f684f03

Please sign in to comment.