@@ -10,11 +10,13 @@ import (
10
10
"github.com/lightninglabs/taproot-assets/address"
11
11
"github.com/lightninglabs/taproot-assets/fn"
12
12
cmsg "github.com/lightninglabs/taproot-assets/tapchannelmsg"
13
+ "github.com/lightninglabs/taproot-assets/tapfeatures"
13
14
"github.com/lightningnetwork/lnd/channeldb"
14
15
lfn "github.com/lightningnetwork/lnd/fn/v2"
15
16
"github.com/lightningnetwork/lnd/input"
16
17
"github.com/lightningnetwork/lnd/lntypes"
17
18
lnwl "github.com/lightningnetwork/lnd/lnwallet"
19
+ "github.com/lightningnetwork/lnd/lnwire"
18
20
"github.com/lightningnetwork/lnd/tlv"
19
21
)
20
22
@@ -24,10 +26,19 @@ const (
24
26
DefaultTimeout = 30 * time .Second
25
27
)
26
28
29
+ // FeatureBitFetcher is responsible for fetching feature bits either by
30
+ // referencing a remote peer, or an established channel.
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
+
27
37
// FetchLeavesFromView attempts to fetch the auxiliary leaves that correspond to
28
38
// the passed aux blob, and pending fully evaluated HTLC view.
29
39
func FetchLeavesFromView (chainParams * address.ChainParams ,
30
- in lnwl.CommitDiffAuxInput ) lfn.Result [lnwl.CommitDiffAuxResult ] {
40
+ in lnwl.CommitDiffAuxInput ,
41
+ bitFetcher FeatureBitFetcher ) lfn.Result [lnwl.CommitDiffAuxResult ] {
31
42
32
43
type returnType = lnwl.CommitDiffAuxResult
33
44
@@ -50,10 +61,18 @@ func FetchLeavesFromView(chainParams *address.ChainParams,
50
61
"commit state: %w" , err ))
51
62
}
52
63
64
+ features := bitFetcher .GetChannelFeatures (
65
+ lnwire .NewChanIDFromOutPoint (
66
+ in .ChannelState .FundingOutpoint ,
67
+ ),
68
+ )
69
+
70
+ supportsSTXO := features .HasFeature (tapfeatures .STXOOptional )
71
+
53
72
allocations , newCommitment , err := GenerateCommitmentAllocations (
54
73
prevState , in .ChannelState , chanAssetState , in .WhoseCommit ,
55
74
in .OurBalance , in .TheirBalance , in .UnfilteredView , chainParams ,
56
- in .KeyRing , false ,
75
+ in .KeyRing , supportsSTXO ,
57
76
)
58
77
if err != nil {
59
78
return lfn.Err [returnType ](fmt .Errorf ("unable to generate " +
@@ -98,6 +117,8 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
98
117
"commitment: %w" , err ))
99
118
}
100
119
120
+ supportSTXO := commitment .STXO .Val
121
+
101
122
incomingHtlcs := commitment .IncomingHtlcAssets .Val .HtlcOutputs
102
123
incomingHtlcLeaves := commitment .AuxLeaves .Val .IncomingHtlcLeaves .
103
124
Val .HtlcAuxLeaves
@@ -129,7 +150,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
129
150
leaf , err := CreateSecondLevelHtlcTx (
130
151
chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
131
152
keys , chainParams , htlcOutputs , cltvTimeout ,
132
- htlc .HtlcIndex , false ,
153
+ htlc .HtlcIndex , supportSTXO ,
133
154
)
134
155
if err != nil {
135
156
return lfn.Err [returnType ](fmt .Errorf ("unable " +
@@ -170,7 +191,7 @@ func FetchLeavesFromCommit(chainParams *address.ChainParams,
170
191
leaf , err := CreateSecondLevelHtlcTx (
171
192
chanState , com .CommitTx , htlc .Amt .ToSatoshis (),
172
193
keys , chainParams , htlcOutputs , cltvTimeout ,
173
- htlc .HtlcIndex , false ,
194
+ htlc .HtlcIndex , supportSTXO ,
174
195
)
175
196
if err != nil {
176
197
return lfn.Err [returnType ](fmt .Errorf ("unable " +
@@ -225,7 +246,8 @@ func FetchLeavesFromRevocation(
225
246
// channel's blob. Given the old blob, and an HTLC view, then a new
226
247
// blob should be returned that reflects the pending updates.
227
248
func 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 ]] {
229
251
230
252
type returnType = lfn.Option [tlv.Blob ]
231
253
@@ -248,10 +270,20 @@ func ApplyHtlcView(chainParams *address.ChainParams,
248
270
"commit state: %w" , err ))
249
271
}
250
272
273
+ features := bitFetcher .GetChannelFeatures (
274
+ lnwire .NewChanIDFromOutPoint (
275
+ in .ChannelState .FundingOutpoint ,
276
+ ),
277
+ )
278
+
279
+ supportSTXO := features .HasFeature (
280
+ tapfeatures .STXOOptional ,
281
+ )
282
+
251
283
_ , newCommitment , err := GenerateCommitmentAllocations (
252
284
prevState , in .ChannelState , chanAssetState , in .WhoseCommit ,
253
285
in .OurBalance , in .TheirBalance , in .UnfilteredView , chainParams ,
254
- in .KeyRing , false ,
286
+ in .KeyRing , supportSTXO ,
255
287
)
256
288
if err != nil {
257
289
return lfn.Err [returnType ](fmt .Errorf ("unable to generate " +
0 commit comments