Log all states and blocks processed
This commit is contained in:
parent
37cd98f3ce
commit
e7b324966d
@ -11,6 +11,7 @@ use operation_pool::{OperationPool, PersistedOperationPool};
|
|||||||
use parking_lot::{RwLock, RwLockReadGuard};
|
use parking_lot::{RwLock, RwLockReadGuard};
|
||||||
use slog::{error, info, warn, Logger};
|
use slog::{error, info, warn, Logger};
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
|
use ssz::Encode;
|
||||||
use state_processing::per_block_processing::{
|
use state_processing::per_block_processing::{
|
||||||
errors::{
|
errors::{
|
||||||
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
|
AttestationValidationError, AttesterSlashingValidationError, DepositValidationError,
|
||||||
@ -21,6 +22,8 @@ use state_processing::per_block_processing::{
|
|||||||
use state_processing::{
|
use state_processing::{
|
||||||
per_block_processing, per_slot_processing, BlockProcessingError, BlockSignatureStrategy,
|
per_block_processing, per_slot_processing, BlockProcessingError, BlockSignatureStrategy,
|
||||||
};
|
};
|
||||||
|
use std::fs;
|
||||||
|
use std::io::prelude::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use store::iter::{BlockRootsIterator, StateRootsIterator};
|
use store::iter::{BlockRootsIterator, StateRootsIterator};
|
||||||
@ -1035,6 +1038,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
|
|
||||||
metrics::stop_timer(db_read_timer);
|
metrics::stop_timer(db_read_timer);
|
||||||
|
|
||||||
|
write_block(&block, block_root, &self.log);
|
||||||
|
write_state(
|
||||||
|
&format!("state_pre_block_{}", block_root),
|
||||||
|
&parent_state,
|
||||||
|
&self.log,
|
||||||
|
);
|
||||||
|
|
||||||
let catchup_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CATCHUP_STATE);
|
let catchup_timer = metrics::start_timer(&metrics::BLOCK_PROCESSING_CATCHUP_STATE);
|
||||||
|
|
||||||
// Keep a list of any states that were "skipped" (block-less) in between the parent state
|
// Keep a list of any states that were "skipped" (block-less) in between the parent state
|
||||||
@ -1083,6 +1093,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
|
|
||||||
let state_root = state.canonical_root();
|
let state_root = state.canonical_root();
|
||||||
|
|
||||||
|
write_state(
|
||||||
|
&format!("state_post_block_{}", block_root),
|
||||||
|
&state,
|
||||||
|
&self.log,
|
||||||
|
);
|
||||||
|
|
||||||
if block.state_root != state_root {
|
if block.state_root != state_root {
|
||||||
return Ok(BlockProcessingOutcome::StateRootMismatch {
|
return Ok(BlockProcessingOutcome::StateRootMismatch {
|
||||||
block: block.state_root,
|
block: block.state_root,
|
||||||
@ -1445,6 +1461,45 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
|
||||||
|
let root = Hash256::from_slice(&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<T: EthSpec>(block: &BeaconBlock<T>, root: Hash256, log: &Logger) {
|
||||||
|
let filename = format!("block_slot_{}_root{}.ssz", block.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)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<DBError> for Error {
|
impl From<DBError> for Error {
|
||||||
fn from(e: DBError) -> Error {
|
fn from(e: DBError) -> Error {
|
||||||
Error::DBError(e)
|
Error::DBError(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user