Largely implements the suggestion from #17484 (comment).
After sethdseed
is called, the CHDChain for the old seed is kept in the wallet. It is kept on the file as a new inactivehdseed
record and in memory in a map m_inactive_hd_seeds
. In LegacyScriptPubKeyMan::MarkUnusedAddresses
we check each used key’s metadata for whether it was derived from an inactive seed. If it is, we then check to see how many keys after that key were derived from the inactive seed. If that number does not match the keypool parameter, we derive more keys from the inactive seed until it does match. This way we won’t miss transactions belonging to keys outside of the range of the keypool initially.
The indexes and internal-ness of a key is gotten by checking it’s key origin data.
Because of this change, we no longer need to wait for IBD to finish before sethdseed
can work so that check is also removed.
A test case for this is added as well which fails on master.