From ecaeddca475da5fab427bed5a7bed64ef9f9d216 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 23 Apr 2021 16:53:53 +0000 Subject: [PATCH] Make the PaymentSecret in `PaymentReceived` events non-Optional --- lightning/src/ln/chanmon_update_fail_tests.rs | 6 +++--- lightning/src/ln/channelmanager.rs | 2 +- lightning/src/ln/functional_test_utils.rs | 4 ++-- lightning/src/ln/functional_tests.rs | 8 ++++---- lightning/src/util/events.rs | 17 +++++++++-------- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lightning/src/ln/chanmon_update_fail_tests.rs b/lightning/src/ln/chanmon_update_fail_tests.rs index 619d02c8c..bcc115ae9 100644 --- a/lightning/src/ln/chanmon_update_fail_tests.rs +++ b/lightning/src/ln/chanmon_update_fail_tests.rs @@ -208,7 +208,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool, persister_fail match events_3[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(payment_hash_1, *payment_hash); - assert_eq!(Some(payment_secret_1), *payment_secret); + assert_eq!(payment_secret_1, *payment_secret); assert_eq!(amt, 1000000); }, _ => panic!("Unexpected event"), @@ -576,7 +576,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) { match events_5[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(payment_hash_2, *payment_hash); - assert_eq!(Some(payment_secret_2), *payment_secret); + assert_eq!(payment_secret_2, *payment_secret); assert_eq!(amt, 1000000); }, _ => panic!("Unexpected event"), @@ -690,7 +690,7 @@ fn test_monitor_update_fail_cs() { match events[0] { Event::PaymentReceived { payment_hash, payment_secret, amt, user_payment_id: _ } => { assert_eq!(payment_hash, our_payment_hash); - assert_eq!(Some(our_payment_secret), payment_secret); + assert_eq!(our_payment_secret, payment_secret); assert_eq!(amt, 1000000); }, _ => panic!("Unexpected event"), diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 1c43d8b0f..b1890853e 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2024,7 +2024,7 @@ impl ChannelMana } else if total_value == payment_data.total_msat { new_events.push(events::Event::PaymentReceived { payment_hash, - payment_secret: Some(payment_data.payment_secret), + payment_secret: payment_data.payment_secret, amt: total_value, user_payment_id: inbound_payment.get().user_payment_id, }); diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index bc1d7ef06..1b0567ab3 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -943,7 +943,7 @@ macro_rules! expect_payment_received { match events[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!($expected_payment_hash, *payment_hash); - assert_eq!(Some($expected_payment_secret), *payment_secret); + assert_eq!($expected_payment_secret, *payment_secret); assert_eq!($expected_recv_value, amt); }, _ => panic!("Unexpected event"), @@ -1011,7 +1011,7 @@ pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path match events_2[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(our_payment_hash, *payment_hash); - assert_eq!(Some(our_payment_secret), *payment_secret); + assert_eq!(our_payment_secret, *payment_secret); assert_eq!(amt, recv_value); }, _ => panic!("Unexpected event"), diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index aea006fe7..56c795d8e 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -2072,7 +2072,7 @@ fn test_channel_reserve_holding_cell_htlcs() { match events[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(our_payment_hash_21, *payment_hash); - assert_eq!(Some(our_payment_secret_21), *payment_secret); + assert_eq!(our_payment_secret_21, *payment_secret); assert_eq!(recv_value_21, amt); }, _ => panic!("Unexpected event"), @@ -2080,7 +2080,7 @@ fn test_channel_reserve_holding_cell_htlcs() { match events[1] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(our_payment_hash_22, *payment_hash); - assert_eq!(Some(our_payment_secret_22), *payment_secret); + assert_eq!(our_payment_secret_22, *payment_secret); assert_eq!(recv_value_22, amt); }, _ => panic!("Unexpected event"), @@ -3648,7 +3648,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8) { match events_2[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt, user_payment_id: _ } => { assert_eq!(payment_hash_1, *payment_hash); - assert_eq!(Some(payment_secret_1), *payment_secret); + assert_eq!(payment_secret_1, *payment_secret); assert_eq!(amt, 1000000); }, _ => panic!("Unexpected event"), @@ -3985,7 +3985,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() { match events_5[0] { Event::PaymentReceived { ref payment_hash, ref payment_secret, amt: _, user_payment_id: _ } => { assert_eq!(payment_hash_2, *payment_hash); - assert_eq!(Some(payment_secret_2), *payment_secret); + assert_eq!(payment_secret_2, *payment_secret); }, _ => panic!("Unexpected event"), } diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index 4486d0510..ad7e61177 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -63,14 +63,15 @@ pub enum Event { payment_hash: PaymentHash, /// The "payment secret". This authenticates the sender to the recipient, preventing a /// number of deanonymization attacks during the routing process. - /// As nodes upgrade, the invoices you provide should likely migrate to setting the - /// payment_secret feature to required, at which point you should fail_backwards any HTLCs - /// which have a None here. - /// Until then, however, values of None should be ignored, and only incorrect Some values - /// should result in an HTLC fail_backwards. - /// Note that, in any case, this value must be passed as-is to any fail or claim calls as - /// the HTLC index includes this value. - payment_secret: Option, + /// It is provided here for your reference, however its accuracy is enforced directly by + /// [`ChannelManager`] using the values you previously provided to + /// [`ChannelManager::create_inbound_payment`] or + /// [`ChannelManager::create_inbound_payment_for_hash`]. + /// + /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + /// [`ChannelManager::create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment + /// [`ChannelManager::create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash + payment_secret: PaymentSecret, /// The value, in thousandths of a satoshi, that this payment is for. Note that you must /// compare this to the expected value before accepting the payment (as otherwise you are /// providing proof-of-payment for less than the value you expected!). -- 2.39.5