Taken from #15032#pullrequestreview-198677243:
I think nTimeFirstKey is only read when the wallet is being loaded from file here:
It’s set in LoadKeyMetadata(), LoadScriptMetadata(), and GenerateNewKey() (through UpdateTimeFirstKey()) before then, but any time that nTimeFirstKey is set after wallet load is unnecessary, since it doesn’t get read again, and isn’t persisted to disk. Notably, any rpc calls that import keys don’t need to update the nTimeFirstKey.
I think nTimeFirstKey should be removed as a wallet global entirely. I think -rescan as a wallet command-line argument can also be removed since we now have the rescan() rpc method (removing -rescan has been suggested here: #7061 (comment) and here: #13044 (comment)). If we want to retain the ability to rescan from the wallet’s birthday (ie the earliest key birthday in the wallet), then there should be a function GetWalletBirthday() to iterate through the wallet keys and return the wallet’s birthday instead of having a wallet global.