Skip to content

Commit 5fab5d0

Browse files
Roasbeefguggero
authored andcommitted
contractcourt: update makeBreachedOutput to accept resolution blob
1 parent 3197525 commit 5fab5d0

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

contractcourt/breach_arbitrator.go

Lines changed: 35 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

@@ -1270,6 +1270,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
12701270
nil,
12711271
breachInfo.LocalOutputSignDesc,
12721272
breachInfo.BreachHeight,
1273+
breachInfo.LocalResolutionBlob,
12731274
)
12741275

12751276
breachedOutputs = append(breachedOutputs, localOutput)
@@ -1296,6 +1297,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
12961297
nil,
12971298
breachInfo.RemoteOutputSignDesc,
12981299
breachInfo.BreachHeight,
1300+
breachInfo.RemoteResolutionBlob,
12991301
)
13001302

13011303
breachedOutputs = append(breachedOutputs, remoteOutput)
@@ -1330,6 +1332,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
13301332
breachInfo.HtlcRetributions[i].SecondLevelWitnessScript,
13311333
&breachInfo.HtlcRetributions[i].SignDesc,
13321334
breachInfo.BreachHeight,
1335+
breachInfo.HtlcRetributions[i].ResolutionBlob,
13331336
)
13341337

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

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

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

1701+
tapCase.SettledCommitBlob.WhenSomeV(
1702+
func(blob tlv.Blob) {
1703+
bo.resolutionBlob = fn.Some(blob)
1704+
},
1705+
)
1706+
16821707
// To spend the revoked output again, we'll apply the same
16831708
// control block value as above, but to a different place.
16841709
case input.TaprootCommitmentRevoke:
16851710
//nolint:lll
16861711
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.Val.RevokeSweepCtrlBlock
16871712

1713+
tapCase.BreachedCommitBlob.WhenSomeV(
1714+
func(blob tlv.Blob) {
1715+
bo.resolutionBlob = fn.Some(blob)
1716+
},
1717+
)
1718+
16881719
// For spending the HTLC outputs, we'll apply the first and
16891720
// second level tweak values.
16901721
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)