Skip to content

Commit

Permalink
fix: resolve compiler errors for benches (#416)
Browse files Browse the repository at this point in the history
* chore(ethereum, benches): Fixes compiler errors for tests + benches

We fix compiler errors that we see while running tests and benchmarking.

* chore: Reshapes PR to target benches crate fixes

* chore: fixes formatting
  • Loading branch information
mw2000 authored Oct 31, 2024
1 parent 50a315f commit dcda271
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
6 changes: 4 additions & 2 deletions benches/file_db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use alloy::primitives::b256;
use config::Config;
use consensus::database::{Database, FileDB};
use criterion::{criterion_group, criterion_main, Criterion};
use helios_ethereum::{
config::Config,
database::{Database, FileDB},
};
use tempfile::tempdir;

mod harness;
Expand Down
2 changes: 1 addition & 1 deletion benches/get_balance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy::primitives::Address;
use criterion::{criterion_group, criterion_main, Criterion};
use helios::types::BlockTag;
use helios_core::types::BlockTag;
use std::str::FromStr;

mod harness;
Expand Down
2 changes: 1 addition & 1 deletion benches/get_code.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy::primitives::Address;
use criterion::{criterion_group, criterion_main, Criterion};
use helios::types::BlockTag;
use helios_core::types::BlockTag;
use std::str::FromStr;

mod harness;
Expand Down
37 changes: 23 additions & 14 deletions benches/harness.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(dead_code)]
use ::client::Client;
use alloy::primitives::{Address, B256, U256};
use helios::{
client::{self, FileDB},
config::networks,
types::BlockTag,
use helios_core::types::BlockTag;
use helios_ethereum::{
config::{checkpoints, networks},
database::FileDB,
EthereumClient, EthereumClientBuilder,
};
use std::{path::PathBuf, str::FromStr};

Expand All @@ -15,7 +15,10 @@ use std::{path::PathBuf, str::FromStr};
/// This list is NOT guaranteed to be secure, but is provided in good faith.
/// The raw list can be found here: https://github.com/ethpandaops/checkpoint-sync-health-checks/blob/master/_data/endpoints.yaml
pub async fn fetch_mainnet_checkpoint() -> eyre::Result<B256> {
let cf = config::CheckpointFallback::new().build().await.unwrap();
let cf = checkpoints::CheckpointFallback::new()
.build()
.await
.unwrap();
cf.fetch_latest_checkpoint(&networks::Network::MAINNET)
.await
}
Expand All @@ -26,13 +29,16 @@ pub async fn fetch_mainnet_checkpoint() -> eyre::Result<B256> {
/// The client is parameterized with a [FileDB](client::FileDB).
/// It will also use the environment variable `MAINNET_EXECUTION_RPC` to connect to a mainnet node.
/// The client will use `https://www.lightclientdata.org` as the consensus RPC.
pub fn construct_mainnet_client(rt: &tokio::runtime::Runtime) -> eyre::Result<Client<FileDB>> {
pub fn construct_mainnet_client(
rt: &tokio::runtime::Runtime,
) -> eyre::Result<EthereumClient<FileDB>> {
rt.block_on(inner_construct_mainnet_client())
}

pub async fn inner_construct_mainnet_client() -> eyre::Result<Client<FileDB>> {
pub async fn inner_construct_mainnet_client() -> eyre::Result<EthereumClient<FileDB>> {
let benchmark_rpc_url = std::env::var("MAINNET_EXECUTION_RPC")?;
let mut client = client::ClientBuilder::new()

let mut client = EthereumClientBuilder::new()
.network(networks::Network::MAINNET)
.consensus_rpc("https://www.lightclientdata.org")
.execution_rpc(&benchmark_rpc_url)
Expand All @@ -45,9 +51,10 @@ pub async fn inner_construct_mainnet_client() -> eyre::Result<Client<FileDB>> {

pub async fn construct_mainnet_client_with_checkpoint(
checkpoint: B256,
) -> eyre::Result<Client<FileDB>> {
) -> eyre::Result<EthereumClient<FileDB>> {
let benchmark_rpc_url = std::env::var("MAINNET_EXECUTION_RPC")?;
let mut client = client::ClientBuilder::new()

let mut client = EthereumClientBuilder::new()
.network(networks::Network::MAINNET)
.consensus_rpc("https://www.lightclientdata.org")
.execution_rpc(&benchmark_rpc_url)
Expand Down Expand Up @@ -75,10 +82,12 @@ pub fn construct_runtime() -> tokio::runtime::Runtime {
/// The client is parameterized with a [FileDB](client::FileDB).
/// It will also use the environment variable `GOERLI_EXECUTION_RPC` to connect to a mainnet node.
/// The client will use `http://testing.prater.beacon-api.nimbus.team` as the consensus RPC.
pub fn construct_goerli_client(rt: &tokio::runtime::Runtime) -> eyre::Result<Client<FileDB>> {
pub fn construct_goerli_client(
rt: &tokio::runtime::Runtime,
) -> eyre::Result<EthereumClient<FileDB>> {
rt.block_on(async {
let benchmark_rpc_url = std::env::var("GOERLI_EXECUTION_RPC")?;
let mut client = client::ClientBuilder::new()
let mut client = EthereumClientBuilder::new()
.network(networks::Network::GOERLI)
.consensus_rpc("http://testing.prater.beacon-api.nimbus.team")
.execution_rpc(&benchmark_rpc_url)
Expand All @@ -92,7 +101,7 @@ pub fn construct_goerli_client(rt: &tokio::runtime::Runtime) -> eyre::Result<Cli
/// Gets the balance of the given address on mainnet.
pub fn get_balance(
rt: &tokio::runtime::Runtime,
client: Client<FileDB>,
client: EthereumClient<FileDB>,
address: &str,
) -> eyre::Result<U256> {
rt.block_on(async {
Expand Down
2 changes: 1 addition & 1 deletion benches/sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloy::primitives::Address;
use criterion::{criterion_group, criterion_main, Criterion};
use helios::types::BlockTag;
use helios_core::types::BlockTag;

mod harness;

Expand Down

0 comments on commit dcda271

Please sign in to comment.