Referenced signer passed to block producer

This commit is contained in:
Age Manning 2019-03-30 14:48:43 +11:00
parent deb0abd4a8
commit ba90901730
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
3 changed files with 16 additions and 15 deletions

View File

@ -10,11 +10,6 @@ use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
#[derive(Debug, PartialEq)]
pub enum Error {
SlotClockError,
SlotUnknowable,
EpochMapPoisoned,
SlotClockPoisoned,
EpochLengthIsZero,
BeaconBlockNodeError(BeaconBlockNodeError),
}
@ -34,7 +29,7 @@ pub enum ValidatorEvent {
/// This struct contains the logic for requesting and signing beacon blocks for a validator. The
/// validator can abstractly sign via the Signer trait object.
pub struct BlockProducer<B: BeaconBlockNode, S: Signer> {
pub struct BlockProducer<'a, B: BeaconBlockNode, S: Signer> {
/// The current fork.
pub fork: Fork,
/// The current slot to produce a block for.
@ -44,10 +39,10 @@ pub struct BlockProducer<B: BeaconBlockNode, S: Signer> {
/// The beacon node to connect to.
pub beacon_node: Arc<B>,
/// The signer to sign the block.
pub signer: Arc<S>,
pub signer: &'a S,
}
impl<B: BeaconBlockNode, S: Signer> BlockProducer<B, S> {
impl<'a, B: BeaconBlockNode, S: Signer> BlockProducer<'a, B, S> {
/// Produce a block at some slot.
///
/// Assumes that a block is required at this slot (does not check the duties).

View File

@ -299,17 +299,23 @@ impl<B: BeaconNodeDuties + 'static, S: Signer + 'static> Service<B, S> {
/// If there are any duties to process, spawn a separate thread and perform required actions.
fn process_duties(&mut self) {
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
for (_public_key, work_type) in work {
for (signer_index, work_type) in work {
if work_type.produce_block {
// spawns a thread to produce a beacon block
let signers = self.duties_manager.signers.clone();
let fork = self.fork.clone();
let slot = self.current_slot.clone();
let spec = self.spec.clone();
let beacon_node = self.beacon_block_client.clone();
std::thread::spawn(move || {
/*
let signer = &signers[signer_index];
let block_producer = BlockProducer {
fork: self.fork,
slot: self.current_slot,
spec: self.spec.clone(),
fork,
slot,
spec,
beacon_node,
signer,
};
*/
});
// TODO: Produce a beacon block in a new thread

View File

@ -2,7 +2,7 @@ use std::fmt::Display;
use types::{Keypair, PublicKey, Signature};
/// Signs message using an internally-maintained private key.
pub trait Signer: Display + Send + Sync {
pub trait Signer: Display + Send + Sync + Clone {
fn sign_block_proposal(&self, message: &[u8], domain: u64) -> Option<Signature>;
fn sign_randao_reveal(&self, message: &[u8], domain: u64) -> Option<Signature>;
/// Returns a public key for the signer object.