diff --git a/Cargo.toml b/Cargo.toml index 3430b2ed7..66788b3a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,3 +56,6 @@ quote = "1.0.18" clap = { version = "4.5.3", features = ["derive"] } convert_case = "0.6.0" walkdir = "2.3.3" + +[profile.release] +debug = true \ No newline at end of file diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2000.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2000.ssz new file mode 100644 index 000000000..1a4ef713f Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2000.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2001.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2001.ssz new file mode 100644 index 000000000..1abf7c80a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2001.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2002.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2002.ssz new file mode 100644 index 000000000..4781861e4 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2002.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2003.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2003.ssz new file mode 100644 index 000000000..338b9e05a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2003.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2004.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2004.ssz new file mode 100644 index 000000000..edc195e98 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2004.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2005.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2005.ssz new file mode 100644 index 000000000..3e4d61c03 --- /dev/null +++ b/ethereum-consensus/examples/data/beacon_blocks/block_2005.ssz @@ -0,0 +1 @@ +{"code":404,"message":"NOT_FOUND: beacon block at slot 2005","stacktraces":[]} \ No newline at end of file diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2006.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2006.ssz new file mode 100644 index 000000000..e83697013 --- /dev/null +++ b/ethereum-consensus/examples/data/beacon_blocks/block_2006.ssz @@ -0,0 +1 @@ +{"code":404,"message":"NOT_FOUND: beacon block at slot 2006","stacktraces":[]} \ No newline at end of file diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2007.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2007.ssz new file mode 100644 index 000000000..002724626 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2007.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2008.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2008.ssz new file mode 100644 index 000000000..ddba3a772 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2008.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2009.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2009.ssz new file mode 100644 index 000000000..3698ac722 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2009.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2010.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2010.ssz new file mode 100644 index 000000000..c66dbd89b Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2010.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2011.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2011.ssz new file mode 100644 index 000000000..7bad9fbc5 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2011.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2012.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2012.ssz new file mode 100644 index 000000000..d7ffd361a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2012.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2013.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2013.ssz new file mode 100644 index 000000000..6f1b73de8 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2013.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2014.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2014.ssz new file mode 100644 index 000000000..381b4affc Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2014.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2015.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2015.ssz new file mode 100644 index 000000000..0c1f00fc1 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2015.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2016.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2016.ssz new file mode 100644 index 000000000..8104531c5 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2016.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2017.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2017.ssz new file mode 100644 index 000000000..6900b5cb4 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2017.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2018.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2018.ssz new file mode 100644 index 000000000..73749407a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2018.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2019.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2019.ssz new file mode 100644 index 000000000..e1e4ddb68 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2019.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2020.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2020.ssz new file mode 100644 index 000000000..03b53f144 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2020.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2021.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2021.ssz new file mode 100644 index 000000000..dabf63d56 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2021.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2022.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2022.ssz new file mode 100644 index 000000000..2fe157d3a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2022.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2023.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2023.ssz new file mode 100644 index 000000000..968867bcc Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2023.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2024.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2024.ssz new file mode 100644 index 000000000..7d9e6a59d Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2024.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2025.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2025.ssz new file mode 100644 index 000000000..e1e1bdeae Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2025.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2026.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2026.ssz new file mode 100644 index 000000000..e625480d9 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2026.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2027.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2027.ssz new file mode 100644 index 000000000..30c189b01 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2027.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2028.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2028.ssz new file mode 100644 index 000000000..4ee8c318b Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2028.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2029.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2029.ssz new file mode 100644 index 000000000..71cc8fefe Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2029.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2030.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2030.ssz new file mode 100644 index 000000000..79b41fd37 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2030.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2031.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2031.ssz new file mode 100644 index 000000000..d507614a9 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2031.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2032.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2032.ssz new file mode 100644 index 000000000..995ad9be5 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2032.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2033.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2033.ssz new file mode 100644 index 000000000..c8f5e4b8d --- /dev/null +++ b/ethereum-consensus/examples/data/beacon_blocks/block_2033.ssz @@ -0,0 +1 @@ +{"code":404,"message":"NOT_FOUND: beacon block at slot 2033","stacktraces":[]} \ No newline at end of file diff --git a/ethereum-consensus/examples/data/beacon_blocks/block_2034.ssz b/ethereum-consensus/examples/data/beacon_blocks/block_2034.ssz new file mode 100644 index 000000000..ae92f79d4 Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_blocks/block_2034.ssz differ diff --git a/ethereum-consensus/examples/data/beacon_states/state_1999.ssz b/ethereum-consensus/examples/data/beacon_states/state_1999.ssz new file mode 100644 index 000000000..07662900a Binary files /dev/null and b/ethereum-consensus/examples/data/beacon_states/state_1999.ssz differ diff --git a/ethereum-consensus/examples/state_transition_mainnet_blocks.rs b/ethereum-consensus/examples/state_transition_mainnet_blocks.rs new file mode 100644 index 000000000..e68a50bed --- /dev/null +++ b/ethereum-consensus/examples/state_transition_mainnet_blocks.rs @@ -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> { + 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(()) +}