mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
add shanghai fork version and epoch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::beacon_block_body::{
|
||||
BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyDank, BeaconBlockBodyMerge,
|
||||
BeaconBlockBodyRef, BeaconBlockBodyRefMut,
|
||||
BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyMerge, BeaconBlockBodyRef,
|
||||
BeaconBlockBodyRefMut, BeaconBlockBodyShanghai,
|
||||
};
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::*;
|
||||
@@ -17,7 +17,7 @@ use tree_hash_derive::TreeHash;
|
||||
|
||||
/// A block of the `BeaconChain`.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variants(Base, Altair, Merge, Shanghai),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -64,8 +64,8 @@ pub struct BeaconBlock<T: EthSpec, Payload: ExecPayload<T> = FullPayload<T>> {
|
||||
pub body: BeaconBlockBodyAltair<T, Payload>,
|
||||
#[superstruct(only(Merge), partial_getter(rename = "body_merge"))]
|
||||
pub body: BeaconBlockBodyMerge<T, Payload>,
|
||||
#[superstruct(only(Dank), partial_getter(rename = "body_dank"))]
|
||||
pub body: BeaconBlockBodyDank<T, Payload>,
|
||||
#[superstruct(only(Shanghai), partial_getter(rename = "body_shanghai"))]
|
||||
pub body: BeaconBlockBodyShanghai<T, Payload>,
|
||||
}
|
||||
|
||||
pub type BlindedBeaconBlock<E> = BeaconBlock<E, BlindedPayload<E>>;
|
||||
@@ -191,7 +191,7 @@ impl<'a, T: EthSpec, Payload: ExecPayload<T>> BeaconBlockRef<'a, T, Payload> {
|
||||
BeaconBlockRef::Base { .. } => ForkName::Base,
|
||||
BeaconBlockRef::Altair { .. } => ForkName::Altair,
|
||||
BeaconBlockRef::Merge { .. } => ForkName::Merge,
|
||||
BeaconBlockRef::Dank { .. } => ForkName::Dank,
|
||||
BeaconBlockRef::Shanghai { .. } => ForkName::Shanghai,
|
||||
};
|
||||
|
||||
if fork_at_slot == object_fork {
|
||||
|
||||
@@ -13,7 +13,7 @@ use tree_hash_derive::TreeHash;
|
||||
///
|
||||
/// This *superstruct* abstracts over the hard-fork.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variants(Base, Altair, Merge, Shanghai),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -47,15 +47,15 @@ pub struct BeaconBlockBody<T: EthSpec, Payload: ExecPayload<T> = FullPayload<T>>
|
||||
pub attestations: VariableList<Attestation<T>, T::MaxAttestations>,
|
||||
pub deposits: VariableList<Deposit, T::MaxDeposits>,
|
||||
pub voluntary_exits: VariableList<SignedVoluntaryExit, T::MaxVoluntaryExits>,
|
||||
#[superstruct(only(Altair, Merge, Dank))]
|
||||
#[superstruct(only(Altair, Merge, Shanghai))]
|
||||
pub sync_aggregate: SyncAggregate<T>,
|
||||
// We flatten the execution payload so that serde can use the name of the inner type,
|
||||
// either `execution_payload` for full payloads, or `execution_payload_header` for blinded
|
||||
// payloads.
|
||||
#[superstruct(only(Merge, Dank))]
|
||||
#[superstruct(only(Merge, Shanghai))]
|
||||
#[serde(flatten)]
|
||||
pub execution_payload: Payload,
|
||||
#[superstruct(only(Dank))]
|
||||
#[superstruct(only(Shanghai))]
|
||||
pub blob_kzgs: VariableList<KZGCommitment, T::MaxObjectListSize>,
|
||||
#[superstruct(only(Base, Altair))]
|
||||
#[ssz(skip_serializing, skip_deserializing)]
|
||||
@@ -71,7 +71,7 @@ impl<'a, T: EthSpec> BeaconBlockBodyRef<'a, T> {
|
||||
BeaconBlockBodyRef::Base { .. } => ForkName::Base,
|
||||
BeaconBlockBodyRef::Altair { .. } => ForkName::Altair,
|
||||
BeaconBlockBodyRef::Merge { .. } => ForkName::Merge,
|
||||
BeaconBlockBodyRef::Dank { .. } => ForkName::Dank,
|
||||
BeaconBlockBodyRef::Shanghai { .. } => ForkName::Shanghai,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::{Blob, EthSpec, SignedBeaconBlock};
|
||||
use crate::{Blob, EthSpec, Hash256, SignedBeaconBlock, Slot};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Encode};
|
||||
use ssz_types::{VariableList};
|
||||
use ssz_derive::Encode;
|
||||
use ssz_types::VariableList;
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
#[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash)]
|
||||
pub struct BeaconBlockAndBlobs<E: EthSpec> {
|
||||
pub block: SignedBeaconBlock<E>,
|
||||
pub struct BlobWrapper<E: EthSpec> {
|
||||
pub beacon_block_root: Hash256,
|
||||
pub beacon_block_slot: Slot,
|
||||
pub blobs: VariableList<Blob<E::ChunksPerBlob>, E::MaxObjectListSize>,
|
||||
}
|
||||
@@ -151,8 +151,10 @@ pub struct ChainSpec {
|
||||
pub safe_slots_to_import_optimistically: u64,
|
||||
|
||||
/*
|
||||
* Danksharding hard fork params
|
||||
*/
|
||||
* Shanghai hard fork params
|
||||
*/
|
||||
pub shanghai_fork_version: [u8; 4],
|
||||
pub shanghai_fork_epoch: Option<Epoch>,
|
||||
|
||||
/*
|
||||
* Networking
|
||||
@@ -234,11 +236,14 @@ impl ChainSpec {
|
||||
|
||||
/// Returns the name of the fork which is active at `epoch`.
|
||||
pub fn fork_name_at_epoch(&self, epoch: Epoch) -> ForkName {
|
||||
match self.bellatrix_fork_epoch {
|
||||
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Merge,
|
||||
_ => match self.altair_fork_epoch {
|
||||
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Altair,
|
||||
_ => ForkName::Base,
|
||||
match self.shanghai_fork_epoch {
|
||||
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Shanghai,
|
||||
_ => match self.bellatrix_fork_epoch {
|
||||
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Merge,
|
||||
_ => match self.altair_fork_epoch {
|
||||
Some(fork_epoch) if epoch >= fork_epoch => ForkName::Altair,
|
||||
_ => ForkName::Base,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -249,8 +254,7 @@ impl ChainSpec {
|
||||
ForkName::Base => self.genesis_fork_version,
|
||||
ForkName::Altair => self.altair_fork_version,
|
||||
ForkName::Merge => self.bellatrix_fork_version,
|
||||
//TODO: update this
|
||||
ForkName::Dank => self.bellatrix_fork_version,
|
||||
ForkName::Shanghai => self.shanghai_fork_version,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,8 +264,7 @@ impl ChainSpec {
|
||||
ForkName::Base => Some(Epoch::new(0)),
|
||||
ForkName::Altair => self.altair_fork_epoch,
|
||||
ForkName::Merge => self.bellatrix_fork_epoch,
|
||||
//TODO: update this
|
||||
ForkName::Dank => self.bellatrix_fork_epoch,
|
||||
ForkName::Shanghai => self.shanghai_fork_epoch,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,6 +579,13 @@ impl ChainSpec {
|
||||
terminal_block_hash_activation_epoch: Epoch::new(u64::MAX),
|
||||
safe_slots_to_import_optimistically: 128u64,
|
||||
|
||||
/*
|
||||
* Shanghai hardfork params
|
||||
*/
|
||||
//FIXME(sean)
|
||||
shanghai_fork_version: [0x03, 0x00, 0x00, 0x00],
|
||||
shanghai_fork_epoch: None,
|
||||
|
||||
/*
|
||||
* Network specific
|
||||
*/
|
||||
@@ -631,6 +641,10 @@ impl ChainSpec {
|
||||
// `Uint256::MAX` which is `2*256- 1`.
|
||||
.checked_add(Uint256::one())
|
||||
.expect("addition does not overflow"),
|
||||
// Shanghai
|
||||
//FIXME(sean)
|
||||
shanghai_fork_version: [0x03, 0x00, 0x00, 0x01],
|
||||
shanghai_fork_epoch: None,
|
||||
// Other
|
||||
network_id: 2, // lighthouse testnet network id
|
||||
deposit_chain_id: 5,
|
||||
@@ -786,6 +800,10 @@ impl ChainSpec {
|
||||
terminal_block_hash_activation_epoch: Epoch::new(u64::MAX),
|
||||
safe_slots_to_import_optimistically: 128u64,
|
||||
|
||||
//FIXME(sean)
|
||||
shanghai_fork_version: [0x03, 0x00, 0x00, 0x64],
|
||||
shanghai_fork_epoch: None,
|
||||
|
||||
/*
|
||||
* Network specific
|
||||
*/
|
||||
@@ -861,6 +879,16 @@ pub struct Config {
|
||||
#[serde(deserialize_with = "deserialize_fork_epoch")]
|
||||
pub bellatrix_fork_epoch: Option<MaybeQuoted<Epoch>>,
|
||||
|
||||
// FIXME(sean): remove this default
|
||||
#[serde(default = "default_shanghai_fork_version")]
|
||||
#[serde(with = "eth2_serde_utils::bytes_4_hex")]
|
||||
shanghai_fork_version: [u8; 4],
|
||||
// FIXME(sean): remove this default
|
||||
#[serde(default = "default_shanghai_fork_epoch")]
|
||||
#[serde(serialize_with = "serialize_fork_epoch")]
|
||||
#[serde(deserialize_with = "deserialize_fork_epoch")]
|
||||
pub shanghai_fork_epoch: Option<MaybeQuoted<Epoch>>,
|
||||
|
||||
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||
seconds_per_slot: u64,
|
||||
#[serde(with = "eth2_serde_utils::quoted_u64")]
|
||||
@@ -898,6 +926,11 @@ fn default_bellatrix_fork_version() -> [u8; 4] {
|
||||
[0xff, 0xff, 0xff, 0xff]
|
||||
}
|
||||
|
||||
fn default_shanghai_fork_version() -> [u8; 4] {
|
||||
// This value shouldn't be used.
|
||||
[0xff, 0xff, 0xff, 0xff]
|
||||
}
|
||||
|
||||
/// Placeholder value: 2^256-2^10 (115792089237316195423570985008687907853269984665640564039457584007913129638912).
|
||||
///
|
||||
/// Taken from https://github.com/ethereum/consensus-specs/blob/d5e4828aecafaf1c57ef67a5f23c4ae7b08c5137/configs/mainnet.yaml#L15-L16
|
||||
@@ -994,6 +1027,10 @@ impl Config {
|
||||
bellatrix_fork_epoch: spec
|
||||
.bellatrix_fork_epoch
|
||||
.map(|epoch| MaybeQuoted { value: epoch }),
|
||||
shanghai_fork_version: spec.shanghai_fork_version,
|
||||
shanghai_fork_epoch: spec
|
||||
.shanghai_fork_epoch
|
||||
.map(|epoch| MaybeQuoted { value: epoch }),
|
||||
|
||||
seconds_per_slot: spec.seconds_per_slot,
|
||||
seconds_per_eth1_block: spec.seconds_per_eth1_block,
|
||||
@@ -1039,6 +1076,8 @@ impl Config {
|
||||
altair_fork_epoch,
|
||||
bellatrix_fork_epoch,
|
||||
bellatrix_fork_version,
|
||||
shanghai_fork_epoch,
|
||||
shanghai_fork_version,
|
||||
seconds_per_slot,
|
||||
seconds_per_eth1_block,
|
||||
min_validator_withdrawability_delay,
|
||||
@@ -1069,6 +1108,8 @@ impl Config {
|
||||
altair_fork_epoch: altair_fork_epoch.map(|q| q.value),
|
||||
bellatrix_fork_epoch: bellatrix_fork_epoch.map(|q| q.value),
|
||||
bellatrix_fork_version,
|
||||
shanghai_fork_epoch: shanghai_fork_epoch.map(|q| q.value),
|
||||
shanghai_fork_version,
|
||||
seconds_per_slot,
|
||||
seconds_per_eth1_block,
|
||||
min_validator_withdrawability_delay,
|
||||
|
||||
@@ -96,7 +96,7 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
|
||||
type MinGasLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type MaxExtraDataBytes: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
/*
|
||||
* New in Danksharding
|
||||
* New in Shanghaisharding
|
||||
*/
|
||||
type MaxObjectListSize: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type ChunksPerBlob: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
|
||||
@@ -47,6 +47,13 @@ impl ForkContext {
|
||||
));
|
||||
}
|
||||
|
||||
if spec.shanghai_fork_epoch.is_some() {
|
||||
fork_to_digest.push((
|
||||
ForkName::Shanghai,
|
||||
ChainSpec::compute_fork_digest(spec.shanghai_fork_version, genesis_validators_root),
|
||||
));
|
||||
}
|
||||
|
||||
let fork_to_digest: HashMap<ForkName, [u8; 4]> = fork_to_digest.into_iter().collect();
|
||||
|
||||
let digest_to_fork = fork_to_digest
|
||||
|
||||
@@ -11,7 +11,7 @@ pub enum ForkName {
|
||||
Base,
|
||||
Altair,
|
||||
Merge,
|
||||
Dank,
|
||||
Shanghai,
|
||||
}
|
||||
|
||||
impl ForkName {
|
||||
@@ -39,10 +39,9 @@ impl ForkName {
|
||||
spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
spec
|
||||
}
|
||||
//TODO(sean): update
|
||||
ForkName::Dank => {
|
||||
spec.altair_fork_epoch = Some(Epoch::new(0));
|
||||
ForkName::Shanghai => {
|
||||
spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
spec.shanghai_fork_epoch = Some(Epoch::new(0));
|
||||
spec
|
||||
}
|
||||
}
|
||||
@@ -56,7 +55,7 @@ impl ForkName {
|
||||
ForkName::Base => None,
|
||||
ForkName::Altair => Some(ForkName::Base),
|
||||
ForkName::Merge => Some(ForkName::Altair),
|
||||
ForkName::Dank => Some(ForkName::Merge),
|
||||
ForkName::Shanghai => Some(ForkName::Merge),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,8 +66,8 @@ impl ForkName {
|
||||
match self {
|
||||
ForkName::Base => Some(ForkName::Altair),
|
||||
ForkName::Altair => Some(ForkName::Merge),
|
||||
ForkName::Merge => Some(ForkName::Dank),
|
||||
ForkName::Dank => None,
|
||||
ForkName::Merge => Some(ForkName::Shanghai),
|
||||
ForkName::Shanghai => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,7 +110,7 @@ macro_rules! map_fork_name_with {
|
||||
($t::Merge(value), extra_data)
|
||||
}
|
||||
//TODO: don't have a beacon state variant for the new fork yet
|
||||
ForkName::Dank => {
|
||||
ForkName::Shanghai => {
|
||||
let (value, extra_data) = $body;
|
||||
($t::Merge(value), extra_data)
|
||||
}
|
||||
@@ -138,7 +137,7 @@ impl Display for ForkName {
|
||||
ForkName::Base => "phase0".fmt(f),
|
||||
ForkName::Altair => "altair".fmt(f),
|
||||
ForkName::Merge => "bellatrix".fmt(f),
|
||||
ForkName::Dank => "dank".fmt(f),
|
||||
ForkName::Shanghai => "shanghai".fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ pub mod sync_subnet_id;
|
||||
mod tree_hash_impls;
|
||||
pub mod validator_registration_data;
|
||||
|
||||
mod beacon_block_and_blobs;
|
||||
mod blob_wrapper;
|
||||
mod kzg_commitment;
|
||||
pub mod slot_data;
|
||||
#[cfg(feature = "sqlite")]
|
||||
@@ -101,12 +101,12 @@ pub use crate::attestation_data::AttestationData;
|
||||
pub use crate::attestation_duty::AttestationDuty;
|
||||
pub use crate::attester_slashing::AttesterSlashing;
|
||||
pub use crate::beacon_block::{
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockDank, BeaconBlockMerge, BeaconBlockRef,
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockShanghai, BeaconBlockMerge, BeaconBlockRef,
|
||||
BeaconBlockRefMut, BlindedBeaconBlock,
|
||||
};
|
||||
pub use crate::beacon_block_body::{
|
||||
BeaconBlockBody, BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyDank,
|
||||
BeaconBlockBodyMerge, BeaconBlockBodyRef, BeaconBlockBodyRefMut,
|
||||
BeaconBlockBody, BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyMerge,
|
||||
BeaconBlockBodyRef, BeaconBlockBodyRefMut, BeaconBlockBodyShanghai,
|
||||
};
|
||||
pub use crate::beacon_block_header::BeaconBlockHeader;
|
||||
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
|
||||
@@ -147,7 +147,7 @@ pub use crate::shuffling_id::AttestationShufflingId;
|
||||
pub use crate::signed_aggregate_and_proof::SignedAggregateAndProof;
|
||||
pub use crate::signed_beacon_block::{
|
||||
SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockHash,
|
||||
SignedBeaconBlockMerge, SignedBlindedBeaconBlock,SignedBeaconBlockDank
|
||||
SignedBeaconBlockMerge, SignedBlindedBeaconBlock,SignedBeaconBlockShanghai
|
||||
};
|
||||
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
|
||||
pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
|
||||
|
||||
@@ -38,7 +38,7 @@ impl From<SignedBeaconBlockHash> for Hash256 {
|
||||
|
||||
/// A `BeaconBlock` and a signature from its proposer.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variants(Base, Altair, Merge, Shanghai),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -72,8 +72,8 @@ pub struct SignedBeaconBlock<E: EthSpec, Payload: ExecPayload<E> = FullPayload<E
|
||||
pub message: BeaconBlockAltair<E, Payload>,
|
||||
#[superstruct(only(Merge), partial_getter(rename = "message_merge"))]
|
||||
pub message: BeaconBlockMerge<E, Payload>,
|
||||
#[superstruct(only(Dank), partial_getter(rename = "message_dank"))]
|
||||
pub message: BeaconBlockDank<E, Payload>,
|
||||
#[superstruct(only(Shanghai), partial_getter(rename = "message_shanghai"))]
|
||||
pub message: BeaconBlockShanghai<E, Payload>,
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
@@ -131,8 +131,8 @@ impl<E: EthSpec, Payload: ExecPayload<E>> SignedBeaconBlock<E, Payload> {
|
||||
BeaconBlock::Merge(message) => {
|
||||
SignedBeaconBlock::Merge(SignedBeaconBlockMerge { message, signature })
|
||||
}
|
||||
BeaconBlock::Dank(message) => {
|
||||
SignedBeaconBlock::Dank(SignedBeaconBlockDank { message, signature })
|
||||
BeaconBlock::Shanghai(message) => {
|
||||
SignedBeaconBlock::Shanghai(SignedBeaconBlockShanghai { message, signature })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user