Temp commit - Re-building validator RPC API
This commit is contained in:
parent
6955330f6c
commit
7c31c052f3
@ -27,7 +27,8 @@ service BeaconBlockService {
|
||||
//its public keys
|
||||
service ValidatorService {
|
||||
rpc ProposeBlockSlot(ProposeBlockSlotRequest) returns (ProposeBlockSlotResponse);
|
||||
rpc ValidatorIndex(PublicKey) returns (IndexResponse);
|
||||
/// Given a set of public keys, returns their respective indicies
|
||||
rpc ValidatorIndex(PublicKeys) returns (Indicies);
|
||||
// rpc ValidatorAssignment(ValidatorAssignmentRequest) returns (ValidatorAssignmentResponse);
|
||||
}
|
||||
|
||||
@ -110,12 +111,12 @@ message ValidatorAssignment {
|
||||
|
||||
// Validator Assignment
|
||||
|
||||
message PublicKey {
|
||||
bytes public_key = 1;
|
||||
message PublicKeys {
|
||||
repeated bytes public_key = 1;
|
||||
}
|
||||
|
||||
message IndexResponse {
|
||||
uint64 index = 1;
|
||||
message Indicies {
|
||||
repeated uint64 index = 1;
|
||||
}
|
||||
|
||||
|
||||
@ -123,16 +124,26 @@ message IndexResponse {
|
||||
|
||||
message ProposeBlockSlotRequest {
|
||||
uint64 epoch = 1;
|
||||
uint64 validator_index = 2;
|
||||
repeated uint64 validator_index = 2;
|
||||
}
|
||||
|
||||
message ProposeBlockSlotResponse {
|
||||
oneof slot_oneof {
|
||||
message GetDutiesResponse {
|
||||
repeated oneof slot_oneof {
|
||||
bool none = 1;
|
||||
uint64 slot = 2;
|
||||
ValidatorDuty duty = 2;
|
||||
}
|
||||
}
|
||||
|
||||
ValidatorDuty {
|
||||
oneof block_oneof {
|
||||
bool none = 1;
|
||||
uint64 block_produce_slot = 2;
|
||||
}
|
||||
uint64 committee_slot = 1;
|
||||
uint64 committee_shard = 2;
|
||||
uint64 committee_index = 3;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Attestation Service Messages
|
||||
|
@ -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>;
|
||||
}
|
||||
|
@ -222,11 +222,11 @@ impl Service {
|
||||
// build requisite objects to pass to core thread.
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(config.spec.slots_per_epoch));
|
||||
let epoch_map_for_attester = Arc::new(EpochMap::new(config.spec.slots_per_epoch));
|
||||
|
||||
let manager = Arc::new(DutiesManager {
|
||||
duties_map,
|
||||
pubkeys: keypairs.iter().map(|keypair| keypair.pk.clone()).collect(),
|
||||
spec: Arc::new(config.spec),
|
||||
slot_clock: service.slot_clock.clone(),
|
||||
slots_per_epoch: config.spec.slots_per_epoch.clone(),
|
||||
beacon_node: service.validator_client.clone(),
|
||||
});
|
||||
|
||||
@ -234,6 +234,7 @@ impl Service {
|
||||
runtime
|
||||
.block_on(interval.for_each(move |_| {
|
||||
let log = service.log.clone();
|
||||
|
||||
// get the current slot
|
||||
let current_slot = match service.slot_clock.present_slot() {
|
||||
Err(e) => {
|
||||
@ -250,24 +251,24 @@ impl Service {
|
||||
|
||||
info!(log, "Processing slot: {}", current_slot.as_u64());
|
||||
|
||||
let cloned_manager = manager.clone();
|
||||
|
||||
// check for new duties
|
||||
let cloned_manager = manager.clone();
|
||||
tokio::spawn(futures::future::poll_fn(move || {
|
||||
cloned_manager.run_update(current_slot.clone(), log.clone())
|
||||
}));
|
||||
|
||||
// execute any specified duties
|
||||
|
||||
Ok(())
|
||||
}))
|
||||
.map_err(|e| format!("Service thread failed: {:?}", e))?;
|
||||
|
||||
// completed a slot process
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
let duties_map = Arc::new(EpochDutiesMap::new(spec.slots_per_epoch));
|
||||
let epoch_map_for_attester = Arc::new(EpochMap::new(spec.slots_per_epoch));
|
||||
|
||||
|
||||
for keypair in keypairs {
|
||||
info!(self.log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user