Ran cargo fmt.
This commit is contained in:
parent
867af4bc6a
commit
87acaac8a0
@ -2,13 +2,13 @@ mod direct_beacon_node;
|
|||||||
mod direct_duties;
|
mod direct_duties;
|
||||||
mod local_signer;
|
mod local_signer;
|
||||||
|
|
||||||
|
use crate::direct_beacon_node::DirectBeaconNode;
|
||||||
use attester::PollOutcome as AttestationPollOutcome;
|
use attester::PollOutcome as AttestationPollOutcome;
|
||||||
use attester::{Attester, Error as AttestationPollError};
|
use attester::{Attester, Error as AttestationPollError};
|
||||||
use beacon_chain::BeaconChain;
|
use beacon_chain::BeaconChain;
|
||||||
use block_proposer::PollOutcome as BlockPollOutcome;
|
use block_proposer::PollOutcome as BlockPollOutcome;
|
||||||
use block_proposer::{BlockProducer, Error as BlockPollError};
|
use block_proposer::{BlockProducer, Error as BlockPollError};
|
||||||
use db::MemoryDB;
|
use db::MemoryDB;
|
||||||
use crate::direct_beacon_node::DirectBeaconNode;
|
|
||||||
use fork_choice::BitwiseLMDGhost;
|
use fork_choice::BitwiseLMDGhost;
|
||||||
use local_signer::LocalSigner;
|
use local_signer::LocalSigner;
|
||||||
use slot_clock::TestingSlotClock;
|
use slot_clock::TestingSlotClock;
|
||||||
@ -32,10 +32,8 @@ type TestingBlockProducer = BlockProducer<
|
|||||||
LocalSigner,
|
LocalSigner,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type TestingAttester = Attester<
|
type TestingAttester =
|
||||||
DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>,
|
Attester<DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>, LocalSigner>;
|
||||||
LocalSigner,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// A `BlockProducer` and `Attester` which sign using a common keypair.
|
/// A `BlockProducer` and `Attester` which sign using a common keypair.
|
||||||
///
|
///
|
||||||
|
@ -3,8 +3,10 @@ mod traits;
|
|||||||
|
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{AttestationData, AttestationDataAndCustodyBit, Attestation, Signature,
|
use types::{
|
||||||
AggregateSignature, Slot, AttestationDuty, Bitfield};
|
AggregateSignature, Attestation, AttestationData, AttestationDataAndCustodyBit,
|
||||||
|
AttestationDuty, Bitfield, Signature, Slot,
|
||||||
|
};
|
||||||
|
|
||||||
pub use self::traits::{
|
pub use self::traits::{
|
||||||
BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer,
|
BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer,
|
||||||
@ -59,20 +61,28 @@ impl<U: BeaconNode, W: Signer> Attester<U, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<B: BeaconNode, W: Signer> Attester<B, W> {
|
impl<B: BeaconNode, W: Signer> Attester<B, W> {
|
||||||
|
fn produce_attestation(
|
||||||
fn produce_attestation(&mut self, attestation_duty: AttestationDuty) -> Result<PollOutcome, Error> {
|
&mut self,
|
||||||
let attestation_data = match self.beacon_node.produce_attestation_data(
|
attestation_duty: AttestationDuty,
|
||||||
attestation_duty.slot,
|
) -> Result<PollOutcome, Error> {
|
||||||
attestation_duty.shard
|
let attestation_data = match self
|
||||||
)? {
|
.beacon_node
|
||||||
|
.produce_attestation_data(attestation_duty.slot, attestation_duty.shard)?
|
||||||
|
{
|
||||||
Some(attestation_data) => attestation_data,
|
Some(attestation_data) => attestation_data,
|
||||||
None => return Ok(PollOutcome::BeaconNodeUnableToProduceAttestation(attestation_duty.slot)),
|
None => {
|
||||||
|
return Ok(PollOutcome::BeaconNodeUnableToProduceAttestation(
|
||||||
|
attestation_duty.slot,
|
||||||
|
))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
dbg!(&attestation_data);
|
dbg!(&attestation_data);
|
||||||
|
|
||||||
if !self.safe_to_produce(&attestation_data) {
|
if !self.safe_to_produce(&attestation_data) {
|
||||||
return Ok(PollOutcome::SlashableAttestationNotProduced(attestation_duty.slot));
|
return Ok(PollOutcome::SlashableAttestationNotProduced(
|
||||||
|
attestation_duty.slot,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let signature = match self.sign_attestation_data(&attestation_data) {
|
let signature = match self.sign_attestation_data(&attestation_data) {
|
||||||
@ -82,7 +92,6 @@ impl<B: BeaconNode, W: Signer> Attester<B, W> {
|
|||||||
let mut agg_sig = AggregateSignature::new();
|
let mut agg_sig = AggregateSignature::new();
|
||||||
agg_sig.add(&signature);
|
agg_sig.add(&signature);
|
||||||
|
|
||||||
|
|
||||||
let attestation = Attestation {
|
let attestation = Attestation {
|
||||||
aggregation_bitfield: Bitfield::new(),
|
aggregation_bitfield: Bitfield::new(),
|
||||||
data: attestation_data,
|
data: attestation_data,
|
||||||
@ -172,10 +181,7 @@ mod tests {
|
|||||||
let attest_epoch = attest_slot / spec.slots_per_epoch;
|
let attest_epoch = attest_slot / spec.slots_per_epoch;
|
||||||
let attest_shard = 12;
|
let attest_shard = 12;
|
||||||
|
|
||||||
let mut attester = Attester::new(
|
let mut attester = Attester::new(beacon_node.clone(), signer.clone());
|
||||||
beacon_node.clone(),
|
|
||||||
signer.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Configure responses from the BeaconNode.
|
// Configure responses from the BeaconNode.
|
||||||
beacon_node.set_next_produce_result(Ok(Some(AttestationData::random_for_test(&mut rng))));
|
beacon_node.set_next_produce_result(Ok(Some(AttestationData::random_for_test(&mut rng))));
|
||||||
@ -220,6 +226,5 @@ mod tests {
|
|||||||
Ok(PollOutcome::ProducerDutiesUnknown(slot))
|
Ok(PollOutcome::ProducerDutiesUnknown(slot))
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::traits::{BeaconNode, BeaconNodeError, PublishOutcome};
|
use crate::traits::{BeaconNode, BeaconNodeError, PublishOutcome};
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
use types::{AttestationData, Attestation, Slot};
|
use types::{Attestation, AttestationData, Slot};
|
||||||
|
|
||||||
type ProduceResult = Result<Option<AttestationData>, BeaconNodeError>;
|
type ProduceResult = Result<Option<AttestationData>, BeaconNodeError>;
|
||||||
type PublishResult = Result<PublishOutcome, BeaconNodeError>;
|
type PublishResult = Result<PublishOutcome, BeaconNodeError>;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use types::{AttestationData, Attestation, Signature, Slot};
|
use types::{Attestation, AttestationData, Signature, Slot};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum BeaconNodeError {
|
pub enum BeaconNodeError {
|
||||||
|
@ -4,7 +4,7 @@ mod traits;
|
|||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use ssz::{SignedRoot, TreeHash};
|
use ssz::{SignedRoot, TreeHash};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{BeaconBlock, ChainSpec, Domain, Slot, Fork};
|
use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
|
||||||
|
|
||||||
pub use self::traits::{
|
pub use self::traits::{
|
||||||
BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer,
|
BeaconNode, BeaconNodeError, DutiesReader, DutiesReaderError, PublishOutcome, Signer,
|
||||||
@ -57,11 +57,7 @@ pub struct BlockProducer<U: BeaconNode, W: Signer> {
|
|||||||
|
|
||||||
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
||||||
/// Returns a new instance where `last_processed_slot == 0`.
|
/// Returns a new instance where `last_processed_slot == 0`.
|
||||||
pub fn new(
|
pub fn new(spec: Arc<ChainSpec>, beacon_node: Arc<U>, signer: Arc<W>) -> Self {
|
||||||
spec: Arc<ChainSpec>,
|
|
||||||
beacon_node: Arc<U>,
|
|
||||||
signer: Arc<W>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
last_processed_slot: None,
|
last_processed_slot: None,
|
||||||
spec,
|
spec,
|
||||||
@ -72,7 +68,6 @@ impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
||||||
|
|
||||||
/* No longer needed because we don't poll any more
|
/* No longer needed because we don't poll any more
|
||||||
/// "Poll" to see if the validator is required to take any action.
|
/// "Poll" to see if the validator is required to take any action.
|
||||||
///
|
///
|
||||||
@ -129,7 +124,6 @@ impl<U: BeaconNode, W: Signer> BlockProducer<U, W> {
|
|||||||
/// The slash-protection code is not yet implemented. There is zero protection against
|
/// The slash-protection code is not yet implemented. There is zero protection against
|
||||||
/// slashing.
|
/// slashing.
|
||||||
fn produce_block(&mut self, slot: Slot, fork: Fork) -> Result<PollOutcome, Error> {
|
fn produce_block(&mut self, slot: Slot, fork: Fork) -> Result<PollOutcome, Error> {
|
||||||
|
|
||||||
let randao_reveal = {
|
let randao_reveal = {
|
||||||
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
|
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
|
||||||
let message = slot.epoch(self.spec.slots_per_epoch).hash_tree_root();
|
let message = slot.epoch(self.spec.slots_per_epoch).hash_tree_root();
|
||||||
@ -238,12 +232,8 @@ mod tests {
|
|||||||
let beacon_node = Arc::new(SimulatedBeaconNode::default());
|
let beacon_node = Arc::new(SimulatedBeaconNode::default());
|
||||||
let signer = Arc::new(LocalSigner::new(Keypair::random()));
|
let signer = Arc::new(LocalSigner::new(Keypair::random()));
|
||||||
|
|
||||||
|
let mut block_proposer =
|
||||||
let mut block_proposer = BlockProducer::new(
|
BlockProducer::new(spec.clone(), beacon_node.clone(), signer.clone());
|
||||||
spec.clone(),
|
|
||||||
beacon_node.clone(),
|
|
||||||
signer.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Configure responses from the BeaconNode.
|
// Configure responses from the BeaconNode.
|
||||||
beacon_node.set_next_produce_result(Ok(Some(BeaconBlock::random_for_test(&mut rng))));
|
beacon_node.set_next_produce_result(Ok(Some(BeaconBlock::random_for_test(&mut rng))));
|
||||||
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
|
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
|
||||||
use protos::services::ProduceAttestationDataRequest;
|
use protos::services::ProduceAttestationDataRequest;
|
||||||
use types::{AttestationData, Attestation, Slot};
|
use types::{Attestation, AttestationData, Slot};
|
||||||
|
|
||||||
pub struct AttestationGrpcClient {
|
pub struct AttestationGrpcClient {
|
||||||
client: Arc<AttestationServiceClient>,
|
client: Arc<AttestationServiceClient>,
|
||||||
|
@ -44,7 +44,7 @@ impl EpochDuty {
|
|||||||
slot,
|
slot,
|
||||||
shard: self.attestation_shard,
|
shard: self.attestation_shard,
|
||||||
committee_index: self.committee_index as usize,
|
committee_index: self.committee_index as usize,
|
||||||
validator_index: self.validator_index as usize
|
validator_index: self.validator_index as usize,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ impl<U: BeaconNode> DutiesManager<U> {
|
|||||||
Ok(Some(work_type)) => current_work.push((validator_signer.clone(), work_type)),
|
Ok(Some(work_type)) => current_work.push((validator_signer.clone(), work_type)),
|
||||||
Ok(None) => {} // No work for this validator
|
Ok(None) => {} // No work for this validator
|
||||||
//TODO: This should really log an error, as we shouldn't end up with an err here.
|
//TODO: This should really log an error, as we shouldn't end up with an err here.
|
||||||
Err(_) => {} // Unknown epoch or validator, no work
|
Err(_) => {} // Unknown epoch or validator, no work
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if current_work.is_empty() {
|
if current_work.is_empty() {
|
||||||
|
@ -20,6 +20,7 @@ use slog::{debug, error, info, warn};
|
|||||||
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
use slot_clock::{SlotClock, SystemTimeSlotClock};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
use std::thread;
|
||||||
use std::time::{Duration, Instant, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
use tokio::runtime::Builder;
|
use tokio::runtime::Builder;
|
||||||
@ -27,7 +28,6 @@ use tokio::timer::Interval;
|
|||||||
use tokio_timer::clock::Clock;
|
use tokio_timer::clock::Clock;
|
||||||
use types::test_utils::generate_deterministic_keypairs;
|
use types::test_utils::generate_deterministic_keypairs;
|
||||||
use types::{Epoch, Fork, Slot};
|
use types::{Epoch, Fork, Slot};
|
||||||
use std::thread;
|
|
||||||
|
|
||||||
//TODO: This service should be simplified in the future. Can be made more steamlined.
|
//TODO: This service should be simplified in the future. Can be made more steamlined.
|
||||||
|
|
||||||
@ -268,17 +268,11 @@ impl Service {
|
|||||||
// available AttestationDuty info
|
// available AttestationDuty info
|
||||||
let attestation_duty =
|
let attestation_duty =
|
||||||
work_type.attestation_duty.expect("Cannot be None");
|
work_type.attestation_duty.expect("Cannot be None");
|
||||||
let attester_grpc_client =
|
let attester_grpc_client = Arc::new(AttestationGrpcClient::new(
|
||||||
Arc::new(
|
service.attester_client.clone(),
|
||||||
AttestationGrpcClient::new(
|
));
|
||||||
service.attester_client.clone()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
let signer = Arc::new(AttesterLocalSigner::new(keypair.clone()));
|
let signer = Arc::new(AttesterLocalSigner::new(keypair.clone()));
|
||||||
let attester =
|
let attester = Attester::new(attester_grpc_client, signer);
|
||||||
Attester::new(
|
|
||||||
attester_grpc_client,
|
|
||||||
signer);
|
|
||||||
let mut attester_service = AttesterService {
|
let mut attester_service = AttesterService {
|
||||||
attester,
|
attester,
|
||||||
poll_interval_millis: POLL_INTERVAL_MILLIS,
|
poll_interval_millis: POLL_INTERVAL_MILLIS,
|
||||||
|
Loading…
Reference in New Issue
Block a user