add new beacon state variant for shanghai
This commit is contained in:
parent
203418ffc9
commit
acaa340b41
@ -3619,6 +3619,30 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
.ok_or(BlockProductionError::MissingExecutionPayload)?,
|
||||
},
|
||||
}),
|
||||
BeaconState::Shanghai(_) => {
|
||||
let sync_aggregate = get_sync_aggregate()?;
|
||||
let execution_payload = get_execution_payload(self, &state, proposer_index)?;
|
||||
//FIXME(sean) get blobs
|
||||
BeaconBlock::Shanghai(BeaconBlockShanghai {
|
||||
slot,
|
||||
proposer_index,
|
||||
parent_root,
|
||||
state_root: Hash256::zero(),
|
||||
body: BeaconBlockBodyShanghai {
|
||||
randao_reveal,
|
||||
eth1_data,
|
||||
graffiti,
|
||||
proposer_slashings: proposer_slashings.into(),
|
||||
attester_slashings: attester_slashings.into(),
|
||||
attestations,
|
||||
deposits,
|
||||
voluntary_exits: voluntary_exits.into(),
|
||||
sync_aggregate,
|
||||
execution_payload,
|
||||
blob_kzgs: VariableList::empty(),
|
||||
},
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
let block = SignedBeaconBlock::from_block(
|
||||
|
1
beacon_node/beacon_chain/src/blob_verification.rs
Normal file
1
beacon_node/beacon_chain/src/blob_verification.rs
Normal file
@ -0,0 +1 @@
|
||||
|
@ -5,6 +5,7 @@ mod beacon_chain;
|
||||
mod beacon_fork_choice_store;
|
||||
pub mod beacon_proposer_cache;
|
||||
mod beacon_snapshot;
|
||||
mod blob_verification;
|
||||
pub mod block_reward;
|
||||
mod block_times_cache;
|
||||
mod block_verification;
|
||||
|
@ -14,7 +14,7 @@ use types::*;
|
||||
///
|
||||
/// Utilises lazy-loading from separate storage for its vector fields.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge),
|
||||
variants(Base, Altair, Merge, Shanghai),
|
||||
variant_attributes(derive(Debug, PartialEq, Clone, Encode, Decode))
|
||||
)]
|
||||
#[derive(Debug, PartialEq, Clone, Encode)]
|
||||
@ -66,9 +66,9 @@ where
|
||||
pub current_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>,
|
||||
|
||||
// Participation (Altair and later)
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub previous_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub current_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||
|
||||
// Finality
|
||||
@ -78,17 +78,17 @@ where
|
||||
pub finalized_checkpoint: Checkpoint,
|
||||
|
||||
// Inactivity
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub inactivity_scores: VariableList<u64, T::ValidatorRegistryLimit>,
|
||||
|
||||
// Light-client sync committees
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub current_sync_committee: Arc<SyncCommittee<T>>,
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub next_sync_committee: Arc<SyncCommittee<T>>,
|
||||
|
||||
// Execution
|
||||
#[superstruct(only(Merge))]
|
||||
#[superstruct(only(Merge, Shanghai))]
|
||||
pub latest_execution_payload_header: ExecutionPayloadHeader<T>,
|
||||
}
|
||||
|
||||
@ -178,6 +178,20 @@ impl<T: EthSpec> PartialBeaconState<T> {
|
||||
latest_execution_payload_header
|
||||
]
|
||||
),
|
||||
BeaconState::Shanghai(s) => impl_from_state_forgetful!(
|
||||
s,
|
||||
outer,
|
||||
Shanghai,
|
||||
PartialBeaconStateShanghai,
|
||||
[
|
||||
previous_epoch_participation,
|
||||
current_epoch_participation,
|
||||
current_sync_committee,
|
||||
next_sync_committee,
|
||||
inactivity_scores,
|
||||
latest_execution_payload_header
|
||||
]
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@ -365,6 +379,19 @@ impl<E: EthSpec> TryInto<BeaconState<E>> for PartialBeaconState<E> {
|
||||
latest_execution_payload_header
|
||||
]
|
||||
),
|
||||
PartialBeaconState::Shanghai(inner) => impl_try_into_beacon_state!(
|
||||
inner,
|
||||
Shanghai,
|
||||
BeaconStateShanghai,
|
||||
[
|
||||
previous_epoch_participation,
|
||||
current_epoch_participation,
|
||||
current_sync_committee,
|
||||
next_sync_committee,
|
||||
inactivity_scores,
|
||||
latest_execution_payload_header
|
||||
]
|
||||
),
|
||||
};
|
||||
Ok(state)
|
||||
}
|
||||
|
@ -45,9 +45,11 @@ pub fn slash_validator<T: EthSpec>(
|
||||
validator_effective_balance.safe_div(spec.whistleblower_reward_quotient)?;
|
||||
let proposer_reward = match state {
|
||||
BeaconState::Base(_) => whistleblower_reward.safe_div(spec.proposer_reward_quotient)?,
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => whistleblower_reward
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
whistleblower_reward
|
||||
.safe_mul(PROPOSER_WEIGHT)?
|
||||
.safe_div(WEIGHT_DENOMINATOR)?,
|
||||
.safe_div(WEIGHT_DENOMINATOR)?
|
||||
}
|
||||
};
|
||||
|
||||
// Ensure the whistleblower index is in the validator registry.
|
||||
|
@ -37,7 +37,9 @@ pub fn process_epoch<T: EthSpec>(
|
||||
|
||||
match state {
|
||||
BeaconState::Base(_) => base::process_epoch(state, spec),
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => altair::process_epoch(state, spec),
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_epoch(state, spec)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ impl From<BeaconStateHash> for Hash256 {
|
||||
|
||||
/// The state of the `BeaconChain` at some slot.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge),
|
||||
variants(Base, Altair, Merge, Shanghai),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Derivative,
|
||||
@ -250,9 +250,9 @@ where
|
||||
pub current_epoch_attestations: VariableList<PendingAttestation<T>, T::MaxPendingAttestations>,
|
||||
|
||||
// Participation (Altair and later)
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub previous_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub current_epoch_participation: VariableList<ParticipationFlags, T::ValidatorRegistryLimit>,
|
||||
|
||||
// Finality
|
||||
@ -267,17 +267,17 @@ where
|
||||
|
||||
// Inactivity
|
||||
#[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")]
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub inactivity_scores: VariableList<u64, T::ValidatorRegistryLimit>,
|
||||
|
||||
// Light-client sync committees
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub current_sync_committee: Arc<SyncCommittee<T>>,
|
||||
#[superstruct(only(Altair, Merge))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub next_sync_committee: Arc<SyncCommittee<T>>,
|
||||
|
||||
// Execution
|
||||
#[superstruct(only(Merge))]
|
||||
#[superstruct(only(Merge, Shanghai))]
|
||||
pub latest_execution_payload_header: ExecutionPayloadHeader<T>,
|
||||
|
||||
// Caching (not in the spec)
|
||||
@ -389,6 +389,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
BeaconState::Base { .. } => ForkName::Base,
|
||||
BeaconState::Altair { .. } => ForkName::Altair,
|
||||
BeaconState::Merge { .. } => ForkName::Merge,
|
||||
BeaconState::Shanghai { .. } => ForkName::Shanghai,
|
||||
};
|
||||
|
||||
if fork_at_slot == object_fork {
|
||||
@ -1102,6 +1103,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
BeaconState::Base(state) => (&mut state.validators, &mut state.balances),
|
||||
BeaconState::Altair(state) => (&mut state.validators, &mut state.balances),
|
||||
BeaconState::Merge(state) => (&mut state.validators, &mut state.balances),
|
||||
BeaconState::Shanghai(state) => (&mut state.validators, &mut state.balances),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1298,12 +1300,14 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
|
||||
BeaconState::Altair(state) => Ok(&mut state.current_epoch_participation),
|
||||
BeaconState::Merge(state) => Ok(&mut state.current_epoch_participation),
|
||||
BeaconState::Shanghai(state) => Ok(&mut state.current_epoch_participation),
|
||||
}
|
||||
} else if epoch == self.previous_epoch() {
|
||||
match self {
|
||||
BeaconState::Base(_) => Err(BeaconStateError::IncorrectStateVariant),
|
||||
BeaconState::Altair(state) => Ok(&mut state.previous_epoch_participation),
|
||||
BeaconState::Merge(state) => Ok(&mut state.previous_epoch_participation),
|
||||
BeaconState::Shanghai(state) => Ok(&mut state.previous_epoch_participation),
|
||||
}
|
||||
} else {
|
||||
Err(BeaconStateError::EpochOutOfBounds)
|
||||
@ -1608,6 +1612,7 @@ impl<T: EthSpec> BeaconState<T> {
|
||||
BeaconState::Base(inner) => BeaconState::Base(inner.clone()),
|
||||
BeaconState::Altair(inner) => BeaconState::Altair(inner.clone()),
|
||||
BeaconState::Merge(inner) => BeaconState::Merge(inner.clone()),
|
||||
BeaconState::Shanghai(inner) => BeaconState::Shanghai(inner.clone()),
|
||||
};
|
||||
if config.committee_caches {
|
||||
*res.committee_caches_mut() = self.committee_caches().clone();
|
||||
|
@ -274,6 +274,7 @@ impl ChainSpec {
|
||||
BeaconState::Base(_) => self.inactivity_penalty_quotient,
|
||||
BeaconState::Altair(_) => self.inactivity_penalty_quotient_altair,
|
||||
BeaconState::Merge(_) => self.inactivity_penalty_quotient_bellatrix,
|
||||
BeaconState::Shanghai(_) => self.inactivity_penalty_quotient_bellatrix,
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,6 +287,7 @@ impl ChainSpec {
|
||||
BeaconState::Base(_) => self.proportional_slashing_multiplier,
|
||||
BeaconState::Altair(_) => self.proportional_slashing_multiplier_altair,
|
||||
BeaconState::Merge(_) => self.proportional_slashing_multiplier_bellatrix,
|
||||
BeaconState::Shanghai(_) => self.proportional_slashing_multiplier_bellatrix,
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,6 +300,7 @@ impl ChainSpec {
|
||||
BeaconState::Base(_) => self.min_slashing_penalty_quotient,
|
||||
BeaconState::Altair(_) => self.min_slashing_penalty_quotient_altair,
|
||||
BeaconState::Merge(_) => self.min_slashing_penalty_quotient_bellatrix,
|
||||
BeaconState::Shanghai(_) => self.min_slashing_penalty_quotient_bellatrix,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ impl<E: EthSpec> EpochTransition<E> for JustificationAndFinalization {
|
||||
justification_and_finalization_state.apply_changes_to_state(state);
|
||||
Ok(())
|
||||
}
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => {
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
let justification_and_finalization_state =
|
||||
altair::process_justification_and_finalization(
|
||||
state,
|
||||
@ -118,7 +118,7 @@ impl<E: EthSpec> EpochTransition<E> for RewardsAndPenalties {
|
||||
validator_statuses.process_attestations(state)?;
|
||||
base::process_rewards_and_penalties(state, &mut validator_statuses, spec)
|
||||
}
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => {
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_rewards_and_penalties(
|
||||
state,
|
||||
&altair::ParticipationCache::new(state, spec).unwrap(),
|
||||
@ -147,7 +147,7 @@ impl<E: EthSpec> EpochTransition<E> for Slashings {
|
||||
spec,
|
||||
)?;
|
||||
}
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => {
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
process_slashings(
|
||||
state,
|
||||
altair::ParticipationCache::new(state, spec)
|
||||
@ -205,7 +205,7 @@ impl<E: EthSpec> EpochTransition<E> for SyncCommitteeUpdates {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
match state {
|
||||
BeaconState::Base(_) => Ok(()),
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => {
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_sync_committee_updates(state, spec)
|
||||
}
|
||||
}
|
||||
@ -216,11 +216,13 @@ impl<E: EthSpec> EpochTransition<E> for InactivityUpdates {
|
||||
fn run(state: &mut BeaconState<E>, spec: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
match state {
|
||||
BeaconState::Base(_) => Ok(()),
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => altair::process_inactivity_updates(
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_inactivity_updates(
|
||||
state,
|
||||
&altair::ParticipationCache::new(state, spec).unwrap(),
|
||||
spec,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,7 +231,7 @@ impl<E: EthSpec> EpochTransition<E> for ParticipationFlagUpdates {
|
||||
fn run(state: &mut BeaconState<E>, _: &ChainSpec) -> Result<(), EpochProcessingError> {
|
||||
match state {
|
||||
BeaconState::Base(_) => Ok(()),
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => {
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_participation_flag_updates(state)
|
||||
}
|
||||
}
|
||||
|
@ -81,14 +81,16 @@ impl<E: EthSpec> Operation<E> for Attestation<E> {
|
||||
BeaconState::Base(_) => {
|
||||
base::process_attestations(state, &[self.clone()], VerifySignatures::True, spec)
|
||||
}
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) => altair::process_attestation(
|
||||
BeaconState::Altair(_) | BeaconState::Merge(_) | BeaconState::Shanghai(_) => {
|
||||
altair::process_attestation(
|
||||
state,
|
||||
self,
|
||||
0,
|
||||
proposer_index,
|
||||
VerifySignatures::True,
|
||||
spec,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user