multi: let ForEachNodeChannel take a reset param
This commit is contained in:
13 files changed
+57
-43
No files matched your search
+5
-4
@@ -1276,10 +1276,11 @@ func (b *Builder) FetchLightningNode(ctx context.Context,
|
||||
//
|
||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||
func (b *Builder) ForAllOutgoingChannels(ctx context.Context,
|
||||
cb func(*models.ChannelEdgeInfo,
|
||||
*models.ChannelEdgePolicy) error) error {
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error,
|
||||
reset func()) error {
|
||||
|
||||
return b.cfg.Graph.ForEachNodeChannel(ctx, b.cfg.SelfNode,
|
||||
return b.cfg.Graph.ForEachNodeChannel(
|
||||
ctx, b.cfg.SelfNode,
|
||||
func(c *models.ChannelEdgeInfo, e *models.ChannelEdgePolicy,
|
||||
_ *models.ChannelEdgePolicy) error {
|
||||
|
||||
@@ -1289,7 +1290,7 @@ func (b *Builder) ForAllOutgoingChannels(ctx context.Context,
|
||||
}
|
||||
|
||||
return cb(c, e)
|
||||
},
|
||||
}, reset,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+11
-12
@@ -1394,7 +1394,8 @@ func TestGraphTraversal(t *testing.T) {
|
||||
// outgoing channels for a particular node.
|
||||
numNodeChans := 0
|
||||
firstNode, secondNode := nodeList[0], nodeList[1]
|
||||
err = graph.ForEachNodeChannel(ctx, firstNode.PubKeyBytes,
|
||||
err = graph.ForEachNodeChannel(
|
||||
ctx, firstNode.PubKeyBytes,
|
||||
func(_ *models.ChannelEdgeInfo, outEdge,
|
||||
inEdge *models.ChannelEdgePolicy) error {
|
||||
|
||||
@@ -1425,7 +1426,8 @@ func TestGraphTraversal(t *testing.T) {
|
||||
numNodeChans++
|
||||
|
||||
return nil
|
||||
})
|
||||
}, func() {},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, numChannels, numNodeChans)
|
||||
}
|
||||
@@ -3144,7 +3146,8 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
||||
expectedOut bool) {
|
||||
|
||||
calls := 0
|
||||
err := graph.ForEachNodeChannel(ctx, node.PubKeyBytes,
|
||||
err := graph.ForEachNodeChannel(
|
||||
ctx, node.PubKeyBytes,
|
||||
func(_ *models.ChannelEdgeInfo, outEdge,
|
||||
inEdge *models.ChannelEdgePolicy) error {
|
||||
|
||||
@@ -3167,14 +3170,10 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
||||
calls++
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to scan channels: %v", err)
|
||||
}
|
||||
|
||||
if calls != 1 {
|
||||
t.Fatalf("Expected only one callback call")
|
||||
}
|
||||
}, func() {},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, calls)
|
||||
}
|
||||
|
||||
checkPolicies(node2, false, false)
|
||||
@@ -4248,7 +4247,7 @@ func BenchmarkForEachChannel(b *testing.B) {
|
||||
return nil
|
||||
}
|
||||
|
||||
err := graph.ForEachNodeChannel(ctx, n, cb)
|
||||
err := graph.ForEachNodeChannel(ctx, n, cb, func() {})
|
||||
require.NoError(b, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ type V1Store interface { //nolint:interfacebloat
|
||||
// Unknown policies are passed into the callback as nil values.
|
||||
ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error
|
||||
*models.ChannelEdgePolicy) error, reset func()) error
|
||||
|
||||
// ForEachNodeCached is similar to forEachNode, but it returns
|
||||
// DirectedChannel data to the call-back.
|
||||
|
||||
@@ -406,7 +406,7 @@ func (c *KVStore) AddrsForNode(ctx context.Context,
|
||||
// callback.
|
||||
func (c *KVStore) ForEachChannel(_ context.Context,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
|
||||
return forEachChannel(c.db, cb, reset)
|
||||
}
|
||||
@@ -679,7 +679,7 @@ func (c *KVStore) FetchNodeFeatures(nodePub route.Vertex) (
|
||||
// NOTE: The callback contents MUST not be modified.
|
||||
func (c *KVStore) ForEachNodeCached(_ context.Context,
|
||||
cb func(node route.Vertex,
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
chans map[uint64]*DirectedChannel) error) error {
|
||||
|
||||
reset := func() {}
|
||||
|
||||
@@ -3182,7 +3182,7 @@ func (c *KVStore) HasLightningNode(_ context.Context,
|
||||
// function's View/Update call which will then apply to the whole transaction.
|
||||
func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
||||
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
|
||||
traversal := func(tx kvdb.RTx) error {
|
||||
edges := tx.ReadBucket(edgeBucket)
|
||||
@@ -3271,9 +3271,7 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
||||
// Unknown policies are passed into the callback as nil values.
|
||||
func (c *KVStore) ForEachNodeChannel(_ context.Context, nodePub route.Vertex,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error {
|
||||
|
||||
reset := func() {}
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
|
||||
return nodeTraversal(
|
||||
nil, nodePub[:], c.db, func(_ kvdb.RTx,
|
||||
@@ -3291,7 +3289,7 @@ func (c *KVStore) ForEachNodeChannel(_ context.Context, nodePub route.Vertex,
|
||||
// peer's node information.
|
||||
func (c *KVStore) ForEachSourceNodeChannel(_ context.Context,
|
||||
cb func(chanPoint wire.OutPoint, havePolicy bool,
|
||||
otherNode *models.LightningNode) error, reset func()) error {
|
||||
otherNode *models.LightningNode) error, reset func()) error {
|
||||
|
||||
return kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||
nodes := tx.ReadBucket(nodeBucket)
|
||||
@@ -3341,7 +3339,7 @@ func (c *KVStore) ForEachSourceNodeChannel(_ context.Context,
|
||||
// NOTE: the reset function is only meaningful if the tx param is nil.
|
||||
func (c *KVStore) forEachNodeChannelTx(tx kvdb.RTx,
|
||||
nodePub route.Vertex, cb func(kvdb.RTx, *models.ChannelEdgeInfo,
|
||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error,
|
||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error,
|
||||
reset func()) error {
|
||||
|
||||
return nodeTraversal(tx, nodePub[:], c.db, cb, reset)
|
||||
|
||||
@@ -962,9 +962,7 @@ func (s *SQLStore) ForEachNodeCacheable(ctx context.Context,
|
||||
// NOTE: part of the V1Store interface.
|
||||
func (s *SQLStore) ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error {
|
||||
|
||||
reset := func() {}
|
||||
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||
|
||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||
dbNode, err := db.GetNodeByPubKey(
|
||||
|
||||
+2
-2
@@ -72,7 +72,7 @@ type ChannelGraphSource interface {
|
||||
// star-graph.
|
||||
ForAllOutgoingChannels(ctx context.Context,
|
||||
cb func(c *models.ChannelEdgeInfo,
|
||||
e *models.ChannelEdgePolicy) error) error
|
||||
e *models.ChannelEdgePolicy) error, reset func()) error
|
||||
|
||||
// CurrentBlockHeight returns the block height from POV of the router
|
||||
// subsystem.
|
||||
@@ -260,7 +260,7 @@ type DB interface {
|
||||
// Unknown policies are passed into the callback as nil values.
|
||||
ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error
|
||||
*models.ChannelEdgePolicy) error, reset func()) error
|
||||
|
||||
// AddEdgeProof sets the proof of an existing edge in the graph
|
||||
// database.
|
||||
|
||||
Reference in new issue
Block a user