Skip to content

Commit

Permalink
Snapshot when current block near the current time
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Mar 22, 2024
1 parent 01b1569 commit 7e35d5c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3725,6 +3725,10 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams &chainPar
}
}

static bool BlockchainNearTip(const int64_t blockTime) {
return blockTime > (GetTime() - nMaxTipAge);
}

/** Disconnect m_chain's tip.
* After calling, the mempool will be in an inconsistent state, with
* transactions from disconnected blocks being added to disconnectpool. You
Expand Down Expand Up @@ -3808,7 +3812,7 @@ bool CChainState::DisconnectTip(CValidationState &state,
// DisconnectTip might be called before psnapshotManager has been initialised
// as part of start-up so check psnapshotManager before using it.
if (psnapshotManager) {
if (!IsInitialBlockDownload()) {
if (BlockchainNearTip(pindexDelete->pprev->GetBlockTime())) {
psnapshotManager->SetBlockSnapshot(*pcustomcsview, pindexDelete->pprev);
} else {
psnapshotManager->EraseCurrentSnapshot();
Expand Down Expand Up @@ -4013,7 +4017,7 @@ bool CChainState::ConnectTip(CValidationState &state,

// ConnectTip might be called before psnapshotManager has been initialised
// as part of start-up so check psnapshotManager before using it.
if (psnapshotManager && !IsInitialBlockDownload()) {
if (psnapshotManager && BlockchainNearTip(pindexNew->GetBlockTime())) {
psnapshotManager->SetBlockSnapshot(*pcustomcsview, pindexNew);
}

Expand Down

0 comments on commit 7e35d5c

Please sign in to comment.