mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 01:33:02 +01:00
Merge pull request #9420 from yyforyongyu/assert-channel-graph
itest+lntest: make sure to assert edge in both graph db and cache
This commit is contained in:
commit
e0a920af44
@ -660,18 +660,27 @@ func testUpdateNodeAnnouncement(ht *lntest.HarnessTest) {
|
||||
func assertSyncType(ht *lntest.HarnessTest, hn *node.HarnessNode,
|
||||
peer string, syncType lnrpc.Peer_SyncType) {
|
||||
|
||||
resp := hn.RPC.ListPeers()
|
||||
for _, rpcPeer := range resp.Peers {
|
||||
if rpcPeer.PubKey != peer {
|
||||
continue
|
||||
err := wait.NoError(func() error {
|
||||
resp := hn.RPC.ListPeers()
|
||||
|
||||
for _, rpcPeer := range resp.Peers {
|
||||
if rpcPeer.PubKey != peer {
|
||||
continue
|
||||
}
|
||||
|
||||
// Exit early if the sync type is matched.
|
||||
if syncType == rpcPeer.SyncType {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("sync type: want %v got %v", syncType,
|
||||
rpcPeer.SyncType)
|
||||
}
|
||||
|
||||
require.Equal(ht, syncType, rpcPeer.SyncType)
|
||||
return fmt.Errorf("unable to find peer: %s", peer)
|
||||
}, defaultTimeout)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ht.Fatalf("unable to find peer: %s", peer)
|
||||
require.NoError(ht, err, "%s: timeout checking sync type", hn.Name())
|
||||
}
|
||||
|
||||
// compareNodeAnns compares that two node announcements match or returns an
|
||||
|
@ -1588,7 +1588,8 @@ func testLocalClaimIncomingHTLCSimpleTaprootZeroConf(ht *lntest.HarnessTest) {
|
||||
Private: true,
|
||||
}
|
||||
|
||||
// Prepare Carol's node config to enable zero-conf and leased channel.
|
||||
// Prepare Carol's node config to enable zero-conf and simple taproot
|
||||
// channel.
|
||||
cfg := node.CfgSimpleTaproot
|
||||
cfg = append(cfg, node.CfgZeroConf...)
|
||||
cfgs := [][]string{cfg, cfg, cfg}
|
||||
|
@ -1838,8 +1838,8 @@ func (h *HarnessTest) AssertNotInGraph(hn *node.HarnessNode, chanID uint64) {
|
||||
"found in graph")
|
||||
}
|
||||
|
||||
// AssertChannelInGraph asserts that a given channel is found in the graph.
|
||||
func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
|
||||
// AssertChannelInGraphDB asserts that a given channel is found in the graph db.
|
||||
func (h *HarnessTest) AssertChannelInGraphDB(hn *node.HarnessNode,
|
||||
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
|
||||
|
||||
ctxt, cancel := context.WithCancel(h.runCtx)
|
||||
@ -1875,12 +1875,72 @@ func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
|
||||
|
||||
return nil
|
||||
}, DefaultTimeout)
|
||||
|
||||
require.NoError(h, err, "%s: timeout finding channel in graph",
|
||||
hn.Name())
|
||||
|
||||
return edge
|
||||
}
|
||||
|
||||
// AssertChannelInGraphCache asserts a given channel is found in the graph
|
||||
// cache.
|
||||
func (h *HarnessTest) AssertChannelInGraphCache(hn *node.HarnessNode,
|
||||
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
|
||||
|
||||
var edge *lnrpc.ChannelEdge
|
||||
|
||||
req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
|
||||
cpStr := channelPointStr(chanPoint)
|
||||
|
||||
err := wait.NoError(func() error {
|
||||
chanGraph := hn.RPC.DescribeGraph(req)
|
||||
|
||||
// Iterate all the known edges, and make sure the edge policies
|
||||
// are populated when a matched edge is found.
|
||||
for _, e := range chanGraph.Edges {
|
||||
if e.ChanPoint != cpStr {
|
||||
continue
|
||||
}
|
||||
|
||||
if e.Node1Policy == nil {
|
||||
return fmt.Errorf("no policy for node1 %v",
|
||||
e.Node1Pub)
|
||||
}
|
||||
|
||||
if e.Node2Policy == nil {
|
||||
return fmt.Errorf("no policy for node2 %v",
|
||||
e.Node1Pub)
|
||||
}
|
||||
|
||||
edge = e
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// If we've iterated over all the known edges and we weren't
|
||||
// able to find this specific one, then we'll fail.
|
||||
return fmt.Errorf("no edge found for channel point: %s", cpStr)
|
||||
}, DefaultTimeout)
|
||||
|
||||
require.NoError(h, err, "%s: timeout finding channel %v in graph cache",
|
||||
cpStr, hn.Name())
|
||||
|
||||
return edge
|
||||
}
|
||||
|
||||
// AssertChannelInGraphDB asserts that a given channel is found both in the
|
||||
// graph db (GetChanInfo) and the graph cache (DescribeGraph).
|
||||
func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
|
||||
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
|
||||
|
||||
// Make sure the channel is found in the db first.
|
||||
h.AssertChannelInGraphDB(hn, chanPoint)
|
||||
|
||||
// Assert the channel is also found in the graph cache, which refreshes
|
||||
// every `--caches.rpc-graph-cache-duration`.
|
||||
return h.AssertChannelInGraphCache(hn, chanPoint)
|
||||
}
|
||||
|
||||
// AssertTxAtHeight gets all of the transactions that a node's wallet has a
|
||||
// record of at the target height, and finds and returns the tx with the target
|
||||
// txid, failing if it is not found.
|
||||
|
Loading…
x
Reference in New Issue
Block a user