test: exercise index reorg assertion failure

This commit is contained in:
furszy
2025-07-09 15:47:25 -04:00
committed by Hao Xu
parent acf50233cd
commit 3aef38f44b
2 changed files with 84 additions and 7 deletions

View File

@@ -186,8 +186,8 @@ void BaseIndex::Sync()
{
const CBlockIndex* pindex = m_best_block_index.load();
if (!m_synced) {
std::chrono::steady_clock::time_point last_log_time{0s};
std::chrono::steady_clock::time_point last_locator_write_time{0s};
auto last_log_time{NodeClock::now()};
auto last_locator_write_time{last_log_time};
while (true) {
if (m_interrupt) {
LogInfo("%s: m_interrupt set; exiting ThreadSync", GetName());
@@ -229,14 +229,13 @@ void BaseIndex::Sync()
if (!ProcessBlock(pindex)) return; // error logged internally
auto current_time{std::chrono::steady_clock::now()};
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
LogInfo("Syncing %s with block chain from height %d",
GetName(), pindex->nHeight);
auto current_time{NodeClock::now()};
if (current_time - last_log_time >= SYNC_LOG_INTERVAL) {
LogInfo("Syncing %s with block chain from height %d", GetName(), pindex->nHeight);
last_log_time = current_time;
}
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
if (current_time - last_locator_write_time >= SYNC_LOCATOR_WRITE_INTERVAL) {
SetBestBlockIndex(pindex);
last_locator_write_time = current_time;
// No need to handle errors in Commit. See rationale above.