mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
Add fork choice JSON dumping
This commit is contained in:
@@ -3,13 +3,19 @@ use parking_lot::RwLock;
|
||||
use proto_array_fork_choice::ProtoArrayForkChoice;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use state_processing::common::get_attesting_indices;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::marker::PhantomData;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use store::Error as StoreError;
|
||||
use types::{
|
||||
Attestation, BeaconBlock, BeaconState, BeaconStateError, Checkpoint, Epoch, EthSpec, Hash256,
|
||||
Slot,
|
||||
};
|
||||
|
||||
/// If `true`, fork choice will be dumped to a JSON file in `/tmp` whenever find head fail.
|
||||
pub const FORK_CHOICE_DEBUGGING: bool = true;
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -250,6 +256,20 @@ impl<T: BeaconChainTypes> ForkChoice<T> {
|
||||
|
||||
metrics::stop_timer(timer);
|
||||
|
||||
if FORK_CHOICE_DEBUGGING {
|
||||
if let Err(e) = &result {
|
||||
if let Ok(duration) = SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||
let time = duration.as_millis();
|
||||
if let Ok(mut file) = File::create(format!("/tmp/fork-choice-{}", time)) {
|
||||
let _ = write!(file, "{:?}\n", e);
|
||||
if let Ok(json) = self.backend.as_json() {
|
||||
let _ = write!(file, "{}", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user