Skip to content

Commit

Permalink
Don't process transactions/blocks when the working thread is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela committed Dec 2, 2024
1 parent 8176991 commit 960ccd6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
15 changes: 12 additions & 3 deletions libraries/appbase/include/appbase/shutdown_mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace hive {
std::map< hive_p2p_handler_type, shutdown_state::ptr_shutdown_state > states;

appbase::application& theApp;

plugins::chain::chain_plugin& chain;

const char* fStatus(std::future_status s)
{
Expand Down Expand Up @@ -122,8 +124,8 @@ namespace hive {

public:

shutdown_mgr( std::string _name, appbase::application& app )
: name( _name ), running( true ), theApp( app )
shutdown_mgr( std::string _name, appbase::application& app, plugins::chain::chain_plugin& chain )
: name( _name ), running( true ), theApp( app ), chain( chain )
{
std::map< hive_p2p_handler_type, std::string > input = {
{ hive_p2p_handler_type::HIVE_P2P_BLOCK_HANDLER, "P2P_BLOCK" },
Expand Down Expand Up @@ -171,7 +173,14 @@ namespace hive {

bool is_running() const
{
return running.load() && !theApp.is_interrupt_request();
/*
Explanation of `is_finished_write_processing`.
Sometimes stopping of the working thread is triggered by SIGINT, but sometimes by CLI parameteres like `stop-at-block`.
We have to have certanity that the working thread is closed regardless of a reason,
so the best option is to wait for SIGINT and a real finish of the working thread.
*/
return running.load() && !theApp.is_interrupt_request() && !chain.is_finished_write_processing();
}

shutdown_state& get_state( hive_p2p_handler_type handler )
Expand Down
6 changes: 6 additions & 0 deletions libraries/plugins/chain/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,4 +2069,10 @@ void chain_plugin::finish_request()
{
my->finish_request();
}

bool chain_plugin::is_finished_write_processing() const
{
return my->finish.status.load();
}

} } } // namespace hive::plugis::chain::chain_apis
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class chain_plugin : public plugin< chain_plugin >
void disable_p2p( bool also_disable_work = true ) const;

void finish_request();
bool is_finished_write_processing() const;

private:
std::unique_ptr< detail::chain_plugin_impl, detail::chain_plugin_impl_deleter > my;
Expand Down
2 changes: 1 addition & 1 deletion libraries/plugins/p2p/p2p_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class p2p_plugin_impl : public graphene::net::node_delegate
public:

p2p_plugin_impl( plugins::chain::chain_plugin& c, appbase::application& app )
: shutdown_helper( "P2P plugin", c.get_app() ), chain( c ), theApp( app )
: shutdown_helper( "P2P plugin", c.get_app(), c ), chain( c ), theApp( app )
{
}
virtual ~p2p_plugin_impl()
Expand Down

0 comments on commit 960ccd6

Please sign in to comment.