-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Refactor: Require scriptPubKey to get wallet SigningProvider #17371
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
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. |
fd8ab05
to
f7510c1
Compare
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.
Code review ACK f7510c1. Pretty straightforward to verify this doesn't change behavior.
@@ -550,7 +550,11 @@ static UniValue signmessage(const JSONRPCRequest& request) | |||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | |||
} | |||
|
|||
const SigningProvider* provider = pwallet->GetSigningProvider(); | |||
CScript script_pub_key = GetScriptForDestination(*pkhash); |
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 "Refactor: Require scriptPubKey to get wallet SigningProvider" (f7510c1)
It would seem more direct to replace *pkhash
with dest
here and call GetScriptForDestination(dest)
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 don't think it really matters as we still need pkhash
since signmessage
is supposed to only work on p2pkh addresses.
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.
we still need
pkhash
sincesignmessage
is supposed to only work onp2pkh
addresses
That will change in https://github.com/bitcoin/bitcoin/pull/16440/files#diff-df7d84ff2f53fcb2a0dc15a3a51e55ceR559
SignTransaction will be called multiple times in the future. Pass it a result UniValue so that it can accumulate the results of multiple SignTransaction passes.
f7510c1
to
b2e509c
Compare
Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. It passes new CScript arguments to signing functions, but the arguments aren't currently used.
b2e509c
to
d0dab89
Compare
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.
Code review ACK d0dab89. Thanks for the SignTransaction update. No other changes since last review
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.
Code review ACK d0dab89
@@ -550,7 +550,11 @@ static UniValue signmessage(const JSONRPCRequest& request) | |||
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); | |||
} | |||
|
|||
const SigningProvider* provider = pwallet->GetSigningProvider(); | |||
CScript script_pub_key = GetScriptForDestination(*pkhash); |
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.
we still need
pkhash
sincesignmessage
is supposed to only work onp2pkh
addresses
That will change in https://github.com/bitcoin/bitcoin/pull/16440/files#diff-df7d84ff2f53fcb2a0dc15a3a51e55ceR559
@instagibbs and @meshcollider, you may be interested to review this. This is code you previously acked when it was part of #16341 |
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.
Code review ACK d0dab89.
*/ | ||
UniValue SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType); | ||
void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType, UniValue& result); |
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.
An overload could be added, like
UniValue SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore, const std::map<COutPoint, Coin>& coins, const UniValue& hashType)
{
UniValue result(UniValue::VOBJ);
SignTransaction(mtx, &keystore, coins, hashType, result);
return result;
}
But I see that in the next commit this refactor is handy in signrawtransactionwithwallet
RPC.
@@ -117,8 +117,22 @@ class WalletImpl : public Wallet | |||
std::string error; | |||
return m_wallet->GetNewDestination(type, label, dest, error); | |||
} | |||
bool getPubKey(const CKeyID& address, CPubKey& pub_key) override { return m_wallet->GetLegacyScriptPubKeyMan()->GetPubKey(address, pub_key); } | |||
bool getPrivKey(const CKeyID& address, CKey& key) override { return m_wallet->GetLegacyScriptPubKeyMan()->GetKey(address, key); } | |||
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override |
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.
note for future work(TM): address
is a horrible name for this argument
@@ -2096,7 +2100,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector< | |||
continue; | |||
} | |||
|
|||
const SigningProvider* provider = GetSigningProvider(); | |||
const SigningProvider* provider = GetSigningProvider(wtx.tx->vout[i].scriptPubKey); |
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.
do we need to check for knowledge of provider 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.
oh i cannot read.
providers.insert(std::move(provider)); | ||
} | ||
} | ||
if (providers.size() == 0) { |
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.
non-blocking-nit: .empty()
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.
Not fixing to avoid invalidating ACKs.
utACK d0dab89 |
ready for merge? @meshcollider |
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.
Code review ACK d0dab89
{ | ||
const SigningProvider* provider = m_wallet->GetSigningProvider(script); | ||
if (provider) { | ||
return provider->GetPubKey(address, pub_key); |
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.
Its kinda not that nice that there is no check the script
and address
have anything to do with each other. You could end up requesting the wrong SPKM for an address quite easily. Maybe move some of the ExtractDestination stuff inside here instead?
const SigningProvider* provider = GetSigningProvider(); | ||
const SigningProvider* provider = GetSigningProvider(scriptPubKey); | ||
if (!provider) { | ||
// We don't know about this scriptpbuKey; |
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: typo (same below)
@@ -2971,8 +2977,11 @@ static UniValue listunspent(const JSONRPCRequest& request) | |||
entry.pushKV("spendable", out.fSpendable); | |||
entry.pushKV("solvable", out.fSolvable); | |||
if (out.fSolvable) { | |||
auto descriptor = InferDescriptor(scriptPubKey, *pwallet->GetLegacyScriptPubKeyMan()); | |||
entry.pushKV("desc", descriptor->ToString()); | |||
const SigningProvider* provider = pwallet->GetSigningProvider(scriptPubKey); |
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 can probably be combined with above to simplify
…vider d0dab89 Refactor: Require scriptPubKey to get wallet SigningProvider (Andrew Chow) 4b0c718 Accumulate result UniValue in SignTransaction (Andrew Chow) Pull request description: Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. It passes new CScript arguments to signing functions, but the arguments aren't currently used. Split from #17261 ACKs for top commit: instagibbs: utACK d0dab89 ryanofsky: Code review ACK d0dab89. Thanks for the SignTransaction update. No other changes since last review Sjors: Code review ACK d0dab89 promag: Code review ACK d0dab89. meshcollider: Code review ACK d0dab89 Tree-SHA512: c3f52df20fd9d6b3b5aa65562cf5f7dce7b7f44c148b0f988f8b578fce2a28e9b7bf010f5f04bb5bf60f5272b2899f1dbbfb8aee81579c21c9cba559d1d2bb70
…ningProvider d0dab89 Refactor: Require scriptPubKey to get wallet SigningProvider (Andrew Chow) 4b0c718 Accumulate result UniValue in SignTransaction (Andrew Chow) Pull request description: Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. It passes new CScript arguments to signing functions, but the arguments aren't currently used. Split from bitcoin#17261 ACKs for top commit: instagibbs: utACK bitcoin@d0dab89 ryanofsky: Code review ACK d0dab89. Thanks for the SignTransaction update. No other changes since last review Sjors: Code review ACK d0dab89 promag: Code review ACK d0dab89. meshcollider: Code review ACK d0dab89 Tree-SHA512: c3f52df20fd9d6b3b5aa65562cf5f7dce7b7f44c148b0f988f8b578fce2a28e9b7bf010f5f04bb5bf60f5272b2899f1dbbfb8aee81579c21c9cba559d1d2bb70
… within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of #17156, non-trivial due to crossing the refactor in #17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
Summary: SignTransaction will be called multiple times in the future. Pass it a result UniValue so that it can accumulate the results of multiple SignTransaction passes. --- bitcoin/bitcoin@4b0c718 Partial backport of Core [[bitcoin/bitcoin#17371 | PR17371]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D7686
…ningProvider Summary: Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. It passes new CScript arguments to signing functions, but the arguments aren't currently used. --- bitcoin/bitcoin@d0dab89 Depends on D7686 Concludes backport of Core [[bitcoin/bitcoin#17371 | PR17371]] Test Plan: ninja check check-functional Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D7687
…ningProvider d0dab89 Refactor: Require scriptPubKey to get wallet SigningProvider (Andrew Chow) 4b0c718 Accumulate result UniValue in SignTransaction (Andrew Chow) Pull request description: Easier to review ignoring whitespace: git log -p -n1 -w This commit does not change behavior. It passes new CScript arguments to signing functions, but the arguments aren't currently used. Split from bitcoin#17261 ACKs for top commit: instagibbs: utACK bitcoin@d0dab89 ryanofsky: Code review ACK d0dab89. Thanks for the SignTransaction update. No other changes since last review Sjors: Code review ACK d0dab89 promag: Code review ACK d0dab89. meshcollider: Code review ACK d0dab89 Tree-SHA512: c3f52df20fd9d6b3b5aa65562cf5f7dce7b7f44c148b0f988f8b578fce2a28e9b7bf010f5f04bb5bf60f5272b2899f1dbbfb8aee81579c21c9cba559d1d2bb70
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…nts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…and amounts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
…and amounts are within bounds f5fb7fc psbt: check output index is within bounds before accessing (Andrew Chow) 1cf77a2 Don't calculate tx fees for PSBTs with invalid money values (Andrew Chow) Pull request description: Backport of bitcoin#17156, non-trivial due to crossing the refactor in bitcoin#17371 ACKs for top commit: laanwj: ACK f5fb7fc Tree-SHA512: 7aabf9a6b8a8e287a26dfbf73a437a3bc55177bef8fc5149d822ef81b8ef2458e1d718c3a19c73532c5cef0f9bd8144574c7fad90ca89f13a08b44edf3a2656d
Easier to review ignoring whitespace:
This commit does not change behavior. It passes new CScript arguments to
signing functions, but the arguments aren't currently used.
Split from #17261