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 protos::services::{Empty, Fork, NodeInfo};
|
||||
use protos::services_grpc::BeaconNodeService;
|
||||
use slog::{debug, trace, warn};
|
||||
use slog::{trace, warn};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -17,17 +17,23 @@ impl BeaconNodeService for BeaconNodeServiceInstance {
|
||||
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfo>) {
|
||||
trace!(self.log, "Node info requested via RPC");
|
||||
|
||||
// build the response
|
||||
let mut node_info = NodeInfo::new();
|
||||
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
|
||||
let mut fork = Fork::new();
|
||||
fork.set_previous_version(state_fork.previous_version.to_vec());
|
||||
fork.set_current_version(state_fork.current_version.to_vec());
|
||||
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);
|
||||
|
||||
// send the node_info the requester
|
||||
|
@ -44,6 +44,7 @@ message NodeInfo {
|
||||
string version = 1;
|
||||
Fork fork = 2;
|
||||
uint32 chain_id = 3;
|
||||
uint64 genesis_time = 4;
|
||||
}
|
||||
|
||||
message Fork {
|
||||
@ -56,7 +57,6 @@ message Empty {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
/// duties.
|
||||
#[derive(Debug)]
|
||||
pub struct Service {
|
||||
/// The node we currently connected to.
|
||||
connected_node_version: String,
|
||||
@ -30,8 +29,8 @@ pub struct Service {
|
||||
chain_id: u16,
|
||||
/// The fork state we processing on.
|
||||
fork: Fork,
|
||||
// /// The slot clock keeping track of time.
|
||||
// slot_clock: Arc<SlotClock>,
|
||||
/// The slot clock keeping track of time.
|
||||
slot_clock: Arc<SystemTimeSlotClock>,
|
||||
}
|
||||
|
||||
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 mut previous_version: [u8; 4] = [0; 4];
|
||||
@ -67,9 +69,8 @@ impl Service {
|
||||
epoch: Epoch::from(proto_fork.get_epoch()),
|
||||
};
|
||||
|
||||
let genesis_time = 1_549_935_547;
|
||||
// build the validator slot clock
|
||||
let slot_clock = {
|
||||
info!(log, "Genesis time"; "unix_epoch_seconds" => genesis_time);
|
||||
let clock = SystemTimeSlotClock::new(genesis_time, seconds_per_slot)
|
||||
.expect("Unable to instantiate SystemTimeSlotClock.");
|
||||
Arc::new(clock)
|
||||
@ -79,6 +80,7 @@ impl Service {
|
||||
connected_node_version: node_info.version,
|
||||
chain_id: node_info.chain_id as u16,
|
||||
fork,
|
||||
slot_clock,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user