Skip to content

Commit 39f9b80

Browse files
committed
refactor: De-globalize last notified header index
In future, users of the kernel library might run multiple chainstates in parallel, or create and destroy multiple chainstates over the lifetime of a process. Having static, mutable variables could lead to state inconsistencies in these scenarios.
1 parent 3443943 commit 39f9b80

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/validation.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,16 +3409,15 @@ static bool NotifyHeaderTip(ChainstateManager& chainman) LOCKS_EXCLUDED(cs_main)
34093409
{
34103410
bool fNotify = false;
34113411
bool fInitialBlockDownload = false;
3412-
static CBlockIndex* pindexHeaderOld = nullptr;
34133412
CBlockIndex* pindexHeader = nullptr;
34143413
{
34153414
LOCK(cs_main);
34163415
pindexHeader = chainman.m_best_header;
34173416

3418-
if (pindexHeader != pindexHeaderOld) {
3417+
if (pindexHeader != chainman.m_last_notified_header) {
34193418
fNotify = true;
34203419
fInitialBlockDownload = chainman.IsInitialBlockDownload();
3421-
pindexHeaderOld = pindexHeader;
3420+
chainman.m_last_notified_header = pindexHeader;
34223421
}
34233422
}
34243423
// Send block tip changed notifications without cs_main

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,9 @@ class ChainstateManager
10631063
/** Best header we've seen so far (used for getheaders queries' starting points). */
10641064
CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
10651065

1066+
/** The last header for which a headerTip notification was issued. */
1067+
CBlockIndex* m_last_notified_header GUARDED_BY(::cs_main){nullptr};
1068+
10661069
//! The total number of bytes available for us to use across all in-memory
10671070
//! coins caches. This will be split somehow across chainstates.
10681071
int64_t m_total_coinstip_cache{0};

0 commit comments

Comments
 (0)