Skip to content

Commit

Permalink
invoicesrpc: remove direct access to ChannelGraph pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Feb 13, 2025
1 parent 9c2c95d commit 02e6628
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
5 changes: 3 additions & 2 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 3 additions & 3 deletions lnrpc/invoicesrpc/addinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions lnrpc/invoicesrpc/config_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions lnrpc/invoicesrpc/interfaces.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion lnrpc/invoicesrpc/invoices_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion subrpcserver_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 02e6628

Please sign in to comment.