diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index 6048e42b1..e764e1b1d 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -1,4 +1,4 @@ -use crate::beacon_chain::{BeaconChain, BeaconChainTypes}; +use beacon_chain::{BeaconChain, BeaconChainTypes}; use futures::Future; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink}; use protos::services::{ @@ -34,7 +34,7 @@ impl AttestationService for AttestationServiceInstance { // verify the slot, drop lock on state afterwards { let slot_requested = req.get_slot(); - let state = self.chain.get_state(); + let state = &self.chain.head().beacon_state; // Start by performing some checks // Check that the AttestionData is for the current slot (otherwise it will not be valid) diff --git a/beacon_node/rpc/src/beacon_block.rs b/beacon_node/rpc/src/beacon_block.rs index e553b79e7..c28c4f111 100644 --- a/beacon_node/rpc/src/beacon_block.rs +++ b/beacon_node/rpc/src/beacon_block.rs @@ -1,4 +1,4 @@ -use crate::beacon_chain::{BeaconChain, BeaconChainTypes}; +use beacon_chain::{BeaconChain, BeaconChainTypes}; use crossbeam_channel; use eth2_libp2p::PubsubMessage; use futures::Future; diff --git a/beacon_node/rpc/src/beacon_chain.rs b/beacon_node/rpc/src/beacon_chain.rs deleted file mode 100644 index a37c219f6..000000000 --- a/beacon_node/rpc/src/beacon_chain.rs +++ /dev/null @@ -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: Send + Sync { - fn get_spec(&self) -> &ChainSpec; - - fn get_state(&self) -> RwLockReadGuard>; - - fn get_mut_state(&self) -> RwLockWriteGuard>; - - fn process_block(&self, block: BeaconBlock) - -> Result; - - fn produce_block( - &self, - randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), BlockProductionError>; - - fn produce_attestation_data(&self, shard: u64) -> Result; - - fn process_attestation( - &self, - attestation: Attestation, - ) -> Result<(), AttestationValidationError>; -} - -impl BeaconChain for RawBeaconChain { - fn get_spec(&self) -> &ChainSpec { - &self.spec - } - - fn get_state(&self) -> RwLockReadGuard> { - self.state.read() - } - - fn get_mut_state(&self) -> RwLockWriteGuard> { - self.state.write() - } - - fn process_block( - &self, - block: BeaconBlock, - ) -> Result { - self.process_block(block) - } - - fn produce_block( - &self, - randao_reveal: Signature, - ) -> Result<(BeaconBlock, BeaconState), BlockProductionError> { - self.produce_block(randao_reveal) - } - - fn produce_attestation_data(&self, shard: u64) -> Result { - self.produce_attestation_data(shard) - } - - fn process_attestation( - &self, - attestation: Attestation, - ) -> Result<(), AttestationValidationError> { - self.process_attestation(attestation) - } -} diff --git a/beacon_node/rpc/src/beacon_node.rs b/beacon_node/rpc/src/beacon_node.rs index a923bbb35..8b49b193e 100644 --- a/beacon_node/rpc/src/beacon_node.rs +++ b/beacon_node/rpc/src/beacon_node.rs @@ -1,10 +1,11 @@ -use crate::beacon_chain::{BeaconChain, BeaconChainTypes}; +use beacon_chain::{BeaconChain, BeaconChainTypes}; use futures::Future; use grpcio::{RpcContext, UnarySink}; use protos::services::{Empty, Fork, NodeInfoResponse}; use protos::services_grpc::BeaconNodeService; use slog::{trace, warn}; use std::sync::Arc; +use types::EthSpec; #[derive(Clone)] pub struct BeaconNodeServiceInstance { @@ -22,7 +23,7 @@ impl BeaconNodeService for BeaconNodeServiceInstance { node_info.set_version(version::version()); // get the chain state - let state = self.chain.get_state(); + let state = &self.chain.head().beacon_state; let state_fork = state.fork.clone(); let genesis_time = state.genesis_time; @@ -32,10 +33,12 @@ impl BeaconNodeService for BeaconNodeServiceInstance { fork.set_current_version(state_fork.current_version.to_vec()); fork.set_epoch(state_fork.epoch.into()); + let spec = T::EthSpec::spec(); + node_info.set_fork(fork); node_info.set_genesis_time(genesis_time); - node_info.set_genesis_slot(self.chain.get_spec().genesis_slot.as_u64()); - node_info.set_chain_id(u32::from(self.chain.get_spec().chain_id)); + node_info.set_genesis_slot(spec.genesis_slot.as_u64()); + node_info.set_chain_id(u32::from(spec.chain_id)); // send the node_info the requester let error_log = self.log.clone(); diff --git a/beacon_node/rpc/src/lib.rs b/beacon_node/rpc/src/lib.rs index 9646135b6..95c2e2916 100644 --- a/beacon_node/rpc/src/lib.rs +++ b/beacon_node/rpc/src/lib.rs @@ -1,15 +1,14 @@ mod attestation; mod beacon_block; -pub mod beacon_chain; mod beacon_node; pub mod config; mod validator; use self::attestation::AttestationServiceInstance; use self::beacon_block::BeaconBlockServiceInstance; -use self::beacon_chain::{BeaconChain, BeaconChainTypes}; use self::beacon_node::BeaconNodeServiceInstance; use self::validator::ValidatorServiceInstance; +use beacon_chain::{BeaconChain, BeaconChainTypes}; pub use config::Config as RPCConfig; use futures::Future; use grpcio::{Environment, ServerBuilder}; diff --git a/beacon_node/rpc/src/validator.rs b/beacon_node/rpc/src/validator.rs index e58c202d6..4ab9588c4 100644 --- a/beacon_node/rpc/src/validator.rs +++ b/beacon_node/rpc/src/validator.rs @@ -1,4 +1,4 @@ -use crate::beacon_chain::{BeaconChain, BeaconChainTypes}; +use beacon_chain::{BeaconChain, BeaconChainTypes}; use bls::PublicKey; use futures::Future; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink}; @@ -7,7 +7,7 @@ use protos::services_grpc::ValidatorService; use slog::{trace, warn}; use ssz::Decode; use std::sync::Arc; -use types::{Epoch, RelativeEpoch}; +use types::{Epoch, EthSpec, RelativeEpoch}; #[derive(Clone)] pub struct ValidatorServiceInstance { @@ -29,8 +29,8 @@ impl ValidatorService for ValidatorServiceInstance { let validators = req.get_validators(); trace!(self.log, "RPC request"; "endpoint" => "GetValidatorDuties", "epoch" => req.get_epoch()); - let spec = self.chain.get_spec(); - let state = self.chain.get_state(); + let spec = T::EthSpec::spec(); + let state = &self.chain.head().beacon_state; let epoch = Epoch::from(req.get_epoch()); let mut resp = GetDutiesResponse::new(); let resp_validators = resp.mut_active_validators();