Merge pull request #1856 from tnull/2022-10-expose-channel-id
[rust-lightning] / lightning / src / ln / chanmon_update_fail_tests.rs
index 0f922302e37d5872a33ea3e36e5515390a1ff522..b1b6b79712dc75fad8ccd2e2a2126dc1cf3f9d16 100644 (file)
@@ -19,11 +19,10 @@ use bitcoin::network::constants::Network;
 use crate::chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
 use crate::chain::transaction::OutPoint;
 use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
-use crate::ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
+use crate::ln::channelmanager::{self, ChannelManager, RAACommitmentOrder, PaymentSendFailure, PaymentId};
 use crate::ln::channel::AnnouncementSigsState;
 use crate::ln::msgs;
 use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
-use crate::util::config::UserConfig;
 use crate::util::enforcing_trait_impls::EnforcingSigner;
 use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
 use crate::util::errors::APIError;
@@ -51,7 +50,7 @@ fn test_simple_monitor_permanent_update_fail() {
 
        let (route, payment_hash_1, _, payment_secret_1) = get_route_and_payment_hash!(&nodes[0], nodes[1], 1000000);
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
-       unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)), true, APIError::ChannelUnavailable {..}, {});
+       unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)), true, APIError::ChannelUnavailable {..}, {});
        check_added_monitors!(nodes[0], 2);
 
        let events_1 = nodes[0].node.get_and_clear_pending_msg_events();
@@ -170,7 +169,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
 
        {
-               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)), false, APIError::MonitorUpdateInProgress, {});
+               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)), false, APIError::MonitorUpdateInProgress, {});
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -201,9 +200,11 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
        let events_3 = nodes[1].node.get_and_clear_pending_events();
        assert_eq!(events_3.len(), 1);
        match events_3[0] {
-               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
+               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, receiver_node_id, via_channel_id, via_user_channel_id: _ } => {
                        assert_eq!(payment_hash_1, *payment_hash);
                        assert_eq!(amount_msat, 1_000_000);
+                       assert_eq!(receiver_node_id.unwrap(), nodes[1].node.get_our_node_id());
+                       assert_eq!(via_channel_id, Some(channel_id));
                        match &purpose {
                                PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
                                        assert!(payment_preimage.is_none());
@@ -221,7 +222,7 @@ fn do_test_simple_monitor_temporary_update_fail(disconnect: bool) {
        let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(&nodes[0], nodes[1], 1000000);
        {
                chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
-               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateInProgress, {});
+               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)), false, APIError::MonitorUpdateInProgress, {});
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -285,7 +286,7 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
                chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
-               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)), false, APIError::MonitorUpdateInProgress, {});
+               unwrap_send_err!(nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)), false, APIError::MonitorUpdateInProgress, {});
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -325,7 +326,6 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
                                nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), commitment_signed);
                                check_added_monitors!(nodes[0], 1);
                                assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
-                               nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
                        }
 
                        (update_fulfill_htlcs[0].clone(), commitment_signed.clone())
@@ -569,9 +569,11 @@ fn do_test_monitor_temporary_update_fail(disconnect_count: usize) {
        let events_5 = nodes[1].node.get_and_clear_pending_events();
        assert_eq!(events_5.len(), 1);
        match events_5[0] {
-               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
+               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, receiver_node_id, via_channel_id, via_user_channel_id: _ } => {
                        assert_eq!(payment_hash_2, *payment_hash);
                        assert_eq!(amount_msat, 1_000_000);
+                       assert_eq!(receiver_node_id.unwrap(), nodes[1].node.get_our_node_id());
+                       assert_eq!(via_channel_id, Some(channel_id));
                        match &purpose {
                                PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
                                        assert!(payment_preimage.is_none());
@@ -624,7 +626,7 @@ fn test_monitor_update_fail_cs() {
 
        let (route, our_payment_hash, payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
+               nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -634,7 +636,6 @@ fn test_monitor_update_fail_cs() {
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &send_event.commitment_msg);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
 
@@ -665,7 +666,6 @@ fn test_monitor_update_fail_cs() {
                        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
                        nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &updates.commitment_signed);
                        assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
-                       nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
                        check_added_monitors!(nodes[0], 1);
                        assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
                },
@@ -686,9 +686,11 @@ fn test_monitor_update_fail_cs() {
        let events = nodes[1].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::PaymentReceived { payment_hash, ref purpose, amount_msat } => {
+               Event::PaymentReceived { payment_hash, ref purpose, amount_msat, receiver_node_id, via_channel_id, via_user_channel_id: _ } => {
                        assert_eq!(payment_hash, our_payment_hash);
                        assert_eq!(amount_msat, 1_000_000);
+                       assert_eq!(receiver_node_id.unwrap(), nodes[1].node.get_our_node_id());
+                       assert_eq!(via_channel_id, Some(channel_id));
                        match &purpose {
                                PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
                                        assert!(payment_preimage.is_none());
@@ -716,7 +718,7 @@ fn test_monitor_update_fail_no_rebroadcast() {
 
        let (route, our_payment_hash, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, our_payment_hash, &Some(payment_secret_1)).unwrap();
+               nodes[0].node.send_payment(&route, our_payment_hash, &Some(payment_secret_1), PaymentId(our_payment_hash.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -727,7 +729,6 @@ fn test_monitor_update_fail_no_rebroadcast() {
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &bs_raa);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
        assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
        check_added_monitors!(nodes[1], 1);
@@ -764,14 +765,14 @@ fn test_monitor_update_raa_while_paused() {
        send_payment(&nodes[0], &[&nodes[1]], 5000000);
        let (route, our_payment_hash_1, payment_preimage_1, our_payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, our_payment_hash_1, &Some(our_payment_secret_1)).unwrap();
+               nodes[0].node.send_payment(&route, our_payment_hash_1, &Some(our_payment_secret_1), PaymentId(our_payment_hash_1.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
        let send_event_1 = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0));
 
        let (route, our_payment_hash_2, payment_preimage_2, our_payment_secret_2) = get_route_and_payment_hash!(nodes[1], nodes[0], 1000000);
        {
-               nodes[1].node.send_payment(&route, our_payment_hash_2, &Some(our_payment_secret_2)).unwrap();
+               nodes[1].node.send_payment(&route, our_payment_hash_2, &Some(our_payment_secret_2), PaymentId(our_payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[1], 1);
        }
        let send_event_2 = SendEvent::from_event(nodes[1].node.get_and_clear_pending_msg_events().remove(0));
@@ -785,12 +786,11 @@ fn test_monitor_update_raa_while_paused() {
        nodes[0].node.handle_update_add_htlc(&nodes[1].node.get_our_node_id(), &send_event_2.msgs[0]);
        nodes[0].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &send_event_2.commitment_msg);
        assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[0], 1);
+       assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
 
        nodes[0].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa);
        assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Existing pending monitor update prevented responses to RAA".to_string(), 1);
        check_added_monitors!(nodes[0], 1);
 
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
@@ -860,7 +860,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
        // holding cell.
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -876,7 +876,6 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[1].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &bs_revoke_and_ack);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
        check_added_monitors!(nodes[1], 1);
@@ -885,7 +884,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
        // being paused waiting a monitor update.
        let (route, payment_hash_3, _, payment_secret_3) = get_route_and_payment_hash!(nodes[0], nodes[2], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), PaymentId(payment_hash_3.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -904,7 +903,7 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
        let (payment_preimage_4, payment_hash_4) = if test_ignore_second_cs {
                // Try to route another payment backwards from 2 to make sure 1 holds off on responding
                let (route, payment_hash_4, payment_preimage_4, payment_secret_4) = get_route_and_payment_hash!(nodes[2], nodes[0], 1000000);
-               nodes[2].node.send_payment(&route, payment_hash_4, &Some(payment_secret_4)).unwrap();
+               nodes[2].node.send_payment(&route, payment_hash_4, &Some(payment_secret_4), PaymentId(payment_hash_4.0)).unwrap();
                check_added_monitors!(nodes[2], 1);
 
                send_event = SendEvent::from_event(nodes[2].node.get_and_clear_pending_msg_events().remove(0));
@@ -912,8 +911,6 @@ fn do_test_monitor_update_fail_raa(test_ignore_second_cs: bool) {
                nodes[1].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &send_event.commitment_msg);
                check_added_monitors!(nodes[1], 1);
                assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-               nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
-               assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
                (Some(payment_preimage_4), Some(payment_hash_4))
        } else { (None, None) };
 
@@ -1137,7 +1134,7 @@ fn test_monitor_update_fail_reestablish() {
                get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, nodes[1].node.get_our_node_id())
                        .contents.flags & 2, 0); // The "disabled" bit should be unset as we just reconnected
 
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
+       nodes[1].node.get_and_clear_pending_msg_events(); // Free the holding cell
        check_added_monitors!(nodes[1], 1);
 
        nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
@@ -1198,9 +1195,9 @@ fn raa_no_response_awaiting_raa_state() {
        // requires only an RAA response due to AwaitingRAA) we can deliver the RAA and require the CS
        // generation during RAA while in monitor-update-failed state.
        {
-               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
-               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[0], 0);
        }
 
@@ -1229,12 +1226,11 @@ fn raa_no_response_awaiting_raa_state() {
        nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
        nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
+       assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
 
        nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Existing pending monitor update prevented responses to RAA".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
 
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
@@ -1250,7 +1246,7 @@ fn raa_no_response_awaiting_raa_state() {
        // chanmon_fail_consistency test required it to actually find the bug (by seeing out-of-sync
        // commitment transaction states) whereas here we can explicitly check for it.
        {
-               nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), PaymentId(payment_hash_3.0)).unwrap();
                check_added_monitors!(nodes[0], 0);
                assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
        }
@@ -1332,7 +1328,6 @@ fn claim_while_disconnected_monitor_update_fail() {
 
        nodes[1].node.handle_channel_reestablish(&nodes[0].node.get_our_node_id(), &as_reconnect);
        let _bs_channel_update = get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, nodes[0].node.get_our_node_id());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
 
@@ -1340,7 +1335,7 @@ fn claim_while_disconnected_monitor_update_fail() {
        // the monitor still failed
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -1349,7 +1344,6 @@ fn claim_while_disconnected_monitor_update_fail() {
        nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &as_updates.commitment_signed);
        check_added_monitors!(nodes[1], 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
        // Note that nodes[1] not updating monitor here is OK - it wont take action on the new HTLC
        // until we've channel_monitor_update'd and updated for the new commitment transaction.
 
@@ -1430,7 +1424,7 @@ fn monitor_failed_no_reestablish_response() {
        // on receipt).
        let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -1441,7 +1435,6 @@ fn monitor_failed_no_reestablish_response() {
        nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
        nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
 
        // Now disconnect and immediately reconnect, delivering the channel_reestablish while nodes[1]
@@ -1503,7 +1496,7 @@ fn first_message_on_recv_ordering() {
        // can deliver it and fail the monitor update.
        let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -1526,7 +1519,7 @@ fn first_message_on_recv_ordering() {
        // Route the second payment, generating an update_add_htlc/commitment_signed
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
        let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -1541,7 +1534,6 @@ fn first_message_on_recv_ordering() {
        // to the next message also tests resetting the delivery order.
        nodes[1].node.handle_revoke_and_ack(&nodes[0].node.get_our_node_id(), &as_raa);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[1], 1);
 
        // Now deliver the update_add_htlc/commitment_signed for the second payment, which does need an
@@ -1551,7 +1543,6 @@ fn first_message_on_recv_ordering() {
        nodes[1].node.handle_commitment_signed(&nodes[0].node.get_our_node_id(), &payment_event.commitment_msg);
        check_added_monitors!(nodes[1], 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Previous monitor update failure prevented generation of RAA".to_string(), 1);
 
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
        let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
@@ -1600,7 +1591,7 @@ fn test_monitor_update_fail_claim() {
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[1].node.claim_funds(payment_preimage_1);
        expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Temporary failure claiming HTLC, treating as success: Failed to update ChannelMonitor".to_string(), 1);
+       assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
        check_added_monitors!(nodes[1], 1);
 
        // Note that at this point there is a pending commitment transaction update for A being held by
@@ -1610,7 +1601,7 @@ fn test_monitor_update_fail_claim() {
 
        let (route, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[2], nodes[0], 1_000_000);
        {
-               nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[2], 1);
        }
 
@@ -1627,7 +1618,7 @@ fn test_monitor_update_fail_claim() {
        commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false, true);
 
        let (_, payment_hash_3, payment_secret_3) = get_payment_preimage_hash!(nodes[0]);
-       nodes[2].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3)).unwrap();
+       nodes[2].node.send_payment(&route, payment_hash_3, &Some(payment_secret_3), PaymentId(payment_hash_3.0)).unwrap();
        check_added_monitors!(nodes[2], 1);
 
        let mut events = nodes[2].node.get_and_clear_pending_msg_events();
@@ -1639,7 +1630,8 @@ fn test_monitor_update_fail_claim() {
        commitment_signed_dance!(nodes[1], nodes[2], payment_event.commitment_msg, false, true);
 
        // Now restore monitor updating on the 0<->1 channel and claim the funds on B.
-       let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_1.2).unwrap().clone();
+       let channel_id = chan_1.2;
+       let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
        nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, latest_update);
        check_added_monitors!(nodes[1], 0);
 
@@ -1660,9 +1652,12 @@ fn test_monitor_update_fail_claim() {
        let events = nodes[0].node.get_and_clear_pending_events();
        assert_eq!(events.len(), 2);
        match events[0] {
-               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
+               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, receiver_node_id, via_channel_id, via_user_channel_id } => {
                        assert_eq!(payment_hash_2, *payment_hash);
                        assert_eq!(1_000_000, amount_msat);
+                       assert_eq!(receiver_node_id.unwrap(), nodes[0].node.get_our_node_id());
+                       assert_eq!(via_channel_id, Some(channel_id));
+                       assert_eq!(via_user_channel_id, Some(42));
                        match &purpose {
                                PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
                                        assert!(payment_preimage.is_none());
@@ -1674,9 +1669,11 @@ fn test_monitor_update_fail_claim() {
                _ => panic!("Unexpected event"),
        }
        match events[1] {
-               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat } => {
+               Event::PaymentReceived { ref payment_hash, ref purpose, amount_msat, receiver_node_id, via_channel_id, via_user_channel_id: _ } => {
                        assert_eq!(payment_hash_3, *payment_hash);
                        assert_eq!(1_000_000, amount_msat);
+                       assert_eq!(receiver_node_id.unwrap(), nodes[0].node.get_our_node_id());
+                       assert_eq!(via_channel_id, Some(channel_id));
                        match &purpose {
                                PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
                                        assert!(payment_preimage.is_none());
@@ -1717,7 +1714,7 @@ fn test_monitor_update_on_pending_forwards() {
 
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[2], nodes[0], 1000000);
        {
-               nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[2].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[2], 1);
        }
 
@@ -1731,7 +1728,6 @@ fn test_monitor_update_on_pending_forwards() {
        expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[1], vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[2].node.get_our_node_id()), channel_id: chan_2.2 }]);
        check_added_monitors!(nodes[1], 1);
        assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
 
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
        let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_1.2).unwrap().clone();
@@ -1777,7 +1773,7 @@ fn monitor_update_claim_fail_no_response() {
        // Now start forwarding a second payment, skipping the last RAA so B is in AwaitingRAA
        let (route, payment_hash_2, payment_preimage_2, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[1], 1000000);
        {
-               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+               nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
        }
 
@@ -1792,9 +1788,7 @@ fn monitor_update_claim_fail_no_response() {
        expect_payment_claimed!(nodes[1], payment_hash_1, 1_000_000);
        check_added_monitors!(nodes[1], 1);
 
-       let events = nodes[1].node.get_and_clear_pending_msg_events();
-       assert_eq!(events.len(), 0);
-       nodes[1].logger.assert_log("lightning::ln::channelmanager".to_string(), "Temporary failure claiming HTLC, treating as success: Failed to update ChannelMonitor".to_string(), 1);
+       assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
 
        chanmon_cfgs[1].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
        let (outpoint, latest_update, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
@@ -1842,9 +1836,8 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
 
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()));
-       assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
-       nodes[0].logger.assert_log("lightning::ln::channelmanager".to_string(), "Failed to update ChannelMonitor".to_string(), 1);
        check_added_monitors!(nodes[0], 1);
+       assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
        assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
        let (outpoint, latest_update, _) = nodes[0].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&channel_id).unwrap().clone();
@@ -1971,7 +1964,7 @@ fn test_path_paused_mpp() {
        // Now check that we get the right return value, indicating that the first path succeeded but
        // the second got a MonitorUpdateInProgress err. This implies
        // PaymentSendFailure::PartialFailure as some paths succeeded, preventing retry.
-       if let Err(PaymentSendFailure::PartialFailure { results, ..}) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)) {
+       if let Err(PaymentSendFailure::PartialFailure { results, ..}) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)) {
                assert_eq!(results.len(), 2);
                if let Ok(()) = results[0] {} else { panic!(); }
                if let Err(APIError::MonitorUpdateInProgress) = results[1] {} else { panic!(); }
@@ -2016,7 +2009,7 @@ fn test_pending_update_fee_ack_on_reconnect() {
        send_payment(&nodes[0], &[&nodes[1]], 100_000_00);
 
        let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[1], nodes[0], 1_000_000);
-       nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap();
+       nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret), PaymentId(payment_hash.0)).unwrap();
        check_added_monitors!(nodes[1], 1);
        let bs_initial_send_msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
        // bs_initial_send_msgs are not delivered until they are re-generated after reconnect
@@ -2267,12 +2260,12 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
        // (c) will not be freed from the holding cell.
        let (payment_preimage_0, payment_hash_0, _) = route_payment(&nodes[1], &[&nodes[0]], 100_000);
 
-       nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
+       nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1), PaymentId(payment_hash_1.0)).unwrap();
        check_added_monitors!(nodes[0], 1);
        let send = SendEvent::from_node(&nodes[0]);
        assert_eq!(send.msgs.len(), 1);
 
-       nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2)).unwrap();
+       nodes[0].node.send_payment(&route, payment_hash_2, &Some(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
        check_added_monitors!(nodes[0], 0);
 
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
@@ -2294,40 +2287,8 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
                // disconnect the peers. Note that the fuzzer originally found this issue because
                // deserializing a ChannelManager in this state causes an assertion failure.
                if reload_a {
-                       let nodes_0_serialized = nodes[0].node.encode();
-                       let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
-                       get_monitor!(nodes[0], chan_id).write(&mut chan_0_monitor_serialized).unwrap();
-
-                       persister = test_utils::TestPersister::new();
-                       let keys_manager = &chanmon_cfgs[0].keys_manager;
-                       new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster.clone(), nodes[0].logger, node_cfgs[0].fee_estimator, &persister, keys_manager);
-                       nodes[0].chain_monitor = &new_chain_monitor;
-                       let mut chan_0_monitor_read = &chan_0_monitor_serialized.0[..];
-                       let (_, mut chan_0_monitor) = <(BlockHash, ChannelMonitor<EnforcingSigner>)>::read(
-                               &mut chan_0_monitor_read, keys_manager).unwrap();
-                       assert!(chan_0_monitor_read.is_empty());
-
-                       let mut nodes_0_read = &nodes_0_serialized[..];
-                       let config = UserConfig::default();
-                       nodes_0_deserialized = {
-                               let mut channel_monitors = HashMap::new();
-                               channel_monitors.insert(chan_0_monitor.get_funding_txo().0, &mut chan_0_monitor);
-                               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
-                                       default_config: config,
-                                       keys_manager,
-                                       fee_estimator: node_cfgs[0].fee_estimator,
-                                       chain_monitor: nodes[0].chain_monitor,
-                                       tx_broadcaster: nodes[0].tx_broadcaster.clone(),
-                                       logger: nodes[0].logger,
-                                       channel_monitors,
-                               }).unwrap().1
-                       };
-                       nodes[0].node = &nodes_0_deserialized;
-                       assert!(nodes_0_read.is_empty());
-
-                       assert_eq!(nodes[0].chain_monitor.watch_channel(chan_0_monitor.get_funding_txo().0.clone(), chan_0_monitor),
-                               ChannelMonitorUpdateStatus::Completed);
-                       check_added_monitors!(nodes[0], 1);
+                       let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
+                       reload_node!(nodes[0], &nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized);
                } else {
                        nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                }
@@ -2464,7 +2425,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim, second_f
                // In order to get the HTLC claim into the holding cell at nodes[1], we need nodes[1] to be
                // awaiting a remote revoke_and_ack from nodes[0].
                let (route, second_payment_hash, _, second_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], 100_000);
-               nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret)).unwrap();
+               nodes[0].node.send_payment(&route, second_payment_hash, &Some(second_payment_secret), PaymentId(second_payment_hash.0)).unwrap();
                check_added_monitors!(nodes[0], 1);
 
                let send_event = SendEvent::from_event(nodes[0].node.get_and_clear_pending_msg_events().remove(0));
@@ -2832,28 +2793,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
        nodes[0].chain_source.watched_txn.lock().unwrap().clear();
        nodes[0].chain_source.watched_outputs.lock().unwrap().clear();
 
-       let nodes_0_serialized = nodes[0].node.encode();
-       persister = test_utils::TestPersister::new();
-       let keys_manager = &chanmon_cfgs[0].keys_manager;
-       new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[0].chain_source), nodes[0].tx_broadcaster.clone(), nodes[0].logger, node_cfgs[0].fee_estimator, &persister, keys_manager);
-       nodes[0].chain_monitor = &new_chain_monitor;
-
-       let mut nodes_0_read = &nodes_0_serialized[..];
-       let config = UserConfig::default();
-       nodes_0_deserialized = {
-               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
-                       default_config: config,
-                       keys_manager,
-                       fee_estimator: node_cfgs[0].fee_estimator,
-                       chain_monitor: nodes[0].chain_monitor,
-                       tx_broadcaster: nodes[0].tx_broadcaster.clone(),
-                       logger: nodes[0].logger,
-                       channel_monitors: HashMap::new(),
-               }).unwrap().1
-       };
-       nodes[0].node = &nodes_0_deserialized;
-       assert!(nodes_0_read.is_empty());
-
+       reload_node!(nodes[0], &nodes[0].node.encode(), &[], persister, new_chain_monitor, nodes_0_deserialized);
        check_closed_event!(nodes[0], 1, ClosureReason::DisconnectedPeer);
        assert!(nodes[0].node.list_channels().is_empty());
 }
@@ -2938,27 +2878,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
        nodes[1].chain_source.watched_txn.lock().unwrap().clear();
        nodes[1].chain_source.watched_outputs.lock().unwrap().clear();
 
-       let nodes_1_serialized = nodes[1].node.encode();
-       persister = test_utils::TestPersister::new();
-       let keys_manager = &chanmon_cfgs[1].keys_manager;
-       new_chain_monitor = test_utils::TestChainMonitor::new(Some(nodes[1].chain_source), nodes[1].tx_broadcaster.clone(), nodes[1].logger, node_cfgs[1].fee_estimator, &persister, keys_manager);
-       nodes[1].chain_monitor = &new_chain_monitor;
-
-       let mut nodes_1_read = &nodes_1_serialized[..];
-       let config = UserConfig::default();
-       nodes_1_deserialized = {
-               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_1_read, ChannelManagerReadArgs {
-                       default_config: config,
-                       keys_manager,
-                       fee_estimator: node_cfgs[1].fee_estimator,
-                       chain_monitor: nodes[1].chain_monitor,
-                       tx_broadcaster: nodes[1].tx_broadcaster.clone(),
-                       logger: nodes[1].logger,
-                       channel_monitors: HashMap::new(),
-               }).unwrap().1
-       };
-       nodes[1].node = &nodes_1_deserialized;
-       assert!(nodes_1_read.is_empty());
+       reload_node!(nodes[1], &nodes[1].node.encode(), &[], persister, new_chain_monitor, nodes_1_deserialized);
 
        check_closed_event!(nodes[1], 1, ClosureReason::DisconnectedPeer);
        assert!(nodes[1].node.list_channels().is_empty());