Skip to content

Commit 3ed3231

Browse files
committed
tapchannel: parameterize stxo for commitments
We change the commitment related generations to now include stxo proofs if the setting allows so. Previously we would always exclude stxo proofs, but now we add them if both parties understand & expect them.
1 parent 034a7ab commit 3ed3231

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

tapchannel/aux_funding_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ func newCommitBlobAndLeaves(pendingFunding *pendingAssetFunding,
571571
fakePrevState, lndOpenChan, assetOpenChan, whoseCommit,
572572
localSatBalance, remoteSatBalance, fakeView,
573573
pendingFunding.chainParams, keyRing.GetForParty(whoseCommit),
574+
false,
574575
)
575576
if err != nil {
576577
return nil, lnwallet.CommitAuxLeaves{}, err

tapchannel/aux_leaf_creator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func FetchLeavesFromView(chainParams *address.ChainParams,
5353
allocations, newCommitment, err := GenerateCommitmentAllocations(
5454
prevState, in.ChannelState, chanAssetState, in.WhoseCommit,
5555
in.OurBalance, in.TheirBalance, in.UnfilteredView, chainParams,
56-
in.KeyRing,
56+
in.KeyRing, false,
5757
)
5858
if err != nil {
5959
return lfn.Err[returnType](fmt.Errorf("unable to generate "+
@@ -129,7 +129,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
129129
leaf, err := CreateSecondLevelHtlcTx(
130130
chanState, com.CommitTx, htlc.Amt.ToSatoshis(),
131131
keys, chainParams, htlcOutputs, cltvTimeout,
132-
htlc.HtlcIndex,
132+
htlc.HtlcIndex, false,
133133
)
134134
if err != nil {
135135
return lfn.Err[returnType](fmt.Errorf("unable "+
@@ -170,7 +170,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
170170
leaf, err := CreateSecondLevelHtlcTx(
171171
chanState, com.CommitTx, htlc.Amt.ToSatoshis(),
172172
keys, chainParams, htlcOutputs, cltvTimeout,
173-
htlc.HtlcIndex,
173+
htlc.HtlcIndex, false,
174174
)
175175
if err != nil {
176176
return lfn.Err[returnType](fmt.Errorf("unable "+
@@ -251,7 +251,7 @@ func ApplyHtlcView(chainParams *address.ChainParams,
251251
_, newCommitment, err := GenerateCommitmentAllocations(
252252
prevState, in.ChannelState, chanAssetState, in.WhoseCommit,
253253
in.OurBalance, in.TheirBalance, in.UnfilteredView, chainParams,
254-
in.KeyRing,
254+
in.KeyRing, false,
255255
)
256256
if err != nil {
257257
return lfn.Err[returnType](fmt.Errorf("unable to generate "+

tapchannel/commitment.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ func GenerateCommitmentAllocations(prevState *cmsg.Commitment,
497497
whoseCommit lntypes.ChannelParty, ourBalance,
498498
theirBalance lnwire.MilliSatoshi, originalView lnwallet.AuxHtlcView,
499499
chainParams *address.ChainParams,
500-
keys lnwallet.CommitmentKeyRing) ([]*tapsend.Allocation,
500+
keys lnwallet.CommitmentKeyRing, stxo bool) ([]*tapsend.Allocation,
501501
*cmsg.Commitment, error) {
502502

503503
log.Tracef("Generating allocations, whoseCommit=%v, ourBalance=%d, "+
@@ -589,8 +589,18 @@ func GenerateCommitmentAllocations(prevState *cmsg.Commitment,
589589
"packets: %w", err)
590590
}
591591

592+
var (
593+
opts []tapsend.OutputCommitmentOption
594+
proofOpts []proof.GenOption
595+
)
596+
597+
if !stxo {
598+
opts = append(opts, tapsend.WithNoSTXOProofs())
599+
proofOpts = append(proofOpts, proof.WithNoSTXOProofs())
600+
}
601+
592602
outCommitments, err := tapsend.CreateOutputCommitments(
593-
vPackets, tapsend.WithNoSTXOProofs(),
603+
vPackets, opts...,
594604
)
595605
if err != nil {
596606
return nil, nil, fmt.Errorf("unable to create output "+
@@ -626,7 +636,7 @@ func GenerateCommitmentAllocations(prevState *cmsg.Commitment,
626636
fakeCommitTx, vPkt, outCommitments, outIdx,
627637
vPackets, tapsend.NonAssetExclusionProofs(
628638
allocations,
629-
), proof.WithNoSTXOProofs(),
639+
), proofOpts...,
630640
)
631641
if err != nil {
632642
return nil, nil, fmt.Errorf("unable to create "+
@@ -1432,7 +1442,7 @@ func CreateSecondLevelHtlcTx(chanState lnwallet.AuxChanState,
14321442
commitTx *wire.MsgTx, htlcAmt btcutil.Amount,
14331443
keys lnwallet.CommitmentKeyRing, chainParams *address.ChainParams,
14341444
htlcOutputs []*cmsg.AssetOutput, htlcTimeout fn.Option[uint32],
1435-
htlcIndex uint64) (input.AuxTapLeaf, error) {
1445+
htlcIndex uint64, stxo bool) (input.AuxTapLeaf, error) {
14361446

14371447
none := input.NoneTapLeaf()
14381448

@@ -1445,8 +1455,13 @@ func CreateSecondLevelHtlcTx(chanState lnwallet.AuxChanState,
14451455
"packets: %w", err)
14461456
}
14471457

1458+
var opts []tapsend.OutputCommitmentOption
1459+
if !stxo {
1460+
opts = append(opts, tapsend.WithNoSTXOProofs())
1461+
}
1462+
14481463
outCommitments, err := tapsend.CreateOutputCommitments(
1449-
vPackets, tapsend.WithNoSTXOProofs(),
1464+
vPackets, opts...,
14501465
)
14511466
if err != nil {
14521467
return none, fmt.Errorf("unable to create output commitments: "+

0 commit comments

Comments
 (0)