From 17f08a87db6f7ac92c77cd9ce14d979593b5b9e4 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 3 Nov 2022 18:15:02 +0800 Subject: [PATCH] lntest+itest: remove assertion while iterating mempool --- itest/lnd_revocation_test.go | 9 ++++++++- lntest/harness_miner.go | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/itest/lnd_revocation_test.go b/itest/lnd_revocation_test.go index dba130025..1ca9ee35e 100644 --- a/itest/lnd_revocation_test.go +++ b/itest/lnd_revocation_test.go @@ -477,7 +477,14 @@ func testRevokedCloseRetributionRemoteHodl(ht *lntest.HarnessTest) { for _, txid := range mempool { // Check that the justice tx has the appropriate number // of inputs. - tx := ht.Miner.GetRawTransaction(txid) + // + // NOTE: We don't use `ht.Miner.GetRawTransaction` + // which asserts a txid must be found as the HTLC + // spending txes might be aggregated. + tx, err := ht.Miner.Client.GetRawTransaction(txid) + if err != nil { + return nil, err + } exNumInputs := 2 + numInvoices if len(tx.MsgTx().TxIn) == exNumInputs { diff --git a/lntest/harness_miner.go b/lntest/harness_miner.go index 7e829c516..189df54b1 100644 --- a/lntest/harness_miner.go +++ b/lntest/harness_miner.go @@ -372,9 +372,17 @@ func (h *HarnessMiner) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx { } for _, txid := range mempool { - // We require the RPC call to be succeeded and won't - // wait for it as it's an unexpected behavior. - tx := h.GetRawTransaction(txid) + // We don't use `ht.Miner.GetRawTransaction` which + // asserts a txid must be found. While iterating here, + // the actual mempool state might have been changed, + // causing a given txid being removed and cannot be + // found. For instance, the aggregation logic used in + // sweeping HTLC outputs will update the mempool by + // replacing the HTLC spending txes with a single one. + tx, err := h.Client.GetRawTransaction(txid) + if err != nil { + return err + } msgTx = tx.MsgTx() for _, txIn := range msgTx.TxIn {