Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zeth rpc #511

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
})
}
Loading