Started migrating FreeAttestation to Attestation in the harnesses - doesn't compile yet.
This commit is contained in:
parent
6c8abd8990
commit
be592c86d1
@ -137,11 +137,11 @@ impl BeaconChainHarness {
|
|||||||
slot
|
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
|
/// Note: validators will only produce attestations _once per slot_. So, if you call this twice
|
||||||
/// you'll only get attestations on the first run.
|
/// 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 present_slot = self.beacon_chain.present_slot();
|
||||||
|
|
||||||
let attesting_validators = self
|
let attesting_validators = self
|
||||||
@ -158,7 +158,7 @@ impl BeaconChainHarness {
|
|||||||
let attesting_validators: HashSet<usize> =
|
let attesting_validators: HashSet<usize> =
|
||||||
HashSet::from_iter(attesting_validators.iter().cloned());
|
HashSet::from_iter(attesting_validators.iter().cloned());
|
||||||
|
|
||||||
let free_attestations: Vec<FreeAttestation> = self
|
let attestations: Vec<Attestation> = self
|
||||||
.validators
|
.validators
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -176,8 +176,8 @@ impl BeaconChainHarness {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Gathered {} FreeAttestations for slot {}.",
|
"Gathered {} Attestations for slot {}.",
|
||||||
free_attestations.len(),
|
attestations.len(),
|
||||||
present_slot
|
present_slot
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ impl BeaconChainHarness {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
});
|
||||||
|
|
||||||
debug!("Free attestations processed.");
|
debug!("attestations processed.");
|
||||||
|
|
||||||
block
|
block
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ use fork_choice::ForkChoice;
|
|||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use types::{AttestationData, BeaconBlock, FreeAttestation, Signature, Slot};
|
use types::{AttestationData, BeaconBlock, Attestation, Signature, Slot};
|
||||||
|
|
||||||
// mod attester;
|
// mod attester;
|
||||||
// mod producer;
|
// 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
|
/// Connect directly to a borrowed `BeaconChain` instance so an attester/producer can request/submit
|
||||||
/// blocks/attestations.
|
/// 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
|
/// 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.
|
/// block/attestation directly, or modify it before submission.
|
||||||
pub struct DirectBeaconNode<T: ClientDB, U: SlotClock, F: ForkChoice> {
|
pub struct DirectBeaconNode<T: ClientDB, U: SlotClock, F: ForkChoice> {
|
||||||
beacon_chain: Arc<BeaconChain<T, U, F>>,
|
beacon_chain: Arc<BeaconChain<T, U, F>>,
|
||||||
published_blocks: RwLock<Vec<BeaconBlock>>,
|
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> {
|
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).
|
/// 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())
|
Some(self.published_attestations.read().last()?.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeac
|
|||||||
_slot: Slot,
|
_slot: Slot,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
) -> Result<Option<AttestationData>, NodeError> {
|
) -> 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)),
|
Ok(attestation_data) => Ok(Some(attestation_data)),
|
||||||
Err(e) => Err(NodeError::RemoteFailure(format!("{:?}", e))),
|
Err(e) => Err(NodeError::RemoteFailure(format!("{:?}", e))),
|
||||||
}
|
}
|
||||||
@ -63,9 +63,9 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeac
|
|||||||
|
|
||||||
fn publish_attestation(
|
fn publish_attestation(
|
||||||
&self,
|
&self,
|
||||||
free_attestation: FreeAttestation,
|
attestation: Attestation,
|
||||||
) -> Result<AttestationPublishOutcome, NodeError> {
|
) -> Result<AttestationPublishOutcome, NodeError> {
|
||||||
self.published_attestations.write().push(free_attestation);
|
self.published_attestations.write().push(attestation);
|
||||||
Ok(AttestationPublishOutcome::ValidAttestation)
|
Ok(AttestationPublishOutcome::ValidAttestation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ mod direct_beacon_node;
|
|||||||
mod direct_duties;
|
mod direct_duties;
|
||||||
mod local_signer;
|
mod local_signer;
|
||||||
|
|
||||||
use crate::direct_beacon_node::DirectBeaconNode;
|
use crate::validator_harness::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;
|
||||||
@ -44,10 +44,8 @@ pub struct ValidatorHarness {
|
|||||||
pub block_producer: TestingBlockProducer,
|
pub block_producer: TestingBlockProducer,
|
||||||
pub attester: TestingAttester,
|
pub attester: TestingAttester,
|
||||||
pub spec: Arc<ChainSpec>,
|
pub spec: Arc<ChainSpec>,
|
||||||
pub epoch_map: Arc<DirectDuties<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
|
|
||||||
pub keypair: Keypair,
|
pub keypair: Keypair,
|
||||||
pub beacon_node: Arc<DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
|
pub beacon_node: Arc<DirectBeaconNode<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
|
||||||
pub slot_clock: Arc<TestingSlotClock>,
|
|
||||||
pub signer: Arc<LocalSigner>,
|
pub signer: Arc<LocalSigner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,22 +59,16 @@ impl ValidatorHarness {
|
|||||||
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
|
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock, BitwiseLMDGhost<MemoryDB>>>,
|
||||||
spec: Arc<ChainSpec>,
|
spec: Arc<ChainSpec>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let slot_clock = Arc::new(TestingSlotClock::new(spec.genesis_slot.as_u64()));
|
|
||||||
let signer = Arc::new(LocalSigner::new(keypair.clone()));
|
let signer = Arc::new(LocalSigner::new(keypair.clone()));
|
||||||
let beacon_node = Arc::new(DirectBeaconNode::new(beacon_chain.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(
|
let block_producer = BlockProducer::new(
|
||||||
spec.clone(),
|
spec.clone(),
|
||||||
epoch_map.clone(),
|
|
||||||
slot_clock.clone(),
|
|
||||||
beacon_node.clone(),
|
beacon_node.clone(),
|
||||||
signer.clone(),
|
signer.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let attester = Attester::new(
|
let attester = Attester::new(
|
||||||
epoch_map.clone(),
|
|
||||||
slot_clock.clone(),
|
|
||||||
beacon_node.clone(),
|
beacon_node.clone(),
|
||||||
signer.clone(),
|
signer.clone(),
|
||||||
);
|
);
|
||||||
@ -85,10 +77,8 @@ impl ValidatorHarness {
|
|||||||
block_producer,
|
block_producer,
|
||||||
attester,
|
attester,
|
||||||
spec,
|
spec,
|
||||||
epoch_map,
|
|
||||||
keypair,
|
keypair,
|
||||||
beacon_node,
|
beacon_node,
|
||||||
slot_clock,
|
|
||||||
signer,
|
signer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +103,7 @@ impl ValidatorHarness {
|
|||||||
/// Run the `poll` function on the `Attester` and produce a `FreeAttestation`.
|
/// Run the `poll` function on the `Attester` and produce a `FreeAttestation`.
|
||||||
///
|
///
|
||||||
/// An error is returned if the attester refuses to attest.
|
/// 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() {
|
match self.attester.poll() {
|
||||||
Ok(AttestationPollOutcome::AttestationProduced(_)) => {}
|
Ok(AttestationPollOutcome::AttestationProduced(_)) => {}
|
||||||
Ok(outcome) => return Err(AttestationProduceError::DidNotProduce(outcome)),
|
Ok(outcome) => return Err(AttestationProduceError::DidNotProduce(outcome)),
|
||||||
|
Loading…
Reference in New Issue
Block a user