From be592c86d11fcd6cc0b80e0939d657355ac512b3 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Fri, 29 Mar 2019 10:39:37 +1100 Subject: [PATCH] Started migrating FreeAttestation to Attestation in the harnesses - doesn't compile yet. --- .../test_harness/src/beacon_chain_harness.rs | 12 ++++++------ .../src/validator_harness/direct_beacon_node.rs | 14 +++++++------- .../test_harness/src/validator_harness/mod.rs | 14 ++------------ 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs index 942497476..9f6643c7d 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs @@ -137,11 +137,11 @@ impl BeaconChainHarness { slot } - /// Gather the `FreeAttestation`s from the valiators. + /// Gather the `Attestation`s from the valiators. /// /// Note: validators will only produce attestations _once per slot_. So, if you call this twice /// you'll only get attestations on the first run. - pub fn gather_free_attesations(&mut self) -> Vec { + pub fn gather_attesations(&mut self) -> Vec { let present_slot = self.beacon_chain.present_slot(); let attesting_validators = self @@ -158,7 +158,7 @@ impl BeaconChainHarness { let attesting_validators: HashSet = HashSet::from_iter(attesting_validators.iter().cloned()); - let free_attestations: Vec = self + let attestations: Vec = self .validators .par_iter_mut() .enumerate() @@ -176,8 +176,8 @@ impl BeaconChainHarness { .collect(); debug!( - "Gathered {} FreeAttestations for slot {}.", - free_attestations.len(), + "Gathered {} Attestations for slot {}.", + attestations.len(), present_slot ); @@ -232,7 +232,7 @@ impl BeaconChainHarness { .unwrap(); }); - debug!("Free attestations processed."); + debug!("attestations processed."); block } diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs index 17630833b..7fc0376c8 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs @@ -12,7 +12,7 @@ use fork_choice::ForkChoice; use parking_lot::RwLock; use slot_clock::SlotClock; use std::sync::Arc; -use types::{AttestationData, BeaconBlock, FreeAttestation, Signature, Slot}; +use types::{AttestationData, BeaconBlock, Attestation, Signature, Slot}; // mod attester; // mod producer; @@ -20,13 +20,13 @@ use types::{AttestationData, BeaconBlock, FreeAttestation, Signature, Slot}; /// Connect directly to a borrowed `BeaconChain` instance so an attester/producer can request/submit /// blocks/attestations. /// -/// `BeaconBlock`s and `FreeAttestation`s are not actually published to the `BeaconChain`, instead +/// `BeaconBlock`s and `Attestation`s are not actually published to the `BeaconChain`, instead /// they are stored inside this struct. This is to allow one to benchmark the submission of the /// block/attestation directly, or modify it before submission. pub struct DirectBeaconNode { beacon_chain: Arc>, published_blocks: RwLock>, - published_attestations: RwLock>, + published_attestations: RwLock>, } impl DirectBeaconNode { @@ -44,7 +44,7 @@ impl DirectBeaconNode { } /// Get the last published attestation (if any). - pub fn last_published_free_attestation(&self) -> Option { + pub fn last_published_free_attestation(&self) -> Option { Some(self.published_attestations.read().last()?.clone()) } } @@ -55,7 +55,7 @@ impl AttesterBeaconNode for DirectBeac _slot: Slot, shard: u64, ) -> Result, NodeError> { - match self.beacon_chain.produce_attestation(shard) { + match self.beacon_chain.produce_attestation_data(shard) { Ok(attestation_data) => Ok(Some(attestation_data)), Err(e) => Err(NodeError::RemoteFailure(format!("{:?}", e))), } @@ -63,9 +63,9 @@ impl AttesterBeaconNode for DirectBeac fn publish_attestation( &self, - free_attestation: FreeAttestation, + attestation: Attestation, ) -> Result { - self.published_attestations.write().push(free_attestation); + self.published_attestations.write().push(attestation); Ok(AttestationPublishOutcome::ValidAttestation) } } diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs index 43ad03ea7..60258c794 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs @@ -2,7 +2,7 @@ mod direct_beacon_node; mod direct_duties; mod local_signer; -use crate::direct_beacon_node::DirectBeaconNode; +use crate::validator_harness::direct_beacon_node::DirectBeaconNode; use attester::PollOutcome as AttestationPollOutcome; use attester::{Attester, Error as AttestationPollError}; use beacon_chain::BeaconChain; @@ -44,10 +44,8 @@ pub struct ValidatorHarness { pub block_producer: TestingBlockProducer, pub attester: TestingAttester, pub spec: Arc, - pub epoch_map: Arc>>, pub keypair: Keypair, pub beacon_node: Arc>>, - pub slot_clock: Arc, pub signer: Arc, } @@ -61,22 +59,16 @@ impl ValidatorHarness { beacon_chain: Arc>>, spec: Arc, ) -> Self { - let slot_clock = Arc::new(TestingSlotClock::new(spec.genesis_slot.as_u64())); let signer = Arc::new(LocalSigner::new(keypair.clone())); let beacon_node = Arc::new(DirectBeaconNode::new(beacon_chain.clone())); - let epoch_map = Arc::new(DirectDuties::new(keypair.pk.clone(), beacon_chain.clone())); let block_producer = BlockProducer::new( spec.clone(), - epoch_map.clone(), - slot_clock.clone(), beacon_node.clone(), signer.clone(), ); let attester = Attester::new( - epoch_map.clone(), - slot_clock.clone(), beacon_node.clone(), signer.clone(), ); @@ -85,10 +77,8 @@ impl ValidatorHarness { block_producer, attester, spec, - epoch_map, keypair, beacon_node, - slot_clock, signer, } } @@ -113,7 +103,7 @@ impl ValidatorHarness { /// Run the `poll` function on the `Attester` and produce a `FreeAttestation`. /// /// An error is returned if the attester refuses to attest. - pub fn produce_free_attestation(&mut self) -> Result { + pub fn produce_attestation(&mut self) -> Result { match self.attester.poll() { Ok(AttestationPollOutcome::AttestationProduced(_)) => {} Ok(outcome) => return Err(AttestationProduceError::DidNotProduce(outcome)),