@@ -35,14 +35,15 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
3535 tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
3636 }
3737
38- let payment_id = node_a. spontaneous_payment ( ) . send_with_preimage (
38+ let spontaneous_payment = node_a. spontaneous_payment ( ) ;
39+ let payment_id = spontaneous_payment. send_with_preimage (
3940 amount_msat,
4041 node_b. node_id ( ) ,
4142 preimage,
4243 None ,
4344 ) ;
4445
45- match payment_id {
46+ match payment_id. await {
4647 Ok ( payment_id) => {
4748 println ! (
4849 "{}: Awaiting payment with id {}" ,
@@ -93,7 +94,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
9394 } ,
9495 }
9596
96- node_a. event_handled ( ) . unwrap ( ) ;
97+ node_a. event_handled ( ) . await . unwrap ( ) ;
9798 }
9899
99100 let duration = start. elapsed ( ) ;
@@ -110,37 +111,36 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
110111 PaymentPreimage ( preimage_bytes) ,
111112 None ,
112113 )
114+ . await
113115 . ok ( )
114116 . unwrap ( ) ;
115117
116118 duration
117119}
118120
119121fn payment_benchmark ( c : & mut Criterion ) {
120- // Set up two nodes. Because this is slow, we reuse the same nodes for each sample.
121- let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
122- let chain_source = random_chain_source ( & bitcoind, & electrsd) ;
123-
124- let ( node_a, node_b) = setup_two_nodes_with_store (
125- & chain_source,
126- false ,
127- true ,
128- false ,
129- common:: TestStoreType :: Sqlite ,
130- ) ;
131-
132122 let runtime =
133123 tokio:: runtime:: Builder :: new_multi_thread ( ) . worker_threads ( 4 ) . enable_all ( ) . build ( ) . unwrap ( ) ;
134124
135- let node_a = Arc :: new ( node_a) ;
136- let node_b = Arc :: new ( node_b) ;
125+ // Set up two nodes. Because this is slow, we reuse the same nodes for each sample.
126+ let ( setup_done, setup_result) = std:: sync:: mpsc:: channel ( ) ;
127+ runtime. spawn ( async move {
128+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
129+ let chain_source = random_chain_source ( & bitcoind, & electrsd) ;
130+ let ( node_a, node_b) = setup_two_nodes_with_store (
131+ & chain_source,
132+ false ,
133+ true ,
134+ false ,
135+ common:: TestStoreType :: Sqlite ,
136+ )
137+ . await ;
138+
139+ let node_a = Arc :: new ( node_a) ;
140+ let node_b = Arc :: new ( node_b) ;
137141
138- // Fund the nodes and setup a channel between them. The criterion function cannot be async, so we need to execute
139- // the setup using a runtime.
140- let node_a_cloned = Arc :: clone ( & node_a) ;
141- let node_b_cloned = Arc :: clone ( & node_b) ;
142- runtime. block_on ( async move {
143- let address_a = node_a_cloned. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
142+ // Fund the nodes and setup a channel between them.
143+ let address_a = node_a. onchain_payment ( ) . new_address ( ) . await . unwrap ( ) ;
144144 let premine_sat = 25_000_000 ;
145145 premine_and_distribute_funds (
146146 & bitcoind. client ,
@@ -149,23 +149,18 @@ fn payment_benchmark(c: &mut Criterion) {
149149 Amount :: from_sat ( premine_sat) ,
150150 )
151151 . await ;
152- node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
153- node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
154- open_channel_push_amt (
155- & node_a_cloned,
156- & node_b_cloned,
157- 16_000_000 ,
158- Some ( 1_000_000_000 ) ,
159- false ,
160- & electrsd,
161- )
162- . await ;
152+ node_a. sync_wallets ( ) . await . unwrap ( ) ;
153+ node_b. sync_wallets ( ) . await . unwrap ( ) ;
154+ open_channel_push_amt ( & node_a, & node_b, 16_000_000 , Some ( 1_000_000_000 ) , false , & electrsd)
155+ . await ;
163156 generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
164- node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
165- node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
166- expect_channel_ready_event ! ( node_a_cloned, node_b_cloned. node_id( ) ) ;
167- expect_channel_ready_event ! ( node_b_cloned, node_a_cloned. node_id( ) ) ;
157+ node_a. sync_wallets ( ) . await . unwrap ( ) ;
158+ node_b. sync_wallets ( ) . await . unwrap ( ) ;
159+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
160+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
161+ setup_done. send ( ( node_a, node_b) ) . unwrap ( ) ;
168162 } ) ;
163+ let ( node_a, node_b) = setup_result. recv ( ) . unwrap ( ) ;
169164
170165 let mut group = c. benchmark_group ( "payments" ) ;
171166 group. sample_size ( 10 ) ;
0 commit comments