forked from a16z/helios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.rs
81 lines (73 loc) · 3.14 KB
/
sync.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use criterion::{criterion_group, criterion_main, Criterion};
use ethers::types::Address;
use helios::types::BlockTag;
mod harness;
criterion_main!(sync);
criterion_group! {
name = sync;
config = Criterion::default().sample_size(10);
targets =
bench_full_sync,
bench_full_sync_with_call,
bench_full_sync_checkpoint_fallback,
bench_full_sync_with_call_checkpoint_fallback,
}
/// Benchmark full client sync.
pub fn bench_full_sync(c: &mut Criterion) {
// Externally, let's fetch the latest checkpoint from our fallback service so as not to benchmark the checkpoint fetch.
let checkpoint = harness::await_future(harness::fetch_mainnet_checkpoint()).unwrap();
let checkpoint = hex::encode(checkpoint);
// On client construction, it will sync to the latest checkpoint using our fetched checkpoint.
c.bench_function("full_sync", |b| {
b.to_async(harness::construct_runtime()).iter(|| async {
let _client = std::sync::Arc::new(
harness::construct_mainnet_client_with_checkpoint(&checkpoint)
.await
.unwrap(),
);
})
});
}
/// Benchmark full client sync.
/// Address: 0x00000000219ab540356cbb839cbe05303d7705fa (beacon chain deposit address)
pub fn bench_full_sync_with_call(c: &mut Criterion) {
// Externally, let's fetch the latest checkpoint from our fallback service so as not to benchmark the checkpoint fetch.
let checkpoint = harness::await_future(harness::fetch_mainnet_checkpoint()).unwrap();
let checkpoint = hex::encode(checkpoint);
// On client construction, it will sync to the latest checkpoint using our fetched checkpoint.
c.bench_function("full_sync_call", |b| {
b.to_async(harness::construct_runtime()).iter(|| async {
let client = std::sync::Arc::new(
harness::construct_mainnet_client_with_checkpoint(&checkpoint)
.await
.unwrap(),
);
let addr = "0x00000000219ab540356cbb839cbe05303d7705fa"
.parse::<Address>()
.unwrap();
let block = BlockTag::Latest;
client.get_balance(&addr, block).await.unwrap()
})
});
}
/// Benchmark full client sync with checkpoint fallback.
pub fn bench_full_sync_checkpoint_fallback(c: &mut Criterion) {
c.bench_function("full_sync_fallback", |b| {
let rt = harness::construct_runtime();
b.iter(|| {
let _client = std::sync::Arc::new(harness::construct_mainnet_client(&rt).unwrap());
})
});
}
/// Benchmark full client sync with a call and checkpoint fallback.
/// Address: 0x00000000219ab540356cbb839cbe05303d7705fa (beacon chain deposit address)
pub fn bench_full_sync_with_call_checkpoint_fallback(c: &mut Criterion) {
c.bench_function("full_sync_call", |b| {
let addr = "0x00000000219ab540356cbb839cbe05303d7705fa";
let rt = harness::construct_runtime();
b.iter(|| {
let client = std::sync::Arc::new(harness::construct_mainnet_client(&rt).unwrap());
harness::get_balance(&rt, client, addr).unwrap();
})
});
}