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",
"auto_impl",
"derive_more",
"once_cell",
"reth-ethereum-forks",
"reth-network-peers",
"reth-primitives-traits",
@ -8698,6 +8697,7 @@ dependencies = [
"derive_more",
"k256",
"modular-bitfield",
"once_cell",
"op-alloy-consensus",
"proptest",
"proptest-arbitrary-interop",

View File

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

View File

@ -11,12 +11,6 @@
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
pub(crate) mod constants;
pub use constants::MIN_TRANSACTION_GAS;
@ -40,6 +34,8 @@ pub use spec::{
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.
pub fn once_cell_set<T>(value: T) -> OnceLock<T> {
let once = OnceLock::new();

View File

@ -1,6 +1,6 @@
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 alloy_chains::{Chain, NamedChain};
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,
sepolia_nodes, NodeRecord,
};
use reth_primitives_traits::SealedHeader;
use reth_primitives_traits::{
sync::{LazyLock, OnceLock},
SealedHeader,
};
/// The Ethereum mainnet spec
pub static MAINNET: LazyLock<Arc<ChainSpec>> = LazyLock::new(|| {

View File

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

View File

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

View File

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

View File

@ -69,6 +69,8 @@ pub use alloy_primitives::{logs_bloom, Log, LogData};
mod storage;
pub use storage::StorageEntry;
pub mod sync;
/// Common header types
pub mod header;
#[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 derive_more::{AsRef, Deref};
use once_cell as _;
#[cfg(not(feature = "std"))]
use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock};
#[cfg(feature = "optimism")]
use op_alloy_consensus::DepositTransaction;
#[cfg(feature = "optimism")]
@ -30,6 +28,7 @@ use op_alloy_consensus::TxDeposit;
pub use pooled::PooledTransactionsElementEcRecovered;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
pub use reth_primitives_traits::{
sync::{LazyLock, OnceLock},
transaction::{
error::{
InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError,
@ -42,8 +41,6 @@ use reth_primitives_traits::{InMemorySize, SignedTransaction};
use revm_primitives::{AuthorizationList, TxEnv};
use serde::{Deserialize, Serialize};
pub use signature::{recover_signer, recover_signer_unchecked};
#[cfg(feature = "std")]
use std::sync::{LazyLock, OnceLock};
pub use tx_type::TxType;
/// Handling transaction signature operations, including signature recovery,