Skip to content

Commit 53eb0d7

Browse files
authored
Merge pull request #1861 from TheBlueMatt/2022-11-tx-connection-idempotency
Ensure transactions_confirmed is idempotent
2 parents af7c292 + cd315d5 commit 53eb0d7

File tree

5 files changed

+159
-19
lines changed

5 files changed

+159
-19
lines changed

lightning/src/chain/channelmonitor.rs

+45-3
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
826826
/// spending CSV for revocable outputs).
827827
htlcs_resolved_on_chain: Vec<IrrevocablyResolvedHTLC>,
828828

829+
/// The set of `SpendableOutput` events which we have already passed upstream to be claimed.
830+
/// These are tracked explicitly to ensure that we don't generate the same events redundantly
831+
/// if users duplicatively confirm old transactions. Specifically for transactions claiming a
832+
/// revoked remote outpoint we otherwise have no tracking at all once they've reached
833+
/// [`ANTI_REORG_DELAY`], so we have to track them here.
834+
spendable_txids_confirmed: Vec<Txid>,
835+
829836
// We simply modify best_block in Channel's block_connected so that serialization is
830837
// consistent but hopefully the users' copy handles block_connected in a consistent way.
831838
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -1071,6 +1078,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
10711078
(7, self.funding_spend_seen, required),
10721079
(9, self.counterparty_node_id, option),
10731080
(11, self.confirmed_commitment_tx_counterparty_output, option),
1081+
(13, self.spendable_txids_confirmed, vec_type),
10741082
});
10751083

10761084
Ok(())
@@ -1179,6 +1187,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11791187
funding_spend_confirmed: None,
11801188
confirmed_commitment_tx_counterparty_output: None,
11811189
htlcs_resolved_on_chain: Vec::new(),
1190+
spendable_txids_confirmed: Vec::new(),
11821191

11831192
best_block,
11841193
counterparty_node_id: Some(counterparty_node_id),
@@ -2860,7 +2869,37 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28602869

28612870
let mut watch_outputs = Vec::new();
28622871
let mut claimable_outpoints = Vec::new();
2863-
for tx in &txn_matched {
2872+
'tx_iter: for tx in &txn_matched {
2873+
let txid = tx.txid();
2874+
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
2875+
if Some(txid) == self.funding_spend_confirmed {
2876+
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);
2877+
continue 'tx_iter;
2878+
}
2879+
for ev in self.onchain_events_awaiting_threshold_conf.iter() {
2880+
if ev.txid == txid {
2881+
if let Some(conf_hash) = ev.block_hash {
2882+
assert_eq!(header.block_hash(), conf_hash,
2883+
"Transaction {} was already confirmed and is being re-confirmed in a different block.\n\
2884+
This indicates a severe bug in the transaction connection logic - a reorg should have been processed first!", ev.txid);
2885+
}
2886+
log_debug!(logger, "Skipping redundant processing of confirming tx {} as it was previously confirmed", txid);
2887+
continue 'tx_iter;
2888+
}
2889+
}
2890+
for htlc in self.htlcs_resolved_on_chain.iter() {
2891+
if Some(txid) == htlc.resolving_txid {
2892+
log_debug!(logger, "Skipping redundant processing of HTLC resolution tx {} as it was previously confirmed", txid);
2893+
continue 'tx_iter;
2894+
}
2895+
}
2896+
for spendable_txid in self.spendable_txids_confirmed.iter() {
2897+
if txid == *spendable_txid {
2898+
log_debug!(logger, "Skipping redundant processing of spendable tx {} as it was previously confirmed", txid);
2899+
continue 'tx_iter;
2900+
}
2901+
}
2902+
28642903
if tx.input.len() == 1 {
28652904
// Assuming our keys were not leaked (in which case we're screwed no matter what),
28662905
// commitment transactions and HTLC transactions will all only ever have one input,
@@ -2870,7 +2909,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28702909
if prevout.txid == self.funding_info.0.txid && prevout.vout == self.funding_info.0.index as u32 {
28712910
let mut balance_spendable_csv = None;
28722911
log_info!(logger, "Channel {} closed by funding output spend in txid {}.",
2873-
log_bytes!(self.funding_info.0.to_channel_id()), tx.txid());
2912+
log_bytes!(self.funding_info.0.to_channel_id()), txid);
28742913
self.funding_spend_seen = true;
28752914
let mut commitment_tx_to_counterparty_output = None;
28762915
if (tx.input[0].sequence.0 >> 8*3) as u8 == 0x80 && (tx.lock_time.0 >> 8*3) as u8 == 0x20 {
@@ -2893,7 +2932,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
28932932
}
28942933
}
28952934
}
2896-
let txid = tx.txid();
28972935
self.onchain_events_awaiting_threshold_conf.push(OnchainEventEntry {
28982936
txid,
28992937
transaction: Some((*tx).clone()),
@@ -3042,6 +3080,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
30423080
self.pending_events.push(Event::SpendableOutputs {
30433081
outputs: vec![descriptor]
30443082
});
3083+
self.spendable_txids_confirmed.push(entry.txid);
30453084
},
30463085
OnchainEvent::HTLCSpendConfirmation { commitment_tx_output_idx, preimage, .. } => {
30473086
self.htlcs_resolved_on_chain.push(IrrevocablyResolvedHTLC {
@@ -3777,13 +3816,15 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K>
37773816
let mut funding_spend_seen = Some(false);
37783817
let mut counterparty_node_id = None;
37793818
let mut confirmed_commitment_tx_counterparty_output = None;
3819+
let mut spendable_txids_confirmed = Some(Vec::new());
37803820
read_tlv_fields!(reader, {
37813821
(1, funding_spend_confirmed, option),
37823822
(3, htlcs_resolved_on_chain, vec_type),
37833823
(5, pending_monitor_events, vec_type),
37843824
(7, funding_spend_seen, option),
37853825
(9, counterparty_node_id, option),
37863826
(11, confirmed_commitment_tx_counterparty_output, option),
3827+
(13, spendable_txids_confirmed, vec_type),
37873828
});
37883829

37893830
let mut secp_ctx = Secp256k1::new();
@@ -3836,6 +3877,7 @@ impl<'a, K: KeysInterface> ReadableArgs<&'a K>
38363877
funding_spend_confirmed,
38373878
confirmed_commitment_tx_counterparty_output,
38383879
htlcs_resolved_on_chain: htlcs_resolved_on_chain.unwrap(),
3880+
spendable_txids_confirmed: spendable_txids_confirmed.unwrap(),
38393881

38403882
best_block,
38413883
counterparty_node_id,

lightning/src/ln/functional_test_utils.rs

+41-5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ pub enum ConnectStyle {
107107
/// The same as `TransactionsFirst`, however when we have multiple blocks to connect, we only
108108
/// make a single `best_block_updated` call.
109109
TransactionsFirstSkippingBlocks,
110+
/// The same as `TransactionsFirst`, however when we have multiple blocks to connect, we only
111+
/// make a single `best_block_updated` call. Further, we call `transactions_confirmed` multiple
112+
/// times to ensure it's idempotent.
113+
TransactionsDuplicativelyFirstSkippingBlocks,
114+
/// The same as `TransactionsFirst`, however when we have multiple blocks to connect, we only
115+
/// make a single `best_block_updated` call. Further, we call `transactions_confirmed` multiple
116+
/// times to ensure it's idempotent.
117+
HighlyRedundantTransactionsFirstSkippingBlocks,
110118
/// The same as `TransactionsFirst` when connecting blocks. During disconnection only
111119
/// `transaction_unconfirmed` is called.
112120
TransactionsFirstReorgsOnlyTip,
@@ -121,14 +129,16 @@ impl ConnectStyle {
121129
use core::hash::{BuildHasher, Hasher};
122130
// Get a random value using the only std API to do so - the DefaultHasher
123131
let rand_val = std::collections::hash_map::RandomState::new().build_hasher().finish();
124-
let res = match rand_val % 7 {
132+
let res = match rand_val % 9 {
125133
0 => ConnectStyle::BestBlockFirst,
126134
1 => ConnectStyle::BestBlockFirstSkippingBlocks,
127135
2 => ConnectStyle::BestBlockFirstReorgsOnlyTip,
128136
3 => ConnectStyle::TransactionsFirst,
129137
4 => ConnectStyle::TransactionsFirstSkippingBlocks,
130-
5 => ConnectStyle::TransactionsFirstReorgsOnlyTip,
131-
6 => ConnectStyle::FullBlockViaListen,
138+
5 => ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks,
139+
6 => ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks,
140+
7 => ConnectStyle::TransactionsFirstReorgsOnlyTip,
141+
8 => ConnectStyle::FullBlockViaListen,
132142
_ => unreachable!(),
133143
};
134144
eprintln!("Using Block Connection Style: {:?}", res);
@@ -143,6 +153,7 @@ impl ConnectStyle {
143153
pub fn connect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, depth: u32) -> BlockHash {
144154
let skip_intermediaries = match *node.connect_style.borrow() {
145155
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks|
156+
ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks|ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks|
146157
ConnectStyle::BestBlockFirstReorgsOnlyTip|ConnectStyle::TransactionsFirstReorgsOnlyTip => true,
147158
_ => false,
148159
};
@@ -193,8 +204,32 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
193204
node.node.best_block_updated(&block.header, height);
194205
node.node.transactions_confirmed(&block.header, &txdata, height);
195206
},
196-
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks|ConnectStyle::TransactionsFirstReorgsOnlyTip => {
207+
ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks|
208+
ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks|ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks|
209+
ConnectStyle::TransactionsFirstReorgsOnlyTip => {
210+
if *node.connect_style.borrow() == ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks {
211+
let mut connections = Vec::new();
212+
for (block, height) in node.blocks.lock().unwrap().iter() {
213+
if !block.txdata.is_empty() {
214+
// Reconnect all transactions we've ever seen to ensure transaction connection
215+
// is *really* idempotent. This is a somewhat likely deployment for some
216+
// esplora implementations of chain sync which try to reduce state and
217+
// complexity as much as possible.
218+
//
219+
// Sadly we have to clone the block here to maintain lockorder. In the
220+
// future we should consider Arc'ing the blocks to avoid this.
221+
connections.push((block.clone(), *height));
222+
}
223+
}
224+
for (old_block, height) in connections {
225+
node.chain_monitor.chain_monitor.transactions_confirmed(&old_block.header,
226+
&old_block.txdata.iter().enumerate().collect::<Vec<_>>(), height);
227+
}
228+
}
197229
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
230+
if *node.connect_style.borrow() == ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks {
231+
node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
232+
}
198233
call_claimable_balances(node);
199234
node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
200235
node.node.transactions_confirmed(&block.header, &txdata, height);
@@ -226,7 +261,8 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
226261
node.chain_monitor.chain_monitor.block_disconnected(&orig.0.header, orig.1);
227262
Listen::block_disconnected(node.node, &orig.0.header, orig.1);
228263
},
229-
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks => {
264+
ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks|
265+
ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks|ConnectStyle::TransactionsDuplicativelyFirstSkippingBlocks => {
230266
if i == count - 1 {
231267
node.chain_monitor.chain_monitor.best_block_updated(&prev.0.header, prev.1);
232268
node.node.best_block_updated(&prev.0.header, prev.1);

lightning/src/ln/functional_tests.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -2814,12 +2814,17 @@ fn test_htlc_on_chain_success() {
28142814
check_added_monitors!(nodes[1], 1);
28152815
check_closed_event!(nodes[1], 1, ClosureReason::CommitmentTxConfirmed);
28162816
let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clone();
2817-
assert_eq!(node_txn.len(), 6); // ChannelManager : 3 (commitment tx + HTLC-Sucess * 2), ChannelMonitor : 3 (HTLC-Success, 2* RBF bumps of above HTLC txn)
2817+
assert!(node_txn.len() == 4 || node_txn.len() == 6); // ChannelManager : 3 (commitment tx + HTLC-Sucess * 2), ChannelMonitor : 3 (HTLC-Success, 2* RBF bumps of above HTLC txn)
28182818
let commitment_spend =
28192819
if node_txn[0].input[0].previous_output.txid == node_a_commitment_tx[0].txid() {
2820-
check_spends!(node_txn[1], commitment_tx[0]);
2821-
check_spends!(node_txn[2], commitment_tx[0]);
2822-
assert_ne!(node_txn[1].input[0].previous_output.vout, node_txn[2].input[0].previous_output.vout);
2820+
if node_txn.len() == 6 {
2821+
// In some block `ConnectionStyle`s we may avoid broadcasting the double-spending
2822+
// transactions spending the HTLC outputs of C's commitment transaction. Otherwise,
2823+
// check that the extra broadcasts (double-)spend those here.
2824+
check_spends!(node_txn[1], commitment_tx[0]);
2825+
check_spends!(node_txn[2], commitment_tx[0]);
2826+
assert_ne!(node_txn[1].input[0].previous_output.vout, node_txn[2].input[0].previous_output.vout);
2827+
}
28232828
&node_txn[0]
28242829
} else {
28252830
check_spends!(node_txn[0], commitment_tx[0]);
@@ -2834,10 +2839,11 @@ fn test_htlc_on_chain_success() {
28342839
assert_eq!(commitment_spend.input[1].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
28352840
assert_eq!(commitment_spend.lock_time.0, 0);
28362841
assert!(commitment_spend.output[0].script_pubkey.is_v0_p2wpkh()); // direct payment
2837-
check_spends!(node_txn[3], chan_1.3);
2838-
assert_eq!(node_txn[3].input[0].witness.clone().last().unwrap().len(), 71);
2839-
check_spends!(node_txn[4], node_txn[3]);
2840-
check_spends!(node_txn[5], node_txn[3]);
2842+
let funding_spend_offset = if node_txn.len() == 6 { 3 } else { 1 };
2843+
check_spends!(node_txn[funding_spend_offset], chan_1.3);
2844+
assert_eq!(node_txn[funding_spend_offset].input[0].witness.clone().last().unwrap().len(), 71);
2845+
check_spends!(node_txn[funding_spend_offset + 1], node_txn[funding_spend_offset]);
2846+
check_spends!(node_txn[funding_spend_offset + 2], node_txn[funding_spend_offset]);
28412847
// We don't bother to check that B can claim the HTLC output on its commitment tx here as
28422848
// we already checked the same situation with A.
28432849

@@ -3370,6 +3376,12 @@ fn test_htlc_ignore_latest_remote_commitment() {
33703376
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
33713377
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
33723378
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
3379+
if *nodes[1].connect_style.borrow() == ConnectStyle::FullBlockViaListen {
3380+
// We rely on the ability to connect a block redundantly, which isn't allowed via
3381+
// `chain::Listen`, so we never run the test if we randomly get assigned that
3382+
// connect_style.
3383+
return;
3384+
}
33733385
create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
33743386

33753387
route_payment(&nodes[0], &[&nodes[1]], 10000000);
@@ -3391,7 +3403,6 @@ fn test_htlc_ignore_latest_remote_commitment() {
33913403

33923404
// Duplicate the connect_block call since this may happen due to other listeners
33933405
// registering new transactions
3394-
header.prev_blockhash = header.block_hash();
33953406
connect_block(&nodes[1], &Block { header, txdata: vec![node_txn[0].clone(), node_txn[2].clone()]});
33963407
}
33973408

lightning/src/ln/monitor_tests.rs

+50
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,16 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
567567
connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
568568
assert_eq!(Vec::<Balance>::new(),
569569
nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
570+
571+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
572+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
573+
// monitor events or claimable balances.
574+
for node in nodes.iter() {
575+
connect_blocks(node, 6);
576+
connect_blocks(node, 6);
577+
assert!(node.chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
578+
assert!(node.chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
579+
}
570580
}
571581

572582
#[test]
@@ -750,6 +760,14 @@ fn test_balances_on_local_commitment_htlcs() {
750760
connect_blocks(&nodes[0], node_a_htlc_claimable - nodes[0].best_block_info().1);
751761
assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
752762
test_spendable_output(&nodes[0], &as_txn[1]);
763+
764+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
765+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
766+
// monitor events or claimable balances.
767+
connect_blocks(&nodes[0], 6);
768+
connect_blocks(&nodes[0], 6);
769+
assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
770+
assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
753771
}
754772

755773
#[test]
@@ -982,6 +1000,14 @@ fn test_no_preimage_inbound_htlc_balances() {
9821000

9831001
connect_blocks(&nodes[1], 1);
9841002
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
1003+
1004+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
1005+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
1006+
// monitor events or claimable balances.
1007+
connect_blocks(&nodes[1], 6);
1008+
connect_blocks(&nodes[1], 6);
1009+
assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
1010+
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
9851011
}
9861012

9871013
fn sorted_vec_with_additions<T: Ord + Clone>(v_orig: &Vec<T>, extra_ts: &[&T]) -> Vec<T> {
@@ -1231,6 +1257,14 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo
12311257
test_spendable_output(&nodes[1], &claim_txn[1]);
12321258
expect_payment_failed!(nodes[1], timeout_payment_hash, false);
12331259
assert_eq!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances(), Vec::new());
1260+
1261+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
1262+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
1263+
// monitor events or claimable balances.
1264+
connect_blocks(&nodes[1], 6);
1265+
connect_blocks(&nodes[1], 6);
1266+
assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
1267+
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
12341268
}
12351269

12361270
#[test]
@@ -1437,6 +1471,14 @@ fn test_revoked_counterparty_htlc_tx_balances() {
14371471
test_spendable_output(&nodes[0], &as_second_htlc_claim_tx[1]);
14381472

14391473
assert_eq!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances(), Vec::new());
1474+
1475+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
1476+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
1477+
// monitor events or claimable balances.
1478+
connect_blocks(&nodes[0], 6);
1479+
connect_blocks(&nodes[0], 6);
1480+
assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
1481+
assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
14401482
}
14411483

14421484
#[test]
@@ -1628,4 +1670,12 @@ fn test_revoked_counterparty_aggregated_claims() {
16281670
expect_payment_failed!(nodes[1], revoked_payment_hash, false);
16291671
test_spendable_output(&nodes[1], &claim_txn_2[0]);
16301672
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
1673+
1674+
// Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
1675+
// using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
1676+
// monitor events or claimable balances.
1677+
connect_blocks(&nodes[1], 6);
1678+
connect_blocks(&nodes[1], 6);
1679+
assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
1680+
assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
16311681
}

lightning/src/ln/payment_tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,9 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co
786786
let funding_txo = OutPoint { txid: funding_tx.txid(), index: 0 };
787787
let mon_updates: Vec<_> = chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap()
788788
.get_mut(&funding_txo).unwrap().drain().collect();
789-
// If we are using chain::Confirm instead of chain::Listen, we will get the same update twice
790-
assert!(mon_updates.len() == 1 || mon_updates.len() == 2);
789+
// If we are using chain::Confirm instead of chain::Listen, we will get the same update twice.
790+
// If we're testing connection idempotency we may get substantially more.
791+
assert!(mon_updates.len() >= 1);
791792
assert!(nodes[0].chain_monitor.release_pending_monitor_events().is_empty());
792793
assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
793794

0 commit comments

Comments
 (0)