@@ -1282,6 +1282,72 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
12821282 } } ;
12831283 }
12841284
1285+ let splice_channel = |node : & ChannelManager < _ , _ , _ , _ , _ , _ , _ , _ , _ > ,
1286+ counterparty_node_id : & PublicKey ,
1287+ channel_id : & ChannelId ,
1288+ contribution : SpliceContribution ,
1289+ funding_feerate_sat_per_kw : u32 | {
1290+ if let Err ( e) = node. splice_channel (
1291+ channel_id,
1292+ counterparty_node_id,
1293+ contribution,
1294+ funding_feerate_sat_per_kw,
1295+ None ,
1296+ ) {
1297+ assert ! (
1298+ matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
1299+ "{:?}" ,
1300+ e
1301+ ) ;
1302+ }
1303+ } ;
1304+
1305+ let splice_in = |node : & ChannelManager < _ , _ , _ , _ , _ , _ , _ , _ , _ > ,
1306+ counterparty_node_id : & PublicKey ,
1307+ channel_id : & ChannelId ,
1308+ input : FundingTxInput ,
1309+ funding_feerate_sat_per_kw : u32 | {
1310+ let contribution =
1311+ SpliceContribution :: splice_in ( Amount :: from_sat ( 10_000 ) , vec ! [ input] , None ) ;
1312+ splice_channel (
1313+ node,
1314+ counterparty_node_id,
1315+ channel_id,
1316+ contribution,
1317+ funding_feerate_sat_per_kw,
1318+ ) ;
1319+ } ;
1320+
1321+ let splice_out = |node : & ChannelManager < _ , _ , _ , _ , _ , _ , _ , _ , _ > ,
1322+ counterparty_node_id : & PublicKey ,
1323+ channel_id : & ChannelId ,
1324+ output : TxOut ,
1325+ funding_feerate_sat_per_kw : u32 | {
1326+ // We conditionally splice out `MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS` only when the node
1327+ // has double the balance required to send a payment upon a `0xff` byte. We do this to
1328+ // ensure there's always liquidity available for a payment to succeed then.
1329+ let outbound_capacity_msat = node
1330+ . list_channels ( )
1331+ . iter ( )
1332+ . find ( |chan| chan. channel_id == * channel_id)
1333+ . map ( |chan| chan. outbound_capacity_msat )
1334+ . unwrap ( ) ;
1335+ if outbound_capacity_msat < 20_000_000 {
1336+ return ;
1337+ }
1338+ let contribution = SpliceContribution :: splice_out ( vec ! [ TxOut {
1339+ value: Amount :: from_sat( MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ) ,
1340+ script_pubkey: output. script_pubkey,
1341+ } ] ) ;
1342+ splice_channel (
1343+ node,
1344+ counterparty_node_id,
1345+ channel_id,
1346+ contribution,
1347+ funding_feerate_sat_per_kw,
1348+ ) ;
1349+ } ;
1350+
12851351 let wallet_a = TestWallet :: new ( SecretKey :: from_slice ( & [ 1 ; 32 ] ) . unwrap ( ) ) ;
12861352 let wallet_b = TestWallet :: new ( SecretKey :: from_slice ( & [ 2 ; 32 ] ) . unwrap ( ) ) ;
12871353 let wallet_c = TestWallet :: new ( SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ) ;
@@ -2306,199 +2372,92 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
23062372
23072373 0xa0 => {
23082374 let input = FundingTxInput :: new_p2wpkh ( coinbase_tx. clone ( ) , 0 ) . unwrap ( ) ;
2309- let contribution =
2310- SpliceContribution :: splice_in ( Amount :: from_sat ( 10_000 ) , vec ! [ input] , None ) ;
23112375 let funding_feerate_sat_per_kw = fee_est_a. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2312- if let Err ( e ) = nodes [ 0 ] . splice_channel (
2313- & chan_a_id ,
2376+ splice_in (
2377+ & nodes [ 0 ] ,
23142378 & nodes[ 1 ] . get_our_node_id ( ) ,
2315- contribution,
2379+ & chan_a_id,
2380+ input,
23162381 funding_feerate_sat_per_kw,
2317- None ,
2318- ) {
2319- assert ! (
2320- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2321- "{:?}" ,
2322- e
2323- ) ;
2324- }
2382+ ) ;
23252383 } ,
23262384 0xa1 => {
23272385 let input = FundingTxInput :: new_p2wpkh ( coinbase_tx. clone ( ) , 1 ) . unwrap ( ) ;
2328- let contribution =
2329- SpliceContribution :: splice_in ( Amount :: from_sat ( 10_000 ) , vec ! [ input] , None ) ;
23302386 let funding_feerate_sat_per_kw = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2331- if let Err ( e ) = nodes [ 1 ] . splice_channel (
2332- & chan_a_id ,
2387+ splice_in (
2388+ & nodes [ 1 ] ,
23332389 & nodes[ 0 ] . get_our_node_id ( ) ,
2334- contribution,
2390+ & chan_a_id,
2391+ input,
23352392 funding_feerate_sat_per_kw,
2336- None ,
2337- ) {
2338- assert ! (
2339- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2340- "{:?}" ,
2341- e
2342- ) ;
2343- }
2393+ ) ;
23442394 } ,
23452395 0xa2 => {
23462396 let input = FundingTxInput :: new_p2wpkh ( coinbase_tx. clone ( ) , 1 ) . unwrap ( ) ;
2347- let contribution =
2348- SpliceContribution :: splice_in ( Amount :: from_sat ( 10_000 ) , vec ! [ input] , None ) ;
23492397 let funding_feerate_sat_per_kw = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2350- if let Err ( e ) = nodes [ 1 ] . splice_channel (
2351- & chan_b_id ,
2398+ splice_in (
2399+ & nodes [ 1 ] ,
23522400 & nodes[ 2 ] . get_our_node_id ( ) ,
2353- contribution,
2401+ & chan_b_id,
2402+ input,
23542403 funding_feerate_sat_per_kw,
2355- None ,
2356- ) {
2357- assert ! (
2358- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2359- "{:?}" ,
2360- e
2361- ) ;
2362- }
2404+ ) ;
23632405 } ,
23642406 0xa3 => {
23652407 let input = FundingTxInput :: new_p2wpkh ( coinbase_tx. clone ( ) , 2 ) . unwrap ( ) ;
2366- let contribution =
2367- SpliceContribution :: splice_in ( Amount :: from_sat ( 10_000 ) , vec ! [ input] , None ) ;
23682408 let funding_feerate_sat_per_kw = fee_est_c. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2369- if let Err ( e ) = nodes [ 2 ] . splice_channel (
2370- & chan_b_id ,
2409+ splice_in (
2410+ & nodes [ 2 ] ,
23712411 & nodes[ 1 ] . get_our_node_id ( ) ,
2372- contribution,
2412+ & chan_b_id,
2413+ input,
23732414 funding_feerate_sat_per_kw,
2374- None ,
2375- ) {
2376- assert ! (
2377- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2378- "{:?}" ,
2379- e
2380- ) ;
2381- }
2415+ ) ;
23822416 } ,
23832417
2384- // We conditionally splice out `MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS` only when the node
2385- // has double the balance required to send a payment upon a `0xff` byte. We do this to
2386- // ensure there's always liquidity available for a payment to succeed then.
23872418 0xa4 => {
2388- let outbound_capacity_msat = nodes[ 0 ]
2389- . list_channels ( )
2390- . iter ( )
2391- . find ( |chan| chan. channel_id == chan_a_id)
2392- . map ( |chan| chan. outbound_capacity_msat )
2393- . unwrap ( ) ;
2394- if outbound_capacity_msat >= 20_000_000 {
2395- let contribution = SpliceContribution :: splice_out ( vec ! [ TxOut {
2396- value: Amount :: from_sat( MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ) ,
2397- script_pubkey: coinbase_tx. output[ 0 ] . script_pubkey. clone( ) ,
2398- } ] ) ;
2399- let funding_feerate_sat_per_kw =
2400- fee_est_a. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2401- if let Err ( e) = nodes[ 0 ] . splice_channel (
2402- & chan_a_id,
2403- & nodes[ 1 ] . get_our_node_id ( ) ,
2404- contribution,
2405- funding_feerate_sat_per_kw,
2406- None ,
2407- ) {
2408- assert ! (
2409- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2410- "{:?}" ,
2411- e
2412- ) ;
2413- }
2414- }
2419+ let output = coinbase_tx. output [ 0 ] . clone ( ) ;
2420+ let funding_feerate_sat_per_kw = fee_est_a. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2421+ splice_out (
2422+ & nodes[ 0 ] ,
2423+ & nodes[ 1 ] . get_our_node_id ( ) ,
2424+ & chan_a_id,
2425+ output,
2426+ funding_feerate_sat_per_kw,
2427+ ) ;
24152428 } ,
24162429 0xa5 => {
2417- let outbound_capacity_msat = nodes[ 1 ]
2418- . list_channels ( )
2419- . iter ( )
2420- . find ( |chan| chan. channel_id == chan_a_id)
2421- . map ( |chan| chan. outbound_capacity_msat )
2422- . unwrap ( ) ;
2423- if outbound_capacity_msat >= 20_000_000 {
2424- let contribution = SpliceContribution :: splice_out ( vec ! [ TxOut {
2425- value: Amount :: from_sat( MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ) ,
2426- script_pubkey: coinbase_tx. output[ 1 ] . script_pubkey. clone( ) ,
2427- } ] ) ;
2428- let funding_feerate_sat_per_kw =
2429- fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2430- if let Err ( e) = nodes[ 1 ] . splice_channel (
2431- & chan_a_id,
2432- & nodes[ 0 ] . get_our_node_id ( ) ,
2433- contribution,
2434- funding_feerate_sat_per_kw,
2435- None ,
2436- ) {
2437- assert ! (
2438- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2439- "{:?}" ,
2440- e
2441- ) ;
2442- }
2443- }
2430+ let output = coinbase_tx. output [ 1 ] . clone ( ) ;
2431+ let funding_feerate_sat_per_kw = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2432+ splice_out (
2433+ & nodes[ 1 ] ,
2434+ & nodes[ 0 ] . get_our_node_id ( ) ,
2435+ & chan_a_id,
2436+ output,
2437+ funding_feerate_sat_per_kw,
2438+ ) ;
24442439 } ,
24452440 0xa6 => {
2446- let outbound_capacity_msat = nodes[ 1 ]
2447- . list_channels ( )
2448- . iter ( )
2449- . find ( |chan| chan. channel_id == chan_b_id)
2450- . map ( |chan| chan. outbound_capacity_msat )
2451- . unwrap ( ) ;
2452- if outbound_capacity_msat >= 20_000_000 {
2453- let contribution = SpliceContribution :: splice_out ( vec ! [ TxOut {
2454- value: Amount :: from_sat( MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ) ,
2455- script_pubkey: coinbase_tx. output[ 1 ] . script_pubkey. clone( ) ,
2456- } ] ) ;
2457- let funding_feerate_sat_per_kw =
2458- fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2459- if let Err ( e) = nodes[ 1 ] . splice_channel (
2460- & chan_b_id,
2461- & nodes[ 2 ] . get_our_node_id ( ) ,
2462- contribution,
2463- funding_feerate_sat_per_kw,
2464- None ,
2465- ) {
2466- assert ! (
2467- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2468- "{:?}" ,
2469- e
2470- ) ;
2471- }
2472- }
2441+ let output = coinbase_tx. output [ 1 ] . clone ( ) ;
2442+ let funding_feerate_sat_per_kw = fee_est_b. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2443+ splice_out (
2444+ & nodes[ 1 ] ,
2445+ & nodes[ 2 ] . get_our_node_id ( ) ,
2446+ & chan_b_id,
2447+ output,
2448+ funding_feerate_sat_per_kw,
2449+ ) ;
24732450 } ,
24742451 0xa7 => {
2475- let outbound_capacity_msat = nodes[ 2 ]
2476- . list_channels ( )
2477- . iter ( )
2478- . find ( |chan| chan. channel_id == chan_b_id)
2479- . map ( |chan| chan. outbound_capacity_msat )
2480- . unwrap ( ) ;
2481- if outbound_capacity_msat >= 20_000_000 {
2482- let contribution = SpliceContribution :: splice_out ( vec ! [ TxOut {
2483- value: Amount :: from_sat( MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS ) ,
2484- script_pubkey: coinbase_tx. output[ 2 ] . script_pubkey. clone( ) ,
2485- } ] ) ;
2486- let funding_feerate_sat_per_kw =
2487- fee_est_c. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2488- if let Err ( e) = nodes[ 2 ] . splice_channel (
2489- & chan_b_id,
2490- & nodes[ 1 ] . get_our_node_id ( ) ,
2491- contribution,
2492- funding_feerate_sat_per_kw,
2493- None ,
2494- ) {
2495- assert ! (
2496- matches!( e, APIError :: APIMisuseError { ref err } if err. contains( "splice pending" ) ) ,
2497- "{:?}" ,
2498- e
2499- ) ;
2500- }
2501- }
2452+ let output = coinbase_tx. output [ 2 ] . clone ( ) ;
2453+ let funding_feerate_sat_per_kw = fee_est_c. ret_val . load ( atomic:: Ordering :: Acquire ) ;
2454+ splice_out (
2455+ & nodes[ 2 ] ,
2456+ & nodes[ 1 ] . get_our_node_id ( ) ,
2457+ & chan_b_id,
2458+ output,
2459+ funding_feerate_sat_per_kw,
2460+ ) ;
25022461 } ,
25032462
25042463 // Sync node by 1 block to cover confirmation of a transaction.
0 commit comments