kernel: Add notification interface

This commit is part of the libbitcoinkernel project and seeks to remove
the ChainstateManager's and, more generally, the kernel library's
dependency on interface_ui with options methods in this and the following
few commits. By removing interface_ui from the kernel library, its
dependency on boost is reduced to just boost::multi_index.

Define a new kernel notification class with virtual methods for
notifying about internal kernel events. Create a new file in the node
library for defining a function creating the default set of notification
methods such that these do not need to be re-defined all over the
codebase. As a first step, add a `blockTip` method, wrapping
`uiInterface.NotifyBlockTip`.
This commit is contained in:
TheCharlatan
2023-05-10 22:29:17 +02:00
parent 0f8c95dccd
commit 447761c822
13 changed files with 103 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
#include <net.h>
#include <net_processing.h>
#include <netgroup.h>
#include <node/kernel_notifications.h>
#include <policy/fees.h>
#include <scheduler.h>
#include <txmempool.h>

View File

@@ -30,6 +30,8 @@ class WalletLoader;
} // namespace interfaces
namespace node {
class KernelNotifications;
//! NodeContext struct containing references to chain state and connection
//! state.
//!
@@ -62,6 +64,7 @@ struct NodeContext {
interfaces::WalletLoader* wallet_loader{nullptr};
std::unique_ptr<CScheduler> scheduler;
std::function<void()> rpc_interruption_point = [] {};
std::unique_ptr<KernelNotifications> notifications;
//! Declare default constructor and destructor that are not inline, so code
//! instantiating the NodeContext struct doesn't need to #include class

View File

@@ -0,0 +1,16 @@
// 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.
#include <node/kernel_notifications.h>
#include <node/interface_ui.h>
namespace node {
void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
{
uiInterface.NotifyBlockTip(state, &index);
}
} // namespace node

View File

@@ -0,0 +1,21 @@
// 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_NODE_KERNEL_NOTIFICATIONS_H
#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
#include <kernel/notifications_interface.h>
class CBlockIndex;
enum class SynchronizationState;
namespace node {
class KernelNotifications : public kernel::Notifications
{
public:
void blockTip(SynchronizationState state, CBlockIndex& index) override;
};
} // namespace node
#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H