Tidy slot_dump, remove SlotDump
, use CheckPoint
This commit is contained in:
parent
4d062d77f9
commit
b99e4ed9f4
@ -1,7 +1,9 @@
|
||||
use serde_derive::Serialize;
|
||||
use types::{BeaconBlock, BeaconState, Hash256};
|
||||
|
||||
/// Represents some block and it's associated state. Generally, this will be used for tracking the
|
||||
/// head, justified head and finalized head.
|
||||
#[derive(PartialEq, Clone, Serialize)]
|
||||
pub struct CheckPoint {
|
||||
pub beacon_block: BeaconBlock,
|
||||
pub beacon_block_root: Hash256,
|
||||
|
@ -1,18 +1,11 @@
|
||||
use super::{BeaconChain, ClientDB, DBError, SlotClock};
|
||||
use serde_derive::Serialize;
|
||||
use types::{BeaconBlock, BeaconState, Hash256};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct SlotDump {
|
||||
pub beacon_block: BeaconBlock,
|
||||
pub beacon_block_root: Hash256,
|
||||
pub beacon_state: BeaconState,
|
||||
pub beacon_state_root: Hash256,
|
||||
}
|
||||
use super::{BeaconChain, CheckPoint, ClientDB, DBError, SlotClock};
|
||||
use types::Hash256;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Error {
|
||||
/// There was an error reading from the database. This is an internal error.
|
||||
DBError(String),
|
||||
/// There is a missing (or invalid) block in the database. This is an internal error.
|
||||
MissingBlock(Hash256),
|
||||
}
|
||||
|
||||
@ -21,10 +14,14 @@ where
|
||||
T: ClientDB,
|
||||
U: SlotClock,
|
||||
{
|
||||
pub fn chain_dump(&self) -> Result<Vec<SlotDump>, Error> {
|
||||
/// Dumps the entire canonical chain, from the head to genesis to a vector for analysis.
|
||||
///
|
||||
/// This could be a very expensive operation and should only be done in testing/analysis
|
||||
/// activities.
|
||||
pub fn chain_dump(&self) -> Result<Vec<CheckPoint>, Error> {
|
||||
let mut dump = vec![];
|
||||
|
||||
let mut last_slot = SlotDump {
|
||||
let mut last_slot = CheckPoint {
|
||||
beacon_block: self.head().beacon_block.clone(),
|
||||
beacon_block_root: self.head().beacon_block_root,
|
||||
beacon_state: self.head().beacon_state.clone(),
|
||||
@ -37,8 +34,7 @@ where
|
||||
let beacon_block_root = last_slot.beacon_block.parent_root;
|
||||
|
||||
if beacon_block_root == self.spec.zero_hash {
|
||||
// Genesis has been reached.
|
||||
break;
|
||||
break; // Genesis has been reached.
|
||||
}
|
||||
|
||||
let beacon_block = self
|
||||
@ -51,7 +47,7 @@ where
|
||||
.get_deserialized(&beacon_state_root)?
|
||||
.ok_or_else(|| Error::MissingBlock(beacon_state_root))?;
|
||||
|
||||
let slot = SlotDump {
|
||||
let slot = CheckPoint {
|
||||
beacon_block,
|
||||
beacon_block_root,
|
||||
beacon_state,
|
||||
|
@ -15,7 +15,6 @@ mod state;
|
||||
|
||||
use self::attestation_targets::AttestationTargets;
|
||||
use self::block_graph::BlockGraph;
|
||||
use self::checkpoint::CheckPoint;
|
||||
use attestation_aggregator::AttestationAggregator;
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
@ -29,6 +28,7 @@ use std::sync::Arc;
|
||||
use types::{BeaconState, ChainSpec, Hash256};
|
||||
|
||||
pub use self::block_processing::Outcome as BlockProcessingOutcome;
|
||||
pub use self::checkpoint::CheckPoint;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum BeaconChainError {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::TestValidator;
|
||||
pub use beacon_chain::dump::{Error as DumpError, SlotDump};
|
||||
use beacon_chain::BeaconChain;
|
||||
pub use beacon_chain::{dump::Error as DumpError, CheckPoint};
|
||||
use db::{
|
||||
stores::{BeaconBlockStore, BeaconStateStore},
|
||||
MemoryDB,
|
||||
@ -208,11 +208,11 @@ impl BeaconChainHarness {
|
||||
debug!("Free attestations processed.");
|
||||
}
|
||||
|
||||
pub fn chain_dump(&self) -> Result<Vec<SlotDump>, DumpError> {
|
||||
pub fn chain_dump(&self) -> Result<Vec<CheckPoint>, DumpError> {
|
||||
self.beacon_chain.chain_dump()
|
||||
}
|
||||
|
||||
pub fn dump_to_file(&self, filename: String, chain_dump: &Vec<SlotDump>) {
|
||||
pub fn dump_to_file(&self, filename: String, chain_dump: &Vec<CheckPoint>) {
|
||||
let json = serde_json::to_string(chain_dump).unwrap();
|
||||
let mut file = File::create(filename).unwrap();
|
||||
file.write_all(json.as_bytes())
|
||||
|
Loading…
Reference in New Issue
Block a user