0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

kernel: Add headerTip method to notifications

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.
This commit is contained in:
TheCharlatan 2023-05-10 22:35:49 +02:00
parent 447761c822
commit 84d71457e7
No known key found for this signature in database
GPG key ID: 9B79B45691DB4173
5 changed files with 19 additions and 2 deletions

View file

@ -32,6 +32,7 @@
#include <validationinterface.h> #include <validationinterface.h>
#include <cassert> #include <cassert>
#include <cstdint>
#include <filesystem> #include <filesystem>
#include <functional> #include <functional>
#include <iosfwd> #include <iosfwd>
@ -89,6 +90,10 @@ int main(int argc, char* argv[])
{ {
std::cout << "Block tip changed" << std::endl; std::cout << "Block tip changed" << std::endl;
} }
void headerTip(SynchronizationState, int64_t height, int64_t timestamp, bool presync) override
{
std::cout << "Header tip changed: " << height << ", " << timestamp << ", " << presync << std::endl;
}
}; };
auto notifications = std::make_unique<KernelNotifications>(); auto notifications = std::make_unique<KernelNotifications>();

View file

@ -5,6 +5,8 @@
#ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H #ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
#define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H #define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
#include <cstdint>
class CBlockIndex; class CBlockIndex;
enum class SynchronizationState; enum class SynchronizationState;
@ -20,6 +22,7 @@ public:
virtual ~Notifications(){}; virtual ~Notifications(){};
virtual void blockTip(SynchronizationState state, CBlockIndex& index) {} virtual void blockTip(SynchronizationState state, CBlockIndex& index) {}
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
}; };
} // namespace kernel } // namespace kernel

View file

@ -13,4 +13,9 @@ void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& inde
uiInterface.NotifyBlockTip(state, &index); uiInterface.NotifyBlockTip(state, &index);
} }
void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
{
uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
}
} // namespace node } // namespace node

View file

@ -7,6 +7,8 @@
#include <kernel/notifications_interface.h> #include <kernel/notifications_interface.h>
#include <cstdint>
class CBlockIndex; class CBlockIndex;
enum class SynchronizationState; enum class SynchronizationState;
@ -15,6 +17,8 @@ class KernelNotifications : public kernel::Notifications
{ {
public: public:
void blockTip(SynchronizationState state, CBlockIndex& index) override; void blockTip(SynchronizationState state, CBlockIndex& index) override;
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
}; };
} // namespace node } // namespace node

View file

@ -3097,7 +3097,7 @@ static bool NotifyHeaderTip(Chainstate& chainstate) LOCKS_EXCLUDED(cs_main) {
} }
// Send block tip changed notifications without cs_main // Send block tip changed notifications without cs_main
if (fNotify) { if (fNotify) {
uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false); chainstate.m_chainman.GetNotifications().headerTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false);
} }
return fNotify; return fNotify;
} }
@ -3920,7 +3920,7 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t
m_last_presync_update = now; m_last_presync_update = now;
} }
bool initial_download = chainstate.IsInitialBlockDownload(); bool initial_download = chainstate.IsInitialBlockDownload();
uiInterface.NotifyHeaderTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true); GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
if (initial_download) { if (initial_download) {
const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing}; const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing};
const double progress{100.0 * height / (height + blocks_left)}; const double progress{100.0 * height / (height + blocks_left)};