Correct attestation error handling

This commit is contained in:
Age Manning 2019-03-30 19:48:45 +11:00
parent fc5142c09a
commit 51ffbc07d2
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
3 changed files with 24 additions and 6 deletions

View File

@ -25,7 +25,7 @@ impl AttestationService for AttestationServiceInstance {
req: ProduceAttestationDataRequest, req: ProduceAttestationDataRequest,
sink: UnarySink<ProduceAttestationDataResponse>, sink: UnarySink<ProduceAttestationDataResponse>,
) { ) {
warn!( trace!(
&self.log, &self.log,
"Attempting to produce attestation at slot {}", "Attempting to produce attestation at slot {}",
req.get_slot() req.get_slot()
@ -92,7 +92,7 @@ impl AttestationService for AttestationServiceInstance {
req: PublishAttestationRequest, req: PublishAttestationRequest,
sink: UnarySink<PublishAttestationResponse>, sink: UnarySink<PublishAttestationResponse>,
) { ) {
warn!(self.log, "Publishing attestation"); trace!(self.log, "Publishing attestation");
let mut resp = PublishAttestationResponse::new(); let mut resp = PublishAttestationResponse::new();
let ssz_serialized_attestation = req.get_attestation().get_ssz(); let ssz_serialized_attestation = req.get_attestation().get_ssz();
@ -128,6 +128,7 @@ impl AttestationService for AttestationServiceInstance {
self.log, self.log,
"PublishAttestation"; "PublishAttestation";
"type" => "invalid_attestation", "type" => "invalid_attestation",
"error" => format!("{:?}", e),
); );
resp.set_success(false); resp.set_success(false);
resp.set_msg(format!("InvalidAttestation: {:?}", e).as_bytes().to_vec()); resp.set_msg(format!("InvalidAttestation: {:?}", e).as_bytes().to_vec());

View File

@ -4,7 +4,7 @@ mod grpc;
use std::sync::Arc; use std::sync::Arc;
use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot}; use types::{BeaconBlock, ChainSpec, Domain, Fork, Slot};
//TODO: Move these higher up in the crate //TODO: Move these higher up in the crate
use super::block_producer::{BeaconNodeError, ValidatorEvent}; use super::block_producer::{BeaconNodeError, PublishOutcome, ValidatorEvent};
use crate::signer::Signer; use crate::signer::Signer;
use beacon_node_attestation::BeaconNodeAttestation; use beacon_node_attestation::BeaconNodeAttestation;
use slog::{error, info, warn}; use slog::{error, info, warn};
@ -58,6 +58,12 @@ impl<'a, B: BeaconNodeAttestation, S: Signer> AttestationProducer<'a, B, S> {
Ok(ValidatorEvent::BeaconNodeUnableToProduceAttestation(_slot)) => { Ok(ValidatorEvent::BeaconNodeUnableToProduceAttestation(_slot)) => {
error!(log, "Attestation production error"; "Error" => format!("Beacon node was unable to produce an attestation")) error!(log, "Attestation production error"; "Error" => format!("Beacon node was unable to produce an attestation"))
} }
Ok(ValidatorEvent::PublishAttestationFailed) => {
error!(log, "Attestation production error"; "Error" => format!("Beacon node was unable to publish an attestation"))
}
Ok(ValidatorEvent::InvalidAttestation) => {
error!(log, "Attestation production error"; "Error" => format!("The signed attestation was invalid"))
}
Ok(v) => { Ok(v) => {
warn!(log, "Unknown result for attestation production"; "Error" => format!("{:?}",v)) warn!(log, "Unknown result for attestation production"; "Error" => format!("{:?}",v))
} }
@ -83,8 +89,15 @@ impl<'a, B: BeaconNodeAttestation, S: Signer> AttestationProducer<'a, B, S> {
if self.safe_to_produce(&attestation) { if self.safe_to_produce(&attestation) {
let domain = self.spec.get_domain(epoch, Domain::Attestation, &self.fork); let domain = self.spec.get_domain(epoch, Domain::Attestation, &self.fork);
if let Some(attestation) = self.sign_attestation(attestation, self.duty, domain) { if let Some(attestation) = self.sign_attestation(attestation, self.duty, domain) {
self.beacon_node.publish_attestation(attestation)?; match self.beacon_node.publish_attestation(attestation) {
Ok(ValidatorEvent::AttestationProduced(self.duty.slot)) Ok(PublishOutcome::InvalidAttestation(_string)) => {
Ok(ValidatorEvent::InvalidAttestation)
}
Ok(PublishOutcome::Valid) => {
Ok(ValidatorEvent::AttestationProduced(self.duty.slot))
}
Err(_) | Ok(_) => Ok(ValidatorEvent::PublishAttestationFailed),
}
} else { } else {
Ok(ValidatorEvent::SignerRejection(self.duty.slot)) Ok(ValidatorEvent::SignerRejection(self.duty.slot))
} }
@ -101,7 +114,7 @@ impl<'a, B: BeaconNodeAttestation, S: Signer> AttestationProducer<'a, B, S> {
/// done upstream. /// done upstream.
fn sign_attestation( fn sign_attestation(
&mut self, &mut self,
mut attestation: AttestationData, attestation: AttestationData,
duties: AttestationDuty, duties: AttestationDuty,
domain: u64, domain: u64,
) -> Option<Attestation> { ) -> Option<Attestation> {

View File

@ -31,6 +31,10 @@ pub enum ValidatorEvent {
BeaconNodeUnableToProduceAttestation(Slot), BeaconNodeUnableToProduceAttestation(Slot),
/// The signer failed to sign the message. /// The signer failed to sign the message.
SignerRejection(Slot), SignerRejection(Slot),
/// Publishing an attestation failed.
PublishAttestationFailed,
/// Beacon node rejected the attestation.
InvalidAttestation,
} }
/// This struct contains the logic for requesting and signing beacon blocks for a validator. The /// This struct contains the logic for requesting and signing beacon blocks for a validator. The