Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Nov 15, 2024
1 parent d10f015 commit 21d67c5
Show file tree
Hide file tree
Showing 14 changed files with 1,614 additions and 95 deletions.
11 changes: 11 additions & 0 deletions cmd/multinode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
graphsources "github.com/lightningnetwork/lnd/graph/sources"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/signal"
)

Expand Down Expand Up @@ -82,8 +83,18 @@ func (g *graphProvider) Graph(_ context.Context,
return nil, err
}

getLocalPub := func() (route.Vertex, error) {
node, err := dbs.GraphDB.SourceNode()
if err != nil {
return route.Vertex{}, err
}

return route.NewVertexFromBytes(node.PubKeyBytes[:])
}

return graphsources.NewGraphBackend(
graphsources.NewDBGSource(dbs.GraphDB), graphSource,
getLocalPub,
), nil
}
func graphConfig() *lnd.Config {
Expand Down
14 changes: 13 additions & 1 deletion config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/msgmux"
"github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sqldb"
Expand Down Expand Up @@ -290,7 +291,18 @@ func (d *DefaultWalletImpl) Graph(_ context.Context,

remoteSourceClient := graphrpc.NewRemoteClient(conn, d.cfg.net)

return sources.NewGraphBackend(localSource, remoteSourceClient), nil
getLocalPub := func() (route.Vertex, error) {
node, err := dbs.GraphDB.SourceNode()
if err != nil {
return route.Vertex{}, err
}

return route.NewVertexFromBytes(node.PubKeyBytes[:])
}

return sources.NewGraphBackend(
localSource, remoteSourceClient, getLocalPub,
), nil
}

// connectRPC tries to establish an RPC connection to the given host:port with
Expand Down
11 changes: 7 additions & 4 deletions graph/db/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (c *ChannelGraph) DisabledChannelIDs() ([]uint64, error) {
// ForEachNode iterates through all the stored vertices/nodes in the graph,
// executing the passed callback with each node encountered. If the callback
// returns an error, then the transaction is aborted and the iteration stops
// early.
// early. No error is returned if no nodes are found.
//
// TODO(roasbeef): add iterator interface to allow for memory efficient graph
// traversal when graph gets mega
Expand Down Expand Up @@ -935,6 +935,7 @@ func addLightningNode(tx kvdb.RwTx, node *models.LightningNode) error {
}

// LookupAlias attempts to return the alias as advertised by the target node.
// ErrNodeAliasNotFound is returned if no alias is found.
// TODO(roasbeef): currently assumes that aliases are unique...
func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) {
var alias string
Expand Down Expand Up @@ -3218,7 +3219,8 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
// of each end of the channel. The first edge policy is the outgoing edge *to*
// the connecting node, while the second is the incoming edge *from* the
// connecting node. If the callback returns an error, then the iteration is
// halted with the error propagated back up to the caller.
// halted with the error propagated back up to the caller. No error is returned
// if the node is not found.
//
// Unknown policies are passed into the callback as nil values.
func (c *ChannelGraph) ForEachNodeChannel(nodePub route.Vertex,
Expand Down Expand Up @@ -3406,7 +3408,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (
// for the channel itself is returned as well as two structs that contain the
// routing policies for the channel in either direction.
//
// ErrZombieEdge an be returned if the edge is currently marked as a zombie
// ErrZombieEdge can be returned if the edge is currently marked as a zombie
// within the database. In this case, the ChannelEdgePolicy's will be nil, and
// the ChannelEdgeInfo will only include the public keys of each node.
func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (
Expand Down Expand Up @@ -3510,7 +3512,8 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (

// 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.
// source node's point of view. If this node is unknown, then
// graphdb.ErrGraphNodeNotFound is returned.
func (c *ChannelGraph) IsPublicNode(pubKey [33]byte) (bool, error) {
var nodeIsPublic bool
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
Expand Down
5 changes: 3 additions & 2 deletions graph/session/graph_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type graph interface {
// node, executing the passed callback on the directed edge representing
// the channel and its incoming policy. If the callback returns an
// error, then the iteration is halted with the error propagated back
// up to the caller.
// up to the caller. No error is returned if the node is not found.
//
// Unknown policies are passed into the callback as nil values.
//
Expand All @@ -135,7 +135,8 @@ type graph interface {
cb func(channel *graphdb.DirectedChannel) error) error

// FetchNodeFeatures returns the features of a given node. If no
// features are known for the node, an empty feature vector is returned.
// features are known for the node or if the node itself is unknown,
// an empty feature vector is returned.
//
// NOTE: if a nil tx is provided, then it is expected that the
// implementation create a read only tx.
Expand Down
20 changes: 14 additions & 6 deletions graph/sources/chan_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/autopilot"
"github.com/lightningnetwork/lnd/discovery"
graphdb "github.com/lightningnetwork/lnd/graph/db"
Expand Down Expand Up @@ -106,6 +107,7 @@ func (s *DBSource) FetchChannelEdgesByID(_ context.Context,

// IsPublicNode 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.
// If this node is unknown, then graphdb.ErrGraphNodeNotFound is returned.
//
// NOTE: this is part of the invoicesrpc.GraphSource interface.
func (s *DBSource) IsPublicNode(_ context.Context,
Expand All @@ -115,7 +117,8 @@ func (s *DBSource) IsPublicNode(_ context.Context,
}

// FetchChannelEdgesByOutpoint returns the channel edge info and most recent
// channel edge policies for a given outpoint.
// channel edge policies for a given outpoint. If the channel can't be found,
// then graphdb.ErrEdgeNotFound is returned.
//
// NOTE: this is part of the netann.ChannelGraph interface.
func (s *DBSource) FetchChannelEdgesByOutpoint(_ context.Context,
Expand All @@ -140,20 +143,25 @@ func (s *DBSource) AddrsForNode(ctx context.Context,
// and invokes the passed callback for each edge. If the callback returns an
// error, then the transaction is aborted and the iteration stops early. An
// edge's policy structs may be nil if the ChannelUpdate in question has not yet
// been received for the channel.
// been received for the channel. No error is returned if no channels are found.
//
// NOTE: this is part of the GraphSource interface.
func (s *DBSource) ForEachChannel(_ context.Context,
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
*models.ChannelEdgePolicy) error) error {

return s.db.ForEachChannel(cb)
err := s.db.ForEachChannel(cb)
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
return err
}

return nil
}

// ForEachNode iterates through all the stored vertices/nodes in the graph,
// executing the passed callback with each node encountered. If the callback
// returns an error, then the transaction is aborted and the iteration stops
// early.
// early. No error is returned if no nodes are found.
//
// NOTE: this is part of the GraphSource interface.
func (s *DBSource) ForEachNode(_ context.Context,
Expand All @@ -170,7 +178,7 @@ func (s *DBSource) ForEachNode(_ context.Context,
// target node identity public key. If the node exists in the database, a
// timestamp of when the data for the node was lasted updated is returned along
// with a true boolean. Otherwise, an empty time.Time is returned with a false
// boolean.
// boolean and a nil error.
//
// NOTE: this is part of the GraphSource interface.
func (s *DBSource) HasLightningNode(_ context.Context,
Expand All @@ -195,7 +203,7 @@ func (s *DBSource) LookupAlias(_ context.Context,
// connecting node, while the second is the incoming edge *from* the connecting
// node. If the callback returns an error, then the iteration is halted with the
// error propagated back up to the caller. Unknown policies are passed into the
// callback as nil values.
// callback as nil values. No error is returned if the node is not found.
//
// NOTE: this is part of the GraphSource interface.
func (s *DBSource) ForEachNodeChannel(_ context.Context,
Expand Down
8 changes: 5 additions & 3 deletions graph/sources/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,24 @@ type GraphSource interface {
// callback returns an error, then the transaction is aborted and the
// iteration stops early. An edge's policy structs may be nil if the
// ChannelUpdate in question has not yet been received for the channel.
// No error is returned if no channels are found.
ForEachChannel(ctx context.Context, cb func(*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy,
*models.ChannelEdgePolicy) error) error

// ForEachNode iterates through all the stored vertices/nodes in the
// graph, executing the passed callback with each node encountered. If
// the callback returns an error, then the transaction is aborted and
// the iteration stops early.
// the iteration stops early. No error is returned if no nodes are
// found.
ForEachNode(ctx context.Context,
cb func(*models.LightningNode) error) error

// HasLightningNode determines if the graph has a vertex identified by
// the target node identity public key. If the node exists in the
// database, a timestamp of when the data for the node was lasted
// updated is returned along with a true boolean. Otherwise, an empty
// time.Time is returned with a false boolean.
// time.Time is returned with a false boolean and a nil error.
HasLightningNode(ctx context.Context, nodePub [33]byte) (time.Time,
bool, error)

Expand All @@ -61,7 +63,7 @@ type GraphSource interface {
// incoming edge *from* the connecting node. If the callback returns an
// error, then the iteration is halted with the error propagated back up
// to the caller. Unknown policies are passed into the callback as nil
// values.
// values. No error is returned if the node is not found.
ForEachNodeChannel(ctx context.Context,
nodePub route.Vertex, cb func(*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy,
Expand Down
Loading

0 comments on commit 21d67c5

Please sign in to comment.