Skip to content

Commit

Permalink
lntest: make sure standby nodes' edges are cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Nov 7, 2024
1 parent 7f939c8 commit 54f895c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 18 additions & 3 deletions lntest/harness_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions lntest/node/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 54f895c

Please sign in to comment.