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

@@ -12,6 +12,7 @@
// It is part of the libbitcoinkernel project.
#include <kernel/chainparams.h>
#include <kernel/chainstatemanager_opts.h>
#include <kernel/checks.h>
#include <kernel/context.h>
#include <kernel/validation_cache_sizes.h>
@@ -34,6 +35,7 @@
#include <filesystem>
#include <functional>
#include <iosfwd>
#include <memory>
int main(int argc, char* argv[])
{
@@ -80,12 +82,22 @@ int main(int argc, char* argv[])
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
class KernelNotifications : public kernel::Notifications
{
public:
void blockTip(SynchronizationState, CBlockIndex&) override
{
std::cout << "Block tip changed" << std::endl;
}
};
auto notifications = std::make_unique<KernelNotifications>();
// SETUP: Chainstate
const ChainstateManager::Options chainman_opts{
.chainparams = *chainparams,
.datadir = gArgs.GetDataDirNet(),
.adjusted_time_callback = NodeClock::now,
.notifications = *notifications,
};
const node::BlockManager::Options blockman_opts{
.chainparams = chainman_opts.chainparams,