Skip to content

Commit 0fbe00e

Browse files
committed
chore: refactor spec id loading to init only once
1 parent cd05cc9 commit 0fbe00e

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

src/tasks/block/cfg.rs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
use reth_chainspec::ChainSpec;
33
use signet_block_processor::revm_spec;
44
use signet_constants::{mainnet, pecorino};
5-
use signet_genesis::PECORINO_GENESIS;
6-
use std::sync::LazyLock;
5+
use signet_genesis::{MAINNET_GENESIS, PECORINO_GENESIS};
6+
use std::sync::OnceLock;
77
use trevm::revm::{context::CfgEnv, primitives::hardfork::SpecId};
88

9-
/// The RU Pecorino [`ChainSpec`].
10-
static PECORINO_SPEC: LazyLock<ChainSpec> =
11-
LazyLock::new(|| ChainSpec::from_genesis(PECORINO_GENESIS.to_owned()));
9+
/// The RU [`ChainSpec`].
10+
static RU_SPEC: OnceLock<SpecId> = OnceLock::new();
1211

13-
/// The RU Mainnet [`ChainSpec`].
14-
static MAINNET_RU_SPEC: LazyLock<ChainSpec> =
15-
LazyLock::new(|| ChainSpec::from_genesis(signet_genesis::MAINNET_GENESIS.to_owned()));
12+
/// The Host [`ChainSpec`].
13+
static HOST_SPEC: OnceLock<SpecId> = OnceLock::new();
1614

1715
/// [`SignetCfgEnv`] holds network-level configuration values.
1816
#[derive(Debug, Clone, Copy)]
@@ -30,14 +28,13 @@ impl SignetCfgEnv {
3028
}
3129

3230
fn spec_id(&self) -> SpecId {
33-
match self.chain_id {
34-
// Pecorino
35-
pecorino::HOST_CHAIN_ID | pecorino::RU_CHAIN_ID => {
36-
revm_spec(&PECORINO_SPEC, self.timestamp)
31+
*match self.chain_id {
32+
pecorino::RU_CHAIN_ID | mainnet::RU_CHAIN_ID => {
33+
RU_SPEC.get_or_init(|| initialize_ru_spec(self.chain_id, self.timestamp))
34+
}
35+
pecorino::HOST_CHAIN_ID | mainnet::HOST_CHAIN_ID => {
36+
HOST_SPEC.get_or_init(|| initialize_host_spec(self.chain_id, self.timestamp))
3737
}
38-
// Mainnet RU
39-
mainnet::RU_CHAIN_ID => revm_spec(&MAINNET_RU_SPEC, self.timestamp),
40-
mainnet::HOST_CHAIN_ID => revm_spec(&reth_chainspec::MAINNET, self.timestamp),
4138
_ => unimplemented!("Unknown chain ID: {}", self.chain_id),
4239
}
4340
}
@@ -50,6 +47,29 @@ impl trevm::Cfg for SignetCfgEnv {
5047
}
5148
}
5249

50+
fn initialize_ru_spec(chain_id: u64, timestamp: u64) -> SpecId {
51+
match chain_id {
52+
pecorino::RU_CHAIN_ID => {
53+
revm_spec(&ChainSpec::from_genesis(PECORINO_GENESIS.to_owned()), timestamp)
54+
}
55+
mainnet::RU_CHAIN_ID => {
56+
revm_spec(&ChainSpec::from_genesis(MAINNET_GENESIS.to_owned()), timestamp)
57+
}
58+
_ => unimplemented!("Unknown chain ID: {}", chain_id),
59+
}
60+
}
61+
62+
fn initialize_host_spec(chain_id: u64, timestamp: u64) -> SpecId {
63+
match chain_id {
64+
pecorino::HOST_CHAIN_ID => {
65+
revm_spec(&ChainSpec::from_genesis(PECORINO_GENESIS.to_owned()), timestamp)
66+
}
67+
mainnet::HOST_CHAIN_ID => revm_spec(&reth_chainspec::MAINNET, timestamp),
68+
_ => unimplemented!("Unknown chain ID: {}", chain_id),
69+
}
70+
}
71+
72+
5373
#[cfg(test)]
5474
mod tests {
5575
use super::*;

0 commit comments

Comments
 (0)