-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Use CWallet::Import* functions in all import* RPCs #16301
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
Conversation
8ae9638 to
2b0033b
Compare
|
This also makes the |
30ca265 to
e66ed3b
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Approach ACK |
promag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. Spent some time reviewing the changes commit by commit and this mostly looks good to me considering latests refactors to the wallet. IMO last commit should be reworked or add a explanation as to why it's safe to ignore errors/return values.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e66ed3b84593bebd3550e18b5b3be3605e08ced1
These changes are kind of breaking change, the caller has no way to know if something went bad - as it is will always succeed.Is this the case just because dumpwallet/importwallet should not be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was because it ImportScripts and ImportPrivKeys doesn't return why it failed. It could fail because the script or privkey already exists in the wallet which would still be fine, or it could cail because something went wrong with writing the data to the wallet file which is bad. I suppose I could make them return an enum, but that's a larger change that I didn't really want to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errors reported as-is appear to at least be somewhat helpful.
It could fail because the script or privkey already exists in the wallet
I don't think that's true. These two checks appear to be only reporting real errors. Perhaps I missed something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but these checks are part of ImportPrivKeys and ImportScripts both of which can return false in non-error cases. Both have HaveKey and/or HaveCScript checks that can fail, but not cause the import to be bad. But there could also be an actual error which would result in the import being bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (991ecfdbbb289bd6e4c50fc63f9201edbca14f70)
Both have HaveKey and/or HaveCScript checks that can fail, but not cause the import to be bad.
What's this referring to? Import methods seem to return true if imported data was already found. But maybe I'm misinterpreting. Might help to refer to a specific example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out I was having a hard time with the negations.
I've pushed another commit that makes it more explicit when something is being skipped because we already have it, as well as logging when this happens.
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice changes. Almost finished reviewing (will update list below with progress).
- 12fd3a849c4be0879e48e65661ca1628c21308b2 Optionally apply labels to imported scriptPubKeys (1/6)
- ea665e323f76766def6c4f46a46c53e38365d179 Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys (2/6)
- 94ad6ad965ba6dfffaf7387b15ac659323fc85d0 Have importpubkey use CWallet's ImportScriptPubKeys and ImportPubKeys functions (3/6)
- 2fb78f8baad0778de81dc81209340e04ccef4df6 Have importaddress use ImportScripts and ImportScriptPubKeys (4/6)
- 92863d7de8cf0d7432bc47f36bf1aa4de257c548 Optionally allow ImportScripts to set script creation timestamp (5/6)
- e66ed3b84593bebd3550e18b5b3be3605e08ced1 Have importwallet use ImportPrivKeys and ImportScripts (6/6)
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (ea665e323f76766def6c4f46a46c53e38365d179)
Just curious, but why is this replacing the LearnAllRelatedScripts() call with inlined code? The change seems fine but is duplicative, makes code longer, and seems like the opposite of the other changes here switching to higher level ImportPrivKeys() and ImportScriptPubKeys() calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done in preparation for the wallet restructure which causes LearnAllRelatedScripts to no longer be part of CWallet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually find this slightly more readable than the previous LearnAllRelatedScripts -> LearnRelatedScripts(key, OutputType::P2SH_SEGWIT);. .... However it's hard to tell if it's really doing the same thing. Maybe add an extra commit to make that more clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (5776e6d72e76e03251d346588035fcdb0423440c)
Just for the record, I like Sjors idea of putting the AddKeyPubKey->ImportPrivKeys and LearnAllRelatedScripts->ImportScripts in two separate commits, since they are independent changes. But it's not very important.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importpubkey use CWallet's ImportScriptPubKeys and ImportPubKeys functions" (94ad6ad965ba6dfffaf7387b15ac659323fc85d0)
Just a note to other reviewers: this seems to happen in ImportPubKeys now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more specifically here's the rough logic of ImportScript:
mark dirty
addwatchonly
if is redeem script:
addcscript
ImportAddress
else
SetAddressBook
And in this case it's not a redeemscript(last arg is false), so it marks dirty, adds watchonly, and sets address book.
Mark dirty is top-level now, ImportScriptPubKeys takes care of the SetAddressBookWithDB, and both ImportScriptPubKeys and ImportPubKeys adds watch only in specific situations(when pubkey is not already in wallet, or the script is not in the wallet yet). Previously the watchonly script was added when ISMINE was not spendable. I'll leave it up to other reviewers to figure if this is desired/same semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it up to other reviewers to figure if this is desired/same semantics.
@achow101 could you clarify in commit message whether this causes a change in behavior or not? If you aren't sure, it'd at least be good to say if it potentially changes behavior. This is hurting my head to think about but it seems only potential difference is whether timestamp is overridden when key already exists?
For all these commits, it'd be really helpful to note in commit messages whether they do or don't or maybe change behavior and what the scope of the change is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a note to each commit indicating what behavior changes in it.
Here, the only behavior change is that the timestamp for the key will be set to 1 if we already have it.
e66ed3b to
cf2d294
Compare
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. I have some questions about the first commit, will study the rest later.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually find this slightly more readable than the previous LearnAllRelatedScripts -> LearnRelatedScripts(key, OutputType::P2SH_SEGWIT);. .... However it's hard to tell if it's really doing the same thing. Maybe add an extra commit to make that more clear?
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not obvious to me how dropping SetAddressBook doesn't change behavior, e.g. we're no longer calling NotifyAddressBookChanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetAddressBook happens in ImportScriptPubKeys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the imported key is !internal and is valid destination, it does appear to SetAddressBookWithDB which in this RPC is true.
cf2d294 to
041e654
Compare
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 1 and not 0? No internal documentation I can find on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dunno, it's just adapted from the changed code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 was introduced in #7551...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 1 and not 0? No internal documentation I can find on this.
As far as I know, there is no substantive difference anymore between 0 and 1, but I think it's good to keep using 1 here so this is a refactoring change, not a change in behavior.
I do think in general it's better to use 1 as an explicit request to rescan from the beginning of the chain as opposed to 0 which could indidcate we're dealing with an old wallet that didn't save metadata (see #9108, #9682), or an uninitialized variable, or some other undefined craziness from all the spaghetti code.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the imported key is !internal and is valid destination, it does appear to SetAddressBookWithDB which in this RPC is true.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(request.params[1].isNull()) && pwallet->mapAddressBook.count(dest) != 0 /* internal */
This seems like an extreme abuse of the flag based on the name and confused me. This should be renamed add_to_book_if_valid or maybe even better just have the validity check inside SetToAddressBook(do we ever want to import invalid destinations?) and call it add_to_addrbook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed the flag to apply_label.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? This is already done by GetAllDestinationsForKey
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImportScriptPubKeys doesn't actually add the scripts to the wallet, so we add the script here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to say as much
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more specifically here's the rough logic of ImportScript:
mark dirty
addwatchonly
if is redeem script:
addcscript
ImportAddress
else
SetAddressBook
And in this case it's not a redeemscript(last arg is false), so it marks dirty, adds watchonly, and sets address book.
Mark dirty is top-level now, ImportScriptPubKeys takes care of the SetAddressBookWithDB, and both ImportScriptPubKeys and ImportPubKeys adds watch only in specific situations(when pubkey is not already in wallet, or the script is not in the wallet yet). Previously the watchonly script was added when ISMINE was not spendable. I'll leave it up to other reviewers to figure if this is desired/same semantics.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you annotate key_origins too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/wallet/wallet.h
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: timestamp since you're calling it that in other places and it matches better other args
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this backwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it's reporting errors when it returns true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, whoops. Fixed.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errors reported as-is appear to at least be somewhat helpful.
It could fail because the script or privkey already exists in the wallet
I don't think that's true. These two checks appear to be only reporting real errors. Perhaps I missed something.
The internal bool was only to indicate whether the given label should be applied as things that are internal should not have a label. To make this clearer, we change internal to apply_label and invert its usage so things that have labels set this to true in order to have their labels applied.
041e654 to
0a5b973
Compare
|
Fixed travis hopefully. |
0a5b973 to
991ecfd
Compare
|
utACK 991ecfdbbb289bd6e4c50fc63f9201edbca14f70 |
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the whole PR, and I think it's close, but am unsure about some issues. Details are in code comments, but my main concerns were:
- It seems bad that importprivkey might be calling ImportScriptPubKeys instead of SetAddressBook just to set the label.
- There might be some unintended changes around updating nCreateTime. In general, commits are unclear about how and whether they are intended to change behavior.
- Error handling in the importwallet commit seems wrong
But aside from these specific concerns, the change seem very good and moves in a welcome direction.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (74ec96b601dd6417f01f4801d83e01eeb7dded18)
It's not really clear from context that this comment is referring to the apply_label argument passed to ImportScriptPubKeys below. Would suggest moving the comment or mentioning this explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the below change entirely.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (e3cc8e102fc2736b3871869646f8d60599988f82)
Is this ever going to add watch only scripts given the !IsMine check in ImportScriptPubKeys?
It'd be nice to have a succinct comment here saying when this will add a watch only script, and why it's necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't ever add the scripts as watch only because we import the private keys earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 1 and not 0? No internal documentation I can find on this.
As far as I know, there is no substantive difference anymore between 0 and 1, but I think it's good to keep using 1 here so this is a refactoring change, not a change in behavior.
I do think in general it's better to use 1 as an explicit request to rescan from the beginning of the chain as opposed to 0 which could indidcate we're dealing with an old wallet that didn't save metadata (see #9108, #9682), or an uninitialized variable, or some other undefined craziness from all the spaghetti code.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (74ec96b601dd6417f01f4801d83e01eeb7dded18)
I don't understand why this is calling ImportScriptPubKeys instead of just SetAddressBook like before. This is confusing because the code is first going out of its way to remove associated watch-only scripts from setWatchOnly (in AddKeyPubKeyWithDB via ImportPrivKeys):
And then after removing the scripts it looks like it goes out of its way to add them by calling ImportScriptPubKeys. But then the ImportScriptPubKeys call doesn't add the scripts because have_solving_data and IsMine are both true in the following check?
Something seems wrong here. If scripts are meant to be added to setWatchOnly it seems like the removal code shouldn't be called and the adding code might need to be fixed. Of the scripts are meant to be removed, then it's misleading to call ImportScriptPubKeys instead of just SetAddressBook like before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (74ec96b601dd6417f01f4801d83e01eeb7dded18)
It looks like there is a minor change in behavior here due to implementation of ImportPrivKeys:
Previously nCreateTime would not be updated if key already existed, and now it will be (in memory only, apparently the value is not written to disk on the next line).
Would suggesting fixing up ImportPrivKeys to avoid this change in behavior, or documenting in the commit message here that there is a slight change in behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed ImportPrivKeys
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Optionally allow ImportScripts to set script creation timestamp" (ace5d082034cbaa52f596689433381a2226a21dc)
Can you clairfy in the commit message whether this is a change in behavior for the importmulti RPC. Seems like a minor bugfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (991ecfdbbb289bd6e4c50fc63f9201edbca14f70)
IMO, would be clearer to call ImportPrivKeys({keyid, key}}, time) than have the extra map variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (991ecfdbbb289bd6e4c50fc63f9201edbca14f70)
Ths doesn't seem right, if HaveKey is true, ImportPrivKeys returns true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No?
nvm, looking at a change that I had locally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've restored fGood and the error messages.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (991ecfdbbb289bd6e4c50fc63f9201edbca14f70)
This print statement should precede the import above...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (991ecfdbbb289bd6e4c50fc63f9201edbca14f70)
Both have HaveKey and/or HaveCScript checks that can fail, but not cause the import to be bad.
What's this referring to? Import methods seem to return true if imported data was already found. But maybe I'm misinterpreting. Might help to refer to a specific example.
1af1689 to
7a58ad5
Compare
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7a58ad5624b2ea9c2d2c661446cc6e046a222fca
nTimeBegin is not being updated, the rescan below could miss wallet transactions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the nTimeBegin update back.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7a58ad5624b2ea9c2d2c661446cc6e046a222fca
nit, this wouldn't be logged if the key is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note in the commit message that this happens.
7a58ad5 to
35805ce
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 35805ce74a780674c2a04259f98c8888906d7e91. Thanks for the previous fixes, and feel free to ignore my questions / comments, but I hope one you'll consider is restoring the direct SetAddressBook call in importwallet instead of calling it indirectly through ImportScriptPubKeys, because it's confusing how ImportScriptPubKeys appears to add watch only scripts.
src/wallet/wallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Log when an import is being skipped because we already have it" (8bd426d238a526f8cfa4e8dd567fb3ccadb40cf7)
Note: Beyond adding the log, this commit also changes behavior of ImportPrivKeys to not update the nCreateTime when the key already exists. This is a good change, so just wanted to point it out.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (5776e6d72e76e03251d346588035fcdb0423440c)
Nice! From ea665e323f76766def6c4f46a46c53e38365d179 to 5776e6d72e76e03251d346588035fcdb0423440c this commit is so much simpler now. The ImportScriptPubKeys stuff was so confusing to me before.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys" (5776e6d72e76e03251d346588035fcdb0423440c)
Just for the record, I like Sjors idea of putting the AddKeyPubKey->ImportPrivKeys and LearnAllRelatedScripts->ImportScripts in two separate commits, since they are independent changes. But it's not very important.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (35805ce74a780674c2a04259f98c8888906d7e91)
Any particular reason this this is calling ImportScriptPubKeys to indirectly set the labels instead of just directly calling SetAddressBook like before? This seems to create same confusion around removing watch only scripts, and then appearing to add them again, but then not really adding them due to ismine, that was in a prior version of the importprivkey commit #16301 (comment).
Would suggest reverting here and just calling SetAddressBook instead of ImportScriptPubKeys like before. Or adding a comment about what ImportScriptPubKeys is intended to do in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted.
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Have importwallet use ImportPrivKeys and ImportScripts" (35805ce74a780674c2a04259f98c8888906d7e91)
Interesting there is still a case that treats 0 and 1 key times differently. It might a be nice idea in a followup PR to replace all the 0's and 1's in the code with SKIP_RESCAN = 0, FULL_RESCAN = 1 constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the use of 0 and 1 is kind of inconsistent and all of the the timestamp stuff needs to be cleaned up. But that should be done in a followup PR.
src/wallet/wallet.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "Log when an import is being skipped because we already have it" (8bd426d238a526f8cfa4e8dd567fb3ccadb40cf7)
Noting another change in behavior: This will now avoid adding the key to the keypool if add_keypool is true and the public key already exists. Could potentially be documented in the commit message or add_keypool description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note in the commit message
Behavior Changes: * Those pubkeys being imported with add_keypool set and are already in the wallet will no longer be added to the keypool
…mportScriptPubKeys Behavior changes: * If we already have the key, it's wpkh script will still be added, although it should already be there
35805ce to
bc8ecc0
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK bc8ecc056ffa42c758b04d5bcae32c1354c3fbe1. Only change since last review was reverting the importwallet ImportScriptPubKeys change I felt was confusing, and updating one of the commit log messages to note a change in behavior.
Really nice job with this PR, and thanks for being so responsive!
|
partial ACK up to af6dced944 Some questions:
Show signature and timestampSignature: Timestamp of file with hash |
… functions Behavior changes: * If any scripts for the pubkey were already in the wallet, their timestamps will be set to 1 and label updated
Also removes the now unused ImportAddress and ImportScript from rpcdump.cpp Behavior changes: * No errors will be thrown when the script or key already exists in the wallet. * If the key or script is already in the wallet, their labels will be updated.
Behavior changes: * scripts imported in importmulti that are not explicilty scriptPubKeys will have timestamps set for them
Behavior changes: * An "Importing ..." line is logged for every key, even ones that are skipped
bc8ecc0 to
40ad2f6
Compare
Updated the commit message
|
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 40ad2f6. Only change since last review is a tweaked commit message (mentioning label update in importpubkey commit)
|
ACK 40ad2f6 (checked that behavior changes are mentioned in the commit body) Show signature and timestampSignature: Timestamp of file with hash |
|
I've written some tests in #16465 |
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 40ad2f6. Those extra tests also pass.
40ad2f6 Have importwallet use ImportPrivKeys and ImportScripts (Andrew Chow) 78941da Optionally allow ImportScripts to set script creation timestamp (Andrew Chow) 94bf156 Have importaddress use ImportScripts and ImportScriptPubKeys (Andrew Chow) a00d1e5 Have importpubkey use CWallet's ImportScriptPubKeys and ImportPubKeys functions (Andrew Chow) c6a8274 Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys (Andrew Chow) fae7a5b Log when an import is being skipped because we already have it (Andrew Chow) ab28e31 Change ImportScriptPubKeys' internal to apply_label (Andrew Chow) Pull request description: #15741 introduced `ImportPrivKeys`, `ImportPubKeys`, `ImportScripts`, and `ImportScriptPubKeys` in `CWallet` which are used by `importmulti`. This PR changes the remaining `import*` RPCs (`importaddress`, `importprivkey`, `importpubkey`, and `importwallet`) to use these functions as well instead of directly adding the imported items to the wallet. ACKs for top commit: MarcoFalke: ACK 40ad2f6 (checked that behavior changes are mentioned in the commit body) ryanofsky: utACK 40ad2f6. Only change since last review is a tweaked commit message (mentioning label update in importpubkey commit) Sjors: ACK 40ad2f6. Those extra tests also pass. Tree-SHA512: 910e3bbe20b6f8809a47b7293775db234125615d886c7fd99c194f4cdf00c765eb1e24b1799260f1213b98c88f9bbe696796f36087c182925e567d44e9194c98
40ad2f6 Have importwallet use ImportPrivKeys and ImportScripts (Andrew Chow) 78941da Optionally allow ImportScripts to set script creation timestamp (Andrew Chow) 94bf156 Have importaddress use ImportScripts and ImportScriptPubKeys (Andrew Chow) a00d1e5 Have importpubkey use CWallet's ImportScriptPubKeys and ImportPubKeys functions (Andrew Chow) c6a8274 Have importprivkey use CWallet's ImportPrivKeys, ImportScripts, and ImportScriptPubKeys (Andrew Chow) fae7a5b Log when an import is being skipped because we already have it (Andrew Chow) ab28e31 Change ImportScriptPubKeys' internal to apply_label (Andrew Chow) Pull request description: bitcoin#15741 introduced `ImportPrivKeys`, `ImportPubKeys`, `ImportScripts`, and `ImportScriptPubKeys` in `CWallet` which are used by `importmulti`. This PR changes the remaining `import*` RPCs (`importaddress`, `importprivkey`, `importpubkey`, and `importwallet`) to use these functions as well instead of directly adding the imported items to the wallet. ACKs for top commit: MarcoFalke: ACK 40ad2f6 (checked that behavior changes are mentioned in the commit body) ryanofsky: utACK 40ad2f6. Only change since last review is a tweaked commit message (mentioning label update in importpubkey commit) Sjors: ACK 40ad2f6. Those extra tests also pass. Tree-SHA512: 910e3bbe20b6f8809a47b7293775db234125615d886c7fd99c194f4cdf00c765eb1e24b1799260f1213b98c88f9bbe696796f36087c182925e567d44e9194c98
Summary: Behavior Changes: * Those pubkeys being imported with add_keypool set and are already in the wallet will no longer be added to the keypool This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@fae7a5b Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6411
Summary: The internal bool was only to indicate whether the given label should be applied as things that are internal should not have a label. To make this clearer, we change internal to apply_label and invert its usage so things that have labels set this to true in order to have their labels applied. This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@ab28e31 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6410
…mportScriptPubKeys Summary: Behavior changes: * If we already have the key, it's wpkh script will still be added, although it should already be there Tis is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@c6a8274 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6412
… functions Summary: Behavior changes: * If any scripts for the pubkey were already in the wallet, their timestamps will be set to 1 and label updated This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@a00d1e5 Depends on D6410 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6413
Summary: Also removes the now unused ImportAddress and ImportScript from rpcdump.cpp Behavior changes: * No errors will be thrown when the script or key already exists in the wallet. * If the key or script is already in the wallet, their labels will be updated. This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@94bf156 Depends on D6413 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6414
Summary: Behavior changes: * scripts imported in importmulti that are not explicilty scriptPubKeys will have timestamps set for them This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@78941da Depends on D6414 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6415
Summary: Behavior changes: * An "Importing ..." line is logged for every key, even ones that are skipped This is a partial backport of Core [[bitcoin/bitcoin#16301 | PR16301]] : bitcoin/bitcoin@40ad2f6 Depends on D6415 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, majcosta Reviewed By: #bitcoin_abc, majcosta Differential Revision: https://reviews.bitcoinabc.org/D6416

#15741 introduced
ImportPrivKeys,ImportPubKeys,ImportScripts, andImportScriptPubKeysinCWalletwhich are used byimportmulti. This PR changes the remainingimport*RPCs (importaddress,importprivkey,importpubkey, andimportwallet) to use these functions as well instead of directly adding the imported items to the wallet.