Skip to content

Commit

Permalink
add zeth support in rpc type
Browse files Browse the repository at this point in the history
  • Loading branch information
temaniarpit27 committed Nov 18, 2024
1 parent b63c8e2 commit 7a2d98b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions zero/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::prover::BlockProverInput;
pub mod jerigon;
pub mod native;
pub mod retry;
pub mod zeth;

use crate::provider::CachedProvider;

Expand All @@ -37,6 +38,7 @@ const PREVIOUS_HASHES_COUNT: usize = 256;
pub enum RpcType {
Jerigon,
Native,
Zeth,
}

/// Obtain the prover input for one block
Expand All @@ -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
}
}
}

Expand Down
45 changes: 45 additions & 0 deletions zero/src/rpc/zeth.rs
Original file line number Diff line number Diff line change
@@ -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<ProviderT, TransportT>(
cached_provider: std::sync::Arc<CachedProvider<ProviderT, TransportT>>,
target_block_id: BlockId,
checkpoint_block_number: u64,
) -> anyhow::Result<BlockProverInput>
where
ProviderT: Provider<TransportT>,
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,
})
}

0 comments on commit 7a2d98b

Please sign in to comment.