Skip to content

Commit 51f0a33

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 7df3b77 commit 51f0a33

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
@@ -2235,19 +2235,21 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
22352235
resolveBlob := fn.MapOptionZ(
22362236
auxResolver,
22372237
func(a AuxContractResolver) fn.Result[tlv.Blob] {
2238+
//nolint:lll
22382239
return a.ResolveContract(ResolutionReq{
2239-
ChanPoint: chanState.FundingOutpoint,
2240-
ShortChanID: chanState.ShortChanID(),
2241-
Initiator: chanState.IsInitiator,
2242-
CommitBlob: chanState.RemoteCommitment.CustomBlob, //nolint:lll
2243-
FundingBlob: chanState.CustomBlob,
2244-
Type: input.TaprootRemoteCommitSpend, //nolint:lll
2245-
CloseType: Breach,
2246-
CommitTx: spendTx,
2247-
SignDesc: *br.LocalOutputSignDesc,
2248-
KeyRing: keyRing,
2249-
CsvDelay: theirDelay,
2250-
CommitFee: chanState.RemoteCommitment.CommitFee, //nolint:lll
2240+
ChanPoint: chanState.FundingOutpoint,
2241+
ShortChanID: chanState.ShortChanID(),
2242+
Initiator: chanState.IsInitiator,
2243+
CommitBlob: revokedLog.CustomBlob.ValOpt(),
2244+
FundingBlob: chanState.CustomBlob,
2245+
Type: input.TaprootRemoteCommitSpend,
2246+
CloseType: Breach,
2247+
CommitTx: spendTx,
2248+
SignDesc: *br.LocalOutputSignDesc,
2249+
KeyRing: keyRing,
2250+
CsvDelay: ourDelay,
2251+
BreachCsvDelay: fn.Some(theirDelay),
2252+
CommitFee: chanState.RemoteCommitment.CommitFee,
22512253
})
22522254
},
22532255
)
@@ -2309,19 +2311,21 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
23092311
resolveBlob := fn.MapOptionZ(
23102312
auxResolver,
23112313
func(a AuxContractResolver) fn.Result[tlv.Blob] {
2314+
//nolint:lll
23122315
return a.ResolveContract(ResolutionReq{
2313-
ChanPoint: chanState.FundingOutpoint,
2314-
ShortChanID: chanState.ShortChanID(),
2315-
Initiator: chanState.IsInitiator,
2316-
CommitBlob: chanState.RemoteCommitment.CustomBlob, //nolint:lll
2317-
FundingBlob: chanState.CustomBlob,
2318-
Type: input.TaprootCommitmentRevoke, //nolint:lll
2319-
CloseType: Breach,
2320-
CommitTx: spendTx,
2321-
SignDesc: *br.RemoteOutputSignDesc,
2322-
KeyRing: keyRing,
2323-
CsvDelay: theirDelay,
2324-
CommitFee: chanState.RemoteCommitment.CommitFee, //nolint:lll
2316+
ChanPoint: chanState.FundingOutpoint,
2317+
ShortChanID: chanState.ShortChanID(),
2318+
Initiator: chanState.IsInitiator,
2319+
CommitBlob: revokedLog.CustomBlob.ValOpt(),
2320+
FundingBlob: chanState.CustomBlob,
2321+
Type: input.TaprootCommitmentRevoke,
2322+
CloseType: Breach,
2323+
CommitTx: spendTx,
2324+
SignDesc: *br.RemoteOutputSignDesc,
2325+
KeyRing: keyRing,
2326+
CsvDelay: theirDelay,
2327+
BreachCsvDelay: fn.Some(theirDelay),
2328+
CommitFee: chanState.RemoteCommitment.CommitFee,
23252329
})
23262330
},
23272331
)

0 commit comments

Comments
 (0)