graph/db: remove NodeRTx ForEachChannel method
This commit is contained in:
4 files changed
+10
-48
No files matched your search
@@ -20,11 +20,6 @@ import (
|
|||||||
type NodeRTx interface {
|
type NodeRTx interface {
|
||||||
// Node returns the raw information of the node.
|
// Node returns the raw information of the node.
|
||||||
Node() *models.LightningNode
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeTraverser is an abstract read only interface that provides information
|
// NodeTraverser is an abstract read only interface that provides information
|
||||||
|
|||||||
@@ -4906,24 +4906,3 @@ func newChanGraphNodeTx(tx kvdb.RTx, db *KVStore,
|
|||||||
func (c *chanGraphNodeTx) Node() *models.LightningNode {
|
func (c *chanGraphNodeTx) Node() *models.LightningNode {
|
||||||
return c.node
|
return c.node
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForEachChannel can be used to iterate over the node's channels under
|
|
||||||
// the same transaction used to fetch the node.
|
|
||||||
//
|
|
||||||
// NOTE: This is a part of the NodeRTx interface.
|
|
||||||
func (c *chanGraphNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
|
|
||||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
|
||||||
|
|
||||||
return c.db.forEachNodeChannelTx(
|
|
||||||
c.tx, c.node.PubKeyBytes,
|
|
||||||
func(_ kvdb.RTx, info *models.ChannelEdgeInfo, policy1,
|
|
||||||
policy2 *models.ChannelEdgePolicy) error {
|
|
||||||
|
|
||||||
return f(info, policy1, policy2)
|
|
||||||
},
|
|
||||||
// NOTE: We don't need to reset anything here as the caller is
|
|
||||||
// expected to pass in the reset function to the ForEachNode
|
|
||||||
// method that constructed the chanGraphNodeTx.
|
|
||||||
func() {},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -853,18 +853,6 @@ func (s *sqlGraphNodeTx) Node() *models.LightningNode {
|
|||||||
return s.node
|
return s.node
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForEachChannel can be used to iterate over the node's channels under the same
|
|
||||||
// transaction used to fetch the node.
|
|
||||||
//
|
|
||||||
// NOTE: This is a part of the NodeRTx interface.
|
|
||||||
func (s *sqlGraphNodeTx) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
|
||||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
return forEachNodeChannel(ctx, s.db, s.cfg, s.id, cb)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
@@ -3,12 +3,13 @@ package itest
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd"
|
"github.com/lightningnetwork/lnd"
|
||||||
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
graphdb "github.com/lightningnetwork/lnd/graph/db"
|
||||||
"github.com/lightningnetwork/lnd/graph/db/models"
|
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/node"
|
"github.com/lightningnetwork/lnd/lntest/node"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/sqldb"
|
"github.com/lightningnetwork/lnd/sqldb"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -69,19 +70,18 @@ func testGraphMigration(ht *lntest.HarnessTest) {
|
|||||||
numNodes int
|
numNodes int
|
||||||
edges = make(map[uint64]bool)
|
edges = make(map[uint64]bool)
|
||||||
)
|
)
|
||||||
err := db.ForEachNode(ctx, func(tx graphdb.NodeRTx) error {
|
err := db.ForEachNodeCached(ctx, false, func(_ context.Context,
|
||||||
|
_ route.Vertex, _ []net.Addr,
|
||||||
|
chans map[uint64]*graphdb.DirectedChannel) error {
|
||||||
|
|
||||||
numNodes++
|
numNodes++
|
||||||
|
|
||||||
// For each node, also count the number of edges.
|
// For each node, also count the number of edges.
|
||||||
return tx.ForEachChannel(
|
for _, ch := range chans {
|
||||||
func(info *models.ChannelEdgeInfo,
|
edges[ch.ChannelID] = true
|
||||||
_ *models.ChannelEdgePolicy,
|
}
|
||||||
_ *models.ChannelEdgePolicy) error {
|
|
||||||
|
|
||||||
edges[info.ChannelID] = true
|
return nil
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}, func() {
|
}, func() {
|
||||||
clear(edges)
|
clear(edges)
|
||||||
numNodes = 0
|
numNodes = 0
|
||||||
|
|||||||
Reference in new issue
Block a user