mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
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.
25 lines
995 B
Go
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)
|
|
}
|