From cb4b39863a4c80110d1528039faaaa4e02f0e4ec Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Sun, 3 Sep 2023 16:45:55 +0200 Subject: [PATCH 1/2] feat: show banner --- README.md | 4 ++-- src/args.rs | 4 ++-- src/indexer.rs | 30 ++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a7d08b4..f84cad0 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ The indexer supports the following command-line arguments for configuring the in - `-f, --from-slot `: It allows you to specify the starting slot for indexing ignoring the default behavior, which is starting from the latest slot stored in the database. -- `-n, --num-threads `: It allows you to specify the number of threads that will be utilized to parallelize the indexing process. If the argument is not provided, the number of cores of the machine will be used. -- `-s, --slots-per-save `: It allows you to specify the number of slots to be processed before saving the latest slot in the database. +- `-n, --num-threads `: It allows you to specify the number of threads that will be utilized to parallelize the indexing process. Default: the number of CPU cores. +- `-s, --slots-per-save `: It allows you to specify the number of slots to be processed before saving the latest slot in the database. Default: 1000 ### Example usage diff --git a/src/args.rs b/src/args.rs index 7b66246..d3c7d12 100644 --- a/src/args.rs +++ b/src/args.rs @@ -13,6 +13,6 @@ pub struct Args { pub num_threads: Option, /// Amount of slots to be processed before saving latest slot in the database - #[arg(short, long)] - pub slots_per_save: Option, + #[arg(short, long, default_value_t = 1000)] + pub slots_per_save: u32, } diff --git a/src/indexer.rs b/src/indexer.rs index b7f43f8..0648af6 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -17,13 +17,39 @@ use crate::{ utils::exp_backoff::get_exp_backoff_config, }; +pub fn print_banner(args: &Args, env: &Environment) { + let num_threads = args.num_threads.unwrap_or_default(); + let sentry_dsn = env.sentry_dsn.clone(); + println!("____ _ _ "); + println!("| __ )| | ___ | |__ ___ ___ __ _ _ __ "); + println!("| _ \\| |/ _ \\| '_ \\/ __|/ __/ _` | '_ \\ "); + println!("| |_) | | (_) | |_) \\__ \\ (_| (_| | | | |"); + println!("|____/|_|\\___/|_.__/|___/\\___\\__,_|_| |_|"); + println!(""); + println!("Blobscan indexer (EIP-4844 blob indexer) - blobscan.com"); + println!("======================================================="); + if num_threads == 0 { + println!("Number of threads: auto"); + } else { + println!("Number of threads: {}", num_threads); + } + println!("Slot chunk size: {}", args.slots_per_save); + println!("Blobscan API endpoint: {}", env.blobscan_api_endpoint); + println!("CL endpoint: {}", env.beacon_node_endpoint); + println!("EL endpoint: {}", env.execution_node_endpoint); + println!("Sentry DSN: {}", sentry_dsn.unwrap_or_default()); + println!(""); +} + pub async fn run(env: Environment) -> Result<()> { let args = Args::parse(); - let max_slot_per_save = args.slots_per_save.unwrap_or(1000); let slots_processor_config = args .num_threads .map(|threads_length| SlotsProcessorConfig { threads_length }); + + print_banner(&args, &env); + let context = match Context::try_new(ContextConfig::from(env)) { Ok(c) => c, Err(error) => { @@ -100,7 +126,7 @@ pub async fn run(env: Environment) -> Result<()> { ); while unprocessed_slots > 0 { - let slots_chunk = min(unprocessed_slots, max_slot_per_save); + let slots_chunk = min(unprocessed_slots, args.slots_per_save); let chunk_initial_slot = current_slot; let chunk_final_slot = current_slot + slots_chunk; From a47d60891e6b66fc4f6046261b08d57c33ef58c3 Mon Sep 17 00:00:00 2001 From: Pablo Castellano Date: Mon, 4 Sep 2023 19:13:58 +0200 Subject: [PATCH 2/2] style: fix lint --- src/indexer.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/indexer.rs b/src/indexer.rs index 0648af6..fa641d8 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -24,8 +24,7 @@ pub fn print_banner(args: &Args, env: &Environment) { println!("| __ )| | ___ | |__ ___ ___ __ _ _ __ "); println!("| _ \\| |/ _ \\| '_ \\/ __|/ __/ _` | '_ \\ "); println!("| |_) | | (_) | |_) \\__ \\ (_| (_| | | | |"); - println!("|____/|_|\\___/|_.__/|___/\\___\\__,_|_| |_|"); - println!(""); + println!("|____/|_|\\___/|_.__/|___/\\___\\__,_|_| |_|\n"); println!("Blobscan indexer (EIP-4844 blob indexer) - blobscan.com"); println!("======================================================="); if num_threads == 0 { @@ -38,7 +37,7 @@ pub fn print_banner(args: &Args, env: &Environment) { println!("CL endpoint: {}", env.beacon_node_endpoint); println!("EL endpoint: {}", env.execution_node_endpoint); println!("Sentry DSN: {}", sentry_dsn.unwrap_or_default()); - println!(""); + println!("\n"); } pub async fn run(env: Environment) -> Result<()> {