This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
221 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,115 @@ | ||
use alloy::{ | ||
providers::Provider, | ||
rpc::types::eth::{BlockId, BlockTransactionsKind, Withdrawal}, | ||
transports::Transport, | ||
}; | ||
use anyhow::Context as _; | ||
use evm_arithmetization::proof::{BlockHashes, BlockMetadata}; | ||
use futures::{StreamExt as _, TryStreamExt as _}; | ||
use trace_decoder::types::{BlockLevelData, OtherBlockData}; | ||
|
||
mod compat; | ||
pub mod jerigon; | ||
mod metadata; | ||
pub mod native; | ||
pub mod retry; | ||
|
||
use compat::Compat; | ||
|
||
/// Fetches other block data | ||
async fn fetch_other_block_data<ProviderT, TransportT>( | ||
provider: ProviderT, | ||
target_block_id: BlockId, | ||
checkpoint_block_id: BlockId, | ||
) -> anyhow::Result<OtherBlockData> | ||
where | ||
ProviderT: Provider<TransportT>, | ||
TransportT: Transport + Clone, | ||
{ | ||
let target_block = provider | ||
.get_block(target_block_id, BlockTransactionsKind::Hashes) | ||
.await? | ||
.context("target block does not exist")?; | ||
let target_block_number = target_block | ||
.header | ||
.number | ||
.context("target block is missing field `number`")?; | ||
let chain_id = provider.get_chain_id().await?; | ||
let checkpoint_state_trie_root = provider | ||
.get_block(checkpoint_block_id, BlockTransactionsKind::Hashes) | ||
.await? | ||
.context("checkpoint block does not exist")? | ||
.header | ||
.state_root; | ||
|
||
let mut prev_hashes = [alloy::primitives::B256::ZERO; 256]; | ||
let concurrency = prev_hashes.len(); | ||
futures::stream::iter( | ||
prev_hashes | ||
.iter_mut() | ||
.rev() // fill RTL | ||
.zip(std::iter::successors(Some(target_block_number), |it| { | ||
it.checked_sub(1) | ||
})) | ||
.map(|(dst, n)| { | ||
let provider = &provider; | ||
async move { | ||
let block = provider | ||
.get_block(n.into(), BlockTransactionsKind::Hashes) | ||
.await | ||
.context("couldn't get block")? | ||
.context("no such block")?; | ||
*dst = block.header.parent_hash; | ||
anyhow::Ok(()) | ||
} | ||
}), | ||
) | ||
.buffered(concurrency) | ||
.try_collect::<()>() | ||
.await | ||
.context("couldn't fill previous hashes")?; | ||
|
||
let other_data = OtherBlockData { | ||
b_data: BlockLevelData { | ||
b_meta: BlockMetadata { | ||
block_beneficiary: target_block.header.miner.compat(), | ||
block_timestamp: target_block.header.timestamp.into(), | ||
block_number: target_block_number.into(), | ||
block_difficulty: target_block.header.difficulty.into(), | ||
block_random: target_block | ||
.header | ||
.mix_hash | ||
.context("target block is missing field `mix_hash`")? | ||
.compat(), | ||
block_gaslimit: target_block.header.gas_limit.into(), | ||
block_chain_id: chain_id.into(), | ||
block_base_fee: target_block | ||
.header | ||
.base_fee_per_gas | ||
.context("target block is missing field `base_fee_per_gas`")? | ||
.into(), | ||
block_gas_used: target_block.header.gas_used.into(), | ||
block_bloom: target_block.header.logs_bloom.compat(), | ||
}, | ||
b_hashes: BlockHashes { | ||
prev_hashes: prev_hashes.map(|it| it.compat()).into(), | ||
cur_hash: target_block | ||
.header | ||
.hash | ||
.context("target block is missing field `hash`")? | ||
.compat(), | ||
}, | ||
withdrawals: target_block | ||
.withdrawals | ||
.into_iter() | ||
.flatten() | ||
.map( | ||
|Withdrawal { | ||
address, amount, .. | ||
}| { (address.compat(), amount.into()) }, | ||
) | ||
.collect(), | ||
}, | ||
checkpoint_state_trie_root: checkpoint_state_trie_root.compat(), | ||
}; | ||
Ok(other_data) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.