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

[input/size] Check tx size constants #4775

Merged
merged 4 commits into from
Mar 10, 2021

Conversation

halseth
Copy link
Contributor

@halseth halseth commented Nov 17, 2020

We ensure the size constants and their godoc checks out.

See lightning/bolts#815 for a disagreement with the spec that was found in the process.

@halseth
Copy link
Contributor Author

halseth commented Nov 18, 2020

Moving to v0.13, will cherry pick what is needed for sweeper changes.

Copy link
Contributor

@bjarnemagnussen bjarnemagnussen left a comment

Choose a reason for hiding this comment

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

Although not touched in this PR I fell over the size description for BaseCommitmentTxSize in line 158, which says "125 + 43 * num-htlc-outputs bytes". Maybe the description should be changed to "125 bytes", and instead the "43 * num-htlc-outputs" explained in a line beneath it, as it is not part of the size calculation for BaseCommitmentTxSize?

Similarly for BaseAnchorCommitmentTxSize in line 179

input/size.go Outdated
// - OP_CSV: 1 byte // HTLC script types. The size won't be correct in all cases,
// - OP_DROP: 1 byte // but it is just an upper bound used for fee estimation in any case.
// - OP_1: 1 byte // These 3 extra bytes are only
// - OP_CSV: 1 byte // present for the for the
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a typo: uses two times "for the for the"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! 👍

input/size.go Outdated
// - OP_CSV: 1 byte
// - OP_DROP: 1 byte
// - OP_1: 1 byte // These 3 extra bytes are only
// - OP_CSV: 1 byte // present for the for the
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a typo: uses two times "for the for the"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed! 👍

@Roasbeef Roasbeef added bug fix fees Related to the fees paid for transactions (both LN and funding/commitment transactions) P1 MUST be fixed or reviewed labels Jan 28, 2021
@halseth halseth force-pushed the input-tx-size-constants branch 4 times, most recently from 32f9bd4 to 6dd5bfe Compare February 1, 2021 13:21
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🌸

//
// TODO(halseth): the non-confirmed version currently includes the
// overhead.
AcceptedHtlcScriptSizeConfirmed = AcceptedHtlcScriptSize // + HtlcConfirmedScriptOverhead
Copy link
Member

Choose a reason for hiding this comment

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

Why was this commented out in the past again?

Copy link
Member

Choose a reason for hiding this comment

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

Ah nvm, I see the TODO now

@@ -115,6 +115,7 @@ const (
// - Sequence: 4 bytes
InputSize = 32 + 4 + 1 + 4

// FundingInputSize 41 bytes
Copy link
Member

Choose a reason for hiding this comment

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

Where's the script that was run? Should we consider adding it to the repo, or instead extending our tests to craft the actual transaction to compare to the estimate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a pretty rough script I wrote, not sure if worth adding it since we shouldn't be changing these very often.

Posting for reference: halseth@d86684c

Copy link
Contributor

Choose a reason for hiding this comment

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

my vote would be to add the script and have it generate a test suite that verifies the actual size. we can fail the build if the tests are not properly committed in git or fail the size checks. I'd be okay with making that a follow up as well

}

// TestWitnessSizes asserts the correctness of our magic tx size constants.
func TestTxSizes(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

Scratch my other comment re extending the tests.

@Roasbeef Roasbeef requested review from cfromknecht and removed request for cfromknecht February 9, 2021 03:31
@halseth halseth force-pushed the input-tx-size-constants branch 2 times, most recently from 3720f15 to fc104fd Compare February 11, 2021 14:16
input/size_test.go Outdated Show resolved Hide resolved
@@ -115,6 +115,7 @@ const (
// - Sequence: 4 bytes
InputSize = 32 + 4 + 1 + 4

// FundingInputSize 41 bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

my vote would be to add the script and have it generate a test suite that verifies the actual size. we can fail the build if the tests are not properly committed in git or fail the size checks. I'd be okay with making that a follow up as well

@Roasbeef
Copy link
Member

Roasbeef commented Mar 5, 2021

What's needed to move this forward?

@halseth
Copy link
Contributor Author

halseth commented Mar 5, 2021

What's needed to move this forward?

Travis 🤪

This to more easily track mismatches if constants and get more accurate
fee estimates for the two channel types.

The non-anchor weight estimates will now be smaller, this is okay since
these constants are only being used for fee estimation (and will now be
more accurate).
We run a script that ensures the constant sizes listed is actually the
value of the constant.
Similar to what we do for witnesses, check that the HTLC weight
constants check out.

They actually do not, since the spec is off by one. We ensure we agree
with the spec.
@Roasbeef
Copy link
Member

@halseth looks fine to me?

Have you review comments been addressed @cfromknecht ?

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

LGTM 🏅

@cfromknecht cfromknecht merged commit 7e33548 into lightningnetwork:master Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix fees Related to the fees paid for transactions (both LN and funding/commitment transactions) P1 MUST be fixed or reviewed v0.13
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants