diff --git a/zero/src/rpc/mod.rs b/zero/src/rpc/mod.rs index b972bc501..0c3af3f1d 100644 --- a/zero/src/rpc/mod.rs +++ b/zero/src/rpc/mod.rs @@ -25,6 +25,7 @@ use crate::prover::BlockProverInput; pub mod jerigon; pub mod native; pub mod retry; +pub mod zeth; use crate::provider::CachedProvider; @@ -37,6 +38,7 @@ const PREVIOUS_HASHES_COUNT: usize = 256; pub enum RpcType { Jerigon, Native, + Zeth, } /// Obtain the prover input for one block @@ -56,6 +58,9 @@ where RpcType::Native => { native::block_prover_input(cached_provider, block_id, checkpoint_block_number).await } + RpcType::Zeth => { + zeth::block_prover_input(cached_provider, block_id, checkpoint_block_number).await + } } } diff --git a/zero/src/rpc/zeth.rs b/zero/src/rpc/zeth.rs new file mode 100644 index 000000000..5a8e10f42 --- /dev/null +++ b/zero/src/rpc/zeth.rs @@ -0,0 +1,45 @@ +use alloy::{providers::Provider, rpc::types::eth::BlockId, transports::Transport}; +use serde::Deserialize; +use trace_decoder::{BlockTrace, TxnInfo}; + +use super::fetch_other_block_data; +use crate::prover::BlockProverInput; +use crate::provider::CachedProvider; + +/// Transaction traces retrieved from Erigon zeroTracer. +#[derive(Debug, Deserialize)] +pub struct ZeroTxResult { + #[serde(rename(deserialize = "txHash"))] + pub tx_hash: alloy::primitives::TxHash, + pub result: TxnInfo, +} + +pub async fn block_prover_input( + cached_provider: std::sync::Arc>, + target_block_id: BlockId, + checkpoint_block_number: u64, +) -> anyhow::Result +where + ProviderT: Provider, + TransportT: Transport + Clone, +{ + let block_number = match target_block_id { + BlockId::Number(block_number) => block_number, + _ => return Err(anyhow::anyhow!("block number expected")), + }; + + let block_trace = cached_provider + .get_provider() + .await? + .raw_request::<_, BlockTrace>("zero_getBlockTraceByNumber".into(), vec![block_number]) + .await?; + + let other_data = + fetch_other_block_data(cached_provider, target_block_id, checkpoint_block_number).await?; + println!("block_prover_input: {:?}", block_trace); + // Assemble + Ok(BlockProverInput { + block_trace, + other_data, + }) +}