Skip to content

Conversation

achow101
Copy link
Member

This PR has importmulti import public keys if specified instead of ignoring them when the thing being imported is p2sh.

// TODO Is this necessary?
CScript scriptRawPubKey = GetScriptForRawPubKey(pubKey);

if (::IsMine(*pwallet, scriptRawPubKey) == ISMINE_SPENDABLE) {
Copy link
Member

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?

Copy link
Member Author

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();
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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();
Copy link
Member

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);
Copy link
Member

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 23, 2018

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.

@instagibbs
Copy link
Member

utACK 54ab69ce78a88f24c96ebcab09c63da27db2ee9d

I think removing the TODO is fine since we're doing it for everything until a future wallet refactor.

@luke-jr
Copy link
Member

luke-jr commented Aug 29, 2018

Why? If you're importing p2sh, the wallet shouldn't recognise lone keys...

@achow101
Copy link
Member Author

@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.

@sipa
Copy link
Member

sipa commented Aug 29, 2018

@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.

@instagibbs
Copy link
Member

instagibbs commented Sep 14, 2018

tACK 7bcf2cb

In use on active wallets.

Copy link
Contributor

@jb55 jb55 left a 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']
Copy link
Contributor

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).

Copy link
Member Author

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) {
const std::string& pubkey = pubKeys[i].get_str();
Copy link
Contributor

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())

Copy link
Member Author

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) {
Copy link
Contributor

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?

Copy link
Member Author

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']},
Copy link
Contributor

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 :trollface:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@achow101 achow101 force-pushed the import-multi-pubkeys branch from 7bcf2cb to 6412265 Compare September 27, 2018 03:53
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key");
}

CTxDestination pubkey_dest = pubKey.GetID();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: pubkey_dest => pubKeyDest?

Copy link
Member Author

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.

Copy link
Contributor

@etscrivner etscrivner Sep 28, 2018

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)

Copy link
Member Author

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.

Copy link
Contributor

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.

@etscrivner
Copy link
Contributor

tACK 6412265

@instagibbs
Copy link
Member

tACK 6412265

@meshcollider
Copy link
Contributor

this PR is replaced by #14454, please review that instead :)

@fanquake
Copy link
Member

@achow101 Is #14454 a full replacement for this PR? If so, can you close this.

@achow101
Copy link
Member Author

Superseded by #14454. Also, from discussion on IRC just now, it seems that this feature is no longer necessary following #14424

@achow101 achow101 closed this Oct 15, 2018
laanwj added a commit that referenced this pull request Oct 31, 2018
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants