mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-16 20:39:10 +00:00
add/update types
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::beacon_block_body::{
|
||||
BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyMerge, BeaconBlockBodyRef,
|
||||
BeaconBlockBodyRefMut,
|
||||
BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyDank, BeaconBlockBodyMerge,
|
||||
BeaconBlockBodyRef, BeaconBlockBodyRefMut,
|
||||
};
|
||||
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),
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -64,6 +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>,
|
||||
}
|
||||
|
||||
pub type BlindedBeaconBlock<E> = BeaconBlock<E, BlindedPayload<E>>;
|
||||
@@ -189,6 +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,
|
||||
};
|
||||
|
||||
if fork_at_slot == object_fork {
|
||||
|
||||
13
consensus/types/src/beacon_block_and_blobs.rs
Normal file
13
consensus/types/src/beacon_block_and_blobs.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::{BLSFieldElement, Blob, EthSpec, SignedBeaconBlock};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::{FixedVector, 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 blobs: VariableList<Blob<E::ChunksPerBlob>, E::MaxObjectListSize>,
|
||||
}
|
||||
@@ -13,7 +13,7 @@ use tree_hash_derive::TreeHash;
|
||||
///
|
||||
/// This *superstruct* abstracts over the hard-fork.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge),
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -47,14 +47,16 @@ 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))]
|
||||
#[superstruct(only(Altair, Merge, Dank))]
|
||||
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))]
|
||||
#[superstruct(only(Merge, Dank))]
|
||||
#[serde(flatten)]
|
||||
pub execution_payload: Payload,
|
||||
#[superstruct(only(Dank))]
|
||||
pub blob_kzgs: VariableList<KZGCommitment, T::MaxObjectListSize>,
|
||||
#[superstruct(only(Base, Altair))]
|
||||
#[ssz(skip_serializing, skip_deserializing)]
|
||||
#[tree_hash(skip_hashing)]
|
||||
@@ -69,6 +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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +150,10 @@ pub struct ChainSpec {
|
||||
pub terminal_block_hash_activation_epoch: Epoch,
|
||||
pub safe_slots_to_import_optimistically: u64,
|
||||
|
||||
/*
|
||||
* Danksharding hard fork params
|
||||
*/
|
||||
|
||||
/*
|
||||
* Networking
|
||||
*/
|
||||
@@ -245,6 +249,8 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +260,8 @@ 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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
|
||||
type GasLimitDenominator: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type MinGasLimit: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type MaxExtraDataBytes: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
/*
|
||||
* New in Danksharding
|
||||
*/
|
||||
type MaxObjectListSize: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
type ChunksPerBlob: Unsigned + Clone + Sync + Send + Debug + PartialEq;
|
||||
/*
|
||||
* Derived values (set these CAREFULLY)
|
||||
*/
|
||||
@@ -262,6 +267,8 @@ impl EthSpec for MainnetEthSpec {
|
||||
type GasLimitDenominator = U1024;
|
||||
type MinGasLimit = U5000;
|
||||
type MaxExtraDataBytes = U32;
|
||||
type MaxObjectListSize = U16777216; // 2**24
|
||||
type ChunksPerBlob = U4096;
|
||||
type SyncSubcommitteeSize = U128; // 512 committee size / 4 sync committee subnet count
|
||||
type MaxPendingAttestations = U4096; // 128 max attestations * 32 slots per epoch
|
||||
type SlotsPerEth1VotingPeriod = U2048; // 64 epochs * 32 slots per epoch
|
||||
@@ -309,7 +316,9 @@ impl EthSpec for MinimalEthSpec {
|
||||
BytesPerLogsBloom,
|
||||
GasLimitDenominator,
|
||||
MinGasLimit,
|
||||
MaxExtraDataBytes
|
||||
MaxExtraDataBytes,
|
||||
MaxObjectListSize,
|
||||
ChunksPerBlob
|
||||
});
|
||||
|
||||
fn default_spec() -> ChainSpec {
|
||||
@@ -354,6 +363,8 @@ impl EthSpec for GnosisEthSpec {
|
||||
type SyncSubcommitteeSize = U128; // 512 committee size / 4 sync committee subnet count
|
||||
type MaxPendingAttestations = U2048; // 128 max attestations * 16 slots per epoch
|
||||
type SlotsPerEth1VotingPeriod = U1024; // 64 epochs * 16 slots per epoch
|
||||
type MaxObjectListSize = U16777216; // 2**24
|
||||
type ChunksPerBlob = U4096;
|
||||
|
||||
fn default_spec() -> ChainSpec {
|
||||
ChainSpec::gnosis()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{ChainSpec, Epoch};
|
||||
use crate::{ChainSpec, Epoch, Fork};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
@@ -11,6 +11,7 @@ pub enum ForkName {
|
||||
Base,
|
||||
Altair,
|
||||
Merge,
|
||||
Dank,
|
||||
}
|
||||
|
||||
impl ForkName {
|
||||
@@ -38,6 +39,12 @@ impl ForkName {
|
||||
spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
spec
|
||||
}
|
||||
//TODO(sean): update
|
||||
ForkName::Dank => {
|
||||
spec.altair_fork_epoch = Some(Epoch::new(0));
|
||||
spec.bellatrix_fork_epoch = Some(Epoch::new(0));
|
||||
spec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +56,7 @@ impl ForkName {
|
||||
ForkName::Base => None,
|
||||
ForkName::Altair => Some(ForkName::Base),
|
||||
ForkName::Merge => Some(ForkName::Altair),
|
||||
ForkName::Dank => Some(ForkName::Merge),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +67,8 @@ impl ForkName {
|
||||
match self {
|
||||
ForkName::Base => Some(ForkName::Altair),
|
||||
ForkName::Altair => Some(ForkName::Merge),
|
||||
ForkName::Merge => None,
|
||||
ForkName::Merge => Some(ForkName::Dank),
|
||||
ForkName::Dank => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,6 +110,11 @@ macro_rules! map_fork_name_with {
|
||||
let (value, extra_data) = $body;
|
||||
($t::Merge(value), extra_data)
|
||||
}
|
||||
//TODO: don't have a beacon state variant for the new fork yet
|
||||
ForkName::Dank => {
|
||||
let (value, extra_data) = $body;
|
||||
($t::Merge(value), extra_data)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -124,6 +138,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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
63
consensus/types/src/kzg_commitment.rs
Normal file
63
consensus/types/src/kzg_commitment.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::*;
|
||||
use derivative::Derivative;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::{Decode, DecodeError, Encode};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use ssz_types::VariableList;
|
||||
use superstruct::superstruct;
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
//TODO: is there a way around this newtype
|
||||
#[derive(Derivative, Debug, Clone, Serialize, Deserialize)]
|
||||
#[derivative(PartialEq, Eq, Hash)]
|
||||
pub struct KZGCommitment(#[serde(with = "BigArray")] [u8; 48]);
|
||||
impl TreeHash for KZGCommitment {
|
||||
fn tree_hash_type() -> tree_hash::TreeHashType {
|
||||
<[u8; 48] as TreeHash>::tree_hash_type()
|
||||
}
|
||||
|
||||
fn tree_hash_packed_encoding(&self) -> Vec<u8> {
|
||||
self.0.tree_hash_packed_encoding()
|
||||
}
|
||||
|
||||
fn tree_hash_packing_factor() -> usize {
|
||||
<[u8; 48] as TreeHash>::tree_hash_packing_factor()
|
||||
}
|
||||
|
||||
fn tree_hash_root(&self) -> tree_hash::Hash256 {
|
||||
self.0.tree_hash_root()
|
||||
}
|
||||
}
|
||||
|
||||
impl TestRandom for KZGCommitment {
|
||||
fn random_for_test(rng: &mut impl rand::RngCore) -> Self {
|
||||
KZGCommitment(<[u8; 48] as TestRandom>::random_for_test(rng))
|
||||
}
|
||||
}
|
||||
|
||||
impl Decode for KZGCommitment {
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
<[u8; 48] as Decode>::is_ssz_fixed_len()
|
||||
}
|
||||
|
||||
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError> {
|
||||
<[u8; 48] as Decode>::from_ssz_bytes(bytes).map(KZGCommitment)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encode for KZGCommitment {
|
||||
fn is_ssz_fixed_len() -> bool {
|
||||
<[u8; 48] as Encode>::is_ssz_fixed_len()
|
||||
}
|
||||
|
||||
fn ssz_append(&self, buf: &mut Vec<u8>) {
|
||||
self.0.ssz_append(buf)
|
||||
}
|
||||
|
||||
fn ssz_bytes_len(&self) -> usize {
|
||||
self.0.ssz_bytes_len()
|
||||
}
|
||||
}
|
||||
@@ -86,11 +86,15 @@ pub mod sync_subnet_id;
|
||||
mod tree_hash_impls;
|
||||
pub mod validator_registration_data;
|
||||
|
||||
mod beacon_block_and_blobs;
|
||||
mod kzg_commitment;
|
||||
pub mod slot_data;
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub mod sqlite;
|
||||
pub use kzg_commitment::KZGCommitment;
|
||||
|
||||
use ethereum_types::{H160, H256};
|
||||
use serde::Serialize;
|
||||
|
||||
pub use crate::aggregate_and_proof::AggregateAndProof;
|
||||
pub use crate::attestation::{Attestation, Error as AttestationError};
|
||||
@@ -98,12 +102,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, BeaconBlockMerge, BeaconBlockRef,
|
||||
BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockDank, BeaconBlockMerge, BeaconBlockRef,
|
||||
BeaconBlockRefMut, BlindedBeaconBlock,
|
||||
};
|
||||
pub use crate::beacon_block_body::{
|
||||
BeaconBlockBody, BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyMerge,
|
||||
BeaconBlockBodyRef, BeaconBlockBodyRefMut,
|
||||
BeaconBlockBody, BeaconBlockBodyAltair, BeaconBlockBodyBase, BeaconBlockBodyDank,
|
||||
BeaconBlockBodyMerge, BeaconBlockBodyRef, BeaconBlockBodyRefMut,
|
||||
};
|
||||
pub use crate::beacon_block_header::BeaconBlockHeader;
|
||||
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
|
||||
@@ -144,7 +148,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,
|
||||
SignedBeaconBlockMerge, SignedBlindedBeaconBlock,SignedBeaconBlockDank
|
||||
};
|
||||
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
|
||||
pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
|
||||
@@ -165,12 +169,15 @@ pub use crate::validator::Validator;
|
||||
pub use crate::validator_registration_data::*;
|
||||
pub use crate::validator_subscription::ValidatorSubscription;
|
||||
pub use crate::voluntary_exit::VoluntaryExit;
|
||||
use serde_big_array::BigArray;
|
||||
|
||||
pub type CommitteeIndex = u64;
|
||||
pub type Hash256 = H256;
|
||||
pub type Uint256 = ethereum_types::U256;
|
||||
pub type Address = H160;
|
||||
pub type ForkVersion = [u8; 4];
|
||||
pub type BLSFieldElement = Uint256;
|
||||
pub type Blob<T> = FixedVector<BLSFieldElement, T>;
|
||||
|
||||
pub use bls::{
|
||||
AggregatePublicKey, AggregateSignature, Keypair, PublicKey, PublicKeyBytes, SecretKey,
|
||||
|
||||
@@ -38,7 +38,7 @@ impl From<SignedBeaconBlockHash> for Hash256 {
|
||||
|
||||
/// A `BeaconBlock` and a signature from its proposer.
|
||||
#[superstruct(
|
||||
variants(Base, Altair, Merge),
|
||||
variants(Base, Altair, Merge, Dank),
|
||||
variant_attributes(
|
||||
derive(
|
||||
Debug,
|
||||
@@ -72,6 +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>,
|
||||
pub signature: Signature,
|
||||
}
|
||||
|
||||
@@ -129,6 +131,9 @@ 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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user