multi+refactor: create ForEachNodeChannel with no tx param
In prep for a clean Graph DB interface, we add a version of ForEachNodeChannel that does not take in an existing db transaction.
This commit is contained in:
6 files changed
+28
-12
No files matched your search
+1
-1
@@ -89,7 +89,7 @@ func (d *dbNode) Addrs() []net.Addr {
|
|||||||
//
|
//
|
||||||
// NOTE: Part of the autopilot.Node interface.
|
// NOTE: Part of the autopilot.Node interface.
|
||||||
func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
||||||
return d.db.ForEachNodeChannel(d.tx, d.node.PubKeyBytes,
|
return d.db.ForEachNodeChannelTx(d.tx, d.node.PubKeyBytes,
|
||||||
func(tx kvdb.RTx, ei *models.ChannelEdgeInfo, ep,
|
func(tx kvdb.RTx, ei *models.ChannelEdgeInfo, ep,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
+21
-5
@@ -565,7 +565,7 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
|||||||
return c.ForEachNode(func(tx kvdb.RTx, node *LightningNode) error {
|
return c.ForEachNode(func(tx kvdb.RTx, node *LightningNode) error {
|
||||||
channels := make(map[uint64]*DirectedChannel)
|
channels := make(map[uint64]*DirectedChannel)
|
||||||
|
|
||||||
err := c.ForEachNodeChannel(tx, node.PubKeyBytes,
|
err := c.ForEachNodeChannelTx(tx, node.PubKeyBytes,
|
||||||
func(tx kvdb.RTx, e *models.ChannelEdgeInfo,
|
func(tx kvdb.RTx, e *models.ChannelEdgeInfo,
|
||||||
p1 *models.ChannelEdgePolicy,
|
p1 *models.ChannelEdgePolicy,
|
||||||
p2 *models.ChannelEdgePolicy) error {
|
p2 *models.ChannelEdgePolicy) error {
|
||||||
@@ -2931,7 +2931,7 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
|
|||||||
// used to terminate the check early.
|
// used to terminate the check early.
|
||||||
nodeIsPublic := false
|
nodeIsPublic := false
|
||||||
errDone := errors.New("done")
|
errDone := errors.New("done")
|
||||||
err := c.ForEachNodeChannel(tx, nodePub, func(tx kvdb.RTx,
|
err := c.ForEachNodeChannelTx(tx, nodePub, func(tx kvdb.RTx,
|
||||||
info *models.ChannelEdgeInfo, _ *models.ChannelEdgePolicy,
|
info *models.ChannelEdgeInfo, _ *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -3224,13 +3224,29 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
|||||||
// halted with the error propagated back up to the caller.
|
// halted with the error propagated back up to the caller.
|
||||||
//
|
//
|
||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
|
func (c *ChannelGraph) ForEachNodeChannel(nodePub route.Vertex,
|
||||||
|
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
|
return nodeTraversal(nil, nodePub[:], c.db, cb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ForEachNodeChannelTx iterates through all channels of the given node,
|
||||||
|
// executing the passed callback with an edge info structure and the policies
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Unknown policies are passed into the callback as nil values.
|
||||||
//
|
//
|
||||||
// If the caller wishes to re-use an existing boltdb transaction, then it
|
// If the caller wishes to re-use an existing boltdb transaction, then it
|
||||||
// should be passed as the first argument. Otherwise the first argument should
|
// should be passed as the first argument. Otherwise, the first argument should
|
||||||
// be nil and a fresh transaction will be created to execute the graph
|
// be nil and a fresh transaction will be created to execute the graph
|
||||||
// traversal.
|
// traversal.
|
||||||
func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, nodePub route.Vertex,
|
func (c *ChannelGraph) ForEachNodeChannelTx(tx kvdb.RTx,
|
||||||
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
nodePub route.Vertex, cb func(kvdb.RTx, *models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return nodeTraversal(tx, nodePub[:], c.db, cb)
|
return nodeTraversal(tx, nodePub[:], c.db, cb)
|
||||||
|
|||||||
@@ -1055,7 +1055,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// outgoing channels for a particular node.
|
// outgoing channels for a particular node.
|
||||||
numNodeChans := 0
|
numNodeChans := 0
|
||||||
firstNode, secondNode := nodeList[0], nodeList[1]
|
firstNode, secondNode := nodeList[0], nodeList[1]
|
||||||
err = graph.ForEachNodeChannel(nil, firstNode.PubKeyBytes,
|
err = graph.ForEachNodeChannel(firstNode.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *models.ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -2737,7 +2737,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
|||||||
// Ensure that channel is reported with unknown policies.
|
// Ensure that channel is reported with unknown policies.
|
||||||
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
||||||
calls := 0
|
calls := 0
|
||||||
err := graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
err := graph.ForEachNodeChannel(node.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *models.ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2937,7 +2937,7 @@ func (r *ChannelRouter) ForEachNode(
|
|||||||
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
||||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return r.cfg.Graph.ForEachNodeChannel(nil, r.cfg.SelfNode,
|
return r.cfg.Graph.ForEachNodeChannel(r.cfg.SelfNode,
|
||||||
func(tx kvdb.RTx, c *models.ChannelEdgeInfo,
|
func(tx kvdb.RTx, c *models.ChannelEdgeInfo,
|
||||||
e *models.ChannelEdgePolicy,
|
e *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|||||||
+2
-2
@@ -6361,7 +6361,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
channels []*lnrpc.ChannelEdge
|
channels []*lnrpc.ChannelEdge
|
||||||
)
|
)
|
||||||
|
|
||||||
err = graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
err = graph.ForEachNodeChannel(node.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, edge *models.ChannelEdgeInfo,
|
func(_ kvdb.RTx, edge *models.ChannelEdgeInfo,
|
||||||
c1, c2 *models.ChannelEdgePolicy) error {
|
c1, c2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -7014,7 +7014,7 @@ func (r *rpcServer) FeeReport(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var feeReports []*lnrpc.ChannelFeeReport
|
var feeReports []*lnrpc.ChannelFeeReport
|
||||||
err = channelGraph.ForEachNodeChannel(nil, selfNode.PubKeyBytes,
|
err = channelGraph.ForEachNodeChannel(selfNode.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, chanInfo *models.ChannelEdgeInfo,
|
func(_ kvdb.RTx, chanInfo *models.ChannelEdgeInfo,
|
||||||
edgePolicy, _ *models.ChannelEdgePolicy) error {
|
edgePolicy, _ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
@@ -3119,7 +3119,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
// TODO(roasbeef): instead iterate over link nodes and query graph for
|
// TODO(roasbeef): instead iterate over link nodes and query graph for
|
||||||
// each of the nodes.
|
// each of the nodes.
|
||||||
selfPub := s.identityECDH.PubKey().SerializeCompressed()
|
selfPub := s.identityECDH.PubKey().SerializeCompressed()
|
||||||
err = s.graphDB.ForEachNodeChannel(nil, sourceNode.PubKeyBytes, func(
|
err = s.graphDB.ForEachNodeChannel(sourceNode.PubKeyBytes, func(
|
||||||
tx kvdb.RTx,
|
tx kvdb.RTx,
|
||||||
chanInfo *models.ChannelEdgeInfo,
|
chanInfo *models.ChannelEdgeInfo,
|
||||||
policy, _ *models.ChannelEdgePolicy) error {
|
policy, _ *models.ChannelEdgePolicy) error {
|
||||||
|
|||||||
Reference in new issue
Block a user