Skip to content

Commit ece157b

Browse files
committed
graph/db: implement ForEachNodeChannel
Which lets us then run `TestIncompleteChannelPolicies` and `BenchmarkForEachChannel` against our SQL backends.
1 parent 0607982 commit ece157b

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ circuit. The indices are only available for forwarding events saved after v0.20.
7777
* [2](https://github.com/lightningnetwork/lnd/pull/9869)
7878
* [3](https://github.com/lightningnetwork/lnd/pull/9887)
7979
* [4](https://github.com/lightningnetwork/lnd/pull/9931)
80+
* [5](https://github.com/lightningnetwork/lnd/pull/9935)
8081

8182
## RPC Updates
8283

graph/db/graph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
30413041
t.Parallel()
30423042
ctx := context.Background()
30433043

3044-
graph := MakeTestGraph(t)
3044+
graph := MakeTestGraphNew(t)
30453045

30463046
// Create two nodes.
30473047
node1 := createTestVertex(t)
@@ -4110,7 +4110,7 @@ func TestBatchedUpdateEdgePolicy(t *testing.T) {
41104110
// BenchmarkForEachChannel is a benchmark test that measures the number of
41114111
// allocations and the total memory consumed by the full graph traversal.
41124112
func BenchmarkForEachChannel(b *testing.B) {
4113-
graph := MakeTestGraph(b)
4113+
graph := MakeTestGraphNew(b)
41144114

41154115
const numNodes = 100
41164116
const numChannels = 4

graph/db/sql_store.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,41 @@ func (s *SQLStore) ForEachNodeCacheable(cb func(route.Vertex,
895895
return nil
896896
}
897897

898+
// ForEachNodeChannel iterates through all channels of the given node,
899+
// executing the passed callback with an edge info structure and the policies
900+
// of each end of the channel. The first edge policy is the outgoing edge *to*
901+
// the connecting node, while the second is the incoming edge *from* the
902+
// connecting node. If the callback returns an error, then the iteration is
903+
// halted with the error propagated back up to the caller.
904+
//
905+
// Unknown policies are passed into the callback as nil values.
906+
//
907+
// NOTE: part of the V1Store interface.
908+
func (s *SQLStore) ForEachNodeChannel(nodePub route.Vertex,
909+
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
910+
*models.ChannelEdgePolicy) error) error {
911+
912+
var ctx = context.TODO()
913+
914+
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
915+
dbNode, err := db.GetNodeByPubKey(
916+
ctx, sqlc.GetNodeByPubKeyParams{
917+
Version: int16(ProtocolV1),
918+
PubKey: nodePub[:],
919+
},
920+
)
921+
if errors.Is(err, sql.ErrNoRows) {
922+
return nil
923+
} else if err != nil {
924+
return fmt.Errorf("unable to fetch node: %w", err)
925+
}
926+
927+
return forEachNodeChannel(
928+
ctx, db, s.cfg.ChainHash, dbNode.ID, cb,
929+
)
930+
}, sqldb.NoOpReset)
931+
}
932+
898933
// forEachNodeDirectedChannel iterates through all channels of a given
899934
// node, executing the passed callback on the directed edge representing the
900935
// channel and its incoming policy. If the node is not found, no error is

0 commit comments

Comments
 (0)