Skip to content

Commit 9c4e749

Browse files
Roasbeefguggero
authored andcommitted
contractcourt: update makeBreachedOutput to accept resolution blob
1 parent e2281d5 commit 9c4e749

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

contractcourt/breach_arbitrator.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,9 @@ type breachedOutput struct {
10781078
// makeBreachedOutput assembles a new breachedOutput that can be used by the
10791079
// breach arbiter to construct a justice or sweep transaction.
10801080
func makeBreachedOutput(outpoint *wire.OutPoint,
1081-
witnessType input.StandardWitnessType,
1082-
secondLevelScript []byte,
1083-
signDescriptor *input.SignDescriptor,
1084-
confHeight uint32) breachedOutput {
1081+
witnessType input.StandardWitnessType, secondLevelScript []byte,
1082+
signDescriptor *input.SignDescriptor, confHeight uint32,
1083+
resolutionBlob fn.Option[tlv.Blob]) breachedOutput {
10851084

10861085
amount := signDescriptor.Output.Value
10871086

@@ -1092,6 +1091,7 @@ func makeBreachedOutput(outpoint *wire.OutPoint,
10921091
witnessType: witnessType,
10931092
signDesc: *signDescriptor,
10941093
confHeight: confHeight,
1094+
resolutionBlob: resolutionBlob,
10951095
}
10961096
}
10971097

@@ -1269,6 +1269,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
12691269
nil,
12701270
breachInfo.LocalOutputSignDesc,
12711271
breachInfo.BreachHeight,
1272+
breachInfo.LocalResolutionBlob,
12721273
)
12731274

12741275
breachedOutputs = append(breachedOutputs, localOutput)
@@ -1295,6 +1296,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
12951296
nil,
12961297
breachInfo.RemoteOutputSignDesc,
12971298
breachInfo.BreachHeight,
1299+
breachInfo.RemoteResolutionBlob,
12981300
)
12991301

13001302
breachedOutputs = append(breachedOutputs, remoteOutput)
@@ -1329,6 +1331,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
13291331
breachInfo.HtlcRetributions[i].SecondLevelWitnessScript,
13301332
&breachInfo.HtlcRetributions[i].SignDesc,
13311333
breachInfo.BreachHeight,
1334+
breachInfo.HtlcRetributions[i].ResolutionBlob,
13321335
)
13331336

13341337
// For taproot outputs, we also need to hold onto the second
@@ -1635,12 +1638,28 @@ func taprootBriefcaseFromRetInfo(retInfo *retributionInfo) *taprootBriefcase {
16351638
//nolint:lll
16361639
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock = bo.signDesc.ControlBlock
16371640

1641+
bo.resolutionBlob.WhenSome(func(blob tlv.Blob) {
1642+
tapCase.SettledCommitBlob = tlv.SomeRecordT(
1643+
tlv.NewPrimitiveRecord[tlv.TlvType2](
1644+
blob,
1645+
),
1646+
)
1647+
})
1648+
16381649
// To spend the revoked output again, we'll store the same
16391650
// control block value as above, but in a different place.
16401651
case input.TaprootCommitmentRevoke:
16411652
//nolint:lll
16421653
tapCase.CtrlBlocks.Val.RevokeSweepCtrlBlock = bo.signDesc.ControlBlock
16431654

1655+
bo.resolutionBlob.WhenSome(func(blob tlv.Blob) {
1656+
tapCase.BreachedCommitBlob = tlv.SomeRecordT(
1657+
tlv.NewPrimitiveRecord[tlv.TlvType3](
1658+
blob,
1659+
),
1660+
)
1661+
})
1662+
16441663
// For spending the HTLC outputs, we'll store the first and
16451664
// second level tweak values.
16461665
case input.TaprootHtlcAcceptedRevoke:
@@ -1678,12 +1697,22 @@ func applyTaprootRetInfo(tapCase *taprootBriefcase,
16781697
//nolint:lll
16791698
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock
16801699

1700+
tapCase.SettledCommitBlob.WhenSomeV(func(blob tlv.Blob) { //nolint:lll
1701+
bo.resolutionBlob = fn.Some(blob)
1702+
})
1703+
16811704
// To spend the revoked output again, we'll apply the same
16821705
// control block value as above, but to a different place.
16831706
case input.TaprootCommitmentRevoke:
16841707
//nolint:lll
16851708
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.Val.RevokeSweepCtrlBlock
16861709

1710+
tapCase.BreachedCommitBlob.WhenSomeV(
1711+
func(blob tlv.Blob) {
1712+
bo.resolutionBlob = fn.Some(blob)
1713+
},
1714+
)
1715+
16871716
// For spending the HTLC outputs, we'll apply the first and
16881717
// second level tweak values.
16891718
case input.TaprootHtlcAcceptedRevoke:

contractcourt/breach_arbitrator_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,8 @@ func TestBreachCreateJusticeTx(t *testing.T) {
11991199
input.HtlcSecondLevelRevoke,
12001200
}
12011201

1202+
rBlob := fn.Some([]byte{0x01})
1203+
12021204
breachedOutputs := make([]breachedOutput, len(outputTypes))
12031205
for i, wt := range outputTypes {
12041206
// Create a fake breached output for each type, ensuring they
@@ -1217,6 +1219,7 @@ func TestBreachCreateJusticeTx(t *testing.T) {
12171219
nil,
12181220
signDesc,
12191221
1,
1222+
rBlob,
12201223
)
12211224
}
12221225

contractcourt/utxonursery.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/lightningnetwork/lnd/lnutils"
2222
"github.com/lightningnetwork/lnd/lnwallet"
2323
"github.com/lightningnetwork/lnd/sweep"
24+
"github.com/lightningnetwork/lnd/tlv"
2425
)
2526

2627
// SUMMARY OF OUTPUT STATES
@@ -1423,6 +1424,7 @@ func makeKidOutput(outpoint, originChanPoint *wire.OutPoint,
14231424
return kidOutput{
14241425
breachedOutput: makeBreachedOutput(
14251426
outpoint, witnessType, nil, signDescriptor, heightHint,
1427+
fn.None[tlv.Blob](),
14261428
),
14271429
isHtlc: isHtlc,
14281430
originChanPoint: *originChanPoint,

0 commit comments

Comments
 (0)