Skip to content

Commit 76c0706

Browse files
committed
tapchannel+tapsend: disable STXO asset creation for channels
To avoid breaking backward compatibility with older nodes and existing channels, we need to make sure we don't add STXO proofs to channel related transactions.
1 parent 1e9e38a commit 76c0706

File tree

5 files changed

+66
-21
lines changed

5 files changed

+66
-21
lines changed

tapchannel/aux_closer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,9 @@ func (a *AuxChanCloser) AuxCloseOutputs(
453453
// With the outputs prepared, we can now create the set of output
454454
// commitments, then with the output index locations known, we can set
455455
// the output indexes in the allocations.
456-
outCommitments, err := tapsend.CreateOutputCommitments(vPackets)
456+
outCommitments, err := tapsend.CreateOutputCommitments(
457+
vPackets, tapsend.WithNoSTXOProofs(),
458+
)
457459
if err != nil {
458460
return none, fmt.Errorf("unable to create output "+
459461
"commitments: %w", err)

tapchannel/aux_funding_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,9 @@ func (f *FundingController) anchorVPackets(fundedPkt *tapsend.FundedPsbt,
10801080

10811081
// Given the set of vPackets we've created, we'll now merge them all to
10821082
// create a map from output index to final tap commitment.
1083-
outputCommitments, err := tapsend.CreateOutputCommitments(allPackets)
1083+
outputCommitments, err := tapsend.CreateOutputCommitments(
1084+
allPackets, tapsend.WithNoSTXOProofs(),
1085+
)
10841086
if err != nil {
10851087
return nil, fmt.Errorf("unable to create new output "+
10861088
"commitments: %w", err)

tapchannel/aux_sweeper.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,9 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
15901590
"packets: %w", err)
15911591
}
15921592

1593-
outCommitments, err := tapsend.CreateOutputCommitments(vPackets)
1593+
outCommitments, err := tapsend.CreateOutputCommitments(
1594+
vPackets, tapsend.WithNoSTXOProofs(),
1595+
)
15941596
if err != nil {
15951597
return fmt.Errorf("unable to create output "+
15961598
"commitments: %w", err)
@@ -2219,7 +2221,9 @@ func (a *AuxSweeper) sweepContracts(inputs []input.Input,
22192221

22202222
// Now that we have our set of resolutions, we'll make a new commitment
22212223
// out of all the vPackets contained.
2222-
outCommitments, err := tapsend.CreateOutputCommitments(directPkts)
2224+
outCommitments, err := tapsend.CreateOutputCommitments(
2225+
directPkts, tapsend.WithNoSTXOProofs(),
2226+
)
22232227
if err != nil {
22242228
return lfn.Errf[returnType]("unable to create "+
22252229
"output commitments: %w", err)
@@ -2400,7 +2404,9 @@ func (a *AuxSweeper) registerAndBroadcastSweep(req *sweep.BumpRequest,
24002404
}
24012405

24022406
// Now that we have our vPkts, we'll re-create the output commitments.
2403-
outCommitments, err := tapsend.CreateOutputCommitments(vPkts.allPkts())
2407+
outCommitments, err := tapsend.CreateOutputCommitments(
2408+
vPkts.allPkts(), tapsend.WithNoSTXOProofs(),
2409+
)
24042410
if err != nil {
24052411
return fmt.Errorf("unable to create output "+
24062412
"commitments: %w", err)

tapchannel/commitment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,9 @@ func GenerateCommitmentAllocations(prevState *cmsg.Commitment,
575575
"packets: %w", err)
576576
}
577577

578-
outCommitments, err := tapsend.CreateOutputCommitments(vPackets)
578+
outCommitments, err := tapsend.CreateOutputCommitments(
579+
vPackets, tapsend.WithNoSTXOProofs(),
580+
)
579581
if err != nil {
580582
return nil, nil, fmt.Errorf("unable to create output "+
581583
"commitments: %w", err)
@@ -1423,7 +1425,9 @@ func CreateSecondLevelHtlcTx(chanState lnwallet.AuxChanState,
14231425
"packets: %w", err)
14241426
}
14251427

1426-
outCommitments, err := tapsend.CreateOutputCommitments(vPackets)
1428+
outCommitments, err := tapsend.CreateOutputCommitments(
1429+
vPackets, tapsend.WithNoSTXOProofs(),
1430+
)
14271431
if err != nil {
14281432
return none, fmt.Errorf("unable to create output commitments: "+
14291433
"%w", err)

tapsend/send.go

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -909,11 +909,38 @@ func addKeyTweaks(unknowns []*psbt.Unknown, desc *lndclient.SignDescriptor) {
909909
}
910910
}
911911

912+
// OutputCommitmentConfig is a struct that holds the configuration for the
913+
// output commitment creation process.
914+
type OutputCommitmentConfig struct {
915+
// noSTXOProofs indicates whether we should skip the generation of
916+
// STXO proofs. This should only be done for asset channels to preserve
917+
// the backward compatibility with older peers.
918+
noSTXOProofs bool
919+
}
920+
921+
// OutputCommitmentOption is a functional option that can be used to configure
922+
// the output commitment creation process.
923+
type OutputCommitmentOption func(*OutputCommitmentConfig)
924+
925+
// WithNoSTXOProofs is an option that can be used to skip the generation of
926+
// STXO proofs. This should only be done for asset channels to preserve the
927+
// backward compatibility with older peers.
928+
func WithNoSTXOProofs() OutputCommitmentOption {
929+
return func(cfg *OutputCommitmentConfig) {
930+
cfg.noSTXOProofs = true
931+
}
932+
}
933+
912934
// CreateOutputCommitments creates the final set of Taproot asset commitments
913935
// representing the asset sends of the given packets of active and passive
914936
// assets.
915-
func CreateOutputCommitments(
916-
packets []*tappsbt.VPacket) (tappsbt.OutputCommitments, error) {
937+
func CreateOutputCommitments(packets []*tappsbt.VPacket,
938+
opts ...OutputCommitmentOption) (tappsbt.OutputCommitments, error) {
939+
940+
cfg := &OutputCommitmentConfig{}
941+
for _, opt := range opts {
942+
opt(cfg)
943+
}
917944

918945
// Inputs must be unique.
919946
if err := AssertInputsUnique(packets); err != nil {
@@ -948,7 +975,7 @@ func CreateOutputCommitments(
948975
// And now we commit each packet to the respective anchor output
949976
// commitments.
950977
for _, vPkt := range packets {
951-
err := commitPacket(vPkt, outputCommitments)
978+
err := commitPacket(vPkt, cfg.noSTXOProofs, outputCommitments)
952979
if err != nil {
953980
return nil, err
954981
}
@@ -959,7 +986,7 @@ func CreateOutputCommitments(
959986

960987
// commitPacket creates the output commitments for a virtual packet and merges
961988
// it with the existing commitments for the anchor outputs.
962-
func commitPacket(vPkt *tappsbt.VPacket,
989+
func commitPacket(vPkt *tappsbt.VPacket, noSTXOProofs bool,
963990
outputCommitments tappsbt.OutputCommitments) error {
964991

965992
inputs := vPkt.Inputs
@@ -995,17 +1022,21 @@ func commitPacket(vPkt *tappsbt.VPacket,
9951022
return fmt.Errorf("error committing assets: %w", err)
9961023
}
9971024

998-
// Collect the spent assets for this output.
999-
stxoAssets, err := asset.CollectSTXO(vOut.Asset)
1000-
if err != nil {
1001-
return fmt.Errorf("error collecting STXO assets: %w",
1002-
err)
1003-
}
1025+
// To not break backward compatibility with older peers, we skip
1026+
// the generation of STXO proofs for asset channels.
1027+
if !noSTXOProofs {
1028+
// Collect the spent assets for this output.
1029+
stxoAssets, err := asset.CollectSTXO(vOut.Asset)
1030+
if err != nil {
1031+
return fmt.Errorf("error collecting STXO "+
1032+
"assets: %w", err)
1033+
}
10041034

1005-
// If we have STXOs, we will encumber vOut.AltLeaves with
1006-
// them.They will be merged into the commitment later with
1007-
// MergeAltLeaves.
1008-
vOut.AltLeaves = append(vOut.AltLeaves, stxoAssets...)
1035+
// If we have STXOs, we will encumber vOut.AltLeaves
1036+
// with them. They will be merged into the commitment
1037+
// later with MergeAltLeaves.
1038+
vOut.AltLeaves = append(vOut.AltLeaves, stxoAssets...)
1039+
}
10091040

10101041
// Because the receiver of this output might be receiving
10111042
// through an address (non-interactive), we need to blank out

0 commit comments

Comments
 (0)