Skip to content

Commit 226d03d

Browse files
committed
validation: Send correct notification during snapshot completion
If AssumeUtxo background sync is completed in this ActivateBestChain() call, the GetRole() function returns "normal" instead of "background" for this chainstate. This would make the wallet (which ignores BlockConnected notifcation for the background chainstate) process it, change m_last_block_processed_height, and display an incorrect balance.
1 parent fc7b214 commit 226d03d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/validation.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,10 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
35263526

35273527
bool fInvalidFound = false;
35283528
std::shared_ptr<const CBlock> nullBlockPtr;
3529+
// BlockConnected signals must be sent for the original role;
3530+
// in case snapshot validation is completed during ActivateBestChainStep, the
3531+
// result of GetRole() changes from BACKGROUND to NORMAL.
3532+
const ChainstateRole chainstate_role{this->GetRole()};
35293533
if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connectTrace)) {
35303534
// A system error occurred
35313535
return false;
@@ -3541,7 +3545,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
35413545
for (const PerBlockConnectTrace& trace : connectTrace.GetBlocksConnected()) {
35423546
assert(trace.pblock && trace.pindex);
35433547
if (m_chainman.m_options.signals) {
3544-
m_chainman.m_options.signals->BlockConnected(this->GetRole(), trace.pblock, trace.pindex);
3548+
m_chainman.m_options.signals->BlockConnected(chainstate_role, trace.pblock, trace.pindex);
35453549
}
35463550
}
35473551

0 commit comments

Comments
 (0)