Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoicesrpc: remove direct access to ChannelGraph pointer #9516

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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](https://github.com/lightningnetwork/lnd/pull/9516)

* [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
Loading