spec v0.6: update beacon_node, validator_client

This commit is contained in:
Michael Sproul 2019-06-03 16:13:51 +10:00
parent 7fbcdd54d7
commit 6bde64bd6a
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914
7 changed files with 26 additions and 16 deletions

View File

@ -16,6 +16,7 @@ use state_processing::{
};
use std::sync::Arc;
use store::{Error as DBError, Store};
use tree_hash::TreeHash;
use types::*;
#[derive(Debug, PartialEq)]
@ -326,8 +327,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// If required, transition the new state to the present slot.
for _ in state.slot.as_u64()..present_slot.as_u64() {
// Ensure the next epoch state caches are built in case of an epoch transition.
state.build_committee_cache(RelativeEpoch::NextWithoutRegistryChange, &self.spec)?;
state.build_committee_cache(RelativeEpoch::NextWithRegistryChange, &self.spec)?;
state.build_committee_cache(RelativeEpoch::Next, &self.spec)?;
per_slot_processing(&mut *state, &self.spec)?;
}
@ -459,7 +459,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
if let Some(attestation_duty) = self
.state
.read()
.get_attestation_duties(validator_index, &self.spec)?
.get_attestation_duties(validator_index, RelativeEpoch::Current)?
{
Ok(Some((attestation_duty.slot, attestation_duty.shard)))
} else {
@ -497,15 +497,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
*self.state.read().get_block_root(current_epoch_start_slot)?
};
let previous_crosslink_root =
Hash256::from_slice(&state.get_current_crosslink(shard)?.tree_hash_root());
Ok(AttestationData {
slot: self.state.read().slot,
shard,
beacon_block_root: self.head().beacon_block_root,
target_root,
crosslink_data_root: Hash256::zero(),
previous_crosslink: state.latest_crosslinks[shard as usize].clone(),
source_epoch: state.current_justified_epoch,
source_root: state.current_justified_root,
target_epoch: state.current_epoch(),
target_root,
shard,
previous_crosslink_root,
crosslink_data_root: Hash256::zero(),
})
}
@ -678,14 +681,17 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
slot: state.slot,
previous_block_root,
state_root: Hash256::zero(), // Updated after the state is calculated.
signature: self.spec.empty_signature.clone(), // To be completed by a validator.
signature: Signature::empty_signature(), // To be completed by a validator.
body: BeaconBlockBody {
randao_reveal,
eth1_data: Eth1Data {
// TODO: replace with real data
deposit_count: 0,
deposit_root: Hash256::zero(),
block_hash: Hash256::zero(),
},
// TODO: badass Lighthouse graffiti
graffiti: [0; 32],
proposer_slashings,
attester_slashings,
attestations: self

View File

@ -115,7 +115,9 @@ impl<T: BeaconChainTypes> ValidatorService for ValidatorServiceInstance<T> {
};
// get attestation duties and check if validator is active
let attestation_duties = match state.get_attestation_duties(val_index, &spec) {
let attestation_duties = match state
.get_attestation_duties(val_index, RelativeEpoch::Current)
{
Ok(Some(v)) => v,
Ok(_) => {
// validator is inactive, go to the next validator

View File

@ -75,6 +75,7 @@ fn test_yaml_vectors(
let spec = FoundationEthSpec::spec();
let zero_hash = Hash256::zero();
let eth1_data = Eth1Data {
deposit_count: 0,
deposit_root: zero_hash.clone(),
block_hash: zero_hash.clone(),
};
@ -83,6 +84,7 @@ fn test_yaml_vectors(
let body = BeaconBlockBody {
eth1_data,
randao_reveal,
graffiti: [0; 32],
proposer_slashings: vec![],
attester_slashings: vec![],
attestations: vec![],

View File

@ -67,7 +67,7 @@ fn invalid_block_signature() {
let keypair = Keypair::random();
let message = block.signed_root();
let epoch = block.slot.epoch(spec.slots_per_epoch);
let domain = spec.get_domain(epoch, Domain::BeaconBlock, &state.fork);
let domain = spec.get_domain(epoch, Domain::BeaconProposer, &state.fork);
block.signature = Signature::new(&message, domain, &keypair.sk);
// process block with invalid block signature

View File

@ -738,11 +738,9 @@ impl<T: EthSpec> BeaconState<T> {
/// Returns the `slot`, `shard` and `committee_index` for which a validator must produce an
/// attestation.
///
/// Only reads the current epoch.
///
/// Note: Utilizes the cache and will fail if the appropriate cache is not initialized.
///
/// Spec v0.5.1
/// Spec v0.6.2
pub fn get_attestation_duties(
&self,
validator_index: usize,

View File

@ -140,7 +140,7 @@ impl<'a, B: BeaconNodeAttestation, S: Signer> AttestationProducer<'a, B, S> {
aggregation_bitfield,
data: attestation,
custody_bitfield,
aggregate_signature,
signature: aggregate_signature,
})
}

View File

@ -100,7 +100,9 @@ impl<'a, B: BeaconNodeBlock, S: Signer> BlockProducer<'a, B, S> {
.produce_beacon_block(self.slot, &randao_reveal)?
{
if self.safe_to_produce(&block) {
let domain = self.spec.get_domain(epoch, Domain::BeaconBlock, &self.fork);
let domain = self
.spec
.get_domain(epoch, Domain::BeaconProposer, &self.fork);
if let Some(block) = self.sign_block(block, domain) {
self.beacon_node.publish_beacon_block(block)?;
Ok(ValidatorEvent::BlockProduced(self.slot))