Skip to content

Commit

Permalink
add zeth rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
frisitano committed Aug 17, 2024
1 parent 0e55293 commit c6c0171
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zero_bin/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub mod jerigon;
pub mod native;
pub mod provider;
pub mod retry;
pub mod zeth;

use crate::provider::CachedProvider;

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

/// Obtain the prover input for a given block interval
Expand Down Expand Up @@ -61,6 +63,10 @@ where
native::block_prover_input(cached_provider, block_id, checkpoint_state_trie_root)
.await?
}
RpcType::Zeth => {
zeth::block_prover_input(cached_provider, block_id, checkpoint_state_trie_root)
.await?
}
};

block_proofs.push(block_prover_input);
Expand Down
36 changes: 36 additions & 0 deletions zero_bin/rpc/src/zeth.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use alloy::{
primitives::B256, providers::Provider, rpc::types::eth::BlockId, transports::Transport,
};
use prover::BlockProverInput;
use trace_decoder::BlockTrace;

use super::{fetch_other_block_data, CachedProvider};

pub async fn block_prover_input<ProviderT, TransportT>(
provider: &CachedProvider<ProviderT, TransportT>,
target_block_id: BlockId,
checkpoint_state_trie_root: B256,
) -> 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 = provider
.as_provider()
.raw_request::<_, BlockTrace>("zero_getBlockTraceByNumber".into(), vec![block_number])
.await?;

let other_data =
fetch_other_block_data(provider, target_block_id, checkpoint_state_trie_root).await?;

// Assemble
Ok(BlockProverInput {
block_trace,
other_data,
})
}

0 comments on commit c6c0171

Please sign in to comment.