mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 21:34:46 +00:00
Temp commit - Re-building validator RPC API
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::traits::{BeaconNode, BeaconNodeError};
|
||||
use super::EpochDuties;
|
||||
use protos::services::{ProposeBlockSlotRequest, PublicKey as IndexRequest};
|
||||
use protos::services::{ProposeBlockSlotRequest, PublicKeys as IndexRequest};
|
||||
use protos::services_grpc::ValidatorServiceClient;
|
||||
use ssz::ssz_encode;
|
||||
use types::{Epoch, PublicKey, Slot};
|
||||
@@ -15,12 +15,14 @@ impl BeaconNode for ValidatorServiceClient {
|
||||
fn request_shuffling(
|
||||
&self,
|
||||
epoch: Epoch,
|
||||
public_key: &PublicKey,
|
||||
pubkeys: &[PublicKey],
|
||||
) -> Result<Option<EpochDuties>, BeaconNodeError> {
|
||||
// Lookup the validator index for the supplied public key.
|
||||
let validator_index = {
|
||||
// Lookup the validator indexes for all the supplied public keys.
|
||||
let validator_indices = {
|
||||
let mut req = IndexRequest::new();
|
||||
req.set_public_key(ssz_encode(public_key).to_vec());
|
||||
for public_key in pubkeys {
|
||||
req.mut_public_key().push(ssz_encode(public_key));
|
||||
}
|
||||
let resp = self
|
||||
.validator_index(&req)
|
||||
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
||||
|
||||
@@ -10,9 +10,8 @@ use self::traits::{BeaconNode, BeaconNodeError};
|
||||
use bls::PublicKey;
|
||||
use futures::Async;
|
||||
use slog::{debug, error, info};
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use types::{ChainSpec, Epoch, Slot};
|
||||
use types::{Epoch, Slot};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum UpdateOutcome {
|
||||
@@ -30,8 +29,6 @@ pub enum UpdateOutcome {
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
SlotClockError,
|
||||
SlotUnknowable,
|
||||
EpochMapPoisoned,
|
||||
BeaconNodeError(BeaconNodeError),
|
||||
}
|
||||
@@ -40,27 +37,23 @@ pub enum Error {
|
||||
/// Node.
|
||||
///
|
||||
/// This keeps track of all validator keys and required voting slots.
|
||||
pub struct DutiesManager<T: SlotClock, U: BeaconNode> {
|
||||
pub struct DutiesManager<U: BeaconNode> {
|
||||
pub duties_map: Arc<EpochDutiesMap>,
|
||||
/// A list of all public keys known to the validator service.
|
||||
pub pubkeys: Vec<PublicKey>,
|
||||
pub spec: Arc<ChainSpec>,
|
||||
pub slot_clock: Arc<T>,
|
||||
pub slots_per_epoch: u64,
|
||||
pub beacon_node: Arc<U>,
|
||||
}
|
||||
|
||||
impl<T: SlotClock, U: BeaconNode> DutiesManager<T, U> {
|
||||
impl<U: BeaconNode> DutiesManager<U> {
|
||||
/// Check the Beacon Node for `EpochDuties`.
|
||||
///
|
||||
/// The present `epoch` will be learned from the supplied `SlotClock`. In production this will
|
||||
/// be a wall-clock (e.g., system time, remote server time, etc.).
|
||||
fn update(&self, slot: Slot) -> Result<UpdateOutcome, Error> {
|
||||
let epoch = slot.epoch(self.spec.slots_per_epoch);
|
||||
let epoch = slot.epoch(self.slots_per_epoch);
|
||||
|
||||
if let Some(duties) = self
|
||||
.beacon_node
|
||||
.request_shuffling(epoch, &self.pubkeys[0])?
|
||||
{
|
||||
if let Some(duties) = self.beacon_node.request_shuffling(epoch, &self.pubkeys)? {
|
||||
// If these duties were known, check to see if they're updates or identical.
|
||||
let result = if let Some(known_duties) = self.duties_map.get(epoch)? {
|
||||
if known_duties == duties {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use super::EpochDuties;
|
||||
use bls::PublicKey;
|
||||
use types::Epoch;
|
||||
use types::{Epoch, PublicKey};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum BeaconNodeError {
|
||||
@@ -15,6 +14,6 @@ pub trait BeaconNode: Send + Sync {
|
||||
fn request_shuffling(
|
||||
&self,
|
||||
epoch: Epoch,
|
||||
public_key: &PublicKey,
|
||||
pubkeys: &[PublicKey],
|
||||
) -> Result<Option<EpochDuties>, BeaconNodeError>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user