Skip to content

Commit faa1f67

Browse files
committed
lntest: assert channel edge in both graph db and cache
We need to make sure the channel edge has been updated in both the graph DB and cache.
1 parent e576d66 commit faa1f67

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

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)