input: add CommitmentToRemoteConfirmed witness type

This commit is contained in:
Johan T. Halseth 2020-03-06 16:11:46 +01:00
parent 990992ce94
commit 6deb913a8d
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 43 additions and 2 deletions

@ -213,6 +213,22 @@ const (
// - witness_script (to_local_script) // - witness_script (to_local_script)
ToLocalPenaltyWitnessSize = 1 + 1 + 73 + 1 + 1 + ToLocalScriptSize ToLocalPenaltyWitnessSize = 1 + 1 + 73 + 1 + 1 + ToLocalScriptSize
// ToRemoteConfirmedScriptSize 37 bytes
// - OP_DATA: 1 byte
// - to_remote_key: 33 bytes
// - OP_CHECKSIGVERIFY: 1 byte
// - OP_1: 1 byte
// - OP_CHECKSEQUENCEVERIFY: 1 byte
ToRemoteConfirmedScriptSize = 1 + 33 + 1 + 1 + 1
// ToRemoteConfirmedWitnessSize 113 bytes
// - number_of_witness_elements: 1 byte
// - sig_length: 1 byte
// - sig: 73 bytes
// - witness_script_length: 1 byte
// - witness_script (to_remote_delayed_script)
ToRemoteConfirmedWitnessSize = 1 + 1 + 73 + 1 + ToRemoteConfirmedScriptSize
// AcceptedHtlcScriptSize 142 bytes // AcceptedHtlcScriptSize 142 bytes
// - OP_DUP: 1 byte // - OP_DUP: 1 byte
// - OP_HASH160: 1 byte // - OP_HASH160: 1 byte

@ -48,8 +48,9 @@ type StandardWitnessType uint16
var _ WitnessType = (StandardWitnessType)(0) var _ WitnessType = (StandardWitnessType)(0)
const ( const (
// CommitmentTimeLock is a witness that allows us to spend the output of // CommitmentTimeLock is a witness that allows us to spend our output
// a commitment transaction after a relative lock-time lockout. // on our local commitment transaction after a relative lock-time
// lockout.
CommitmentTimeLock StandardWitnessType = 0 CommitmentTimeLock StandardWitnessType = 0
// CommitmentNoDelay is a witness that allows us to spend a settled // CommitmentNoDelay is a witness that allows us to spend a settled
@ -119,6 +120,11 @@ const (
// type, but it omits the tweak that randomizes the key we need to // type, but it omits the tweak that randomizes the key we need to
// spend with a channel peer supplied set of randomness. // spend with a channel peer supplied set of randomness.
CommitSpendNoDelayTweakless StandardWitnessType = 12 CommitSpendNoDelayTweakless StandardWitnessType = 12
// CommitmentToRemoteConfirmed is a witness that allows us to spend our
// output on the counterparty's commitment transaction after a
// confirmation.
CommitmentToRemoteConfirmed StandardWitnessType = 13
) )
// String returns a human readable version of the target WitnessType. // String returns a human readable version of the target WitnessType.
@ -129,6 +135,9 @@ func (wt StandardWitnessType) String() string {
case CommitmentTimeLock: case CommitmentTimeLock:
return "CommitmentTimeLock" return "CommitmentTimeLock"
case CommitmentToRemoteConfirmed:
return "CommitmentToRemoteConfirmed"
case CommitmentNoDelay: case CommitmentNoDelay:
return "CommitmentNoDelay" return "CommitmentNoDelay"
@ -197,6 +206,18 @@ func (wt StandardWitnessType) WitnessGenerator(signer Signer,
Witness: witness, Witness: witness,
}, nil }, nil
case CommitmentToRemoteConfirmed:
witness, err := CommitSpendToRemoteConfirmed(
signer, desc, tx,
)
if err != nil {
return nil, err
}
return &Script{
Witness: witness,
}, nil
case CommitmentNoDelay: case CommitmentNoDelay:
witness, err := CommitSpendNoDelay(signer, desc, tx, false) witness, err := CommitSpendNoDelay(signer, desc, tx, false)
if err != nil { if err != nil {
@ -323,6 +344,10 @@ func (wt StandardWitnessType) SizeUpperBound() (int, bool, error) {
case CommitmentTimeLock: case CommitmentTimeLock:
return ToLocalTimeoutWitnessSize, false, nil return ToLocalTimeoutWitnessSize, false, nil
// 1 CSV time locked output to us on remote commitment.
case CommitmentToRemoteConfirmed:
return ToRemoteConfirmedWitnessSize, false, nil
// Outgoing second layer HTLC's that have confirmed within the // Outgoing second layer HTLC's that have confirmed within the
// chain, and the output they produced is now mature enough to // chain, and the output they produced is now mature enough to
// sweep. // sweep.