-
Notifications
You must be signed in to change notification settings - Fork 0
beacon state tile in-memory storage + messages #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,4 +45,4 @@ jobs: | |
| run: just fmt-check | ||
|
|
||
| - name: Check clippy | ||
| run: just clippy | ||
| run: just clippy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| consensus-spec-tests/ | ||
| *.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>, | ||
|
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, | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.