[BUG] g_IsSapling active flag during reindex #1998
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
Starting the wallet with
--reindex(w/wo--zapwallettxes) causes a crash if the wallet has shield transactions.Cause:
g_IsSaplingActiveis used to select the proper serialization for v2 txes (with or without sapData).During init,
g_IsSaplingActiveis set to true inLoadBlockIndexDBwhen connecting a post-enforcement block.When
--reindexing, though,LoadBlockIndexDBis skipped inLoadBlockIndex, and the global flag remains false.Therefore
g_IsSaplingActiveis false when init gets toInitLoadWalletand the deserialization of shield transactions throws.Solution:
Set
g_IsSaplingActiveto true when--reindex.This way the wallet can be loaded, and then the flag switches back to false as soon as the first pre-enforcement block is connected (
ThreadImportstarts only after the wallet has been loaded).Note: A wallet would now crash during a reindex, if containing a pre-enforcement v2 transaction (old serialization, no sapData).
But such transactions are non-standard (afaik there's only one on the whole main-net blockchain).
A wallet with this transaction (if it still exists) would not be able to use
--reindexand would be forced to--resync.