This PR ensures that we always check the keypool during SyncTransaction and, that the lookup window for HD restore is large enough (currently +20 keys). Once the keypool size falls below the min gap limit (currently 20 keys) and the keypool can’t be extended (locked wallet), the wallet then temporary pauses synchronisation.
unencrypted wallets
For unencrypted wallets, the key pool will always be topped up. During sync (SyncTransaction), we check for used keypool keys and mark all keys up to the matched key as used. Additionally we topup the keypool to ensure we not fall below the gap limit (20 keys).
encrypted wallets in non pruning mode
Same as above, but, If we hit the gap limit with an encrypted wallet, we can’t topup the keypool. In that case, we just pause the sync (not the node, only the wallet).
Once the user unlocks the wallet over walletpassphrase
, we rescan down to the point where we have stopped previously to ensure we don’t miss possible funds.
encrypted wallets in pruned mode
Same as above, but, we also stop requesting and connecting blocks. The full node will “pause” in this case until the user did unlock his wallet (== topup, rescan, etc.).
This has a little bit of complexity and requires careful reviews.