Skip to content

Commit 84d7145

Browse files
committed
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.
1 parent 447761c commit 84d7145

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

src/bitcoin-chainstate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <validationinterface.h>
3333

3434
#include <cassert>
35+
#include <cstdint>
3536
#include <filesystem>
3637
#include <functional>
3738
#include <iosfwd>
@@ -89,6 +90,10 @@ int main(int argc, char* argv[])
8990
{
9091
std::cout << "Block tip changed" << std::endl;
9192
}
93+
void headerTip(SynchronizationState, int64_t height, int64_t timestamp, bool presync) override
94+
{
95+
std::cout << "Header tip changed: " << height << ", " << timestamp << ", " << presync << std::endl;
96+
}
9297
};
9398
auto notifications = std::make_unique<KernelNotifications>();
9499

src/kernel/notifications_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
66
#define BITCOIN_KERNEL_NOTIFICATIONS_INTERFACE_H
77

8+
#include <cstdint>
9+
810
class CBlockIndex;
911
enum class SynchronizationState;
1012

@@ -20,6 +22,7 @@ class Notifications
2022
virtual ~Notifications(){};
2123

2224
virtual void blockTip(SynchronizationState state, CBlockIndex& index) {}
25+
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) {}
2326
};
2427
} // namespace kernel
2528

src/node/kernel_notifications.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& inde
1313
uiInterface.NotifyBlockTip(state, &index);
1414
}
1515

16+
void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
17+
{
18+
uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
19+
}
20+
1621
} // namespace node

src/node/kernel_notifications.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <kernel/notifications_interface.h>
99

10+
#include <cstdint>
11+
1012
class CBlockIndex;
1113
enum class SynchronizationState;
1214

@@ -15,6 +17,8 @@ class KernelNotifications : public kernel::Notifications
1517
{
1618
public:
1719
void blockTip(SynchronizationState state, CBlockIndex& index) override;
20+
21+
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
1822
};
1923
} // namespace node
2024

src/validation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,7 @@ static bool NotifyHeaderTip(Chainstate& chainstate) LOCKS_EXCLUDED(cs_main) {
30973097
}
30983098
// Send block tip changed notifications without cs_main
30993099
if (fNotify) {
3100-
uiInterface.NotifyHeaderTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false);
3100+
chainstate.m_chainman.GetNotifications().headerTip(GetSynchronizationState(fInitialBlockDownload), pindexHeader->nHeight, pindexHeader->nTime, false);
31013101
}
31023102
return fNotify;
31033103
}
@@ -3920,7 +3920,7 @@ void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t
39203920
m_last_presync_update = now;
39213921
}
39223922
bool initial_download = chainstate.IsInitialBlockDownload();
3923-
uiInterface.NotifyHeaderTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
3923+
GetNotifications().headerTip(GetSynchronizationState(initial_download), height, timestamp, /*presync=*/true);
39243924
if (initial_download) {
39253925
const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing};
39263926
const double progress{100.0 * height / (height + blocks_left)};

0 commit comments

Comments
 (0)