mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 05:18:30 +00:00
Implement publish block and blobs endpoint (WIP)
This commit is contained in:
@@ -106,6 +106,7 @@ pub mod block_contents;
|
||||
pub mod signed_blob;
|
||||
pub mod signed_block_and_blobs;
|
||||
pub mod transaction;
|
||||
pub mod signed_block_contents;
|
||||
|
||||
use ethereum_types::{H160, H256};
|
||||
|
||||
@@ -187,8 +188,8 @@ pub use crate::signed_beacon_block::{
|
||||
};
|
||||
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
|
||||
pub use crate::signed_blob::*;
|
||||
pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecar;
|
||||
pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecarDecode;
|
||||
pub use crate::signed_block_and_blobs::{SignedBeaconBlockAndBlobsSidecar, SignedBeaconBlockAndBlobsSidecarDecode, SignedBeaconBlockAndBlobSidecars};
|
||||
pub use crate::signed_block_contents::SignedBlockContents;
|
||||
pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange;
|
||||
pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
|
||||
pub use crate::signed_voluntary_exit::SignedVoluntaryExit;
|
||||
|
||||
@@ -3,6 +3,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use test_random_derive::TestRandom;
|
||||
use tree_hash_derive::TreeHash;
|
||||
use derivative::Derivative;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
@@ -14,10 +15,12 @@ use tree_hash_derive::TreeHash;
|
||||
Decode,
|
||||
TestRandom,
|
||||
TreeHash,
|
||||
Derivative,
|
||||
arbitrary::Arbitrary,
|
||||
)]
|
||||
#[serde(bound = "T: EthSpec")]
|
||||
#[arbitrary(bound = "T: EthSpec")]
|
||||
#[derivative(Hash(bound = "T: EthSpec"))]
|
||||
pub struct SignedBlobSidecar<T: EthSpec> {
|
||||
pub message: BlobSidecar<T>,
|
||||
pub signature: Signature,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844};
|
||||
use crate::{AbstractExecPayload, BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844, SignedBlobSidecar};
|
||||
use derivative::Derivative;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz::{Decode, DecodeError};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::sync::Arc;
|
||||
use ssz_types::VariableList;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, PartialEq)]
|
||||
@@ -13,6 +14,7 @@ pub struct SignedBeaconBlockAndBlobsSidecarDecode<T: EthSpec> {
|
||||
pub blobs_sidecar: BlobsSidecar<T>,
|
||||
}
|
||||
|
||||
// TODO: will be removed once we decouple blobs in Gossip
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)]
|
||||
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
|
||||
pub struct SignedBeaconBlockAndBlobsSidecar<T: EthSpec> {
|
||||
@@ -32,3 +34,11 @@ impl<T: EthSpec> SignedBeaconBlockAndBlobsSidecar<T> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)]
|
||||
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
|
||||
#[serde(bound = "T: EthSpec")]
|
||||
pub struct SignedBeaconBlockAndBlobSidecars<T: EthSpec, Payload: AbstractExecPayload<T>> {
|
||||
pub signed_block: SignedBeaconBlock<T, Payload>,
|
||||
pub signed_blob_sidecars: VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>,
|
||||
}
|
||||
40
consensus/types/src/signed_block_contents.rs
Normal file
40
consensus/types/src/signed_block_contents.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use crate::{AbstractExecPayload, EthSpec, FullPayload, SignedBeaconBlock, SignedBlobSidecar};
|
||||
use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobSidecars;
|
||||
use derivative::Derivative;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_types::VariableList;
|
||||
|
||||
/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobSidecars`].
|
||||
#[derive(Clone, Debug, Derivative, Serialize, Deserialize)]
|
||||
#[derivative(PartialEq, Hash(bound = "T: EthSpec"))]
|
||||
#[serde(untagged)]
|
||||
#[serde(bound = "T: EthSpec")]
|
||||
pub enum SignedBlockContents<T: EthSpec, Payload: AbstractExecPayload<T> = FullPayload<T>> {
|
||||
BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars<T, Payload>),
|
||||
Block(SignedBeaconBlock<T, Payload>),
|
||||
}
|
||||
|
||||
impl<T: EthSpec, Payload: AbstractExecPayload<T>> SignedBlockContents<T, Payload> {
|
||||
pub fn signed_block(&self) -> &SignedBeaconBlock<T, Payload> {
|
||||
match self {
|
||||
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => &block_and_sidecars.signed_block,
|
||||
SignedBlockContents::Block(block) => block,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deconstruct(self) -> (SignedBeaconBlock<T, Payload>, Option<VariableList<SignedBlobSidecar<T>, <T as EthSpec>::MaxBlobsPerBlock>>) {
|
||||
match self {
|
||||
SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => (
|
||||
block_and_sidecars.signed_block,
|
||||
Some(block_and_sidecars.signed_blob_sidecars),
|
||||
),
|
||||
SignedBlockContents::Block(block) => (block, None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec, Payload: AbstractExecPayload<T>> From<SignedBeaconBlock<T, Payload>> for SignedBlockContents<T, Payload> {
|
||||
fn from(block: SignedBeaconBlock<T, Payload>) -> Self {
|
||||
SignedBlockContents::Block(block)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user