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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
run: just fmt-check

- name: Check clippy
run: just clippy
run: just clippy
5 changes: 4 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ jobs:
with:
setup_only: true

- name: Download consensus-spec-tests
run: make -C crates/beacon_state

- name: Run tests
run: cargo test
run: cargo test --no-fail-fast
93 changes: 82 additions & 11 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"crates/beacon_state",
"crates/common",
"crates/compression",
"crates/discovery",
Expand Down Expand Up @@ -75,6 +76,7 @@ rcgen = "0.14.7"
ring = "0.17"
rustc-hash = "2"
secp256k1 = { version = "0.30", features = ["global-context", "rand", "hashes"] }
blst = "0.3"
rustls = "0.23.37"
serde = { version = "1.0.228", features = ["derive"] }
sha2 = "0.10"
Expand Down
2 changes: 2 additions & 0 deletions crates/beacon_state/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
consensus-spec-tests/
*.tar.gz
16 changes: 16 additions & 0 deletions crates/beacon_state/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "silver_beacon_state"
edition.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
silver-common.workspace = true
flux.workspace = true
ring.workspace = true

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
serde_yml = "0.0.12"
snap = "0.1"
16 changes: 16 additions & 0 deletions crates/beacon_state/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CONSENSUS_SPECS_TEST_VERSION ?= v1.7.0-alpha.1
OUTPUT_DIR := ./consensus-spec-tests

.PHONY: all clean

all: $(OUTPUT_DIR)

clean:
rm -rf *.tar.gz $(OUTPUT_DIR)

$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
curl --progress-bar --location --remote-name --show-error --retry 3 --retry-all-errors --fail \
"https://github.com/ethereum/consensus-specs/releases/download/$(CONSENSUS_SPECS_TEST_VERSION)/mainnet.tar.gz"
tar -xzf mainnet.tar.gz -C $(OUTPUT_DIR)
rm -f mainnet.tar.gz
Comment thread
ninaiiad marked this conversation as resolved.
42 changes: 42 additions & 0 deletions crates/beacon_state/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# silver_beacon_state

## EF-based tests

Two test suites read vectors published by the Ethereum Foundation at
[`consensus-spec-tests`](https://github.com/ethereum/consensus-specs/releases)
(mainnet, Fulu fork):

- `tests/sync_scenarios.rs` — YAML-driven scenarios that drive
`BeaconStateTile` through a real `SilverSpine` adapter. Each scenario
loads a `*.ssz_snappy` checkpoint/block and asserts observable state
(mode, head slot).
- `tests/ssz_view_fixtures.rs` — field-level verification of every
`silver_common::ssz_view` accessor against `ssz_static/<Container>/ssz_random`
fixtures.

Both suites expect the vectors to be present and fail if they
aren't — run `make` first. `ssz_view_fixtures` asserts each container
directory is non-empty; `sync_scenarios` panics when `snappy_decode`
can't open the referenced file. CI runs `make` before `cargo test`.

### Fetch vectors

```sh
make -C crates/beacon_state
```

Downloads `mainnet.tar.gz` (pinned in the `Makefile`) and extracts to
`crates/beacon_state/consensus-spec-tests/`. The directory is gitignored.

### Run

```sh
# all tests
cargo test -p silver_beacon_state

# only scenarios
cargo test -p silver_beacon_state --test sync_scenarios

# only ssz_view field checks
cargo test -p silver_beacon_state --test ssz_view_fixtures
```
58 changes: 58 additions & 0 deletions crates/beacon_state/src/arena.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use flux::communication::ShmemData;
use silver_common::{TierPool, arena::open_or_create_shm};

use crate::types::{
EPOCH_POOL_CAP, EpochData, HistoricalLongtail, IMM_POOL_CAP, Immutable, LONGTAIL_POOL_CAP,
ROOTS_POOL_CAP, SLOT_POOL_CAP, SlotData, SlotRoots, VID_POOL_CAP, ValidatorIdentity,
box_zeroed,
};

#[repr(C)]
pub struct BeaconArena {
pub imm: TierPool<Immutable, IMM_POOL_CAP>,
pub vid: TierPool<ValidatorIdentity, VID_POOL_CAP>,
Comment thread
vladimir-ea marked this conversation as resolved.
pub longtail: TierPool<HistoricalLongtail, LONGTAIL_POOL_CAP>,
pub epoch: TierPool<EpochData, EPOCH_POOL_CAP>,
pub roots: TierPool<SlotRoots, ROOTS_POOL_CAP>,
pub slot: TierPool<SlotData, SLOT_POOL_CAP>,
}

impl BeaconArena {
pub const SIZE: usize = core::mem::size_of::<Self>();
pub const ALIGN: usize = core::mem::align_of::<Self>();

/// # Safety
/// `ptr` must be non-null, `ALIGN`-aligned, and point to a
/// zero-initialised `BeaconArena` that outlives `'a`.
pub unsafe fn from_ptr<'a>(ptr: *mut u8) -> &'a Self {
debug_assert!(!ptr.is_null());
debug_assert_eq!(ptr as usize % Self::ALIGN, 0);
unsafe { &*(ptr as *const Self) }
}
}

pub enum ArenaBacking {
Shm(ShmemData<BeaconArena>),
Heap(Box<BeaconArena>),
}

impl ArenaBacking {
pub fn open_shm(app_name: &str) -> Self {
Self::Shm(unsafe { open_or_create_shm::<BeaconArena>(app_name) })
}

pub fn heap() -> Self {
Self::Heap(box_zeroed())
}
}

impl core::ops::Deref for ArenaBacking {
type Target = BeaconArena;

fn deref(&self) -> &BeaconArena {
match self {
Self::Shm(s) => s,
Self::Heap(b) => b,
}
}
}
Loading
Loading