Skip to content

Commit fa70fb4

Browse files
committed
multi: start the RFQ service on startup
This commit plugs the new RFQ service into the greater tapd service.
1 parent a44b738 commit fa70fb4

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

chain_bridge.go

+59
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/btcsuite/btcd/chaincfg/chainhash"
88
"github.com/btcsuite/btcd/wire"
99
"github.com/lightninglabs/lndclient"
10+
"github.com/lightninglabs/taproot-assets/rfq"
1011
"github.com/lightninglabs/taproot-assets/tapgarden"
1112
"github.com/lightningnetwork/lnd/chainntnfs"
1213
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
@@ -203,3 +204,61 @@ func (l *LndRpcChainBridge) EstimateFee(ctx context.Context,
203204
// A compile time assertion to ensure LndRpcChainBridge meets the
204205
// tapgarden.ChainBridge interface.
205206
var _ tapgarden.ChainBridge = (*LndRpcChainBridge)(nil)
207+
208+
// LndMsgTransportClient is an LND RPC message transport client.
209+
type LndMsgTransportClient struct {
210+
lnd *lndclient.LndServices
211+
}
212+
213+
// NewLndMsgTransportClient creates a new message transport RPC client for a
214+
// given LND service.
215+
func NewLndMsgTransportClient(
216+
lnd *lndclient.LndServices) *LndMsgTransportClient {
217+
218+
return &LndMsgTransportClient{
219+
lnd: lnd,
220+
}
221+
}
222+
223+
// SubscribeCustomMessages creates a subscription to custom messages received
224+
// from our peers.
225+
func (l *LndMsgTransportClient) SubscribeCustomMessages(
226+
ctx context.Context) (<-chan lndclient.CustomMessage,
227+
<-chan error, error) {
228+
229+
return l.lnd.Client.SubscribeCustomMessages(ctx)
230+
}
231+
232+
// SendCustomMessage sends a custom message to a peer.
233+
func (l *LndMsgTransportClient) SendCustomMessage(ctx context.Context,
234+
msg lndclient.CustomMessage) error {
235+
236+
return l.lnd.Client.SendCustomMessage(ctx, msg)
237+
}
238+
239+
// Ensure LndMsgTransportClient implements the rfq.PeerMessenger interface.
240+
var _ rfq.PeerMessenger = (*LndMsgTransportClient)(nil)
241+
242+
// LndRouterClient is an LND router RPC client.
243+
type LndRouterClient struct {
244+
lnd *lndclient.LndServices
245+
}
246+
247+
// NewLndRouterClient creates a new LND router client for a given LND service.
248+
func NewLndRouterClient(lnd *lndclient.LndServices) *LndRouterClient {
249+
return &LndRouterClient{
250+
lnd: lnd,
251+
}
252+
}
253+
254+
// InterceptHtlcs intercepts all incoming HTLCs and calls the given handler
255+
// function with the HTLC details. The handler function can then decide whether
256+
// to accept or reject the HTLC.
257+
func (l *LndRouterClient) InterceptHtlcs(
258+
ctx context.Context, handler lndclient.HtlcInterceptHandler) error {
259+
260+
return l.lnd.Router.InterceptHtlcs(ctx, handler)
261+
}
262+
263+
// Ensure LndRouterClient implements the rfq.HtlcInterceptor interface.
264+
var _ rfq.HtlcInterceptor = (*LndRouterClient)(nil)

config.go

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/taproot-assets/address"
1111
"github.com/lightninglabs/taproot-assets/monitoring"
1212
"github.com/lightninglabs/taproot-assets/proof"
13+
"github.com/lightninglabs/taproot-assets/rfq"
1314
"github.com/lightninglabs/taproot-assets/tapdb"
1415
"github.com/lightninglabs/taproot-assets/tapfreighter"
1516
"github.com/lightninglabs/taproot-assets/tapgarden"
@@ -122,6 +123,8 @@ type Config struct {
122123

123124
UniverseFederation *universe.FederationEnvoy
124125

126+
RfqManager *rfq.Manager
127+
125128
UniverseStats universe.Telemetry
126129

127130
// UniversePublicAccess is flag which, If true, and the Universe server

log.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/lightninglabs/taproot-assets/commitment"
77
"github.com/lightninglabs/taproot-assets/monitoring"
88
"github.com/lightninglabs/taproot-assets/proof"
9+
"github.com/lightninglabs/taproot-assets/rfq"
910
"github.com/lightninglabs/taproot-assets/tapdb"
1011
"github.com/lightninglabs/taproot-assets/tapfreighter"
1112
"github.com/lightninglabs/taproot-assets/tapgarden"
@@ -109,6 +110,7 @@ func SetupLoggers(root *build.RotatingLogWriter, interceptor signal.Interceptor)
109110
AddSubLogger(
110111
root, monitoring.Subsystem, interceptor, monitoring.UseLogger,
111112
)
113+
AddSubLogger(root, rfq.Subsystem, interceptor, rfq.UseLogger)
112114
}
113115

114116
// AddSubLogger is a helper method to conveniently create and register the

server.go

+9
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func (s *Server) initialize(interceptorChain *rpcperms.InterceptorChain) error {
158158
"federation: %v", err)
159159
}
160160

161+
// Start the request for quote (RFQ) manager.
162+
if err := s.cfg.RfqManager.Start(); err != nil {
163+
return fmt.Errorf("unable to start RFQ manager: %w", err)
164+
}
165+
161166
if s.cfg.UniversePublicAccess {
162167
err := s.cfg.UniverseFederation.SetAllowPublicAccess()
163168
if err != nil {
@@ -586,6 +591,10 @@ func (s *Server) Stop() error {
586591
return err
587592
}
588593

594+
if err := s.cfg.RfqManager.Stop(); err != nil {
595+
return err
596+
}
597+
589598
if s.macaroonService != nil {
590599
err := s.macaroonService.Stop()
591600
if err != nil {

tapcfg/server.go

+20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/lightninglabs/taproot-assets/address"
1414
"github.com/lightninglabs/taproot-assets/asset"
1515
"github.com/lightninglabs/taproot-assets/proof"
16+
"github.com/lightninglabs/taproot-assets/rfq"
1617
"github.com/lightninglabs/taproot-assets/tapdb"
1718
"github.com/lightninglabs/taproot-assets/tapdb/sqlc"
1819
"github.com/lightninglabs/taproot-assets/tapfreighter"
@@ -96,6 +97,8 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
9697
keyRing := tap.NewLndRpcKeyRing(lndServices)
9798
walletAnchor := tap.NewLndRpcWalletAnchor(lndServices)
9899
chainBridge := tap.NewLndRpcChainBridge(lndServices)
100+
msgTransportClient := tap.NewLndMsgTransportClient(lndServices)
101+
lndRouterClient := tap.NewLndRouterClient(lndServices)
99102

100103
assetStore := tapdb.NewAssetStore(assetDB, defaultClock)
101104

@@ -321,6 +324,22 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
321324

322325
multiNotifier := proof.NewMultiArchiveNotifier(assetStore, multiverse)
323326

327+
// TODO(ffranr): Replace the mock price oracle with a real one.
328+
priceOracle := rfq.NewMockPriceOracle(3600)
329+
330+
// Construct the RFQ manager.
331+
rfqManager, err := rfq.NewManager(
332+
rfq.ManagerCfg{
333+
PeerMessenger: msgTransportClient,
334+
HtlcInterceptor: lndRouterClient,
335+
PriceOracle: priceOracle,
336+
ErrChan: mainErrChan,
337+
},
338+
)
339+
if err != nil {
340+
return nil, err
341+
}
342+
324343
return &tap.Config{
325344
DebugLevel: cfg.DebugLevel,
326345
RuntimeID: runtimeID,
@@ -393,6 +412,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
393412
UniversePublicAccess: cfg.Universe.PublicAccess,
394413
UniverseQueriesPerSecond: cfg.Universe.UniverseQueriesPerSecond,
395414
UniverseQueriesBurst: cfg.Universe.UniverseQueriesBurst,
415+
RfqManager: rfqManager,
396416
LogWriter: cfg.LogWriter,
397417
DatabaseConfig: &tap.DatabaseConfig{
398418
RootKeyStore: tapdb.NewRootKeyStore(rksDB),

0 commit comments

Comments
 (0)