Skip to content

Commit 54f895c

Browse files
committed
lntest: make sure standby nodes' edges are cleaned
1 parent 7f939c8 commit 54f895c

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

lntest/harness.go

+12
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,18 @@ func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error {
909909
"delete all of them properly", hn.Name())
910910
}
911911

912+
// The number of public edges should be zero.
913+
if hn.State.Edge.Public != 0 {
914+
return fmt.Errorf("%s: found active public egdes, please "+
915+
"clean them properly", hn.Name())
916+
}
917+
918+
// The number of edges should be zero.
919+
if hn.State.Edge.Total != 0 {
920+
return fmt.Errorf("%s: found active edges, please "+
921+
"clean them properly", hn.Name())
922+
}
923+
912924
return nil
913925
}
914926

lntest/harness_assertion.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/btcsuite/btcd/txscript"
2020
"github.com/btcsuite/btcd/wire"
2121
"github.com/lightningnetwork/lnd/channeldb"
22+
"github.com/lightningnetwork/lnd/fn"
2223
"github.com/lightningnetwork/lnd/lnrpc"
2324
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
2425
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@@ -251,19 +252,33 @@ func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode,
251252
old = hn.State.Edge.Total
252253
}
253254

255+
// filterDisabled is a helper closure that filters out disabled
256+
// channels.
257+
filterDisabled := func(edge *lnrpc.ChannelEdge) bool {
258+
if edge.Node1Policy.Disabled {
259+
return false
260+
}
261+
if edge.Node2Policy.Disabled {
262+
return false
263+
}
264+
265+
return true
266+
}
267+
254268
err := wait.NoError(func() error {
255269
req := &lnrpc.ChannelGraphRequest{
256270
IncludeUnannounced: includeUnannounced,
257271
}
258-
chanGraph := hn.RPC.DescribeGraph(req)
259-
total := len(chanGraph.Edges)
272+
resp := hn.RPC.DescribeGraph(req)
273+
activeEdges := fn.Filter(filterDisabled, resp.Edges)
274+
total := len(activeEdges)
260275

261276
if total-old == expected {
262277
if expected != 0 {
263278
// NOTE: assume edges come in ascending order
264279
// that the old edges are at the front of the
265280
// slice.
266-
edges = chanGraph.Edges[old:]
281+
edges = activeEdges[old:]
267282
}
268283

269284
return nil

lntest/node/state.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/btcsuite/btcd/wire"
10+
"github.com/lightningnetwork/lnd/fn"
1011
"github.com/lightningnetwork/lnd/lnrpc"
1112
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
1213
"github.com/lightningnetwork/lnd/lntest/rpc"
@@ -308,13 +309,26 @@ func (s *State) updateUTXOStats() {
308309

309310
// updateEdgeStats counts the total edges.
310311
func (s *State) updateEdgeStats() {
312+
// filterDisabled is a helper closure that filters out disabled
313+
// channels.
314+
filterDisabled := func(edge *lnrpc.ChannelEdge) bool {
315+
if edge.Node1Policy.Disabled {
316+
return false
317+
}
318+
if edge.Node2Policy.Disabled {
319+
return false
320+
}
321+
322+
return true
323+
}
324+
311325
req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
312326
resp := s.rpc.DescribeGraph(req)
313-
s.Edge.Total = len(resp.Edges)
327+
s.Edge.Total = len(fn.Filter(filterDisabled, resp.Edges))
314328

315329
req = &lnrpc.ChannelGraphRequest{IncludeUnannounced: false}
316330
resp = s.rpc.DescribeGraph(req)
317-
s.Edge.Public = len(resp.Edges)
331+
s.Edge.Public = len(fn.Filter(filterDisabled, resp.Edges))
318332
}
319333

320334
// updateWalletBalance creates stats for the node's wallet balance.

0 commit comments

Comments
 (0)