Skip to content

Commit

Permalink
Update confirmation height in another thread (#1877)
Browse files Browse the repository at this point in the history
* Move confirmation height updating to another thread

* Fix Linux/gcc build

* Formatting

* Re-add equal comparison

* Use pessimistic approach for updating confirmation heights

* Pop pending confirmation before using it (like previously)

* Add confirmation height stats

* Add to memory stats RPC

* Rename confirmation_height_processor.hpp/cpp to remove underscores

* Add minor optimization to reuse a potential unncessary read

* Fix build removing underscores when including the files

* Change open_receive to receive to improve readability

* Check if processor is stopped and exit early in inner do-while loop

* Revert to checking active roots by default if ledger.blocks_confirmed returns false

* Use node store not wallet in wallet_pending

* Change back to using underscores for filenames

* Only start confirming frontiers when there aren't many confirmations pending already

* Formatting

* Forgot to add the newly extracted pending_confirmation_height to the node's memory stats

* Memory stats RPC can take a while if the confirmation height processor is on a long chain

* Add CLI --debug_block_cemented_count

* Add break to confirmation_height_processing thread name setting

* Check confirmation height processing queue in RPCs block_info and blocks_info when returning confirmed status

* Write in batches

* Fix assert build issue

* Add "include_only_confirmed" option to rpc tests

* Fix num_blocks_process issue

* Add tests for recursive chains, long chains and all block types

* Formatting

* Use new helper function in various places to check whether a block has been confirmed

* Review comments

* Formatting

* Protect the current hash

* Update comment placement

* Correctly confirm all the blocks before the first encountered receive block starting from the original block being confirmed

* Make sure lock () is always set when exiting do while loop

* Replace std::mutex for receive_source_pairs with a cached atomic with the size

* Remove ledger dependency

* Add unstable/debug RPC command confirmation_height_currently_processing to see what hash is currently ungoing confirmation height processing

* Send intentionally unpocketed transactions to a new account to prevent the tested accounts auto receiving the blocks

* Make the last confirmation part of the do-while loop

* Check for is_zero and epoch link

* Make sure the confirmation height processing is done before sending the RPC request to reduce timing issues with ci.

* Give all parameters _a suffix

* Make block_confirmed in rpc_handler have a single return at end

* Make receive_source_pairs_size == 0 an assert instead of release_assert

* Formatting

* Formatting
  • Loading branch information
wezrule authored Apr 24, 2019
1 parent f5a4581 commit 0b9007f
Show file tree
Hide file tree
Showing 21 changed files with 1,843 additions and 847 deletions.
256 changes: 240 additions & 16 deletions nano/core_test/network.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions nano/lib/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ std::string nano::error_rpc_messages::message (int ev) const
return "Representative account and previous hash required";
case nano::error_rpc::block_create_requirements_send:
return "Destination account, previous hash, current balance and amount required";
case nano::error_rpc::confirmation_height_not_processing:
return "There are no blocks currently being processed for adding confirmation height";
case nano::error_rpc::confirmation_not_found:
return "Active confirmation not found";
case nano::error_rpc::difficulty_limit:
Expand Down
1 change: 1 addition & 0 deletions nano/lib/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ enum class error_rpc
block_create_requirements_receive,
block_create_requirements_change,
block_create_requirements_send,
confirmation_height_not_processing,
confirmation_not_found,
difficulty_limit,
invalid_balance,
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ namespace thread_role
case nano::thread_role::name::rpc_process_container:
thread_role_name_string = "RPC process";
break;
case nano::thread_role::name::confirmation_height_processing:
thread_role_name_string = "Conf height";
break;
}

/*
Expand Down
3 changes: 2 additions & 1 deletion nano/lib/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ namespace thread_role
signature_checking,
rpc_request_processor,
rpc_process_container,
work_watcher
work_watcher,
confirmation_height_processing
};
/*
* Get/Set the identifier for the current thread
Expand Down
15 changes: 14 additions & 1 deletion nano/nano_node/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int main (int argc, char * const * argv)
("debug_random_feed", "Generates output to RNG test suites")
("debug_validate_blocks", "Check all blocks for correct hash, signature, work value")
("debug_peers", "Display peer IPv6:port connections")
("debug_ipc", "Read an IPC command in JSON from stdin and invoke it. Network operations will have no effect")
("debug_cemented_block_count", "Displays the number of cemented (confirmed) blocks")
("platform", boost::program_options::value<std::string> (), "Defines the <platform> for OpenCL commands")
("device", boost::program_options::value<std::string> (), "Defines <device> for OpenCL command")
("threads", boost::program_options::value<std::string> (), "Defines <threads> count for OpenCL command")
Expand Down Expand Up @@ -960,6 +960,19 @@ int main (int argc, char * const * argv)
std::cout << boost::str (boost::format ("%1%\n") % nano::endpoint (boost::asio::ip::address_v6 (i->first.address_bytes ()), i->first.port ()));
}
}
else if (vm.count ("debug_cemented_block_count"))
{
nano::inactive_node node (data_path);
auto transaction (node.node->store.tx_begin ());

uint64_t sum = 0;
for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i)
{
nano::account_info info (i->second);
sum += info.confirmation_height;
}
std::cout << "Total cemented block count: " << sum << std::endl;
}
else if (vm.count ("version"))
{
if (NANO_VERSION_PATCH == 0)
Expand Down
7 changes: 6 additions & 1 deletion nano/node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ endif ()

add_library (node
${platform_sources}
active_transactions.hpp
active_transactions.cpp
blockprocessor.cpp
blockprocessor.hpp
blockprocessor.cpp
bootstrap.hpp
Expand All @@ -20,8 +23,10 @@ add_library (node
cli.cpp
common.hpp
common.cpp
daemonconfig.cpp
confirmation_height_processor.hpp
confirmation_height_processor.cpp
daemonconfig.hpp
daemonconfig.cpp
ipc.hpp
ipc.cpp
ipcconfig.hpp
Expand Down
Loading

0 comments on commit 0b9007f

Please sign in to comment.