Skip to content

Commit e0a920a

Browse files
authored
Merge pull request #9420 from yyforyongyu/assert-channel-graph
itest+lntest: make sure to assert edge in both graph db and cache
2 parents 572784a + faa1f67 commit e0a920a

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

itest/lnd_channel_graph_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -660,18 +660,27 @@ func testUpdateNodeAnnouncement(ht *lntest.HarnessTest) {
660660
func assertSyncType(ht *lntest.HarnessTest, hn *node.HarnessNode,
661661
peer string, syncType lnrpc.Peer_SyncType) {
662662

663-
resp := hn.RPC.ListPeers()
664-
for _, rpcPeer := range resp.Peers {
665-
if rpcPeer.PubKey != peer {
666-
continue
667-
}
663+
err := wait.NoError(func() error {
664+
resp := hn.RPC.ListPeers()
668665

669-
require.Equal(ht, syncType, rpcPeer.SyncType)
666+
for _, rpcPeer := range resp.Peers {
667+
if rpcPeer.PubKey != peer {
668+
continue
669+
}
670670

671-
return
672-
}
671+
// Exit early if the sync type is matched.
672+
if syncType == rpcPeer.SyncType {
673+
return nil
674+
}
675+
676+
return fmt.Errorf("sync type: want %v got %v", syncType,
677+
rpcPeer.SyncType)
678+
}
679+
680+
return fmt.Errorf("unable to find peer: %s", peer)
681+
}, defaultTimeout)
673682

674-
ht.Fatalf("unable to find peer: %s", peer)
683+
require.NoError(ht, err, "%s: timeout checking sync type", hn.Name())
675684
}
676685

677686
// compareNodeAnns compares that two node announcements match or returns an

itest/lnd_multi-hop_force_close_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,8 @@ func testLocalClaimIncomingHTLCSimpleTaprootZeroConf(ht *lntest.HarnessTest) {
15881588
Private: true,
15891589
}
15901590

1591-
// Prepare Carol's node config to enable zero-conf and leased channel.
1591+
// Prepare Carol's node config to enable zero-conf and simple taproot
1592+
// channel.
15921593
cfg := node.CfgSimpleTaproot
15931594
cfg = append(cfg, node.CfgZeroConf...)
15941595
cfgs := [][]string{cfg, cfg, cfg}

lntest/harness_assertion.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,8 +1838,8 @@ func (h *HarnessTest) AssertNotInGraph(hn *node.HarnessNode, chanID uint64) {
18381838
"found in graph")
18391839
}
18401840

1841-
// AssertChannelInGraph asserts that a given channel is found in the graph.
1842-
func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
1841+
// AssertChannelInGraphDB asserts that a given channel is found in the graph db.
1842+
func (h *HarnessTest) AssertChannelInGraphDB(hn *node.HarnessNode,
18431843
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
18441844

18451845
ctxt, cancel := context.WithCancel(h.runCtx)
@@ -1875,12 +1875,72 @@ func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
18751875

18761876
return nil
18771877
}, DefaultTimeout)
1878+
18781879
require.NoError(h, err, "%s: timeout finding channel in graph",
18791880
hn.Name())
18801881

18811882
return edge
18821883
}
18831884

1885+
// AssertChannelInGraphCache asserts a given channel is found in the graph
1886+
// cache.
1887+
func (h *HarnessTest) AssertChannelInGraphCache(hn *node.HarnessNode,
1888+
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
1889+
1890+
var edge *lnrpc.ChannelEdge
1891+
1892+
req := &lnrpc.ChannelGraphRequest{IncludeUnannounced: true}
1893+
cpStr := channelPointStr(chanPoint)
1894+
1895+
err := wait.NoError(func() error {
1896+
chanGraph := hn.RPC.DescribeGraph(req)
1897+
1898+
// Iterate all the known edges, and make sure the edge policies
1899+
// are populated when a matched edge is found.
1900+
for _, e := range chanGraph.Edges {
1901+
if e.ChanPoint != cpStr {
1902+
continue
1903+
}
1904+
1905+
if e.Node1Policy == nil {
1906+
return fmt.Errorf("no policy for node1 %v",
1907+
e.Node1Pub)
1908+
}
1909+
1910+
if e.Node2Policy == nil {
1911+
return fmt.Errorf("no policy for node2 %v",
1912+
e.Node1Pub)
1913+
}
1914+
1915+
edge = e
1916+
1917+
return nil
1918+
}
1919+
1920+
// If we've iterated over all the known edges and we weren't
1921+
// able to find this specific one, then we'll fail.
1922+
return fmt.Errorf("no edge found for channel point: %s", cpStr)
1923+
}, DefaultTimeout)
1924+
1925+
require.NoError(h, err, "%s: timeout finding channel %v in graph cache",
1926+
cpStr, hn.Name())
1927+
1928+
return edge
1929+
}
1930+
1931+
// AssertChannelInGraphDB asserts that a given channel is found both in the
1932+
// graph db (GetChanInfo) and the graph cache (DescribeGraph).
1933+
func (h *HarnessTest) AssertChannelInGraph(hn *node.HarnessNode,
1934+
chanPoint *lnrpc.ChannelPoint) *lnrpc.ChannelEdge {
1935+
1936+
// Make sure the channel is found in the db first.
1937+
h.AssertChannelInGraphDB(hn, chanPoint)
1938+
1939+
// Assert the channel is also found in the graph cache, which refreshes
1940+
// every `--caches.rpc-graph-cache-duration`.
1941+
return h.AssertChannelInGraphCache(hn, chanPoint)
1942+
}
1943+
18841944
// AssertTxAtHeight gets all of the transactions that a node's wallet has a
18851945
// record of at the target height, and finds and returns the tx with the target
18861946
// txid, failing if it is not found.

0 commit comments

Comments
 (0)