lnd/graph/db/interfaces.go
Elle Mouton 14cedef58e
graph/db: add NodeRTx interface and implement it
In this commit, a new NodeRTx interface is added which represents
consistent access to a persisted models.LightningNode. The
ForEachChannel method of the interface gives the caller access to the
node's channels under the same read transaction (if any) that was used
to fetch the node in the first place. The FetchNode method returns
another NodeRTx which again will have the same underlying read
transaction.

The main point of this interface is to provide this consistent access
without needing to expose the `kvdb.RTx` type as a method parameter.
This will then make it much easier in future to add new implementations
of this interface that are backed by other databases (or RPC
connections) where the `kvdb.RTx` type does not apply.

We will make use of the new interface in the `autopilot` package in
upcoming commits in order to remove the `autopilot`'s dependence on the
pointer to the `*graphdb.ChannelGraph` which it has today.
2025-02-10 08:23:58 +02:00

25 lines
995 B
Go

package graphdb
import (
"github.com/lightningnetwork/lnd/graph/db/models"
"github.com/lightningnetwork/lnd/routing/route"
)
// NodeRTx represents transaction object with an underlying node associated that
// can be used to make further queries to the graph under the same transaction.
// This is useful for consistency during graph traversal and queries.
type NodeRTx interface {
// Node returns the raw information of the node.
Node() *models.LightningNode
// ForEachChannel can be used to iterate over the node's channels under
// the same transaction used to fetch the node.
ForEachChannel(func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
*models.ChannelEdgePolicy) error) error
// FetchNode fetches the node with the given pub key under the same
// transaction used to fetch the current node. The returned node is also
// a NodeRTx and any operations on that NodeRTx will also be done under
// the same transaction.
FetchNode(node route.Vertex) (NodeRTx, error)
}