Add beacon_chain trait for gRPC server

This commit is contained in:
Age Manning
2019-03-22 13:51:17 +11:00
parent ee6a0ccb92
commit 858cf4f1f4
3 changed files with 42 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
use beacon_chain::{db::ClientDB, fork_choice::ForkChoice, slot_clock::SlotClock, BeaconChain};
use crate::beacon_chain::BeaconChain;
use futures::Future;
use grpcio::{RpcContext, UnarySink};
use protos::services::{Empty, Fork, NodeInfo};
@@ -7,22 +7,12 @@ use slog::{debug, trace, warn};
use std::sync::Arc;
#[derive(Clone)]
pub struct BeaconNodeServiceInstance<T, U, F>
where
T: ClientDB + Clone,
U: SlotClock + Clone,
F: ForkChoice + Clone,
{
pub chain: Arc<BeaconChain<T, U, F>>,
pub struct BeaconNodeServiceInstance {
pub chain: Arc<BeaconChain>,
pub log: slog::Logger,
}
impl<T, U, F> BeaconNodeService for BeaconNodeServiceInstance<T, U, F>
where
T: ClientDB + Clone,
U: SlotClock + Clone,
F: ForkChoice + Clone,
{
impl BeaconNodeService for BeaconNodeServiceInstance {
/// Provides basic node information.
fn info(&mut self, ctx: RpcContext, _req: Empty, sink: UnarySink<NodeInfo>) {
trace!(self.log, "Node info requested via RPC");
@@ -30,7 +20,7 @@ where
let mut node_info = NodeInfo::new();
node_info.set_version(version::version());
// get the chain state fork
let state_fork = self.chain.state.read().fork.clone();
let state_fork = self.chain.get_state().fork.clone();
// build the rpc fork struct
let mut fork = Fork::new();
fork.set_previous_version(state_fork.previous_version.to_vec());
@@ -38,7 +28,7 @@ where
fork.set_epoch(state_fork.epoch.into());
node_info.set_fork(fork);
node_info.set_chain_id(self.chain.spec.chain_id as u32);
node_info.set_chain_id(self.chain.get_spec().chain_id as u32);
// send the node_info the requester
let error_log = self.log.clone();