lntest: make sure standby nodes' edges are cleaned

This commit is contained in:
yyforyongyu
2024-10-24 18:24:38 +08:00
parent e7d0754615
commit a745d74e7c
3 changed files with 46 additions and 5 deletions

View File

@@ -909,6 +909,18 @@ func (h *HarnessTest) validateNodeState(hn *node.HarnessNode) error {
"delete all of them properly", hn.Name()) "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 return nil
} }

View File

@@ -19,6 +19,7 @@ import (
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@@ -251,19 +252,33 @@ func (h *HarnessTest) AssertNumEdges(hn *node.HarnessNode,
old = hn.State.Edge.Total 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 { err := wait.NoError(func() error {
req := &lnrpc.ChannelGraphRequest{ req := &lnrpc.ChannelGraphRequest{
IncludeUnannounced: includeUnannounced, IncludeUnannounced: includeUnannounced,
} }
chanGraph := hn.RPC.DescribeGraph(req) resp := hn.RPC.DescribeGraph(req)
total := len(chanGraph.Edges) activeEdges := fn.Filter(filterDisabled, resp.Edges)
total := len(activeEdges)
if total-old == expected { if total-old == expected {
if expected != 0 { if expected != 0 {
// NOTE: assume edges come in ascending order // NOTE: assume edges come in ascending order
// that the old edges are at the front of the // that the old edges are at the front of the
// slice. // slice.
edges = chanGraph.Edges[old:] edges = activeEdges[old:]
} }
return nil return nil

View File

@@ -7,6 +7,7 @@ import (
"time" "time"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc" "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest/rpc" "github.com/lightningnetwork/lnd/lntest/rpc"
@@ -308,13 +309,26 @@ func (s *State) updateUTXOStats() {
// updateEdgeStats counts the total edges. // updateEdgeStats counts the total edges.
func (s *State) updateEdgeStats() { 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} req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
resp := s.rpc.DescribeGraph(req) 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} req = &lnrpc.ChannelGraphRequest{IncludeUnannounced: false}
resp = s.rpc.DescribeGraph(req) 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. // updateWalletBalance creates stats for the node's wallet balance.