Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Aug 23, 2024
1 parent 260e2e4 commit 52f00d6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions zero_bin/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ where
ProviderT: Provider<TransportT>,
TransportT: Transport + Clone,
{
// Here, we perform the `eth_call` to the smart contract to get the previous
// block hashes (read-only execution). We set the target address to be
// empty, hence the node executes this call as a contract creation function.
// We use that execution not to produce a new contract bytecode - instead, we
// return hashes. To look at the code using `cast disassemble
// 0x60005B60010180430340816020025280610101116300000002576120205FF3`
let bytes = cached_provider
.as_provider()
.raw_request::<_, Bytes>(
Expand All @@ -156,7 +162,7 @@ where
.collect::<Result<Vec<_>, _>>()?;

PreviousBlockHashes::try_from(prev_hashes)
.map_err(|_| anyhow!("Invalid number of block hashes"))
.map_err(|_| anyhow!("invalid conversion to 256 previous block hashes"))
}

async fn fetch_previous_block_hashes<ProviderT, TransportT>(
Expand All @@ -174,17 +180,15 @@ where
if !prev_block_hahes.into_iter().all(|it| it.0 == [0u8; 32]) {
// Previous hashes valid, return result
return Ok(prev_block_hahes);
} else {
warn!("all retrieved block hashes empty, falling back to `eth_getBlockByNumber` for block {}", target_block_number);
}
}
Err(e) => {
warn!("unable to retrieve previous block hashes with `eth_call`: {e}");
}
}

warn!(
"retrieving previous block hashes with `eth_getBlockByNumber` for block {}",
target_block_number
);
fetch_previous_block_hashes_from_block(cached_provider, target_block_number).await
}

Expand Down

0 comments on commit 52f00d6

Please sign in to comment.