Skip to content

Commit 3bb4db2

Browse files
Roasbeefguggero
authored andcommitted
lnwallet: fix bugs in ResolutionReq for breach handling
In this commit, we fix three existing bugs in the way we make `ResolutionReq` for breach handling: 1. We were passing in the commit blob of the *current* channel state, instead of the one stored in the revocation log for this breached state. 2. We were using theirDelay for CsvDelay, when we want ourDelay, which in this case will be 1 CSV, as this is a non delayed output. 3. We also need to pass in the delay for the remote party's to_local delayed output.
1 parent a4cc835 commit 3bb4db2

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

lnwallet/aux_resolutions.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ type ResolutionReq struct {
6969
// CsvDelay is the CSV delay for the local output for this commitment.
7070
CsvDelay uint32
7171

72+
// BreachCsvDelay is the CSV delay for the remote output. This is only
73+
// set when the CloseType is Breach. This indicates the CSV delay to
74+
// use for the remote party's to_local delayed output, that is now
75+
// rightfully ours in a breach situation.
76+
BreachCsvDelay fn.Option[uint32]
77+
7278
// CltvDelay is the CLTV delay for the outpoint.
7379
CltvDelay fn.Option[uint32]
7480
}

lnwallet/channel.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,19 +2226,21 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
22262226
resolveBlob := fn.MapOptionZ(
22272227
auxResolver,
22282228
func(a AuxContractResolver) fn.Result[tlv.Blob] {
2229+
//nolint:lll
22292230
return a.ResolveContract(ResolutionReq{
2230-
ChanPoint: chanState.FundingOutpoint,
2231-
ShortChanID: chanState.ShortChanID(),
2232-
Initiator: chanState.IsInitiator,
2233-
CommitBlob: chanState.RemoteCommitment.CustomBlob, //nolint:lll
2234-
FundingBlob: chanState.CustomBlob,
2235-
Type: input.TaprootRemoteCommitSpend, //nolint:lll
2236-
CloseType: Breach,
2237-
CommitTx: spendTx,
2238-
SignDesc: *br.LocalOutputSignDesc,
2239-
KeyRing: keyRing,
2240-
CsvDelay: theirDelay,
2241-
CommitFee: chanState.RemoteCommitment.CommitFee, //nolint:lll
2231+
ChanPoint: chanState.FundingOutpoint,
2232+
ShortChanID: chanState.ShortChanID(),
2233+
Initiator: chanState.IsInitiator,
2234+
CommitBlob: revokedLog.CustomBlob.ValOpt(),
2235+
FundingBlob: chanState.CustomBlob,
2236+
Type: input.TaprootRemoteCommitSpend,
2237+
CloseType: Breach,
2238+
CommitTx: spendTx,
2239+
SignDesc: *br.LocalOutputSignDesc,
2240+
KeyRing: keyRing,
2241+
CsvDelay: ourDelay,
2242+
BreachCsvDelay: fn.Some(theirDelay),
2243+
CommitFee: chanState.RemoteCommitment.CommitFee,
22422244
})
22432245
},
22442246
)
@@ -2300,19 +2302,21 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
23002302
resolveBlob := fn.MapOptionZ(
23012303
auxResolver,
23022304
func(a AuxContractResolver) fn.Result[tlv.Blob] {
2305+
//nolint:lll
23032306
return a.ResolveContract(ResolutionReq{
2304-
ChanPoint: chanState.FundingOutpoint,
2305-
ShortChanID: chanState.ShortChanID(),
2306-
Initiator: chanState.IsInitiator,
2307-
CommitBlob: chanState.RemoteCommitment.CustomBlob, //nolint:lll
2308-
FundingBlob: chanState.CustomBlob,
2309-
Type: input.TaprootCommitmentRevoke, //nolint:lll
2310-
CloseType: Breach,
2311-
CommitTx: spendTx,
2312-
SignDesc: *br.RemoteOutputSignDesc,
2313-
KeyRing: keyRing,
2314-
CsvDelay: theirDelay,
2315-
CommitFee: chanState.RemoteCommitment.CommitFee, //nolint:lll
2307+
ChanPoint: chanState.FundingOutpoint,
2308+
ShortChanID: chanState.ShortChanID(),
2309+
Initiator: chanState.IsInitiator,
2310+
CommitBlob: revokedLog.CustomBlob.ValOpt(),
2311+
FundingBlob: chanState.CustomBlob,
2312+
Type: input.TaprootCommitmentRevoke,
2313+
CloseType: Breach,
2314+
CommitTx: spendTx,
2315+
SignDesc: *br.RemoteOutputSignDesc,
2316+
KeyRing: keyRing,
2317+
CsvDelay: theirDelay,
2318+
BreachCsvDelay: fn.Some(theirDelay),
2319+
CommitFee: chanState.RemoteCommitment.CommitFee,
23162320
})
23172321
},
23182322
)

0 commit comments

Comments
 (0)