@@ -21,7 +21,7 @@ use ln::features::{InitFeatures, InvoiceFeatures};
21
21
use ln:: msgs;
22
22
use ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler , OptionalField } ;
23
23
use util:: enforcing_trait_impls:: EnforcingSigner ;
24
- use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
24
+ use util:: events:: { ClosureReason , Event , MessageSendEvent , MessageSendEventsProvider } ;
25
25
use util:: config:: UserConfig ;
26
26
use util:: ser:: { Writeable , ReadableArgs } ;
27
27
use util:: test_utils;
@@ -840,3 +840,52 @@ fn test_public_0_conf_channel() {
840
840
_ => panic ! ( "Unexpected event" ) ,
841
841
} ;
842
842
}
843
+
844
+ #[ test]
845
+ fn test_0_conf_channel_reorg ( ) {
846
+ // If we accept a 0conf channel, which is then confirmed, but then changes SCID in a reorg, we
847
+ // have to make sure we handle this correctly (or, currently, just force-close the channel).
848
+
849
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
850
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
851
+ let mut chan_config = test_default_channel_config ( ) ;
852
+ chan_config. manually_accept_inbound_channels = true ;
853
+
854
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( chan_config) ] ) ;
855
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
856
+
857
+ // This is the default but we force it on anyway
858
+ chan_config. channel_options . announced_channel = true ;
859
+ let tx = open_zero_conf_channel ( & nodes[ 0 ] , & nodes[ 1 ] , Some ( chan_config) ) ;
860
+
861
+ // We can use the channel immediately, but we can't announce it until we get 6+ confirmations
862
+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100_000 ) ;
863
+
864
+ mine_transaction ( & nodes[ 0 ] , & tx) ;
865
+ mine_transaction ( & nodes[ 1 ] , & tx) ;
866
+
867
+ // Send a payment using the channel's real SCID, which will be public in a few blocks once we
868
+ // can generate a channel_announcement.
869
+ let real_scid = nodes[ 0 ] . node . list_usable_channels ( ) [ 0 ] . short_channel_id . unwrap ( ) ;
870
+ assert_eq ! ( nodes[ 1 ] . node. list_usable_channels( ) [ 0 ] . short_channel_id. unwrap( ) , real_scid) ;
871
+
872
+ let ( mut route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 10_000 ) ;
873
+ assert_eq ! ( route. paths[ 0 ] [ 0 ] . short_channel_id, real_scid) ;
874
+ send_along_route_with_secret ( & nodes[ 0 ] , route, & [ & [ & nodes[ 1 ] ] ] , 10_000 , payment_hash, payment_secret) ;
875
+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage) ;
876
+
877
+ disconnect_blocks ( & nodes[ 0 ] , 1 ) ;
878
+ disconnect_blocks ( & nodes[ 1 ] , 1 ) ;
879
+
880
+ // At this point the channel no longer has an SCID again. In the future we should likely
881
+ // support simply un-setting the SCID and waiting until the channel gets re-confirmed, but for
882
+ // now we force-close the channel here.
883
+ check_closed_event ! ( & nodes[ 0 ] , 1 , ClosureReason :: ProcessingError {
884
+ err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs." . to_owned( )
885
+ } ) ;
886
+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
887
+ check_closed_event ! ( & nodes[ 1 ] , 1 , ClosureReason :: ProcessingError {
888
+ err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs." . to_owned( )
889
+ } ) ;
890
+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
891
+ }
0 commit comments