2019-01-24 06:05:48 +00:00
|
|
|
use beacon_chain::{block_production::Error as BlockProductionError, BeaconChain};
|
|
|
|
use block_producer::{DutiesReader, DutiesReaderError};
|
|
|
|
use db::ClientDB;
|
|
|
|
use slot_clock::SlotClock;
|
2019-01-25 00:30:06 +00:00
|
|
|
use std::sync::Arc;
|
2019-01-24 06:05:48 +00:00
|
|
|
use types::PublicKey;
|
|
|
|
|
2019-01-25 00:30:06 +00:00
|
|
|
pub struct DirectDuties<T: ClientDB, U: SlotClock> {
|
|
|
|
beacon_chain: Arc<BeaconChain<T, U>>,
|
2019-01-24 06:05:48 +00:00
|
|
|
pubkey: PublicKey,
|
|
|
|
}
|
|
|
|
|
2019-01-25 00:30:06 +00:00
|
|
|
impl<T: ClientDB, U: SlotClock> DirectDuties<T, U> {
|
|
|
|
pub fn new(pubkey: PublicKey, beacon_chain: Arc<BeaconChain<T, U>>) -> Self {
|
2019-01-24 06:05:48 +00:00
|
|
|
Self {
|
|
|
|
beacon_chain,
|
|
|
|
pubkey,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 00:30:06 +00:00
|
|
|
impl<T: ClientDB, U: SlotClock> DutiesReader for DirectDuties<T, U>
|
2019-01-24 06:05:48 +00:00
|
|
|
where
|
|
|
|
BlockProductionError: From<<U>::Error>,
|
|
|
|
{
|
2019-01-25 00:30:06 +00:00
|
|
|
fn is_block_production_slot(&self, slot: u64) -> Result<bool, DutiesReaderError> {
|
2019-01-24 06:05:48 +00:00
|
|
|
let validator_index = self
|
|
|
|
.beacon_chain
|
|
|
|
.validator_index(&self.pubkey)
|
|
|
|
.ok_or_else(|| DutiesReaderError::UnknownValidator)?;
|
|
|
|
|
|
|
|
match self.beacon_chain.block_proposer(slot) {
|
|
|
|
Some(proposer) if proposer == validator_index => Ok(true),
|
|
|
|
Some(_) => Ok(false),
|
|
|
|
None => Err(DutiesReaderError::UnknownEpoch),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|