Skip to content
Open
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
19 changes: 14 additions & 5 deletions lean_client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lean_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["chain", "containers", "fork_choice", "networking", "validator"]
members = ["chain", "containers", "env-config", "fork_choice", "networking", "validator"]
resolver = "2"

[workspace.package]
Expand All @@ -14,7 +14,7 @@ containers = { path = "./containers" }
fork_choice = { path = "./fork_choice" }
networking = { path = "./networking" }
validator = { path = "./validator" }
libp2p = {version = "0.56.0", default-features = false, features = [
libp2p = { version = "0.56.0", default-features = false, features = [
'dns',
'gossipsub',
'identify',
Expand Down Expand Up @@ -52,8 +52,10 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["xmss-signing"]
default = ["devnet2", "xmss-signing"]
xmss-signing = ["validator/xmss-signing"]
devnet1 = ["containers/devnet1", "fork-choice/devnet1", "networking/devnet1", "validator/devnet1"]
devnet2 = ["containers/devnet2", "fork-choice/devnet2", "networking/devnet2", "validator/devnet2"]

[dependencies]
chain = { path = "./chain" }
Expand Down
26 changes: 26 additions & 0 deletions lean_client/ENVIRONMENT_SELECTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### To select which devnet you want to compile

#### Option A
- Change the default features in root `Cargo.toml`:
```toml
[features]
default = ["devnet1", "<...other features>"] # Change to "devnet2" if needed
devnet1 = [...]
devnet2 = [...]
```

#### Option B
- Use the `--no-default-features` flag and specify the desired devnet feature when building or running the project:
```bash
cargo build --no-default-features --features devnet1 # Change to devnet2
```


### Running tests for a specific devnet

From root directory, use the following command:
```bash
cargo test -p <crate_name> --no-default-features --features devnet1 # Change to devnet2
```

Use `<crate_name>` to specify the crate you want to test.
59 changes: 25 additions & 34 deletions lean_client/chain/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@ pub struct BasisPoint(pub u64);

impl BasisPoint {
pub const MAX: u64 = 10_000;

pub const fn new(value: u64) -> Option<Self> {
if value <= Self::MAX { Some(BasisPoint(value)) } else { None }
}
#[inline] pub fn get(&self) -> u64 { self.0 }

#[inline]
pub fn get(&self) -> u64 { self.0 }
}

pub const INTERVALS_PER_SLOT: u64 = 4;
pub const SLOT_DURATION_MS: u64 = 4_000;
pub const SECONDS_PER_SLOT: u64 = SLOT_DURATION_MS / 1_000;
pub const SECONDS_PER_INTERVAL: u64 = SECONDS_PER_SLOT / INTERVALS_PER_SLOT;
pub const JUSTIFICATION_LOOKBACK_SLOTS: u64 = 3;

pub const PROPOSER_REORG_CUTOFF_BPS: BasisPoint = match BasisPoint::new(2_500) { Some(x) => x, None => panic!() };
pub const VOTE_DUE_BPS: BasisPoint = match BasisPoint::new(5_000) { Some(x) => x, None => panic!() };
pub const FAST_CONFIRM_DUE_BPS: BasisPoint = match BasisPoint::new(7_500) { Some(x) => x, None => panic!() };
pub const VIEW_FREEZE_CUTOFF_BPS: BasisPoint= match BasisPoint::new(7_500) { Some(x) => x, None => panic!() };

pub const HISTORICAL_ROOTS_LIMIT: u64 = 1u64 << 18;
pub const VALIDATOR_REGISTRY_LIMIT: u64 = 1u64 << 12;

#[derive(Clone, Debug)]
pub struct ChainConfig {
pub intervals_per_slot: u64,
pub slot_duration_ms: u64,
pub second_per_slot: u64,
pub seconds_per_slot: u64,
pub seconds_per_interval: u64,
pub justification_lookback_slots: u64,
pub proposer_reorg_cutoff_bps: BasisPoint,
pub vote_due_bps: BasisPoint,
Expand All @@ -36,24 +27,24 @@ pub struct ChainConfig {
pub validator_registry_limit: u64,
}

pub const DEVNET_CONFIG: ChainConfig = ChainConfig {
slot_duration_ms: SLOT_DURATION_MS,
second_per_slot: SECONDS_PER_SLOT,
justification_lookback_slots: JUSTIFICATION_LOOKBACK_SLOTS,
proposer_reorg_cutoff_bps: PROPOSER_REORG_CUTOFF_BPS,
vote_due_bps: VOTE_DUE_BPS,
fast_confirm_due_bps: FAST_CONFIRM_DUE_BPS,
view_freeze_cutoff_bps: VIEW_FREEZE_CUTOFF_BPS,
historical_roots_limit: HISTORICAL_ROOTS_LIMIT,
validator_registry_limit: VALIDATOR_REGISTRY_LIMIT,
};
impl ChainConfig {
pub fn devnet() -> Self {
let slot_duration_ms = 4_000;
let seconds_per_slot = slot_duration_ms / 1_000;
let intervals_per_slot = 4;

#[cfg(test)]
mod tests {
use super::*;
#[test] fn time_math_is_consistent() {
assert_eq!(SLOT_DURATION_MS, 4_000);
assert_eq!(SECONDS_PER_SLOT, 4);
assert_eq!(SECONDS_PER_INTERVAL, 1);
Self {
slot_duration_ms,
seconds_per_slot,
intervals_per_slot,
seconds_per_interval: seconds_per_slot / intervals_per_slot,
justification_lookback_slots: 3,
proposer_reorg_cutoff_bps: BasisPoint::new(2_500).expect("Valid BPS"),
vote_due_bps: BasisPoint::new(5_000).expect("Valid BPS"),
fast_confirm_due_bps: BasisPoint::new(7_500).expect("Valid BPS"),
view_freeze_cutoff_bps: BasisPoint::new(7_500).expect("Valid BPS"),
historical_roots_limit: 1u64 << 18,
validator_registry_limit: 1u64 << 12,
}
}
}
3 changes: 2 additions & 1 deletion lean_client/chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod config;
mod config;
pub use config::ChainConfig;
4 changes: 4 additions & 0 deletions lean_client/containers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ edition = "2021"

[features]
xmss-verify = ["leansig"]
default = []
devnet1 = ["env-config/devnet1"]
devnet2 = ["env-config/devnet2"]

[lib]
name = "containers"
path = "src/lib.rs"

[dependencies]
env-config = { path = "../env-config", default-features = false }
ssz = { git = "https://github.com/grandinetech/grandine", package = "ssz", branch = "develop", submodules = true }
ssz_derive = { git = "https://github.com/grandinetech/grandine", package = "ssz_derive", branch = "develop", submodules = false }
typenum = "1"
Expand Down
Loading