lnwallet+breacharbiter: record local csv delay
This commit is contained in:
parent
92af2342da
commit
ad8e9f30c6
@ -896,6 +896,13 @@ func (bo *breachedOutput) CraftInputScript(signer input.Signer, txn *wire.MsgTx,
|
|||||||
// must be built on top of the confirmation height before the output can be
|
// must be built on top of the confirmation height before the output can be
|
||||||
// spent.
|
// spent.
|
||||||
func (bo *breachedOutput) BlocksToMaturity() uint32 {
|
func (bo *breachedOutput) BlocksToMaturity() uint32 {
|
||||||
|
// If the output is a to_remote output we can claim, and it's of the
|
||||||
|
// confirmed type, we must wait one block before claiming it.
|
||||||
|
if bo.witnessType == input.CommitmentToRemoteConfirmed {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// All other breached outputs have no CSV delay.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -952,6 +959,12 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
|
|||||||
witnessType = input.CommitSpendNoDelayTweakless
|
witnessType = input.CommitSpendNoDelayTweakless
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the local delay is non-zero, it means this output is of
|
||||||
|
// the confirmed to_remote type.
|
||||||
|
if breachInfo.LocalDelay != 0 {
|
||||||
|
witnessType = input.CommitmentToRemoteConfirmed
|
||||||
|
}
|
||||||
|
|
||||||
localOutput := makeBreachedOutput(
|
localOutput := makeBreachedOutput(
|
||||||
&breachInfo.LocalOutpoint,
|
&breachInfo.LocalOutpoint,
|
||||||
witnessType,
|
witnessType,
|
||||||
@ -1117,6 +1130,7 @@ func (b *breachArbiter) sweepSpendableOutputsTxn(txWeight int64,
|
|||||||
for _, input := range inputs {
|
for _, input := range inputs {
|
||||||
txn.AddTxIn(&wire.TxIn{
|
txn.AddTxIn(&wire.TxIn{
|
||||||
PreviousOutPoint: *input.OutPoint(),
|
PreviousOutPoint: *input.OutPoint(),
|
||||||
|
Sequence: input.BlocksToMaturity(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2013,6 +2013,10 @@ type BreachRetribution struct {
|
|||||||
// party) within the breach transaction.
|
// party) within the breach transaction.
|
||||||
LocalOutpoint wire.OutPoint
|
LocalOutpoint wire.OutPoint
|
||||||
|
|
||||||
|
// LocalDelay is the CSV delay for the to_remote script on the breached
|
||||||
|
// commitment.
|
||||||
|
LocalDelay uint32
|
||||||
|
|
||||||
// RemoteOutputSignDesc is a SignDescriptor which is capable of
|
// RemoteOutputSignDesc is a SignDescriptor which is capable of
|
||||||
// generating the signature required to claim the funds as described
|
// generating the signature required to claim the funds as described
|
||||||
// within the revocation clause of the remote party's commitment
|
// within the revocation clause of the remote party's commitment
|
||||||
@ -2026,6 +2030,10 @@ type BreachRetribution struct {
|
|||||||
// party within the breach transaction.
|
// party within the breach transaction.
|
||||||
RemoteOutpoint wire.OutPoint
|
RemoteOutpoint wire.OutPoint
|
||||||
|
|
||||||
|
// RemoteDelay specifies the CSV delay applied to to-local scripts on
|
||||||
|
// the breaching commitment transaction.
|
||||||
|
RemoteDelay uint32
|
||||||
|
|
||||||
// HtlcRetributions is a slice of HTLC retributions for each output
|
// HtlcRetributions is a slice of HTLC retributions for each output
|
||||||
// active HTLC output within the breached commitment transaction.
|
// active HTLC output within the breached commitment transaction.
|
||||||
HtlcRetributions []HtlcRetribution
|
HtlcRetributions []HtlcRetribution
|
||||||
@ -2034,10 +2042,6 @@ type BreachRetribution struct {
|
|||||||
// breaching commitment transaction. This allows downstream clients to
|
// breaching commitment transaction. This allows downstream clients to
|
||||||
// have access to the public keys used in the scripts.
|
// have access to the public keys used in the scripts.
|
||||||
KeyRing *CommitmentKeyRing
|
KeyRing *CommitmentKeyRing
|
||||||
|
|
||||||
// RemoteDelay specifies the CSV delay applied to to-local scripts on
|
|
||||||
// the breaching commitment transaction.
|
|
||||||
RemoteDelay uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBreachRetribution creates a new fully populated BreachRetribution for the
|
// NewBreachRetribution creates a new fully populated BreachRetribution for the
|
||||||
@ -2090,7 +2094,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
|||||||
|
|
||||||
// Since it is the remote breach we are reconstructing, the output going
|
// Since it is the remote breach we are reconstructing, the output going
|
||||||
// to us will be a to-remote script with our local params.
|
// to us will be a to-remote script with our local params.
|
||||||
ourScript, _, err := CommitScriptToRemote(
|
ourScript, ourDelay, err := CommitScriptToRemote(
|
||||||
chanState.ChanType, keyRing.ToRemoteKey,
|
chanState.ChanType, keyRing.ToRemoteKey,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2226,11 +2230,12 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
|||||||
PendingHTLCs: revokedSnapshot.Htlcs,
|
PendingHTLCs: revokedSnapshot.Htlcs,
|
||||||
LocalOutpoint: ourOutpoint,
|
LocalOutpoint: ourOutpoint,
|
||||||
LocalOutputSignDesc: ourSignDesc,
|
LocalOutputSignDesc: ourSignDesc,
|
||||||
|
LocalDelay: ourDelay,
|
||||||
RemoteOutpoint: theirOutpoint,
|
RemoteOutpoint: theirOutpoint,
|
||||||
RemoteOutputSignDesc: theirSignDesc,
|
RemoteOutputSignDesc: theirSignDesc,
|
||||||
|
RemoteDelay: theirDelay,
|
||||||
HtlcRetributions: htlcRetributions,
|
HtlcRetributions: htlcRetributions,
|
||||||
KeyRing: keyRing,
|
KeyRing: keyRing,
|
||||||
RemoteDelay: theirDelay,
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user