primitives: use alloy MAINNET_GENESIS_HASH constant (#11848)

This commit is contained in:
Thomas Coratger
2024-10-17 21:44:04 +02:00
committed by GitHub
parent 52848a352a
commit a6c8bda029
14 changed files with 29 additions and 33 deletions

5
Cargo.lock generated
View File

@ -2857,6 +2857,7 @@ dependencies = [
name = "example-manual-p2p"
version = "0.0.0"
dependencies = [
"alloy-consensus",
"eyre",
"futures",
"reth-chainspec",
@ -6528,6 +6529,7 @@ name = "reth-chainspec"
version = "1.1.0"
dependencies = [
"alloy-chains",
"alloy-consensus",
"alloy-eips",
"alloy-genesis",
"alloy-primitives",
@ -6813,6 +6815,7 @@ dependencies = [
name = "reth-db-common"
version = "1.1.0"
dependencies = [
"alloy-consensus",
"alloy-genesis",
"alloy-primitives",
"boyer-moore-magiclen",
@ -7303,6 +7306,7 @@ name = "reth-ethereum-forks"
version = "1.1.0"
dependencies = [
"alloy-chains",
"alloy-consensus",
"alloy-primitives",
"alloy-rlp",
"arbitrary",
@ -7931,6 +7935,7 @@ dependencies = [
name = "reth-node-ethereum"
version = "1.1.0"
dependencies = [
"alloy-consensus",
"alloy-genesis",
"alloy-primitives",
"eyre",

View File

@ -23,6 +23,7 @@ alloy-eips = { workspace = true, features = ["serde"] }
alloy-genesis.workspace = true
alloy-primitives = { workspace = true, features = ["rand", "rlp"] }
alloy-trie.workspace = true
alloy-consensus.workspace = true
# misc
auto_impl.workspace = true

View File

@ -7,6 +7,7 @@ use alloy_primitives::{address, b256, Address, BlockNumber, B256, U256};
use alloy_trie::EMPTY_ROOT_HASH;
use derive_more::From;
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
use reth_ethereum_forks::{
ChainHardforks, DisplayHardforks, EthereumHardfork, EthereumHardforks, ForkCondition,
ForkFilter, ForkFilterKey, ForkHash, ForkId, Hardfork, Hardforks, Head, DEV_HARDFORKS,
@ -18,7 +19,7 @@ use reth_network_peers::{
use reth_primitives_traits::{
constants::{
DEV_GENESIS_HASH, EIP1559_INITIAL_BASE_FEE, EMPTY_WITHDRAWALS, ETHEREUM_BLOCK_GAS_LIMIT,
HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH,
HOLESKY_GENESIS_HASH, SEPOLIA_GENESIS_HASH,
},
Header, SealedHeader,
};

View File

@ -36,6 +36,7 @@ auto_impl.workspace = true
[dev-dependencies]
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
alloy-consensus.workspace = true
[features]
default = ["std", "serde", "rustc-hash"]

View File

@ -446,15 +446,12 @@ impl Cache {
#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::b256;
const GENESIS_HASH: B256 =
b256!("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
// EIP test vectors.
#[test]
fn forkhash() {
let mut fork_hash = ForkHash::from(GENESIS_HASH);
let mut fork_hash = ForkHash::from(MAINNET_GENESIS_HASH);
assert_eq!(fork_hash.0, hex!("fc64ec04"));
fork_hash += 1_150_000u64;
@ -468,7 +465,7 @@ mod tests {
fn compatibility_check() {
let mut filter = ForkFilter::new(
Head { number: 0, ..Default::default() },
GENESIS_HASH,
MAINNET_GENESIS_HASH,
0,
vec![
ForkFilterKey::Block(1_150_000),
@ -727,7 +724,7 @@ mod tests {
let mut fork_filter = ForkFilter::new(
Head { number: 0, ..Default::default() },
GENESIS_HASH,
MAINNET_GENESIS_HASH,
0,
vec![ForkFilterKey::Block(b1), ForkFilterKey::Block(b2)],
);

View File

@ -52,6 +52,7 @@ alloy-genesis.workspace = true
tokio.workspace = true
futures-util.workspace = true
serde_json.workspace = true
alloy-consensus.workspace = true
[features]
default = []

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
use alloy_genesis::Genesis;
use alloy_primitives::b256;
use reth::{
args::RpcServerArgs,
builder::{NodeBuilder, NodeConfig, NodeHandle},
@ -75,13 +75,11 @@ async fn can_handle_blobs() -> eyre::Result<()> {
.submit_payload(blob_payload, blob_attr, PayloadStatusEnum::Valid, versioned_hashes.clone())
.await?;
let genesis_hash = b256!("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
let (_, _) = tokio::join!(
// send fcu with blob hash
node.engine_api.update_forkchoice(genesis_hash, blob_block_hash),
node.engine_api.update_forkchoice(MAINNET_GENESIS_HASH, blob_block_hash),
// send fcu with normal hash
node.engine_api.update_forkchoice(genesis_hash, payload.block().hash())
node.engine_api.update_forkchoice(MAINNET_GENESIS_HASH, payload.block().hash())
);
// submit normal payload

View File

@ -138,10 +138,10 @@ impl Default for Status {
///
/// # Example
/// ```
/// use alloy_consensus::constants::MAINNET_GENESIS_HASH;
/// use alloy_primitives::{B256, U256};
/// use reth_chainspec::{Chain, EthereumHardfork, MAINNET};
/// use reth_eth_wire_types::{EthVersion, Status};
/// use reth_primitives::MAINNET_GENESIS_HASH;
///
/// // this is just an example status message!
/// let status = Status::builder()
@ -216,6 +216,7 @@ impl StatusBuilder {
#[cfg(test)]
mod tests {
use crate::{EthVersion, Status};
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
use alloy_genesis::Genesis;
use alloy_primitives::{hex, B256, U256};
use alloy_rlp::{Decodable, Encodable};
@ -235,10 +236,7 @@ mod tests {
"feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d",
)
.unwrap(),
genesis: B256::from_str(
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
)
.unwrap(),
genesis: MAINNET_GENESIS_HASH,
forkid: ForkId { hash: ForkHash([0xb7, 0x15, 0x07, 0x7d]), next: 0 },
};
@ -258,10 +256,7 @@ mod tests {
"feb27336ca7923f8fab3bd617fcb6e75841538f71c1bcfc267d7838489d9e13d",
)
.unwrap(),
genesis: B256::from_str(
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
)
.unwrap(),
genesis: MAINNET_GENESIS_HASH,
forkid: ForkId { hash: ForkHash([0xb7, 0x15, 0x07, 0x7d]), next: 0 },
};
let status = Status::decode(&mut &data[..]).unwrap();

View File

@ -98,11 +98,6 @@ pub const FINNEY_TO_WEI: u128 = (GWEI_TO_WEI as u128) * 1_000_000;
/// Multiplier for converting ether to wei.
pub const ETH_TO_WEI: u128 = FINNEY_TO_WEI * 1000;
/// The Ethereum mainnet genesis hash:
/// `0x0d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3`
pub const MAINNET_GENESIS_HASH: B256 =
b256!("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
/// Sepolia genesis hash: `0x25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9`
pub const SEPOLIA_GENESIS_HASH: B256 =
b256!("25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9");

View File

@ -39,10 +39,7 @@ pub use block::{
};
#[cfg(feature = "reth-codec")]
pub use compression::*;
pub use constants::{
DEV_GENESIS_HASH, HOLESKY_GENESIS_HASH, KECCAK_EMPTY, MAINNET_GENESIS_HASH,
SEPOLIA_GENESIS_HASH,
};
pub use constants::{DEV_GENESIS_HASH, HOLESKY_GENESIS_HASH, KECCAK_EMPTY, SEPOLIA_GENESIS_HASH};
pub use receipt::{
gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts,
};

View File

@ -42,6 +42,7 @@ tracing.workspace = true
[dev-dependencies]
reth-primitives-traits.workspace = true
reth-provider = { workspace = true, features = ["test-utils"] }
alloy-consensus.workspace = true
[lints]
workspace = true

View File

@ -581,6 +581,7 @@ struct GenesisAccountWithAddress {
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
use alloy_genesis::Genesis;
use reth_chainspec::{Chain, ChainSpec, HOLESKY, MAINNET, SEPOLIA};
use reth_db::DatabaseEnv;
@ -591,7 +592,7 @@ mod tests {
transaction::DbTx,
Database,
};
use reth_primitives::{HOLESKY_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH};
use reth_primitives::{HOLESKY_GENESIS_HASH, SEPOLIA_GENESIS_HASH};
use reth_primitives_traits::IntegerList;
use reth_provider::{
test_utils::{create_test_provider_factory_with_chain_spec, MockNodeTypesWithDB},

View File

@ -14,6 +14,8 @@ reth-eth-wire.workspace = true
reth-ecies.workspace = true
reth-network-peers.workspace = true
alloy-consensus.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "rand-std", "recovery"] }
futures.workspace = true

View File

@ -8,6 +8,7 @@
use std::time::Duration;
use alloy_consensus::constants::MAINNET_GENESIS_HASH;
use futures::StreamExt;
use reth_chainspec::{Chain, MAINNET};
use reth_discv4::{DiscoveryUpdate, Discv4, Discv4ConfigBuilder, DEFAULT_DISCOVERY_ADDRESS};
@ -17,7 +18,7 @@ use reth_eth_wire::{
};
use reth_network::config::rng_secret_key;
use reth_network_peers::{mainnet_nodes, pk2id, NodeRecord};
use reth_primitives::{EthereumHardfork, Head, MAINNET_GENESIS_HASH};
use reth_primitives::{EthereumHardfork, Head};
use secp256k1::{SecretKey, SECP256K1};
use std::sync::LazyLock;
use tokio::net::TcpStream;