This was discovered in a discussion in #29996
If the base block of the snapshot is marked invalid or part of an invalid chain, we currently still load the snapshot and get stuck in a weird state where we have the snapshot chainstate but it will never connect to our valid chain.
While this scenario is highly unlikely to occur on mainnet, it still seems good to prevent this inconsistent state.
The behavior change described above is in the second commit.
The first commit refactors the early checks in the loadtxoutset
RPC by moving them into ActivateSnapshot()
in order to have the chance to cover them by unit tests in the future and have a more consistent interface. Previously checks were spread out between rpc/blockchain.cpp
and validation.cpp
. In order to be able to return the error message to users of the RPC, the return type of ActivateSnapshot()
is changed from bool
to util::Result
.
The third commit removes an unnecessary restart introduced in #29428.