Skip to content

Commit a4da00a

Browse files
committed
rfq: use aux chan negotiator
1 parent 7770292 commit a4da00a

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

rfq/manager.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lightninglabs/taproot-assets/fn"
2020
"github.com/lightninglabs/taproot-assets/rfqmath"
2121
"github.com/lightninglabs/taproot-assets/rfqmsg"
22+
"github.com/lightninglabs/taproot-assets/tapfeatures"
2223
"github.com/lightninglabs/taproot-assets/taprpc/rfqrpc"
2324
"github.com/lightningnetwork/lnd/lnrpc"
2425
"github.com/lightningnetwork/lnd/lnutils"
@@ -112,6 +113,8 @@ type ManagerCfg struct {
112113
// into the manager once lnd and tapd are hooked together.
113114
AliasManager ScidAliasManager
114115

116+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
117+
115118
// AcceptPriceDeviationPpm is the price deviation in
116119
// parts per million that is accepted by the RFQ negotiator.
117120
//
@@ -251,12 +254,13 @@ func (m *Manager) startSubsystems(ctx context.Context) error {
251254

252255
// Initialise and start the order handler.
253256
m.orderHandler, err = NewOrderHandler(OrderHandlerCfg{
254-
CleanupInterval: CacheCleanupInterval,
255-
HtlcInterceptor: m.cfg.HtlcInterceptor,
256-
HtlcSubscriber: m.cfg.HtlcSubscriber,
257-
AcceptHtlcEvents: m.acceptHtlcEvents,
258-
SpecifierChecker: m.AssetMatchesSpecifier,
259-
NoOpHTLCs: m.cfg.NoOpHTLCs,
257+
CleanupInterval: CacheCleanupInterval,
258+
HtlcInterceptor: m.cfg.HtlcInterceptor,
259+
HtlcSubscriber: m.cfg.HtlcSubscriber,
260+
AcceptHtlcEvents: m.acceptHtlcEvents,
261+
SpecifierChecker: m.AssetMatchesSpecifier,
262+
NoOpHTLCs: m.cfg.NoOpHTLCs,
263+
AuxChanNegotiator: m.cfg.AuxChanNegotiator,
260264
})
261265
if err != nil {
262266
return fmt.Errorf("error initializing RFQ order handler: %w",

rfq/order.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import (
1414
"github.com/lightninglabs/taproot-assets/fn"
1515
"github.com/lightninglabs/taproot-assets/rfqmath"
1616
"github.com/lightninglabs/taproot-assets/rfqmsg"
17+
"github.com/lightninglabs/taproot-assets/tapfeatures"
1718
"github.com/lightningnetwork/lnd/graph/db/models"
1819
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
1920
"github.com/lightningnetwork/lnd/lnutils"
2021
"github.com/lightningnetwork/lnd/lnwallet"
2122
"github.com/lightningnetwork/lnd/lnwire"
23+
"github.com/lightningnetwork/lnd/routing/route"
2224
"github.com/lightningnetwork/lnd/tlv"
2325
)
2426

@@ -125,13 +127,20 @@ type AssetSalePolicy struct {
125127
// wants us to produce NoOp HTLCs.
126128
NoOpHTLCs bool
127129

130+
auxChanNegotiator *tapfeatures.AuxChannelNegotiator
131+
132+
peer route.Vertex
133+
128134
// expiry is the policy's expiry unix timestamp after which the policy
129135
// is no longer valid.
130136
expiry uint64
131137
}
132138

133139
// NewAssetSalePolicy creates a new asset sale policy.
134-
func NewAssetSalePolicy(quote rfqmsg.BuyAccept, noop bool) *AssetSalePolicy {
140+
func NewAssetSalePolicy(quote rfqmsg.BuyAccept, noop bool,
141+
chanNegotiator *tapfeatures.AuxChannelNegotiator,
142+
peer route.Vertex) *AssetSalePolicy {
143+
135144
htlcToAmtMap := make(map[models.CircuitKey]lnwire.MilliSatoshi)
136145

137146
return &AssetSalePolicy{
@@ -142,6 +151,8 @@ func NewAssetSalePolicy(quote rfqmsg.BuyAccept, noop bool) *AssetSalePolicy {
142151
expiry: uint64(quote.AssetRate.Expiry.Unix()),
143152
htlcToAmt: htlcToAmtMap,
144153
NoOpHTLCs: noop,
154+
auxChanNegotiator: chanNegotiator,
155+
peer: peer,
145156
}
146157
}
147158

@@ -290,10 +301,13 @@ func (c *AssetSalePolicy) GenerateInterceptorResponse(
290301
fn.None[[]rfqmsg.ID](),
291302
)
292303

304+
peerFeatures := c.auxChanNegotiator.GetPeerFeatures(c.peer)
305+
supportNoOp := peerFeatures.HasFeature(tapfeatures.NoOpHTLCsOptional)
306+
293307
// We are about to create an outgoing HTLC that carries assets. Let's
294308
// set the noop flag in order to eventually only settle the assets but
295309
// never settle the sats anchor amount that will carry them.
296-
if c.NoOpHTLCs {
310+
if c.NoOpHTLCs && supportNoOp {
297311
htlcRecord.SetNoopAdd(rfqmsg.UseNoOpHTLCs)
298312
}
299313

@@ -686,6 +700,11 @@ type OrderHandlerCfg struct {
686700
// NoOpHTLCs is a boolean indicating whether the daemon configuration
687701
// wants us to produce NoOp HTLCs.
688702
NoOpHTLCs bool
703+
704+
// AuxChannelNegotiator is responsible for producing the extra tlv blob
705+
// that is encapsulated in the init and reestablish peer messages. This
706+
// helps us communicate custom feature bits with our peer.
707+
AuxChanNegotiator *tapfeatures.AuxChannelNegotiator
689708
}
690709

691710
// OrderHandler orchestrates management of accepted quote bundles. It monitors
@@ -940,7 +959,11 @@ func (h *OrderHandler) RegisterAssetSalePolicy(buyAccept rfqmsg.BuyAccept) {
940959
log.Debugf("Order handler is registering an asset sale policy given a "+
941960
"buy accept message: %s", buyAccept.String())
942961

943-
policy := NewAssetSalePolicy(buyAccept, h.cfg.NoOpHTLCs)
962+
policy := NewAssetSalePolicy(
963+
buyAccept, h.cfg.NoOpHTLCs, h.cfg.AuxChanNegotiator,
964+
buyAccept.Peer,
965+
)
966+
944967
h.policies.Store(policy.AcceptedQuoteId.Scid(), policy)
945968
}
946969

0 commit comments

Comments
 (0)