multi: remove kvdb.RTx from ForEachNodeChannel

Since we have not removed all call-sites that make use of this
parameter, we can remove it. This helps hide DB-specific details from
the interface we will introduce for the graph store.
This commit is contained in:
Elle Mouton 2025-03-26 17:28:10 +02:00
parent 14ce1ffe0e
commit 302a1342dd
No known key found for this signature in database
GPG Key ID: D7D916376026F177
7 changed files with 18 additions and 20 deletions

View File

@ -736,7 +736,7 @@ func (t *testNodeTx) Node() *models.LightningNode {
func (t *testNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo, func (t *testNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error { *models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
return t.db.db.ForEachNodeChannel(t.node.PubKeyBytes, func(_ kvdb.RTx, return t.db.db.ForEachNodeChannel(t.node.PubKeyBytes, func(
edge *models.ChannelEdgeInfo, policy1, edge *models.ChannelEdgeInfo, policy1,
policy2 *models.ChannelEdgePolicy) error { policy2 *models.ChannelEdgePolicy) error {

View File

@ -13,7 +13,6 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/chainntnfs"
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/graph/db/models"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnutils" "github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
@ -1276,8 +1275,7 @@ func (b *Builder) ForAllOutgoingChannels(cb func(*models.ChannelEdgeInfo,
*models.ChannelEdgePolicy) error) error { *models.ChannelEdgePolicy) error) error {
return b.cfg.Graph.ForEachNodeChannel(b.cfg.SelfNode, return b.cfg.Graph.ForEachNodeChannel(b.cfg.SelfNode,
func(_ kvdb.RTx, c *models.ChannelEdgeInfo, func(c *models.ChannelEdgeInfo, e *models.ChannelEdgePolicy,
e *models.ChannelEdgePolicy,
_ *models.ChannelEdgePolicy) error { _ *models.ChannelEdgePolicy) error {
if e == nil { if e == nil {

View File

@ -1141,7 +1141,7 @@ func TestGraphTraversal(t *testing.T) {
numNodeChans := 0 numNodeChans := 0
firstNode, secondNode := nodeList[0], nodeList[1] firstNode, secondNode := nodeList[0], nodeList[1]
err = graph.ForEachNodeChannel(firstNode.PubKeyBytes, err = graph.ForEachNodeChannel(firstNode.PubKeyBytes,
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge, func(_ *models.ChannelEdgeInfo, outEdge,
inEdge *models.ChannelEdgePolicy) error { inEdge *models.ChannelEdgePolicy) error {
// All channels between first and second node should // All channels between first and second node should
@ -2882,7 +2882,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
calls := 0 calls := 0
err := graph.ForEachNodeChannel(node.PubKeyBytes, err := graph.ForEachNodeChannel(node.PubKeyBytes,
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge, func(_ *models.ChannelEdgeInfo, outEdge,
inEdge *models.ChannelEdgePolicy) error { inEdge *models.ChannelEdgePolicy) error {
if !expectedOut && outEdge != nil { if !expectedOut && outEdge != nil {
@ -4001,8 +4001,7 @@ func BenchmarkForEachChannel(b *testing.B) {
require.NoError(b, err) require.NoError(b, err)
for _, n := range nodes { for _, n := range nodes {
cb := func(tx kvdb.RTx, cb := func(info *models.ChannelEdgeInfo,
info *models.ChannelEdgeInfo,
policy *models.ChannelEdgePolicy, policy *models.ChannelEdgePolicy,
policy2 *models.ChannelEdgePolicy) error { //nolint:ll policy2 *models.ChannelEdgePolicy) error { //nolint:ll

View File

@ -3103,10 +3103,15 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
// //
// Unknown policies are passed into the callback as nil values. // Unknown policies are passed into the callback as nil values.
func (c *KVStore) ForEachNodeChannel(nodePub route.Vertex, func (c *KVStore) ForEachNodeChannel(nodePub route.Vertex,
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
*models.ChannelEdgePolicy) error) error { *models.ChannelEdgePolicy) error) error {
return nodeTraversal(nil, nodePub[:], c.db, cb) return nodeTraversal(nil, nodePub[:], c.db, func(_ kvdb.RTx,
info *models.ChannelEdgeInfo, policy,
policy2 *models.ChannelEdgePolicy) error {
return cb(info, policy, policy2)
})
} }
// ForEachSourceNodeChannel iterates through all channels of the source node, // ForEachSourceNodeChannel iterates through all channels of the source node,

View File

@ -8,7 +8,6 @@ import (
"github.com/lightningnetwork/lnd/batch" "github.com/lightningnetwork/lnd/batch"
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/graph/db/models"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
) )
@ -254,10 +253,9 @@ type DB interface {
// to the caller. // to the caller.
// //
// Unknown policies are passed into the callback as nil values. // Unknown policies are passed into the callback as nil values.
ForEachNodeChannel(nodePub route.Vertex, cb func(kvdb.RTx, ForEachNodeChannel(nodePub route.Vertex,
*models.ChannelEdgeInfo, cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error
*models.ChannelEdgePolicy) error) error
// AddEdgeProof sets the proof of an existing edge in the graph // AddEdgeProof sets the proof of an existing edge in the graph
// database. // database.

View File

@ -56,7 +56,6 @@ import (
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/labels" "github.com/lightningnetwork/lnd/labels"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
@ -6959,7 +6958,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
) )
err = graph.ForEachNodeChannel(node.PubKeyBytes, err = graph.ForEachNodeChannel(node.PubKeyBytes,
func(_ kvdb.RTx, edge *models.ChannelEdgeInfo, func(edge *models.ChannelEdgeInfo,
c1, c2 *models.ChannelEdgePolicy) error { c1, c2 *models.ChannelEdgePolicy) error {
numChannels++ numChannels++
@ -7641,7 +7640,7 @@ func (r *rpcServer) FeeReport(ctx context.Context,
var feeReports []*lnrpc.ChannelFeeReport var feeReports []*lnrpc.ChannelFeeReport
err = channelGraph.ForEachNodeChannel(selfNode.PubKeyBytes, err = channelGraph.ForEachNodeChannel(selfNode.PubKeyBytes,
func(_ kvdb.RTx, chanInfo *models.ChannelEdgeInfo, func(chanInfo *models.ChannelEdgeInfo,
edgePolicy, _ *models.ChannelEdgePolicy) error { edgePolicy, _ *models.ChannelEdgePolicy) error {
// Self node should always have policies for its // Self node should always have policies for its

View File

@ -51,7 +51,6 @@ import (
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/invoices" "github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/keychain" "github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lncfg" "github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnencrypt" "github.com/lightningnetwork/lnd/lnencrypt"
"github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnpeer"
@ -1212,7 +1211,7 @@ func newServer(_ context.Context, cfg *Config, listenAddrs []net.Addr,
*models.ChannelEdgePolicy) error) error { *models.ChannelEdgePolicy) error) error {
return s.graphDB.ForEachNodeChannel(selfVertex, return s.graphDB.ForEachNodeChannel(selfVertex,
func(_ kvdb.RTx, c *models.ChannelEdgeInfo, func(c *models.ChannelEdgeInfo,
e *models.ChannelEdgePolicy, e *models.ChannelEdgePolicy,
_ *models.ChannelEdgePolicy) error { _ *models.ChannelEdgePolicy) error {