mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Alloy migration (#4737)
Co-authored-by: Alessandro Mazza <121622391+alessandromazza98@users.noreply.github.com> Co-authored-by: Supernovahs.eth <91280922+supernovahs@users.noreply.github.com> Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
@ -16,9 +16,10 @@ reth-primitives.workspace = true
|
||||
reth-db = { workspace = true, features = ["mdbx", "test-utils"] }
|
||||
reth-provider.workspace = true
|
||||
reth-stages = { path = "../../crates/stages" }
|
||||
reth-rlp.workspace = true
|
||||
reth-interfaces.workspace = true
|
||||
reth-revm = { path = "../../crates/revm" }
|
||||
|
||||
alloy-rlp.workspace = true
|
||||
tokio = "1.28.1"
|
||||
walkdir = "2.3.3"
|
||||
serde = "1.0.163"
|
||||
|
||||
@ -4,10 +4,10 @@ use crate::{
|
||||
models::{BlockchainTest, ForkSpec, RootOrState},
|
||||
Case, Error, Suite,
|
||||
};
|
||||
use alloy_rlp::Decodable;
|
||||
use reth_db::test_utils::create_test_rw_db;
|
||||
use reth_primitives::{BlockBody, SealedBlock};
|
||||
use reth_provider::{BlockWriter, ProviderFactory};
|
||||
use reth_rlp::Decodable;
|
||||
use reth_stages::{stages::ExecutionStage, ExecInput, Stage};
|
||||
use std::{collections::BTreeMap, fs, path::Path, sync::Arc};
|
||||
|
||||
|
||||
@ -7,9 +7,9 @@ use reth_db::{
|
||||
transaction::{DbTx, DbTxMut},
|
||||
};
|
||||
use reth_primitives::{
|
||||
keccak256, Account as RethAccount, Address, BigEndianHash, Bloom, Bytecode, Bytes, ChainSpec,
|
||||
ChainSpecBuilder, Header as RethHeader, JsonU256, SealedHeader, StorageEntry, Withdrawal, H160,
|
||||
H256, H64, U256,
|
||||
keccak256, Account as RethAccount, Address, Bloom, Bytecode, Bytes, ChainSpec,
|
||||
ChainSpecBuilder, Header as RethHeader, JsonU256, SealedHeader, StorageEntry, Withdrawal, B256,
|
||||
B64, U256,
|
||||
};
|
||||
use serde::{self, Deserialize};
|
||||
use std::{collections::BTreeMap, ops::Deref};
|
||||
@ -30,7 +30,7 @@ pub struct BlockchainTest {
|
||||
/// The test pre-state.
|
||||
pub pre: State,
|
||||
/// Hash of the best block.
|
||||
pub lastblockhash: H256,
|
||||
pub lastblockhash: B256,
|
||||
/// Network spec.
|
||||
pub network: ForkSpec,
|
||||
#[serde(default)]
|
||||
@ -55,35 +55,35 @@ pub struct Header {
|
||||
/// Gas used.
|
||||
pub gas_used: JsonU256,
|
||||
/// Block Hash.
|
||||
pub hash: H256,
|
||||
pub hash: B256,
|
||||
/// Mix hash.
|
||||
pub mix_hash: H256,
|
||||
pub mix_hash: B256,
|
||||
/// Seal nonce.
|
||||
pub nonce: H64,
|
||||
pub nonce: B64,
|
||||
/// Block number.
|
||||
pub number: JsonU256,
|
||||
/// Parent hash.
|
||||
pub parent_hash: H256,
|
||||
pub parent_hash: B256,
|
||||
/// Receipt trie.
|
||||
pub receipt_trie: H256,
|
||||
pub receipt_trie: B256,
|
||||
/// State root.
|
||||
pub state_root: H256,
|
||||
pub state_root: B256,
|
||||
/// Timestamp.
|
||||
pub timestamp: JsonU256,
|
||||
/// Transactions trie.
|
||||
pub transactions_trie: H256,
|
||||
pub transactions_trie: B256,
|
||||
/// Uncle hash.
|
||||
pub uncle_hash: H256,
|
||||
pub uncle_hash: B256,
|
||||
/// Base fee per gas.
|
||||
pub base_fee_per_gas: Option<JsonU256>,
|
||||
/// Withdrawals root.
|
||||
pub withdrawals_root: Option<H256>,
|
||||
pub withdrawals_root: Option<B256>,
|
||||
/// Blob gas used.
|
||||
pub blob_gas_used: Option<JsonU256>,
|
||||
/// Excess blob gas.
|
||||
pub excess_blob_gas: Option<JsonU256>,
|
||||
/// Parent beacon block root.
|
||||
pub parent_beacon_block_root: Option<H256>,
|
||||
pub parent_beacon_block_root: Option<B256>,
|
||||
}
|
||||
|
||||
impl From<Header> for SealedHeader {
|
||||
@ -96,7 +96,7 @@ impl From<Header> for SealedHeader {
|
||||
gas_limit: value.gas_limit.0.to::<u64>(),
|
||||
gas_used: value.gas_used.0.to::<u64>(),
|
||||
mix_hash: value.mix_hash,
|
||||
nonce: value.nonce.into_uint().as_u64(),
|
||||
nonce: u64::from_be_bytes(value.nonce.0),
|
||||
number: value.number.0.to::<u64>(),
|
||||
timestamp: value.timestamp.0.to::<u64>(),
|
||||
transactions_root: value.transactions_trie,
|
||||
@ -164,12 +164,12 @@ impl State {
|
||||
},
|
||||
)?;
|
||||
if let Some(code_hash) = code_hash {
|
||||
tx.put::<tables::Bytecodes>(code_hash, Bytecode::new_raw(account.code.0.clone()))?;
|
||||
tx.put::<tables::Bytecodes>(code_hash, Bytecode::new_raw(account.code.clone()))?;
|
||||
}
|
||||
account.storage.iter().try_for_each(|(k, v)| {
|
||||
tx.put::<tables::PlainStorageState>(
|
||||
address,
|
||||
StorageEntry { key: H256::from_slice(&k.0.to_be_bytes::<32>()), value: v.0 },
|
||||
StorageEntry { key: B256::from_slice(&k.0.to_be_bytes::<32>()), value: v.0 },
|
||||
)
|
||||
})?;
|
||||
}
|
||||
@ -191,7 +191,7 @@ impl Deref for State {
|
||||
#[serde(untagged)]
|
||||
pub enum RootOrState {
|
||||
/// If state is too big, only state root is present
|
||||
Root(H256),
|
||||
Root(B256),
|
||||
/// State
|
||||
State(BTreeMap<Address, Account>),
|
||||
}
|
||||
@ -238,7 +238,7 @@ impl Account {
|
||||
let mut storage_cursor = tx.cursor_dup_read::<tables::PlainStorageState>()?;
|
||||
for (slot, value) in self.storage.iter() {
|
||||
if let Some(entry) =
|
||||
storage_cursor.seek_by_key_subkey(address, H256(slot.0.to_be_bytes()))?
|
||||
storage_cursor.seek_by_key_subkey(address, B256::new(slot.0.to_be_bytes()))?
|
||||
{
|
||||
if U256::from_be_bytes(entry.key.0) == slot.0 {
|
||||
assert_equal(
|
||||
@ -396,7 +396,7 @@ pub struct Transaction {
|
||||
/// Max priority fee per gas
|
||||
pub max_priority_fee_per_gas: Option<JsonU256>,
|
||||
/// Transaction hash.
|
||||
pub hash: Option<H256>,
|
||||
pub hash: Option<B256>,
|
||||
}
|
||||
|
||||
/// Access list item
|
||||
@ -404,9 +404,9 @@ pub struct Transaction {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AccessListItem {
|
||||
/// Account address
|
||||
pub address: H160,
|
||||
pub address: Address,
|
||||
/// Storage key.
|
||||
pub storage_keys: Vec<H256>,
|
||||
pub storage_keys: Vec<B256>,
|
||||
}
|
||||
|
||||
/// Access list.
|
||||
|
||||
@ -46,7 +46,7 @@ pub enum Error {
|
||||
RethError(#[from] RethError),
|
||||
/// An error occurred while decoding RLP.
|
||||
#[error("An error occurred deserializing RLP")]
|
||||
RlpDecodeError(#[from] reth_rlp::DecodeError),
|
||||
RlpDecodeError(#[from] alloy_rlp::Error),
|
||||
}
|
||||
|
||||
/// The result of running a test.
|
||||
|
||||
Reference in New Issue
Block a user