mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
Merge bitcoin/bitcoin#28051: Get rid of shutdown.cpp/shutdown.h, use SignalInterrupt directly
6db04be102Get rid of shutdown.cpp/shutdown.h, use SignalInterrupt directly (Ryan Ofsky)213542b625refactor: Add InitContext function to initialize NodeContext with global pointers (Ryan Ofsky)feeb7b816arefactor: Remove calls to StartShutdown from KernelNotifications (Ryan Ofsky)6824eecaf1refactor: Remove call to StartShutdown from stop RPC (Ryan Ofsky)1d92d89edbutil: Get rid of uncaught exceptions thrown by SignalInterrupt class (Ryan Ofsky)ba93966368refactor: Remove call to ShutdownRequested from IndexWaitSynced (Ryan Ofsky)42e5829d97refactor: Remove call to ShutdownRequested from HTTPRequest (Ryan Ofsky)73133c36aarefactor: Add NodeContext::shutdown member (Ryan Ofsky)f4a8bd6e2frefactor: Remove call to StartShutdown from qt (Ryan Ofsky)f0c73c1336refactor: Remove call to ShutdownRequested from rpc/mining (Ryan Ofsky)263b23f008refactor: Remove call to ShutdownRequested from chainstate init (Ryan Ofsky) Pull request description: This change drops `shutdown.h` and `shutdown.cpp` files, replacing them with a `NodeContext::shutdown` member which is used to trigger shutdowns directly. This gets rid of an unnecessary layer of indirection, and allows getting rid of the `kernel::g_context` global. Additionally, this PR tries to improve error handling of `SignalInterrupt` code by marking relevant methods `[[nodiscard]]` to avoid the possibility of uncaught exceptions mentioned https://github.com/bitcoin/bitcoin/pull/27861#discussion_r1255496707. Behavior is changing In a few cases which are noted in individual commit messages. Particularly: GUI code more consistently interrupts RPCs when it is shutting down, shutdown state no longer persists between unit tests, the stop RPC now returns an RPC error if requesting shutdown fails instead of aborting, and other failed shutdown calls now log errors instead of aborting. This PR is a net reduction in lines of code, but in some cases the explicit error handling and lack of global shutdown functions do make it more verbose. The verbosity can be seen as good thing if it discourages more code from directly triggering shutdowns, and instead encourages code to return errors or send notifications that could be translated into shutdowns. Probably a number of existing shutdown calls could just be replaced by better error handling. ACKs for top commit: achow101: ACK6db04be102TheCharlatan: Re-ACK6db04be102maflcko: ACK6db04be102👗 stickies-v: re-ACK6db04be102Tree-SHA512: 7a34cb69085f37e813c43bdaded1a0cbf6c53bd95fdde96f0cb45346127fc934604c43bccd3328231ca2f1faf712a7418d047ceabd22ef2dca3c32ebb659e634
This commit is contained in:
@@ -5,16 +5,16 @@
|
||||
#include <test/util/index.h>
|
||||
|
||||
#include <index/base.h>
|
||||
#include <shutdown.h>
|
||||
#include <util/check.h>
|
||||
#include <util/signalinterrupt.h>
|
||||
#include <util/time.h>
|
||||
|
||||
void IndexWaitSynced(const BaseIndex& index)
|
||||
void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt)
|
||||
{
|
||||
while (!index.BlockUntilSyncedToCurrentChain()) {
|
||||
// Assert shutdown was not requested to abort the test, instead of looping forever, in case
|
||||
// there was an unexpected error in the index that caused it to stop syncing and request a shutdown.
|
||||
Assert(!ShutdownRequested());
|
||||
Assert(!interrupt);
|
||||
|
||||
UninterruptibleSleep(100ms);
|
||||
}
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
#define BITCOIN_TEST_UTIL_INDEX_H
|
||||
|
||||
class BaseIndex;
|
||||
namespace util {
|
||||
class SignalInterrupt;
|
||||
} // namespace util
|
||||
|
||||
/** Block until the index is synced to the current chain */
|
||||
void IndexWaitSynced(const BaseIndex& index);
|
||||
void IndexWaitSynced(const BaseIndex& index, const util::SignalInterrupt& interrupt);
|
||||
|
||||
#endif // BITCOIN_TEST_UTIL_INDEX_H
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <rpc/server.h>
|
||||
#include <scheduler.h>
|
||||
#include <script/sigcache.h>
|
||||
#include <shutdown.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/net.h>
|
||||
#include <test/util/random.h>
|
||||
@@ -102,6 +101,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
|
||||
: m_path_root{fs::temp_directory_path() / "test_common_" PACKAGE_NAME / g_insecure_rand_ctx_temp_path.rand256().ToString()},
|
||||
m_args{}
|
||||
{
|
||||
m_node.shutdown = &m_interrupt;
|
||||
m_node.args = &gArgs;
|
||||
std::vector<const char*> arguments = Cat(
|
||||
{
|
||||
@@ -179,7 +179,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
|
||||
|
||||
m_cache_sizes = CalculateCacheSizes(m_args);
|
||||
|
||||
m_node.notifications = std::make_unique<KernelNotifications>(m_node.exit_status);
|
||||
m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status);
|
||||
|
||||
const ChainstateManager::Options chainman_opts{
|
||||
.chainparams = chainparams,
|
||||
@@ -194,7 +194,7 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
|
||||
.blocks_dir = m_args.GetBlocksDirPath(),
|
||||
.notifications = chainman_opts.notifications,
|
||||
};
|
||||
m_node.chainman = std::make_unique<ChainstateManager>(m_node.kernel->interrupt, chainman_opts, blockman_opts);
|
||||
m_node.chainman = std::make_unique<ChainstateManager>(*Assert(m_node.shutdown), chainman_opts, blockman_opts);
|
||||
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<BlockTreeDB>(DBParams{
|
||||
.path = m_args.GetDataDirNet() / "blocks" / "index",
|
||||
.cache_bytes = static_cast<size_t>(m_cache_sizes.block_tree_db),
|
||||
|
||||
@@ -47,6 +47,7 @@ static constexpr CAmount CENT{1000000};
|
||||
* This just configures logging, data dir and chain parameters.
|
||||
*/
|
||||
struct BasicTestingSetup {
|
||||
util::SignalInterrupt m_interrupt;
|
||||
node::NodeContext m_node; // keep as first member to be destructed last
|
||||
|
||||
explicit BasicTestingSetup(const ChainType chainType = ChainType::MAIN, const std::vector<const char*>& extra_args = {});
|
||||
|
||||
Reference in New Issue
Block a user