X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmonitor_tests.rs;h=1f9a2cf3a74e3b9555e8a64c6e6ed9f143324697;hb=0ecb4b093ac1134cbf06275cc48dd79ef7524774;hp=5b2b29dbb76f11675a2269cc3ebafb527eda063d;hpb=db123f74be168e6f5432fb337dbe45bd7db0bde9;p=rust-lightning diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 5b2b29db..1f9a2cf3 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -10,7 +10,7 @@ //! Further functional tests which test blockchain reorganizations. #[cfg(anchors)] -use crate::chain::keysinterface::{ChannelSigner, EcdsaChannelSigner}; +use crate::sign::{ChannelSigner, EcdsaChannelSigner}; #[cfg(anchors)] use crate::chain::channelmonitor::LATENCY_GRACE_PERIOD_BLOCKS; use crate::chain::channelmonitor::{ANTI_REORG_DELAY, Balance}; @@ -298,28 +298,49 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { let opt_anchors = get_opt_anchors!(nodes[0], nodes[1], chan_id); let remote_txn = get_local_commitment_txn!(nodes[1], chan_id); + let sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 3_000, + claimable_height: htlc_cltv_timeout, + payment_hash, + }; + let sent_htlc_timeout_balance = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 4_000, + claimable_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, + }; + let received_htlc_balance = Balance::MaybePreimageClaimableHTLC { + claimable_amount_satoshis: 3_000, + expiry_height: htlc_cltv_timeout, + payment_hash, + }; + let received_htlc_timeout_balance = Balance::MaybePreimageClaimableHTLC { + claimable_amount_satoshis: 4_000, + expiry_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, + }; + let received_htlc_claiming_balance = Balance::ContentiousClaimable { + claimable_amount_satoshis: 3_000, + timeout_height: htlc_cltv_timeout, + payment_hash, + payment_preimage, + }; + let received_htlc_timeout_claiming_balance = Balance::ContentiousClaimable { + claimable_amount_satoshis: 4_000, + timeout_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, + payment_preimage: timeout_payment_preimage, + }; + // Before B receives the payment preimage, it only suggests the push_msat value of 1_000 sats // as claimable. A lists both its to-self balance and the (possibly-claimable) HTLCs. assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose { claimable_amount_satoshis: 1_000_000 - 3_000 - 4_000 - 1_000 - 3 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 3_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }]), + }, sent_htlc_balance.clone(), sent_htlc_timeout_balance.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose { claimable_amount_satoshis: 1_000, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 3_000, - expiry_height: htlc_cltv_timeout, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 4_000, - expiry_height: htlc_cltv_timeout, - }]), + }, received_htlc_balance.clone(), received_htlc_timeout_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); nodes[1].node.claim_funds(payment_preimage); @@ -364,15 +385,9 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + if prev_commitment_tx { 1 } else { 2 } * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }]; + }, sent_htlc_timeout_balance.clone()]; if !prev_commitment_tx { - a_expected_balances.push(Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 3_000, - claimable_height: htlc_cltv_timeout, - }); + a_expected_balances.push(sent_htlc_balance.clone()); } assert_eq!(sorted_vec(a_expected_balances), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); @@ -419,13 +434,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { claimable_amount_satoshis: 1_000_000 - 3_000 - 4_000 - 1_000 - 3 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: nodes[0].best_block_info().1 + ANTI_REORG_DELAY - 1, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 3_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }]), + }, sent_htlc_balance.clone(), sent_htlc_timeout_balance.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // The main non-HTLC balance is just awaiting confirmations, but the claimable height is the // CSV delay, not ANTI_REORG_DELAY. @@ -435,13 +444,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { }, // Both HTLC balances are "contentious" as our counterparty could claim them if we wait too // long. - Balance::ContentiousClaimable { - claimable_amount_satoshis: 3_000, - timeout_height: htlc_cltv_timeout, - }, Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }]), + received_htlc_claiming_balance.clone(), received_htlc_timeout_claiming_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1); @@ -450,24 +453,12 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { // After ANTI_REORG_DELAY, A will consider its balance fully spendable and generate a // `SpendableOutputs` event. However, B still has to wait for the CSV delay. - assert_eq!(sorted_vec(vec![Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 3_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }]), + assert_eq!(sorted_vec(vec![sent_htlc_balance.clone(), sent_htlc_timeout_balance.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 1_000, confirmation_height: node_b_commitment_claimable, - }, Balance::ContentiousClaimable { - claimable_amount_satoshis: 3_000, - timeout_height: htlc_cltv_timeout, - }, Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }]), + }, received_htlc_claiming_balance.clone(), received_htlc_timeout_claiming_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); test_spendable_output(&nodes[0], &remote_txn[0]); @@ -481,23 +472,14 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { } else { expect_payment_sent!(nodes[0], payment_preimage); } - assert_eq!(sorted_vec(vec![Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 3_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }]), + assert_eq!(sorted_vec(vec![sent_htlc_balance.clone(), sent_htlc_timeout_balance.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1); - assert_eq!(vec![Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 4_000, - claimable_height: htlc_cltv_timeout, - }], + assert_eq!(vec![sent_htlc_timeout_balance.clone()], nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()); // When the HTLC timeout output is spendable in the next block, A should broadcast it - connect_blocks(&nodes[0], htlc_cltv_timeout - nodes[0].best_block_info().1 - 1); + connect_blocks(&nodes[0], htlc_cltv_timeout - nodes[0].best_block_info().1); let a_broadcast_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(a_broadcast_txn.len(), 2); assert_eq!(a_broadcast_txn[0].input.len(), 1); @@ -540,10 +522,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { }, Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 3_000, confirmation_height: node_b_htlc_claimable, - }, Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }]), + }, received_htlc_timeout_claiming_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // After reaching the commitment output CSV, we'll get a SpendableOutputs event for it and have @@ -554,10 +533,7 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 3_000, confirmation_height: node_b_htlc_claimable, - }, Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }]), + }, received_htlc_timeout_claiming_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // After reaching the claimed HTLC output CSV, we'll get a SpendableOutptus event for it and @@ -565,20 +541,14 @@ fn do_test_claim_value_force_close(prev_commitment_tx: bool) { connect_blocks(&nodes[1], node_b_htlc_claimable - nodes[1].best_block_info().1); test_spendable_output(&nodes[1], &b_broadcast_txn[0]); - assert_eq!(vec![Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }], + assert_eq!(vec![received_htlc_timeout_claiming_balance.clone()], nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()); // Finally, mine the HTLC timeout transaction that A broadcasted (even though B should be able // to claim this HTLC with the preimage it knows!). It will remain listed as a claimable HTLC // until ANTI_REORG_DELAY confirmations on the spend. mine_transaction(&nodes[1], &a_broadcast_txn[1]); - assert_eq!(vec![Balance::ContentiousClaimable { - claimable_amount_satoshis: 4_000, - timeout_height: htlc_cltv_timeout, - }], + assert_eq!(vec![received_htlc_timeout_claiming_balance.clone()], nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()); connect_blocks(&nodes[1], ANTI_REORG_DELAY - 1); assert_eq!(Vec::::new(), @@ -669,17 +639,22 @@ fn test_balances_on_local_commitment_htlcs() { check_closed_broadcast!(nodes[0], true); check_closed_event!(nodes[0], 1, ClosureReason::CommitmentTxConfirmed); + let htlc_balance_known_preimage = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 10_000, + claimable_height: htlc_cltv_timeout, + payment_hash, + }; + let htlc_balance_unknown_preimage = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 20_000, + claimable_height: htlc_cltv_timeout, + payment_hash: payment_hash_2, + }; + assert_eq!(sorted_vec(vec![Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 1_000_000 - 10_000 - 20_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: node_a_commitment_claimable, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 10_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]), + }, htlc_balance_known_preimage.clone(), htlc_balance_unknown_preimage.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // Get nodes[1]'s HTLC claim tx for the second HTLC @@ -698,13 +673,7 @@ fn test_balances_on_local_commitment_htlcs() { claimable_amount_satoshis: 1_000_000 - 10_000 - 20_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: node_a_commitment_claimable, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 10_000, - claimable_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]), + }, htlc_balance_known_preimage.clone(), htlc_balance_unknown_preimage.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); assert_eq!(as_txn[1].lock_time.0, nodes[0].best_block_info().1 + 1); // as_txn[1] can be included in the next block @@ -722,10 +691,7 @@ fn test_balances_on_local_commitment_htlcs() { }, Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 10_000, confirmation_height: node_a_htlc_claimable, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]), + }, htlc_balance_unknown_preimage.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // Now confirm nodes[1]'s HTLC claim, giving nodes[0] the preimage. Note that the "maybe @@ -739,10 +705,7 @@ fn test_balances_on_local_commitment_htlcs() { }, Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 10_000, confirmation_height: node_a_htlc_claimable, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]), + }, htlc_balance_unknown_preimage.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // Finally make the HTLC transactions have ANTI_REORG_DELAY blocks. This call previously @@ -806,6 +769,27 @@ fn test_no_preimage_inbound_htlc_balances() { let chan_feerate = get_feerate!(nodes[0], nodes[1], chan_id) as u64; let opt_anchors = get_opt_anchors!(nodes[0], nodes[1], chan_id); + let a_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 10_000, + claimable_height: htlc_cltv_timeout, + payment_hash: to_b_failed_payment_hash, + }; + let a_received_htlc_balance = Balance::MaybePreimageClaimableHTLC { + claimable_amount_satoshis: 20_000, + expiry_height: htlc_cltv_timeout, + payment_hash: to_a_failed_payment_hash, + }; + let b_received_htlc_balance = Balance::MaybePreimageClaimableHTLC { + claimable_amount_satoshis: 10_000, + expiry_height: htlc_cltv_timeout, + payment_hash: to_b_failed_payment_hash, + }; + let b_sent_htlc_balance = Balance::MaybeTimeoutClaimableHTLC { + claimable_amount_satoshis: 20_000, + claimable_height: htlc_cltv_timeout, + payment_hash: to_a_failed_payment_hash, + }; + // Both A and B will have an HTLC that's claimable on timeout and one that's claimable if they // receive the preimage. These will remain the same through the channel closure and until the // HTLC output is spent. @@ -813,24 +797,12 @@ fn test_no_preimage_inbound_htlc_balances() { assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose { claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 20_000, - expiry_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 10_000, - claimable_height: htlc_cltv_timeout, - }]), + }, a_received_htlc_balance.clone(), a_sent_htlc_balance.clone()]), sorted_vec(nodes[0].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); assert_eq!(sorted_vec(vec![Balance::ClaimableOnChannelClose { claimable_amount_satoshis: 500_000 - 20_000, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 10_000, - expiry_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]), + }, b_received_htlc_balance.clone(), b_sent_htlc_balance.clone()]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); // Get nodes[0]'s commitment transaction and HTLC-Timeout transaction @@ -846,13 +818,7 @@ fn test_no_preimage_inbound_htlc_balances() { claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: node_a_commitment_claimable, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 20_000, - expiry_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 10_000, - claimable_height: htlc_cltv_timeout, - }]); + }, a_received_htlc_balance.clone(), a_sent_htlc_balance.clone()]); mine_transaction(&nodes[0], &as_txn[0]); nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clear(); @@ -872,13 +838,7 @@ fn test_no_preimage_inbound_htlc_balances() { let mut bs_pre_spend_claims = sorted_vec(vec![Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 500_000 - 20_000, confirmation_height: node_b_commitment_claimable, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 10_000, - expiry_height: htlc_cltv_timeout, - }, Balance::MaybeTimeoutClaimableHTLC { - claimable_amount_satoshis: 20_000, - claimable_height: htlc_cltv_timeout, - }]); + }, b_received_htlc_balance.clone(), b_sent_htlc_balance.clone()]); assert_eq!(bs_pre_spend_claims, sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); @@ -887,7 +847,7 @@ fn test_no_preimage_inbound_htlc_balances() { // HTLC has been spent, even after the HTLC expires. We'll also fail the inbound HTLC, but it // won't do anything as the channel is already closed. - connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); + connect_blocks(&nodes[0], TEST_FINAL_CLTV); let as_htlc_timeout_claim = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); assert_eq!(as_htlc_timeout_claim.len(), 1); check_spends!(as_htlc_timeout_claim[0], as_txn[0]); @@ -908,7 +868,7 @@ fn test_no_preimage_inbound_htlc_balances() { // The next few blocks for B look the same as for A, though for the opposite HTLC nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().clear(); - connect_blocks(&nodes[1], TEST_FINAL_CLTV - (ANTI_REORG_DELAY - 1) - 1); + connect_blocks(&nodes[1], TEST_FINAL_CLTV - (ANTI_REORG_DELAY - 1)); expect_pending_htlcs_forwardable_conditions!(nodes[1], [HTLCDestination::FailedPayment { payment_hash: to_b_failed_payment_hash }]); let bs_htlc_timeout_claim = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); @@ -930,10 +890,7 @@ fn test_no_preimage_inbound_htlc_balances() { claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: node_a_commitment_claimable, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 20_000, - expiry_height: htlc_cltv_timeout, - }, Balance::ClaimableAwaitingConfirmations { + }, a_received_htlc_balance.clone(), Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 10_000, confirmation_height: as_timeout_claimable_height, }]), @@ -944,10 +901,7 @@ fn test_no_preimage_inbound_htlc_balances() { claimable_amount_satoshis: 1_000_000 - 500_000 - 10_000 - chan_feerate * (channel::commitment_tx_base_weight(opt_anchors) + 2 * channel::COMMITMENT_TX_WEIGHT_PER_HTLC) / 1000, confirmation_height: node_a_commitment_claimable, - }, Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 20_000, - expiry_height: htlc_cltv_timeout, - }, Balance::ClaimableAwaitingConfirmations { + }, a_received_htlc_balance.clone(), Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 10_000, confirmation_height: as_timeout_claimable_height, }]), @@ -985,20 +939,14 @@ fn test_no_preimage_inbound_htlc_balances() { // was already claimed. mine_transaction(&nodes[1], &bs_htlc_timeout_claim[0]); let bs_timeout_claimable_height = nodes[1].best_block_info().1 + ANTI_REORG_DELAY - 1; - assert_eq!(sorted_vec(vec![Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 10_000, - expiry_height: htlc_cltv_timeout, - }, Balance::ClaimableAwaitingConfirmations { + assert_eq!(sorted_vec(vec![b_received_htlc_balance.clone(), Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 20_000, confirmation_height: bs_timeout_claimable_height, }]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); mine_transaction(&nodes[1], &as_htlc_timeout_claim[0]); - assert_eq!(sorted_vec(vec![Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 10_000, - expiry_height: htlc_cltv_timeout, - }, Balance::ClaimableAwaitingConfirmations { + assert_eq!(sorted_vec(vec![b_received_htlc_balance.clone(), Balance::ClaimableAwaitingConfirmations { claimable_amount_satoshis: 20_000, confirmation_height: bs_timeout_claimable_height, }]), @@ -1007,10 +955,7 @@ fn test_no_preimage_inbound_htlc_balances() { connect_blocks(&nodes[1], ANTI_REORG_DELAY - 2); expect_payment_failed!(nodes[1], to_a_failed_payment_hash, false); - assert_eq!(vec![Balance::MaybePreimageClaimableHTLC { - claimable_amount_satoshis: 10_000, - expiry_height: htlc_cltv_timeout, - }], + assert_eq!(vec![b_received_htlc_balance.clone()], nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances()); test_spendable_output(&nodes[1], &bs_htlc_timeout_claim[0]); @@ -1133,12 +1078,15 @@ fn do_test_revoked_counterparty_commitment_balances(confirm_htlc_spend_first: bo }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 2_000, claimable_height: missing_htlc_cltv_timeout, + payment_hash: missing_htlc_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 4_000, claimable_height: htlc_cltv_timeout, + payment_hash: timeout_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 5_000, claimable_height: live_htlc_cltv_timeout, + payment_hash: live_payment_hash, }]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); @@ -1567,9 +1515,11 @@ fn test_revoked_counterparty_aggregated_claims() { }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 4_000, claimable_height: htlc_cltv_timeout, + payment_hash: revoked_payment_hash, }, Balance::MaybeTimeoutClaimableHTLC { claimable_amount_satoshis: 3_000, claimable_height: htlc_cltv_timeout, + payment_hash: claimed_payment_hash, }]), sorted_vec(nodes[1].chain_monitor.chain_monitor.get_monitor(funding_outpoint).unwrap().get_claimable_balances())); @@ -1734,7 +1684,7 @@ fn do_test_restored_packages_retry(check_old_monitor_retries_after_upgrade: bool mine_transaction(&nodes[0], &commitment_tx); // Connect blocks until the HTLC's expiration is met, expecting a transaction broadcast. - connect_blocks(&nodes[0], TEST_FINAL_CLTV - 1); + connect_blocks(&nodes[0], TEST_FINAL_CLTV); let htlc_timeout_tx = { let mut txn = nodes[0].tx_broadcaster.txn_broadcast(); assert_eq!(txn.len(), 1); @@ -1784,7 +1734,6 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { if anchors { assert!(cfg!(anchors)); } - let secp = Secp256k1::new(); let mut chanmon_cfgs = create_chanmon_cfgs(2); let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); let mut config = test_default_channel_config(); @@ -1838,6 +1787,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, }) = events.pop().unwrap() { + let secp = Secp256k1::new(); assert_eq!(htlc_descriptors.len(), 1); let descriptor = htlc_descriptors.pop().unwrap(); assert_eq!(descriptor.commitment_txid, commitment_txn[0].txid()); @@ -1885,7 +1835,7 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) { }; // Connect blocks up to one before the HTLC expires. This should not result in a claim/retry. - connect_blocks(&nodes[0], htlc_expiry - nodes[0].best_block_info().1 - 2); + connect_blocks(&nodes[0], htlc_expiry - nodes[0].best_block_info().1 - 1); check_htlc_retry(false, false); // Connect one more block, producing our first claim.