@@ -19,6 +19,7 @@ use crate::ln::msgs;
19
19
use crate :: ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler , ErrorAction } ;
20
20
use crate :: util:: enforcing_trait_impls:: EnforcingSigner ;
21
21
use crate :: util:: test_utils;
22
+ use crate :: util:: errors:: APIError ;
22
23
use crate :: util:: events:: { ClosureReason , Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider } ;
23
24
use crate :: util:: ser:: { Writeable , ReadableArgs } ;
24
25
use crate :: util:: config:: UserConfig ;
@@ -851,20 +852,26 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
851
852
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
852
853
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
853
854
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.
854
858
let node_encoded = nodes[ 1 ] . node . encode ( ) ;
855
859
860
+ let mut intercept_id = None ;
861
+ let mut expected_outbound_amount_msat = None ;
856
862
if use_intercept {
857
863
let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
858
864
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 ] {
860
866
crate :: util:: events:: Event :: HTLCIntercepted {
861
867
intercept_id, expected_outbound_amount_msat, ..
862
868
} => {
863
- ( intercept_id, expected_outbound_amount_msat)
869
+ ( Some ( intercept_id) , Some ( expected_outbound_amount_msat) )
864
870
} ,
865
871
_ => panic ! ( )
866
872
} ;
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 ( ) ;
868
875
}
869
876
870
877
expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
@@ -894,8 +901,20 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
894
901
let chan_1_monitor_serialized = get_monitor ! ( nodes[ 1 ] , chan_id_2) . encode ( ) ;
895
902
reload_node ! ( nodes[ 1 ] , node_encoded, & [ & chan_0_monitor_serialized, & chan_1_monitor_serialized] , persister, new_chain_monitor, nodes_1_deserialized) ;
896
903
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.
897
906
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: OutdatedChannelManager ) ;
898
907
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
+
899
918
let bs_commitment_tx = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
900
919
assert_eq ! ( bs_commitment_tx. len( ) , 1 ) ;
901
920
0 commit comments