-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: use options struct for signing and PSBT operations #32876
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
base: master
Are you sure you want to change the base?
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32876. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
edbb5d8
to
2829cb7
Compare
22ceffe
to
f9cf412
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
Some jobs get confused without this: diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
index 54f3d2d199..db8f223c7a 100644
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -312,7 +312,8 @@ void SignTransaction(CMutableTransaction& mtx, const SigningProvider* keystore,
// Script verification errors
std::map<int, bilingual_str> input_errors;
- bool complete = SignTransaction(mtx, keystore, coins, {.sighash_type = *nHashType}, input_errors);
+ SignOptions options{.sighash_type = *nHashType};
+ bool complete = SignTransaction(mtx, keystore, coins, options, input_errors);
SignTransactionResultToJSON(mtx, complete, coins, input_errors, result);
} See e.g. https://cirrus-ci.com/task/6541653541912576:
|
SignOptions options{.sighash_type = *nHashType}; | ||
bool complete = SignTransaction(mtx, keystore, coins, options, input_errors); |
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: Maybe options
could be inlined 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.
@optout21 see #32876 (comment) (also added a comment to the PR description, will add a code comment on the next push)
f9cf412
to
99e7ec9
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.
Concept ACK 99e7ec9
I, too, usually prefer grouping together related items in a struct
. In favour of PSBTOptions
grouping as ISTM that it cleans up the code a bit. SignOptions
could also prove to be helpful with the incoming changes in future PRs.
src/common/types.h
Outdated
/** | ||
* Instructions for how a PSBT should be signed or filled with information. | ||
*/ | ||
struct PSBTOptions { |
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 2923087 "refactor: use PSBTOptions for filling and signing"
PSBTOptions
seems quite generic to me, maybe PSBTFillingOptions
? The doc above also states something similar.
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.
Renamed to PSBTFillOptions
99e7ec9
to
d94c02e
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 d94c02e
Mostly lgtm, asked couple questions along with couple nits.
Using SIGHASH_DEFAULT
as the default value in this PR instead of relying on int sighash
being 0
as done previously is much better from readability POV.
/** | ||
* Whether to fill in bip32 derivation information if available. | ||
*/ | ||
bool bip32_derivs{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.
In 576da4c "refactor: use PSBTFillOptions for filling and signing"
Opinionated supernit if retouched: For variables that are supposed to take action, names starting with a verb is easier to relate to imho. Eg: sign
& finalize
in this struct.
So, maybe derive_bip32.
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.
Although I agree that's a better name, renaming would introduce (even) more churn. And it would either be a breaking change with the RPC or introduce two different names for the same thing.
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.
introduce two different names for the same thing.
Yeah, this is what I had in mind & would prefer this over breaking change with the RPC. But fine to leave it as-is to avoid more churn.
std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type = std::nullopt, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override; | ||
std::optional<common::PSBTError> FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, common::PSBTFillOptions options, int* n_signed = nullptr) const 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.
In 576da4c "refactor: use PSBTFillOptions for filling and signing"
ISTM that the default value of bip32derivs
is switched from false
to true
with the use of PSBTFillOptions
here. Is this intended?
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.
Every call to FillPSBT(
sets bip32derivs
explicitly so this change shouldn't matter.
Except in src/wallet/feebumper.cpp
where I originally dropped /*bip32derivs=*/true
. I brought that back for clarity.
Replace the sign, finalize , bip32derivs and sighash_type arguments which are passed to FillPSBT() and SignPSBTInput() with a PSBTFillOptions struct. This makes it easier to add additional options later without large code churn, such as avoid_script_path proposed in bitcoin#32857. It also makes the use of default boolean options safer compared to positional arguments that can easily get mixed up.
d94c02e
to
7092541
Compare
Rebased (just in case after ##32930) and addressed comments, mainly:
|
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.
LGTM ACK 7092541
Reviewed range-diff this time, thanks for incorporating minor points:
git range-diff d94c02e...7092541
/** | ||
* Whether to fill in bip32 derivation information if available. | ||
*/ | ||
bool bip32_derivs{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.
introduce two different names for the same thing.
Yeah, this is what I had in mind & would prefer this over breaking change with the RPC. But fine to leave it as-is to avoid more churn.
Replace the
sign
,finalize
,bip32derivs
andsighash_type
arguments that are passed toFillPSBT()
andSignPSBTInput()
with aPSBTFillOptions
struct.Additionally this PR introduces:
This is used by
SignTransaction
and theMutableTransactionSignatureCreator
constructor.These changes make it easier to add additional options later without large code churn, such as
avoid_script_path
proposed in #32857. It also makes the use of default boolean options safer compared to positional arguments that can easily get mixed up.The
options
structs are usually passed inline, except insrc/rpc/rawtransaction_util.cpp
where otherwise LLVM 16 gets confused.