Started migrating FreeAttestation to Attestation in the harnesses - doesn't compile yet.

This commit is contained in:
Luke Anderson 2019-03-29 10:39:37 +11:00
parent 6c8abd8990
commit be592c86d1
No known key found for this signature in database
GPG Key ID: 44408169EC61E228
3 changed files with 15 additions and 25 deletions

View File

@ -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<FreeAttestation> {
pub fn gather_attesations(&mut self) -> Vec<Attestation> {
let present_slot = self.beacon_chain.present_slot();
let attesting_validators = self
@ -158,7 +158,7 @@ impl BeaconChainHarness {
let attesting_validators: HashSet<usize> =
HashSet::from_iter(attesting_validators.iter().cloned());
let free_attestations: Vec<FreeAttestation> = self
let attestations: Vec<Attestation> = 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
}

View File

@ -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<T: ClientDB, U: SlotClock, F: ForkChoice> {
beacon_chain: Arc<BeaconChain<T, U, F>>,
published_blocks: RwLock<Vec<BeaconBlock>>,
published_attestations: RwLock<Vec<FreeAttestation>>,
published_attestations: RwLock<Vec<Attestation>>,
}
impl<T: ClientDB, U: SlotClock, F: ForkChoice> DirectBeaconNode<T, U, F> {
@ -44,7 +44,7 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> DirectBeaconNode<T, U, F> {
}
/// Get the last published attestation (if any).
pub fn last_published_free_attestation(&self) -> Option<FreeAttestation> {
pub fn last_published_free_attestation(&self) -> Option<Attestation> {
Some(self.published_attestations.read().last()?.clone())
}
}
@ -55,7 +55,7 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeac
_slot: Slot,
shard: u64,
) -> Result<Option<AttestationData>, 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<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeac
fn publish_attestation(
&self,
free_attestation: FreeAttestation,
attestation: Attestation,
) -> Result<AttestationPublishOutcome, NodeError> {
self.published_attestations.write().push(free_attestation);
self.published_attestations.write().push(attestation);
Ok(AttestationPublishOutcome::ValidAttestation)
}
}

View File

@ -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<ChainSpec>,
pub epoch_map: Arc<DirectDuties<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
pub keypair: Keypair,
pub beacon_node: Arc<DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
pub slot_clock: Arc<TestingSlotClock>,
pub signer: Arc<LocalSigner>,
}
@ -61,22 +59,16 @@ impl ValidatorHarness {
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
spec: Arc<ChainSpec>,
) -> 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<FreeAttestation, AttestationProduceError> {
pub fn produce_attestation(&mut self) -> Result<Attestation, AttestationProduceError> {
match self.attester.poll() {
Ok(AttestationPollOutcome::AttestationProduced(_)) => {}
Ok(outcome) => return Err(AttestationProduceError::DidNotProduce(outcome)),