@@ -10,11 +10,13 @@ import (
1010 "github.com/lightninglabs/taproot-assets/address"
1111 "github.com/lightninglabs/taproot-assets/fn"
1212 cmsg "github.com/lightninglabs/taproot-assets/tapchannelmsg"
13+ "github.com/lightninglabs/taproot-assets/tapfeatures"
1314 "github.com/lightningnetwork/lnd/channeldb"
1415 lfn "github.com/lightningnetwork/lnd/fn/v2"
1516 "github.com/lightningnetwork/lnd/input"
1617 "github.com/lightningnetwork/lnd/lntypes"
1718 lnwl "github.com/lightningnetwork/lnd/lnwallet"
19+ "github.com/lightningnetwork/lnd/lnwire"
1820 "github.com/lightningnetwork/lnd/tlv"
1921)
2022
@@ -24,10 +26,19 @@ const (
2426 DefaultTimeout = 30 * time .Second
2527)
2628
29+ // FeatureBitFetcher is responsible for fetching feature bits by referencing a
30+ // channel ID.
31+ type FeatureBitFetcher interface {
32+ // GetChannelFeatures returns the negotiated features that are active
33+ // over the channel identifier by the provided channelID.
34+ GetChannelFeatures (cid lnwire.ChannelID ) lnwire.FeatureVector
35+ }
36+
2737// FetchLeavesFromView attempts to fetch the auxiliary leaves that correspond to
2838// the passed aux blob, and pending fully evaluated HTLC view.
2939func FetchLeavesFromView (chainParams * address.ChainParams ,
30- in lnwl.CommitDiffAuxInput ) lfn.Result [lnwl.CommitDiffAuxResult ] {
40+ in lnwl.CommitDiffAuxInput ,
41+ bitFetcher FeatureBitFetcher ) lfn.Result [lnwl.CommitDiffAuxResult ] {
3142
3243 type returnType = lnwl.CommitDiffAuxResult
3344
@@ -50,10 +61,18 @@ func FetchLeavesFromView(chainParams *address.ChainParams,
5061 "commit state: %w" , err ))
5162 }
5263
64+ features := bitFetcher .GetChannelFeatures (
65+ lnwire .NewChanIDFromOutPoint (
66+ in .ChannelState .FundingOutpoint ,
67+ ),
68+ )
69+
70+ supportsSTXO := features .HasFeature (tapfeatures .STXOOptional )
71+
5372 allocations , newCommitment , err := GenerateCommitmentAllocations (
5473 prevState , in .ChannelState , chanAssetState , in .WhoseCommit ,
5574 in .OurBalance , in .TheirBalance , in .UnfilteredView , chainParams ,
56- in .KeyRing , false ,
75+ in .KeyRing , supportsSTXO ,
5776 )
5877 if err != nil {
5978 return lfn.Err [returnType ](fmt .Errorf ("unable to generate " +
@@ -98,6 +117,8 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
98117 "commitment: %w" , err ))
99118 }
100119
120+ supportSTXO := commitment .STXO .Val
121+
101122 incomingHtlcs := commitment .IncomingHtlcAssets .Val .HtlcOutputs
102123 incomingHtlcLeaves := commitment .AuxLeaves .Val .IncomingHtlcLeaves .
103124 Val .HtlcAuxLeaves
@@ -129,7 +150,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
129150 leaf , err := CreateSecondLevelHtlcTx (
130151 chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
131152 keys , chainParams , htlcOutputs , cltvTimeout ,
132- htlc .HtlcIndex , false ,
153+ htlc .HtlcIndex , supportSTXO ,
133154 )
134155 if err != nil {
135156 return lfn.Err [returnType ](fmt .Errorf ("unable " +
@@ -170,7 +191,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
170191 leaf , err := CreateSecondLevelHtlcTx (
171192 chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
172193 keys , chainParams , htlcOutputs , cltvTimeout ,
173- htlc .HtlcIndex , false ,
194+ htlc .HtlcIndex , supportSTXO ,
174195 )
175196 if err != nil {
176197 return lfn.Err [returnType ](fmt .Errorf ("unable " +
@@ -225,7 +246,8 @@ func FetchLeavesFromRevocation(
225246// channel's blob. Given the old blob, and an HTLC view, then a new
226247// blob should be returned that reflects the pending updates.
227248func ApplyHtlcView (chainParams * address.ChainParams ,
228- in lnwl.CommitDiffAuxInput ) lfn.Result [lfn.Option [tlv.Blob ]] {
249+ in lnwl.CommitDiffAuxInput ,
250+ bitFetcher FeatureBitFetcher ) lfn.Result [lfn.Option [tlv.Blob ]] {
229251
230252 type returnType = lfn.Option [tlv.Blob ]
231253
@@ -248,10 +270,20 @@ func ApplyHtlcView(chainParams *address.ChainParams,
248270 "commit state: %w" , err ))
249271 }
250272
273+ features := bitFetcher .GetChannelFeatures (
274+ lnwire .NewChanIDFromOutPoint (
275+ in .ChannelState .FundingOutpoint ,
276+ ),
277+ )
278+
279+ supportSTXO := features .HasFeature (
280+ tapfeatures .STXOOptional ,
281+ )
282+
251283 _ , newCommitment , err := GenerateCommitmentAllocations (
252284 prevState , in .ChannelState , chanAssetState , in .WhoseCommit ,
253285 in .OurBalance , in .TheirBalance , in .UnfilteredView , chainParams ,
254- in .KeyRing , false ,
286+ in .KeyRing , supportSTXO ,
255287 )
256288 if err != nil {
257289 return lfn.Err [returnType ](fmt .Errorf ("unable to generate " +
0 commit comments