From c9a7977d6998183458ab7a5d365ac08d8fa69257 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Wed, 27 Mar 2019 14:30:09 +1100 Subject: [PATCH] Renamed some functions, trying to get beaconnode attestation stuff to work. --- beacon_node/beacon_chain/src/beacon_chain.rs | 2 +- beacon_node/rpc/src/beacon_attester.rs | 17 +++++++---------- protos/src/services.proto | 2 +- .../attester_service/attestation_grpc_client.rs | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 61b5fb58b..110d1a99d 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -280,7 +280,7 @@ where } /// Produce an `AttestationData` that is valid for the present `slot` and given `shard`. - pub fn produce_attestation(&self, shard: u64) -> Result { + pub fn produce_attestation_data(&self, shard: u64) -> Result { trace!("BeaconChain::produce_attestation: shard: {}", shard); let source_epoch = self.state.read().current_justified_epoch; let source_root = *self.state.read().get_block_root( diff --git a/beacon_node/rpc/src/beacon_attester.rs b/beacon_node/rpc/src/beacon_attester.rs index 88caacdd0..4166c30d4 100644 --- a/beacon_node/rpc/src/beacon_attester.rs +++ b/beacon_node/rpc/src/beacon_attester.rs @@ -9,6 +9,8 @@ use protos::services::{ use protos::services_grpc::BeaconBlockService; use slog::{Logger, info, warn, error}; +const TEST_SHARD_PHASE_ZERO: u8 = 0; + #[derive(Clone)] pub struct AttestationServiceInstance { pub chain: Arc, @@ -29,9 +31,11 @@ impl AttestationService for AttestationServiceInstance { let spec = self.chain.get_spec(); let state = self.chain.get_state(); + let slot_requested = req.get_slot(); + // Start by performing some checks // Check that the the AttestionData is for the current slot (otherwise it will not be valid) - if req.get_slot() != state.slot { + if slot_requested != state.slot { let f = sink .fail(RpcStatus::new( RpcStatusCode::OutOfRange, @@ -40,15 +44,8 @@ impl AttestationService for AttestationServiceInstance { .map_err(move |e| error!(&self.log, "Failed to reply with failure {:?}: {:?}", req, e)); } - // Then collect the data we need for the AttesatationData object - //let beacon_block_root = state.latest_block_roots.first().ok_or_else(|e| ) - - // And finally build the AttestationData object - let mut attestation_data = AttestationDataProto::new(); - attestation_data.set_slot(state.slot.as_u64()); - attestation_data.set_shard(spec.genesis_start_shard); - attestation_data.set_beacon_block_root(b"cats".to_vec()); - //attestation_data. + // Then get the AttestationData from the beacon chain (for shard 0 for now) + let attestation_data = self.chain.produce_attestation_data(TEST_SHARD_PHASE_ZERO); let mut resp = ProduceAttestationDataResponse::new(); resp.set_attestation_data(attestation_data); diff --git a/protos/src/services.proto b/protos/src/services.proto index 35b9c32af..1dfb53c06 100644 --- a/protos/src/services.proto +++ b/protos/src/services.proto @@ -33,7 +33,7 @@ service ValidatorService { /// Service that handles validator attestations service AttestationService { - rpc ProduceAttestation(ProduceAttestationDataRequest) returns (ProduceAttestationDataResponse); + rpc ProduceAttestationData(ProduceAttestationDataRequest) returns (ProduceAttestationDataResponse); rpc PublishAttestation(PublishAttestationRequest) returns (PublishAttestationResponse); } diff --git a/validator_client/src/attester_service/attestation_grpc_client.rs b/validator_client/src/attester_service/attestation_grpc_client.rs index f55acc4f7..bfb7f67c6 100644 --- a/validator_client/src/attester_service/attestation_grpc_client.rs +++ b/validator_client/src/attester_service/attestation_grpc_client.rs @@ -27,7 +27,7 @@ impl BeaconNode for AttestationGrpcClient { let reply = self .client - .produce_attestation(&req) + .produce_attestation_data(&req) .map_err(|err| BeaconNodeError::RemoteFailure(format!("{:?}", err)))?; // TODO: return correct Attestation