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
wallet: Remove redundant wpkh script import #16724
Conversation
|
Concept ACK
Do you know where this happens? That function doesn't seem to do it directly, at least. |
It's done by bitcoin/src/script/signingprovider.cpp Lines 87 to 92 in adff8fe
Here's a stack trace showing how it's called by
|
Thanks! That's pretty sneaky, I was indeed searching for Looks good to me then. Code review ACK b6e7aa8 |
It is sneaky. The author of these lines obviously didn't see it either. Thanks for the review! |
Concept ACK, the fix makes sense, haven't checked that the behaviour of ImplicitlyLearnRelatedKeyScripts behaves in the same way as ImportScripts though (with respect to writing to the wallet). I think this is fine? |
This will prevent the segwit output script from being written to the wallet file. While |
@achow101 That's a good point, I think you're right. Here's another idea. The original code, for reference: bitcoin/src/wallet/rpcdump.cpp Lines 188 to 196 in f5db3f2
If we switch the order of these two blocks, like so:
the warning referenced in #16711 goes away, because |
Actually, the above would work, but this highlights a bigger problem. Lines 1778 to 1781 in e9ef1b2
So perhaps instead, the conditional statement above could be changed to read from the actual wallet to determine if a script exists. |
@achow101 @meshcollider did you want to follow up with approach thoughts here? |
IMO places where the map is edited directly without writing (other than the initial read of the wallet) are going to be dangerous, that behavior should be changed instead of adding more checks that the script is in the wallet. I think we should make it not possible to add to the map without adding to the wallet file. EDIT: Thinking about this more, I think it is okay to just make ImportScripts check the database rather than just the map. Just make sure FillableSigningProvider doesn't have to worry about the database. Approach ACK 👍 This is actually a bugfix |
Are there any legit reasons to not even try to write to DB? |
I'm now leaning towards a write to the wallet after My initial understanding of the map is that it's just a cache to avoid repeated disk reads. Is that accurate? If that's true, 1) it should always write through immediately and 2) reads should almost always be done from the map (other than initially populating the map). Thanks for your patience, everyone! I'm still wrapping my head around the codebase. |
To reiterate, there is a more significant bug here than the superfluous warning this was initially submitted for:
|
I'm not really a fan of that. It's going to be a ton of disk reads and slow down large imports even further (we recently improved it with batched writes).
I'm not sure that that's necessarily a bug. IIRC, the point of Perhaps @sipa can provide some more insights about that as he wrote the code. If the intention of writing the scripts to the wallet was just to allow downgrading, we can actually just check the wallet version number to decide whether to write or not as recent wallet versions are too new to be downgraded anyways. |
Scripts in the map are written to the wallet somewhere?
Yes, I was trying to account for your earlier comment that loading the wallet into older versions of bitcoin core would not carry the segwit scripts loaded implicitly with it. |
Keys in the keypool don't have their scripts written to the wallet. Instead those scripts are loaded into memory via |
wpkh script. The block being removed effectively just printed a false
positive warning. Fixes
importprivkey
always gives warning about already having script #16711