From: Arik Sosman Date: Sat, 26 Aug 2023 00:34:10 +0000 (-0700) Subject: Fix flaky aggregated HTLC revocation test. X-Git-Tag: v0.0.117-alpha1~36^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=f80284cc88ccbac8168316eba887e51142623cc1;p=rust-lightning Fix flaky aggregated HTLC revocation test. Releasing write locks in between monitor updates requires storing a set of cloned keys to iterate over. For efficiency purposes, that set of keys is an actual set, as opposed to array, which means that the iteration order may not be consistent. The test was relying on an event array index to access the revocation transaction. We change that to accessing a hash map keyed by the txid, fixing the test. --- diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 728752f97..58878a999 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -2191,7 +2191,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() { // Alice should see that Bob is trying to claim to HTLCs, so she should now try to claim them at // the second level instead. - let revoked_claims = { + let revoked_claim_transactions = { let txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(txn.len(), 2); @@ -2205,10 +2205,14 @@ fn test_anchors_aggregated_revoked_htlc_tx() { check_spends!(revoked_htlc_claim, htlc_tx); } - txn + let mut revoked_claim_transaction_map = HashMap::new(); + for current_tx in txn.into_iter() { + revoked_claim_transaction_map.insert(current_tx.txid(), current_tx); + } + revoked_claim_transaction_map }; for node in &nodes { - mine_transactions(node, &revoked_claims.iter().collect::>()); + mine_transactions(node, &revoked_claim_transactions.values().collect::>()); } @@ -2234,7 +2238,8 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs( &[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(), ).unwrap(); - check_spends!(spend_tx, revoked_claims[idx]); + + check_spends!(spend_tx, revoked_claim_transactions.get(&spend_tx.input[0].previous_output.txid).unwrap()); } else { panic!("unexpected event"); }