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

[2/3] Graph RIP: multi: Graph Source Abstraction #9243

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
488fa3e
graph: remove unused ForEachNode method
ellemouton Nov 8, 2024
9d389ad
graph: let FetchNodeFeatures take an optional read tx
ellemouton Nov 8, 2024
755065b
graph: rename directory from graphsession to session
ellemouton Nov 13, 2024
6c008ff
lnd+graph: add GraphSource interface and implementation
ellemouton Nov 11, 2024
aa24804
graph: add ReadOnlyGraph interface to GraphSource interface
ellemouton Nov 11, 2024
9854bad
graph: add contexts to the ReadOnlyGraph interface
ellemouton Nov 11, 2024
6f3d45f
invoicesrpc: remove invoicerpc server's access to ChannelGraph pointer
ellemouton Nov 11, 2024
237151d
netann+lnd: add netann.ChannelGraph to the GraphSource interface
ellemouton Nov 11, 2024
bfe6262
graph+channeldb: add AddrSource interface to GraphSource
ellemouton Nov 12, 2024
28415f5
graph+lnd: add various calls to GraphSource
ellemouton Nov 12, 2024
0f33d41
discovery: pass contexts to NetworkPeerBootstrapper methods
ellemouton Nov 12, 2024
372883a
lnd+graph: add GraphBootstrapper to the GraphSource interface
ellemouton Nov 12, 2024
8007061
graph+lnd: add NetworkStats to GraphSource interface
ellemouton Nov 12, 2024
f36fbd0
graph+lnd: add BetweennessCentrality to GraphSource interface
ellemouton Nov 12, 2024
2192bf4
lnd+chanbackup: thread contexts through
ellemouton Nov 13, 2024
dcfffd6
invoicesrpc: remove a context.TODO
ellemouton Nov 13, 2024
75b1069
blindedpath: remove a context.TODO
ellemouton Nov 13, 2024
a28102e
netann: remove context.TODO
ellemouton Nov 11, 2024
c5cc6f1
routing: remove context.TODOs
ellemouton Nov 11, 2024
791ac91
remove context.TODOs from tests
ellemouton Nov 11, 2024
15c2161
docs: update release notes
ellemouton Nov 4, 2024
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
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ func (c *Config) ImplementationConfig(
),
WalletConfigBuilder: rpcImpl,
ChainControlBuilder: rpcImpl,
GraphProvider: rpcImpl,
}
}

Expand All @@ -1813,6 +1814,7 @@ func (c *Config) ImplementationConfig(
DatabaseBuilder: NewDefaultDatabaseBuilder(c, ltndLog),
WalletConfigBuilder: defaultImpl,
ChainControlBuilder: defaultImpl,
GraphProvider: defaultImpl,
}
}

Expand Down
24 changes: 24 additions & 0 deletions config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/funding"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/sources"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
Expand Down Expand Up @@ -125,6 +126,14 @@ type ChainControlBuilder interface {
*btcwallet.Config) (*chainreg.ChainControl, func(), error)
}

// GraphProvider is an interface that must be satisfied by any external system
// that wants to provide LND with graph information.
type GraphProvider interface {
// Graph returns the GraphSource that LND will use for read-only graph
// related queries.
Graph(context.Context, *DatabaseInstances) (sources.GraphSource, error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wdyt of calling it GetGraphSource instead?

}

// ImplementationCfg is a struct that holds all configuration items for
// components that can be implemented outside lnd itself.
type ImplementationCfg struct {
Expand Down Expand Up @@ -155,6 +164,10 @@ type ImplementationCfg struct {
// AuxComponents is a set of auxiliary components that can be used by
// lnd for certain custom channel types.
AuxComponents

// GraphProvider is a type that can provide a custom GraphSource for LND
// to use for read-only graph calls.
GraphProvider
}

// AuxComponents is a set of auxiliary components that can be used by lnd for
Expand Down Expand Up @@ -249,6 +262,17 @@ func (d *DefaultWalletImpl) RegisterGrpcSubserver(s *grpc.Server) error {
return nil
}

// Graph returns the GraphSource that LND will use for read-only graph related
// queries. By default, the GraphSource implementation is this LND node's
// backing graphdb.ChannelGraph.
//
// NOTE: this is part of the GraphProvider interface.
func (d *DefaultWalletImpl) Graph(_ context.Context,
dbs *DatabaseInstances) (sources.GraphSource, error) {

return sources.NewDBGSource(dbs.GraphDB), nil
}

// ValidateMacaroon extracts the macaroon from the context's gRPC metadata,
// checks its signature, makes sure all specified permissions for the called
// method are contained within and finally ensures all caveat conditions are
Expand Down
21 changes: 21 additions & 0 deletions graph/sources/chan_graph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sources

import graphdb "github.com/lightningnetwork/lnd/graph/db"

// DBSource is an implementation of the GraphSource interface backed by a local
// persistence layer holding graph related data.
type DBSource struct {
db *graphdb.ChannelGraph
}

// A compile-time check to ensure that sources.DBSource implements the
// GraphSource interface.
var _ GraphSource = (*DBSource)(nil)

// NewDBGSource returns a new instance of the DBSource backed by a
// graphdb.ChannelGraph instance.
func NewDBGSource(db *graphdb.ChannelGraph) *DBSource {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the constructor could also be called NewDBSource. Or if we want the "graph" term in the name the type could also be named DBGraphSource.

return &DBSource{
db: db,
}
}
6 changes: 6 additions & 0 deletions graph/sources/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package sources

// GraphSource defines the read-only graph interface required by LND for graph
// related queries.
type GraphSource interface {
}
7 changes: 6 additions & 1 deletion lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
return mkErr("error deriving node key: %v", err)
}

graphSource, err := implCfg.Graph(ctx, dbs)
if err != nil {
return mkErr("error obtaining graph source: %v", err)
}

if cfg.Tor.StreamIsolation && cfg.Tor.SkipProxyForClearNetTargets {
return errStreamIsolationWithProxySkip
}
Expand Down Expand Up @@ -601,7 +606,7 @@ func Main(cfg *Config, lisCfg ListenerCfg, implCfg *ImplementationCfg,
cfg, cfg.Listeners, dbs, activeChainControl, &idKeyDesc,
activeChainControl.Cfg.WalletUnlockParams.ChansToRestore,
multiAcceptor, torController, tlsManager, leaderElector,
implCfg,
graphSource, implCfg,
)
if err != nil {
return mkErr("unable to create server: %v", err)
Expand Down
8 changes: 7 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/graph/db/models"
graphsession "github.com/lightningnetwork/lnd/graph/session"
"github.com/lightningnetwork/lnd/graph/sources"
"github.com/lightningnetwork/lnd/healthcheck"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
Expand Down Expand Up @@ -261,6 +262,10 @@ type server struct {

graphDB *graphdb.ChannelGraph

// graphSource can be used for any read only graph queries. This may be
// implemented by this LND node or some other external source.
graphSource sources.GraphSource

chanStateDB *channeldb.ChannelStateDB

addrSource channeldb.AddrSource
Expand Down Expand Up @@ -507,7 +512,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
chansToRestore walletunlocker.ChannelsToRecover,
chanPredicate chanacceptor.ChannelAcceptor,
torController *tor.Controller, tlsManager *TLSManager,
leaderElector cluster.LeaderElector,
leaderElector cluster.LeaderElector, graphSource sources.GraphSource,
implCfg *ImplementationCfg) (*server, error) {

var (
Expand Down Expand Up @@ -613,6 +618,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
cfg: cfg,
implCfg: implCfg,
graphDB: dbs.GraphDB,
graphSource: graphSource,
chanStateDB: dbs.ChanStateDB.ChannelStateDB(),
addrSource: addrSource,
miscDB: dbs.ChanStateDB,
Expand Down