refactor: move LazyLock and OnlyLock exports to primitives traits (#13682)

This commit is contained in:
Léa Narzis
2025-01-07 15:28:57 +01:00
committed by GitHub
parent 4d12dcda7c
commit 0d5c0d2701
10 changed files with 27 additions and 23 deletions

2
Cargo.lock generated
View File

@ -6670,7 +6670,6 @@ dependencies = [
"alloy-trie", "alloy-trie",
"auto_impl", "auto_impl",
"derive_more", "derive_more",
"once_cell",
"reth-ethereum-forks", "reth-ethereum-forks",
"reth-network-peers", "reth-network-peers",
"reth-primitives-traits", "reth-primitives-traits",
@ -8698,6 +8697,7 @@ dependencies = [
"derive_more", "derive_more",
"k256", "k256",
"modular-bitfield", "modular-bitfield",
"once_cell",
"op-alloy-consensus", "op-alloy-consensus",
"proptest", "proptest",
"proptest-arbitrary-interop", "proptest-arbitrary-interop",

View File

@ -26,7 +26,6 @@ alloy-consensus.workspace = true
# misc # misc
auto_impl.workspace = true auto_impl.workspace = true
once_cell.workspace = true
serde_json.workspace = true serde_json.workspace = true
derive_more.workspace = true derive_more.workspace = true
@ -47,7 +46,6 @@ std = [
"alloy-trie/std", "alloy-trie/std",
"reth-primitives-traits/std", "reth-primitives-traits/std",
"alloy-consensus/std", "alloy-consensus/std",
"once_cell/std",
"alloy-rlp/std", "alloy-rlp/std",
"reth-ethereum-forks/std", "reth-ethereum-forks/std",
"derive_more/std", "derive_more/std",

View File

@ -11,12 +11,6 @@
extern crate alloc; extern crate alloc;
use once_cell as _;
#[cfg(not(feature = "std"))]
pub(crate) use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock};
#[cfg(feature = "std")]
pub(crate) use std::sync::{LazyLock, OnceLock};
/// Chain specific constants /// Chain specific constants
pub(crate) mod constants; pub(crate) mod constants;
pub use constants::MIN_TRANSACTION_GAS; pub use constants::MIN_TRANSACTION_GAS;
@ -40,6 +34,8 @@ pub use spec::{
DepositContract, ForkBaseFeeParams, DEV, HOLESKY, MAINNET, SEPOLIA, DepositContract, ForkBaseFeeParams, DEV, HOLESKY, MAINNET, SEPOLIA,
}; };
use reth_primitives_traits::sync::OnceLock;
/// Simple utility to create a thread-safe sync cell with a value set. /// Simple utility to create a thread-safe sync cell with a value set.
pub fn once_cell_set<T>(value: T) -> OnceLock<T> { pub fn once_cell_set<T>(value: T) -> OnceLock<T> {
let once = OnceLock::new(); let once = OnceLock::new();

View File

@ -1,6 +1,6 @@
pub use alloy_eips::eip1559::BaseFeeParams; pub use alloy_eips::eip1559::BaseFeeParams;
use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec, LazyLock, OnceLock}; use crate::{constants::MAINNET_DEPOSIT_CONTRACT, once_cell_set, EthChainSpec};
use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, vec::Vec}; use alloc::{boxed::Box, collections::BTreeMap, string::String, sync::Arc, vec::Vec};
use alloy_chains::{Chain, NamedChain}; use alloy_chains::{Chain, NamedChain};
use alloy_consensus::{ use alloy_consensus::{
@ -28,7 +28,10 @@ use reth_network_peers::{
base_nodes, base_testnet_nodes, holesky_nodes, mainnet_nodes, op_nodes, op_testnet_nodes, base_nodes, base_testnet_nodes, holesky_nodes, mainnet_nodes, op_nodes, op_testnet_nodes,
sepolia_nodes, NodeRecord, sepolia_nodes, NodeRecord,
}; };
use reth_primitives_traits::SealedHeader; use reth_primitives_traits::{
sync::{LazyLock, OnceLock},
SealedHeader,
};
/// The Ethereum mainnet spec /// The Ethereum mainnet spec
pub static MAINNET: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| { pub static MAINNET: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {

View File

@ -16,11 +16,11 @@ workspace = true
alloy-chains.workspace = true alloy-chains.workspace = true
alloy-eip2124.workspace = true alloy-eip2124.workspace = true
alloy-primitives = { workspace = true, features = ["serde", "rlp"] } alloy-primitives = { workspace = true, features = ["serde", "rlp"] }
once_cell.workspace = true
# misc # misc
serde = { workspace = true, features = ["derive"], optional = true } serde = { workspace = true, features = ["derive"], optional = true }
dyn-clone.workspace = true dyn-clone.workspace = true
once_cell.workspace = true
rustc-hash = { workspace = true, optional = true } rustc-hash = { workspace = true, optional = true }
# arbitrary utils # arbitrary utils
@ -48,8 +48,8 @@ std = [
"alloy-chains/std", "alloy-chains/std",
"alloy-primitives/std", "alloy-primitives/std",
"rustc-hash/std", "rustc-hash/std",
"once_cell/std",
"serde?/std", "serde?/std",
"alloy-eip2124/std" "alloy-eip2124/std",
"once_cell/std"
] ]
rustc-hash = ["dep:rustc-hash"] rustc-hash = ["dep:rustc-hash"]

View File

@ -26,8 +26,6 @@ pub use base::BASE_MAINNET;
pub use base_sepolia::BASE_SEPOLIA; pub use base_sepolia::BASE_SEPOLIA;
use derive_more::{Constructor, Deref, Display, From, Into}; use derive_more::{Constructor, Deref, Display, From, Into};
pub use dev::OP_DEV; pub use dev::OP_DEV;
#[cfg(not(feature = "std"))]
pub(crate) use once_cell::sync::Lazy as LazyLock;
pub use op::OP_MAINNET; pub use op::OP_MAINNET;
use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError}; use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError};
pub use op_sepolia::OP_SEPOLIA; pub use op_sepolia::OP_SEPOLIA;
@ -38,8 +36,7 @@ use reth_chainspec::{
use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition, Hardfork}; use reth_ethereum_forks::{ChainHardforks, EthereumHardfork, ForkCondition, Hardfork};
use reth_network_peers::NodeRecord; use reth_network_peers::NodeRecord;
use reth_optimism_forks::{OpHardfork, OpHardforks}; use reth_optimism_forks::{OpHardfork, OpHardforks};
#[cfg(feature = "std")] use reth_primitives_traits::sync::LazyLock;
pub(crate) use std::sync::LazyLock;
/// Chain spec builder for a OP stack chain. /// Chain spec builder for a OP stack chain.
#[derive(Debug, Default, From)] #[derive(Debug, Default, From)]

View File

@ -34,11 +34,12 @@ secp256k1 = { workspace = true, features = [
k256.workspace = true k256.workspace = true
# misc # misc
auto_impl.workspace = true
byteorder = { workspace = true, optional = true } byteorder = { workspace = true, optional = true }
bytes.workspace = true bytes.workspace = true
derive_more.workspace = true derive_more.workspace = true
once_cell.workspace = true
serde_with = { workspace = true, optional = true } serde_with = { workspace = true, optional = true }
auto_impl.workspace = true
thiserror.workspace = true thiserror.workspace = true
# required by reth-codecs # required by reth-codecs
@ -87,6 +88,7 @@ std = [
"bytes/std", "bytes/std",
"derive_more/std", "derive_more/std",
"k256/std", "k256/std",
"once_cell/std",
"secp256k1?/std", "secp256k1?/std",
"thiserror/std", "thiserror/std",
"alloy-trie/std", "alloy-trie/std",

View File

@ -69,6 +69,8 @@ pub use alloy_primitives::{logs_bloom, Log, LogData};
mod storage; mod storage;
pub use storage::StorageEntry; pub use storage::StorageEntry;
pub mod sync;
/// Common header types /// Common header types
pub mod header; pub mod header;
#[cfg(any(test, feature = "arbitrary", feature = "test-utils"))] #[cfg(any(test, feature = "arbitrary", feature = "test-utils"))]

View File

@ -0,0 +1,9 @@
//! Lock synchronization primitives
use once_cell as _;
#[cfg(not(feature = "std"))]
pub use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock};
#[cfg(feature = "std")]
pub use std::sync::{LazyLock, OnceLock};

View File

@ -21,8 +21,6 @@ use alloy_rlp::{Decodable, Encodable, Header};
use core::hash::{Hash, Hasher}; use core::hash::{Hash, Hasher};
use derive_more::{AsRef, Deref}; use derive_more::{AsRef, Deref};
use once_cell as _; use once_cell as _;
#[cfg(not(feature = "std"))]
use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock};
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
use op_alloy_consensus::DepositTransaction; use op_alloy_consensus::DepositTransaction;
#[cfg(feature = "optimism")] #[cfg(feature = "optimism")]
@ -30,6 +28,7 @@ use op_alloy_consensus::TxDeposit;
pub use pooled::PooledTransactionsElementEcRecovered; pub use pooled::PooledTransactionsElementEcRecovered;
use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use rayon::prelude::{IntoParallelIterator, ParallelIterator};
pub use reth_primitives_traits::{ pub use reth_primitives_traits::{
sync::{LazyLock, OnceLock},
transaction::{ transaction::{
error::{ error::{
InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError, InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError,
@ -42,8 +41,6 @@ use reth_primitives_traits::{InMemorySize, SignedTransaction};
use revm_primitives::{AuthorizationList, TxEnv}; use revm_primitives::{AuthorizationList, TxEnv};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
pub use signature::{recover_signer, recover_signer_unchecked}; pub use signature::{recover_signer, recover_signer_unchecked};
#[cfg(feature = "std")]
use std::sync::{LazyLock, OnceLock};
pub use tx_type::TxType; pub use tx_type::TxType;
/// Handling transaction signature operations, including signature recovery, /// Handling transaction signature operations, including signature recovery,