-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Import pubkeys when importing p2sh with importmulti #14019
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
// TODO Is this necessary? | ||
CScript scriptRawPubKey = GetScriptForRawPubKey(pubKey); | ||
|
||
if (::IsMine(*pwallet, scriptRawPubKey) == ISMINE_SPENDABLE) { |
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.
Curious why we aren't calling HaveKey
here and in similar locations?
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. I just copied this from below
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script"); | ||
} | ||
|
||
pwallet->MarkDirty(); |
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 the MarkDirty here? Needs a comment imo.
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.
Copied from below. It seems that we always do MarkDirty
before importing stuff. This pattern appears throughout the other import stuff.
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.
If #14303 is correct, these can be removed. Please review.
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script"); | ||
} | ||
|
||
pwallet->MarkDirty(); |
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 the MarkDirty here? Needs a comment imo.
} | ||
|
||
// TODO Is this necessary? | ||
CScript scriptRawPubKey = GetScriptForRawPubKey(pubKey); |
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.
Seems kind of expected until we stop abusing keys sadly.
Reviewers, 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. |
utACK 54ab69ce78a88f24c96ebcab09c63da27db2ee9d I think removing the TODO is fine since we're doing it for everything until a future wallet refactor. |
54ab69c
to
7bcf2cb
Compare
Why? If you're importing p2sh, the wallet shouldn't recognise lone keys... |
@luke-jr This PR is largely to work in combination with #14021, but I decided it would be better to split it into it's own PR. The reason for doing this is so that a PSBT can be made which includes the pubkey and the key derivation information (master key fingerprint and keypath) for a P2SH script (e.g. a multisig redeemScript). Without this, the wallet has no way of knowing the key and its metadata in order to put that into a PSBT. This is particularly useful for hardware wallet support. |
@luke-jr It's an unfortunate side effect of the current design that importing keys/script sometimes results in outputs involving those becoming treated as IsMine. The goal here isn't changing IsMine, but making sure the information is available for signing. This issue will be independently solved by moving to descriptor based wallets, where nothing except the scripts defined by the imported descriptors will be treated as IsMine. |
tACK 7bcf2cb In use on active wallets. |
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 7bcf2cb
Only nit I have is: since keys are getting imported in a loop, any error thrown on an individual key might be hard to diagnose. Happy to defer this to a future PR though.
"timestamp": "now", | ||
}] | ||
) | ||
assert result[0]['success'] |
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, assert_equal(result[0]['success'], 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.
Done
src/wallet/rpcdump.cpp
Outdated
@@ -917,6 +917,53 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con | |||
pwallet->SetAddressBook(dest, label, "receive"); | |||
} | |||
|
|||
// Import public keys | |||
for (size_t i = 0; i < pubKeys.size(); ++i) { | |||
const std::string& pubkey = pubKeys[i].get_str(); |
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.
Use HexToPubKey
:
CPubKey pubKey = HexToPubKey(pubKeys[i].get_str())
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
@@ -917,6 +917,53 @@ static UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, con | |||
pwallet->SetAddressBook(dest, label, "receive"); | |||
} | |||
|
|||
// Import public keys | |||
for (size_t i = 0; i < pubKeys.size(); ++i) { |
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, use range-based for-loop?
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 does not work as UniValue
does not have an end()
function apparently.
ms = self.nodes[1].createmultisig(2, [pub1, pub2]) | ||
result = self.nodes[0].importmulti( | ||
[{ | ||
'scriptPubKey' : { 'address' : ms['address']}, |
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, space before }
?
we should style lint python
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
7bcf2cb
to
6412265
Compare
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key"); | ||
} | ||
|
||
CTxDestination pubkey_dest = pubKey.GetID(); |
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: pubkey_dest
=> pubKeyDest
?
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. The style guide says to use snake case for variable names.
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.
Any reason why the other local variables don't follow this naming convention? (For example, pubKey
, pubKeyScript
, and scriptRawPubKey
)
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 style convention has changed over time. New code should follow the new convention. Changing all of the existing code to follow that would break a ton of PRs so we don't do that.
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.
Gotcha. So the variables I named are new code
AFAICT - though I may be missing something. They appear to be new variables defined as part of the work done for this PR.
tACK 6412265 |
tACK 6412265 |
this PR is replaced by #14454, please review that instead :) |
c11875c Add segwit address tests for importmulti (MeshCollider) 201451b Make getaddressinfo return solvability (MeshCollider) 1753d21 Add release notes for importmulti segwit change (MeshCollider) 353c064 Fix typo in test_framework/blocktools (MeshCollider) f6ed748 Add SegWit support to importmulti with some ProcessImport cleanup (MeshCollider) Pull request description: Add support for segwit to importmulti, supports P2WSH, P2WPKH, P2SH-P2WPKH, P2SH-P2WSH. Adds a new `witnessscript` parameter which must be used for the witness scripts in the relevant situations. Also includes some tests for the various import types. ~Also makes the change in #14019 redundant, but cherry-picks the test from that PR to test the behavior (@achow101).~ Fixes #12253, also addresses the second point in #12703, and fixes #14407 Tree-SHA512: 775a755c524d1c387a99acddd772f677d2073876b72403dcfb92c59f9b405ae13ceedcf4dbd2ee1d7a8db91c494f67ca137161032ee3a2071282eeb411be090a
This PR has
importmulti
import public keys if specified instead of ignoring them when the thing being imported is p2sh.