@@ -99,6 +99,24 @@ macro_rules! expect_channel_ready_event {
9999
100100pub ( crate ) use expect_channel_ready_event;
101101
102+ macro_rules! expect_splice_pending_event {
103+ ( $node: expr, $counterparty_node_id: expr) => { {
104+ match $node. next_event_async( ) . await {
105+ ref e @ Event :: SplicePending { new_funding_txo, counterparty_node_id, .. } => {
106+ println!( "{} got event {:?}" , $node. node_id( ) , e) ;
107+ assert_eq!( counterparty_node_id, $counterparty_node_id) ;
108+ $node. event_handled( ) . unwrap( ) ;
109+ new_funding_txo
110+ } ,
111+ ref e => {
112+ panic!( "{} got unexpected event!: {:?}" , std:: stringify!( $node) , e) ;
113+ } ,
114+ }
115+ } } ;
116+ }
117+
118+ pub ( crate ) use expect_splice_pending_event;
119+
102120macro_rules! expect_payment_received_event {
103121 ( $node: expr, $amount_msat: expr) => { {
104122 match $node. next_event_async( ) . await {
@@ -761,8 +779,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
761779 node_b_anchor_reserve_sat
762780 ) ;
763781
764- let user_channel_id = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
765- expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
782+ let user_channel_id_a = expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
783+ let user_channel_id_b = expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
766784
767785 println ! ( "\n B receive" ) ;
768786 let invoice_amount_1_msat = 2500_000 ;
@@ -1051,12 +1069,65 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
10511069 1
10521070 ) ;
10531071
1072+ println ! ( "\n B splices out to pay A" ) ;
1073+ let addr_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
1074+ let splice_out_sat = funding_amount_sat / 2 ;
1075+ node_b. splice_out ( & user_channel_id_b, node_a. node_id ( ) , addr_a, splice_out_sat) . unwrap ( ) ;
1076+
1077+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1078+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1079+
1080+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1081+ node_a. sync_wallets ( ) . unwrap ( ) ;
1082+ node_b. sync_wallets ( ) . unwrap ( ) ;
1083+
1084+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1085+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1086+
1087+ assert_eq ! (
1088+ node_a
1089+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
1090+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1091+ . len( ) ,
1092+ 2
1093+ ) ;
1094+ // FIXME: Should a splice-out be considered an outbound onchain payment?
1095+ //assert_eq!(
1096+ // node_b
1097+ // .list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound
1098+ // && matches!(p.kind, PaymentKind::Onchain { .. }))
1099+ // .len(),
1100+ // 1
1101+ //);
1102+
1103+ println ! ( "\n A splices in the splice-out payment from B" ) ;
1104+ let splice_in_sat = splice_out_sat;
1105+ node_a. splice_in ( & user_channel_id_a, node_b. node_id ( ) , splice_in_sat) . unwrap ( ) ;
1106+
1107+ expect_splice_pending_event ! ( node_a, node_b. node_id( ) ) ;
1108+ expect_splice_pending_event ! ( node_b, node_a. node_id( ) ) ;
1109+
1110+ generate_blocks_and_wait ( & bitcoind, electrsd, 6 ) . await ;
1111+ node_a. sync_wallets ( ) . unwrap ( ) ;
1112+ node_b. sync_wallets ( ) . unwrap ( ) ;
1113+
1114+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
1115+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
1116+
1117+ assert_eq ! (
1118+ node_a
1119+ . list_payments_with_filter( |p| p. direction == PaymentDirection :: Outbound
1120+ && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
1121+ . len( ) ,
1122+ 2
1123+ ) ;
1124+
10541125 println ! ( "\n B close_channel (force: {})" , force_close) ;
10551126 if force_close {
10561127 tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
1057- node_a. force_close_channel ( & user_channel_id , node_b. node_id ( ) , None ) . unwrap ( ) ;
1128+ node_a. force_close_channel ( & user_channel_id_a , node_b. node_id ( ) , None ) . unwrap ( ) ;
10581129 } else {
1059- node_a. close_channel ( & user_channel_id , node_b. node_id ( ) ) . unwrap ( ) ;
1130+ node_a. close_channel ( & user_channel_id_a , node_b. node_id ( ) ) . unwrap ( ) ;
10601131 }
10611132
10621133 expect_event ! ( node_a, ChannelClosed ) ;
@@ -1155,7 +1226,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11551226 + invoice_amount_3_msat
11561227 + determined_amount_msat
11571228 + keysend_amount_msat)
1158- / 1000 ;
1229+ / 1000 - splice_out_sat ;
11591230 let node_a_upper_bound_sat =
11601231 ( premine_amount_sat - funding_amount_sat) + ( funding_amount_sat - sum_of_all_payments_sat) ;
11611232 let node_a_lower_bound_sat = node_a_upper_bound_sat - onchain_fee_buffer_sat;
@@ -1176,7 +1247,7 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
11761247 . list_payments_with_filter( |p| p. direction == PaymentDirection :: Inbound
11771248 && matches!( p. kind, PaymentKind :: Onchain { .. } ) )
11781249 . len( ) ,
1179- 2
1250+ 3
11801251 ) ;
11811252 assert_eq ! (
11821253 node_b
0 commit comments