Skip to content

Commit 47bcc18

Browse files
tests: make PaymentSecret optional in pass_along path
and use it to make more keysend tests
1 parent 0328be3 commit 47bcc18

File tree

4 files changed

+282
-13
lines changed

4 files changed

+282
-13
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,15 +2039,15 @@ fn test_path_paused_mpp() {
20392039
// Pass the first HTLC of the payment along to nodes[3].
20402040
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20412041
assert_eq!(events.len(), 1);
2042-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), payment_secret, events.pop().unwrap(), false, None);
2042+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), false, None);
20432043

20442044
// And check that, after we successfully update the monitor for chan_2 we can pass the second
20452045
// HTLC along to nodes[3] and claim the whole payment back to nodes[0].
20462046
let (outpoint, latest_update) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2_id).unwrap().clone();
20472047
nodes[0].node.channel_monitor_updated(&outpoint, latest_update);
20482048
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
20492049
assert_eq!(events.len(), 1);
2050-
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), payment_secret, events.pop().unwrap(), true, None);
2050+
pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 200_000, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), true, None);
20512051

20522052
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], false, payment_preimage);
20532053
}

lightning/src/ln/channelmanager.rs

Lines changed: 270 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5108,14 +5108,21 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
51085108

51095109
#[cfg(test)]
51105110
mod tests {
5111-
use ln::channelmanager::PersistenceNotifier;
5112-
use sync::Arc;
5111+
use bitcoin::hashes::Hash;
5112+
use bitcoin::hashes::sha256::Hash as Sha256;
51135113
use core::sync::atomic::{AtomicBool, Ordering};
5114-
use std::thread;
51155114
use core::time::Duration;
5115+
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
5116+
use ln::channelmanager::PersistenceNotifier;
5117+
use ln::features::{InitFeatures, InvoiceFeatures};
51165118
use ln::functional_test_utils::*;
5117-
use ln::features::InitFeatures;
5119+
use ln::msgs;
51185120
use ln::msgs::ChannelMessageHandler;
5121+
use routing::router::{get_keysend_route, get_route};
5122+
use util::events::{Event, MessageSendEvent, MessageSendEventsProvider};
5123+
use util::test_utils;
5124+
use std::sync::Arc;
5125+
use std::thread;
51195126

51205127
#[cfg(feature = "std")]
51215128
#[test]
@@ -5231,6 +5238,265 @@ mod tests {
52315238
assert_ne!(nodes[0].node.list_channels()[0], node_a_chan_info);
52325239
assert_ne!(nodes[1].node.list_channels()[0], node_b_chan_info);
52335240
}
5241+
5242+
#[test]
5243+
fn test_keysend_dup_hash_partial_mpp() {
5244+
// Test that a keysend payment with a duplicate hash to an existing partial MPP payment fails as
5245+
// expected.
5246+
let chanmon_cfgs = create_chanmon_cfgs(2);
5247+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
5248+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
5249+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
5250+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
5251+
let logger = test_utils::TestLogger::new();
5252+
5253+
// First, send a partial MPP payment.
5254+
let net_graph_msg_handler = &nodes[0].net_graph_msg_handler;
5255+
let route = get_route(&nodes[0].node.get_our_node_id(), &net_graph_msg_handler.network_graph.read().unwrap(), &nodes[1].node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5256+
let (payment_preimage, our_payment_hash, payment_secret) = get_payment_preimage_hash!(&nodes[1]);
5257+
// Use the utility function send_payment_along_path to send the payment with MPP data which
5258+
// indicates there are more HTLCs coming.
5259+
let cur_height = CHAN_CONFIRM_DEPTH + 1; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
5260+
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, &None).unwrap();
5261+
check_added_monitors!(nodes[0], 1);
5262+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5263+
assert_eq!(events.len(), 1);
5264+
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), false, None);
5265+
5266+
// Next, send a keysend payment with the same payment_hash and make sure it fails.
5267+
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
5268+
check_added_monitors!(nodes[0], 1);
5269+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5270+
assert_eq!(events.len(), 1);
5271+
let ev = events.drain(..).next().unwrap();
5272+
let payment_event = SendEvent::from_event(ev);
5273+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
5274+
check_added_monitors!(nodes[1], 0);
5275+
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
5276+
expect_pending_htlcs_forwardable!(nodes[1]);
5277+
expect_pending_htlcs_forwardable!(nodes[1]);
5278+
check_added_monitors!(nodes[1], 1);
5279+
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
5280+
assert!(updates.update_add_htlcs.is_empty());
5281+
assert!(updates.update_fulfill_htlcs.is_empty());
5282+
assert_eq!(updates.update_fail_htlcs.len(), 1);
5283+
assert!(updates.update_fail_malformed_htlcs.is_empty());
5284+
assert!(updates.update_fee.is_none());
5285+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]);
5286+
commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true);
5287+
expect_payment_failed!(nodes[0], our_payment_hash, true);
5288+
5289+
// Send the second half of the original MPP payment.
5290+
nodes[0].node.send_payment_along_path(&route.paths[0], &our_payment_hash, &Some(payment_secret), 200_000, cur_height, &None).unwrap();
5291+
check_added_monitors!(nodes[0], 1);
5292+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5293+
assert_eq!(events.len(), 1);
5294+
pass_along_path(&nodes[0], &[&nodes[1]], 200_000, our_payment_hash, Some(payment_secret), events.drain(..).next().unwrap(), true, None);
5295+
5296+
// Claim the full MPP payment. Note that we can't use a test utility like
5297+
// claim_funds_along_route because the ordering of the messages causes the second half of the
5298+
// payment to be put in the holding cell, which confuses the test utilities. So we exchange the
5299+
// lightning messages manually.
5300+
assert!(nodes[1].node.claim_funds(payment_preimage));
5301+
check_added_monitors!(nodes[1], 2);
5302+
let bs_first_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
5303+
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_first_updates.update_fulfill_htlcs[0]);
5304+
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_first_updates.commitment_signed);
5305+
check_added_monitors!(nodes[0], 1);
5306+
let (as_first_raa, as_first_cs) = get_revoke_commit_msgs!(nodes[0], nodes[1].node.get_our_node_id());
5307+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_first_raa);
5308+
check_added_monitors!(nodes[1], 1);
5309+
let bs_second_updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
5310+
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_first_cs);
5311+
check_added_monitors!(nodes[1], 1);
5312+
let bs_first_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id());
5313+
nodes[0].node.handle_update_fulfill_htlc(&nodes[1].node.get_our_node_id(), &bs_second_updates.update_fulfill_htlcs[0]);
5314+
nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_second_updates.commitment_signed);
5315+
check_added_monitors!(nodes[0], 1);
5316+
let as_second_raa = get_event_msg!(nodes[0], MessageSendEvent::SendRevokeAndACK, nodes[1].node.get_our_node_id());
5317+
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_first_raa);
5318+
let as_second_updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
5319+
check_added_monitors!(nodes[0], 1);
5320+
nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_second_raa);
5321+
check_added_monitors!(nodes[1], 1);
5322+
nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_second_updates.commitment_signed);
5323+
check_added_monitors!(nodes[1], 1);
5324+
let bs_third_raa = get_event_msg!(nodes[1], MessageSendEvent::SendRevokeAndACK, nodes[0].node.get_our_node_id());
5325+
nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_third_raa);
5326+
check_added_monitors!(nodes[0], 1);
5327+
5328+
// There's an existing bug that generates a PaymentSent event for each MPP path, so handle that here.
5329+
let events = nodes[0].node.get_and_clear_pending_events();
5330+
match events[0] {
5331+
Event::PaymentSent { payment_preimage: ref preimage } => {
5332+
assert_eq!(payment_preimage, *preimage);
5333+
},
5334+
_ => panic!("Unexpected event"),
5335+
}
5336+
match events[1] {
5337+
Event::PaymentSent { payment_preimage: ref preimage } => {
5338+
assert_eq!(payment_preimage, *preimage);
5339+
},
5340+
_ => panic!("Unexpected event"),
5341+
}
5342+
}
5343+
5344+
#[test]
5345+
fn test_keysend_dup_payment_hash() {
5346+
// (1): Test that a keysend payment with a duplicate payment hash to an existing pending
5347+
// outbound regular payment fails as expected.
5348+
// (2): Test that a regular payment with a duplicate payment hash to an existing keysend payment
5349+
// fails as expected.
5350+
let chanmon_cfgs = create_chanmon_cfgs(2);
5351+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
5352+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
5353+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
5354+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
5355+
let logger = test_utils::TestLogger::new();
5356+
5357+
// To start (1), send a regular payment but don't claim it.
5358+
let expected_route = [&nodes[1]];
5359+
let (payment_preimage, payment_hash, _) = route_payment(&nodes[0], &expected_route, 100_000);
5360+
5361+
// Next, attempt a keysend payment and make sure it fails.
5362+
let route = get_route(&nodes[0].node.get_our_node_id(), &nodes[0].net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5363+
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
5364+
check_added_monitors!(nodes[0], 1);
5365+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5366+
assert_eq!(events.len(), 1);
5367+
let ev = events.drain(..).next().unwrap();
5368+
let payment_event = SendEvent::from_event(ev);
5369+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
5370+
check_added_monitors!(nodes[1], 0);
5371+
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
5372+
expect_pending_htlcs_forwardable!(nodes[1]);
5373+
expect_pending_htlcs_forwardable!(nodes[1]);
5374+
check_added_monitors!(nodes[1], 1);
5375+
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
5376+
assert!(updates.update_add_htlcs.is_empty());
5377+
assert!(updates.update_fulfill_htlcs.is_empty());
5378+
assert_eq!(updates.update_fail_htlcs.len(), 1);
5379+
assert!(updates.update_fail_malformed_htlcs.is_empty());
5380+
assert!(updates.update_fee.is_none());
5381+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]);
5382+
commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true);
5383+
expect_payment_failed!(nodes[0], payment_hash, true);
5384+
5385+
// Finally, claim the original payment.
5386+
claim_payment(&nodes[0], &expected_route, payment_preimage);
5387+
5388+
// To start (2), send a keysend payment but don't claim it.
5389+
let payment_preimage = PaymentPreimage([42; 32]);
5390+
let route = get_route(&nodes[0].node.get_our_node_id(), &nodes[0].net_graph_msg_handler.network_graph.read().unwrap(), &expected_route.last().unwrap().node.get_our_node_id(), Some(InvoiceFeatures::known()), None, &Vec::new(), 100_000, TEST_FINAL_CLTV, &logger).unwrap();
5391+
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage)).unwrap();
5392+
check_added_monitors!(nodes[0], 1);
5393+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5394+
assert_eq!(events.len(), 1);
5395+
let event = events.pop().unwrap();
5396+
let path = vec![&nodes[1]];
5397+
pass_along_path(&nodes[0], &path, 100_000, payment_hash, None, event, true, Some(payment_preimage));
5398+
5399+
// Next, attempt a regular payment and make sure it fails.
5400+
let payment_secret = PaymentSecret([43; 32]);
5401+
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap();
5402+
check_added_monitors!(nodes[0], 1);
5403+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
5404+
assert_eq!(events.len(), 1);
5405+
let ev = events.drain(..).next().unwrap();
5406+
let payment_event = SendEvent::from_event(ev);
5407+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
5408+
check_added_monitors!(nodes[1], 0);
5409+
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
5410+
expect_pending_htlcs_forwardable!(nodes[1]);
5411+
expect_pending_htlcs_forwardable!(nodes[1]);
5412+
check_added_monitors!(nodes[1], 1);
5413+
let updates = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
5414+
assert!(updates.update_add_htlcs.is_empty());
5415+
assert!(updates.update_fulfill_htlcs.is_empty());
5416+
assert_eq!(updates.update_fail_htlcs.len(), 1);
5417+
assert!(updates.update_fail_malformed_htlcs.is_empty());
5418+
assert!(updates.update_fee.is_none());
5419+
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates.update_fail_htlcs[0]);
5420+
commitment_signed_dance!(nodes[0], nodes[1], updates.commitment_signed, true, true);
5421+
expect_payment_failed!(nodes[0], payment_hash, true);
5422+
5423+
// Finally, succeed the keysend payment.
5424+
claim_payment(&nodes[0], &expected_route, payment_preimage);
5425+
}
5426+
5427+
#[test]
5428+
fn test_keysend_hash_mismatch() {
5429+
// Test that if we receive a keysend `update_add_htlc` msg, we fail as expected if the keysend
5430+
// preimage doesn't match the msg's payment hash.
5431+
let chanmon_cfgs = create_chanmon_cfgs(2);
5432+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
5433+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
5434+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
5435+
5436+
let payer_pubkey = nodes[0].node.get_our_node_id();
5437+
let payee_pubkey = nodes[1].node.get_our_node_id();
5438+
nodes[0].node.peer_connected(&payee_pubkey, &msgs::Init { features: InitFeatures::known() });
5439+
nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() });
5440+
5441+
let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known());
5442+
let network_graph = nodes[0].net_graph_msg_handler.network_graph.read().unwrap();
5443+
let first_hops = nodes[0].node.list_usable_channels();
5444+
let route = get_keysend_route(&payer_pubkey, &network_graph, &payee_pubkey,
5445+
Some(&first_hops.iter().collect::<Vec<_>>()), &vec![], 10000, 40,
5446+
nodes[0].logger).unwrap();
5447+
5448+
let test_preimage = PaymentPreimage([42; 32]);
5449+
let mismatch_payment_hash = PaymentHash([43; 32]);
5450+
let _ = nodes[0].node.send_payment_internal(&route, mismatch_payment_hash, &None, Some(test_preimage)).unwrap();
5451+
check_added_monitors!(nodes[0], 1);
5452+
5453+
let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
5454+
assert_eq!(updates.update_add_htlcs.len(), 1);
5455+
assert!(updates.update_fulfill_htlcs.is_empty());
5456+
assert!(updates.update_fail_htlcs.is_empty());
5457+
assert!(updates.update_fail_malformed_htlcs.is_empty());
5458+
assert!(updates.update_fee.is_none());
5459+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
5460+
5461+
nodes[1].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "Payment preimage didn't match payment hash".to_string(), 1);
5462+
}
5463+
5464+
#[test]
5465+
fn test_keysend_msg_with_secret_err() {
5466+
// Test that we error as expected if we receive a keysend payment that includes a payment secret.
5467+
let chanmon_cfgs = create_chanmon_cfgs(2);
5468+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
5469+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
5470+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
5471+
5472+
let payer_pubkey = nodes[0].node.get_our_node_id();
5473+
let payee_pubkey = nodes[1].node.get_our_node_id();
5474+
nodes[0].node.peer_connected(&payee_pubkey, &msgs::Init { features: InitFeatures::known() });
5475+
nodes[1].node.peer_connected(&payer_pubkey, &msgs::Init { features: InitFeatures::known() });
5476+
5477+
let _chan = create_chan_between_nodes(&nodes[0], &nodes[1], InitFeatures::known(), InitFeatures::known());
5478+
let network_graph = nodes[0].net_graph_msg_handler.network_graph.read().unwrap();
5479+
let first_hops = nodes[0].node.list_usable_channels();
5480+
let route = get_keysend_route(&payer_pubkey, &network_graph, &payee_pubkey,
5481+
Some(&first_hops.iter().collect::<Vec<_>>()), &vec![], 10000, 40,
5482+
nodes[0].logger).unwrap();
5483+
5484+
let test_preimage = PaymentPreimage([42; 32]);
5485+
let test_secret = PaymentSecret([43; 32]);
5486+
let payment_hash = PaymentHash(Sha256::hash(&test_preimage.0).into_inner());
5487+
let _ = nodes[0].node.send_payment_internal(&route, payment_hash, &Some(test_secret), Some(test_preimage)).unwrap();
5488+
check_added_monitors!(nodes[0], 1);
5489+
5490+
let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
5491+
assert_eq!(updates.update_add_htlcs.len(), 1);
5492+
assert!(updates.update_fulfill_htlcs.is_empty());
5493+
assert!(updates.update_fail_htlcs.is_empty());
5494+
assert!(updates.update_fail_malformed_htlcs.is_empty());
5495+
assert!(updates.update_fee.is_none());
5496+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
5497+
5498+
nodes[1].logger.assert_log_contains("lightning::ln::channelmanager".to_string(), "We don't support MPP keysend payments".to_string(), 1);
5499+
}
52345500
}
52355501

52365502
#[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))]

lightning/src/ln/functional_test_utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>,
10561056
pass_along_route(origin_node, expected_paths, recv_value, our_payment_hash, our_payment_secret);
10571057
}
10581058

1059-
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret, ev: MessageSendEvent, payment_received_expected: bool, expected_preimage: Option<PaymentPreimage>) {
1059+
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_received_expected: bool, expected_preimage: Option<PaymentPreimage>) {
10601060
let mut payment_event = SendEvent::from_event(ev);
10611061
let mut prev_node = origin_node;
10621062

@@ -1079,9 +1079,12 @@ pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path
10791079
match &purpose {
10801080
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
10811081
assert_eq!(expected_preimage, *payment_preimage);
1082-
assert_eq!(our_payment_secret, *payment_secret);
1082+
assert_eq!(our_payment_secret.unwrap(), *payment_secret);
1083+
},
1084+
PaymentPurpose::SpontaneousPayment(payment_preimage) => {
1085+
assert_eq!(expected_preimage.unwrap(), *payment_preimage);
1086+
assert!(our_payment_secret.is_none());
10831087
},
1084-
_ => {},
10851088
}
10861089
assert_eq!(amt, recv_value);
10871090
},
@@ -1109,7 +1112,7 @@ pub fn pass_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_rou
11091112
// Once we've gotten through all the HTLCs, the last one should result in a
11101113
// PaymentReceived (but each previous one should not!), .
11111114
let expect_payment = path_idx == expected_route.len() - 1;
1112-
pass_along_path(origin_node, expected_path, recv_value, our_payment_hash.clone(), our_payment_secret, ev, expect_payment, None);
1115+
pass_along_path(origin_node, expected_path, recv_value, our_payment_hash.clone(), Some(our_payment_secret), ev, expect_payment, None);
11131116
}
11141117
}
11151118

0 commit comments

Comments
 (0)