Skip to content

Commit f80284c

Browse files
committed
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.
1 parent c7a4949 commit f80284c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lightning/src/ln/monitor_tests.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
21912191

21922192
// Alice should see that Bob is trying to claim to HTLCs, so she should now try to claim them at
21932193
// the second level instead.
2194-
let revoked_claims = {
2194+
let revoked_claim_transactions = {
21952195
let txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
21962196
assert_eq!(txn.len(), 2);
21972197

@@ -2205,10 +2205,14 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
22052205
check_spends!(revoked_htlc_claim, htlc_tx);
22062206
}
22072207

2208-
txn
2208+
let mut revoked_claim_transaction_map = HashMap::new();
2209+
for current_tx in txn.into_iter() {
2210+
revoked_claim_transaction_map.insert(current_tx.txid(), current_tx);
2211+
}
2212+
revoked_claim_transaction_map
22092213
};
22102214
for node in &nodes {
2211-
mine_transactions(node, &revoked_claims.iter().collect::<Vec<_>>());
2215+
mine_transactions(node, &revoked_claim_transactions.values().collect::<Vec<_>>());
22122216
}
22132217

22142218

@@ -2234,7 +2238,8 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
22342238
let spend_tx = nodes[0].keys_manager.backing.spend_spendable_outputs(
22352239
&[&outputs[0]], Vec::new(), Script::new_op_return(&[]), 253, None, &Secp256k1::new(),
22362240
).unwrap();
2237-
check_spends!(spend_tx, revoked_claims[idx]);
2241+
2242+
check_spends!(spend_tx, revoked_claim_transactions.get(&spend_tx.input[0].previous_output.txid).unwrap());
22382243
} else {
22392244
panic!("unexpected event");
22402245
}

0 commit comments

Comments
 (0)