diff --git a/lntest/harness.go b/lntest/harness.go index c68c3ad08..fd35b84d4 100644 --- a/lntest/harness.go +++ b/lntest/harness.go @@ -909,6 +909,18 @@ func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error { "delete all of them properly", hn.Name()) } + // The number of public edges should be zero. + if hn.State.Edge.Public != 0 { + return fmt.Errorf("%s: found active public egdes, please "+ + "clean them properly", hn.Name()) + } + + // The number of edges should be zero. + if hn.State.Edge.Total != 0 { + return fmt.Errorf("%s: found active edges, please "+ + "clean them properly", hn.Name()) + } + return nil } diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index d56e70703..d6c739177 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -19,6 +19,7 @@ import ( "github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc" @@ -251,19 +252,33 @@ func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode, old = hn.State.Edge.Total } + // filterDisabled is a helper closure that filters out disabled + // channels. + filterDisabled := func(edge *lnrpc.ChannelEdge) bool { + if edge.Node1Policy.Disabled { + return false + } + if edge.Node2Policy.Disabled { + return false + } + + return true + } + err := wait.NoError(func() error { req := &lnrpc.ChannelGraphRequest{ IncludeUnannounced: includeUnannounced, } - chanGraph := hn.RPC.DescribeGraph(req) - total := len(chanGraph.Edges) + resp := hn.RPC.DescribeGraph(req) + activeEdges := fn.Filter(filterDisabled, resp.Edges) + total := len(activeEdges) if total-old == expected { if expected != 0 { // NOTE: assume edges come in ascending order // that the old edges are at the front of the // slice. - edges = chanGraph.Edges[old:] + edges = activeEdges[old:] } return nil diff --git a/lntest/node/state.go b/lntest/node/state.go index bab178bd0..6b9446240 100644 --- a/lntest/node/state.go +++ b/lntest/node/state.go @@ -7,6 +7,7 @@ import ( "time" "github.com/btcsuite/btcd/wire" + "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lntest/rpc" @@ -308,13 +309,26 @@ func (s *State) updateUTXOStats() { // updateEdgeStats counts the total edges. func (s *State) updateEdgeStats() { + // filterDisabled is a helper closure that filters out disabled + // channels. + filterDisabled := func(edge *lnrpc.ChannelEdge) bool { + if edge.Node1Policy.Disabled { + return false + } + if edge.Node2Policy.Disabled { + return false + } + + return true + } + req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true} resp := s.rpc.DescribeGraph(req) - s.Edge.Total = len(resp.Edges) + s.Edge.Total = len(fn.Filter(filterDisabled, resp.Edges)) req = &lnrpc.ChannelGraphRequest{IncludeUnannounced: false} resp = s.rpc.DescribeGraph(req) - s.Edge.Public = len(resp.Edges) + s.Edge.Public = len(fn.Filter(filterDisabled, resp.Edges)) } // updateWalletBalance creates stats for the node's wallet balance.