Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: improve env vars #62

Merged
merged 2 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub struct Environment {
#[serde(default = "default_execution_node_endpoint")]
pub execution_node_endpoint: String,
pub secret_key: String,
pub lowest_indexed_slot: Option<u32>,
#[serde(default = "default_dencun_fork_slot")]
pub dencun_fork_slot: u32,
pub sentry_dsn: Option<String>,
}

Expand All @@ -26,6 +27,10 @@ fn default_execution_node_endpoint() -> String {
"http://localhost:8545".to_string()
}

fn default_dencun_fork_slot() -> u32 {
0
}

impl Environment {
pub fn from_env() -> Result<Self, envy::Error> {
match envy::from_env::<Environment>() {
Expand Down
13 changes: 7 additions & 6 deletions src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub mod types;

pub struct Indexer {
context: Context,
lowest_indexed_slot: u32,
dencun_fork_slot: u32,
num_threads: u32,
slots_checkpoint: Option<u32>,
}
Expand All @@ -42,19 +42,20 @@ impl Indexer {
return Err(error.into());
}
};
let slots_checkpoint = args.slots_per_save;
let num_threads = match args.num_threads {
Some(num_threads) => num_threads,
None => thread::available_parallelism()
.map_err(|err| anyhow!("Failed to get number of available threads: {:?}", err))?
.get() as u32,
};
let lowest_indexed_slot = env.lowest_indexed_slot.unwrap_or(0);
let dencun_fork_slot = env.dencun_fork_slot;

Ok(Self {
context,
num_threads,
slots_checkpoint: args.slots_per_save,
lowest_indexed_slot,
slots_checkpoint,
dencun_fork_slot,
})
}

Expand Down Expand Up @@ -119,11 +120,11 @@ impl Indexer {
start_block_id: BlockId,
) -> JoinHandle<IndexerTaskResult> {
let mut synchronizer = self._create_synchronizer();
let lowest_indexed_slot = self.lowest_indexed_slot;
let target_lowest_slot = self.dencun_fork_slot;

tokio::spawn(async move {
let result = synchronizer
.run(&start_block_id, &BlockId::Slot(lowest_indexed_slot))
.run(&start_block_id, &BlockId::Slot(target_lowest_slot))
.await;

if let Err(error) = result {
Expand Down
13 changes: 10 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ pub fn print_banner(args: &Args, env: &Environment) {
println!("Blobscan indexer (EIP-4844 blob indexer) - blobscan.com");
println!("=======================================================");

if let Some(from_slot) = args.from_slot.clone() {
println!("Start slot: {}", from_slot);
} else {
println!("Start slot: 0");
}

if let Some(num_threads) = args.num_threads {
println!("Number of threads: {}", num_threads);
} else {
println!("Number of threads: auto");
println!("Number of threads: 1");
}

if let Some(slots_per_save) = args.slots_per_save {
println!("Slot chunk size: {}", slots_per_save);
println!("Slots checkpoint size: {}", slots_per_save);
} else {
println!("Slot chunk size: auto");
println!("Slots checkpoint size: 1000");
}

println!("Dencun fork slot: {}", env.dencun_fork_slot);
println!("Blobscan API endpoint: {}", env.blobscan_api_endpoint);
println!(
"CL endpoint: {:?}",
Expand Down
Loading