X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpayment_tests.rs;h=e5af136656f8ab8328e47f796bb6e8c29139f5ac;hb=971f7a7e42652d5697d761df6650ae9e6dcaa5db;hp=0c94adb356084adc3bf5b13a5f547baeb4bbcf14;hpb=2e113b549d06aaab67a5119c001b53987157e2c3;p=rust-lightning diff --git a/lightning/src/ln/payment_tests.rs b/lightning/src/ln/payment_tests.rs index 0c94adb3..e5af1366 100644 --- a/lightning/src/ln/payment_tests.rs +++ b/lightning/src/ln/payment_tests.rs @@ -17,14 +17,15 @@ use crate::sign::EntropySource; use crate::chain::transaction::OutPoint; use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason, PaymentPurpose}; use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS; -use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS, RecentPaymentDetails, RecipientOnionFields, HTLCForwardInfo, PendingHTLCRouting, PendingAddHTLCInfo}; +use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, RecentPaymentDetails, RecipientOnionFields, HTLCForwardInfo, PendingHTLCRouting, PendingAddHTLCInfo}; use crate::ln::features::Bolt11InvoiceFeatures; use crate::ln::{msgs, ChannelId, PaymentSecret, PaymentPreimage}; use crate::ln::msgs::ChannelMessageHandler; -use crate::ln::outbound_payment::Retry; +use crate::ln::outbound_payment::{IDEMPOTENCY_TIMEOUT_TICKS, Retry}; use crate::routing::gossip::{EffectiveCapacity, RoutingFees}; use crate::routing::router::{get_route, Path, PaymentParameters, Route, Router, RouteHint, RouteHintHop, RouteHop, RouteParameters, find_route}; use crate::routing::scoring::ChannelUsage; +use crate::util::config::UserConfig; use crate::util::test_utils; use crate::util::errors::APIError; use crate::util::ser::Writeable; @@ -611,7 +612,7 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]); check_added_monitors!(nodes[1], 1); commitment_signed_dance!(nodes[1], nodes[2], htlc_fulfill_updates.commitment_signed, false); - expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, false, false); + expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, true, false); if confirm_before_reload { let best_block = nodes[0].blocks.lock().unwrap().last().unwrap().clone(); @@ -663,9 +664,9 @@ fn do_retry_with_no_persist(confirm_before_reload: bool) { let mut peer_state = per_peer_state.get(&nodes[2].node.get_our_node_id()) .unwrap().lock().unwrap(); let mut channel = peer_state.channel_by_id.get_mut(&chan_id_2).unwrap(); - let mut new_config = channel.context.config(); + let mut new_config = channel.context().config(); new_config.forwarding_fee_base_msat += 100_000; - channel.context.update_config(&new_config); + channel.context_mut().update_config(&new_config); new_route.paths[0].hops[0].fee_msat += 100_000; } @@ -913,7 +914,7 @@ fn do_test_dup_htlc_onchain_fails_on_reload(persist_manager_post_event: bool, co // Route a payment, but force-close the channel before the HTLC fulfill message arrives at // nodes[0]. - let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 10_000_000); + let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 10_000_000); nodes[0].node.force_close_broadcasting_latest_txn(&nodes[0].node.list_channels()[0].channel_id, &nodes[1].node.get_our_node_id()).unwrap(); check_closed_broadcast!(nodes[0], true); check_added_monitors!(nodes[0], 1); @@ -1051,7 +1052,7 @@ fn test_fulfill_restart_failure() { let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); let chan_id = create_announced_chan_between_nodes(&nodes, 0, 1).2; - let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 100_000); + let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 100_000); // The simplest way to get a failure after a fulfill is to reload nodes[1] from a state // pre-fulfill, which we do by serializing it here. @@ -1304,6 +1305,102 @@ fn onchain_failed_probe_yields_event() { assert!(!nodes[0].node.has_pending_payments()); } +#[test] +fn preflight_probes_yield_event_and_skip() { + let chanmon_cfgs = create_chanmon_cfgs(5); + let node_cfgs = create_node_cfgs(5, &chanmon_cfgs); + + // We alleviate the HTLC max-in-flight limit, as otherwise we'd always be limited through that. + let mut no_htlc_limit_config = test_default_channel_config(); + no_htlc_limit_config.channel_handshake_config.max_inbound_htlc_value_in_flight_percent_of_channel = 100; + + let user_configs = std::iter::repeat(no_htlc_limit_config).take(5).map(|c| Some(c)).collect::>>(); + let node_chanmgrs = create_node_chanmgrs(5, &node_cfgs, &user_configs); + let nodes = create_network(5, &node_cfgs, &node_chanmgrs); + + // Setup channel topology: + // (30k:0)- N2 -(1M:0) + // / \ + // N0 -(100k:0)-> N1 N4 + // \ / + // (70k:0)- N3 -(1M:0) + // + let first_chan_update = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100_000, 0).0; + create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 30_000, 0); + create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 70_000, 0); + create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 1_000_000, 0); + create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 1_000_000, 0); + + let mut invoice_features = Bolt11InvoiceFeatures::empty(); + invoice_features.set_basic_mpp_optional(); + + let mut payment_params = PaymentParameters::from_node_id(nodes[4].node.get_our_node_id(), TEST_FINAL_CLTV) + .with_bolt11_features(invoice_features).unwrap(); + + let route_params = RouteParameters { payment_params, final_value_msat: 80_000_000 }; + let res = nodes[0].node.send_preflight_probes(route_params, None).unwrap(); + + // We check that only one probe was sent, the other one was skipped due to limited liquidity. + assert_eq!(res.len(), 1); + let log_msg = format!("Skipped sending payment probe to avoid putting channel {} under the liquidity limit.", + first_chan_update.contents.short_channel_id); + node_cfgs[0].logger.assert_log_contains("lightning::ln::channelmanager", &log_msg, 1); + + let (payment_hash, payment_id) = res.first().unwrap(); + + // node[0] -- update_add_htlcs -> node[1] + check_added_monitors!(nodes[0], 1); + let probe_event = SendEvent::from_node(&nodes[0]); + nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &probe_event.msgs[0]); + check_added_monitors!(nodes[1], 0); + commitment_signed_dance!(nodes[1], nodes[0], probe_event.commitment_msg, false); + expect_pending_htlcs_forwardable!(nodes[1]); + + // node[1] -- update_add_htlcs -> node[2] + check_added_monitors!(nodes[1], 1); + let probe_event = SendEvent::from_node(&nodes[1]); + nodes[2].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &probe_event.msgs[0]); + check_added_monitors!(nodes[2], 0); + commitment_signed_dance!(nodes[2], nodes[1], probe_event.commitment_msg, false); + expect_pending_htlcs_forwardable!(nodes[2]); + + // node[2] -- update_add_htlcs -> node[4] + check_added_monitors!(nodes[2], 1); + let probe_event = SendEvent::from_node(&nodes[2]); + nodes[4].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &probe_event.msgs[0]); + check_added_monitors!(nodes[4], 0); + commitment_signed_dance!(nodes[4], nodes[2], probe_event.commitment_msg, true, true); + + // node[2] <- update_fail_htlcs -- node[4] + let updates = get_htlc_update_msgs!(nodes[4], nodes[2].node.get_our_node_id()); + nodes[2].node.handle_update_fail_htlc(&nodes[4].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + check_added_monitors!(nodes[2], 0); + commitment_signed_dance!(nodes[2], nodes[4], updates.commitment_signed, true); + + // node[1] <- update_fail_htlcs -- node[2] + let updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id()); + nodes[1].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + check_added_monitors!(nodes[1], 0); + commitment_signed_dance!(nodes[1], nodes[2], updates.commitment_signed, true); + + // node[0] <- update_fail_htlcs -- node[1] + let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id()); + nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]); + check_added_monitors!(nodes[0], 0); + commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, false); + + let mut events = nodes[0].node.get_and_clear_pending_events(); + assert_eq!(events.len(), 1); + match events.drain(..).next().unwrap() { + crate::events::Event::ProbeSuccessful { payment_id: ev_pid, payment_hash: ev_ph, .. } => { + assert_eq!(*payment_id, ev_pid); + assert_eq!(*payment_hash, ev_ph); + }, + _ => panic!(), + }; + assert!(!nodes[0].node.has_pending_payments()); +} + #[test] fn claimed_send_payment_idempotent() { // Tests that `send_payment` (and friends) are (reasonably) idempotent. @@ -1459,7 +1556,7 @@ fn test_trivial_inflight_htlc_tracking(){ let (_, _, chan_2_id, _) = create_announced_chan_between_nodes(&nodes, 1, 2); // Send and claim the payment. Inflight HTLCs should be empty. - let payment_hash = send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 500000).1; + let (_, payment_hash, _, payment_id) = send_payment(&nodes[0], &[&nodes[1], &nodes[2]], 500000); let inflight_htlcs = node_chanmgrs[0].compute_inflight_htlcs(); { let mut node_0_per_peer_lock; @@ -1469,7 +1566,7 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()), - channel_1.context.get_short_channel_id().unwrap() + channel_1.context().get_short_channel_id().unwrap() ); assert_eq!(chan_1_used_liquidity, None); } @@ -1481,14 +1578,14 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[2].node.get_our_node_id()), - channel_2.context.get_short_channel_id().unwrap() + channel_2.context().get_short_channel_id().unwrap() ); assert_eq!(chan_2_used_liquidity, None); } let pending_payments = nodes[0].node.list_recent_payments(); assert_eq!(pending_payments.len(), 1); - assert_eq!(pending_payments[0], RecentPaymentDetails::Fulfilled { payment_hash: Some(payment_hash) }); + assert_eq!(pending_payments[0], RecentPaymentDetails::Fulfilled { payment_hash: Some(payment_hash), payment_id }); // Remove fulfilled payment for _ in 0..=IDEMPOTENCY_TIMEOUT_TICKS { @@ -1496,7 +1593,7 @@ fn test_trivial_inflight_htlc_tracking(){ } // Send the payment, but do not claim it. Our inflight HTLCs should contain the pending payment. - let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 500000); + let (payment_preimage, payment_hash, _, payment_id) = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 500000); let inflight_htlcs = node_chanmgrs[0].compute_inflight_htlcs(); { let mut node_0_per_peer_lock; @@ -1506,7 +1603,7 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()), - channel_1.context.get_short_channel_id().unwrap() + channel_1.context().get_short_channel_id().unwrap() ); // First hop accounts for expected 1000 msat fee assert_eq!(chan_1_used_liquidity, Some(501000)); @@ -1519,14 +1616,14 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[2].node.get_our_node_id()), - channel_2.context.get_short_channel_id().unwrap() + channel_2.context().get_short_channel_id().unwrap() ); assert_eq!(chan_2_used_liquidity, Some(500000)); } let pending_payments = nodes[0].node.list_recent_payments(); assert_eq!(pending_payments.len(), 1); - assert_eq!(pending_payments[0], RecentPaymentDetails::Pending { payment_hash, total_msat: 500000 }); + assert_eq!(pending_payments[0], RecentPaymentDetails::Pending { payment_id, payment_hash, total_msat: 500000 }); // Now, let's claim the payment. This should result in the used liquidity to return `None`. claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage); @@ -1545,7 +1642,7 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_1_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()), - channel_1.context.get_short_channel_id().unwrap() + channel_1.context().get_short_channel_id().unwrap() ); assert_eq!(chan_1_used_liquidity, None); } @@ -1557,7 +1654,7 @@ fn test_trivial_inflight_htlc_tracking(){ let chan_2_used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[2].node.get_our_node_id()), - channel_2.context.get_short_channel_id().unwrap() + channel_2.context().get_short_channel_id().unwrap() ); assert_eq!(chan_2_used_liquidity, None); } @@ -1598,7 +1695,7 @@ fn test_holding_cell_inflight_htlcs() { let used_liquidity = inflight_htlcs.used_liquidity_msat( &NodeId::from_pubkey(&nodes[0].node.get_our_node_id()) , &NodeId::from_pubkey(&nodes[1].node.get_our_node_id()), - channel.context.get_short_channel_id().unwrap() + channel.context().get_short_channel_id().unwrap() ); assert_eq!(used_liquidity, Some(2000000)); @@ -1691,7 +1788,7 @@ fn do_test_intercepted_payment(test: InterceptTest) { // Check for unknown channel id error. let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &ChannelId::from_bytes([42; 32]), nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err(); assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { - err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.", + err: format!("Channel with id {} not found for the passed counterparty node_id {}.", log_bytes!([42; 32]), nodes[2].node.get_our_node_id()) }); if test == InterceptTest::Fail { @@ -1717,8 +1814,8 @@ fn do_test_intercepted_payment(test: InterceptTest) { let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap(); let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err(); assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { - err: format!("Funded channel with id {} not found for the passed counterparty node_id {}. Channel may still be opening.", - &temp_chan_id, nodes[2].node.get_our_node_id()) }); + err: format!("Channel with id {} for the passed counterparty node_id {} is still opening.", + temp_chan_id, nodes[2].node.get_our_node_id()) }); assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1); // Open the just-in-time channel so the payment can then be forwarded. @@ -2161,12 +2258,14 @@ fn auto_retry_partial_failure() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); + // Open three channels, the first has plenty of liquidity, the second and third have ~no + // available liquidity, causing any outbound payments routed over it to fail immediately. let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id; - let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id; - let chan_3_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id; + let chan_2_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id; + let chan_3_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id; // Marshall data to send the payment - let amt_msat = 20_000; + let amt_msat = 10_000_000; let (_, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat); #[cfg(feature = "std")] let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60; @@ -2181,16 +2280,6 @@ fn auto_retry_partial_failure() { .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat); - // Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the - // second (for the initial send path2 over chan_2) fails. - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure); - // Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for - // the retry1's path2 over chan_3) fails, and monitor updates succeed after that. - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure); - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed); - // Configure the initial send, retry1 and retry2's paths. let send_route = Route { paths: vec![ @@ -2201,6 +2290,7 @@ fn auto_retry_partial_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: amt_msat / 2, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[1].node.get_our_node_id(), @@ -2209,6 +2299,7 @@ fn auto_retry_partial_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: amt_msat / 2, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, ], route_params: Some(route_params.clone()), @@ -2222,6 +2313,7 @@ fn auto_retry_partial_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: amt_msat / 4, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[1].node.get_our_node_id(), @@ -2230,6 +2322,7 @@ fn auto_retry_partial_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: amt_msat / 4, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, ], route_params: Some(route_params.clone()), @@ -2243,6 +2336,7 @@ fn auto_retry_partial_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: amt_msat / 4, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, ], route_params: Some(route_params.clone()), @@ -2262,32 +2356,23 @@ fn auto_retry_partial_failure() { // Send a payment that will partially fail on send, then partially fail on retry, then succeed. nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(3)).unwrap(); - let closed_chan_events = nodes[0].node.get_and_clear_pending_events(); - assert_eq!(closed_chan_events.len(), 4); - match closed_chan_events[0] { - Event::ChannelClosed { .. } => {}, - _ => panic!("Unexpected event"), - } - match closed_chan_events[1] { + let payment_failed_events = nodes[0].node.get_and_clear_pending_events(); + assert_eq!(payment_failed_events.len(), 2); + match payment_failed_events[0] { Event::PaymentPathFailed { .. } => {}, _ => panic!("Unexpected event"), } - match closed_chan_events[2] { - Event::ChannelClosed { .. } => {}, - _ => panic!("Unexpected event"), - } - match closed_chan_events[3] { + match payment_failed_events[1] { Event::PaymentPathFailed { .. } => {}, _ => panic!("Unexpected event"), } // Pass the first part of the payment along the path. - check_added_monitors!(nodes[0], 5); // three outbound channel updates succeeded, two permanently failed + check_added_monitors!(nodes[0], 1); // only one HTLC actually made it out let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events(); - // First message is the first update_add, remaining messages are broadcasting channel updates and - // errors for the permfailed channels - assert_eq!(msg_events.len(), 5); + // Only one HTLC/channel update actually made it out + assert_eq!(msg_events.len(), 1); let mut payment_event = SendEvent::from_event(msg_events.remove(0)); nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]); @@ -2376,12 +2461,13 @@ fn auto_retry_zero_attempts_send_error() { let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs); - create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id; - create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id; + // Open a single channel that does not have sufficient liquidity for the payment we want to + // send. + let chan_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id; // Marshall data to send the payment - let amt_msat = 20_000; - let (_, payment_hash, _, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat); + let amt_msat = 10_000_000; + let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None); #[cfg(feature = "std")] let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60; #[cfg(not(feature = "std"))] @@ -2395,16 +2481,31 @@ fn auto_retry_zero_attempts_send_error() { .with_bolt11_features(invoice_features).unwrap(); let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat); - chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure); + // Override the route search to return a route, rather than failing at the route-finding step. + let send_route = Route { + paths: vec![ + Path { hops: vec![RouteHop { + pubkey: nodes[1].node.get_our_node_id(), + node_features: nodes[1].node.node_features(), + short_channel_id: chan_id, + channel_features: nodes[1].node.channel_features(), + fee_msat: amt_msat, + cltv_expiry_delta: 100, + maybe_announced_channel: true, + }], blinded_tail: None }, + ], + route_params: Some(route_params.clone()), + }; + nodes[0].router.expect_find_route(route_params.clone(), Ok(send_route)); + nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap(); - assert_eq!(nodes[0].node.get_and_clear_pending_msg_events().len(), 2); // channel close messages + assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty()); let events = nodes[0].node.get_and_clear_pending_events(); - assert_eq!(events.len(), 3); - if let Event::ChannelClosed { .. } = events[0] { } else { panic!(); } - if let Event::PaymentPathFailed { .. } = events[1] { } else { panic!(); } - if let Event::PaymentFailed { .. } = events[2] { } else { panic!(); } - check_added_monitors!(nodes[0], 2); + assert_eq!(events.len(), 2); + if let Event::PaymentPathFailed { .. } = events[0] { } else { panic!(); } + if let Event::PaymentFailed { .. } = events[1] { } else { panic!(); } + check_added_monitors!(nodes[0], 0); } #[test] @@ -2487,6 +2588,7 @@ fn retry_multi_path_single_failed_payment() { channel_features: nodes[1].node.channel_features(), fee_msat: 10_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[1].node.get_our_node_id(), @@ -2495,6 +2597,7 @@ fn retry_multi_path_single_failed_payment() { channel_features: nodes[1].node.channel_features(), fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, ], route_params: Some(route_params.clone()), @@ -2576,6 +2679,7 @@ fn immediate_retry_on_failure() { channel_features: nodes[1].node.channel_features(), fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, ], route_params: Some(RouteParameters::from_payment_params_and_value( @@ -2662,6 +2766,7 @@ fn no_extra_retries_on_back_to_back_fail() { channel_features: nodes[1].node.channel_features(), fee_msat: 0, // nodes[1] will fail the payment as we don't pay its fee cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[2].node.get_our_node_id(), node_features: nodes[2].node.node_features(), @@ -2669,6 +2774,7 @@ fn no_extra_retries_on_back_to_back_fail() { channel_features: nodes[2].node.channel_features(), fee_msat: 100_000_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[1].node.get_our_node_id(), @@ -2677,6 +2783,7 @@ fn no_extra_retries_on_back_to_back_fail() { channel_features: nodes[1].node.channel_features(), fee_msat: 0, // nodes[1] will fail the payment as we don't pay its fee cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[2].node.get_our_node_id(), node_features: nodes[2].node.node_features(), @@ -2684,6 +2791,7 @@ fn no_extra_retries_on_back_to_back_fail() { channel_features: nodes[2].node.channel_features(), fee_msat: 100_000_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None } ], route_params: Some(RouteParameters::from_payment_params_and_value( @@ -2862,6 +2970,7 @@ fn test_simple_partial_retry() { channel_features: nodes[1].node.channel_features(), fee_msat: 0, // nodes[1] will fail the payment as we don't pay its fee cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[2].node.get_our_node_id(), node_features: nodes[2].node.node_features(), @@ -2869,6 +2978,7 @@ fn test_simple_partial_retry() { channel_features: nodes[2].node.channel_features(), fee_msat: 100_000_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[1].node.get_our_node_id(), @@ -2877,6 +2987,7 @@ fn test_simple_partial_retry() { channel_features: nodes[1].node.channel_features(), fee_msat: 100_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[2].node.get_our_node_id(), node_features: nodes[2].node.node_features(), @@ -2884,6 +2995,7 @@ fn test_simple_partial_retry() { channel_features: nodes[2].node.channel_features(), fee_msat: 100_000_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None } ], route_params: Some(RouteParameters::from_payment_params_and_value( @@ -3026,6 +3138,7 @@ fn test_threaded_payment_retries() { channel_features: nodes[1].node.channel_features(), fee_msat: 0, cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[3].node.get_our_node_id(), node_features: nodes[2].node.node_features(), @@ -3033,6 +3146,7 @@ fn test_threaded_payment_retries() { channel_features: nodes[2].node.channel_features(), fee_msat: amt_msat / 1000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None }, Path { hops: vec![RouteHop { pubkey: nodes[2].node.get_our_node_id(), @@ -3041,6 +3155,7 @@ fn test_threaded_payment_retries() { channel_features: nodes[2].node.channel_features(), fee_msat: 100_000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }, RouteHop { pubkey: nodes[3].node.get_our_node_id(), node_features: nodes[3].node.node_features(), @@ -3048,6 +3163,7 @@ fn test_threaded_payment_retries() { channel_features: nodes[3].node.channel_features(), fee_msat: amt_msat - amt_msat / 1000, cltv_expiry_delta: 100, + maybe_announced_channel: true, }], blinded_tail: None } ], route_params: Some(RouteParameters::from_payment_params_and_value( @@ -3159,7 +3275,7 @@ fn do_no_missing_sent_on_reload(persist_manager_with_payment: bool, at_midpoint: nodes_0_serialized = nodes[0].node.encode(); } - let (our_payment_preimage, our_payment_hash, _) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000); + let (our_payment_preimage, our_payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 1_000_000); if persist_manager_with_payment { nodes_0_serialized = nodes[0].node.encode();