input/size: split constants into confirmed/non-confirmed

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).
This commit is contained in:
Johan T. Halseth 2020-11-17 13:23:00 +01:00
parent 56b61078c5
commit fe71c905e5
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 57 additions and 40 deletions

@ -286,7 +286,7 @@ const (
// - witness_script (to_remote_delayed_script) // - witness_script (to_remote_delayed_script)
ToRemoteConfirmedWitnessSize = 1 + 1 + 73 + 1 + ToRemoteConfirmedScriptSize ToRemoteConfirmedWitnessSize = 1 + 1 + 73 + 1 + ToRemoteConfirmedScriptSize
// AcceptedHtlcScriptSize 143 bytes // AcceptedHtlcScriptSize 140 bytes
// - OP_DUP: 1 byte // - OP_DUP: 1 byte
// - OP_HASH160: 1 byte // - OP_HASH160: 1 byte
// - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length) // - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length)
@ -321,20 +321,18 @@ const (
// - OP_DROP: 1 byte // - OP_DROP: 1 byte
// - OP_CHECKSIG: 1 byte // - OP_CHECKSIG: 1 byte
// - OP_ENDIF: 1 byte // - OP_ENDIF: 1 byte
// - OP_1: 1 byte // These 3 extra bytes are used for both confirmed and regular // - OP_1: 1 byte // These 3 extra bytes are only
// - OP_CSV: 1 byte // HTLC script types. The size won't be correct in all cases, // - OP_CSV: 1 byte // present for the confirmed
// - OP_DROP: 1 byte // but it is just an upper bound used for fee estimation in any case. // - OP_DROP: 1 byte // HTLC script types.
// - OP_ENDIF: 1 byte // - OP_ENDIF: 1 byte
AcceptedHtlcScriptSize = 3*1 + 20 + 5*1 + 33 + 8*1 + 20 + 4*1 + 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 // AcceptedHtlcScriptSizeConfirmed 143 bytes
// AcceptedHtlcScriptSizeConfirmed = AcceptedHtlcScriptSize +
// TODO(halseth): the non-confirmed version currently includes the HtlcConfirmedScriptOverhead
// overhead.
AcceptedHtlcScriptSizeConfirmed = AcceptedHtlcScriptSize // + HtlcConfirmedScriptOverhead
// AcceptedHtlcTimeoutWitnessSize 219 // AcceptedHtlcTimeoutWitnessSize 216
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - sender_sig_length: 1 byte // - sender_sig_length: 1 byte
// - sender_sig: 73 bytes // - sender_sig: 73 bytes
@ -343,7 +341,11 @@ const (
// - witness_script: (accepted_htlc_script) // - witness_script: (accepted_htlc_script)
AcceptedHtlcTimeoutWitnessSize = 1 + 1 + 73 + 1 + 1 + AcceptedHtlcScriptSize AcceptedHtlcTimeoutWitnessSize = 1 + 1 + 73 + 1 + 1 + AcceptedHtlcScriptSize
// AcceptedHtlcPenaltyWitnessSize 252 bytes // AcceptedHtlcTimeoutWitnessSizeConfirmed 219 bytes
AcceptedHtlcTimeoutWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 1 +
AcceptedHtlcScriptSizeConfirmed
// AcceptedHtlcPenaltyWitnessSize 249 bytes
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - revocation_sig_length: 1 byte // - revocation_sig_length: 1 byte
// - revocation_sig: 73 bytes // - revocation_sig: 73 bytes
@ -353,7 +355,11 @@ const (
// - witness_script (accepted_htlc_script) // - witness_script (accepted_htlc_script)
AcceptedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + AcceptedHtlcScriptSize AcceptedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + AcceptedHtlcScriptSize
// AcceptedHtlcSuccessWitnessSize 322 bytes // AcceptedHtlcPenaltyWitnessSizeConfirmed 252 bytes
AcceptedHtlcPenaltyWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 33 + 1 +
AcceptedHtlcScriptSizeConfirmed
// AcceptedHtlcSuccessWitnessSize 319 bytes
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - nil_length: 1 byte // - nil_length: 1 byte
// - sig_alice_length: 1 byte // - sig_alice_length: 1 byte
@ -364,16 +370,18 @@ const (
// - preimage: 32 bytes // - preimage: 32 bytes
// - witness_script_length: 1 byte // - witness_script_length: 1 byte
// - witness_script (accepted_htlc_script) // - 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 + AcceptedHtlcSuccessWitnessSize = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 32 + 1 +
AcceptedHtlcScriptSize AcceptedHtlcScriptSize
// AcceptedHtlcSuccessWitnessSizeConfirmed 327 bytes // AcceptedHtlcSuccessWitnessSizeConfirmed 322 bytes
// //
// Input to second level success tx, spending 1 CSV delayed HTLC output. // Input to second level success tx, spending 1 CSV delayed HTLC output.
AcceptedHtlcSuccessWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 32 + 1 + AcceptedHtlcSuccessWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 32 + 1 +
AcceptedHtlcScriptSizeConfirmed AcceptedHtlcScriptSizeConfirmed
// OfferedHtlcScriptSize 136 bytes // OfferedHtlcScriptSize 133 bytes
// - OP_DUP: 1 byte // - OP_DUP: 1 byte
// - OP_HASH160: 1 byte // - OP_HASH160: 1 byte
// - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length) // - OP_DATA: 1 byte (RIPEMD160(SHA256(revocationkey)) length)
@ -404,19 +412,17 @@ const (
// - OP_EQUALVERIFY: 1 byte // - OP_EQUALVERIFY: 1 byte
// - OP_CHECKSIG: 1 byte // - OP_CHECKSIG: 1 byte
// - OP_ENDIF: 1 byte // - OP_ENDIF: 1 byte
// - OP_1: 1 byte // - OP_1: 1 byte // These 3 extra bytes are only
// - OP_CSV: 1 byte // - OP_CSV: 1 byte // present for the confirmed
// - OP_DROP: 1 byte // - OP_DROP: 1 byte // HTLC script types.
// - OP_ENDIF: 1 byte // - 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 // OfferedHtlcScriptSizeConfirmed 136 bytes
// OfferedHtlcScriptSizeConfirmed = OfferedHtlcScriptSize +
// TODO(halseth): the non-confirmed version currently includes the HtlcConfirmedScriptOverhead
// overhead.
OfferedHtlcScriptSizeConfirmed = OfferedHtlcScriptSize // + HtlcConfirmedScriptOverhead
// OfferedHtlcSuccessWitnessSize 245 bytes // OfferedHtlcSuccessWitnessSize 242 bytes
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - receiver_sig_length: 1 byte // - receiver_sig_length: 1 byte
// - receiver_sig: 73 bytes // - receiver_sig: 73 bytes
@ -426,7 +432,11 @@ const (
// - witness_script (offered_htlc_script) // - witness_script (offered_htlc_script)
OfferedHtlcSuccessWitnessSize = 1 + 1 + 73 + 1 + 32 + 1 + OfferedHtlcScriptSize OfferedHtlcSuccessWitnessSize = 1 + 1 + 73 + 1 + 32 + 1 + OfferedHtlcScriptSize
// OfferedHtlcTimeoutWitnessSize 285 bytes // OfferedHtlcSuccessWitnessSizeConfirmed 245 bytes
OfferedHtlcSuccessWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 32 + 1 +
OfferedHtlcScriptSizeConfirmed
// OfferedHtlcTimeoutWitnessSize 282 bytes
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - nil_length: 1 byte // - nil_length: 1 byte
// - sig_alice_length: 1 byte // - sig_alice_length: 1 byte
@ -436,15 +446,18 @@ const (
// - nil_length: 1 byte // - nil_length: 1 byte
// - witness_script_length: 1 byte // - witness_script_length: 1 byte
// - witness_script (offered_htlc_script) // - 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 // OfferedHtlcTimeoutWitnessSizeConfirmed 285 bytes
// //
// Input to second level timeout tx, spending 1 CSV delayed HTLC output. // Input to second level timeout tx, spending 1 CSV delayed HTLC output.
OfferedHtlcTimeoutWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 1 + OfferedHtlcTimeoutWitnessSizeConfirmed = 1 + 1 + 1 + 73 + 1 + 73 + 1 + 1 +
OfferedHtlcScriptSizeConfirmed OfferedHtlcScriptSizeConfirmed
// OfferedHtlcPenaltyWitnessSize 246 bytes // OfferedHtlcPenaltyWitnessSize 243 bytes
// - number_of_witness_elements: 1 byte // - number_of_witness_elements: 1 byte
// - revocation_sig_length: 1 byte // - revocation_sig_length: 1 byte
// - revocation_sig: 73 bytes // - revocation_sig: 73 bytes
@ -454,6 +467,10 @@ const (
// - witness_script (offered_htlc_script) // - witness_script (offered_htlc_script)
OfferedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + OfferedHtlcScriptSize OfferedHtlcPenaltyWitnessSize = 1 + 1 + 73 + 1 + 33 + 1 + OfferedHtlcScriptSize
// OfferedHtlcPenaltyWitnessSizeConfirmed 246 bytes
OfferedHtlcPenaltyWitnessSizeConfirmed = 1 + 1 + 73 + 1 + 33 + 1 +
OfferedHtlcScriptSizeConfirmed
// AnchorScriptSize 40 bytes // AnchorScriptSize 40 bytes
// - pubkey_length: 1 byte // - pubkey_length: 1 byte
// - pubkey: 33 bytes // - pubkey: 33 bytes

@ -485,7 +485,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc revoke", name: "offered htlc revoke",
expSize: input.OfferedHtlcPenaltyWitnessSize - 3, expSize: input.OfferedHtlcPenaltyWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.SenderHTLCScript( witScript, err := input.SenderHTLCScript(
testPubkey, testPubkey, testPubkey, testPubkey, testPubkey, testPubkey,
@ -515,7 +515,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc revoke confirmed", name: "offered htlc revoke confirmed",
expSize: input.OfferedHtlcPenaltyWitnessSize, expSize: input.OfferedHtlcPenaltyWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
hash := make([]byte, 20) hash := make([]byte, 20)
@ -547,7 +547,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc timeout", name: "offered htlc timeout",
expSize: input.OfferedHtlcTimeoutWitnessSize - 3, expSize: input.OfferedHtlcTimeoutWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.SenderHTLCScript( witScript, err := input.SenderHTLCScript(
testPubkey, testPubkey, testPubkey, testPubkey, testPubkey, testPubkey,
@ -574,7 +574,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc timeout confirmed", name: "offered htlc timeout confirmed",
expSize: input.OfferedHtlcTimeoutWitnessSize, expSize: input.OfferedHtlcTimeoutWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.SenderHTLCScript( witScript, err := input.SenderHTLCScript(
testPubkey, testPubkey, testPubkey, testPubkey, testPubkey, testPubkey,
@ -601,7 +601,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc success", name: "offered htlc success",
expSize: input.OfferedHtlcSuccessWitnessSize - 3, expSize: input.OfferedHtlcSuccessWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.SenderHTLCScript( witScript, err := input.SenderHTLCScript(
testPubkey, testPubkey, testPubkey, testPubkey, testPubkey, testPubkey,
@ -627,7 +627,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "offered htlc success confirmed", name: "offered htlc success confirmed",
expSize: input.OfferedHtlcSuccessWitnessSize, expSize: input.OfferedHtlcSuccessWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.SenderHTLCScript( witScript, err := input.SenderHTLCScript(
testPubkey, testPubkey, testPubkey, testPubkey, testPubkey, testPubkey,
@ -653,7 +653,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc revoke", name: "accepted htlc revoke",
expSize: input.AcceptedHtlcPenaltyWitnessSize - 3, expSize: input.AcceptedHtlcPenaltyWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
testCLTVExpiry, testPubkey, testPubkey, testCLTVExpiry, testPubkey, testPubkey,
@ -683,7 +683,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc revoke confirmed", name: "accepted htlc revoke confirmed",
expSize: input.AcceptedHtlcPenaltyWitnessSize, expSize: input.AcceptedHtlcPenaltyWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
testCLTVExpiry, testPubkey, testPubkey, testCLTVExpiry, testPubkey, testPubkey,
@ -713,7 +713,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc timeout", name: "accepted htlc timeout",
expSize: input.AcceptedHtlcTimeoutWitnessSize - 3, expSize: input.AcceptedHtlcTimeoutWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
@ -741,7 +741,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc timeout confirmed", name: "accepted htlc timeout confirmed",
expSize: input.AcceptedHtlcTimeoutWitnessSize, expSize: input.AcceptedHtlcTimeoutWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
testCLTVExpiry, testPubkey, testPubkey, testCLTVExpiry, testPubkey, testPubkey,
@ -768,7 +768,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc success", name: "accepted htlc success",
expSize: input.AcceptedHtlcSuccessWitnessSize - 3, expSize: input.AcceptedHtlcSuccessWitnessSize,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
testCLTVExpiry, testPubkey, testPubkey, testCLTVExpiry, testPubkey, testPubkey,
@ -798,7 +798,7 @@ var witnessSizeTests = []witnessSizeTest{
}, },
{ {
name: "accepted htlc success confirmed", name: "accepted htlc success confirmed",
expSize: input.AcceptedHtlcSuccessWitnessSize, expSize: input.AcceptedHtlcSuccessWitnessSizeConfirmed,
genWitness: func(t *testing.T) wire.TxWitness { genWitness: func(t *testing.T) wire.TxWitness {
witScript, err := input.ReceiverHTLCScript( witScript, err := input.ReceiverHTLCScript(
testCLTVExpiry, testPubkey, testPubkey, testCLTVExpiry, testPubkey, testPubkey,

@ -15,7 +15,7 @@ var (
input.HtlcOfferedRemoteTimeout, input.HtlcOfferedRemoteTimeout,
input.WitnessKeyHash, input.WitnessKeyHash,
} }
expectedWeight = int64(1463) expectedWeight = int64(1460)
expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " + expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " +
"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " + "0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " +
"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " + "0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " +