mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Update to spec v0.9.0
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//TODO: generalise these enums to the crate
|
||||
use crate::block_producer::{BeaconNodeError, PublishOutcome};
|
||||
use types::{Attestation, AttestationData, EthSpec, Slot};
|
||||
use types::{Attestation, AttestationData, CommitteeIndex, EthSpec, Slot};
|
||||
|
||||
/// Defines the methods required to produce and publish attestations on a Beacon Node. Abstracts the
|
||||
/// actual beacon node.
|
||||
@@ -10,7 +10,7 @@ pub trait BeaconNodeAttestation: Send + Sync {
|
||||
fn produce_attestation_data(
|
||||
&self,
|
||||
slot: Slot,
|
||||
shard: u64,
|
||||
index: CommitteeIndex,
|
||||
) -> Result<AttestationData, BeaconNodeError>;
|
||||
|
||||
/// Request that the node publishes a attestation.
|
||||
|
||||
@@ -6,17 +6,17 @@ use ssz::{Decode, Encode};
|
||||
use protos::services::{
|
||||
Attestation as GrpcAttestation, ProduceAttestationDataRequest, PublishAttestationRequest,
|
||||
};
|
||||
use types::{Attestation, AttestationData, EthSpec, Slot};
|
||||
use types::{Attestation, AttestationData, CommitteeIndex, EthSpec, Slot};
|
||||
|
||||
impl BeaconNodeAttestation for AttestationServiceClient {
|
||||
fn produce_attestation_data(
|
||||
&self,
|
||||
slot: Slot,
|
||||
shard: u64,
|
||||
index: CommitteeIndex,
|
||||
) -> Result<AttestationData, BeaconNodeError> {
|
||||
let mut req = ProduceAttestationDataRequest::new();
|
||||
req.set_slot(slot.as_u64());
|
||||
req.set_shard(shard);
|
||||
req.set_shard(index);
|
||||
|
||||
let reply = self
|
||||
.produce_attestation_data(&req)
|
||||
|
||||
@@ -57,11 +57,21 @@ impl<'a, B: BeaconNodeAttestation, S: Signer, E: EthSpec> AttestationProducer<'a
|
||||
"slot" => slot,
|
||||
),
|
||||
Err(e) => error!(log, "Attestation production error"; "Error" => format!("{:?}", e)),
|
||||
Ok(ValidatorEvent::SignerRejection(_slot)) => error!(log, "Attestation production error"; "Error" => "Signer could not sign the attestation".to_string()),
|
||||
Ok(ValidatorEvent::IndexedAttestationNotProduced(_slot)) => error!(log, "Attestation production error"; "Error" => "Rejected the attestation as it could have been slashed".to_string()),
|
||||
Ok(ValidatorEvent::PublishAttestationFailed) => error!(log, "Attestation production error"; "Error" => "Beacon node was unable to publish an attestation".to_string()),
|
||||
Ok(ValidatorEvent::InvalidAttestation) => error!(log, "Attestation production error"; "Error" => "The signed attestation was invalid".to_string()),
|
||||
Ok(v) => warn!(log, "Unknown result for attestation production"; "Error" => format!("{:?}",v)),
|
||||
Ok(ValidatorEvent::SignerRejection(_slot)) => {
|
||||
error!(log, "Attestation production error"; "Error" => "Signer could not sign the attestation".to_string())
|
||||
}
|
||||
Ok(ValidatorEvent::IndexedAttestationNotProduced(_slot)) => {
|
||||
error!(log, "Attestation production error"; "Error" => "Rejected the attestation as it could have been slashed".to_string())
|
||||
}
|
||||
Ok(ValidatorEvent::PublishAttestationFailed) => {
|
||||
error!(log, "Attestation production error"; "Error" => "Beacon node was unable to publish an attestation".to_string())
|
||||
}
|
||||
Ok(ValidatorEvent::InvalidAttestation) => {
|
||||
error!(log, "Attestation production error"; "Error" => "The signed attestation was invalid".to_string())
|
||||
}
|
||||
Ok(v) => {
|
||||
warn!(log, "Unknown result for attestation production"; "Error" => format!("{:?}",v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +90,11 @@ impl<'a, B: BeaconNodeAttestation, S: Signer, E: EthSpec> AttestationProducer<'a
|
||||
|
||||
let attestation = self
|
||||
.beacon_node
|
||||
.produce_attestation_data(self.duty.slot, self.duty.shard)?;
|
||||
.produce_attestation_data(self.duty.slot, self.duty.index)?;
|
||||
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::BeaconAttester, &self.fork);
|
||||
if let Some(attestation) = self.sign_attestation(attestation, self.duty, domain) {
|
||||
match self.beacon_node.publish_attestation(attestation) {
|
||||
Ok(PublishOutcome::InvalidAttestation(_string)) => {
|
||||
@@ -132,7 +144,7 @@ impl<'a, B: BeaconNodeAttestation, S: Signer, E: EthSpec> AttestationProducer<'a
|
||||
|
||||
let mut aggregation_bits = BitList::with_capacity(duties.committee_len).ok()?;
|
||||
let custody_bits = BitList::with_capacity(duties.committee_len).ok()?;
|
||||
aggregation_bits.set(duties.committee_index, true).ok()?;
|
||||
aggregation_bits.set(duties.committee_position, true).ok()?;
|
||||
|
||||
Some(Attestation {
|
||||
aggregation_bits,
|
||||
|
||||
@@ -35,7 +35,7 @@ impl EpochDuty {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
// if the validator is required to attest to a shard, create the data
|
||||
// if the validator is required to attest to a index, create the data
|
||||
let mut attestation_duty = None;
|
||||
if self.attestation_duty.slot == slot {
|
||||
attestation_duty = Some(self.attestation_duty)
|
||||
@@ -59,8 +59,8 @@ impl fmt::Display for EpochDuty {
|
||||
}
|
||||
write!(
|
||||
f,
|
||||
"produce block slot: {}, attestation slot: {}, attestation shard: {}",
|
||||
display_block, self.attestation_duty.slot, self.attestation_duty.shard
|
||||
"produce block slot: {}, attestation slot: {}, attestation index: {}",
|
||||
display_block, self.attestation_duty.slot, self.attestation_duty.index
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ impl BeaconNodeDuties for ValidatorServiceClient {
|
||||
|
||||
let attestation_duty = AttestationDuty {
|
||||
slot: Slot::from(active_duty.get_attestation_slot()),
|
||||
shard: active_duty.get_attestation_shard(),
|
||||
committee_index: active_duty.get_committee_index() as usize,
|
||||
index: active_duty.get_attestation_shard(),
|
||||
committee_position: active_duty.get_committee_index() as usize,
|
||||
committee_len: active_duty.get_committee_len() as usize,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user