From 226d03dd610dd65938554bcf0abfe79f7ca7fb4d Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Mon, 23 Dec 2024 13:51:36 -0500 Subject: [PATCH] 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. --- src/validation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index 3f774fd0a1e..372a0aad48c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3526,6 +3526,10 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< bool fInvalidFound = false; std::shared_ptr nullBlockPtr; + // BlockConnected signals must be sent for the original role; + // in case snapshot validation is completed during ActivateBestChainStep, the + // result of GetRole() changes from BACKGROUND to NORMAL. + const ChainstateRole chainstate_role{this->GetRole()}; if (!ActivateBestChainStep(state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock : nullBlockPtr, fInvalidFound, connectTrace)) { // A system error occurred return false; @@ -3541,7 +3545,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr< for (const PerBlockConnectTrace& trace : connectTrace.GetBlocksConnected()) { assert(trace.pblock && trace.pindex); if (m_chainman.m_options.signals) { - m_chainman.m_options.signals->BlockConnected(this->GetRole(), trace.pblock, trace.pindex); + m_chainman.m_options.signals->BlockConnected(chainstate_role, trace.pblock, trace.pindex); } }