-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates example code that processes beacon blocks from slots 2000-2034
- Loading branch information
Showing
38 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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 @@ | ||
{"code":404,"message":"NOT_FOUND: beacon block at slot 2005","stacktraces":[]} |
This file contains 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 @@ | ||
{"code":404,"message":"NOT_FOUND: beacon block at slot 2006","stacktraces":[]} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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 @@ | ||
{"code":404,"message":"NOT_FOUND: beacon block at slot 2033","stacktraces":[]} |
Binary file not shown.
Binary file not shown.
49 changes: 49 additions & 0 deletions
49
ethereum-consensus/examples/state_transition_mainnet_blocks.rs
This file contains 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,49 @@ | ||
use ethereum_consensus::{ | ||
phase0::mainnet as spec, | ||
state_transition::mainnet::{Context, Executor}, | ||
types::{mainnet::SignedBeaconBlock, BeaconState}, | ||
}; | ||
use ssz_rs::prelude::*; | ||
use std::{error::Error, fs}; | ||
|
||
fn main() -> std::result::Result<(), Box<dyn Error>> { | ||
println!("this example illustrates how the spec applies state transitions to mainnet data."); | ||
|
||
// Read and deserialize prestate | ||
let state_path = "./ethereum-consensus/examples/data/beacon_states/state_1999.ssz"; | ||
let f = fs::read(state_path).unwrap(); | ||
let prestate = spec::BeaconState::deserialize(&f)?; | ||
let prestate = BeaconState::Phase0(prestate); | ||
|
||
// Create executor | ||
let context = Context::for_mainnet(); | ||
let mut executor = Executor::new(prestate, context); | ||
|
||
// Read and process blocks 2000-2034 | ||
for slot in 2000..=2034 { | ||
let block_path = | ||
format!("./ethereum-consensus/examples/data/beacon_blocks/block_{}.ssz", slot); | ||
let block_bytes = fs::read(&block_path)?; | ||
|
||
// Error handling: skip missed slots | ||
if block_bytes.len() < 100 { | ||
match std::str::from_utf8(&block_bytes) { | ||
Ok(text) if text.contains("NOT_FOUND") => { | ||
println!("Slot {} was skipped (no block produced)", slot); | ||
continue; | ||
} | ||
_ => { | ||
println!("Unexpected small file for slot {}", slot); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
// Process block | ||
let signed_block = spec::SignedBeaconBlock::deserialize(&block_bytes)?; | ||
let block = SignedBeaconBlock::Phase0(signed_block); | ||
executor.apply_block(&block)?; | ||
println!("Block at slot {} was processed.", slot) | ||
} | ||
Ok(()) | ||
} |