Skip to content
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

wallet: allow psbtbumpfee to work with txs with external inputs #23202

Merged
merged 7 commits into from Aug 22, 2022

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Oct 6, 2021

This PR allows psbtbumpfee to return a PSBT for transactions that contain external inputs. This does not work for bumping in the GUI nor bumpfee because these need private keys available to sign and send the transaction. But psbtbumpfee returns a psbt, so it is fine to not be able to sign.

In order to correctly estimate the size of the inputs for coin selection, the fee bumper will use the size of the inputs of the transaction being bumped. Because the sizes of signatures are not guaranteed, for external inputs, the fee bumper will verify the scripts with a special SignatureChecker which will compute the weight of all of the signatures in that input, and compute their weights if those signatures were maximally sized. This allows the fee bumper to obtain a max size estimate for each external input.

Builds on #23201 as it relies on the ability to pass weights in to coin selection.

Closes #23189

@fanquake fanquake added the Wallet label Oct 6, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 6, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22793 (Simplify BaseSignatureChecker virtual functions and GenericTransactionSignatureChecker constructors by achow101)

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.

@ghost
Copy link

ghost commented Oct 14, 2021

Concept ACK

@ghost
Copy link

ghost commented Jan 26, 2022

Compiling this branch now as its ready for review. Not sure if I will be able to test everything but this is an interesting feature which should exist in Core. Hoping other devs review this without any club.

@t-bast
Copy link
Contributor

t-bast commented Jan 26, 2022

I would really love to see this land. I can test this end-to-end with eclair whenever it's ready and verify that it lets us bump lightning transactions (I can add tests with various kinds of inputs, confirmed / unconfirmed / unsafe).

How does it impact @xekyo's work on ancestor aware funding (https://github.com/Xekyo/bitcoin/commits/ancestor-aware-funding)? Ideally the feerate computed here should take into account all unconfirmed ancestors, but maybe Xekyo's work would just land after this PR and fix its feerate computation?

@achow101
Copy link
Member Author

How does it impact @xekyo's work on ancestor aware funding (https://github.com/Xekyo/bitcoin/commits/ancestor-aware-funding)? Ideally the feerate computed here should take into account all unconfirmed ancestors, but maybe Xekyo's work would just land after this PR and fix its feerate computation?

I believe that work will require some mempool changes that have not been implemented yet, so it is probable that it will still be some time before that is ready for review.

@t-bast
Copy link
Contributor

t-bast commented Jan 26, 2022

Thanks for the quick answer, so I guess @xekyo's work will simply improve psbtbumpfee's feerate estimation when there are unconfirmed ancestors and can be added after this PR is merged.

@achow101
Copy link
Member Author

@t-bast @ishaanam @instagibbs @xekyo Re-review?

@t-bast
Copy link
Contributor

t-bast commented Aug 17, 2022

There seems to be an issue when I provide the fee_rate parameter, I'm getting the following (seemingly unrelated) error:

bitcoind: wallet/wallet.cpp:1540: bool wallet::FillInputToWeight(CTxIn&, int64_t): Assertion `txin.scriptWitness.IsNull()' failed.

I was calling psbtbumpfee on the following regtest tx:

02000000000102b72c3d62593110e0e340e15363b9d12dbe79af9fb9aa2087ba306436d5a51bca0200000000010000003182d6341b973d2f83b9b07a2075a6501e9753831df26427cbe0de6c601b43000100000000fdffffff02bb08000000000000220020352a6494d2541ba95998c1f2881bce71cb4fe420ebda7cba45f66d88222e4ba02858eb0200000000225120996aa742c86fe13934f855a461a3ac23acfca489369a3b80c8829ba5d122cbc005004730440220309709721d51a931c9984ae02c4f6cefc72d947a61b4d46d39f891f0ff24f92402202fd39201ccfa4e201e5f4c6a72fcb248ac985b21946dc07c2d1ccff3f30e45ed83473044022022fe0c3dd42c641e9cd4756360165597333ef24b1aebbe6f1a7f66e7e2288403022040cffadb335097ab36036d18ee18178520bc92b8bac894c430961242fe3e82880120fa64d24aac82ae7f180cd3fb75391a1be94913130d514b75d3d2001018f14f968d76a91458ea2a44f040121f04384be65d29024be6be21a18763ac672102a1af0b6995a260ad47f9438ae5525701c8bdafd3792b8418376384466f1e55777c8201208763a914a451fab97f394a6bb0e74f22992c227e28e62b2f88527c2103faf880218ed6f87580e99a4760857726a74adf878be803567f7babea4166c0a052ae6775022701b175ac6851b2756801401f5c05b6fc4a49e8b5bf4557753e9d861b62b3509bf82c497698328b519bd1f29360b89c095e22b4e1276d8801fe515ed15f46edd8ab74416b241fefef33927d00000000

Its second input is a wallet input and the second output is the change output, and the amount should allow bumping to the feerate I'm expecting.

@achow101
Copy link
Member Author

There seems to be an issue when I provide the fee_rate parameter, I'm getting the following (seemingly unrelated) error:

Good catch. I've added a fix for that and a test case.

@achow101 achow101 force-pushed the bumpfee-ext-inputs branch 2 times, most recently from ffd6935 to bea4313 Compare August 17, 2022 21:26
Copy link
Contributor

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

ACK bea4313, I tried to bump lightning htlc transactions and everything seems to work fine 👍

@fanquake fanquake requested review from ishaanam and instagibbs and removed request for ishaanam August 19, 2022 07:33
@instagibbs
Copy link
Member

ACK bea4313

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Needs to be rebased, b3d33ef was included in #25679.

Instead of calculating the fee by using what is stored in the wallet,
calculate it by looking up the UTXOs.
When bumping the fee of a transaction containing external inputs,
determine the weights of those inputs. Because signatures can have a
variable size, the script is executed with a special SignatureChecker
which will compute the total weight of the signatures in the transaction
and the weight if they were all maximum size signatures. This allows us
to compute the maximum weight of the input for use during coin
selection.
The max size calculation expects some inputs to have empty scriptSigs
and witnesses, so we need to clear these before doing that calculation.
In some cases, notably psbtbumpfee, it is okay, and potentially desired,
to be able to bump the fee of a transaction which contains external
inputs.
@achow101
Copy link
Member Author

Needs to be rebased, b3d33ef was already included in #25679.

Rebased

Copy link
Contributor

@ishaanam ishaanam left a comment

Choose a reason for hiding this comment

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

reACK b1f8fa3

src/wallet/test/feebumper_tests.cpp Outdated Show resolved Hide resolved
test/functional/wallet_bumpfee.py Outdated Show resolved Hide resolved
@ishaanam
Copy link
Contributor

reACK c3b099a

Copy link
Contributor

@t-bast t-bast left a comment

Choose a reason for hiding this comment

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

Re-ran my tests agains c3b099a, ACK

@fanquake fanquake merged commit 607d5a4 into bitcoin:master Aug 22, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 22, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Aug 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RPC: support fee bumping with external inputs
9 participants