mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2024-12-22 03:30:38 +00:00
Add BlobSidecar type
This commit is contained in:
parent
91a8d4575d
commit
39d4f0a1f3
51
consensus/types/src/blob_sidecar.rs
Normal file
51
consensus/types/src/blob_sidecar.rs
Normal file
@ -0,0 +1,51 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{Blob, EthSpec, Hash256, SignedRoot, Slot};
|
||||
use derivative::Derivative;
|
||||
use kzg::{KzgCommitment, KzgProof};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::Encode;
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Encode,
|
||||
Decode,
|
||||
TreeHash,
|
||||
Default,
|
||||
TestRandom,
|
||||
Derivative,
|
||||
arbitrary::Arbitrary,
|
||||
)]
|
||||
#[serde(bound = "T: EthSpec")]
|
||||
#[arbitrary(bound = "T: EthSpec")]
|
||||
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
|
||||
pub struct BlobSidecar<T: EthSpec> {
|
||||
pub block_root: Hash256,
|
||||
// TODO: fix the type, should fit in u8 as well
|
||||
pub index: u64,
|
||||
pub slot: Slot,
|
||||
pub block_parent_root: Hash256,
|
||||
pub proposer_index: u64,
|
||||
pub blob: Blob<T>,
|
||||
pub kzg_commitment: KzgCommitment,
|
||||
pub kzg_proof: KzgProof,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> SignedRoot for BlobSidecar<T> {}
|
||||
|
||||
impl<T: EthSpec> BlobSidecar<T> {
|
||||
pub fn empty() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[allow(clippy::integer_arithmetic)]
|
||||
pub fn max_size() -> usize {
|
||||
// Fixed part
|
||||
Self::empty().as_ssz_bytes().len()
|
||||
}
|
||||
}
|
@ -99,6 +99,7 @@ pub mod slot_data;
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub mod sqlite;
|
||||
|
||||
pub mod blob_sidecar;
|
||||
pub mod blobs_sidecar;
|
||||
pub mod signed_block_and_blobs;
|
||||
pub mod transaction;
|
||||
@ -121,7 +122,8 @@ pub use crate::beacon_block_body::{
|
||||
pub use crate::beacon_block_header::BeaconBlockHeader;
|
||||
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
|
||||
pub use crate::beacon_state::{BeaconTreeHashCache, Error as BeaconStateError, *};
|
||||
pub use crate::blobs_sidecar::{Blobs, BlobsSidecar, KzgCommitments};
|
||||
pub use crate::blob_sidecar::BlobSidecar;
|
||||
pub use crate::blobs_sidecar::BlobsSidecar;
|
||||
pub use crate::bls_to_execution_change::BlsToExecutionChange;
|
||||
pub use crate::chain_spec::{ChainSpec, Config, Domain};
|
||||
pub use crate::checkpoint::Checkpoint;
|
||||
|
@ -20,6 +20,12 @@ impl Display for KzgCommitment {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KzgCommitment {
|
||||
fn default() -> Self {
|
||||
KzgCommitment([0; KZG_COMMITMENT_BYTES_LEN])
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeHash for KzgCommitment {
|
||||
fn tree_hash_type() -> tree_hash::TreeHashType {
|
||||
<[u8; KZG_COMMITMENT_BYTES_LEN] as TreeHash>::tree_hash_type()
|
||||
|
Loading…
Reference in New Issue
Block a user