@@ -22,7 +22,7 @@ use ln::msgs;
2222use ln:: msgs:: { ChannelMessageHandler , RoutingMessageHandler , OptionalField , ChannelUpdate } ;
2323use ln:: wire:: Encode ;
2424use util:: enforcing_trait_impls:: EnforcingSigner ;
25- use util:: events:: { Event , MessageSendEvent , MessageSendEventsProvider } ;
25+ use util:: events:: { ClosureReason , Event , MessageSendEvent , MessageSendEventsProvider } ;
2626use util:: config:: UserConfig ;
2727use util:: ser:: { Writeable , ReadableArgs } ;
2828use util:: test_utils;
@@ -873,3 +873,52 @@ fn test_public_0conf_channel() {
873873 _ => panic ! ( "Unexpected event" ) ,
874874 } ;
875875}
876+
877+ #[ test]
878+ fn test_0conf_channel_reorg ( ) {
879+ // If we accept a 0conf channel, which is then confirmed, but then changes SCID in a reorg, we
880+ // have to make sure we handle this correctly (or, currently, just force-close the channel).
881+
882+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
883+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
884+ let mut chan_config = test_default_channel_config ( ) ;
885+ chan_config. manually_accept_inbound_channels = true ;
886+
887+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , Some ( chan_config) ] ) ;
888+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
889+
890+ // This is the default but we force it on anyway
891+ chan_config. channel_options . announced_channel = true ;
892+ let tx = open_zero_conf_channel ( & nodes[ 0 ] , & nodes[ 1 ] , Some ( chan_config) ) ;
893+
894+ // We can use the channel immediately, but we can't announce it until we get 6+ confirmations
895+ send_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 100_000 ) ;
896+
897+ mine_transaction ( & nodes[ 0 ] , & tx) ;
898+ mine_transaction ( & nodes[ 1 ] , & tx) ;
899+
900+ // Send a payment using the channel's real SCID, which will be public in a few blocks once we
901+ // can generate a channel_announcement.
902+ let real_scid = nodes[ 0 ] . node . list_usable_channels ( ) [ 0 ] . short_channel_id . unwrap ( ) ;
903+ assert_eq ! ( nodes[ 1 ] . node. list_usable_channels( ) [ 0 ] . short_channel_id. unwrap( ) , real_scid) ;
904+
905+ let ( mut route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 10_000 ) ;
906+ assert_eq ! ( route. paths[ 0 ] [ 0 ] . short_channel_id, real_scid) ;
907+ send_along_route_with_secret ( & nodes[ 0 ] , route, & [ & [ & nodes[ 1 ] ] ] , 10_000 , payment_hash, payment_secret) ;
908+ claim_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , payment_preimage) ;
909+
910+ disconnect_blocks ( & nodes[ 0 ] , 1 ) ;
911+ disconnect_blocks ( & nodes[ 1 ] , 1 ) ;
912+
913+ // At this point the channel no longer has an SCID again. In the future we should likely
914+ // support simply un-setting the SCID and waiting until the channel gets re-confirmed, but for
915+ // now we force-close the channel here.
916+ check_closed_event ! ( & nodes[ 0 ] , 1 , ClosureReason :: ProcessingError {
917+ err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs." . to_owned( )
918+ } ) ;
919+ check_closed_broadcast ! ( nodes[ 0 ] , true ) ;
920+ check_closed_event ! ( & nodes[ 1 ] , 1 , ClosureReason :: ProcessingError {
921+ err: "Funding transaction was un-confirmed. Locked at 0 confs, now have 0 confs." . to_owned( )
922+ } ) ;
923+ check_closed_broadcast ! ( nodes[ 1 ] , true ) ;
924+ }
0 commit comments