@@ -2877,3 +2877,40 @@ fn test_monitor_claims_with_random_signatures() {
2877
2877
do_test_monitor_claims_with_random_signatures ( true , false ) ;
2878
2878
do_test_monitor_claims_with_random_signatures ( true , true ) ;
2879
2879
}
2880
+
2881
+ #[ test]
2882
+ fn test_event_replay_causing_monitor_replay ( ) {
2883
+ // In LDK 0.0.121 there was a bug where if a `PaymentSent` event caused an RAA
2884
+ // `ChannelMonitorUpdate` hold and then the node was restarted after the `PaymentSent` event
2885
+ // and `ChannelMonitorUpdate` both completed but without persisting the `ChannelManager` we'd
2886
+ // replay the `ChannelMonitorUpdate` on restart (which is fine, but triggered a safety panic).
2887
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
2888
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
2889
+ let persister;
2890
+ let new_chain_monitor;
2891
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
2892
+ let node_deserialized;
2893
+ let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2894
+
2895
+ let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 500_000_000 ) ;
2896
+
2897
+ let payment_preimage = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 1_000_000 ) . 0 ;
2898
+
2899
+ do_claim_payment_along_route ( & nodes[ 0 ] , & [ & [ & nodes[ 1 ] ] ] , false , payment_preimage) ;
2900
+
2901
+ // At this point the `PaymentSent` event has not been processed but the full commitment signed
2902
+ // dance has completed.
2903
+ let serialized_channel_manager = nodes[ 0 ] . node . encode ( ) ;
2904
+
2905
+ // Now process the `PaymentSent` to get the final RAA `ChannelMonitorUpdate`, checking that it
2906
+ // resulted in a `ChannelManager` persistence request.
2907
+ nodes[ 0 ] . node . get_and_clear_needs_persistence ( ) ;
2908
+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , true , true /* expected post-event monitor update*/ ) ;
2909
+ assert ! ( nodes[ 0 ] . node. get_and_clear_needs_persistence( ) ) ;
2910
+
2911
+ let serialized_monitor = get_monitor ! ( nodes[ 0 ] , chan. 2 ) . encode ( ) ;
2912
+ reload_node ! ( nodes[ 0 ] , & serialized_channel_manager, & [ & serialized_monitor] , persister, new_chain_monitor, node_deserialized) ;
2913
+
2914
+ // Expect the `PaymentSent` to get replayed, this time without the duplicate monitor update
2915
+ expect_payment_sent ( & nodes[ 0 ] , payment_preimage, None , false , false /* expected post-event monitor update*/ ) ;
2916
+ }
0 commit comments