X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fmonitor_tests.rs;h=c589d57405b0d52c8b6ebfbe59343d457ae0ce46;hb=c1e6a74e0b8309bc85e683824f832ac539806dc5;hp=15d0167ad46c6eabf6a3a9d0413a97538fe0df00;hpb=9fd6127ded8b70a7fe5fe693376d3d79dd4d0024;p=rust-lightning diff --git a/lightning/src/ln/monitor_tests.rs b/lightning/src/ln/monitor_tests.rs index 15d0167a..c589d574 100644 --- a/lightning/src/ln/monitor_tests.rs +++ b/lightning/src/ln/monitor_tests.rs @@ -24,7 +24,7 @@ use crate::ln::channel; use crate::ln::chan_utils; #[cfg(anchors)] use crate::ln::channelmanager::ChannelManager; -use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, PaymentId}; +use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, PaymentId, RecipientOnionFields}; use crate::ln::msgs::ChannelMessageHandler; #[cfg(anchors)] use crate::util::config::UserConfig; @@ -78,7 +78,8 @@ fn chanmon_fail_from_stale_commitment() { let (update_a, _, chan_id_2, _) = create_announced_chan_between_nodes(&nodes, 1, 2); let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000); - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap(); + nodes[0].node.send_payment_with_route(&route, payment_hash, + RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let bs_txn = get_local_commitment_txn!(nodes[1], chan_id_2); @@ -625,7 +626,8 @@ fn test_balances_on_local_commitment_htlcs() { let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 10_000_000); let htlc_cltv_timeout = nodes[0].best_block_info().1 + TEST_FINAL_CLTV + 1; // Note ChannelManager adds one to CLTV timeouts for safety - nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap(); + nodes[0].node.send_payment_with_route(&route, payment_hash, + RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -636,7 +638,8 @@ fn test_balances_on_local_commitment_htlcs() { expect_payment_claimable!(nodes[1], payment_hash, payment_secret, 10_000_000); let (route_2, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 20_000_000); - nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap(); + nodes[0].node.send_payment_with_route(&route_2, payment_hash_2, + RecipientOnionFields::secret_only(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap(); check_added_monitors!(nodes[0], 1); let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id()); @@ -1855,15 +1858,18 @@ fn test_anchors_aggregated_revoked_htlc_tx() { let chan_a = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 20_000_000); let chan_b = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 20_000_000); + // Serialize Bob with the initial state of both channels, which we'll use later. + let bob_serialized = nodes[1].node.encode(); + // Route two payments for each channel from Alice to Bob to lock in the HTLCs. let payment_a = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_b = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_c = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); let payment_d = route_payment(&nodes[0], &[&nodes[1]], 50_000_000); - // Serialize Bob with the HTLCs locked in. We'll restart Bob later on with the state at this - // point such that he broadcasts a revoked commitment transaction. - let bob_serialized = nodes[1].node.encode(); + // Serialize Bob's monitors with the HTLCs locked in. We'll restart Bob later on with the state + // at this point such that he broadcasts a revoked commitment transaction with the HTLCs + // present. let bob_serialized_monitor_a = get_monitor!(nodes[1], chan_a.2).encode(); let bob_serialized_monitor_b = get_monitor!(nodes[1], chan_b.2).encode(); @@ -1893,30 +1899,26 @@ fn test_anchors_aggregated_revoked_htlc_tx() { } } - // Bob force closes by broadcasting his revoked state for each channel. - nodes[1].node.force_close_broadcasting_latest_txn(&chan_a.2, &nodes[0].node.get_our_node_id()).unwrap(); - check_added_monitors(&nodes[1], 1); - check_closed_broadcast(&nodes[1], 1, true); - check_closed_event!(&nodes[1], 1, ClosureReason::HolderForceClosed); - let revoked_commitment_a = { - let mut txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); - assert_eq!(txn.len(), 1); - let revoked_commitment = txn.pop().unwrap(); - assert_eq!(revoked_commitment.output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs - check_spends!(revoked_commitment, chan_a.3); - revoked_commitment - }; - nodes[1].node.force_close_broadcasting_latest_txn(&chan_b.2, &nodes[0].node.get_our_node_id()).unwrap(); - check_added_monitors(&nodes[1], 1); - check_closed_broadcast(&nodes[1], 1, true); - check_closed_event!(&nodes[1], 1, ClosureReason::HolderForceClosed); - let revoked_commitment_b = { - let mut txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); - assert_eq!(txn.len(), 1); - let revoked_commitment = txn.pop().unwrap(); - assert_eq!(revoked_commitment.output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs - check_spends!(revoked_commitment, chan_b.3); - revoked_commitment + // Bob force closes by restarting with the outdated state, prompting the ChannelMonitors to + // broadcast the latest commitment transaction known to them, which in our case is the one with + // the HTLCs still pending. + nodes[1].node.timer_tick_occurred(); + check_added_monitors(&nodes[1], 2); + check_closed_event!(&nodes[1], 2, ClosureReason::OutdatedChannelManager); + let (revoked_commitment_a, revoked_commitment_b) = { + let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0); + assert_eq!(txn.len(), 2); + assert_eq!(txn[0].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs + assert_eq!(txn[1].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs + if txn[0].input[0].previous_output.txid == chan_a.3.txid() { + check_spends!(&txn[0], &chan_a.3); + check_spends!(&txn[1], &chan_b.3); + (txn[0].clone(), txn[1].clone()) + } else { + check_spends!(&txn[1], &chan_a.3); + check_spends!(&txn[0], &chan_b.3); + (txn[1].clone(), txn[0].clone()) + } }; // Bob should now receive two events to bump his revoked commitment transaction fees.