]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add PaymentId to PaymentSent event
authorJeffrey Czyz <jkczyz@gmail.com>
Sun, 17 Oct 2021 22:21:01 +0000 (17:21 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Tue, 26 Oct 2021 06:12:30 +0000 (01:12 -0500)
The payment_hash may not uniquely identify the payment if it has been
reused. Include the payment_id in PaymentSent events so it can
correlated with the send_payment call.

lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/util/events.rs

index 0b1c16d35779948316b733ac1f431f12286533f3..e9b93237e3262222c7d384670be6423ea0bd4661 100644 (file)
@@ -304,7 +304,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
                                let events_3 = nodes[0].node.get_and_clear_pending_events();
                                assert_eq!(events_3.len(), 1);
                                match events_3[0] {
-                                       Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                                       Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                                assert_eq!(*payment_preimage, payment_preimage_1);
                                                assert_eq!(*payment_hash, payment_hash_1);
                                        },
@@ -397,7 +397,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
                        let events_3 = nodes[0].node.get_and_clear_pending_events();
                        assert_eq!(events_3.len(), 1);
                        match events_3[0] {
-                               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                        assert_eq!(*payment_preimage, payment_preimage_1);
                                        assert_eq!(*payment_hash, payment_hash_1);
                                },
@@ -1399,7 +1399,7 @@ fn claim_while_disconnected_monitor_update_fail() {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(*payment_preimage, payment_preimage_1);
                        assert_eq!(*payment_hash, payment_hash_1);
                },
@@ -1806,7 +1806,7 @@ fn monitor_update_claim_fail_no_response() {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(*payment_preimage, payment_preimage_1);
                        assert_eq!(*payment_hash, payment_hash_1);
                },
index 4eb67af2e51299d8ba2577b2d72a051576bdaa93..8e911876fa9bb89ba7697418eb0f3c2c3d3da9de 100644 (file)
@@ -3475,6 +3475,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                                        let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner());
                                        self.pending_events.lock().unwrap().push(
                                                events::Event::PaymentSent {
+                                                       payment_id: Some(payment_id),
                                                        payment_preimage,
                                                        payment_hash: payment_hash
                                                }
@@ -6256,7 +6257,8 @@ mod tests {
                // further events will be generated for subsequence path successes.
                let events = nodes[0].node.get_and_clear_pending_events();
                match events[0] {
-                       Event::PaymentSent { payment_preimage: ref preimage, payment_hash: ref hash } => {
+                       Event::PaymentSent { payment_id: ref id, payment_preimage: ref preimage, payment_hash: ref hash } => {
+                               assert_eq!(Some(payment_id), *id);
                                assert_eq!(payment_preimage, *preimage);
                                assert_eq!(our_payment_hash, *hash);
                        },
index 13fe7f73c31f02f0b78515371405e600560a64fb..014cf3b7ddb777c22ce125039252ceea890f4ee8 100644 (file)
@@ -1085,7 +1085,7 @@ macro_rules! expect_payment_sent {
                let expected_payment_hash = PaymentHash(Sha256::hash(&$expected_payment_preimage.0).into_inner());
                assert_eq!(events.len(), 1);
                match events[0] {
-                       Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                       Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                assert_eq!($expected_payment_preimage, *payment_preimage);
                                assert_eq!(expected_payment_hash, *payment_hash);
                        },
index 7c8bd075fa31ff68b465cb7884f482705e8c687a..d92b914b0b54cad17ca804953914c0f34a91f7b0 100644 (file)
@@ -2659,7 +2659,7 @@ fn test_htlc_on_chain_success() {
        let mut first_claimed = false;
        for event in events {
                match event {
-                       Event::PaymentSent { payment_preimage, payment_hash } => {
+                       Event::PaymentSent { payment_id: _, payment_preimage, payment_hash } => {
                                if payment_preimage == our_payment_preimage && payment_hash == payment_hash_1 {
                                        assert!(!first_claimed);
                                        first_claimed = true;
@@ -3350,7 +3350,7 @@ fn test_simple_peer_disconnect() {
                let events = nodes[0].node.get_and_clear_pending_events();
                assert_eq!(events.len(), 2);
                match events[0] {
-                       Event::PaymentSent { payment_preimage, payment_hash } => {
+                       Event::PaymentSent { payment_id: _, payment_preimage, payment_hash } => {
                                assert_eq!(payment_preimage, payment_preimage_3);
                                assert_eq!(payment_hash, payment_hash_3);
                        },
@@ -3514,7 +3514,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
                let events_4 = nodes[0].node.get_and_clear_pending_events();
                assert_eq!(events_4.len(), 1);
                match events_4[0] {
-                       Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                       Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                assert_eq!(payment_preimage_1, *payment_preimage);
                                assert_eq!(payment_hash_1, *payment_hash);
                        },
@@ -3555,7 +3555,7 @@ fn do_test_drop_messages_peer_disconnect(messages_delivered: u8, simulate_broken
                        let events_4 = nodes[0].node.get_and_clear_pending_events();
                        assert_eq!(events_4.len(), 1);
                        match events_4[0] {
-                               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                        assert_eq!(payment_preimage_1, *payment_preimage);
                                        assert_eq!(payment_hash_1, *payment_hash);
                                },
@@ -3790,7 +3790,7 @@ fn test_drop_messages_peer_disconnect_dual_htlc() {
                        let events_3 = nodes[0].node.get_and_clear_pending_events();
                        assert_eq!(events_3.len(), 1);
                        match events_3[0] {
-                               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+                               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                                        assert_eq!(*payment_preimage, payment_preimage_1);
                                        assert_eq!(*payment_hash, payment_hash_1);
                                },
@@ -5059,7 +5059,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
 
        let events = nodes[0].node.get_and_clear_pending_events();
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(*payment_preimage, our_payment_preimage);
                        assert_eq!(*payment_hash, duplicate_payment_hash);
                }
@@ -5572,7 +5572,7 @@ fn do_htlc_claim_local_commitment_only(use_dust: bool) {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { payment_preimage, payment_hash } => {
+               Event::PaymentSent { payment_id: _, payment_preimage, payment_hash } => {
                        assert_eq!(payment_preimage, our_payment_preimage);
                        assert_eq!(payment_hash, our_payment_hash);
                },
@@ -6000,7 +6000,7 @@ fn test_free_and_fail_holding_cell_htlcs() {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(*payment_preimage, payment_preimage_1);
                        assert_eq!(*payment_hash, payment_hash_1);
                }
index cbf288962f5beb71105a7a36fd9848b9d90b8ff9..388104bf0239a4252f7338bab4b900107ba59587 100644 (file)
@@ -131,7 +131,7 @@ fn updates_shutdown_wait() {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(our_payment_preimage, *payment_preimage);
                        assert_eq!(our_payment_hash, *payment_hash);
                },
@@ -309,7 +309,7 @@ fn do_test_shutdown_rebroadcast(recv_count: u8) {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentSent { ref payment_preimage, ref payment_hash } => {
+               Event::PaymentSent { payment_id: _, ref payment_preimage, ref payment_hash } => {
                        assert_eq!(our_payment_preimage, *payment_preimage);
                        assert_eq!(our_payment_hash, *payment_hash);
                },
index 70a6a2dd4d1be07542494d30752d06388b2c2fed..a311bd52c82de1ea9f14a04014fc533dc8097561 100644 (file)
@@ -15,6 +15,7 @@
 //! few other things.
 
 use chain::keysinterface::SpendableOutputDescriptor;
+use ln::channelmanager::PaymentId;
 use ln::msgs;
 use ln::msgs::DecodeError;
 use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
@@ -178,6 +179,12 @@ pub enum Event {
        /// Note for MPP payments: in rare cases, this event may be preceded by a `PaymentPathFailed`
        /// event. In this situation, you SHOULD treat this payment as having succeeded.
        PaymentSent {
+               /// The id returned by [`ChannelManager::send_payment`] and used with
+               /// [`ChannelManager::retry_payment`].
+               ///
+               /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
+               /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
+               payment_id: Option<PaymentId>,
                /// The preimage to the hash given to ChannelManager::send_payment.
                /// Note that this serves as a payment receipt, if you wish to have such a thing, you must
                /// store it somehow!
@@ -322,11 +329,12 @@ impl Writeable for Event {
                                        (8, payment_preimage, option),
                                });
                        },
-                       &Event::PaymentSent { ref payment_preimage, ref payment_hash} => {
+                       &Event::PaymentSent { ref payment_id, ref payment_preimage, ref payment_hash} => {
                                2u8.write(writer)?;
                                write_tlv_fields!(writer, {
                                        (0, payment_preimage, required),
                                        (1, payment_hash, required),
+                                       (3, payment_id, option),
                                });
                        },
                        &Event::PaymentPathFailed {
@@ -435,14 +443,17 @@ impl MaybeReadable for Event {
                                let f = || {
                                        let mut payment_preimage = PaymentPreimage([0; 32]);
                                        let mut payment_hash = None;
+                                       let mut payment_id = None;
                                        read_tlv_fields!(reader, {
                                                (0, payment_preimage, required),
                                                (1, payment_hash, option),
+                                               (3, payment_id, option),
                                        });
                                        if payment_hash.is_none() {
                                                payment_hash = Some(PaymentHash(Sha256::hash(&payment_preimage.0[..]).into_inner()));
                                        }
                                        Ok(Some(Event::PaymentSent {
+                                               payment_id,
                                                payment_preimage,
                                                payment_hash: payment_hash.unwrap(),
                                        }))