-
Notifications
You must be signed in to change notification settings - Fork 38.7k
fix assert crash when specified change output spend size is unknown #14380
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
|
Opening this to see if people think this is the right solution. |
a27865d to
268f495
Compare
|
Very nice find! |
|
The code wants to know the change signature size so it can figure out if it would have created change that was worthless to spend (because the spending will take more fees than the output is worth). Assuming the size is smallest plausible signature size would be conservative: it'll overvalue the change, at a risk of keeping change it could have eliminated. I think doing that would be strictly superior to not using BnB at all, since preventing BnB will always keep change it should eliminate. So, e.g. assuming any spend of an unknown type will take at least 32(txid)+4(vout)+4(sequence)+1(len)+64*0.25(signature) = 57 bytes would work. (don't assume my math is right. :) ) |
|
Hm yes I suppose you're right. Not running BnB is admitting defeat even if we actually end up being able to discard a larger value. I'll take a look at constructing something that makes a minimal segwit input weight. |
|
|
Isn't the problem that The definition of Line 573 in b012bbe
Lines 1510 to 1520 in b012bbe
The Line 2725 in b012bbe
Related open pull requests in need of review:
Please help reviewing those :-) |
|
@practicalswift yes that's why the assert is finally hit, but it's faulty logic regardless |
268f495 to
9bde981
Compare
|
Pushed a fix in line with @gmaxwell suggestions. It's pretty hardcoded, so I'd rather make this more programmatic, perhaps giving a "hint" to the dummy signer of what type it should be? |
|
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. |
|
Concept ACK |
9bde981 to
5db87a1
Compare
|
Updated the PR to use a function that uses DummySigner flow with an arbitrary valid pubkey as the P2SH-P2WPKH target to estimate the size more programatically. |
6d2a62f to
198830e
Compare
meshcollider
left a comment
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 198830e
test/functional/rpc_psbt.py
Outdated
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 in comment
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 fixed. Suggest something like "Make sure that the wallet can successfully create a funded psbt when it isn't able to sign for the change output" or similar.
|
utACK 198830e06bf4560cfb962e29c73c5b1357d90b37 |
|
|
|
The functional test could be better explained: We need it to try BnB coin selection with a change output that is a script that it doesn't have knowledge of. |
577033c to
0fb2e69
Compare
|
rebased, just a test conflict |
| static const bool DEFAULT_WALLETBROADCAST = true; | ||
| static const bool DEFAULT_DISABLE_WALLET = false; | ||
|
|
||
| //! Pre-calculated constants for input size estimation in *virtual size* |
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: how about Estimated nested input size in *virtual size*, see CalculateNestedKeyhashInputSize
|
utACK 0fb2e69 |
|
utACK 0fb2e69 |
|
utACK 0fb2e69 |
ryanofsky
left a comment
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.
Slightly tested ACK 0fb2e69. Just confirmed python test fails before and succeeds after the fix.
jnewbery
left a comment
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 0fb2e69.
Minor comment nit inline, but I suggest you don't change it in order not to invalidate previous ACKs.
test/functional/rpc_psbt.py
Outdated
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 fixed. Suggest something like "Make sure that the wallet can successfully create a funded psbt when it isn't able to sign for the change output" or similar.
|
utACK |
…e is unknown 0fb2e69 CreateTransaction: Assume minimum p2sh-p2wpkh spend size for unknown change (Gregory Sanders) b06483c Remove stale comment in CalculateMaximumSignedInputSize (Gregory Sanders) Pull request description: This is triggered anytime a fundraw type call(psbt or legacy) is used with a change output address that the wallet doesn't know how to sign for. This regression was added in 6a34ff5 since BnB coin selection actually cares about this. The fix is to assume the smallest typical spend, a P2SH-P2WPKH, which is calculated using a "prototype" dummy signature flow. Future work could generalize this infrastructure to get estimated sizes of inputs for a variety of types. I also removed a comment which I believe is stale and misleading. Tree-SHA512: c7e2be189e524f81a7aa4454ad9370cefba715e3781f1e462c8bab77e4d27540191419029e3ebda11e3744c0703271e479dcd560d05e4d470048d9633e34da16
|
@instagibbs Would you mind creating a backport for 0.17 of this? |
|
@MarcoFalke done |
…t spend size is unknown 2a5cc40 CreateTransaction: Assume minimum p2sh-p2wpkh spend size for unknown change (Gregory Sanders) 53dcf2b Remove stale comment in CalculateMaximumSignedInputSize (Gregory Sanders) Pull request description: backport of #14380 Tree-SHA512: 42e261bd797d1938f8e041ccd10073ecd1d72695e2e4ce322e5a3ce262647e32108b01dde73361b6d2ac36438522ab3c4cd58ca072194f25011132437430cd27
|
Backported in #14851. |
…change Github-Pull: bitcoin#14380 Rebased-From: 0fb2e69
Summary: Remove stale comment in CalculateMaximumSignedInputSize CreateTransaction: Assume minimum p2sh-p2wpkh spend size for unknown change This is a backport of Core [[bitcoin/bitcoin#14380 | PR14380]] Test Plan: ninja check-all Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D8500
This is triggered anytime a fundraw type call(psbt or legacy) is used with a change output address that the wallet doesn't know how to sign for.
This regression was added in 6a34ff5 since BnB coin selection actually cares about this.
The fix is to assume the smallest typical spend, a P2SH-P2WPKH, which is calculated using a "prototype" dummy signature flow. Future work could generalize this infrastructure to get estimated sizes of inputs for a variety of types.
I also removed a comment which I believe is stale and misleading.