Skip to content

Commit

Permalink
feat: Alloy type migration (#4674)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Sep 23, 2023
1 parent 675c6bf commit ccae4eb
Show file tree
Hide file tree
Showing 187 changed files with 1,494 additions and 2,324 deletions.
309 changes: 142 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ reth-network-api = { path = "./crates/net/network-api" }
reth-rpc-types-compat = { path = "./crates/rpc/rpc-types-compat" }

# revm
revm = { git = "https://github.com/bluealloy/revm", rev = "516f62cc" }
revm-primitives = { git = "https://github.com/bluealloy/revm", rev = "516f62cc" }
revm = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }
revm-primitives = { git = "https://github.com/Evalir/revm/", branch = "reintroduce-alloy-rebased" }

## eth
alloy-primitives = "0.3"
ethers-core = { version = "2.0", default-features = false }
ethers-providers = { version = "2.0", default-features = false }
ethers-signers = { version = "2.0", default-features = false }
Expand All @@ -129,7 +130,7 @@ strum = "0.25"
rayon = "1.7"
itertools = "0.11"
parking_lot = "0.12"
metrics = "0.21.1" # Needed for `metrics-macro` to resolve the crate using `::metrics` notation
metrics = "0.21.1" # Needed for `metrics-macro` to resolve the crate using `::metrics` notation
hex-literal = "0.4"

### proc-macros
Expand Down Expand Up @@ -160,7 +161,7 @@ secp256k1 = { version = "0.27.0", default-features = false, features = [
] }
enr = { version = "0.9", default-features = false, features = ["k256"] }
# for eip-4844
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "f5f6f863d475847876a2bd5ee252058d37c3a15d" }
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "fbef59a3f9e8fa998bdb5069d212daf83d586aa5" }

## config
confy = "0.5"
Expand All @@ -172,4 +173,8 @@ assert_matches = "1.5.0"

proptest = "1.0"
proptest-derive = "0.4"
serial_test = "2"
serial_test = "2"

# TODO
[patch.crates-io]
alloy-primitives = { git = "https://github.com/alloy-rs/core" }
1 change: 0 additions & 1 deletion bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ eyre = "0.6.8"
clap = { version = "4", features = ["derive"] }
tempfile = { version = "3.3.0" }
backon = "0.4"
hex = "0.4"
thiserror.workspace = true
pretty_assertions = "1.3.0"
humantime = "2.1.0"
Expand Down
3 changes: 1 addition & 2 deletions bin/reth/src/args/secret_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use hex::encode as hex_encode;
use reth_network::config::rng_secret_key;
use reth_primitives::{fs, fs::FsPathError};
use reth_primitives::{fs, fs::FsPathError, hex::encode as hex_encode};
use secp256k1::{Error as SecretKeyBaseError, SecretKey};
use std::{
io,
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/args/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Clap parser utilities

use reth_primitives::{
fs, AllGenesisFormats, BlockHashOrNumber, ChainSpec, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA,
fs, AllGenesisFormats, BlockHashOrNumber, ChainSpec, DEV, GOERLI, H256, HOLESKY, MAINNET,
SEPOLIA,
};
use reth_revm::primitives::B256 as H256;
use std::{
net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs},
path::PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/chain/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl ImportCommand {
.build(file_client.clone(), consensus.clone(), db.clone())
.into_task();

let (tip_tx, tip_rx) = watch::channel(H256::zero());
let (tip_tx, tip_rx) = watch::channel(H256::ZERO);
let factory = reth_revm::Factory::new(self.chain.clone());

let max_block = file_client.max_block().unwrap_or(0);
Expand Down
6 changes: 3 additions & 3 deletions bin/reth/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Config traits for various node components.

use reth_revm::primitives::bytes::BytesMut;
use reth_primitives::{Bytes, BytesMut};
use reth_rlp::Encodable;
use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret};
use reth_rpc_builder::{
Expand Down Expand Up @@ -72,10 +72,10 @@ pub trait PayloadBuilderConfig {
fn extradata(&self) -> Cow<'_, str>;

/// Returns the rlp-encoded extradata bytes.
fn extradata_rlp_bytes(&self) -> reth_primitives::bytes::Bytes {
fn extradata_rlp_bytes(&self) -> Bytes {
let mut extradata = BytesMut::new();
self.extradata().as_bytes().encode(&mut extradata);
extradata.freeze()
extradata.freeze().into()
}

/// The interval at which the job should build a new payload after the last.
Expand Down
6 changes: 3 additions & 3 deletions bin/reth/src/db/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod tests {
models::{storage_sharded_key::StorageShardedKey, ShardedKey},
AccountHistory, HashedAccount, Headers, StorageHistory, SyncStage,
};
use reth_primitives::{H160, H256};
use reth_primitives::{Address, H256};
use std::str::FromStr;

/// A helper type to parse Args more easily
Expand Down Expand Up @@ -123,7 +123,7 @@ mod tests {
assert_eq!(
args.table_key::<StorageHistory>().unwrap(),
StorageShardedKey::new(
H160::from_str("0x01957911244e546ce519fbac6f798958fafadb41").unwrap(),
Address::from_str("0x01957911244e546ce519fbac6f798958fafadb41").unwrap(),
H256::from_str(
"0x0000000000000000000000000000000000000000000000000000000000000003"
)
Expand All @@ -139,7 +139,7 @@ mod tests {
assert_eq!(
args.table_key::<AccountHistory>().unwrap(),
ShardedKey::new(
H160::from_str("0x4448e1273fd5a8bfdb9ed111e96889c960eee145").unwrap(),
Address::from_str("0x4448e1273fd5a8bfdb9ed111e96889c960eee145").unwrap(),
18446744073709551615
)
);
Expand Down
1 change: 1 addition & 0 deletions bin/reth/src/db/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::utils::{DbTool, ListFilter};
use clap::Parser;
use eyre::WrapErr;
use reth_db::{database::Database, table::Table, DatabaseEnvRO, TableType, TableViewer, Tables};
use reth_primitives::hex;
use std::cell::RefCell;
use tracing::error;

Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/debug_cmd/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Command {

let stage_conf = &config.stages;

let (tip_tx, tip_rx) = watch::channel(H256::zero());
let (tip_tx, tip_rx) = watch::channel(H256::ZERO);
let factory = reth_revm::Factory::new(self.chain.clone());

let header_mode = HeaderSyncMode::Tip(tip_rx);
Expand Down
8 changes: 4 additions & 4 deletions bin/reth/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn insert_genesis_state<DB: Database>(

for (address, account) in &genesis.alloc {
let bytecode_hash = if let Some(code) = &account.code {
let bytecode = Bytecode::new_raw(code.0.clone());
let bytecode = Bytecode::new_raw(code.clone());
let hash = bytecode.hash_slow();
contracts.insert(hash, bytecode);
Some(hash)
Expand Down Expand Up @@ -287,9 +287,9 @@ mod tests {

#[test]
fn init_genesis_history() {
let address_with_balance = Address::from_low_u64_be(1);
let address_with_storage = Address::from_low_u64_be(2);
let storage_key = H256::from_low_u64_be(1);
let address_with_balance = Address::with_last_byte(1);
let address_with_storage = Address::with_last_byte(2);
let storage_key = H256::with_last_byte(1);
let chain_spec = Arc::new(ChainSpec {
chain: Chain::Id(1),
genesis: Genesis {
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
builder = builder.with_max_block(max_block)
}

let (tip_tx, tip_rx) = watch::channel(H256::zero());
let (tip_tx, tip_rx) = watch::channel(H256::ZERO);
use reth_revm_inspectors::stack::InspectorStackConfig;
let factory = reth_revm::Factory::new(self.chain.clone());

Expand Down
52 changes: 30 additions & 22 deletions crates/blockchain-tree/src/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ impl BlockBuffer {

#[cfg(test)]
mod tests {
use reth_interfaces::test_utils::generators;
use std::collections::HashMap;

use reth_interfaces::test_utils::generators::{random_block, Rng};
use reth_primitives::{BlockHash, BlockNumHash, SealedBlockWithSenders};

use crate::BlockBuffer;
use reth_interfaces::test_utils::{
generators,
generators::{random_block, Rng},
};
use reth_primitives::{BlockHash, BlockNumHash, SealedBlockWithSenders};
use std::collections::HashMap;

fn create_block<R: Rng>(rng: &mut R, number: u64, parent: BlockHash) -> SealedBlockWithSenders {
let block = random_block(rng, number, Some(parent), None, None);
Expand All @@ -231,7 +231,8 @@ mod tests {
#[test]
fn simple_insertion() {
let mut rng = generators::rng();
let block1 = create_block(&mut rng, 10, BlockHash::random());
let parent = rng.gen();
let block1 = create_block(&mut rng, 10, parent);
let mut buffer = BlockBuffer::new(3);

buffer.insert_block(block1.clone());
Expand All @@ -244,11 +245,12 @@ mod tests {
fn take_all_chain_of_childrens() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 12, block2.hash);
let block4 = create_block(&mut rng, 14, BlockHash::random());
let parent4 = rng.gen();
let block4 = create_block(&mut rng, 14, parent4);

let mut buffer = BlockBuffer::new(5);

Expand All @@ -273,7 +275,7 @@ mod tests {
fn take_all_multi_level_childrens() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 11, block1.hash);
Expand Down Expand Up @@ -307,7 +309,7 @@ mod tests {
fn take_self_with_childs() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 11, block1.hash);
Expand Down Expand Up @@ -341,11 +343,12 @@ mod tests {
fn clean_chain_of_children() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 12, block2.hash);
let block4 = create_block(&mut rng, 14, BlockHash::random());
let parent4 = rng.gen();
let block4 = create_block(&mut rng, 14, parent4);

let mut buffer = BlockBuffer::new(5);

Expand All @@ -363,7 +366,7 @@ mod tests {
fn clean_all_multi_level_childrens() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 11, block1.hash);
Expand All @@ -385,14 +388,17 @@ mod tests {
fn clean_multi_chains() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block1a = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block2a = create_block(&mut rng, 11, block1.hash);
let random_block1 = create_block(&mut rng, 10, BlockHash::random());
let random_block2 = create_block(&mut rng, 11, BlockHash::random());
let random_block3 = create_block(&mut rng, 12, BlockHash::random());
let random_parent1 = rng.gen();
let random_block1 = create_block(&mut rng, 10, random_parent1);
let random_parent2 = rng.gen();
let random_block2 = create_block(&mut rng, 11, random_parent2);
let random_parent3 = rng.gen();
let random_block3 = create_block(&mut rng, 12, random_parent3);

let mut buffer = BlockBuffer::new(10);

Expand Down Expand Up @@ -436,11 +442,12 @@ mod tests {
fn evict_with_gap() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 12, block2.hash);
let block4 = create_block(&mut rng, 13, BlockHash::random());
let parent4 = rng.gen();
let block4 = create_block(&mut rng, 13, parent4);

let mut buffer = BlockBuffer::new(3);

Expand Down Expand Up @@ -472,11 +479,12 @@ mod tests {
fn simple_eviction() {
let mut rng = generators::rng();

let main_parent = BlockNumHash::new(9, BlockHash::random());
let main_parent = BlockNumHash::new(9, rng.gen());
let block1 = create_block(&mut rng, 10, main_parent.hash);
let block2 = create_block(&mut rng, 11, block1.hash);
let block3 = create_block(&mut rng, 12, block2.hash);
let block4 = create_block(&mut rng, 13, BlockHash::random());
let parent4 = rng.gen();
let block4 = create_block(&mut rng, 13, parent4);

let mut buffer = BlockBuffer::new(3);

Expand Down
16 changes: 8 additions & 8 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ mod tests {
for i in 0..10 {
provider
.tx_ref()
.put::<tables::CanonicalHeaders>(i, H256([100 + i as u8; 32]))
.put::<tables::CanonicalHeaders>(i, H256::new([100 + i as u8; 32]))
.unwrap();
}
provider
Expand Down Expand Up @@ -1320,10 +1320,10 @@ mod tests {
BlockchainTree::new(externals, sender, config, None).expect("failed to create tree");

// genesis block 10 is already canonical
tree.make_canonical(&H256::zero()).unwrap();
tree.make_canonical(&H256::ZERO).unwrap();

// make sure is_block_hash_canonical returns true for genesis block
tree.is_block_hash_canonical(&H256::zero()).unwrap();
tree.is_block_hash_canonical(&H256::ZERO).unwrap();

// make genesis block 10 as finalized
tree.finalize_block(10);
Expand Down Expand Up @@ -1355,7 +1355,7 @@ mod tests {
);

// check if random block is known
let old_block = BlockNumHash::new(1, H256([32; 32]));
let old_block = BlockNumHash::new(1, H256::new([32; 32]));
let err = BlockchainTreeError::PendingBlockIsFinalized { last_finalized: 10 };

assert_eq!(tree.is_block_known(old_block).unwrap_err().as_tree_error(), Some(err));
Expand Down Expand Up @@ -1423,10 +1423,10 @@ mod tests {
/**** INSERT SIDE BLOCKS *** */

let mut block1a = block1.clone();
let block1a_hash = H256([0x33; 32]);
let block1a_hash = H256::new([0x33; 32]);
block1a.hash = block1a_hash;
let mut block2a = block2.clone();
let block2a_hash = H256([0x34; 32]);
let block2a_hash = H256::new([0x34; 32]);
block2a.hash = block2a_hash;

// reinsert two blocks that point to canonical chain
Expand Down Expand Up @@ -1626,8 +1626,8 @@ mod tests {

// insert unconnected block2b
let mut block2b = block2a.clone();
block2b.hash = H256([0x99; 32]);
block2b.parent_hash = H256([0x88; 32]);
block2b.hash = H256::new([0x99; 32]);
block2b.parent_hash = H256::new([0x88; 32]);

assert_eq!(
tree.insert_block(block2b.clone()).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/auto-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl StorageInner {
.map(|r| (*r).clone().expect("receipts have not been pruned").into())
.collect::<Vec<ReceiptWithBloom>>();
header.logs_bloom =
receipts_with_bloom.iter().fold(Bloom::zero(), |bloom, r| bloom | r.bloom);
receipts_with_bloom.iter().fold(Bloom::ZERO, |bloom, r| bloom | r.bloom);
proofs::calculate_receipt_root(&receipts_with_bloom)
};

Expand Down
Loading

0 comments on commit ccae4eb

Please sign in to comment.