@@ -814,15 +814,17 @@ fn test_partial_claim_before_restart() {
814
814
do_test_partial_claim_before_restart ( true ) ;
815
815
}
816
816
817
- fn do_forwarded_payment_no_manager_persistence ( use_cs_commitment : bool , claim_htlc : bool ) {
817
+ fn do_forwarded_payment_no_manager_persistence ( use_cs_commitment : bool , claim_htlc : bool , use_intercept : bool ) {
818
818
if !use_cs_commitment { assert ! ( !claim_htlc) ; }
819
819
// If we go to forward a payment, and the ChannelMonitor persistence completes, but the
820
820
// ChannelManager does not, we shouldn't try to forward the payment again, nor should we fail
821
821
// it back until the ChannelMonitor decides the fate of the HTLC.
822
822
// This was never an issue, but it may be easy to regress here going forward.
823
823
let chanmon_cfgs = create_chanmon_cfgs ( 3 ) ;
824
824
let node_cfgs = create_node_cfgs ( 3 , & chanmon_cfgs) ;
825
- let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , None , None ] ) ;
825
+ let mut intercept_forwards_config = test_default_channel_config ( ) ;
826
+ intercept_forwards_config. accept_intercept_htlcs = true ;
827
+ let node_chanmgrs = create_node_chanmgrs ( 3 , & node_cfgs, & [ None , Some ( intercept_forwards_config) , None ] ) ;
826
828
827
829
let persister;
828
830
let new_chain_monitor;
@@ -833,7 +835,13 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
833
835
let chan_id_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
834
836
let chan_id_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) . 2 ;
835
837
836
- let ( route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
838
+ let intercept_scid = nodes[ 1 ] . node . get_intercept_scid ( ) ;
839
+
840
+ let ( mut route, payment_hash, payment_preimage, payment_secret) =
841
+ get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 2 ] , 1_000_000 ) ;
842
+ if use_intercept {
843
+ route. paths [ 0 ] [ 1 ] . short_channel_id = intercept_scid;
844
+ }
837
845
let payment_id = PaymentId ( nodes[ 0 ] . keys_manager . backing . get_secure_random_bytes ( ) ) ;
838
846
let htlc_expiry = nodes[ 0 ] . best_block_info ( ) . 1 + TEST_FINAL_CLTV ;
839
847
nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , payment_id) . unwrap ( ) ;
@@ -845,6 +853,20 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
845
853
846
854
let node_encoded = nodes[ 1 ] . node . encode ( ) ;
847
855
856
+ if use_intercept {
857
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
858
+ assert_eq ! ( events. len( ) , 1 ) ;
859
+ let ( intercept_id, expected_outbound_amount_msat) = match events[ 0 ] {
860
+ crate :: util:: events:: Event :: HTLCIntercepted {
861
+ intercept_id, expected_outbound_amount_msat, ..
862
+ } => {
863
+ ( intercept_id, expected_outbound_amount_msat)
864
+ } ,
865
+ _ => panic ! ( )
866
+ } ;
867
+ nodes[ 1 ] . node . forward_intercepted_htlc ( intercept_id, & chan_id_2, nodes[ 2 ] . node . get_our_node_id ( ) , expected_outbound_amount_msat) . unwrap ( ) ;
868
+ }
869
+
848
870
expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
849
871
850
872
let payment_event = SendEvent :: from_node ( & nodes[ 1 ] ) ;
@@ -929,9 +951,16 @@ fn do_forwarded_payment_no_manager_persistence(use_cs_commitment: bool, claim_ht
929
951
930
952
#[ test]
931
953
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 ) ;
954
+ do_forwarded_payment_no_manager_persistence ( true , true , false ) ;
955
+ do_forwarded_payment_no_manager_persistence ( true , false , false ) ;
956
+ do_forwarded_payment_no_manager_persistence ( false , false , false ) ;
957
+ }
958
+
959
+ #[ test]
960
+ fn intercepted_payment_no_manager_persistence ( ) {
961
+ do_forwarded_payment_no_manager_persistence ( true , true , true ) ;
962
+ do_forwarded_payment_no_manager_persistence ( true , false , true ) ;
963
+ do_forwarded_payment_no_manager_persistence ( false , false , true ) ;
935
964
}
936
965
937
966
#[ test]
0 commit comments