@@ -24,7 +24,7 @@ use lightning::ln::channelmanager::PaymentId;
2424use lightning:: routing:: router:: RouteParametersConfig ;
2525use lightning_invoice:: { Bolt11InvoiceDescription , Description } ;
2626
27- use crate :: common:: { open_channel_push_amt, TestChainSource , TestStoreType } ;
27+ use crate :: common:: { open_channel_push_amt, TestChainSource , TestConfig , TestStoreType } ;
2828
2929#[ derive( Clone , Copy ) ]
3030struct StoreBenchConfig {
@@ -35,6 +35,7 @@ struct StoreBenchConfig {
3535fn operations_benchmark ( c : & mut Criterion ) {
3636 forwarding_benchmark ( c) ;
3737 channel_open_benchmark ( c) ;
38+ startup_benchmark ( c) ;
3839}
3940
4041fn forwarding_benchmark ( c : & mut Criterion ) {
@@ -131,6 +132,97 @@ fn channel_open_benchmark(c: &mut Criterion) {
131132 }
132133}
133134
135+ fn startup_benchmark ( c : & mut Criterion ) {
136+ let ( bitcoind, electrsd) = setup_bitcoind_and_electrsd ( ) ;
137+ let chain_source = random_chain_source ( & bitcoind, & electrsd) ;
138+ let runtime =
139+ tokio:: runtime:: Builder :: new_multi_thread ( ) . worker_threads ( 4 ) . enable_all ( ) . build ( ) . unwrap ( ) ;
140+
141+ let mut group = c. benchmark_group ( "startup" ) ;
142+ group. sample_size ( 10 ) ;
143+
144+ for store_config in store_bench_configs ( ) {
145+ if !should_register_bench ( "startup" , store_config. name ) {
146+ continue ;
147+ }
148+ let config = setup_startup_seed_node (
149+ & chain_source,
150+ & bitcoind,
151+ & electrsd,
152+ store_config. store_type ,
153+ & runtime,
154+ ) ;
155+
156+ group. bench_function ( store_config. name , |b| {
157+ b. iter_custom ( |iter| {
158+ let mut total = Duration :: ZERO ;
159+ for _ in 0 ..iter {
160+ let start = Instant :: now ( ) ;
161+ let node = setup_node ( & chain_source, config. clone ( ) ) ;
162+ total += start. elapsed ( ) ;
163+ node. stop ( ) . unwrap ( ) ;
164+ }
165+ total
166+ } ) ;
167+ } ) ;
168+ }
169+ }
170+
171+ fn setup_startup_seed_node (
172+ chain_source : & TestChainSource , bitcoind : & BitcoinD , electrsd : & electrsd:: ElectrsD ,
173+ store_type : TestStoreType , runtime : & tokio:: runtime:: Runtime ,
174+ ) -> TestConfig {
175+ let mut config_a = random_config ( true ) ;
176+ config_a. store_type = store_type;
177+ let node_a = Arc :: new ( setup_node ( chain_source, config_a. clone ( ) ) ) ;
178+
179+ let mut config_b = random_config ( true ) ;
180+ config_b. store_type = store_type;
181+ let node_b = Arc :: new ( setup_node ( chain_source, config_b) ) ;
182+
183+ runtime. block_on ( async {
184+ let address_a = node_a. onchain_payment ( ) . new_address ( ) . unwrap ( ) ;
185+ premine_and_distribute_funds (
186+ & bitcoind. client ,
187+ & electrsd. client ,
188+ vec ! [ address_a] ,
189+ Amount :: from_sat ( 5_000_000 ) ,
190+ )
191+ . await ;
192+ node_a. sync_wallets ( ) . unwrap ( ) ;
193+ node_b. sync_wallets ( ) . unwrap ( ) ;
194+
195+ open_channel_push_amt ( & node_a, & node_b, 1_000_000 , Some ( 500_000_000 ) , false , electrsd)
196+ . await ;
197+ generate_blocks_and_wait ( & bitcoind. client , & electrsd. client , 6 ) . await ;
198+ node_a. sync_wallets ( ) . unwrap ( ) ;
199+ node_b. sync_wallets ( ) . unwrap ( ) ;
200+
201+ expect_channel_ready_event ! ( node_a, node_b. node_id( ) ) ;
202+ expect_channel_ready_event ! ( node_b, node_a. node_id( ) ) ;
203+
204+ for description in [ "startup seed 1" , "startup seed 2" ] {
205+ let invoice_description = Bolt11InvoiceDescription :: Direct (
206+ Description :: new ( description. to_string ( ) ) . unwrap ( ) ,
207+ ) ;
208+ let invoice = node_b
209+ . bolt11_payment ( )
210+ . receive ( 1_000_000 , & invoice_description. into ( ) , 9217 )
211+ . unwrap ( ) ;
212+ let payment_id = node_a. bolt11_payment ( ) . send ( & invoice, None ) . unwrap ( ) ;
213+ wait_for_payment_success ( & node_a, payment_id) . await ;
214+ }
215+
216+ drain_events ( & node_a) ;
217+ drain_events ( & node_b) ;
218+ } ) ;
219+
220+ node_a. stop ( ) . unwrap ( ) ;
221+ node_b. stop ( ) . unwrap ( ) ;
222+
223+ config_a
224+ }
225+
134226fn should_register_bench ( group : & str , name : & str ) -> bool {
135227 let target = format ! ( "{}/{}" , group, name) ;
136228 let filters: Vec < String > =
0 commit comments