2 minor findings · 4 suggestions
Earlier concerns neither republished nor resolved: 1 minor finding · 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Per-manager clock cannot control chainstate startup
The setter is unavailable until after chainstate loading, so startup future-tip checks, the first IBD latch evaluation, and initial blockTip progress use the global mock or system clock.
Location: src/node/chainstate.cpp:251 (head).
Details and suggested fix
btck_chainstate_manager_create() loads and verifies chainstate and activates the best chain before returning the handle required by btck_chainstate_manager_set_clock_time(). Until then, m_clock_now_seconds is zero, so chainman.Now() uses the global mock or system clock. That clock determines the future-tip check, the UpdateIBDStatus() call in LoadChainTip(), and the initial blockTip progress value.
For example, an application can set a simulated future clock and persist regtest blocks dated more than two hours ahead of host time, but reopening that datadir fails with “The block database contains a block which appears to be from the future.” The per-manager API cannot control this check; setting btck_set_mock_time() first is the only available workaround, but it gives up per-manager isolation. The IBD latch can likewise become false based on wall-clock time and never reset, despite the header documenting that the setter covers the latch and block-tip progress.
Accept an initial clock value in btck_ChainstateManagerOptions and store it in m_clock_now_seconds before LoadChainstate(). If that is out of scope, document that creation-time checks and notifications use the global or system clock.
[minor] · Extreme -mempoolexpiry values can overflow on every mempool admission
At -mempoolexpiry values of 2,562,048 hours or more, cutoff calculation has signed-overflow undefined behavior on every admission; the base version encountered this only while loading the mempool.
Location: src/validation.cpp:271 (head).
Details and suggested fix
The base version computed the expiry cutoff in seconds, while this version subtracts the seconds-valued expiry from pool.Now(), a MempoolTime point that uses signed 64-bit nanoseconds on libstdc++. Converting the expiry to nanoseconds overflows above about 9.22e9 seconds, or 2,562,048 hours, and ApplyArgsManOptions accepts any value. LimitMempoolSize() runs on every non-bypass single-transaction admission and after reorg re-adds.
With -mempoolexpiry=9999999, a wrapped cutoff can be about 28 years in the future. Expire() then removes every entry, including the newly added one, and the transaction is rejected as “mempool full.” Because the arithmetic has undefined behavior, the actual result depends on code generation. Coarser clocks such as libc++ or MSVC overflow at higher values. The base version had the same overflow during LoadMempool, but not on each admission. No default or checked-in caller supplies such a value, so production occurrence is unconfirmed.
Compare in seconds and skip expiry, or clamp the cutoff to the epoch when the expiry exceeds the seconds elapsed since the epoch at pool.Now(). A plain seconds cast is insufficient because converting a very negative cutoff back to MempoolTime can still overflow. Alternatively, bound -mempoolexpiry in ApplyArgsManOptions, which also fixes the load path.
Optional improvements
[suggestion] · Clock test does not verify per-manager isolation
The test would still pass if SetClockTime() changed the process-global mock time instead of setting an isolated clock for each manager.
Location: src/test/kernel/test_kernel.cpp:1552 (head).
Details and suggested fix
btck_chainstate_manager_set_clock_time_tests creates one chainstate manager and checks only that manager's future-time results. A setter that changed the global mock clock, or a ChainstateManager::Now() that read global state, would produce the same results. The test therefore misses the per-manager isolation that distinguishes this API from btck_set_mock_time().
Create a second manager with its own test directory. Set the managers' clocks on opposite sides of the same unseen header's two-hour future-time limit, then check that one returns TIME_FUTURE and the other accepts the header. If testing SetClockTime(std::nullopt) fallback as well, use a different header because AcceptBlockHeader returns early for headers it already knows.
[suggestion] · Clock API docs do not specify which clock takes precedence
Passing 0 can fall back to the global mock time rather than the system clock, and btck_set_mock_time() does not control every kernel time read when a manager has a nonzero clock.
Location: src/kernel/bitcoinkernel.h:1342 (head).
Details and suggested fix
The new documentation says that passing 0 restores the system clock, but ChainstateManager::Now() falls back to NodeClock::_now_nondet(), which uses the process-global mock time when btck_set_mock_time() has set one. Conversely, a nonzero per-manager value overrides the global mock for that manager's future-time check, IBD latch, and progress values. The existing btck_set_mock_time() documentation still says it “Affects all kernel time reads globally,” so applications using both APIs can misunderstand which clock controls header acceptance or IBD state.
Document the precedence in both API descriptions: a nonzero per-manager clock takes precedence; zero falls back to the global mock time if set, otherwise to the system clock.
[suggestion] · An out-of-range mempool timestamp aborts the remaining import
A negative or too-large timestamp now stops import partway through; only dump files the node did not write are affected.
Location: src/node/mempool_persist.cpp:102 (head).
Details and suggested fix
Previously, a negative nTime was treated as expired and a very large value was passed to AcceptToMemoryPool. Both now throw inside the load loop. The outer catch returns false, skipping all later transactions, mapDeltas, and the unbroadcast set, while retaining entries loaded before the bad record. Since the record's fields have already been read, the stream remains in sync and the record can be skipped instead. The accepted timestamp range also depends on the platform: MempoolTime::max() is roughly year 2262 with libstdc++ nanoseconds and much later with libc++ or MSVC ticks, so the same file can load on one platform and fail on another.
Count an out-of-range record as failed or expired and continue, ideally using a fixed, platform-independent bound. Node-written dumps stay in range because setmocktime is capped at UINT32_MAX; this affects only a corrupted mempool.dat or a crafted file passed to importmempool.
[suggestion] · ConsumeTxMemPoolEntry consumes fewer bytes and shifts fuzz inputs
Existing corpus inputs for several mempool fuzz targets will reach different states after this change.
Location: src/test/fuzz/util/mempool.cpp:25 (head).
Details and suggested fix
The entry time previously came from ConsumeIntegral<int64_t>(), which consumes eight bytes. ConsumeTime() draws from the 2000–2100 range, which fits in 32 bits and consumes four bytes. This shifts every subsequent field, including entry_sequence and entry_height, and all data read after each entry. Existing qa-assets inputs for block_policy_estimator, partially_downloaded_block, rbf, and package_rbf therefore no longer reach the same states. The utxo_total_supply commit preserves byte consumption, so the change appears unintended.
To keep the corpora aligned, consume an int64_t as before and map it into the representable time range. Otherwise, call out the corpus change so the corpora can be regenerated.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: Clarify whether the clock-time override is fixed or advancing
- [suggestion]: Add a release note for the exported clock API