-
Notifications
You must be signed in to change notification settings - Fork 271
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
Restore Send button when using external signer #555
Conversation
Concept ACK. I've verified that no new or changed strings are presented. |
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
src/qt/sendcoinsdialog.cpp
Outdated
// Copy PSBT to clipboard and offer to save | ||
presentPSBT(psbtx); | ||
} else { // Send clicked | ||
assert(!model->wallet().privateKeysDisabled() || model->wallet().hasExternalSigner()); | ||
bool complete = false; |
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 it makes more sense to refactor this to:
bool broadcast = true;
if (model->wallet().hasExternalSigner()) {
// ...
bool complete;
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
if (complete) {
// ...
} else {
// ...
broadcast = false
}
}
if (broadcast) {
// ...
}
This commit does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change
a49bb0c
to
33d165d
Compare
Addressed @promag's feedback. |
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. |
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.
@Sjors it will broadcast even if you reject signing on the device, so it's missing broadcast = false
in that case.
src/qt/sendcoinsdialog.cpp
Outdated
@@ -502,19 +502,34 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked) | |||
} | |||
|
|||
bool send_failure = false; | |||
if (retval == QMessageBox::Save) { | |||
bool broadcast = 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.
diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp
index c420aa3581..87a0e4a098 100644
--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -502,7 +502,6 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
}
bool send_failure = false;
- bool broadcast = true;
if (retval == QMessageBox::Save) { // Create Unsigned clicked
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
PartiallySignedTransaction psbtx(mtx);
@@ -510,11 +509,13 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
presentPSBT(psbtx);
} else { // Send clicked
assert(!model->wallet().privateKeysDisabled() || model->wallet().hasExternalSigner());
+ bool broadcast = true;
if (model->wallet().hasExternalSigner()) {
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
PartiallySignedTransaction psbtx(mtx);
bool complete = false;
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
+ broadcast = complete;
// A transaction signed with an external signer is not always complete,
// e.g. in a multisig wallet.
if (complete) {
@@ -523,7 +524,6 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
m_current_transaction->setWtx(tx);
} else if (!send_failure) {
presentPSBT(psbtx);
- broadcast = false;
}
}
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 the user rejects the transaction then complete = false
and it will present the PSBT. We can't tell the difference between rejection and failure, so that's difficult to avoid. I don't see how this patch would change 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.
If user rejects then complete = false
and send_failure = true
, so it doesn't presentPSBT()
and because
broadcast = true
it calls model->sendCoins()
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 see. I restructured this code and fix a bit...
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.
Thanks, LGTM, will re-test.
Concept ACK |
4ed2a3b
to
86e3e2c
Compare
Concept ACK |
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.
Tested ACK 86e3e2c.
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.
Untested ACK 86e3e2c code review and debug build, the approach and logic looks correct
A few style and readability suggestions, happy to re-review if you update.
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 86e3e2c except for 1 part I'm unsure on
bool complete = false; | ||
// Always fill without signing first. This prevents an external signer | ||
// from being called prematurely and is not expensive. | ||
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, nullptr, psbtx, complete); |
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.
e1c1c61 claims "Does not change behavior.", yet this is no longer done for wallets without an external signer.
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.
Good point. I moved this out of the helper function.
It leads to some duplication in 0538614, but it's probably better to preserve the behavior. It might even useful, though I'm a bit rusty on what PSBT filling does on top of what the wallet already does.
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, as a potential follow-up it looks like this code block could be potentially de-duped by extracting to a helper method that returns psbtx
and mtx
.
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
PartiallySignedTransaction psbtx(mtx);
bool complete = false;
TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
assert(!complete);
assert(err == TransactionError::OK);
(and TransactionError err
could be const)
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'm going to avoid touching this now, but I agree it would be good to move into a helper.
86e3e2c
to
225794f
Compare
347871f
to
0538614
Compare
src/qt/sendcoinsdialog.cpp
Outdated
bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx, CMutableTransaction& mtx, bool& complete) { | ||
TransactionError err; | ||
try { | ||
err = model->wallet().fillPSBT(SIGHASH_ALL, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete); |
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.
sign
was true
here - why was it changed to false
?
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.
Yikes, I broke that during the style fix.
(fixed and re-tested on device this time)
Does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change
Before this change the send confirmation dialog would keep the Send option disabled. The Create Unsigned choice would actually send. This is potentially confusing. With this change the Create Unsigned button will not attempt to sign and always produce a PSBT. The Send button will attempt to sign, and only return a PSBT if more signatures are needed. When using an external signer, the Create Unsigned option only appears when PSBT controls are enabled in the wallet settings. This commit maintains the pre-existing behavior of filling the PSBT (without signing) even when not using an external signer. Closes bitcoin-core#551 Co-authored-by: Jon Atack <jon@atack.com>
0538614
to
2efdfb8
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.
utACK 2efdfb8
utACK 2efdfb8 diff review since my last review, code re-review, rebased to current master, verified clean debug build of each commit |
This commit does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Github-Pull: bitcoin-core/gui#555 Rebased-From: 026b5b4
Does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Github-Pull: bitcoin-core/gui#555 Rebased-From: 4b5a6cd
Before this change the send confirmation dialog would keep the Send option disabled. The Create Unsigned choice would actually send. This is potentially confusing. With this change the Create Unsigned button will not attempt to sign and always produce a PSBT. The Send button will attempt to sign, and only return a PSBT if more signatures are needed. When using an external signer, the Create Unsigned option only appears when PSBT controls are enabled in the wallet settings. This commit maintains the pre-existing behavior of filling the PSBT (without signing) even when not using an external signer. Closes bitcoin#551 Co-authored-by: Jon Atack <jon@atack.com> Github-Pull: bitcoin-core/gui#555 Rebased-From: 2efdfb8
Backported in bitcoin/bitcoin#24596. |
It might be good to have another tested ACK of the latest push. |
70f2c57 options: flip listenonion to false if not listening (Vasil Dimov) 642f272 gui: restore Send for external signer (Sjors Provoost) 9406946 refactor: helper function signWithExternalSigner() (Sjors Provoost) fc421d4 move-only: helper function to present PSBT (Sjors Provoost) Pull request description: Backports from the GUI repo: - bitcoin-core/gui#555 - bitcoin-core/gui#568 ACKs for top commit: Sjors: utACK 70f2c57 gruve-p: ACK 70f2c57 Tree-SHA512: 883c442f8b789a9d11c949179e4382843cbb979a89a625bef3f481c7070421681d9db2af0e5b2449abca362c8ba05cf61db5893aeb6a9237b02088c2fb71e93e
This commit does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Conflicts: src/qt/sendcoinsdialog.cpp Github-Pull: bitcoin-core/gui#555 Rebased-From: 026b5b4523317fdefc69cf5cec55f76f18ad0c0a
Does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Github-Pull: bitcoin-core/gui#555 Rebased-From: 4b5a6cd14967b8ec3cb525e4cb18628de6c15091
Before this change the send confirmation dialog would keep the Send option disabled. The Create Unsigned choice would actually send. This is potentially confusing. With this change the Create Unsigned button will not attempt to sign and always produce a PSBT. The Send button will attempt to sign, and only return a PSBT if more signatures are needed. When using an external signer, the Create Unsigned option only appears when PSBT controls are enabled in the wallet settings. This commit maintains the pre-existing behavior of filling the PSBT (without signing) even when not using an external signer. Closes #551 Co-authored-by: Jon Atack <jon@atack.com> Github-Pull: bitcoin-core/gui#555 Rebased-From: 2efdfb88aab6496dcf2b98e0de30635bc6bade85
This commit does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Github-Pull: bitcoin-core/gui#555 Rebased-From: 026b5b4523317fdefc69cf5cec55f76f18ad0c0a
Does not change behavior. Review hint: git show --color-moved --color-moved-ws=allow-indentation-change Github-Pull: bitcoin-core/gui#555 Rebased-From: 4b5a6cd14967b8ec3cb525e4cb18628de6c15091
Before this change the send confirmation dialog would keep the Send option disabled. The Create Unsigned choice would actually send. This is potentially confusing. With this change the Create Unsigned button will not attempt to sign and always produce a PSBT. The Send button will attempt to sign, and only return a PSBT if more signatures are needed. When using an external signer, the Create Unsigned option only appears when PSBT controls are enabled in the wallet settings. This commit maintains the pre-existing behavior of filling the PSBT (without signing) even when not using an external signer. Closes #551 Co-authored-by: Jon Atack <jon@atack.com> Github-Pull: bitcoin-core/gui#555 Rebased-From: 2efdfb88aab6496dcf2b98e0de30635bc6bade85
Fixes #551
For the simplest use case of a wallet with one external signer and "PSBT Controls" disabled in settings (the default), the send dialog will behave the same as when using a wallet with private keys. I.e. there's no "Create Unsigned" button.
When PSBT controls are turned on, you can now actually make a PSBT with signing it; before this PR that button would trigger a sign event and would broadcast the transaction.
In case a multisig, the Send button will sign on the device, and then fall back to presenting a PSBT (same behavior as before #441).
This PR starts with two refactoring commits to move some stuff into a helper function for improved readability in general, and to make the main commit easier to review.