Adds genesis time to node info. Closes #256
This commit is contained in:
parent
61fc946d54
commit
17cd5bb991
@ -3,7 +3,7 @@ use futures::Future;
|
|||||||
use grpcio::{RpcContext, UnarySink};
|
use grpcio::{RpcContext, UnarySink};
|
||||||
use protos::services::{Empty, Fork, NodeInfo};
|
use protos::services::{Empty, Fork, NodeInfo};
|
||||||
use protos::services_grpc::BeaconNodeService;
|
use protos::services_grpc::BeaconNodeService;
|
||||||
use slog::{debug, trace, warn};
|
use slog::{trace, warn};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -17,17 +17,23 @@ impl BeaconNodeService for BeaconNodeServiceInstance {
|
|||||||
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfo>) {
|
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfo>) {
|
||||||
trace!(self.log, "Node info requested via RPC");
|
trace!(self.log, "Node info requested via RPC");
|
||||||
|
|
||||||
|
// build the response
|
||||||
let mut node_info = NodeInfo::new();
|
let mut node_info = NodeInfo::new();
|
||||||
node_info.set_version(version::version());
|
node_info.set_version(version::version());
|
||||||
// get the chain state fork
|
|
||||||
let state_fork = self.chain.get_state().fork.clone();
|
// get the chain state
|
||||||
|
let state = self.chain.get_state();
|
||||||
|
let state_fork = state.fork.clone();
|
||||||
|
let genesis_time = state.genesis_time.clone();
|
||||||
|
|
||||||
// build the rpc fork struct
|
// build the rpc fork struct
|
||||||
let mut fork = Fork::new();
|
let mut fork = Fork::new();
|
||||||
fork.set_previous_version(state_fork.previous_version.to_vec());
|
fork.set_previous_version(state_fork.previous_version.to_vec());
|
||||||
fork.set_current_version(state_fork.current_version.to_vec());
|
fork.set_current_version(state_fork.current_version.to_vec());
|
||||||
fork.set_epoch(state_fork.epoch.into());
|
fork.set_epoch(state_fork.epoch.into());
|
||||||
node_info.set_fork(fork);
|
|
||||||
|
|
||||||
|
node_info.set_fork(fork);
|
||||||
|
node_info.set_genesis_time(genesis_time);
|
||||||
node_info.set_chain_id(self.chain.get_spec().chain_id as u32);
|
node_info.set_chain_id(self.chain.get_spec().chain_id as u32);
|
||||||
|
|
||||||
// send the node_info the requester
|
// send the node_info the requester
|
||||||
|
@ -44,6 +44,7 @@ message NodeInfo {
|
|||||||
string version = 1;
|
string version = 1;
|
||||||
Fork fork = 2;
|
Fork fork = 2;
|
||||||
uint32 chain_id = 3;
|
uint32 chain_id = 3;
|
||||||
|
uint64 genesis_time = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Fork {
|
message Fork {
|
||||||
@ -56,7 +57,6 @@ message Empty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Block Production Service Messages
|
* Block Production Service Messages
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,6 @@ use types::{Epoch, Fork};
|
|||||||
|
|
||||||
/// The validator service. This is the main thread that executes and maintains validator
|
/// The validator service. This is the main thread that executes and maintains validator
|
||||||
/// duties.
|
/// duties.
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
/// The node we currently connected to.
|
/// The node we currently connected to.
|
||||||
connected_node_version: String,
|
connected_node_version: String,
|
||||||
@ -30,8 +29,8 @@ pub struct Service {
|
|||||||
chain_id: u16,
|
chain_id: u16,
|
||||||
/// The fork state we processing on.
|
/// The fork state we processing on.
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
// /// The slot clock keeping track of time.
|
/// The slot clock keeping track of time.
|
||||||
// slot_clock: Arc<SlotClock>,
|
slot_clock: Arc<SystemTimeSlotClock>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
@ -54,7 +53,10 @@ impl Service {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
info!(log,"Beacon node connected"; "Node Version:" => node_info.version.clone(), "Chain ID:" => node_info.chain_id);
|
// build requisite objects to form Self
|
||||||
|
let genesis_time = node_info.get_genesis_time();
|
||||||
|
|
||||||
|
info!(log,"Beacon node connected"; "Node Version" => node_info.version.clone(), "Chain ID" => node_info.chain_id, "Genesis time" => genesis_time);
|
||||||
|
|
||||||
let proto_fork = node_info.get_fork();
|
let proto_fork = node_info.get_fork();
|
||||||
let mut previous_version: [u8; 4] = [0; 4];
|
let mut previous_version: [u8; 4] = [0; 4];
|
||||||
@ -67,9 +69,8 @@ impl Service {
|
|||||||
epoch: Epoch::from(proto_fork.get_epoch()),
|
epoch: Epoch::from(proto_fork.get_epoch()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let genesis_time = 1_549_935_547;
|
// build the validator slot clock
|
||||||
let slot_clock = {
|
let slot_clock = {
|
||||||
info!(log, "Genesis time"; "unix_epoch_seconds" => genesis_time);
|
|
||||||
let clock = SystemTimeSlotClock::new(genesis_time, seconds_per_slot)
|
let clock = SystemTimeSlotClock::new(genesis_time, seconds_per_slot)
|
||||||
.expect("Unable to instantiate SystemTimeSlotClock.");
|
.expect("Unable to instantiate SystemTimeSlotClock.");
|
||||||
Arc::new(clock)
|
Arc::new(clock)
|
||||||
@ -79,6 +80,7 @@ impl Service {
|
|||||||
connected_node_version: node_info.version,
|
connected_node_version: node_info.version,
|
||||||
chain_id: node_info.chain_id as u16,
|
chain_id: node_info.chain_id as u16,
|
||||||
fork,
|
fork,
|
||||||
|
slot_clock,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user