New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove wallet global nTimeFirstKey #15306
Comments
Requesting @jonasschnelli and @ryanofsky input, since they were the last to look at |
No, Edit: ok, there is no use case for the always updated
Honestly the tradeoff looks worst - keep track of the minimum timestamp vs iterate over all keys.. Edit: if it turns to be used then I think it's preferable to keep track of
👍 |
I expect the 'iterate over all keys in memory' operation is very short compared to the other events that are happening at wallet load/startup, such as parsing all key-values from the wallet file. The reason that I prefer this to storing a wallet member variable is that the current |
Right, it's not clear. I just think it's preferable constant time getter than a linear search, and in that case it could have better comments explaining it. |
FWIW, I agree with jnewbery here. The nTimeFirstKey logic seems fragile and difficult to understand. I wouldn't think its worth keeping around to avoid a linear search in hypothetical future code, so personally I'd be happy to see a PR removing it. |
Concept ACK. This seems to be triggering a rescan on a fresh wallet, which makes no sense. On an existing wallet, we should have a proper locator, so overwriting the block height of the locator with nTimeFirstKey seems fragile and unnecessary. Question: Would we unnecessarily rescan the whole chain when loading an existing wallet that has one of the key's |
I figure it's supposed to be an optimization in case the locator gets zapped or something. But in the normal case agree it should be unnecessary. I think the proposal here is only to get rid of
Not unless the locator forked at the beginning of the chain. The Lines 4511 to 4513 in e6e99d4
bitcoin/src/interfaces/chain.cpp Line 96 in e6e99d4
Lines 468 to 469 in e6e99d4
|
Taken from #15032 (review):
I think
nTimeFirstKey
is only read when the wallet is being loaded from file here:bitcoin/src/wallet/wallet.cpp
Line 4217 in 3b19d8e
It's set in
LoadKeyMetadata()
,LoadScriptMetadata()
, andGenerateNewKey()
(throughUpdateTimeFirstKey()
) before then, but any time thatnTimeFirstKey
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 thenTimeFirstKey
.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 therescan()
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 functionGetWalletBirthday()
to iterate through the wallet keys and return the wallet's birthday instead of having a wallet global.The text was updated successfully, but these errors were encountered: