mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 22:04:44 +00:00
Add fork choice JSON dumping
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use crate::error::Error;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use types::{Epoch, Hash256, Slot};
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, Encode, Decode)]
|
||||
#[derive(Clone, PartialEq, Debug, Encode, Decode, Serialize, Deserialize)]
|
||||
pub struct ProtoNode {
|
||||
/// The `slot` is not necessary for `ProtoArray`, it just exists so external components can
|
||||
/// easily query the block slot. This is useful for upstream fork choice logic.
|
||||
@@ -17,7 +18,7 @@ pub struct ProtoNode {
|
||||
best_descendant: Option<usize>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
#[derive(PartialEq, Serialize, Deserialize)]
|
||||
pub struct ProtoArray {
|
||||
/// Do not attempt to prune the tree unless it has at least this many nodes. Small prunes
|
||||
/// simply waste time.
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::error::Error;
|
||||
use crate::proto_array::ProtoArray;
|
||||
use crate::ssz_container::SszContainer;
|
||||
use parking_lot::RwLock;
|
||||
use serde_json;
|
||||
use ssz::{Decode, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
@@ -220,6 +221,11 @@ impl ProtoArrayForkChoice {
|
||||
.map(Into::into)
|
||||
.map_err(|e| format!("Failed to decode ProtoArrayForkChoice: {:?}", e))
|
||||
}
|
||||
|
||||
pub fn as_json(&self) -> Result<String, String> {
|
||||
serde_json::to_string(&*self.proto_array.read())
|
||||
.map_err(|e| format!("Failed to JSON encode proto_array: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a list of `deltas`, where there is one delta for each of the indices in
|
||||
|
||||
Reference in New Issue
Block a user