input: add weight estimation + tests for all taproot witness gen types
This commit is contained in:
5 files changed
+956
-64
No files matched your search
+268
@@ -153,6 +153,12 @@ const (
|
||||
// - PkScript (P2WSH)
|
||||
CommitmentDelayOutput = 8 + 1 + P2WSHSize
|
||||
|
||||
// TaprootCommitmentOutput 43 bytes
|
||||
// - Value: 8 bytes
|
||||
// - VarInt: 1 byte (PkScript length)
|
||||
// - PkScript (P2TR)
|
||||
TaprootCommitmentOutput = 8 + 1 + P2TRSize
|
||||
|
||||
// CommitmentKeyHashOutput 31 bytes
|
||||
// - Value: 8 bytes
|
||||
// - VarInt: 1 byte (PkScript length)
|
||||
@@ -165,6 +171,12 @@ const (
|
||||
// - PkScript (P2WSH)
|
||||
CommitmentAnchorOutput = 8 + 1 + P2WSHSize
|
||||
|
||||
// TaprootCommitmentAnchorOutput 43 bytes
|
||||
// - Value: 8 bytes
|
||||
// - VarInt: 1 byte (PkScript length)
|
||||
// - PkScript (P2TR)
|
||||
TaprootCommitmentAnchorOutput = 8 + 1 + P2TRSize
|
||||
|
||||
// HTLCSize 43 bytes
|
||||
// - Value: 8 bytes
|
||||
// - VarInt: 1 byte (PkScript length)
|
||||
@@ -222,12 +234,32 @@ const (
|
||||
// BaseAnchorCommitmentTxWeight 900 weight.
|
||||
BaseAnchorCommitmentTxWeight = witnessScaleFactor * BaseAnchorCommitmentTxSize
|
||||
|
||||
// BaseTaprootCommitmentTxWeight 225 + 43 * num-htlc-outputs bytes
|
||||
// - Version: 4 bytes
|
||||
// - WitnessHeader <---- part of the witness data
|
||||
// - CountTxIn: 1 byte
|
||||
// - TxIn: 41 bytes
|
||||
// FundingInput
|
||||
// - CountTxOut: 3 byte
|
||||
// - TxOut: 172 + 43 * num-htlc-outputs bytes
|
||||
// OutputPayingToThem,
|
||||
// OutputPayingToUs,
|
||||
// ....HTLCOutputs...
|
||||
// - LockTime: 4 bytes
|
||||
BaseTaprootCommitmentTxWeight = (4 + 1 + FundingInputSize + 3 +
|
||||
2*TaprootCommitmentOutput + 2*TaprootCommitmentAnchorOutput + 4) *
|
||||
witnessScaleFactor
|
||||
|
||||
// CommitWeight 724 weight.
|
||||
CommitWeight = BaseCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||
|
||||
// AnchorCommitWeight 1124 weight.
|
||||
AnchorCommitWeight = BaseAnchorCommitmentTxWeight + WitnessCommitmentTxWeight
|
||||
|
||||
// TaprootCommitWeight 968 weight.
|
||||
TaprootCommitWeight = (BaseTaprootCommitmentTxWeight +
|
||||
WitnessHeaderSize + TaprootKeyPathWitnessSize)
|
||||
|
||||
// HTLCWeight 172 weight.
|
||||
HTLCWeight = witnessScaleFactor * HTLCSize
|
||||
|
||||
@@ -236,11 +268,19 @@ const (
|
||||
// which will transition an outgoing HTLC to the delay-and-claim state.
|
||||
HtlcTimeoutWeight = 663
|
||||
|
||||
// TaprootHtlcTimeoutWeight is the total weight of the taproot HTLC
|
||||
// timeout transaction.
|
||||
TaprootHtlcTimeoutWeight = 645
|
||||
|
||||
// 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
|
||||
|
||||
// TaprootHtlcSuccessWeight is the total weight of the taproot HTLC
|
||||
// success transaction.
|
||||
TaprootHtlcSuccessWeight = 705
|
||||
|
||||
// HtlcConfirmedScriptOverhead 3 bytes
|
||||
// HtlcConfirmedScriptOverhead is the extra length of an HTLC script
|
||||
// that requires confirmation before it can be spent. These extra bytes
|
||||
@@ -556,6 +596,232 @@ const (
|
||||
// - leafVersionAndParity: 1 byte
|
||||
// - schnorrPubKey: 32 byte
|
||||
TaprootBaseControlBlockWitnessSize = 33
|
||||
|
||||
// TaprootToLocalScriptSize
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - local_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
// - OP_DATA: 1 byte (csv delay)
|
||||
// - csv_delay: 4 bytes (worst case estimate)
|
||||
// - OP_CSV: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootToLocalScriptSize = 41
|
||||
|
||||
// TaprootToLocalWitnessSize: 175 bytes
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - script_len: 1 byte
|
||||
// - taproot_to_local_script_size: 41 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
// - sibling_merkle_hash: 32 bytes
|
||||
TaprootToLocalWitnessSize = 1 + 1 + 65 + 1 + TaprootToLocalScriptSize +
|
||||
1 + TaprootBaseControlBlockWitnessSize + 32
|
||||
|
||||
// TaprootToLocalRevokeScriptSize: 68 bytes
|
||||
// - OP_DATA: 1 byte
|
||||
// - local key: 32 bytes
|
||||
// - OP_DROP: 1 byte
|
||||
// - OP_DATA: 1 byte
|
||||
// - revocation key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
TaprootToLocalRevokeScriptSize = 1 + 32 + 1 + 1 + 32 + 1
|
||||
|
||||
// TaprootToLocalRevokeWitnessSize: 202 bytes
|
||||
// - NumberOfWitnessElements: 1 byte
|
||||
// - sigLength: 1 byte
|
||||
// - sweep sig: 65 bytes
|
||||
// - script len: 1 byte
|
||||
// - revocation script size: 68 bytes
|
||||
// - ctrl block size: 1 byte
|
||||
// - base control block: 33 bytes
|
||||
// - merkle proof: 32
|
||||
TaprootToLocalRevokeWitnessSize = 1 + 1 + 65 + 1 + TaprootToLocalRevokeScriptSize + 1 + 33 + 32
|
||||
|
||||
// TaprootToRemoteScriptSize
|
||||
// - OP_DATA: 1 byte
|
||||
// - remote key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
// - OP_1: 1 byte
|
||||
// - OP_CHECKSEQUENCEVERIFY: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootToRemoteScriptSize = 1 + 32 + 1 + 1 + 1 + 1
|
||||
|
||||
// TaprootToRemoteWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - script_len: 1 byte
|
||||
// - taproot_to_local_script_size: 36 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
TaprootToRemoteWitnessSize = 1 + 1 + 65 + 1 + TaprootToRemoteScriptSize +
|
||||
1 + TaprootBaseControlBlockWitnessSize
|
||||
|
||||
// TaprootAnchorWitnessSize: 67 bytes
|
||||
//
|
||||
// In this case, we use the custom sighash size to give the most
|
||||
// pessemistic estimate.
|
||||
TaprootAnchorWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootSecondLevelHtlcScriptSize: 41 bytes
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - local_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
// - OP_DATA: 1 byte (csv delay)
|
||||
// - csv_delay: 4 bytes (worst case)
|
||||
// - OP_CSV: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootSecondLevelHtlcScriptSize = 1 + 32 + 1 + 1 + 4 + 1 + 1
|
||||
|
||||
// TaprootSecondLevelHtlcWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - script_len: 1 byte
|
||||
// - taproot_second_level_htlc_script_size: 40 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
TaprootSecondLevelHtlcWitnessSize = 1 + 1 + 65 + 1 +
|
||||
TaprootSecondLevelHtlcScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize
|
||||
|
||||
// TaprootSecondLevelRevokeWitnessSize
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
TaprootSecondLevelRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootAcceptedRevokeWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
TaprootAcceptedRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootOfferedRevokeWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
TaprootOfferedRevokeWitnessSize = TaprootKeyPathCustomSighashWitnessSize
|
||||
|
||||
// TaprootHtlcOfferedRemoteTimeoutScriptSize: 42 bytes
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - local_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
// - OP_1: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
// - OP_CHECKSEQUENCEVERIFY: 1 byte
|
||||
// - OP_DATA: 1 byte (cltv_expiry length)
|
||||
// - cltv_expiry: 4 bytes
|
||||
// - OP_CHECKLOCKTIMEVERIFY: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize = 1 + 32 + 1 + 1 + 1 + 1 + 1 + 4 + 1 + 1
|
||||
|
||||
// TaprootHtlcOfferedRemoteTimeoutwitSize: 176 bytes
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - script_len: 1 byte
|
||||
// - taproot_offered_htlc_script_size: 42 bytes
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
// - sibilng_merkle_proof: 32 bytes
|
||||
TaprootHtlcOfferedRemoteTimeoutWitnessSize = 1 + 1 + 65 + 1 +
|
||||
TaprootHtlcOfferedRemoteTimeoutScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize + 32
|
||||
|
||||
// TaprootHtlcOfferedLocalTmeoutScriptSize:
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - local_key: 32 bytes
|
||||
// - OP_CHECKSIGVERIFY: 1 byte
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - remote_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
TaprootHtlcOfferedLocalTimeoutScriptSize = 1 + 32 + 1 + 1 + 32 + 1
|
||||
|
||||
// TaprootOfferedLocalTimeoutWitnessSize
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - script_len: 1 byte
|
||||
// - taproot_offered_htlc_script_timeout_size:
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
// - sibilng_merkle_proof: 32 bytes
|
||||
TaprootOfferedLocalTimeoutWitnessSize = 1 + 1 + 65 + 1 + 65 + 1 +
|
||||
TaprootHtlcOfferedLocalTimeoutScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize + 32
|
||||
|
||||
// TaprootHtlcAcceptedRemoteSuccessScriptSize:
|
||||
// - OP_SIZE: 1 byte
|
||||
// - OP_DATA: 1 byte
|
||||
// - 32: 1 byte
|
||||
// - OP_EQUALVERIFY: 1 byte
|
||||
// - OP_HASH160: 1 byte
|
||||
// - OP_DATA: 1 byte (RIPEMD160(payment_hash) length)
|
||||
// - RIPEMD160(payment_hash): 20 bytes
|
||||
// - OP_EQUALVERIFY: 1 byte
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - remote_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
// - OP_1: 1 byte
|
||||
// - OP_CSV: 1 byte
|
||||
// - OP_DROP: 1 byte
|
||||
TaprootHtlcAcceptedRemoteSuccessScriptSize = 1 + 1 + 1 + 1 + 1 + 1 +
|
||||
1 + 20 + 1 + 32 + 1 + 1 + 1 + 1
|
||||
|
||||
// TaprootHtlcAcceptedRemoteSuccessScriptSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - payment_preimage_length: 1 byte
|
||||
// - payment_preimage: 32 bytes
|
||||
// - script_len: 1 byte
|
||||
// - taproot_offered_htlc_script_success_size:
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
// - sibilng_merkle_proof: 32 bytes
|
||||
TaprootHtlcAcceptedRemoteSuccessWitnessSize = 1 + 1 + 65 + 1 + 32 + 1 +
|
||||
TaprootHtlcAcceptedRemoteSuccessScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize + 32
|
||||
|
||||
// TaprootHtlcAcceptedLocalSuccessScriptSize:
|
||||
// - OP_SIZE: 1 byte
|
||||
// - OP_DATA: 1 byte
|
||||
// - 32: 1 byte
|
||||
// - OP_EQUALVERIFY: 1 byte
|
||||
// - OP_HASH160: 1 byte
|
||||
// - OP_DATA: 1 byte (RIPEMD160(payment_hash) length)
|
||||
// - RIPEMD160(payment_hash): 20 bytes
|
||||
// - OP_EQUALVERIFY: 1 byte
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - local_key: 32 bytes
|
||||
// - OP_CHECKSIGVERIFY: 1 byte
|
||||
// - OP_DATA: 1 byte (pub key len)
|
||||
// - remote_key: 32 bytes
|
||||
// - OP_CHECKSIG: 1 byte
|
||||
TaprootHtlcAcceptedLocalSuccessScriptSize = 1 + 1 + 1 + 1 + 1 + 1 +
|
||||
20 + 1 + 1 + 32 + 1 + 1 + 32 + 1
|
||||
|
||||
// TaprootHtlcAcceptedLocalSuccessWitnessSize:
|
||||
// - number_of_witness_elements: 1 byte
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - sig_len: 1 byte
|
||||
// - sweep_sig: 65 bytes (worst case w/o sighash default)
|
||||
// - payment_preimage_length: 1 byte
|
||||
// - payment_preimage: 32 bytes
|
||||
// - script_len: 1 byte
|
||||
// - taproot_accepted_htlc_script_success_size:
|
||||
// - ctrl_block_len: 1 byte
|
||||
// - base_control_block_size: 33 bytes
|
||||
// - sibilng_merkle_proof: 32 bytes
|
||||
TaprootHtlcAcceptedLocalSuccessWitnessSize = 1 + 1 + 65 + 1 + 65 + 1 +
|
||||
32 + 1 + TaprootHtlcAcceptedLocalSuccessScriptSize + 1 +
|
||||
TaprootBaseControlBlockWitnessSize + 32
|
||||
)
|
||||
|
||||
// EstimateCommitTxWeight estimate commitment transaction weight depending on
|
||||
@@ -572,6 +838,8 @@ func EstimateCommitTxWeight(count int, prediction bool) int64 {
|
||||
baseWeight := int64(BaseCommitmentTxWeight)
|
||||
witnessWeight := int64(WitnessCommitmentTxWeight)
|
||||
|
||||
// TODO(roasbeef): need taproot modifier? also no anchor so wrong?
|
||||
|
||||
return htlcWeight + baseWeight + witnessWeight
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user