Remove BeaconChain
wrapper trait from rpc
This commit is contained in:
parent
0590504261
commit
5a5eebca06
@ -1,4 +1,4 @@
|
|||||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
|
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
|
||||||
use protos::services::{
|
use protos::services::{
|
||||||
@ -34,7 +34,7 @@ impl<T: BeaconChainTypes> AttestationService for AttestationServiceInstance<T> {
|
|||||||
// verify the slot, drop lock on state afterwards
|
// verify the slot, drop lock on state afterwards
|
||||||
{
|
{
|
||||||
let slot_requested = req.get_slot();
|
let slot_requested = req.get_slot();
|
||||||
let state = self.chain.get_state();
|
let state = &self.chain.head().beacon_state;
|
||||||
|
|
||||||
// Start by performing some checks
|
// Start by performing some checks
|
||||||
// Check that the AttestionData is for the current slot (otherwise it will not be valid)
|
// Check that the AttestionData is for the current slot (otherwise it will not be valid)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
use crossbeam_channel;
|
use crossbeam_channel;
|
||||||
use eth2_libp2p::PubsubMessage;
|
use eth2_libp2p::PubsubMessage;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
use beacon_chain::BeaconChain as RawBeaconChain;
|
|
||||||
use beacon_chain::{
|
|
||||||
parking_lot::{RwLockReadGuard, RwLockWriteGuard},
|
|
||||||
types::{BeaconState, ChainSpec, Signature},
|
|
||||||
AttestationValidationError, BlockProductionError,
|
|
||||||
};
|
|
||||||
pub use beacon_chain::{BeaconChainError, BeaconChainTypes, BlockProcessingOutcome};
|
|
||||||
use types::{Attestation, AttestationData, BeaconBlock};
|
|
||||||
|
|
||||||
/// The RPC's API to the beacon chain.
|
|
||||||
pub trait BeaconChain<T: BeaconChainTypes>: Send + Sync {
|
|
||||||
fn get_spec(&self) -> &ChainSpec;
|
|
||||||
|
|
||||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<T::EthSpec>>;
|
|
||||||
|
|
||||||
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState<T::EthSpec>>;
|
|
||||||
|
|
||||||
fn process_block(&self, block: BeaconBlock)
|
|
||||||
-> Result<BlockProcessingOutcome, BeaconChainError>;
|
|
||||||
|
|
||||||
fn produce_block(
|
|
||||||
&self,
|
|
||||||
randao_reveal: Signature,
|
|
||||||
) -> Result<(BeaconBlock, BeaconState<T::EthSpec>), BlockProductionError>;
|
|
||||||
|
|
||||||
fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, BeaconChainError>;
|
|
||||||
|
|
||||||
fn process_attestation(
|
|
||||||
&self,
|
|
||||||
attestation: Attestation,
|
|
||||||
) -> Result<(), AttestationValidationError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: BeaconChainTypes> BeaconChain<T> for RawBeaconChain<T> {
|
|
||||||
fn get_spec(&self) -> &ChainSpec {
|
|
||||||
&self.spec
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_state(&self) -> RwLockReadGuard<BeaconState<T::EthSpec>> {
|
|
||||||
self.state.read()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState<T::EthSpec>> {
|
|
||||||
self.state.write()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn process_block(
|
|
||||||
&self,
|
|
||||||
block: BeaconBlock,
|
|
||||||
) -> Result<BlockProcessingOutcome, BeaconChainError> {
|
|
||||||
self.process_block(block)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn produce_block(
|
|
||||||
&self,
|
|
||||||
randao_reveal: Signature,
|
|
||||||
) -> Result<(BeaconBlock, BeaconState<T::EthSpec>), BlockProductionError> {
|
|
||||||
self.produce_block(randao_reveal)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, BeaconChainError> {
|
|
||||||
self.produce_attestation_data(shard)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn process_attestation(
|
|
||||||
&self,
|
|
||||||
attestation: Attestation,
|
|
||||||
) -> Result<(), AttestationValidationError> {
|
|
||||||
self.process_attestation(attestation)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,11 @@
|
|||||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use grpcio::{RpcContext, UnarySink};
|
use grpcio::{RpcContext, UnarySink};
|
||||||
use protos::services::{Empty, Fork, NodeInfoResponse};
|
use protos::services::{Empty, Fork, NodeInfoResponse};
|
||||||
use protos::services_grpc::BeaconNodeService;
|
use protos::services_grpc::BeaconNodeService;
|
||||||
use slog::{trace, warn};
|
use slog::{trace, warn};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use types::EthSpec;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BeaconNodeServiceInstance<T: BeaconChainTypes> {
|
pub struct BeaconNodeServiceInstance<T: BeaconChainTypes> {
|
||||||
@ -22,7 +23,7 @@ impl<T: BeaconChainTypes> BeaconNodeService for BeaconNodeServiceInstance<T> {
|
|||||||
node_info.set_version(version::version());
|
node_info.set_version(version::version());
|
||||||
|
|
||||||
// get the chain state
|
// get the chain state
|
||||||
let state = self.chain.get_state();
|
let state = &self.chain.head().beacon_state;
|
||||||
let state_fork = state.fork.clone();
|
let state_fork = state.fork.clone();
|
||||||
let genesis_time = state.genesis_time;
|
let genesis_time = state.genesis_time;
|
||||||
|
|
||||||
@ -32,10 +33,12 @@ impl<T: BeaconChainTypes> BeaconNodeService for BeaconNodeServiceInstance<T> {
|
|||||||
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());
|
||||||
|
|
||||||
|
let spec = T::EthSpec::spec();
|
||||||
|
|
||||||
node_info.set_fork(fork);
|
node_info.set_fork(fork);
|
||||||
node_info.set_genesis_time(genesis_time);
|
node_info.set_genesis_time(genesis_time);
|
||||||
node_info.set_genesis_slot(self.chain.get_spec().genesis_slot.as_u64());
|
node_info.set_genesis_slot(spec.genesis_slot.as_u64());
|
||||||
node_info.set_chain_id(u32::from(self.chain.get_spec().chain_id));
|
node_info.set_chain_id(u32::from(spec.chain_id));
|
||||||
|
|
||||||
// send the node_info the requester
|
// send the node_info the requester
|
||||||
let error_log = self.log.clone();
|
let error_log = self.log.clone();
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
mod attestation;
|
mod attestation;
|
||||||
mod beacon_block;
|
mod beacon_block;
|
||||||
pub mod beacon_chain;
|
|
||||||
mod beacon_node;
|
mod beacon_node;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
mod validator;
|
mod validator;
|
||||||
|
|
||||||
use self::attestation::AttestationServiceInstance;
|
use self::attestation::AttestationServiceInstance;
|
||||||
use self::beacon_block::BeaconBlockServiceInstance;
|
use self::beacon_block::BeaconBlockServiceInstance;
|
||||||
use self::beacon_chain::{BeaconChain, BeaconChainTypes};
|
|
||||||
use self::beacon_node::BeaconNodeServiceInstance;
|
use self::beacon_node::BeaconNodeServiceInstance;
|
||||||
use self::validator::ValidatorServiceInstance;
|
use self::validator::ValidatorServiceInstance;
|
||||||
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
pub use config::Config as RPCConfig;
|
pub use config::Config as RPCConfig;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use grpcio::{Environment, ServerBuilder};
|
use grpcio::{Environment, ServerBuilder};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
|
use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||||
use bls::PublicKey;
|
use bls::PublicKey;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
|
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
|
||||||
@ -7,7 +7,7 @@ use protos::services_grpc::ValidatorService;
|
|||||||
use slog::{trace, warn};
|
use slog::{trace, warn};
|
||||||
use ssz::Decode;
|
use ssz::Decode;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{Epoch, RelativeEpoch};
|
use types::{Epoch, EthSpec, RelativeEpoch};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ValidatorServiceInstance<T: BeaconChainTypes> {
|
pub struct ValidatorServiceInstance<T: BeaconChainTypes> {
|
||||||
@ -29,8 +29,8 @@ impl<T: BeaconChainTypes> ValidatorService for ValidatorServiceInstance<T> {
|
|||||||
let validators = req.get_validators();
|
let validators = req.get_validators();
|
||||||
trace!(self.log, "RPC request"; "endpoint" => "GetValidatorDuties", "epoch" => req.get_epoch());
|
trace!(self.log, "RPC request"; "endpoint" => "GetValidatorDuties", "epoch" => req.get_epoch());
|
||||||
|
|
||||||
let spec = self.chain.get_spec();
|
let spec = T::EthSpec::spec();
|
||||||
let state = self.chain.get_state();
|
let state = &self.chain.head().beacon_state;
|
||||||
let epoch = Epoch::from(req.get_epoch());
|
let epoch = Epoch::from(req.get_epoch());
|
||||||
let mut resp = GetDutiesResponse::new();
|
let mut resp = GetDutiesResponse::new();
|
||||||
let resp_validators = resp.mut_active_validators();
|
let resp_validators = resp.mut_active_validators();
|
||||||
|
Loading…
Reference in New Issue
Block a user