mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
Use all attestation subnets (#1257)
* Update `milagro_bls` to new release (#1183) * Update milagro_bls to new release Signed-off-by: Kirk Baird <baird.k@outlook.com> * Tidy up fake cryptos Signed-off-by: Kirk Baird <baird.k@outlook.com> * move SecretHash to bls and put plaintext back Signed-off-by: Kirk Baird <baird.k@outlook.com> * Update v0.12.0 to v0.12.1 * Add compute_subnet_for_attestation * Replace CommitteeIndex topic with Attestation * Fix warnings * Fix attestation service tests * fmt * Appease clippy * return error from validator_subscriptions * move state out of loop * Fix early break on error * Get state from slot clock * Fix beacon state in attestation tests * Add failing test for lookahead > 1 * Minor change * Address some review comments * Add subnet verification to beacon chain * Move subnet verification to processor * Pass committee_count_at_slot to ValidatorDuty and ValidatorSubscription * Pass subnet id for publishing attestations * Fix attestation service tests * Fix more tests * Fix fork choice test * Remove unused code * Remove more unused and expensive code Co-authored-by: Kirk Baird <baird.k@outlook.com> Co-authored-by: Michael Sproul <michael@sigmaprime.io> Co-authored-by: Age Manning <Age@AgeManning.com> Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
use super::{
|
||||
AggregateSignature, AttestationData, BitList, ChainSpec, Domain, EthSpec, Fork, SecretKey,
|
||||
Signature, SignedRoot, SubnetId,
|
||||
Signature, SignedRoot,
|
||||
};
|
||||
use crate::{test_utils::TestRandom, Hash256};
|
||||
use safe_arith::{ArithError, SafeArith};
|
||||
|
||||
use safe_arith::ArithError;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
@@ -84,18 +83,6 @@ impl<T: EthSpec> Attestation<T> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the subnet id associated with the attestation.
|
||||
///
|
||||
/// Note, this will return the subnet id for an aggregated attestation. This is done
|
||||
/// to avoid checking aggregate bits every time we wish to get an id.
|
||||
pub fn subnet_id(&self, spec: &ChainSpec) -> Result<SubnetId, Error> {
|
||||
self.data
|
||||
.index
|
||||
.safe_rem(spec.attestation_subnet_count)
|
||||
.map(SubnetId::new)
|
||||
.map_err(Error::SubnetCountIsZero)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -83,12 +83,12 @@ impl<T: EthSpec> BeaconBlock<T> {
|
||||
};
|
||||
let proposer_slashing = ProposerSlashing {
|
||||
signed_header_1: signed_header.clone(),
|
||||
signed_header_2: signed_header.clone(),
|
||||
signed_header_2: signed_header,
|
||||
};
|
||||
|
||||
let attester_slashing = AttesterSlashing {
|
||||
attestation_1: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation,
|
||||
};
|
||||
|
||||
let attestation: Attestation<T> = Attestation {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
//! Identifies each shard by an integer identifier.
|
||||
use crate::{AttestationData, ChainSpec, CommitteeIndex, EthSpec, Slot};
|
||||
use safe_arith::{ArithError, SafeArith};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
@@ -8,7 +10,42 @@ pub struct SubnetId(u64);
|
||||
|
||||
impl SubnetId {
|
||||
pub fn new(id: u64) -> Self {
|
||||
SubnetId(id)
|
||||
id.into()
|
||||
}
|
||||
|
||||
/// Compute the subnet for an attestation with `attestation_data` where each slot in the
|
||||
/// attestation epoch contains `committee_count_per_slot` committees.
|
||||
pub fn compute_subnet_for_attestation_data<T: EthSpec>(
|
||||
attestation_data: &AttestationData,
|
||||
committee_count_per_slot: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SubnetId, ArithError> {
|
||||
Self::compute_subnet::<T>(
|
||||
attestation_data.slot,
|
||||
attestation_data.index,
|
||||
committee_count_per_slot,
|
||||
spec,
|
||||
)
|
||||
}
|
||||
|
||||
/// Compute the subnet for an attestation with `attestation.data.slot == slot` and
|
||||
/// `attestation.data.index == committee_index` where each slot in the attestation epoch
|
||||
/// contains `committee_count_at_slot` committees.
|
||||
pub fn compute_subnet<T: EthSpec>(
|
||||
slot: Slot,
|
||||
committee_index: CommitteeIndex,
|
||||
committee_count_at_slot: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<SubnetId, ArithError> {
|
||||
let slots_since_epoch_start: u64 = slot.as_u64().safe_rem(T::slots_per_epoch())?;
|
||||
|
||||
let committees_since_epoch_start =
|
||||
committee_count_at_slot.safe_mul(slots_since_epoch_start)?;
|
||||
|
||||
Ok(committees_since_epoch_start
|
||||
.safe_add(committee_index)?
|
||||
.safe_rem(spec.attestation_subnet_count)?
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,3 +62,15 @@ impl DerefMut for SubnetId {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for SubnetId {
|
||||
fn from(x: u64) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<u64> for SubnetId {
|
||||
fn into(self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user