Skip to content

Commit 841b70b

Browse files
committed
feat: add parmigiana to genesis, deprecate pecorino, refactor genesis spec
1 parent 089a927 commit 841b70b

File tree

6 files changed

+88
-56
lines changed

6 files changed

+88
-56
lines changed

Cargo.toml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.14.4"
6+
version = "0.16.0-rc.1"
77
edition = "2024"
88
rust-version = "1.88"
99
authors = ["init4"]
@@ -34,33 +34,33 @@ debug = false
3434
incremental = false
3535

3636
[workspace.dependencies]
37-
signet-blobber = { version = "0.14", path = "crates/blobber" }
38-
signet-block-processor = { version = "0.14", path = "crates/block-processor" }
39-
signet-db = { version = "0.14", path = "crates/db" }
40-
signet-genesis = { version = "0.14", path = "crates/genesis" }
41-
signet-node = { version = "0.14", path = "crates/node" }
42-
signet-node-config = { version = "0.14", path = "crates/node-config" }
43-
signet-node-tests = { version = "0.14", path = "crates/node-tests" }
44-
signet-node-types = { version = "0.14", path = "crates/node-types" }
45-
signet-rpc = { version = "0.14", path = "crates/rpc" }
37+
signet-blobber = { version = "0.16.0-rc.1", path = "crates/blobber" }
38+
signet-block-processor = { version = "0.16.0-rc.1", path = "crates/block-processor" }
39+
signet-db = { version = "0.16.0-rc.1", path = "crates/db" }
40+
signet-genesis = { version = "0.16.0-rc.1", path = "crates/genesis" }
41+
signet-node = { version = "0.16.0-rc.1", path = "crates/node" }
42+
signet-node-config = { version = "0.16.0-rc.1", path = "crates/node-config" }
43+
signet-node-tests = { version = "0.16.0-rc.1", path = "crates/node-tests" }
44+
signet-node-types = { version = "0.16.0-rc.1", path = "crates/node-types" }
45+
signet-rpc = { version = "0.16.0-rc.1", path = "crates/rpc" }
4646

4747
init4-bin-base = { version = "0.17.0", features = ["alloy"] }
4848

49-
signet-bundle = "0.14"
50-
signet-constants = "0.14"
51-
signet-evm = "0.14"
52-
signet-extract = "0.14"
53-
signet-test-utils = "0.14"
54-
signet-tx-cache = "0.14"
55-
signet-types = "0.14"
56-
signet-zenith = "0.14"
57-
signet-journal = "0.14"
49+
signet-bundle = "0.16.0-rc.1"
50+
signet-constants = "0.16.0-rc.1"
51+
signet-evm = "0.16.0-rc.1"
52+
signet-extract = "0.16.0-rc.1"
53+
signet-test-utils = "0.16.0-rc.1"
54+
signet-tx-cache = "0.16.0-rc.1"
55+
signet-types = "0.16.0-rc.1"
56+
signet-zenith = "0.16.0-rc.1"
57+
signet-journal = "0.16.0-rc.1"
5858

5959
# ajj
6060
ajj = { version = "0.3.4" }
6161

6262
# trevm
63-
trevm = { version = "0.31.0", features = ["full_env_cfg"] }
63+
trevm = { version = "0.31.2", features = ["full_env_cfg"] }
6464
revm-inspectors = "0.32.0" # should be 1 more than trevm version, usually
6565

6666
# Alloy periphery crates

crates/genesis/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ Genesis configuration and utilities for the Signet Node.
44

55
This library contains the following:
66

7-
- `GenesisSpec` - An enum representing different genesis specifications (Mainnet,
8-
Pecorino, Test, or custom file paths), which can be used to load genesis data.
9-
- `NetworkGenesis` - A struct containing both rollup and host genesis configurations.
7+
- `GenesisSpec` - An enum representing different genesis specifications
8+
(Mainnet, Parmigiana, Pecorino, Test, or custom file paths), which can be
9+
used to load genesis data.
10+
- `NetworkGenesis` - A struct containing both rollup and host genesis
11+
configurations.
12+
- `PARMIGIANA_GENESIS` / `PARMIGIANA_HOST_GENESIS` - The Parmigiana genesis
13+
data.
1014
- `PECORINO_GENESIS` / `PECORINO_HOST_GENESIS` - The Pecorino genesis data.
11-
- `TEST_GENESIS` / `TEST_HOST_GENESIS` - Local test genesis for testing purposes.
15+
- `TEST_GENESIS` / `TEST_HOST_GENESIS` - Local test genesis for testing
16+
purposes.
1217
- `GenesisError` - Errors that can occur when loading or parsing genesis data.
1318

1419
## Example
1520

1621
```
1722
# use signet_genesis::GenesisSpec;
1823
# fn _main() -> Result<(), Box<dyn std::error::Error>> {
19-
let genesis = GenesisSpec::Pecorino.load_genesis()?;
24+
let genesis = GenesisSpec::Parmigiana.load_genesis()?;
2025
// Access rollup (L2/Signet) genesis
2126
let rollup = &genesis.rollup;
2227
// Access host (L1/Ethereum) genesis

crates/genesis/src/lib.rs

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ pub static MAINNET_HOST_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
4646
serde_json::from_str(MAINNET_HOST_GENESIS_JSON).expect("Failed to parse mainnet host genesis")
4747
});
4848

49+
/// Genesis for the Parmigiana testnet.
50+
pub static PARMIGIANA_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
51+
serde_json::from_str(include_str!("./parmigiana.genesis.json"))
52+
.expect("Failed to parse parmigiana genesis")
53+
});
54+
55+
/// Genesis for the Parmigiana host testnet.
56+
pub static PARMIGIANA_HOST_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
57+
serde_json::from_str(include_str!("./parmigiana.host.genesis.json"))
58+
.expect("Failed to parse parmigiana host genesis")
59+
});
60+
4961
/// Genesis for the Pecorino testnet.
5062
pub static PECORINO_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
5163
serde_json::from_str(PECORINO_GENESIS_JSON).expect("Failed to parse pecorino genesis")
@@ -90,9 +102,9 @@ pub enum GenesisError {
90102
#[derive(Debug, Clone)]
91103
pub struct NetworkGenesis {
92104
/// The rollup genesis configuration.
93-
pub rollup: Genesis,
105+
pub rollup: Cow<'static, Genesis>,
94106
/// The host genesis configuration.
95-
pub host: Genesis,
107+
pub host: Cow<'static, Genesis>,
96108
}
97109

98110
/// Raw genesis JSON strings for a network.
@@ -108,12 +120,8 @@ pub struct RawNetworkGenesis {
108120
#[derive(Debug, Clone, serde::Deserialize)]
109121
#[serde(untagged)]
110122
pub enum GenesisSpec {
111-
/// Signet mainnet.
112-
Mainnet,
113-
/// Pecorino testnet.
114-
Pecorino,
115-
/// Local testnet.
116-
Test,
123+
/// Known chain genesis configurations.
124+
Known(#[serde(deserialize_with = "known_from_str")] KnownChains),
117125
/// Custom paths to genesis files.
118126
Custom {
119127
/// Path to the rollup genesis file.
@@ -123,21 +131,34 @@ pub enum GenesisSpec {
123131
},
124132
}
125133

134+
fn known_from_str<'de, D>(deserializer: D) -> std::result::Result<KnownChains, D::Error>
135+
where
136+
D: serde::Deserializer<'de>,
137+
{
138+
let s = <String as serde::Deserialize>::deserialize(deserializer)?;
139+
KnownChains::from_str(&s).map_err(serde::de::Error::custom)
140+
}
141+
126142
impl GenesisSpec {
127143
/// Load the raw genesis JSON strings from the specified source.
128144
///
129145
/// Returns both rollup and host genesis JSON strings.
130146
pub fn load_raw_genesis(&self) -> Result<RawNetworkGenesis> {
131147
match self {
132-
GenesisSpec::Mainnet => Ok(RawNetworkGenesis {
148+
GenesisSpec::Known(KnownChains::Mainnet) => Ok(RawNetworkGenesis {
133149
rollup: Cow::Borrowed(MAINNET_GENESIS_JSON),
134150
host: Cow::Borrowed(MAINNET_HOST_GENESIS_JSON),
135151
}),
136-
GenesisSpec::Pecorino => Ok(RawNetworkGenesis {
152+
GenesisSpec::Known(KnownChains::Parmigiana) => Ok(RawNetworkGenesis {
153+
rollup: Cow::Borrowed(include_str!("./parmigiana.genesis.json")),
154+
host: Cow::Borrowed(include_str!("./parmigiana.host.genesis.json")),
155+
}),
156+
#[allow(deprecated)]
157+
GenesisSpec::Known(KnownChains::Pecorino) => Ok(RawNetworkGenesis {
137158
rollup: Cow::Borrowed(PECORINO_GENESIS_JSON),
138159
host: Cow::Borrowed(PECORINO_HOST_GENESIS_JSON),
139160
}),
140-
GenesisSpec::Test => Ok(RawNetworkGenesis {
161+
GenesisSpec::Known(KnownChains::Test) => Ok(RawNetworkGenesis {
141162
rollup: Cow::Borrowed(TEST_GENESIS_JSON),
142163
host: Cow::Borrowed(TEST_HOST_GENESIS_JSON),
143164
}),
@@ -153,21 +174,27 @@ impl GenesisSpec {
153174
/// Returns both rollup and host genesis configurations.
154175
pub fn load_genesis(&self) -> Result<NetworkGenesis> {
155176
match self {
156-
GenesisSpec::Mainnet => Ok(NetworkGenesis {
157-
rollup: MAINNET_GENESIS.clone(),
158-
host: MAINNET_HOST_GENESIS.clone(),
177+
GenesisSpec::Known(KnownChains::Mainnet) => Ok(NetworkGenesis {
178+
rollup: Cow::Borrowed(&*MAINNET_GENESIS),
179+
host: Cow::Borrowed(&*MAINNET_HOST_GENESIS),
180+
}),
181+
GenesisSpec::Known(KnownChains::Parmigiana) => Ok(NetworkGenesis {
182+
rollup: Cow::Borrowed(&*PARMIGIANA_GENESIS),
183+
host: Cow::Borrowed(&*PARMIGIANA_HOST_GENESIS),
159184
}),
160-
GenesisSpec::Pecorino => Ok(NetworkGenesis {
161-
rollup: PECORINO_GENESIS.clone(),
162-
host: PECORINO_HOST_GENESIS.clone(),
185+
#[allow(deprecated)]
186+
GenesisSpec::Known(KnownChains::Pecorino) => Ok(NetworkGenesis {
187+
rollup: Cow::Borrowed(&*PECORINO_GENESIS),
188+
host: Cow::Borrowed(&*PECORINO_HOST_GENESIS),
189+
}),
190+
GenesisSpec::Known(KnownChains::Test) => Ok(NetworkGenesis {
191+
rollup: Cow::Borrowed(&*TEST_GENESIS),
192+
host: Cow::Borrowed(&*TEST_HOST_GENESIS),
163193
}),
164-
GenesisSpec::Test => {
165-
Ok(NetworkGenesis { rollup: TEST_GENESIS.clone(), host: TEST_HOST_GENESIS.clone() })
166-
}
167194
GenesisSpec::Custom { .. } => self.load_raw_genesis().and_then(|genesis| {
168195
Ok(NetworkGenesis {
169-
rollup: serde_json::from_str(&genesis.rollup)?,
170-
host: serde_json::from_str(&genesis.host)?,
196+
rollup: Cow::Owned(serde_json::from_str(&genesis.rollup)?),
197+
host: Cow::Owned(serde_json::from_str(&genesis.host)?),
171198
})
172199
}),
173200
}
@@ -240,9 +267,6 @@ impl FromEnv for GenesisSpec {
240267

241268
impl From<KnownChains> for GenesisSpec {
242269
fn from(known: KnownChains) -> Self {
243-
match known {
244-
KnownChains::Pecorino => GenesisSpec::Pecorino,
245-
KnownChains::Test => GenesisSpec::Test,
246-
}
270+
Self::Known(known)
247271
}
248272
}

crates/node-config/src/core.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl SignetNodeConfig {
198198

199199
/// Returns the rollup genesis configuration if any has been loaded.
200200
pub fn genesis(&self) -> &'static Genesis {
201-
static ONCE: OnceLock<Genesis> = OnceLock::new();
201+
static ONCE: OnceLock<Cow<'static, Genesis>> = OnceLock::new();
202202
ONCE.get_or_init(|| self.genesis.load_genesis().expect("Failed to load genesis").rollup)
203203
}
204204

@@ -222,6 +222,7 @@ impl SignetNodeConfig {
222222
#[cfg(test)]
223223
mod defaults {
224224
use super::*;
225+
use signet_types::constants::KnownChains;
225226

226227
impl Default for SignetNodeConfig {
227228
fn default() -> Self {
@@ -233,7 +234,7 @@ mod defaults {
233234
http_port: Some(SIGNET_NODE_DEFAULT_HTTP_PORT),
234235
ws_port: Some(SIGNET_NODE_DEFAULT_HTTP_PORT + 1),
235236
ipc_endpoint: None,
236-
genesis: GenesisSpec::Test,
237+
genesis: GenesisSpec::Known(KnownChains::Test),
237238

238239
slot_calculator: SlotCalculator::new(0, 0, 12),
239240
}

crates/node-config/src/test_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use init4_bin_base::utils::calc::SlotCalculator;
33
use reth_db::test_utils::tempdir_path;
44
use signet_blobber::BlobFetcherConfig;
55
use signet_genesis::GenesisSpec;
6+
use signet_types::constants::KnownChains;
67
use std::borrow::Cow;
78

89
/// Make a test config
@@ -25,6 +26,6 @@ const TEST_CONFIG: SignetNodeConfig = SignetNodeConfig::new(
2526
31391, // NOP
2627
31392, // NOP
2728
Some(Cow::Borrowed("/trethNOP")),
28-
GenesisSpec::Test,
29+
GenesisSpec::Known(KnownChains::Test),
2930
SlotCalculator::new(0, 0, 12),
3031
);

crates/node-tests/tests/basic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use alloy::{
1010
signers::Signer,
1111
};
1212
use serial_test::serial;
13-
use signet_constants::RollupPermitted;
13+
use signet_constants::{KnownChains, RollupPermitted};
1414
use signet_genesis::GenesisSpec;
1515
use signet_node_tests::{HostBlockSpec, run_test, utils::adjust_usd_decimals};
1616

@@ -69,7 +69,8 @@ async fn test_basic_reorg() {
6969
#[tokio::test]
7070
async fn test_genesis_allocs() {
7171
run_test(|ctx| async move {
72-
let genesis = GenesisSpec::Test.load_genesis().expect("Failed to load genesis");
72+
let genesis =
73+
GenesisSpec::Known(KnownChains::Test).load_genesis().expect("Failed to load genesis");
7374
ctx.verify_allocs(&genesis.rollup);
7475
})
7576
.await;

0 commit comments

Comments
 (0)