diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index 7239edbf7..9244d155a 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -11,6 +11,9 @@ path = "src/lib.rs" [dev-dependencies] node_test_rig = { path = "../tests/node_test_rig" } +[features] +write_ssz_files = ["beacon_chain/write_ssz_files"] # Writes debugging .ssz files to /tmp during block processing. + [dependencies] eth2_config = { path = "../eth2/utils/eth2_config" } beacon_chain = { path = "beacon_chain" } diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 2b9f85eab..1af55cc6a 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -5,7 +5,6 @@ authors = ["Paul Hauner ", "Age Manning FullyVerifiedBlock { * invalid. */ + write_state( + &format!("state_pre_block_{}", block_root), + &state, + &chain.log, + ); + write_block(&block, block_root, &chain.log); + let core_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CORE); if let Err(err) = per_block_processing( @@ -551,6 +569,12 @@ impl FullyVerifiedBlock { metrics::stop_timer(state_root_timer); + write_state( + &format!("state_post_block_{}", block_root), + &state, + &chain.log, + ); + /* * Check to ensure the state root on the block matches the one we have calculated. */ @@ -806,3 +830,46 @@ fn get_signature_verifier<'a, E: EthSpec>( spec, ) } + +fn write_state(prefix: &str, state: &BeaconState, log: &Logger) { + if WRITE_BLOCK_PROCESSING_SSZ { + let root = state.tree_hash_root(); + let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot, root); + let mut path = std::env::temp_dir().join("lighthouse"); + let _ = fs::create_dir_all(path.clone()); + path = path.join(filename); + + match fs::File::create(path.clone()) { + Ok(mut file) => { + let _ = file.write_all(&state.as_ssz_bytes()); + } + Err(e) => error!( + log, + "Failed to log state"; + "path" => format!("{:?}", path), + "error" => format!("{:?}", e) + ), + } + } +} + +fn write_block(block: &SignedBeaconBlock, root: Hash256, log: &Logger) { + if WRITE_BLOCK_PROCESSING_SSZ { + let filename = format!("block_slot_{}_root{}.ssz", block.message.slot, root); + let mut path = std::env::temp_dir().join("lighthouse"); + let _ = fs::create_dir_all(path.clone()); + path = path.join(filename); + + match fs::File::create(path.clone()) { + Ok(mut file) => { + let _ = file.write_all(&block.as_ssz_bytes()); + } + Err(e) => error!( + log, + "Failed to log block"; + "path" => format!("{:?}", path), + "error" => format!("{:?}", e) + ), + } + } +} diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 6f7527694..e93dd0192 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -4,6 +4,9 @@ version = "0.2.0" authors = ["Sigma Prime "] edition = "2018" +[features] +write_ssz_files = ["beacon_node/write_ssz_files"] # Writes debugging .ssz files to /tmp during block processing. + [dependencies] beacon_node = { "path" = "../beacon_node" } tokio = "0.1.22"