Referenced signer passed to block producer
This commit is contained in:
parent
deb0abd4a8
commit
ba90901730
@ -10,11 +10,6 @@ use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
SlotClockError,
|
|
||||||
SlotUnknowable,
|
|
||||||
EpochMapPoisoned,
|
|
||||||
SlotClockPoisoned,
|
|
||||||
EpochLengthIsZero,
|
|
||||||
BeaconBlockNodeError(BeaconBlockNodeError),
|
BeaconBlockNodeError(BeaconBlockNodeError),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +29,7 @@ pub enum ValidatorEvent {
|
|||||||
|
|
||||||
/// This struct contains the logic for requesting and signing beacon blocks for a validator. The
|
/// This struct contains the logic for requesting and signing beacon blocks for a validator. The
|
||||||
/// validator can abstractly sign via the Signer trait object.
|
/// 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.
|
/// The current fork.
|
||||||
pub fork: Fork,
|
pub fork: Fork,
|
||||||
/// The current slot to produce a block for.
|
/// 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.
|
/// The beacon node to connect to.
|
||||||
pub beacon_node: Arc<B>,
|
pub beacon_node: Arc<B>,
|
||||||
/// The signer to sign the block.
|
/// 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.
|
/// Produce a block at some slot.
|
||||||
///
|
///
|
||||||
/// Assumes that a block is required at this slot (does not check the duties).
|
/// Assumes that a block is required at this slot (does not check the duties).
|
||||||
|
@ -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.
|
/// If there are any duties to process, spawn a separate thread and perform required actions.
|
||||||
fn process_duties(&mut self) {
|
fn process_duties(&mut self) {
|
||||||
if let Some(work) = self.duties_manager.get_current_work(self.current_slot) {
|
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 {
|
if work_type.produce_block {
|
||||||
// spawns a thread to produce a beacon 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 || {
|
std::thread::spawn(move || {
|
||||||
/*
|
let signer = &signers[signer_index];
|
||||||
let block_producer = BlockProducer {
|
let block_producer = BlockProducer {
|
||||||
fork: self.fork,
|
fork,
|
||||||
slot: self.current_slot,
|
slot,
|
||||||
spec: self.spec.clone(),
|
spec,
|
||||||
|
beacon_node,
|
||||||
|
signer,
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Produce a beacon block in a new thread
|
// TODO: Produce a beacon block in a new thread
|
||||||
|
@ -2,7 +2,7 @@ use std::fmt::Display;
|
|||||||
use types::{Keypair, PublicKey, Signature};
|
use types::{Keypair, PublicKey, Signature};
|
||||||
|
|
||||||
/// Signs message using an internally-maintained private key.
|
/// 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_block_proposal(&self, message: &[u8], domain: u64) -> Option<Signature>;
|
||||||
fn sign_randao_reveal(&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.
|
/// Returns a public key for the signer object.
|
||||||
|
Loading…
Reference in New Issue
Block a user