-
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
[input/size] Check tx size constants #4775
Merged
cfromknecht
merged 4 commits into
lightningnetwork:master
from
halseth:input-tx-size-constants
Mar 10, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ const ( | |
// - Sequence: 4 bytes | ||
InputSize = 32 + 4 + 1 + 4 | ||
|
||
// FundingInputSize 41 bytes | ||
// FundingInputSize represents the size of an input to a funding | ||
// transaction, and is equivalent to the size of a standard segwit input | ||
// as calculated above. | ||
|
@@ -204,31 +205,37 @@ const ( | |
// HTLCWeight 172 weight | ||
HTLCWeight = witnessScaleFactor * HTLCSize | ||
|
||
// HtlcTimeoutWeight 663 weight | ||
// HtlcTimeoutWeight is the weight of the HTLC timeout transaction | ||
// which will transition an outgoing HTLC to the delay-and-claim state. | ||
HtlcTimeoutWeight = 663 | ||
|
||
// HtlcSuccessWeight 703 weight | ||
// HtlcSuccessWeight is the weight of the HTLC success transaction | ||
// which will transition an incoming HTLC to the delay-and-claim state. | ||
HtlcSuccessWeight = 703 | ||
|
||
// HtlcConfirmedScriptOverhead 3 bytes | ||
// HtlcConfirmedScriptOverhead is the extra length of an HTLC script | ||
// that requires confirmation before it can be spent. These extra bytes | ||
// is a result of the extra CSV check. | ||
HtlcConfirmedScriptOverhead = 3 | ||
|
||
// HtlcTimeoutWeightConfirmed 666 weight | ||
// HtlcTimeoutWeightConfirmed is the weight of the HTLC timeout | ||
// transaction which will transition an outgoing HTLC to the | ||
// delay-and-claim state, for the confirmed HTLC outputs. It is 3 bytes | ||
// larger because of the additional CSV check in the input script. | ||
HtlcTimeoutWeightConfirmed = HtlcTimeoutWeight + HtlcConfirmedScriptOverhead | ||
|
||
// HtlcSuccessWeightCOnfirmed is the weight of the HTLC success | ||
// HtlcSuccessWeightConfirmed 706 weight | ||
// HtlcSuccessWeightConfirmed is the weight of the HTLC success | ||
// transaction which will transition an incoming HTLC to the | ||
// delay-and-claim state, for the confirmed HTLC outputs. It is 3 bytes | ||
// larger because of the cdditional CSV check in the input script. | ||
HtlcSuccessWeightConfirmed = HtlcSuccessWeight + HtlcConfirmedScriptOverhead | ||
|
||
// MaxHTLCNumber 966 | ||
// MaxHTLCNumber is the maximum number HTLCs which can be included in a | ||
// commitment transaction. This limit was chosen such that, in the case | ||
// of a contract breach, the punishment transaction is able to sweep | ||
|
@@ -286,7 +293,7 @@ const ( | |
// - witness_script (to_remote_delayed_script) | ||
ToRemoteConfirmedWitnessSize = 1 + 1 + 73 + 1 + ToRemoteConfirmedScriptSize | ||
|
||
// AcceptedHtlcScriptSize 143 bytes | ||
// AcceptedHtlcScriptSize 140 bytes | ||
// - OP_DUP: 1 byte | ||
// - OP_HASH160: 1 byte | ||
// - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length) | ||
|
@@ -321,20 +328,18 @@ const ( | |
// - OP_DROP: 1 byte | ||
// - OP_CHECKSIG: 1 byte | ||
// - OP_ENDIF: 1 byte | ||
// - OP_1: 1 byte // These 3 extra bytes are used for both confirmed and regular | ||
// - 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 confirmed | ||
// - OP_DROP: 1 byte // HTLC script types. | ||
// - OP_ENDIF: 1 byte | ||
AcceptedHtlcScriptSize = 3*1 + 20 + 5*1 + 33 + 8*1 + 20 + 4*1 + | ||
33 + 5*1 + 4 + 8*1 | ||
33 + 5*1 + 4 + 5*1 | ||
|
||
// AcceptedHtlcScriptSizeConfirmed 143 bytes | ||
// | ||
// TODO(halseth): the non-confirmed version currently includes the | ||
// overhead. | ||
AcceptedHtlcScriptSizeConfirmed = AcceptedHtlcScriptSize // + HtlcConfirmedScriptOverhead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this commented out in the past again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah nvm, I see the TODO now |
||
AcceptedHtlcScriptSizeConfirmed = AcceptedHtlcScriptSize + | ||
HtlcConfirmedScriptOverhead | ||
|
||
// AcceptedHtlcTimeoutWitnessSize 219 | ||
// AcceptedHtlcTimeoutWitnessSize 217 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - sender_sig_length: 1 byte | ||
// - sender_sig: 73 bytes | ||
|
@@ -343,7 +348,11 @@ const ( | |
// - witness_script: (accepted_htlc_script) | ||
AcceptedHtlcTimeoutWitnessSize = 1 + 1 + 73 + 1 + 1 + AcceptedHtlcScriptSize | ||
|
||
// AcceptedHtlcPenaltyWitnessSize 252 bytes | ||
// AcceptedHtlcTimeoutWitnessSizeConfirmed 220 bytes | ||
AcceptedHtlcTimeoutWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 1 + | ||
AcceptedHtlcScriptSizeConfirmed | ||
|
||
// AcceptedHtlcPenaltyWitnessSize 250 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - revocation_sig_length: 1 byte | ||
// - revocation_sig: 73 bytes | ||
|
@@ -353,7 +362,11 @@ const ( | |
// - witness_script (accepted_htlc_script) | ||
AcceptedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + AcceptedHtlcScriptSize | ||
|
||
// AcceptedHtlcSuccessWitnessSize 322 bytes | ||
// AcceptedHtlcPenaltyWitnessSizeConfirmed 253 bytes | ||
AcceptedHtlcPenaltyWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 33 + 1 + | ||
AcceptedHtlcScriptSizeConfirmed | ||
|
||
// AcceptedHtlcSuccessWitnessSize 324 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - nil_length: 1 byte | ||
// - sig_alice_length: 1 byte | ||
|
@@ -364,6 +377,8 @@ const ( | |
// - preimage: 32 bytes | ||
// - witness_script_length: 1 byte | ||
// - witness_script (accepted_htlc_script) | ||
// | ||
// Input to second level success tx, spending non-delayed HTLC output. | ||
AcceptedHtlcSuccessWitnessSize = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 32 + 1 + | ||
AcceptedHtlcScriptSize | ||
|
||
|
@@ -373,7 +388,7 @@ const ( | |
AcceptedHtlcSuccessWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 32 + 1 + | ||
AcceptedHtlcScriptSizeConfirmed | ||
|
||
// OfferedHtlcScriptSize 136 bytes | ||
// OfferedHtlcScriptSize 133 bytes | ||
// - OP_DUP: 1 byte | ||
// - OP_HASH160: 1 byte | ||
// - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length) | ||
|
@@ -404,19 +419,17 @@ const ( | |
// - OP_EQUALVERIFY: 1 byte | ||
// - OP_CHECKSIG: 1 byte | ||
// - OP_ENDIF: 1 byte | ||
// - OP_1: 1 byte | ||
// - 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 confirmed | ||
// - OP_DROP: 1 byte // HTLC script types. | ||
// - OP_ENDIF: 1 byte | ||
OfferedHtlcScriptSize = 3*1 + 20 + 5*1 + 33 + 10*1 + 33 + 5*1 + 20 + 7*1 | ||
OfferedHtlcScriptSize = 3*1 + 20 + 5*1 + 33 + 10*1 + 33 + 5*1 + 20 + 4*1 | ||
|
||
// OfferedHtlcScriptSizeConfirmed 136 bytes | ||
// | ||
// TODO(halseth): the non-confirmed version currently includes the | ||
// overhead. | ||
OfferedHtlcScriptSizeConfirmed = OfferedHtlcScriptSize // + HtlcConfirmedScriptOverhead | ||
OfferedHtlcScriptSizeConfirmed = OfferedHtlcScriptSize + | ||
HtlcConfirmedScriptOverhead | ||
|
||
// OfferedHtlcSuccessWitnessSize 245 bytes | ||
// OfferedHtlcSuccessWitnessSize 242 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - receiver_sig_length: 1 byte | ||
// - receiver_sig: 73 bytes | ||
|
@@ -426,6 +439,10 @@ const ( | |
// - witness_script (offered_htlc_script) | ||
OfferedHtlcSuccessWitnessSize = 1 + 1 + 73 + 1 + 32 + 1 + OfferedHtlcScriptSize | ||
|
||
// OfferedHtlcSuccessWitnessSizeConfirmed 245 bytes | ||
OfferedHtlcSuccessWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 32 + 1 + | ||
OfferedHtlcScriptSizeConfirmed | ||
|
||
// OfferedHtlcTimeoutWitnessSize 285 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - nil_length: 1 byte | ||
|
@@ -436,15 +453,18 @@ const ( | |
// - nil_length: 1 byte | ||
// - witness_script_length: 1 byte | ||
// - witness_script (offered_htlc_script) | ||
OfferedHtlcTimeoutWitnessSize = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 1 + OfferedHtlcScriptSize | ||
// | ||
// Input to second level timeout tx, spending non-delayed HTLC output. | ||
OfferedHtlcTimeoutWitnessSize = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 1 + | ||
OfferedHtlcScriptSize | ||
|
||
// OfferedHtlcTimeoutWitnessSizeConfirmed 288 bytes | ||
// | ||
// Input to second level timeout tx, spending 1 CSV delayed HTLC output. | ||
OfferedHtlcTimeoutWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 1 + | ||
OfferedHtlcScriptSizeConfirmed | ||
|
||
// OfferedHtlcPenaltyWitnessSize 246 bytes | ||
// OfferedHtlcPenaltyWitnessSize 243 bytes | ||
// - number_of_witness_elements: 1 byte | ||
// - revocation_sig_length: 1 byte | ||
// - revocation_sig: 73 bytes | ||
|
@@ -454,6 +474,10 @@ const ( | |
// - witness_script (offered_htlc_script) | ||
OfferedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + OfferedHtlcScriptSize | ||
|
||
// OfferedHtlcPenaltyWitnessSizeConfirmed 246 bytes | ||
OfferedHtlcPenaltyWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 33 + 1 + | ||
OfferedHtlcScriptSizeConfirmed | ||
|
||
// AnchorScriptSize 40 bytes | ||
// - pubkey_length: 1 byte | ||
// - pubkey: 33 bytes | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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?
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.
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
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.
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