@@ -8,7 +8,8 @@ use bitcoin::hex::DisplayHex;
88use bitcoin:: Amount ;
99use common:: {
1010 expect_channel_ready_event, generate_blocks_and_wait, premine_and_distribute_funds,
11- random_chain_source, setup_bitcoind_and_electrsd, setup_two_nodes_with_store,
11+ setup_bitcoind_and_electrsd, setup_two_nodes_with_store, store_bench_configs,
12+ wait_for_payment_success, TestChainSource ,
1213} ;
1314use criterion:: { criterion_group, criterion_main, Criterion } ;
1415use ldk_node:: { Event , Node } ;
@@ -102,7 +103,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
102103 // Send back the money for the next iteration.
103104 let mut preimage_bytes = [ 0u8 ; 32 ] ;
104105 rand:: rng ( ) . fill_bytes ( & mut preimage_bytes) ;
105- node_b
106+ let return_payment_id = node_b
106107 . spontaneous_payment ( )
107108 . send_with_preimage (
108109 amount_msat * total_payments,
@@ -112,78 +113,92 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
112113 )
113114 . ok ( )
114115 . unwrap ( ) ;
116+ wait_for_payment_success ( & node_b, return_payment_id) . await ;
115117
116118 duration
117119}
118120
119121fn payment_benchmark ( c : & mut Criterion ) {
120122 // Set up two nodes. Because this is slow, we reuse the same nodes for each sample.
121123 let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
122- let chain_source = random_chain_source ( & bitcoind, & electrsd) ;
123-
124- let ( node_a, node_b) =
125- setup_two_nodes_with_store ( & chain_source, false , false , common:: TestStoreType :: Sqlite ) ;
126-
127- let runtime =
128- tokio:: runtime:: Builder :: new_multi_thread ( ) . worker_threads ( 4 ) . enable_all ( ) . build ( ) . unwrap ( ) ;
129-
130- let node_a = Arc :: new ( node_a) ;
131- let node_b = Arc :: new ( node_b) ;
132-
133- // Fund the nodes and setup a channel between them. The criterion function cannot be async, so we need to execute
134- // the setup using a runtime.
135- let node_a_cloned = Arc :: clone ( & node_a) ;
136- let node_b_cloned = Arc :: clone ( & node_b) ;
137- runtime. block_on ( async move {
138- let address_a = node_a_cloned. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
139- let premine_sat = 25_000_000 ;
140- premine_and_distribute_funds (
141- & bitcoind. client ,
142- & electrsd. client ,
143- vec ! [ address_a] ,
144- Amount :: from_sat ( premine_sat) ,
145- )
146- . await ;
147- node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
148- node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
149- open_channel_push_amt (
150- & node_a_cloned,
151- & node_b_cloned,
152- 16_000_000 ,
153- Some ( 1_000_000_000 ) ,
154- false ,
155- & electrsd,
156- )
157- . await ;
158- generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
159- node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
160- node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
161- expect_channel_ready_event ! ( node_a_cloned, node_b_cloned. node_id( ) ) ;
162- expect_channel_ready_event ! ( node_b_cloned, node_a_cloned. node_id( ) ) ;
163- } ) ;
124+ let chain_source = TestChainSource :: BitcoindRpcSync ( & bitcoind) ;
125+
126+ let store_configs = store_bench_configs ( ) ;
127+
128+ let runtime = benchmark_runtime ( ) ;
164129
165130 let mut group = c. benchmark_group ( "payments" ) ;
166131 group. sample_size ( 10 ) ;
167132
168- group. bench_function ( "payments" , |b| {
169- // Use custom timing so that sending back the money at the end of each iteration isn't included in the
170- // measurement.
171- b. to_async ( & runtime) . iter_custom ( |iter| {
133+ for store_config in store_configs {
134+ let ( node_a, node_b) =
135+ setup_two_nodes_with_store ( & chain_source, false , false , store_config. store_type ) ;
136+
137+ let node_a = Arc :: new ( node_a) ;
138+ let node_b = Arc :: new ( node_b) ;
139+
140+ // Fund the nodes and setup a channel between them. The criterion function cannot be async,
141+ // so we need to execute the setup using a runtime.
142+ let node_a_cloned = Arc :: clone ( & node_a) ;
143+ let node_b_cloned = Arc :: clone ( & node_b) ;
144+ runtime. block_on ( async {
145+ let address_a = node_a_cloned. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
146+ let premine_sat = 25_000_000 ;
147+ premine_and_distribute_funds (
148+ & bitcoind. client ,
149+ & electrsd. client ,
150+ vec ! [ address_a] ,
151+ Amount :: from_sat ( premine_sat) ,
152+ )
153+ . await ;
154+ node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
155+ node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
156+ open_channel_push_amt (
157+ & node_a_cloned,
158+ & node_b_cloned,
159+ 16_000_000 ,
160+ Some ( 1_000_000_000 ) ,
161+ false ,
162+ & electrsd,
163+ )
164+ . await ;
165+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
166+ node_a_cloned. sync_wallets ( ) . unwrap ( ) ;
167+ node_b_cloned. sync_wallets ( ) . unwrap ( ) ;
168+ expect_channel_ready_event ! ( node_a_cloned, node_b_cloned. node_id( ) ) ;
169+ expect_channel_ready_event ! ( node_b_cloned, node_a_cloned. node_id( ) ) ;
170+ } ) ;
171+
172+ group. bench_function ( store_config. name , |b| {
173+ // Use custom timing so that sending back the money at the end of each iteration isn't
174+ // included in the measurement.
172175 let node_a = Arc :: clone ( & node_a) ;
173176 let node_b = Arc :: clone ( & node_b) ;
174-
175- async move {
176- let mut total = Duration :: ZERO ;
177- for _i in 0 ..iter {
178- let node_a = Arc :: clone ( & node_a) ;
179- let node_b = Arc :: clone ( & node_b) ;
180-
181- total += send_payments ( node_a, node_b) . await ;
177+ b. to_async ( & runtime) . iter_custom ( |iter| {
178+ let node_a = Arc :: clone ( & node_a) ;
179+ let node_b = Arc :: clone ( & node_b) ;
180+
181+ async move {
182+ let mut total = Duration :: ZERO ;
183+ for _i in 0 ..iter {
184+ let node_a = Arc :: clone ( & node_a) ;
185+ let node_b = Arc :: clone ( & node_b) ;
186+
187+ total += send_payments ( node_a, node_b) . await ;
188+ }
189+ total
182190 }
183- total
184- }
191+ } ) ;
185192 } ) ;
186- } ) ;
193+ }
194+ }
195+
196+ fn benchmark_runtime ( ) -> tokio:: runtime:: Runtime {
197+ let mut builder = tokio:: runtime:: Builder :: new_multi_thread ( ) ;
198+ builder. worker_threads ( 4 ) . enable_all ( ) ;
199+ #[ cfg( tokio_unstable) ]
200+ builder. enable_eager_driver_handoff ( ) ;
201+ builder. build ( ) . unwrap ( )
187202}
188203
189204criterion_group ! ( benches, payment_benchmark) ;
0 commit comments