Skip to content
34 changes: 18 additions & 16 deletions cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,21 +461,23 @@ pub fn get_ws_socket_addr(opts: &Options) -> SocketAddr {
}

#[cfg(feature = "sync-test")]
async fn set_sync_block(store: &Store) {
if let Ok(block_number) = env::var("SYNC_BLOCK_NUM") {
let block_number = block_number
.parse()
.expect("Block number provided by environment is not numeric");
let block_hash = store
.get_canonical_block_hash(block_number)
.await
.expect("Could not get hash for block number provided by env variable")
.expect("Could not get hash for block number provided by env variable");
store
.forkchoice_update(vec![], block_number, block_hash, None, None)
.await
.expect("Could not set sync block");
}
async fn set_sync_block(store: &Store) -> eyre::Result<()> {
let block_number = env::var("SYNC_BLOCK_NUM")?;
let block_number: u64 = block_number.parse()
.map_err(|_| eyre::eyre!("SYNC_BLOCK_NUM environment variable is not a valid number"))?;
Comment thread
emirongrr marked this conversation as resolved.
Outdated

let block_hash = store
.get_canonical_block_hash(block_number)
.await
.map_err(|e| eyre::eyre!("Failed to query block hash from store: {e}"))?
.ok_or_else(|| eyre::eyre!("Block hash not found for block number {block_number}"))?;

store
.forkchoice_update(vec![], block_number, block_hash, None, None)
.await
.map_err(|e| eyre::eyre!("Failed to set sync block: {e}"))?;

Ok(())
}

pub async fn init_l1(
Expand Down Expand Up @@ -514,7 +516,7 @@ pub async fn init_l1(
}

#[cfg(feature = "sync-test")]
set_sync_block(&store).await;
set_sync_block(&store).await?;

let blockchain = init_blockchain(
store.clone(),
Expand Down
Loading