From 02e662857aa67d819b920ebf291f4b6046851de6 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 13 Feb 2025 11:32:32 +0200 Subject: [PATCH] invoicesrpc: remove direct access to ChannelGraph pointer --- docs/release-notes/release-notes-0.19.0.md | 5 +++-- lnrpc/invoicesrpc/addinvoice.go | 6 +++--- lnrpc/invoicesrpc/config_active.go | 7 +++---- lnrpc/invoicesrpc/interfaces.go | 19 +++++++++++++++++++ lnrpc/invoicesrpc/invoices_server.go | 2 +- subrpcserver_config.go | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 lnrpc/invoicesrpc/interfaces.go diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index f5dadbe57d..a8a91fa193 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -245,8 +245,9 @@ config option](https://github.com/lightningnetwork/lnd/pull/9182) and introduce a new option `channel-max-fee-exposure` which is unambiguous in its description. The underlying functionality between those two options remain the same. -* [Abstraction of graph](https://github.com/lightningnetwork/lnd/pull/9480) - access for autopilot. +* Graph abstraction work: + - [Abstract autopilot access](https://github.com/lightningnetwork/lnd/pull/9480) + - [Abstract invoicerpc server access]() * [Golang was updated to `v1.22.11`](https://github.com/lightningnetwork/lnd/pull/9462). diff --git a/lnrpc/invoicesrpc/addinvoice.go b/lnrpc/invoicesrpc/addinvoice.go index 114e357188..aba5da4dfe 100644 --- a/lnrpc/invoicesrpc/addinvoice.go +++ b/lnrpc/invoicesrpc/addinvoice.go @@ -18,7 +18,6 @@ import ( "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" - graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lntypes" @@ -75,8 +74,9 @@ type AddInvoiceConfig struct { // channel graph. ChanDB *channeldb.ChannelStateDB - // Graph holds a reference to the ChannelGraph database. - Graph *graphdb.ChannelGraph + // Graph gives the invoice server access to various graph related + // queries. + Graph GraphSource // GenInvoiceFeatures returns a feature containing feature bits that // should be advertised on freshly generated invoices. diff --git a/lnrpc/invoicesrpc/config_active.go b/lnrpc/invoicesrpc/config_active.go index 14799c67ba..f2d2b04bb0 100644 --- a/lnrpc/invoicesrpc/config_active.go +++ b/lnrpc/invoicesrpc/config_active.go @@ -6,7 +6,6 @@ package invoicesrpc import ( "github.com/btcsuite/btcd/chaincfg" "github.com/lightningnetwork/lnd/channeldb" - graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/macaroons" @@ -52,9 +51,9 @@ type Config struct { // specified. DefaultCLTVExpiry uint32 - // GraphDB is a global database instance which is needed to access the - // channel graph. - GraphDB *graphdb.ChannelGraph + // Graph provides the invoices with information about the current LN + // graph. + Graph GraphSource // ChanStateDB is a possibly replicated db instance which contains the // channel state diff --git a/lnrpc/invoicesrpc/interfaces.go b/lnrpc/invoicesrpc/interfaces.go new file mode 100644 index 0000000000..df47d2f249 --- /dev/null +++ b/lnrpc/invoicesrpc/interfaces.go @@ -0,0 +1,19 @@ +package invoicesrpc + +import ( + "github.com/lightningnetwork/lnd/graph/db/models" +) + +// GraphSource defines the graph interface required by the invoice rpc server. +type GraphSource interface { + // FetchChannelEdgesByID attempts to look up the two directed edges for + // the channel identified by the channel ID. If the channel can't be + // found, then graphdb.ErrEdgeNotFound is returned. + FetchChannelEdgesByID(chanID uint64) (*models.ChannelEdgeInfo, + *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) + + // IsPublicNode is a helper method that determines whether the node with + // the given public key is seen as a public node in the graph from the + // graph's source node's point of view. + IsPublicNode(pubKey [33]byte) (bool, error) +} diff --git a/lnrpc/invoicesrpc/invoices_server.go b/lnrpc/invoicesrpc/invoices_server.go index 8ca02b260d..7b00b9b643 100644 --- a/lnrpc/invoicesrpc/invoices_server.go +++ b/lnrpc/invoicesrpc/invoices_server.go @@ -346,7 +346,7 @@ func (s *Server) AddHoldInvoice(ctx context.Context, NodeSigner: s.cfg.NodeSigner, DefaultCLTVExpiry: s.cfg.DefaultCLTVExpiry, ChanDB: s.cfg.ChanStateDB, - Graph: s.cfg.GraphDB, + Graph: s.cfg.Graph, GenInvoiceFeatures: s.cfg.GenInvoiceFeatures, GenAmpInvoiceFeatures: s.cfg.GenAmpInvoiceFeatures, GetAlias: s.cfg.GetAlias, diff --git a/subrpcserver_config.go b/subrpcserver_config.go index 102e211187..6a7ba2a4d6 100644 --- a/subrpcserver_config.go +++ b/subrpcserver_config.go @@ -262,7 +262,7 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config, subCfgValue.FieldByName("DefaultCLTVExpiry").Set( reflect.ValueOf(defaultDelta), ) - subCfgValue.FieldByName("GraphDB").Set( + subCfgValue.FieldByName("Graph").Set( reflect.ValueOf(graphDB), ) subCfgValue.FieldByName("ChanStateDB").Set(