From 33473892f27df37fdec79fb4a7d76c8fe241083c Mon Sep 17 00:00:00 2001 From: Age Manning Date: Sun, 31 Mar 2019 14:26:58 +1100 Subject: [PATCH] Validator client fixes. Hack fix for genesis start time --- beacon_node/rpc/src/attestation.rs | 24 ++++++++++++++++--- beacon_node/rpc/src/validator.rs | 13 +--------- .../validate_attestation.rs | 3 +++ .../testing_beacon_state_builder.rs | 10 +++++++- validator_client/src/service.rs | 8 ++++++- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index c6e5c68ee..494b24067 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -37,14 +37,29 @@ impl AttestationService for AttestationServiceInstance { let state = self.chain.get_state(); // Start by performing some checks - // Check that the the AttestionData is for the current slot (otherwise it will not be valid) - if slot_requested != state.slot.as_u64() { + // Check that the AttestionData is for the current slot (otherwise it will not be valid) + if slot_requested > state.slot.as_u64() { let log_clone = self.log.clone(); let f = sink .fail(RpcStatus::new( RpcStatusCode::OutOfRange, Some(format!( - "AttestationData request for a slot that is not the current slot." + "AttestationData request for a slot that is in the future." + )), + )) + .map_err(move |e| { + error!(log_clone, "Failed to reply with failure {:?}: {:?}", req, e) + }); + return ctx.spawn(f); + } + // currently cannot handle past slots. TODO: Handle this case + else if slot_requested < state.slot.as_u64() { + let log_clone = self.log.clone(); + let f = sink + .fail(RpcStatus::new( + RpcStatusCode::InvalidArgument, + Some(format!( + "AttestationData request for a slot that is in the past." )), )) .map_err(move |e| { @@ -71,6 +86,9 @@ impl AttestationService for AttestationServiceInstance { } }; + dbg!("Produced attestation"); + dbg!(attestation_data.clone()); + let mut attestation_data_proto = AttestationDataProto::new(); attestation_data_proto.set_ssz(ssz_encode(&attestation_data)); diff --git a/beacon_node/rpc/src/validator.rs b/beacon_node/rpc/src/validator.rs index 3dbbbdd17..0a9d7015c 100644 --- a/beacon_node/rpc/src/validator.rs +++ b/beacon_node/rpc/src/validator.rs @@ -30,22 +30,11 @@ impl ValidatorService for ValidatorServiceInstance { trace!(self.log, "RPC request"; "endpoint" => "GetValidatorDuties", "epoch" => req.get_epoch()); let spec = self.chain.get_spec(); - // update the caches if necessary - { - let mut mut_state = self.chain.get_mut_state(); - - let _ = mut_state.build_epoch_cache(RelativeEpoch::NextWithoutRegistryChange, spec); - - let _ = mut_state.build_epoch_cache(RelativeEpoch::NextWithRegistryChange, spec); - let _ = mut_state.update_pubkey_cache(); - } - + let state = self.chain.get_state(); let epoch = Epoch::from(req.get_epoch()); let mut resp = GetDutiesResponse::new(); let resp_validators = resp.mut_active_validators(); - let state = self.chain.get_state(); - let relative_epoch = match RelativeEpoch::from_epoch(state.slot.epoch(spec.slots_per_epoch), epoch) { Ok(v) => v, diff --git a/eth2/state_processing/src/per_block_processing/validate_attestation.rs b/eth2/state_processing/src/per_block_processing/validate_attestation.rs index 3b89bec99..76b415796 100644 --- a/eth2/state_processing/src/per_block_processing/validate_attestation.rs +++ b/eth2/state_processing/src/per_block_processing/validate_attestation.rs @@ -99,6 +99,9 @@ fn validate_attestation_parametric( crosslink_data_root: attestation.data.crosslink_data_root, epoch: attestation.data.slot.epoch(spec.slots_per_epoch), }; + dbg!(attestation.clone()); + dbg!(state.latest_crosslinks[attestation.data.shard as usize].clone()); + dbg!(potential_crosslink.clone()); verify!( (attestation.data.previous_crosslink == state.latest_crosslinks[attestation.data.shard as usize]) diff --git a/eth2/types/src/test_utils/testing_beacon_state_builder.rs b/eth2/types/src/test_utils/testing_beacon_state_builder.rs index f437240dc..518f55e3c 100644 --- a/eth2/types/src/test_utils/testing_beacon_state_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_state_builder.rs @@ -6,6 +6,8 @@ use dirs; use log::debug; use rayon::prelude::*; use std::path::{Path, PathBuf}; +//TODO: testing only +use std::time::{Duration, SystemTime}; pub const KEYPAIRS_FILE: &str = "keypairs.raw_keypairs"; @@ -120,7 +122,13 @@ impl TestingBeaconStateBuilder { }) .collect(); - let genesis_time = 1553977336; // arbitrary + //TODO: Testing only + let now = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() + - 30; + let genesis_time = now; // arbitrary let mut state = BeaconState::genesis( genesis_time, diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index ce9e35266..38883e68f 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -29,11 +29,15 @@ use std::sync::RwLock; use std::time::{Duration, Instant, SystemTime}; use tokio::prelude::*; use tokio::runtime::Builder; -use tokio::timer::Interval; +use tokio::timer::{Delay, Interval}; use tokio_timer::clock::Clock; use types::test_utils::generate_deterministic_keypairs; use types::{ChainSpec, Epoch, Fork, Slot}; +/// A fixed amount of time after a slot to perform operations. This gives the node time to complete +/// per-slot processes. +const TIME_DELAY_FROM_SLOT: Duration = Duration::from_millis(200); + /// The validator service. This is the main thread that executes and maintains validator /// duties. //TODO: Generalize the BeaconNode types to use testing @@ -230,6 +234,8 @@ impl Service { runtime.block_on( interval .for_each(move |_| { + // wait for node to process + std::thread::sleep(TIME_DELAY_FROM_SLOT); // if a non-fatal error occurs, proceed to the next slot. let _ignore_error = service.per_slot_execution(); // completed a slot process