@@ -1912,6 +1912,7 @@ async fn lsps2_client_trusts_lsp() {
19121912 client_builder. set_liquidity_source_lsps2 ( service_node_id, service_addr. clone ( ) , None ) ;
19131913 let client_node = client_builder. build ( ) . unwrap ( ) ;
19141914 client_node. start ( ) . unwrap ( ) ;
1915+ let client_node_id = client_node. node_id ( ) ;
19151916
19161917 let payer_config = random_config ( true ) ;
19171918 setup_builder ! ( payer_builder, payer_config. node_config) ;
@@ -1945,8 +1946,6 @@ async fn lsps2_client_trusts_lsp() {
19451946 expect_channel_ready_event ! ( payer_node, service_node. node_id( ) ) ;
19461947 expect_channel_ready_event ! ( service_node, payer_node. node_id( ) ) ;
19471948
1948- let initial_mempool_size = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) . 0 . len ( ) ;
1949-
19501949 let invoice_description =
19511950 Bolt11InvoiceDescription :: Direct ( Description :: new ( String :: from ( "asdf" ) ) . unwrap ( ) ) ;
19521951 let jit_amount_msat = 100_000_000 ;
@@ -1969,21 +1968,41 @@ async fn lsps2_client_trusts_lsp() {
19691968 println ! ( "Paying JIT invoice!" ) ;
19701969 let payment_id = payer_node. bolt11_payment ( ) . send ( & res, None ) . unwrap ( ) ;
19711970 println ! ( "Payment ID: {:?}" , payment_id) ;
1972- expect_channel_pending_event ! ( service_node, client_node. node_id( ) ) ;
1971+ let funding_txo = expect_channel_pending_event ! ( service_node, client_node. node_id( ) ) ;
19731972 expect_channel_ready_event ! ( service_node, client_node. node_id( ) ) ;
19741973 expect_channel_pending_event ! ( client_node, service_node. node_id( ) ) ;
19751974 expect_channel_ready_event ! ( client_node, service_node. node_id( ) ) ;
1975+
1976+ // Check the fundign transaction hasn't broadcasted yet and nodes aren't seeing it.
19761977 println ! ( "Try to find funding tx... It won't be found yet, as the client has not claimed it." ) ;
1977- let mut funding_tx_found = false ;
1978- for _ in 0 ..50 {
1979- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
1980- let current_mempool = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) ;
1981- if current_mempool. 0 . len ( ) > initial_mempool_size {
1982- funding_tx_found = true ;
1983- break ;
1984- }
1978+ for _ in 0 ..30 {
1979+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
1980+ let mempool = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) . into_model ( ) . unwrap ( ) ;
1981+ let funding_tx_found = mempool. 0 . iter ( ) . any ( |txid| * txid == funding_txo. txid ) ;
1982+ assert ! ( !funding_tx_found, "Funding transaction should NOT be broadcast yet" ) ;
19851983 }
1986- assert ! ( !funding_tx_found, "Funding transaction should NOT be broadcast yet" ) ;
1984+ service_node. sync_wallets ( ) . unwrap ( ) ;
1985+ client_node. sync_wallets ( ) . unwrap ( ) ;
1986+ assert_eq ! (
1987+ client_node
1988+ . list_channels( )
1989+ . iter( )
1990+ . find( |c| c. counterparty_node_id == service_node_id)
1991+ . unwrap( )
1992+ . confirmations,
1993+ Some ( 0 )
1994+ ) ;
1995+ assert_eq ! (
1996+ service_node
1997+ . list_channels( )
1998+ . iter( )
1999+ . find( |c| c. counterparty_node_id == client_node_id)
2000+ . unwrap( )
2001+ . confirmations,
2002+ Some ( 0 )
2003+ ) ;
2004+
2005+ // No claim the JIT payment, which should release the funding transaction
19872006 let service_fee_msat = ( jit_amount_msat * channel_opening_fee_ppm as u64 ) / 1_000_000 ;
19882007 let expected_received_amount_msat = jit_amount_msat - service_fee_msat;
19892008
@@ -2003,18 +2022,29 @@ async fn lsps2_client_trusts_lsp() {
20032022
20042023 let _ = expect_payment_received_event ! ( client_node, expected_received_amount_msat) . unwrap ( ) ;
20052024
2006- println ! ( "Waiting for funding transaction to be broadcast..." ) ;
2007- let mut funding_tx_found = false ;
2008- for _ in 0 ..500 {
2009- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
2010- let current_mempool = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) ;
2011- if current_mempool. 0 . len ( ) > initial_mempool_size {
2012- funding_tx_found = true ;
2013- break ;
2014- }
2015- }
2016-
2017- assert ! ( funding_tx_found, "Funding transaction should be broadcast after the client claims it" ) ;
2025+ // Check the nodes pick up on the confirmed funding tx now.
2026+ wait_for_tx ( & electrsd. client , funding_txo. txid ) . await ;
2027+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
2028+ service_node. sync_wallets ( ) . unwrap ( ) ;
2029+ client_node. sync_wallets ( ) . unwrap ( ) ;
2030+ assert_eq ! (
2031+ client_node
2032+ . list_channels( )
2033+ . iter( )
2034+ . find( |c| c. counterparty_node_id == service_node_id)
2035+ . unwrap( )
2036+ . confirmations,
2037+ Some ( 6 )
2038+ ) ;
2039+ assert_eq ! (
2040+ service_node
2041+ . list_channels( )
2042+ . iter( )
2043+ . find( |c| c. counterparty_node_id == client_node_id)
2044+ . unwrap( )
2045+ . confirmations,
2046+ Some ( 6 )
2047+ ) ;
20182048}
20192049
20202050#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
@@ -2058,6 +2088,8 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
20582088 let client_node = client_builder. build ( ) . unwrap ( ) ;
20592089 client_node. start ( ) . unwrap ( ) ;
20602090
2091+ let client_node_id = client_node. node_id ( ) ;
2092+
20612093 let payer_config = random_config ( true ) ;
20622094 setup_builder ! ( payer_builder, payer_config. node_config) ;
20632095 payer_builder. set_chain_source_esplora ( esplora_url. clone ( ) , Some ( sync_config) ) ;
@@ -2090,8 +2122,6 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
20902122 expect_channel_ready_event ! ( payer_node, service_node. node_id( ) ) ;
20912123 expect_channel_ready_event ! ( service_node, payer_node. node_id( ) ) ;
20922124
2093- let initial_mempool_size = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) . 0 . len ( ) ;
2094-
20952125 let invoice_description =
20962126 Bolt11InvoiceDescription :: Direct ( Description :: new ( String :: from ( "asdf" ) ) . unwrap ( ) ) ;
20972127 let jit_amount_msat = 100_000_000 ;
@@ -2113,19 +2143,33 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
21132143 // Have the payer_node pay the invoice, therby triggering channel open service_node -> client_node.
21142144 println ! ( "Paying JIT invoice!" ) ;
21152145 let _payment_id = payer_node. bolt11_payment ( ) . send ( & res, None ) . unwrap ( ) ;
2116- expect_channel_pending_event ! ( service_node, client_node. node_id( ) ) ;
2146+ let funding_txo = expect_channel_pending_event ! ( service_node, client_node. node_id( ) ) ;
21172147 expect_channel_ready_event ! ( service_node, client_node. node_id( ) ) ;
21182148 expect_channel_pending_event ! ( client_node, service_node. node_id( ) ) ;
21192149 expect_channel_ready_event ! ( client_node, service_node. node_id( ) ) ;
2120- println ! ( "Waiting for funding transaction to be broadcast... It will be there because LSP trusts the client, even though the client has not claimed it yet." ) ;
2121- let mut funding_tx_found = false ;
2122- for _ in 0 ..500 {
2123- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) ;
2124- let current_mempool = bitcoind. client . get_raw_mempool ( ) . unwrap ( ) ;
2125- if current_mempool. 0 . len ( ) > initial_mempool_size {
2126- funding_tx_found = true ;
2127- break ;
2128- }
2129- }
2130- assert ! ( funding_tx_found, "Funding transaction should be broadcast" ) ;
2150+ println ! ( "Waiting for funding transaction to be broadcast..." ) ;
2151+
2152+ // Check the nodes pick up on the confirmed funding tx now.
2153+ wait_for_tx ( & electrsd. client , funding_txo. txid ) . await ;
2154+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
2155+ service_node. sync_wallets ( ) . unwrap ( ) ;
2156+ client_node. sync_wallets ( ) . unwrap ( ) ;
2157+ assert_eq ! (
2158+ client_node
2159+ . list_channels( )
2160+ . iter( )
2161+ . find( |c| c. counterparty_node_id == service_node_id)
2162+ . unwrap( )
2163+ . confirmations,
2164+ Some ( 6 )
2165+ ) ;
2166+ assert_eq ! (
2167+ service_node
2168+ . list_channels( )
2169+ . iter( )
2170+ . find( |c| c. counterparty_node_id == client_node_id)
2171+ . unwrap( )
2172+ . confirmations,
2173+ Some ( 6 )
2174+ ) ;
21312175}
0 commit comments