]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add additional testing in `montior_tests` for chain idempotency 2022-11-tx-connection-idempotency
authorMatt Corallo <git@bluematt.me>
Fri, 18 Nov 2022 19:02:02 +0000 (19:02 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 24 Nov 2022 03:40:48 +0000 (03:40 +0000)
At the end of our `monitor_tests`, which test `ChannelMonitor`
`SpendableOutputs` and claimable `Balance`s, add new checks that
ensure that, if we're using the new
`ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we
can replay the full chain without getting redundant events or
`Balance`s.

lightning/src/ln/monitor_tests.rs

index 2916855c0ab34d27b1352ac57e594ad31b090cc9..cee75f8c2076b9df36e4bcf824aa887795358387 100644 (file)
@@ -567,6 +567,16 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) {
        connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1);
        assert_eq!(Vec::<Balance>::new(),
                nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances());
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       for node in nodes.iter() {
+               connect_blocks(node, 6);
+               connect_blocks(node, 6);
+               assert!(node.chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+               assert!(node.chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
+       }
 }
 
 #[test]
@@ -750,6 +760,14 @@ fn test_balances_on_local_commitment_htlcs() {
        connect_blocks(&nodes[0], node_a_htlc_claimable - nodes[0].best_block_info().1);
        assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
        test_spendable_output(&nodes[0], &as_txn[1]);
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       connect_blocks(&nodes[0], 6);
+       connect_blocks(&nodes[0], 6);
+       assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+       assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
 }
 
 #[test]
@@ -982,6 +1000,14 @@ fn test_no_preimage_inbound_htlc_balances() {
 
        connect_blocks(&nodes[1], 1);
        assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       connect_blocks(&nodes[1], 6);
+       connect_blocks(&nodes[1], 6);
+       assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+       assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
 }
 
 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
        test_spendable_output(&nodes[1], &claim_txn[1]);
        expect_payment_failed!(nodes[1], timeout_payment_hash, false);
        assert_eq!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances(), Vec::new());
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       connect_blocks(&nodes[1], 6);
+       connect_blocks(&nodes[1], 6);
+       assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+       assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
 }
 
 #[test]
@@ -1437,6 +1471,14 @@ fn test_revoked_counterparty_htlc_tx_balances() {
        test_spendable_output(&nodes[0], &as_second_htlc_claim_tx[1]);
 
        assert_eq!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances(), Vec::new());
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       connect_blocks(&nodes[0], 6);
+       connect_blocks(&nodes[0], 6);
+       assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+       assert!(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
 }
 
 #[test]
@@ -1628,4 +1670,12 @@ fn test_revoked_counterparty_aggregated_claims() {
        expect_payment_failed!(nodes[1], revoked_payment_hash, false);
        test_spendable_output(&nodes[1], &claim_txn_2[0]);
        assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
+
+       // Ensure that even if we connect more blocks, potentially replaying the entire chain if we're
+       // using `ConnectStyle::HighlyRedundantTransactionsFirstSkippingBlocks`, we don't get new
+       // monitor events or claimable balances.
+       connect_blocks(&nodes[1], 6);
+       connect_blocks(&nodes[1], 6);
+       assert!(nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
+       assert!(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances().is_empty());
 }