-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
lnwallet/size: correct commit to-local and 2nd stage script/witness sizes #1617
lnwallet/size: correct commit to-local and 2nd stage script/witness sizes #1617
Conversation
This addresses the (believed) cause of #1610, tho on its own is not the fix for afflicted users |
0dc050a
to
c151078
Compare
fwiw, the spec estimates 8 bytes for the CSV delay, i can also change the PR to match. that being said, this does seem a place we could deviate if our policy on accepted CSV ranges is properly enforced |
700ce26
to
faf34a5
Compare
This fix was tested by setting In had to comment out the other tests because some of them check sweep balance, which is altered by changing the fee rate. The selected test suite was:
Of these, the integration tests failed for:
All of these now pass after correcting the size estimates. |
In this commit, we correct our size estimates for to-local scripts, which are used on the commitment transaction and the htlc success/timeout transactions. There have been observed cases of transactions getting stuck because our estimates were too low, and cause the transactions to not be relayed. Our previous estimate for the commitment to-local script was derived from an older version of the script. Though the estimate is greater than the actual size, this has been updated with the current estimate of 79 bytes. This estimates makes the assumption that CSV delays will be at most 4 bytes when serialized. Since this value is expressed in relative block heights, this should be more than sufficient for our needs, even though the maximum possible size for the little-endian int64 is 9 bytes (plus an OP_DATA). The other correction is to use the ToLocalScriptSize as our estimate for htlc timeout/success scripts, as they are the same script. Previously, our estimate was derived from the proper script, though we were 6 bytes shy of the new to-local estimate, since we counted the csv_delay as 1 byte, and missed some other OP_DATAs. All derived estimates have been updating depending on the new and improved ToLocalScriptSize estimate, and fix some estimates that did not include the witness length in the estimate. Finally, we correct some weight miscalculations in: - AcceptedHtlcTimeoutWitnessSize: missing data push lengths - OfferedHtlcSuccessWitnessSize: extra 73 byte sig, missing data push lengths - OfferedHtlcPenaltyWitnessSize: missing 33 byte pubkey
This commit switches over the estimates for htlc success/timeout witness sizes to use a symmetric variable, highlighting their equivalence in size.
faf34a5
to
d41d63a
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.
LGTM 👍
// - zero_length: 1 byte | ||
// - witness_script_length: 1 byte | ||
// - witness_script (to_local_script) | ||
// - OP_CHECKSIG: 1 byte |
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.
DId the scripts change at some point here, or was it just always wrong?
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.
The size of this one is correct according to the spec, just the script in the comment is wrong. The other ones were actually incorrect
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.
The spec says 8 bytes for the csv, but in practice this is more like one or two bytes as it's in relative block height. The spec doesn't account for the OP_DATA as we do here, where we allocate 1 + 4 bytes for the CSV. The spec's value overestimates the total size, even without the OP_DATA. I'd be fine with making it 8 as well just to match the spec.
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 ☄️
In this commit, we correct our size estimates for to-local scripts,
which are used on the commitment transaction and the htlc
success/timeout transactions. There have been observed cases of
transactions getting stuck because our estimates were too low, and cause
the transactions to not be relayed.
Our previous estimate for the commitment to-local script was correct
though comment had outdated script. Though the estimate is greater
than the actual size, this has been updated with a proposed estimate
of 79 bytes.
This estimate makes the assumption that CSV delays will be at most
4 bytes when serialized. Since this value is expressed in relative block
heights, this should be more than sufficient for our needs, even though
the maximum possible size for the little-endian int64 is 9 bytes (plus
an OP_DATA).
The other correction is to use the ToLocalScriptSize as our estimate for
htlc timeout/success scripts, as they are the same script. Previously,
our estimate was derived from the proper script, though we were 6 bytes
shy of the new to-local estimate, since we counted the csv_delay as 1
byte, and missed some other OP_DATAs.
All derived estimates have been updating depending on the new and
improved ToLocalScriptSize estimate, and fix some estimates that did not
include the witness length in the estimate.
Finally, we correct some weight miscalculations in: