Skip to content

Commit 3c913a1

Browse files
committed
f comment and make the tests more robust
1 parent 236780d commit 3c913a1

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

lightning/src/ln/reload_tests.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::ln::msgs;
1919
use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, ErrorAction};
2020
use crate::util::enforcing_trait_impls::EnforcingSigner;
2121
use crate::util::test_utils;
22+
use crate::util::errors::APIError;
2223
use crate::util::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider};
2324
use crate::util::ser::{Writeable, ReadableArgs};
2425
use crate::util::config::UserConfig;
@@ -851,20 +852,26 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
851852
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
852853
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
853854

855+
// Store the `ChannelManager` before handling the `PendingHTLCsForwardable`/`HTLCIntercepted`
856+
// events, expecting either event (and the HTLC itself) to be missing on reload even though its
857+
// present when we serialized.
854858
let node_encoded = nodes[1].node.encode();
855859

860+
let mut intercept_id = None;
861+
let mut expected_outbound_amount_msat = None;
856862
if use_intercept {
857863
let events = nodes[1].node.get_and_clear_pending_events();
858864
assert_eq!(events.len(), 1);
859-
let (intercept_id, expected_outbound_amount_msat) = match events[0] {
865+
(intercept_id, expected_outbound_amount_msat) = match events[0] {
860866
crate::util::events::Event::HTLCIntercepted {
861867
intercept_id, expected_outbound_amount_msat, ..
862868
} => {
863-
(intercept_id, expected_outbound_amount_msat)
869+
(Some(intercept_id), Some(expected_outbound_amount_msat))
864870
},
865871
_ => panic!()
866872
};
867-
nodes[1].node.forward_intercepted_htlc(intercept_id, &chan_id_2, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap();
873+
nodes[1].node.forward_intercepted_htlc(intercept_id.unwrap(), &chan_id_2,
874+
nodes[2].node.get_our_node_id(), expected_outbound_amount_msat.unwrap()).unwrap();
868875
}
869876

870877
expect_pending_htlcs_forwardable!(nodes[1]);
@@ -894,8 +901,20 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
894901
let chan_1_monitor_serialized = get_monitor!(nodes[1], chan_id_2).encode();
895902
reload_node!(nodes[1], node_encoded, &[&chan_0_monitor_serialized, &chan_1_monitor_serialized], persister, new_chain_monitor, nodes_1_deserialized);
896903

904+
// Note that this checks that this is the only event on nodes[1], implying the
905+
// `HTLCIntercepted` event has been removed in the `use_intercept` case.
897906
check_closed_event!(nodes[1], 1, ClosureReason::OutdatedChannelManager);
898907

908+
if use_intercept {
909+
// Attempt to forward the HTLC back out over nodes[1]' still-open channel, ensuring we get
910+
// a intercept-doesn't-exist error.
911+
let forward_err = nodes[1].node.forward_intercepted_htlc(intercept_id.unwrap(), &chan_id_1,
912+
nodes[0].node.get_our_node_id(), expected_outbound_amount_msat.unwrap()).unwrap_err();
913+
assert_eq!(forward_err, APIError::APIMisuseError {
914+
err: format!("Payment with intercept id {} not found", log_bytes!(intercept_id.unwrap().0))
915+
});
916+
}
917+
899918
let bs_commitment_tx = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
900919
assert_eq!(bs_commitment_tx.len(), 1);
901920

0 commit comments

Comments
 (0)