From c4ed79a85927054836ee6cb6f8cdb62649c6a2b8 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 3 Jan 2024 13:37:55 -0600 Subject: [PATCH] GH-2021 Simplify pause implementation. --- libraries/chain/controller.cpp | 15 ++++++--------- plugins/net_plugin/net_plugin.cpp | 26 +++----------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index decbce140c..d61c23737e 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -3247,18 +3247,15 @@ fc::sha256 controller::calculate_integrity_hash() { try { void controller::write_snapshot( const snapshot_writer_ptr& snapshot ) { EOS_ASSERT( !my->pending, block_validate_exception, "cannot take a consistent snapshot with a pending block" ); - my->writing_snapshot = true; - try { - my->add_to_snapshot(snapshot); - my->writing_snapshot = false; - } catch(...) { - my->writing_snapshot = false; - throw; - } + my->writing_snapshot.store(true, std::memory_order_release); + fc::scoped_exit> e = [&] { + my->writing_snapshot.store(false, std::memory_order_release); + }; + my->add_to_snapshot(snapshot); } bool controller::is_writing_snapshot() const { - return my->writing_snapshot; + return my->writing_snapshot.load(std::memory_order_acquire); } int64_t controller::set_proposed_producers( vector producers ) { diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index 02d6ec0bf4..ce34dceafd 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -522,11 +522,6 @@ namespace eosio { mutable fc::mutex chain_info_mtx; // protects chain_info_t chain_info_t chain_info GUARDED_BY(chain_info_mtx); - alignas(hardware_destructive_interference_size) - std::mutex pause_mtx; - std::condition_variable pause_cv; - bool paused = false; - public: void update_chain_info(); chain_info_t get_chain_info() const; @@ -542,25 +537,11 @@ namespace eosio { void start_expire_timer(); void start_monitors(); + // we currently pause on snapshot generation void wait_if_paused() { controller& cc = chain_plug->chain(); - if (!cc.is_writing_snapshot()) - return; - - std::unique_lock l(pause_mtx); - paused = true; - while (!pause_cv.wait_for(l, std::chrono::milliseconds(10), [&]{ return !paused; } )) { - if (!cc.is_writing_snapshot()) { - paused = false; - } - } - } - - void unpause() { - std::lock_guard g(pause_mtx); - if (paused) { - paused = false; - pause_cv.notify_all(); + while (cc.is_writing_snapshot()) { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } @@ -3919,7 +3900,6 @@ namespace eosio { // called from application thread void net_plugin_impl::on_accepted_block_header(const block_state_ptr& bs) { - unpause(); update_chain_info(); dispatcher->strand.post([bs]() {