Add const to control writing of ssz files

This commit is contained in:
Paul Hauner 2019-09-08 21:57:48 -04:00
parent 09b0db2535
commit 7b7a44e2f2
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -37,6 +37,12 @@ use types::*;
// |-------must be this long------| // |-------must be this long------|
pub const GRAFFITI: &str = "sigp/lighthouse-0.0.0-prerelease"; pub const GRAFFITI: &str = "sigp/lighthouse-0.0.0-prerelease";
/// If true, everytime a block is processed the pre-state, post-state and block are written to SSZ
/// files in the temp directory.
///
/// Only useful for testing.
const WRITE_BLOCK_PROCESSING_SSZ: bool = true;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum BlockProcessingOutcome { pub enum BlockProcessingOutcome {
/// Block was valid and imported into the block graph. /// Block was valid and imported into the block graph.
@ -1463,6 +1469,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} }
fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) { fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
if WRITE_BLOCK_PROCESSING_SSZ {
let root = Hash256::from_slice(&state.tree_hash_root()); let root = Hash256::from_slice(&state.tree_hash_root());
let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot, root); let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot, root);
let mut path = std::env::temp_dir().join("lighthouse"); let mut path = std::env::temp_dir().join("lighthouse");
@ -1480,9 +1487,11 @@ fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
"error" => format!("{:?}", e) "error" => format!("{:?}", e)
), ),
} }
}
} }
fn write_block<T: EthSpec>(block: &BeaconBlock<T>, root: Hash256, log: &Logger) { fn write_block<T: EthSpec>(block: &BeaconBlock<T>, root: Hash256, log: &Logger) {
if WRITE_BLOCK_PROCESSING_SSZ {
let filename = format!("block_slot_{}_root{}.ssz", block.slot, root); let filename = format!("block_slot_{}_root{}.ssz", block.slot, root);
let mut path = std::env::temp_dir().join("lighthouse"); let mut path = std::env::temp_dir().join("lighthouse");
let _ = fs::create_dir_all(path.clone()); let _ = fs::create_dir_all(path.clone());
@ -1499,6 +1508,7 @@ fn write_block<T: EthSpec>(block: &BeaconBlock<T>, root: Hash256, log: &Logger)
"error" => format!("{:?}", e) "error" => format!("{:?}", e)
), ),
} }
}
} }
impl From<DBError> for Error { impl From<DBError> for Error {