From 473f730eec753a31521eedf242015f18a0e3d3a1 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Mon, 26 Oct 2020 16:25:25 -0300 Subject: [PATCH] itest: Sync nodes to chain during singleHop tests This ensures the Carol and Dave nodes created in the single_hop series of tests are synced to the latest chain tip generated by the miner before creating the route that will eventually be used for payments. This prevents a flake during CI tests where slow processing of blocks by Carol could cause the generated route to have a final CLTV delta too short for Dave to accept. While at it, we switch the test to use the default CLTV delta provided by QueryRoutes which is now the global default CLTV. --- lntest/itest/lnd_test.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index ee064bfa..5e25a397 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -5381,14 +5381,23 @@ func testSingleHopSendToRouteCase(net *lntest.NetworkHarness, t *harnessTest, payAddrs = append(payAddrs, resp.PaymentAddr) } - // Query for routes to pay from Carol to Dave. - // We set FinalCltvDelta to 40 since by default QueryRoutes returns - // the last hop with a final cltv delta of 9 where as the default in - // htlcswitch is 40. + // Assert Carol and Dave are synced to the chain before proceeding, to + // ensure the queried route will have a valid final CLTV once the HTLC + // reaches Dave. + _, minerHeight, err := net.Miner.Node.GetBestBlock() + if err != nil { + t.Fatalf("unable to get best height: %v", err) + } + ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout) + defer cancel() + require.NoError(t.t, waitForNodeBlockHeight(ctxt, carol, minerHeight)) + require.NoError(t.t, waitForNodeBlockHeight(ctxt, dave, minerHeight)) + + // Query for routes to pay from Carol to Dave using the default CLTV + // config. routesReq := &lnrpc.QueryRoutesRequest{ - PubKey: dave.PubKeyStr, - Amt: paymentAmtSat, - FinalCltvDelta: lnd.DefaultBitcoinTimeLockDelta, + PubKey: dave.PubKeyStr, + Amt: paymentAmtSat, } ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) routes, err := carol.QueryRoutes(ctxt, routesReq)