Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.11.0"
version = "0.11.1"
edition = "2024"
rust-version = "1.88"
authors = ["init4"]
Expand Down Expand Up @@ -37,15 +37,21 @@ incremental = false
signet-blobber = { version = "0.11", path = "crates/blobber" }
signet-block-processor = { version = "0.11", path = "crates/block-processor" }
signet-db = { version = "0.11", path = "crates/db" }
signet-genesis = { version = "0.11", path = "crates/genesis" }
signet-node = { version = "0.11", path = "crates/node" }
signet-node-config = { version = "0.11", path = "crates/node-config" }
signet-node-tests = { version = "0.11", path = "crates/node-tests" }
signet-node-types = { version = "0.11", path = "crates/node-types" }
signet-rpc = { version = "0.11", path = "crates/rpc" }


init4-bin-base = { version = "0.13.1", features = ["alloy"] }

signet-bundle = "0.11.1"
signet-constants = "0.11.1"
signet-evm = "0.11.1"
signet-extract = "0.11.1"
signet-test-utils = "0.11.1"
signet-tx-cache = "0.11.1"
signet-types = "0.11.1"
signet-zenith = "0.11.1"
Expand Down Expand Up @@ -124,6 +130,7 @@ tempfile = "3.17.0"
# signet-constants = { path = "../sdk/crates/constants"}
# signet-evm = { path = "../sdk/crates/evm"}
# signet-extract = { path = "../sdk/crates/extract"}
# signet-test-utils = { path = "../sdk/crates/test-utils"}
# signet-tx-cache = { path = "../sdk/crates/tx-cache"}
# signet-types = { path = "../sdk/crates/types"}
# signet-zenith = { path = "../sdk/crates/zenith"}
Expand Down
17 changes: 17 additions & 0 deletions crates/genesis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "signet-genesis"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
alloy = { workspace = true, features = ["genesis"] }
init4-bin-base.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
signet-constants.workspace = true
thiserror.workspace = true
22 changes: 22 additions & 0 deletions crates/genesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Signet Genesis

Genesis configuration and utilities for the Signet Node.

This library contains the following:

- `GenesisSpec` - An enum representing different genesis specifications, either
Pecorino, Test, or a custom genesis file path, which can be used to load
genesis data.
- `PECORINO_GENESIS` - The Pecorino genesis data.
- `TEST_GENESIS` - A local test genesis for testing purposes.
- `GenesisError` - Errors that can occur when loading or parsing genesis data.

## Example

```
# use signet_genesis::GenesisSpec;
# fn _main() -> Result<(), Box<dyn std::error::Error>> {
let genesis = GenesisSpec::Pecorino.load_genesis()?;
# Ok(())
# }
```
152 changes: 152 additions & 0 deletions crates/genesis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#![doc = include_str!("../README.md")]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use alloy::genesis::Genesis;
use init4_bin_base::utils::from_env::{
EnvItemInfo, FromEnv, FromEnvErr, FromEnvVar, parse_env_if_present,
};
use signet_constants::KnownChains;
use std::{borrow::Cow, path::PathBuf, str::FromStr, sync::LazyLock};

/// Pecorino genesis file.
pub const PECORINO_GENESIS_JSON: &str = include_str!("./pecorino.genesis.json");

/// Local genesis file for testing purposes.
pub const TEST_GENESIS_JSON: &str = include_str!("./local.genesis.json");

/// Genesis for the Pecorino testnet.
pub static PECORINO_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
serde_json::from_str(PECORINO_GENESIS_JSON).expect("Failed to parse pecorino genesis")
});

/// Test genesis for local testing.
pub static TEST_GENESIS: LazyLock<Genesis> = LazyLock::new(|| {
serde_json::from_str(TEST_GENESIS_JSON).expect("Failed to parse test genesis")
});

/// Environment variable for specifying the genesis JSON file path.
const GENSIS_JSON_PATH: &str = "GENSIS_JSON_PATH";

/// Result type for genesis operations.
pub type Result<T, E = GenesisError> = std::result::Result<T, E>;

/// Errors that can occur when loading the genesis file.
#[derive(Debug, thiserror::Error)]
pub enum GenesisError {
/// IO error when reading the genesis file.
#[error(transparent)]
Io(#[from] std::io::Error),
/// JSON parsing error when parsing the genesis file.
#[error(transparent)]
Json(#[from] serde_json::Error),
}

/// Different genesis configurations available.
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(untagged)]
pub enum GenesisSpec {
/// Pecorino testnet.
Pecorino,
/// Local testnet.
Test,
/// Custom path to a genesis file.
Path(PathBuf),
}

impl GenesisSpec {
/// Load the genesis JSON from the specified source.
///
/// This will alwys return a valid string for [`KnownChains`].
pub fn load_raw_genesis(&self) -> Result<Cow<'static, str>> {
match self {
GenesisSpec::Pecorino => Ok(Cow::Borrowed(PECORINO_GENESIS_JSON)),
GenesisSpec::Test => Ok(Cow::Borrowed(TEST_GENESIS_JSON)),
GenesisSpec::Path(path) => {
std::fs::read_to_string(path).map(Cow::Owned).map_err(Into::into)
}
}
}

/// Load the genesis from the specified source.
///
/// This will always return a valid genesis for [`KnownChains`].
pub fn load_genesis(&self) -> Result<alloy::genesis::Genesis> {
match self {
GenesisSpec::Pecorino => Ok(PECORINO_GENESIS.clone()),
GenesisSpec::Test => Ok(TEST_GENESIS.clone()),
GenesisSpec::Path(_) => self
.load_raw_genesis()
.and_then(|raw| serde_json::from_str(&raw).map_err(Into::into)),
}
}
}

impl FromStr for GenesisSpec {
type Err = <PathBuf as FromStr>::Err;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Ok(known) = KnownChains::from_str(s) {
return Ok(known.into());
}

Ok(GenesisSpec::Path(s.parse()?))
}
}

impl FromEnvVar for GenesisSpec {
type Error = <GenesisSpec as FromStr>::Err;

fn from_env_var(env_var: &str) -> Result<Self, FromEnvErr<Self::Error>> {
parse_env_if_present(env_var)
}
}

impl FromEnv for GenesisSpec {
type Error = <GenesisSpec as FromStr>::Err;

fn inventory() -> Vec<&'static init4_bin_base::utils::from_env::EnvItemInfo> {
vec![
&EnvItemInfo {
var: "CHAIN_NAME",
description: "The name of the chain. If set, the other environment variables are ignored.",
optional: true,
},
&EnvItemInfo {
var: GENSIS_JSON_PATH,
description: "A filepath to the genesis JSON file. Required if CHAIN_NAME is not set.",
optional: true,
},
]
}

fn from_env() -> Result<Self, FromEnvErr<Self::Error>> {
parse_env_if_present::<KnownChains>("CHAIN_NAME")
.map(Into::into)
.or_else(|_| parse_env_if_present::<PathBuf>(GENSIS_JSON_PATH).map(Into::into))
}
}

impl From<KnownChains> for GenesisSpec {
fn from(known: KnownChains) -> Self {
match known {
KnownChains::Pecorino => GenesisSpec::Pecorino,
KnownChains::Test => GenesisSpec::Test,
}
}
}

impl From<PathBuf> for GenesisSpec {
fn from(path: PathBuf) -> Self {
GenesisSpec::Path(path)
}
}
186 changes: 186 additions & 0 deletions crates/genesis/src/local.genesis.json

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions crates/genesis/src/pecorino.genesis.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions crates/node-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "signet-node-config"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true

[dependencies]
signet-blobber.workspace = true
signet-types.workspace = true

init4-bin-base.workspace = true

reth.workspace = true
reth-chainspec.workspace = true
reth-exex.workspace = true
reth-node-api.workspace = true
reth-db = { workspace = true, optional = true}

alloy.workspace = true

eyre.workspace = true
reqwest.workspace = true
serde.workspace = true
tracing.workspace = true
trevm.workspace = true
signet-genesis.workspace = true

[features]
test_utils = ["dep:reth-db", "reth-db/test-utils"]
8 changes: 8 additions & 0 deletions crates/node-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Signet Node Config

Configuration objects for the Signet Node

This library contains the following:

- `SignetNodeConfig` - The main configuration object for a Signet Node. This
struct can be loaded from the environment, or deserialized from a JSON file.
Loading
Loading