From f3cdbbed2f23e4925c996a8e9c3a4eb2e6085f68 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 13 Jun 2024 10:31:22 -0400 Subject: [PATCH] itest+lntest: let abandoned channel be either not found or in zombie index When abandoning a channel, we remove it from the graph and then add it to the zombie channel index. However, if we then process a ChannelUpdate for this channel it will result in us calling `processZombieUpdate` which will delete the edge from the zombie index. The abandon channel itest currently asserts that a channel is no longer in the graph by asserting that when querying for the channel we get a "marked as zombie" error but to account for the above series of operations, we now also allow it to just not be found at all ("edge not found"). --- itest/lnd_misc_test.go | 2 +- lntest/harness_assertion.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/itest/lnd_misc_test.go b/itest/lnd_misc_test.go index 3c247c4a1..206d5748d 100644 --- a/itest/lnd_misc_test.go +++ b/itest/lnd_misc_test.go @@ -729,7 +729,7 @@ func testAbandonChannel(ht *lntest.HarnessTest) { require.Len(ht, aliceClosedList.Channels, 1, "alice closed channels") // Ensure that the channel can no longer be found in the channel graph. - ht.AssertZombieChannel(alice, chanID) + ht.AssertNotInGraph(alice, chanID) // Make sure the channel is no longer in the channel backup list. err = wait.NoError(func() error { diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index f8c1c9716..9ee9bc4e4 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -1820,6 +1820,37 @@ func (h *HarnessTest) AssertZombieChannel(hn *node.HarnessNode, chanID uint64) { require.NoError(h, err, "timeout while checking zombie channel") } +// AssertNotInGraph asserts that a given channel is either not found at all in +// the graph or that it has been marked as a zombie. +func (h *HarnessTest) AssertNotInGraph(hn *node.HarnessNode, chanID uint64) { + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + err := wait.NoError(func() error { + _, err := hn.RPC.LN.GetChanInfo( + ctxt, &lnrpc.ChanInfoRequest{ChanId: chanID}, + ) + if err == nil { + return fmt.Errorf("expected error but got nil") + } + + switch { + case strings.Contains(err.Error(), "marked as zombie"): + return nil + + case strings.Contains(err.Error(), "edge not found"): + return nil + + default: + return fmt.Errorf("expected error to contain either "+ + "'%s' or '%s' but was: '%v'", "marked as i"+ + "zombie", "edge not found", err) + } + }, DefaultTimeout) + require.NoError(h, err, "timeout while checking that channel is not "+ + "found in graph") +} + // 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.