@@ -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 ;
@@ -814,15 +815,17 @@ fn test_partial_claim_before_restart() {
814
815
do_test_partial_claim_before_restart ( true ) ;
815
816
}
816
817
817
- fn do_forwarded_payment_no_manager_persistence ( use_cs_commitment : bool , claim_htlc : bool ) {
818
+ fn do_forwarded_payment_no_manager_persistence ( use_cs_commitment : bool , claim_htlc : bool , use_intercept : bool ) {
818
819
if !use_cs_commitment { assert ! ( !claim_htlc) ; }
819
820
// If we go to forward a payment, and the ChannelMonitor persistence completes, but the
820
821
// ChannelManager does not, we shouldn't try to forward the payment again, nor should we fail
821
822
// it back until the ChannelMonitor decides the fate of the HTLC.
822
823
// This was never an issue, but it may be easy to regress here going forward.
823
824
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
824
825
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
825
- let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
826
+ let mut intercept_forwards_config = test_default_channel_config ( ) ;
827
+ intercept_forwards_config. accept_intercept_htlcs = true ;
828
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( intercept_forwards_config) , None ] ) ;
826
829
827
830
let persister;
828
831
let new_chain_monitor;
@@ -833,7 +836,13 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
833
836
let chan_id_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
834
837
let chan_id_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
835
838
836
- let ( route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
839
+ let intercept_scid = nodes[ 1 ] . node . get_intercept_scid ( ) ;
840
+
841
+ let ( mut route, payment_hash, payment_preimage, payment_secret) =
842
+ get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
843
+ if use_intercept {
844
+ route. paths [ 0 ] [ 1 ] . short_channel_id = intercept_scid;
845
+ }
837
846
let payment_id = PaymentId ( nodes[ 0 ] . keys_manager . backing . get_secure_random_bytes ( ) ) ;
838
847
let htlc_expiry = nodes[ 0 ] . best_block_info ( ) . 1 + TEST_FINAL_CLTV ;
839
848
nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , payment_id) . unwrap ( ) ;
@@ -843,8 +852,27 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
843
852
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
844
853
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , payment_event. commitment_msg, false ) ;
845
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.
846
858
let node_encoded = nodes[ 1 ] . node . encode ( ) ;
847
859
860
+ let mut intercept_id = None ;
861
+ let mut expected_outbound_amount_msat = None ;
862
+ if use_intercept {
863
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
864
+ assert_eq ! ( events. len( ) , 1 ) ;
865
+ match events[ 0 ] {
866
+ Event :: HTLCIntercepted { intercept_id : ev_id, expected_outbound_amount_msat : ev_amt, .. } => {
867
+ intercept_id = Some ( ev_id) ;
868
+ expected_outbound_amount_msat = Some ( ev_amt) ;
869
+ } ,
870
+ _ => panic ! ( )
871
+ }
872
+ nodes[ 1 ] . node . forward_intercepted_htlc ( intercept_id. unwrap ( ) , & chan_id_2,
873
+ nodes[ 2 ] . node . get_our_node_id ( ) , expected_outbound_amount_msat. unwrap ( ) ) . unwrap ( ) ;
874
+ }
875
+
848
876
expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
849
877
850
878
let payment_event = SendEvent :: from_node ( & nodes[ 1 ] ) ;
@@ -872,8 +900,20 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
872
900
let chan_1_monitor_serialized = get_monitor ! ( nodes[ 1 ] , chan_id_2) . encode ( ) ;
873
901
reload_node ! ( nodes[ 1 ] , node_encoded, & [ & chan_0_monitor_serialized, & chan_1_monitor_serialized] , persister, new_chain_monitor, nodes_1_deserialized) ;
874
902
903
+ // Note that this checks that this is the only event on nodes[1], implying the
904
+ // `HTLCIntercepted` event has been removed in the `use_intercept` case.
875
905
check_closed_event ! ( nodes[ 1 ] , 1 , ClosureReason :: OutdatedChannelManager ) ;
876
906
907
+ if use_intercept {
908
+ // Attempt to forward the HTLC back out over nodes[1]' still-open channel, ensuring we get
909
+ // a intercept-doesn't-exist error.
910
+ let forward_err = nodes[ 1 ] . node . forward_intercepted_htlc ( intercept_id. unwrap ( ) , & chan_id_1,
911
+ nodes[ 0 ] . node . get_our_node_id ( ) , expected_outbound_amount_msat. unwrap ( ) ) . unwrap_err ( ) ;
912
+ assert_eq ! ( forward_err, APIError :: APIMisuseError {
913
+ err: format!( "Payment with intercept id {} not found" , log_bytes!( intercept_id. unwrap( ) . 0 ) )
914
+ } ) ;
915
+ }
916
+
877
917
let bs_commitment_tx = nodes[ 1 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . split_off ( 0 ) ;
878
918
assert_eq ! ( bs_commitment_tx. len( ) , 1 ) ;
879
919
@@ -929,9 +969,16 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
929
969
930
970
#[ test]
931
971
fn forwarded_payment_no_manager_persistence ( ) {
932
- do_forwarded_payment_no_manager_persistence ( true , true ) ;
933
- do_forwarded_payment_no_manager_persistence ( true , false ) ;
934
- do_forwarded_payment_no_manager_persistence ( false , false ) ;
972
+ do_forwarded_payment_no_manager_persistence ( true , true , false ) ;
973
+ do_forwarded_payment_no_manager_persistence ( true , false , false ) ;
974
+ do_forwarded_payment_no_manager_persistence ( false , false , false ) ;
975
+ }
976
+
977
+ #[ test]
978
+ fn intercepted_payment_no_manager_persistence ( ) {
979
+ do_forwarded_payment_no_manager_persistence ( true , true , true ) ;
980
+ do_forwarded_payment_no_manager_persistence ( true , false , true ) ;
981
+ do_forwarded_payment_no_manager_persistence ( false , false , true ) ;
935
982
}
936
983
937
984
#[ test]
0 commit comments