mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
kernel: Remove StartShutdown calls from validation code
This change drops the last kernel dependency on shutdown.cpp. It also adds new hooks for libbitcoinkernel applications to be able to interrupt kernel operations when the chain tip changes. This is a refactoring that does not affect behavior. (Looking at the code it can appear like the new break statement in the ActivateBestChain function is a change in behavior, but actually the previous StartShutdown call was indirectly triggering a break before, because it was causing m_chainman.m_interrupt to be true. The new code just makes the break more obvious.)
This commit is contained in:
@@ -11,17 +11,21 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
class ArgsManager;
|
||||
class CBlockIndex;
|
||||
enum class SynchronizationState;
|
||||
struct bilingual_str;
|
||||
|
||||
namespace node {
|
||||
|
||||
static constexpr int DEFAULT_STOPATHEIGHT{0};
|
||||
|
||||
class KernelNotifications : public kernel::Notifications
|
||||
{
|
||||
public:
|
||||
KernelNotifications(std::atomic<int>& exit_status) : m_exit_status{exit_status} {}
|
||||
|
||||
void blockTip(SynchronizationState state, CBlockIndex& index) override;
|
||||
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override;
|
||||
|
||||
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
|
||||
|
||||
@@ -33,11 +37,16 @@ public:
|
||||
|
||||
void fatalError(const std::string& debug_message, const bilingual_str& user_message = {}) override;
|
||||
|
||||
//! Block height after which blockTip notification will return Interrupted{}, if >0.
|
||||
int m_stop_at_height{DEFAULT_STOPATHEIGHT};
|
||||
//! Useful for tests, can be set to false to avoid shutdown on fatal error.
|
||||
bool m_shutdown_on_fatal_error{true};
|
||||
private:
|
||||
std::atomic<int>& m_exit_status;
|
||||
};
|
||||
|
||||
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
|
||||
|
||||
} // namespace node
|
||||
|
||||
#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
|
||||
|
||||
Reference in New Issue
Block a user