Skip to content

Commit 5c7da7d

Browse files
committed
tapchannel: add stxo support for aux leaves
We also add stxo support for the aux leaf creation. This is crucial and needs to be the same across both channel parties. We rely on the consistency of the feature bit for whether we'll include the stxo alt leaves or not. A disagreement here could lead to a force close.
1 parent 5b219cf commit 5c7da7d

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

server.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,9 @@ func (s *Server) FetchLeavesFromView(
833833

834834
// The aux leaf creator is fully stateless, and we don't need to wait
835835
// for the server to be started before being able to use it.
836-
return tapchannel.FetchLeavesFromView(s.chainParams, in)
836+
return tapchannel.FetchLeavesFromView(
837+
s.chainParams, in, s.cfg.AuxChanNegotiator,
838+
)
837839
}
838840

839841
// FetchLeavesFromCommit attempts to fetch the auxiliary leaves that
@@ -889,7 +891,9 @@ func (s *Server) ApplyHtlcView(
889891

890892
// The aux leaf creator is fully stateless, and we don't need to wait
891893
// for the server to be started before being able to use it.
892-
return tapchannel.ApplyHtlcView(s.chainParams, in)
894+
return tapchannel.ApplyHtlcView(
895+
s.chainParams, in, s.cfg.AuxChanNegotiator,
896+
)
893897
}
894898

895899
// InlineParseCustomData replaces any custom data binary blob in the given RPC

tapchannel/aux_leaf_creator.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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 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+
2737
// FetchLeavesFromView attempts to fetch the auxiliary leaves that correspond to
2838
// the passed aux blob, and pending fully evaluated HTLC view.
2939
func 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.
227248
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]] {
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

Comments
 (0)