Skip to content

Commit c721923

Browse files
committed
Add seeded startup operations benchmark
Add a startup benchmark that restarts a node whose store already contains channel and payment data, so startup cost reflects persisted node state. AI-assisted-by: OpenAI Codex
1 parent bd06c80 commit c721923

1 file changed

Lines changed: 93 additions & 1 deletion

File tree

benches/operations.rs

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use lightning::ln::channelmanager::PaymentId;
2424
use lightning::routing::router::RouteParametersConfig;
2525
use 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)]
3030
struct StoreBenchConfig {
@@ -35,6 +35,7 @@ struct StoreBenchConfig {
3535
fn operations_benchmark(c: &mut Criterion) {
3636
forwarding_benchmark(c);
3737
channel_open_benchmark(c);
38+
startup_benchmark(c);
3839
}
3940

4041
fn 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+
134226
fn should_register_bench(group: &str, name: &str) -> bool {
135227
let target = format!("{}/{}", group, name);
136228
let filters: Vec<String> =

0 commit comments

Comments
 (0)