Renamed attestation -> attestation_data for fetch, but not publish, to acknowledge the difference in the spec. Also started implementing the gRPC get_attestation_data functionality in the BeaconNode.

This commit is contained in:
Luke Anderson 2019-03-26 17:41:43 +11:00
parent a82a5311ee
commit 1584469b7c
No known key found for this signature in database
GPG Key ID: 44408169EC61E228
7 changed files with 53 additions and 32 deletions

View File

@ -50,7 +50,7 @@ impl<T: ClientDB, U: SlotClock, F: ForkChoice> DirectBeaconNode<T, U, F> {
}
impl<T: ClientDB, U: SlotClock, F: ForkChoice> AttesterBeaconNode for DirectBeaconNode<T, U, F> {
fn produce_attestation(
fn produce_attestation_data(
&self,
_slot: Slot,
shard: u64,

View File

@ -1,45 +1,66 @@
use crate::beacon_chain::BeaconChain;
use futures::Future;
use grpcio::{RpcContext, UnarySink};
use grpcio::{RpcContext, UnarySink, RpcStatus, RpcStatusCode};
use protos::services::{
Attestation as AttestationProto, ProduceAttestation, ProduceAttestationResponse,
ProduceAttestationRequest, PublishAttestationResponse, PublishAttestationRequest,
AttestationData as AttestationDataProto, ProduceAttestationData, ProduceAttestationDataResponse,
ProduceAttestationDataRequest, PublishAttestationResponse, PublishAttestationRequest,
PublishAttestation
};
use protos::services_grpc::BeaconBlockService;
use slog::Logger;
use slog::{Logger, info, warn, error};
#[derive(Clone)]
pub struct AttestationServiceInstance {
pub chain: Arc<BeaconChain>,
pub log: Logger,
}
impl AttestationService for AttestationServiceInstance {
/// Produce a `BeaconBlock` for signing by a validator.
fn produce_attestation(
/// Produce the `AttestationData` for signing by a validator.
fn produce_attestation_data(
&mut self,
ctx: RpcContext,
req: ProduceAttestationRequest,
sink: UnarySink<ProduceAttestationResponse>,
req: ProduceAttestationDataRequest,
sink: UnarySink<ProduceAttestationDataResponse>,
) {
println!("producing attestation at slot {}", req.get_slot());
info!(&self.log, "Attempting to produce attestation at slot {}", req.get_slot());
// TODO: build a legit block.
let mut attestation = AttestationProto::new();
attestation.set_slot(req.get_slot());
// TODO Set the shard to something legit.
attestation.set_shard(0);
attestation.set_block_root(b"cats".to_vec());
// get the chain spec & state
let spec = self.chain.get_spec();
let state = self.chain.get_state();
let mut resp = ProduceAttestationResponse::new();
resp.set_attestation_data(attestation);
// 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 {
let f = sink
.fail(RpcStatus::new(
RpcStatusCode::OutOfRange,
"AttestationData request for a slot that is not the current slot."
))
.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.
let mut resp = ProduceAttestationDataResponse::new();
resp.set_attestation_data(attestation_data);
let f = sink
.success(resp)
.map_err(move |e| println!("failed to reply {:?}: {:?}", req, e));
.map_err(move |e| error!("Failed to reply with success {:?}: {:?}", req, e));
ctx.spawn(f)
}
/// Accept some fully-formed `BeaconBlock`, process and publish it.
/// Accept some fully-formed `FreeAttestation` from the validator,
/// store it, and aggregate it into an `Attestation`.
fn publish_attestation(
&mut self,
ctx: RpcContext,

View File

@ -94,7 +94,7 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> Attester<T, U, V,
}
fn produce_attestation(&mut self, slot: Slot, shard: u64) -> Result<PollOutcome, Error> {
let attestation_data = match self.beacon_node.produce_attestation(slot, shard)? {
let attestation_data = match self.beacon_node.produce_attestation_data(slot, shard)? {
Some(attestation_data) => attestation_data,
None => return Ok(PollOutcome::BeaconNodeUnableToProduceAttestation(slot)),
};

View File

@ -26,7 +26,7 @@ impl SimulatedBeaconNode {
}
impl BeaconNode for SimulatedBeaconNode {
fn produce_attestation(&self, slot: Slot, shard: u64) -> ProduceResult {
fn produce_attestation_data(&self, slot: Slot, shard: u64) -> ProduceResult {
*self.produce_input.write().unwrap() = Some((slot, shard));
match *self.produce_result.read().unwrap() {
Some(ref r) => r.clone(),

View File

@ -14,7 +14,7 @@ pub enum PublishOutcome {
/// Defines the methods required to produce and publish blocks on a Beacon Node.
pub trait BeaconNode: Send + Sync {
fn produce_attestation(
fn produce_attestation_data(
&self,
slot: Slot,
shard: u64,

View File

@ -33,7 +33,7 @@ service ValidatorService {
/// Service that handles validator attestations
service AttestationService {
rpc ProduceAttestation(ProduceAttestationRequest) returns (ProduceAttestationResponse);
rpc ProduceAttestation(ProduceAttestationDataRequest) returns (ProduceAttestationDataResponse);
rpc PublishAttestation(PublishAttestationRequest) returns (PublishAttestationResponse);
}
@ -138,13 +138,13 @@ message ProposeBlockSlotResponse {
* Attestation Service Messages
*/
message ProduceAttestationRequest {
message ProduceAttestationDataRequest {
uint64 slot = 1;
uint64 shard = 2;
}
message ProduceAttestationResponse {
Attestation attestation_data = 1;
message ProduceAttestationDataResponse {
AttestationData attestation_data = 1;
}
message PublishAttestationRequest {
@ -162,7 +162,7 @@ message Crosslink {
}
message Attestation {
message AttestationData {
uint64 slot = 1;
uint64 shard = 2;
bytes beacon_block_root = 3;
@ -175,7 +175,7 @@ message Attestation {
}
message FreeAttestation {
Attestation attestation_data = 1;
AttestationData data = 1;
bytes signature = 2;
uint64 validator_index = 3;
}

View File

@ -2,7 +2,7 @@ use protos::services_grpc::AttestationServiceClient;
use std::sync::Arc;
use attester::{BeaconNode, BeaconNodeError, PublishOutcome};
use protos::services::ProduceAttestationRequest;
use protos::services::ProduceAttestationDataRequest;
use types::{AttestationData, FreeAttestation, Slot};
pub struct AttestationGrpcClient {
@ -16,12 +16,12 @@ impl AttestationGrpcClient {
}
impl BeaconNode for AttestationGrpcClient {
fn produce_attestation(
fn produce_attestation_data(
&self,
slot: Slot,
shard: u64,
) -> Result<Option<AttestationData>, BeaconNodeError> {
let mut req = ProduceAttestationRequest::new();
let mut req = ProduceAttestationDataRequest::new();
req.set_slot(slot.as_u64());
req.set_shard(shard);