mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
updates per per review
This commit is contained in:
@@ -2004,18 +2004,6 @@ impl<E: EthSpec> BeaconState<E> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the PTC
|
||||
/// Requires the committee cache to be initialized.
|
||||
/// TODO(EIP-7732): definitely gonna have to cache this..
|
||||
/// TODO(EIP-7732): check this implementation against the latest spec
|
||||
// https://ethereum.github.io/consensus-specs/specs/_features/eip7732/beacon-chain/#new-get_ptc
|
||||
pub fn get_ptc(&self, slot: Slot) -> Result<PTC<E>, Error> {
|
||||
let committee_cache = self.committee_cache_at_slot(slot)?;
|
||||
let committees = committee_cache.get_beacon_committees_at_slot(slot)?;
|
||||
|
||||
PTC::from_committees(&committees)
|
||||
}
|
||||
|
||||
/// Build all caches (except the tree hash cache), if they need to be built.
|
||||
#[instrument(skip_all, level = "debug")]
|
||||
pub fn build_caches(&mut self, spec: &ChainSpec) -> Result<(), Error> {
|
||||
|
||||
@@ -69,7 +69,6 @@ pub mod pending_deposit;
|
||||
pub mod pending_partial_withdrawal;
|
||||
pub mod proposer_preparation_data;
|
||||
pub mod proposer_slashing;
|
||||
pub mod ptc;
|
||||
pub mod relative_epoch;
|
||||
pub mod selection_proof;
|
||||
pub mod shuffling_id;
|
||||
@@ -250,7 +249,6 @@ pub use crate::preset::{
|
||||
};
|
||||
pub use crate::proposer_preparation_data::ProposerPreparationData;
|
||||
pub use crate::proposer_slashing::ProposerSlashing;
|
||||
pub use crate::ptc::PTC;
|
||||
pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch};
|
||||
pub use crate::runtime_fixed_vector::RuntimeFixedVector;
|
||||
pub use crate::runtime_var_list::RuntimeVariableList;
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
use crate::*;
|
||||
use safe_arith::SafeArith;
|
||||
|
||||
/// TODO(EIP-7732): is it easier to return u64 or usize?
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PTC<E: EthSpec>(FixedVector<usize, E::PTCSize>);
|
||||
|
||||
// TODO(EIP-7732): check this implementation against the latest spec
|
||||
// https://ethereum.github.io/consensus-specs/specs/_features/eip7732/beacon-chain/#new-get_ptc
|
||||
impl<E: EthSpec> PTC<E> {
|
||||
pub fn from_committees(committees: &[BeaconCommittee]) -> Result<Self, BeaconStateError> {
|
||||
// this function is only used here and
|
||||
// I have no idea where else to put it
|
||||
fn bit_floor(n: u64) -> u64 {
|
||||
if n == 0 {
|
||||
0
|
||||
} else {
|
||||
1 << (n.leading_zeros() as u64 ^ 63)
|
||||
}
|
||||
}
|
||||
|
||||
let committee_count_per_slot = committees.len() as u64;
|
||||
let committees_per_slot = bit_floor(std::cmp::min(
|
||||
committee_count_per_slot,
|
||||
E::PTCSize::to_u64(),
|
||||
)) as usize;
|
||||
let members_per_committee = E::PTCSize::to_usize().safe_div(committees_per_slot)?;
|
||||
|
||||
let mut ptc = Vec::with_capacity(E::PTCSize::to_usize());
|
||||
for idx in 0..committees_per_slot {
|
||||
let beacon_committee = committees
|
||||
.get(idx as usize)
|
||||
.ok_or_else(|| Error::InvalidCommitteeIndex(idx as u64))?;
|
||||
ptc.extend_from_slice(&beacon_committee.committee[..members_per_committee]);
|
||||
}
|
||||
|
||||
Ok(Self(FixedVector::from(ptc)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: EthSpec> IntoIterator for &'a PTC<E> {
|
||||
type Item = &'a usize;
|
||||
type IntoIter = std::slice::Iter<'a, usize>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: EthSpec> IntoIterator for PTC<E> {
|
||||
type Item = usize;
|
||||
type IntoIter = std::vec::IntoIter<usize>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
@@ -54,37 +54,6 @@ impl<E: EthSpec> SignedExecutionPayloadEnvelope<E> {
|
||||
Self::NextFork(ref signed) => ExecutionPayloadEnvelopeRef::NextFork(&signed.message),
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify `self.signature`.
|
||||
///
|
||||
/// The `parent_state` is the post-state of the beacon block with
|
||||
/// block_root = self.message.beacon_block_root
|
||||
pub fn verify_signature(
|
||||
&self,
|
||||
parent_state: &BeaconState<E>,
|
||||
genesis_validators_root: Hash256,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<bool, BeaconStateError> {
|
||||
let domain = spec.get_domain(
|
||||
parent_state.current_epoch(),
|
||||
Domain::BeaconBuilder,
|
||||
&parent_state.fork(),
|
||||
genesis_validators_root,
|
||||
);
|
||||
let pubkey = parent_state
|
||||
.validators()
|
||||
.get(self.message().builder_index() as usize)
|
||||
.and_then(|v| {
|
||||
let pk: Option<PublicKey> = v.pubkey.decompress().ok();
|
||||
pk
|
||||
})
|
||||
.ok_or_else(|| {
|
||||
BeaconStateError::UnknownValidator(self.message().builder_index() as usize)
|
||||
})?;
|
||||
let message = self.message().signing_root(domain);
|
||||
|
||||
Ok(self.signature().verify(&pubkey, message))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for SignedExecutionPayloadEnvelope<E> {
|
||||
|
||||
Reference in New Issue
Block a user