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
18 changes: 12 additions & 6 deletions graph/db/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,12 @@ func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
// ForEachNodeDirectedChannel iterates through all channels of a given 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.
// is halted with the error propagated back up to the caller. An optional read
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: commit message graphsessoin => graphsession 🤓

// transaction may be provided. If none is provided, a new one will be created.
//
// Unknown policies are passed into the callback as nil values.
//
// NOTE: this is part of the graphsession.graph interface.
func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
node route.Vertex, cb func(channel *DirectedChannel) error) error {

Expand All @@ -517,7 +520,7 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
toNodeCallback := func() route.Vertex {
return node
}
toNodeFeatures, err := c.FetchNodeFeatures(node)
toNodeFeatures, err := c.FetchNodeFeatures(tx, node)
if err != nil {
return err
}
Expand Down Expand Up @@ -562,16 +565,19 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
}

// FetchNodeFeatures returns the features of a given node. If no features are
// known for the node, an empty feature vector is returned.
func (c *ChannelGraph) FetchNodeFeatures(
// known for the node, an empty feature vector is returned. An optional read
// transaction may be provided. If none is provided, a new one will be created.
//
// NOTE: this is part of the graphsession.graph interface.
func (c *ChannelGraph) FetchNodeFeatures(tx kvdb.RTx,
node route.Vertex) (*lnwire.FeatureVector, error) {

if c.graphCache != nil {
return c.graphCache.GetFeatures(node), nil
}

// Fallback that uses the database.
targetNode, err := c.FetchLightningNode(node)
targetNode, err := c.FetchLightningNodeTx(tx, node)
switch err {
// If the node exists and has features, return them directly.
case nil:
Expand Down Expand Up @@ -618,7 +624,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
return node.PubKeyBytes
}
toNodeFeatures, err := c.FetchNodeFeatures(
node.PubKeyBytes,
tx, node.PubKeyBytes,
)
if err != nil {
return err
Expand Down
8 changes: 6 additions & 2 deletions graph/graphsession/graph_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (g *session) ForEachNodeChannel(nodePub route.Vertex,
func (g *session) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return g.graph.FetchNodeFeatures(nodePub)
return g.graph.FetchNodeFeatures(g.tx, nodePub)
}

// A compile-time check to ensure that *session implements the
Expand Down Expand Up @@ -133,7 +133,11 @@ type graph interface {

// FetchNodeFeatures returns the features of a given node. If no
// features are known for the node, an empty feature vector is returned.
FetchNodeFeatures(node route.Vertex) (*lnwire.FeatureVector, error)
//
// NOTE: if a nil tx is provided, then it is expected that the
// implementation create a read only tx.
FetchNodeFeatures(tx kvdb.RTx, node route.Vertex) (
*lnwire.FeatureVector, error)
}

// A compile-time check to ensure that *channeldb.ChannelGraph implements the
Expand Down
2 changes: 1 addition & 1 deletion routing/integrated_routing_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,5 +400,5 @@ func (g *mockGraphSessionChanDB) ForEachNodeChannel(nodePub route.Vertex,
func (g *mockGraphSessionChanDB) FetchNodeFeatures(nodePub route.Vertex) (
*lnwire.FeatureVector, error) {

return g.graph.FetchNodeFeatures(nodePub)
return g.graph.FetchNodeFeatures(g.tx, nodePub)
}