The minimal HD wallet implementation (#8035) changes the derivation scheme for new keys from random to deterministic. This guarantees that an old backup will be able to recreate all keys, and no money can be lost. However, recovery in this case is not trivial, as the wallet will not automatically "look forward" to see if future keys are being used.
The suggestion is to implement a "gap limit" as is called in other BIP32 derived standard, simply reusing the existing keypool. Whenever a key from the keypool is used in a received transaction, we should automatically mark it as used, and if possible replenish.
One difficulty is encrypted wallets. We are unable to replenish the keypool in case the wallet is encrypted. Options to deal with this are:
- Only warn the user in some way, that he may need to unlock the wallet and
-rescan(doesn't play well with pruning). - Stop syncing after the number of keys drops below a configurable number (the gap limit). This means no rescanning is needed, but it may be very annoying if there is a lot of chain to sync.
- Stop syncing the wallet but continue otherwise. This depends on having the wallet sync be made entirely independent from the node's sync (see discussion in http://www.erisian.com.au/meetbot/bitcoin-core-dev/2016/bitcoin-core-dev.2016-09-08-18.59.log.html), and also doesn't play well with pruning.
- Switch to non-hardered derivation at the last level of the path, allowing the computation of new keys without access to the encrypted key material.