mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-02 03:31:09 +00:00
Instead of having separate warning functions (and globals) for each different warning that can be raised, encapsulate this logic into a single class and allow to (un)set any number of warnings. Introduces behaviour change: - the `-alertnotify` command is executed for all `KernelNotifications::warningSet` calls, which now also covers the `LARGE_WORK_INVALID_CHAIN` warning. - previously, warnings were returned based on a predetermined order, e.g. with the "pre-release test build" warning always first. This is no longer the case, and Warnings::GetMessages() will return messages sorted by the id of the warning. Removes warnings.cpp from kernel.
66 lines
2.5 KiB
C++
66 lines
2.5 KiB
C++
// Copyright (c) 2023 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
|
|
#define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
|
|
|
|
#include <cstdint>
|
|
#include <variant>
|
|
|
|
class CBlockIndex;
|
|
enum class SynchronizationState;
|
|
struct bilingual_str;
|
|
|
|
namespace kernel {
|
|
|
|
//! Result type for use with std::variant to indicate that an operation should be interrupted.
|
|
struct Interrupted{};
|
|
enum class Warning;
|
|
|
|
|
|
//! Simple result type for functions that need to propagate an interrupt status and don't have other return values.
|
|
using InterruptResult = std::variant<std::monostate, Interrupted>;
|
|
|
|
template <typename T>
|
|
bool IsInterrupted(const T& result)
|
|
{
|
|
return std::holds_alternative<kernel::Interrupted>(result);
|
|
}
|
|
|
|
/**
|
|
* A base class defining functions for notifying about certain kernel
|
|
* events.
|
|
*/
|
|
class Notifications
|
|
{
|
|
public:
|
|
virtual ~Notifications(){};
|
|
|
|
[[nodiscard]] virtual InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) { return {}; }
|
|
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
|
|
virtual void progress(const bilingual_str& title, int progress_percent, bool resume_possible) {}
|
|
virtual void warningSet(Warning id, const bilingual_str& message) {}
|
|
virtual void warningUnset(Warning id) {}
|
|
|
|
//! The flush error notification is sent to notify the user that an error
|
|
//! occurred while flushing block data to disk. Kernel code may ignore flush
|
|
//! errors that don't affect the immediate operation it is trying to
|
|
//! perform. Applications can choose to handle the flush error notification
|
|
//! by logging the error, or notifying the user, or triggering an early
|
|
//! shutdown as a precaution against causing more errors.
|
|
virtual void flushError(const bilingual_str& message) {}
|
|
|
|
//! The fatal error notification is sent to notify the user when an error
|
|
//! occurs in kernel code that can't be recovered from. After this
|
|
//! notification is sent, whatever function triggered the error should also
|
|
//! return an error code or raise an exception. Applications can choose to
|
|
//! handle the fatal error notification by logging the error, or notifying
|
|
//! the user, or triggering an early shutdown as a precaution against
|
|
//! causing more errors.
|
|
virtual void fatalError(const bilingual_str& message) {}
|
|
};
|
|
} // namespace kernel
|
|
|
|
#endif // BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
|