mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-06 01:40:26 +02:00
input: add witness gen and weight estimates for new commitment type
This witness generators and weight estimates added only apply for the new script-enforced leased channel commitment type.
This commit is contained in:
parent
b84307e62e
commit
652f841738
@ -270,6 +270,17 @@ const (
|
|||||||
// - OP_CHECKSIG: 1 byte
|
// - OP_CHECKSIG: 1 byte
|
||||||
ToLocalScriptSize = 1 + 1 + 33 + 1 + 1 + 4 + 1 + 1 + 1 + 33 + 1 + 1
|
ToLocalScriptSize = 1 + 1 + 33 + 1 + 1 + 4 + 1 + 1 + 1 + 33 + 1 + 1
|
||||||
|
|
||||||
|
// LeaseWitnessScriptSizeOverhead represents the size overhead in bytes
|
||||||
|
// of the witness scripts used within script enforced lease commitments.
|
||||||
|
// This overhead results from the additional CLTV clause required to
|
||||||
|
// spend.
|
||||||
|
//
|
||||||
|
// - OP_DATA: 1 byte
|
||||||
|
// - lease_expiry: 4 bytes
|
||||||
|
// - OP_CHECKLOCKTIMEVERIFY: 1 byte
|
||||||
|
// - OP_DROP: 1 byte
|
||||||
|
LeaseWitnessScriptSizeOverhead = 1 + 4 + 1 + 1
|
||||||
|
|
||||||
// ToLocalTimeoutWitnessSize 156 bytes
|
// ToLocalTimeoutWitnessSize 156 bytes
|
||||||
// - number_of_witness_elements: 1 byte
|
// - number_of_witness_elements: 1 byte
|
||||||
// - local_delay_sig_length: 1 byte
|
// - local_delay_sig_length: 1 byte
|
||||||
|
@ -145,6 +145,36 @@ const (
|
|||||||
// CommitmentAnchor is a witness that allows us to spend our anchor on
|
// CommitmentAnchor is a witness that allows us to spend our anchor on
|
||||||
// the commitment transaction.
|
// the commitment transaction.
|
||||||
CommitmentAnchor StandardWitnessType = 14
|
CommitmentAnchor StandardWitnessType = 14
|
||||||
|
|
||||||
|
// LeaseCommitmentTimeLock is a witness that allows us to spend our
|
||||||
|
// output on our local commitment transaction after a relative and
|
||||||
|
// absolute lock-time lockout as part of the script enforced lease
|
||||||
|
// commitment type.
|
||||||
|
LeaseCommitmentTimeLock StandardWitnessType = 17
|
||||||
|
|
||||||
|
// LeaseCommitmentToRemoteConfirmed is a witness that allows us to spend
|
||||||
|
// our output on the counterparty's commitment transaction after a
|
||||||
|
// confirmation and absolute locktime as part of the script enforced
|
||||||
|
// lease commitment type.
|
||||||
|
LeaseCommitmentToRemoteConfirmed StandardWitnessType = 18
|
||||||
|
|
||||||
|
// LeaseHtlcOfferedTimeoutSecondLevel is a witness that allows us to
|
||||||
|
// sweep an HTLC output that we extended to a party, but was never
|
||||||
|
// fulfilled. This HTLC output isn't directly on the commitment
|
||||||
|
// transaction, but is the result of a confirmed second-level HTLC
|
||||||
|
// transaction. As a result, we can only spend this after a CSV delay
|
||||||
|
// and CLTV locktime as part of the script enforced lease commitment
|
||||||
|
// type.
|
||||||
|
LeaseHtlcOfferedTimeoutSecondLevel StandardWitnessType = 19
|
||||||
|
|
||||||
|
// LeaseHtlcAcceptedSuccessSecondLevel is a witness that allows us to
|
||||||
|
// sweep an HTLC output that was offered to us, and for which we have a
|
||||||
|
// payment preimage. This HTLC output isn't directly on our commitment
|
||||||
|
// transaction, but is the result of confirmed second-level HTLC
|
||||||
|
// transaction. As a result, we can only spend this after a CSV delay
|
||||||
|
// and CLTV locktime as part of the script enforced lease commitment
|
||||||
|
// type.
|
||||||
|
LeaseHtlcAcceptedSuccessSecondLevel StandardWitnessType = 20
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns a human readable version of the target WitnessType.
|
// String returns a human readable version of the target WitnessType.
|
||||||
@ -203,6 +233,18 @@ func (wt StandardWitnessType) String() string {
|
|||||||
case NestedWitnessKeyHash:
|
case NestedWitnessKeyHash:
|
||||||
return "NestedWitnessKeyHash"
|
return "NestedWitnessKeyHash"
|
||||||
|
|
||||||
|
case LeaseCommitmentTimeLock:
|
||||||
|
return "LeaseCommitmentTimeLock"
|
||||||
|
|
||||||
|
case LeaseCommitmentToRemoteConfirmed:
|
||||||
|
return "LeaseCommitmentToRemoteConfirmed"
|
||||||
|
|
||||||
|
case LeaseHtlcOfferedTimeoutSecondLevel:
|
||||||
|
return "LeaseHtlcOfferedTimeoutSecondLevel"
|
||||||
|
|
||||||
|
case LeaseHtlcAcceptedSuccessSecondLevel:
|
||||||
|
return "LeaseHtlcAcceptedSuccessSecondLevel"
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("Unknown WitnessType: %v", uint32(wt))
|
return fmt.Sprintf("Unknown WitnessType: %v", uint32(wt))
|
||||||
}
|
}
|
||||||
@ -225,7 +267,7 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
|||||||
desc.InputIndex = inputIndex
|
desc.InputIndex = inputIndex
|
||||||
|
|
||||||
switch wt {
|
switch wt {
|
||||||
case CommitmentTimeLock:
|
case CommitmentTimeLock, LeaseCommitmentTimeLock:
|
||||||
witness, err := CommitSpendTimeout(signer, desc, tx)
|
witness, err := CommitSpendTimeout(signer, desc, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -235,7 +277,7 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
|||||||
Witness: witness,
|
Witness: witness,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case CommitmentToRemoteConfirmed:
|
case CommitmentToRemoteConfirmed, LeaseCommitmentToRemoteConfirmed:
|
||||||
witness, err := CommitSpendToRemoteConfirmed(
|
witness, err := CommitSpendToRemoteConfirmed(
|
||||||
signer, desc, tx,
|
signer, desc, tx,
|
||||||
)
|
)
|
||||||
@ -307,17 +349,11 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
|
|||||||
Witness: witness,
|
Witness: witness,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
case HtlcOfferedTimeoutSecondLevel:
|
case HtlcOfferedTimeoutSecondLevel,
|
||||||
witness, err := HtlcSecondLevelSpend(signer, desc, tx)
|
LeaseHtlcOfferedTimeoutSecondLevel,
|
||||||
if err != nil {
|
HtlcAcceptedSuccessSecondLevel,
|
||||||
return nil, err
|
LeaseHtlcAcceptedSuccessSecondLevel:
|
||||||
}
|
|
||||||
|
|
||||||
return &Script{
|
|
||||||
Witness: witness,
|
|
||||||
}, nil
|
|
||||||
|
|
||||||
case HtlcAcceptedSuccessSecondLevel:
|
|
||||||
witness, err := HtlcSecondLevelSpend(signer, desc, tx)
|
witness, err := HtlcSecondLevelSpend(signer, desc, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -382,10 +418,18 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
// to us.
|
// to us.
|
||||||
case CommitmentTimeLock:
|
case CommitmentTimeLock:
|
||||||
return ToLocalTimeoutWitnessSize, false, nil
|
return ToLocalTimeoutWitnessSize, false, nil
|
||||||
|
case LeaseCommitmentTimeLock:
|
||||||
|
size := ToLocalTimeoutWitnessSize +
|
||||||
|
LeaseWitnessScriptSizeOverhead
|
||||||
|
return size, false, nil
|
||||||
|
|
||||||
// 1 CSV time locked output to us on remote commitment.
|
// 1 CSV time locked output to us on remote commitment.
|
||||||
case CommitmentToRemoteConfirmed:
|
case CommitmentToRemoteConfirmed:
|
||||||
return ToRemoteConfirmedWitnessSize, false, nil
|
return ToRemoteConfirmedWitnessSize, false, nil
|
||||||
|
case LeaseCommitmentToRemoteConfirmed:
|
||||||
|
size := ToRemoteConfirmedWitnessSize +
|
||||||
|
LeaseWitnessScriptSizeOverhead
|
||||||
|
return size, false, nil
|
||||||
|
|
||||||
// Anchor output on the commitment transaction.
|
// Anchor output on the commitment transaction.
|
||||||
case CommitmentAnchor:
|
case CommitmentAnchor:
|
||||||
@ -396,6 +440,10 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
// sweep.
|
// sweep.
|
||||||
case HtlcOfferedTimeoutSecondLevel:
|
case HtlcOfferedTimeoutSecondLevel:
|
||||||
return ToLocalTimeoutWitnessSize, false, nil
|
return ToLocalTimeoutWitnessSize, false, nil
|
||||||
|
case LeaseHtlcOfferedTimeoutSecondLevel:
|
||||||
|
size := ToLocalTimeoutWitnessSize +
|
||||||
|
LeaseWitnessScriptSizeOverhead
|
||||||
|
return size, false, nil
|
||||||
|
|
||||||
// Input to the outgoing HTLC second layer timeout transaction.
|
// Input to the outgoing HTLC second layer timeout transaction.
|
||||||
case HtlcOfferedTimeoutSecondLevelInputConfirmed:
|
case HtlcOfferedTimeoutSecondLevelInputConfirmed:
|
||||||
@ -406,6 +454,10 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
|
|||||||
// sweep.
|
// sweep.
|
||||||
case HtlcAcceptedSuccessSecondLevel:
|
case HtlcAcceptedSuccessSecondLevel:
|
||||||
return ToLocalTimeoutWitnessSize, false, nil
|
return ToLocalTimeoutWitnessSize, false, nil
|
||||||
|
case LeaseHtlcAcceptedSuccessSecondLevel:
|
||||||
|
size := ToLocalTimeoutWitnessSize +
|
||||||
|
LeaseWitnessScriptSizeOverhead
|
||||||
|
return size, false, nil
|
||||||
|
|
||||||
// Input to the incoming second-layer HTLC success transaction.
|
// Input to the incoming second-layer HTLC success transaction.
|
||||||
case HtlcAcceptedSuccessSecondLevelInputConfirmed:
|
case HtlcAcceptedSuccessSecondLevelInputConfirmed:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user