2019-03-22 02:51:17 +00:00
|
|
|
use beacon_chain::BeaconChain as RawBeaconChain;
|
|
|
|
use beacon_chain::{
|
|
|
|
db::ClientDB,
|
|
|
|
fork_choice::ForkChoice,
|
2019-03-30 13:08:55 +00:00
|
|
|
parking_lot::{RwLockReadGuard, RwLockWriteGuard},
|
2019-03-22 02:51:17 +00:00
|
|
|
slot_clock::SlotClock,
|
2019-03-30 04:58:31 +00:00
|
|
|
types::{BeaconState, ChainSpec, Signature},
|
2019-03-30 08:32:32 +00:00
|
|
|
AttestationValidationError, BlockProductionError,
|
2019-03-22 02:51:17 +00:00
|
|
|
};
|
2019-03-26 04:26:05 +00:00
|
|
|
pub use beacon_chain::{BeaconChainError, BlockProcessingOutcome};
|
2019-03-30 08:32:32 +00:00
|
|
|
use types::{Attestation, AttestationData, BeaconBlock};
|
2019-03-22 02:51:17 +00:00
|
|
|
|
|
|
|
/// The RPC's API to the beacon chain.
|
|
|
|
pub trait BeaconChain: Send + Sync {
|
|
|
|
fn get_spec(&self) -> &ChainSpec;
|
|
|
|
|
|
|
|
fn get_state(&self) -> RwLockReadGuard<BeaconState>;
|
2019-03-26 04:26:05 +00:00
|
|
|
|
2019-03-30 13:08:55 +00:00
|
|
|
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState>;
|
|
|
|
|
2019-03-26 04:26:05 +00:00
|
|
|
fn process_block(&self, block: BeaconBlock)
|
|
|
|
-> Result<BlockProcessingOutcome, BeaconChainError>;
|
2019-03-30 04:58:31 +00:00
|
|
|
|
|
|
|
fn produce_block(
|
|
|
|
&self,
|
|
|
|
randao_reveal: Signature,
|
|
|
|
) -> Result<(BeaconBlock, BeaconState), BlockProductionError>;
|
2019-03-30 08:32:32 +00:00
|
|
|
|
|
|
|
fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, BeaconChainError>;
|
|
|
|
|
|
|
|
fn process_attestation(
|
|
|
|
&self,
|
|
|
|
attestation: Attestation,
|
|
|
|
) -> Result<(), AttestationValidationError>;
|
2019-03-22 02:51:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, U, F> BeaconChain for RawBeaconChain<T, U, F>
|
|
|
|
where
|
|
|
|
T: ClientDB + Sized,
|
|
|
|
U: SlotClock,
|
|
|
|
F: ForkChoice,
|
|
|
|
{
|
|
|
|
fn get_spec(&self) -> &ChainSpec {
|
|
|
|
&self.spec
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_state(&self) -> RwLockReadGuard<BeaconState> {
|
|
|
|
self.state.read()
|
|
|
|
}
|
2019-03-26 04:26:05 +00:00
|
|
|
|
2019-03-30 13:08:55 +00:00
|
|
|
fn get_mut_state(&self) -> RwLockWriteGuard<BeaconState> {
|
|
|
|
self.state.write()
|
|
|
|
}
|
|
|
|
|
2019-03-26 04:26:05 +00:00
|
|
|
fn process_block(
|
|
|
|
&self,
|
|
|
|
block: BeaconBlock,
|
|
|
|
) -> Result<BlockProcessingOutcome, BeaconChainError> {
|
|
|
|
self.process_block(block)
|
|
|
|
}
|
2019-03-30 04:58:31 +00:00
|
|
|
|
|
|
|
fn produce_block(
|
|
|
|
&self,
|
|
|
|
randao_reveal: Signature,
|
|
|
|
) -> Result<(BeaconBlock, BeaconState), BlockProductionError> {
|
|
|
|
self.produce_block(randao_reveal)
|
|
|
|
}
|
2019-03-30 08:32:32 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2019-03-22 02:51:17 +00:00
|
|
|
}
|