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
|
//its public keys
|
||||||
service ValidatorService {
|
service ValidatorService {
|
||||||
rpc ProposeBlockSlot(ProposeBlockSlotRequest) returns (ProposeBlockSlotResponse);
|
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);
|
// rpc ValidatorAssignment(ValidatorAssignmentRequest) returns (ValidatorAssignmentResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,12 +111,12 @@ message ValidatorAssignment {
|
|||||||
|
|
||||||
// Validator Assignment
|
// Validator Assignment
|
||||||
|
|
||||||
message PublicKey {
|
message PublicKeys {
|
||||||
bytes public_key = 1;
|
repeated bytes public_key = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message IndexResponse {
|
message Indicies {
|
||||||
uint64 index = 1;
|
repeated uint64 index = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -123,16 +124,26 @@ message IndexResponse {
|
|||||||
|
|
||||||
message ProposeBlockSlotRequest {
|
message ProposeBlockSlotRequest {
|
||||||
uint64 epoch = 1;
|
uint64 epoch = 1;
|
||||||
uint64 validator_index = 2;
|
repeated uint64 validator_index = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ProposeBlockSlotResponse {
|
message GetDutiesResponse {
|
||||||
oneof slot_oneof {
|
repeated oneof slot_oneof {
|
||||||
bool none = 1;
|
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
|
* Attestation Service Messages
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::traits::{BeaconNode, BeaconNodeError};
|
use super::traits::{BeaconNode, BeaconNodeError};
|
||||||
use super::EpochDuties;
|
use super::EpochDuties;
|
||||||
use protos::services::{ProposeBlockSlotRequest, PublicKey as IndexRequest};
|
use protos::services::{ProposeBlockSlotRequest, PublicKeys as IndexRequest};
|
||||||
use protos::services_grpc::ValidatorServiceClient;
|
use protos::services_grpc::ValidatorServiceClient;
|
||||||
use ssz::ssz_encode;
|
use ssz::ssz_encode;
|
||||||
use types::{Epoch, PublicKey, Slot};
|
use types::{Epoch, PublicKey, Slot};
|
||||||
@ -15,12 +15,14 @@ impl BeaconNode for ValidatorServiceClient {
|
|||||||
fn request_shuffling(
|
fn request_shuffling(
|
||||||
&self,
|
&self,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
public_key: &PublicKey,
|
pubkeys: &[PublicKey],
|
||||||
) -> Result<Option<EpochDuties>, BeaconNodeError> {
|
) -> Result<Option<EpochDuties>, BeaconNodeError> {
|
||||||
// Lookup the validator index for the supplied public key.
|
// Lookup the validator indexes for all the supplied public keys.
|
||||||
let validator_index = {
|
let validator_indices = {
|
||||||
let mut req = IndexRequest::new();
|
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
|
let resp = self
|
||||||
.validator_index(&req)
|
.validator_index(&req)
|
||||||
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
.map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?;
|
||||||
|
@ -10,9 +10,8 @@ use self::traits::{BeaconNode, BeaconNodeError};
|
|||||||
use bls::PublicKey;
|
use bls::PublicKey;
|
||||||
use futures::Async;
|
use futures::Async;
|
||||||
use slog::{debug, error, info};
|
use slog::{debug, error, info};
|
||||||
use slot_clock::SlotClock;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{ChainSpec, Epoch, Slot};
|
use types::{Epoch, Slot};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum UpdateOutcome {
|
pub enum UpdateOutcome {
|
||||||
@ -30,8 +29,6 @@ pub enum UpdateOutcome {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
SlotClockError,
|
|
||||||
SlotUnknowable,
|
|
||||||
EpochMapPoisoned,
|
EpochMapPoisoned,
|
||||||
BeaconNodeError(BeaconNodeError),
|
BeaconNodeError(BeaconNodeError),
|
||||||
}
|
}
|
||||||
@ -40,27 +37,23 @@ pub enum Error {
|
|||||||
/// Node.
|
/// Node.
|
||||||
///
|
///
|
||||||
/// This keeps track of all validator keys and required voting slots.
|
/// 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>,
|
pub duties_map: Arc<EpochDutiesMap>,
|
||||||
/// A list of all public keys known to the validator service.
|
/// A list of all public keys known to the validator service.
|
||||||
pub pubkeys: Vec<PublicKey>,
|
pub pubkeys: Vec<PublicKey>,
|
||||||
pub spec: Arc<ChainSpec>,
|
pub slots_per_epoch: u64,
|
||||||
pub slot_clock: Arc<T>,
|
|
||||||
pub beacon_node: Arc<U>,
|
pub beacon_node: Arc<U>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SlotClock, U: BeaconNode> DutiesManager<T, U> {
|
impl<U: BeaconNode> DutiesManager<U> {
|
||||||
/// Check the Beacon Node for `EpochDuties`.
|
/// Check the Beacon Node for `EpochDuties`.
|
||||||
///
|
///
|
||||||
/// The present `epoch` will be learned from the supplied `SlotClock`. In production this will
|
/// 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.).
|
/// be a wall-clock (e.g., system time, remote server time, etc.).
|
||||||
fn update(&self, slot: Slot) -> Result<UpdateOutcome, Error> {
|
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
|
if let Some(duties) = self.beacon_node.request_shuffling(epoch, &self.pubkeys)? {
|
||||||
.beacon_node
|
|
||||||
.request_shuffling(epoch, &self.pubkeys[0])?
|
|
||||||
{
|
|
||||||
// If these duties were known, check to see if they're updates or identical.
|
// 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)? {
|
let result = if let Some(known_duties) = self.duties_map.get(epoch)? {
|
||||||
if known_duties == duties {
|
if known_duties == duties {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use super::EpochDuties;
|
use super::EpochDuties;
|
||||||
use bls::PublicKey;
|
use types::{Epoch, PublicKey};
|
||||||
use types::Epoch;
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum BeaconNodeError {
|
pub enum BeaconNodeError {
|
||||||
@ -15,6 +14,6 @@ pub trait BeaconNode: Send + Sync {
|
|||||||
fn request_shuffling(
|
fn request_shuffling(
|
||||||
&self,
|
&self,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
public_key: &PublicKey,
|
pubkeys: &[PublicKey],
|
||||||
) -> Result<Option<EpochDuties>, BeaconNodeError>;
|
) -> Result<Option<EpochDuties>, BeaconNodeError>;
|
||||||
}
|
}
|
||||||
|
@ -222,11 +222,11 @@ impl Service {
|
|||||||
// build requisite objects to pass to core thread.
|
// build requisite objects to pass to core thread.
|
||||||
let duties_map = Arc::new(EpochDutiesMap::new(config.spec.slots_per_epoch));
|
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 epoch_map_for_attester = Arc::new(EpochMap::new(config.spec.slots_per_epoch));
|
||||||
|
|
||||||
let manager = Arc::new(DutiesManager {
|
let manager = Arc::new(DutiesManager {
|
||||||
duties_map,
|
duties_map,
|
||||||
pubkeys: keypairs.iter().map(|keypair| keypair.pk.clone()).collect(),
|
pubkeys: keypairs.iter().map(|keypair| keypair.pk.clone()).collect(),
|
||||||
spec: Arc::new(config.spec),
|
slots_per_epoch: config.spec.slots_per_epoch.clone(),
|
||||||
slot_clock: service.slot_clock.clone(),
|
|
||||||
beacon_node: service.validator_client.clone(),
|
beacon_node: service.validator_client.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -234,6 +234,7 @@ impl Service {
|
|||||||
runtime
|
runtime
|
||||||
.block_on(interval.for_each(move |_| {
|
.block_on(interval.for_each(move |_| {
|
||||||
let log = service.log.clone();
|
let log = service.log.clone();
|
||||||
|
|
||||||
// get the current slot
|
// get the current slot
|
||||||
let current_slot = match service.slot_clock.present_slot() {
|
let current_slot = match service.slot_clock.present_slot() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -250,24 +251,24 @@ impl Service {
|
|||||||
|
|
||||||
info!(log, "Processing slot: {}", current_slot.as_u64());
|
info!(log, "Processing slot: {}", current_slot.as_u64());
|
||||||
|
|
||||||
let cloned_manager = manager.clone();
|
|
||||||
|
|
||||||
// check for new duties
|
// check for new duties
|
||||||
|
let cloned_manager = manager.clone();
|
||||||
tokio::spawn(futures::future::poll_fn(move || {
|
tokio::spawn(futures::future::poll_fn(move || {
|
||||||
cloned_manager.run_update(current_slot.clone(), log.clone())
|
cloned_manager.run_update(current_slot.clone(), log.clone())
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// execute any specified duties
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}))
|
}))
|
||||||
.map_err(|e| format!("Service thread failed: {:?}", e))?;
|
.map_err(|e| format!("Service thread failed: {:?}", e))?;
|
||||||
|
|
||||||
|
// completed a slot process
|
||||||
Ok(())
|
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 {
|
for keypair in keypairs {
|
||||||
info!(self.log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
info!(self.log, "Starting validator services"; "validator" => keypair.pk.concatenated_hex_id());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user