graph/db+autopilot: remove NodeRTx FetchNode method
In this commit, we remove the need for the NodeRTx interface to have the FetchNode method on it.
This commit is contained in:
5 files changed
+1
-55
No files matched your search
+1
-6
@@ -98,15 +98,10 @@ func (d *dbNode) ForEachChannel(ctx context.Context,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
node, err := d.tx.FetchNode(ep.ToNode)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
edge := ChannelEdge{
|
edge := ChannelEdge{
|
||||||
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
|
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
|
||||||
Capacity: ei.Capacity,
|
Capacity: ei.Capacity,
|
||||||
Peer: node.Node().PubKeyBytes,
|
Peer: ep.ToNode,
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(ctx, edge)
|
return cb(ctx, edge)
|
||||||
|
|||||||
@@ -742,16 +742,4 @@ func (t *testNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testNodeTx) FetchNode(pub route.Vertex) (graphdb.NodeRTx, error) {
|
|
||||||
node, err := t.db.db.FetchLightningNode(context.Background(), pub)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &testNodeTx{
|
|
||||||
db: t.db,
|
|
||||||
node: node,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ graphdb.NodeRTx = (*testNodeTx)(nil)
|
var _ graphdb.NodeRTx = (*testNodeTx)(nil)
|
||||||
@@ -25,12 +25,6 @@ type NodeRTx interface {
|
|||||||
// the same transaction used to fetch the node.
|
// the same transaction used to fetch the node.
|
||||||
ForEachChannel(func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
ForEachChannel(func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error
|
*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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeTraverser is an abstract read only interface that provides information
|
// NodeTraverser is an abstract read only interface that provides information
|
||||||
|
|||||||
@@ -4902,20 +4902,6 @@ func (c *chanGraphNodeTx) Node() *models.LightningNode {
|
|||||||
return c.node
|
return c.node
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
// NOTE: This is a part of the NodeRTx interface.
|
|
||||||
func (c *chanGraphNodeTx) FetchNode(nodePub route.Vertex) (NodeRTx, error) {
|
|
||||||
node, err := c.db.FetchLightningNodeTx(c.tx, nodePub)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return newChanGraphNodeTx(c.tx, c.db, node), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ForEachChannel can be used to iterate over the node's channels under
|
// ForEachChannel can be used to iterate over the node's channels under
|
||||||
// the same transaction used to fetch the node.
|
// the same transaction used to fetch the node.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -865,23 +865,6 @@ func (s *sqlGraphNodeTx) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
|||||||
return forEachNodeChannel(ctx, s.db, s.cfg, s.id, cb)
|
return forEachNodeChannel(ctx, s.db, s.cfg, s.id, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
// NOTE: This is a part of the NodeRTx interface.
|
|
||||||
func (s *sqlGraphNodeTx) FetchNode(nodePub route.Vertex) (NodeRTx, error) {
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
id, node, err := getNodeByPubKey(ctx, s.db, nodePub)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("unable to fetch V1 node(%x): %w",
|
|
||||||
nodePub, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return newSQLGraphNodeTx(s.db, s.cfg, id, node), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ForEachNodeDirectedChannel iterates through all channels of a given node,
|
// ForEachNodeDirectedChannel iterates through all channels of a given node,
|
||||||
// executing the passed callback on the directed edge representing the channel
|
// executing the passed callback on the directed edge representing the channel
|
||||||
// and its incoming policy. If the callback returns an error, then the iteration
|
// and its incoming policy. If the callback returns an error, then the iteration
|
||||||
|
|||||||
Reference in new issue
Block a user