@@ -14834,7 +14834,7 @@ mod tests {
1483414834 use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
1483514835 use crate::ln::types::ChannelId;
1483614836 use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
14837- use crate::ln::channelmanager::{create_recv_pending_htlc_info, inbound_payment, ChannelConfigOverrides, HTLCForwardInfo, InterceptId, PaymentId, RecipientOnionFields};
14837+ use crate::ln::channelmanager::{RAACommitmentOrder, create_recv_pending_htlc_info, inbound_payment, ChannelConfigOverrides, HTLCForwardInfo, InterceptId, PaymentId, RecipientOnionFields};
1483814838 use crate::ln::functional_test_utils::*;
1483914839 use crate::ln::msgs::{self, AcceptChannel, ErrorAction};
1484014840 use crate::ln::msgs::ChannelMessageHandler;
@@ -15306,6 +15306,80 @@ mod tests {
1530615306 nodes[1].logger.assert_log_contains("lightning::ln::channelmanager", "Payment preimage didn't match payment hash", 1);
1530715307 }
1530815308
15309+ #[test]
15310+ fn test_htlc_localremoved_persistence() {
15311+ let chanmon_cfgs: Vec<TestChanMonCfg> = create_chanmon_cfgs(2);
15312+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
15313+
15314+ let persister;
15315+ let chain_monitor;
15316+ let deserialized_chanmgr;
15317+
15318+ // Send a keysend payment that fails because of a preimage mismatch.
15319+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
15320+ let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
15321+
15322+ let payer_pubkey = nodes[0].node.get_our_node_id();
15323+ let payee_pubkey = nodes[1].node.get_our_node_id();
15324+
15325+ let _chan = create_chan_between_nodes(&nodes[0], &nodes[1]);
15326+ let route_params = RouteParameters::from_payment_params_and_value(
15327+ PaymentParameters::for_keysend(payee_pubkey, 40, false), 10_000);
15328+ let network_graph = nodes[0].network_graph;
15329+ let first_hops = nodes[0].node.list_usable_channels();
15330+ let scorer = test_utils::TestScorer::new();
15331+ let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
15332+ let route = find_route(
15333+ &payer_pubkey, &route_params, &network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
15334+ nodes[0].logger, &scorer, &Default::default(), &random_seed_bytes
15335+ ).unwrap();
15336+
15337+ let test_preimage = PaymentPreimage([42; 32]);
15338+ let mismatch_payment_hash = PaymentHash([43; 32]);
15339+ let session_privs = nodes[0].node.test_add_new_pending_payment(mismatch_payment_hash,
15340+ RecipientOnionFields::spontaneous_empty(), PaymentId(mismatch_payment_hash.0), &route).unwrap();
15341+ nodes[0].node.test_send_payment_internal(&route, mismatch_payment_hash,
15342+ RecipientOnionFields::spontaneous_empty(), Some(test_preimage), PaymentId(mismatch_payment_hash.0), None, session_privs).unwrap();
15343+ check_added_monitors!(nodes[0], 1);
15344+
15345+ let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
15346+ nodes[1].node.handle_update_add_htlc(nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
15347+ commitment_signed_dance!(nodes[1], nodes[0], &updates.commitment_signed, false);
15348+ expect_pending_htlcs_forwardable!(nodes[1]);
15349+ expect_htlc_handling_failed_destinations!(nodes[1].node.get_and_clear_pending_events(), &[HTLCDestination::FailedPayment { payment_hash: mismatch_payment_hash }]);
15350+ check_added_monitors(&nodes[1], 1);
15351+
15352+ // Save the update_fail_htlc message for later comparison.
15353+ let msgs = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
15354+ let htlc_fail_msg = msgs.update_fail_htlcs[0].clone();
15355+
15356+ // Reload node.
15357+ nodes[0].node.peer_disconnected(nodes[1].node.get_our_node_id());
15358+ nodes[1].node.peer_disconnected(nodes[0].node.get_our_node_id());
15359+
15360+ let monitor_encoded = get_monitor!(nodes[1], _chan.3).encode();
15361+ reload_node!(nodes[1], nodes[1].node.encode(), &[&monitor_encoded], persister, chain_monitor, deserialized_chanmgr);
15362+
15363+ nodes[0].node.peer_connected(nodes[1].node.get_our_node_id(), &msgs::Init {
15364+ features: nodes[1].node.init_features(), networks: None, remote_network_address: None
15365+ }, true).unwrap();
15366+ let reestablish_1 = get_chan_reestablish_msgs!(nodes[0], nodes[1]);
15367+ assert_eq!(reestablish_1.len(), 1);
15368+ nodes[1].node.peer_connected(nodes[0].node.get_our_node_id(), &msgs::Init {
15369+ features: nodes[0].node.init_features(), networks: None, remote_network_address: None
15370+ }, false).unwrap();
15371+ let reestablish_2 = get_chan_reestablish_msgs!(nodes[1], nodes[0]);
15372+ assert_eq!(reestablish_2.len(), 1);
15373+ nodes[0].node.handle_channel_reestablish(nodes[1].node.get_our_node_id(), &reestablish_2[0]);
15374+ handle_chan_reestablish_msgs!(nodes[0], nodes[1]);
15375+ nodes[1].node.handle_channel_reestablish(nodes[0].node.get_our_node_id(), &reestablish_1[0]);
15376+
15377+ // Assert that same failure message is resent after reload.
15378+ let msgs = handle_chan_reestablish_msgs!(nodes[1], nodes[0]);
15379+ let htlc_fail_msg_after_reload = msgs.2.unwrap().update_fail_htlcs[0].clone();
15380+ assert_eq!(htlc_fail_msg, htlc_fail_msg_after_reload);
15381+ }
15382+
1530915383 #[test]
1531015384 fn test_multi_hop_missing_secret() {
1531115385 let chanmon_cfgs = create_chanmon_cfgs(4);
0 commit comments