diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 7ac23a9d9..e48f8d7ad 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -31,7 +31,8 @@ use beacon_chain::{ pub use block_id::BlockId; use directory::DEFAULT_ROOT_DIR; use eth2::types::{ - self as api_types, EndpointVersion, SkipRandaoVerification, ValidatorId, ValidatorStatus, + self as api_types, EndpointVersion, SignedBlockContents, SkipRandaoVerification, ValidatorId, + ValidatorStatus, }; use lighthouse_network::{types::SyncState, EnrExt, NetworkGlobals, PeerId, PubsubMessage}; use lighthouse_version::version_with_platform; @@ -57,7 +58,7 @@ use types::{ Attestation, AttestationData, AttesterSlashing, BeaconStateError, BlindedPayload, CommitteeCache, ConfigAndPreset, Epoch, EthSpec, ForkName, FullPayload, ProposerPreparationData, ProposerSlashing, RelativeEpoch, SignedAggregateAndProof, - SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlockContents, SignedBlsToExecutionChange, + SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlsToExecutionChange, SignedContributionAndProof, SignedValidatorRegistrationData, SignedVoluntaryExit, Slot, SyncCommitteeMessage, SyncContributionData, }; diff --git a/beacon_node/http_api/src/publish_blocks.rs b/beacon_node/http_api/src/publish_blocks.rs index 49d655785..dc8bb020a 100644 --- a/beacon_node/http_api/src/publish_blocks.rs +++ b/beacon_node/http_api/src/publish_blocks.rs @@ -3,6 +3,7 @@ use beacon_chain::blob_verification::{AsBlock, BlockWrapper, IntoAvailableBlock} use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now}; use beacon_chain::NotifyExecutionLayer; use beacon_chain::{BeaconChain, BeaconChainTypes, BlockError, CountUnrealized}; +use eth2::types::SignedBlockContents; use lighthouse_network::PubsubMessage; use network::NetworkMessage; use slog::{debug, error, info, warn, Logger}; @@ -12,7 +13,7 @@ use tokio::sync::mpsc::UnboundedSender; use tree_hash::TreeHash; use types::{ AbstractExecPayload, BlindedPayload, EthSpec, ExecPayload, ExecutionBlockHash, FullPayload, - Hash256, SignedBeaconBlock, SignedBlockContents, + Hash256, SignedBeaconBlock, }; use warp::Rejection; diff --git a/beacon_node/http_api/tests/interactive_tests.rs b/beacon_node/http_api/tests/interactive_tests.rs index 7db1b22d6..00fa7faff 100644 --- a/beacon_node/http_api/tests/interactive_tests.rs +++ b/beacon_node/http_api/tests/interactive_tests.rs @@ -513,12 +513,13 @@ pub async fn proposer_boost_re_org_test( let randao_reveal = harness .sign_randao_reveal(&state_b, proposer_index, slot_c) .into(); - let unsigned_block_c = tester + let unsigned_block_contents_c = tester .client .get_validator_blocks(slot_c, &randao_reveal, None) .await .unwrap() .data; + let unsigned_block_c = unsigned_block_contents_c.deconstruct().0; let block_c = harness.sign_beacon_block(unsigned_block_c, &state_b); if should_re_org { @@ -700,7 +701,9 @@ pub async fn fork_choice_before_proposal() { .get_validator_blocks::>(slot_d, &randao_reveal, None) .await .unwrap() - .data; + .data + .deconstruct() + .0; // Head is now B. assert_eq!( diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 977c737fd..423e2d4de 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -2065,7 +2065,9 @@ impl ApiTester { .get_validator_blocks::>(slot, &randao_reveal, None) .await .unwrap() - .data; + .data + .deconstruct() + .0; let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec); diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index d32863912..ffd7a60e4 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -5,6 +5,7 @@ use crate::Error as ServerError; use lighthouse_network::{ConnectionDirection, Enr, Multiaddr, PeerConnectionStatus}; use mime::{Mime, APPLICATION, JSON, OCTET_STREAM, STAR}; use serde::{Deserialize, Serialize}; +use ssz_derive::Encode; use std::cmp::Reverse; use std::convert::TryFrom; use std::fmt; @@ -1322,3 +1323,53 @@ impl> Into> } } } + +pub type BlockContentsTuple = ( + SignedBeaconBlock, + Option, ::MaxBlobsPerBlock>>, +); + +/// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobSidecars`]. +#[derive(Clone, Debug, Serialize, Deserialize)] +#[serde(untagged)] +#[serde(bound = "T: EthSpec")] +pub enum SignedBlockContents = FullPayload> { + BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars), + Block(SignedBeaconBlock), +} + +impl> SignedBlockContents { + pub fn signed_block(&self) -> &SignedBeaconBlock { + match self { + SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => { + &block_and_sidecars.signed_block + } + SignedBlockContents::Block(block) => block, + } + } + + pub fn deconstruct(self) -> BlockContentsTuple { + 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> From> + for SignedBlockContents +{ + fn from(block: SignedBeaconBlock) -> Self { + SignedBlockContents::Block(block) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, Encode)] +#[serde(bound = "T: EthSpec")] +pub struct SignedBeaconBlockAndBlobSidecars> { + pub signed_block: SignedBeaconBlock, + pub signed_blob_sidecars: VariableList, ::MaxBlobsPerBlock>, +} diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index 14f06bb51..6a86e773a 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -102,7 +102,6 @@ pub mod blob_sidecar; pub mod blobs_sidecar; pub mod signed_blob; pub mod signed_block_and_blobs; -pub mod signed_block_contents; pub mod transaction; use ethereum_types::{H160, H256}; @@ -185,10 +184,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::{ - SignedBeaconBlockAndBlobSidecars, SignedBeaconBlockAndBlobsSidecar, - SignedBeaconBlockAndBlobsSidecarDecode, + SignedBeaconBlockAndBlobsSidecar, SignedBeaconBlockAndBlobsSidecarDecode, }; -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; diff --git a/consensus/types/src/signed_block_and_blobs.rs b/consensus/types/src/signed_block_and_blobs.rs index c6d154ef0..a3bd34475 100644 --- a/consensus/types/src/signed_block_and_blobs.rs +++ b/consensus/types/src/signed_block_and_blobs.rs @@ -1,12 +1,8 @@ -use crate::{ - AbstractExecPayload, BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844, - SignedBlobSidecar, -}; +use crate::{BlobsSidecar, EthSpec, SignedBeaconBlock, SignedBeaconBlockEip4844}; use derivative::Derivative; use serde_derive::{Deserialize, Serialize}; use ssz::{Decode, DecodeError}; use ssz_derive::{Decode, Encode}; -use ssz_types::VariableList; use std::sync::Arc; use tree_hash_derive::TreeHash; @@ -37,11 +33,3 @@ impl SignedBeaconBlockAndBlobsSidecar { }) } } - -#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)] -#[derivative(PartialEq, Hash(bound = "T: EthSpec"))] -#[serde(bound = "T: EthSpec")] -pub struct SignedBeaconBlockAndBlobSidecars> { - pub signed_block: SignedBeaconBlock, - pub signed_blob_sidecars: VariableList, ::MaxBlobsPerBlock>, -} diff --git a/consensus/types/src/signed_block_contents.rs b/consensus/types/src/signed_block_contents.rs deleted file mode 100644 index 7f547c86f..000000000 --- a/consensus/types/src/signed_block_contents.rs +++ /dev/null @@ -1,49 +0,0 @@ -use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobSidecars; -use crate::{AbstractExecPayload, EthSpec, FullPayload, SignedBeaconBlock, SignedBlobSidecar}; -use derivative::Derivative; -use serde_derive::{Deserialize, Serialize}; -use ssz_types::VariableList; - -pub type BlockContentsTuple = ( - SignedBeaconBlock, - Option, ::MaxBlobsPerBlock>>, -); - -/// 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 = FullPayload> { - BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars), - Block(SignedBeaconBlock), -} - -impl> SignedBlockContents { - pub fn signed_block(&self) -> &SignedBeaconBlock { - match self { - SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => { - &block_and_sidecars.signed_block - } - SignedBlockContents::Block(block) => block, - } - } - - pub fn deconstruct(self) -> BlockContentsTuple { - 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> From> - for SignedBlockContents -{ - fn from(block: SignedBeaconBlock) -> Self { - SignedBlockContents::Block(block) - } -} diff --git a/validator_client/src/block_service.rs b/validator_client/src/block_service.rs index 48d646016..0eb9a07c3 100644 --- a/validator_client/src/block_service.rs +++ b/validator_client/src/block_service.rs @@ -7,6 +7,7 @@ use crate::{ }; use crate::{http_metrics::metrics, validator_store::ValidatorStore}; use environment::RuntimeContext; +use eth2::types::SignedBlockContents; use slog::{crit, debug, error, info, trace, warn}; use slot_clock::SlotClock; use std::ops::Deref; @@ -16,7 +17,7 @@ use tokio::sync::mpsc; use tokio::time::sleep; use types::{ AbstractExecPayload, BeaconBlock, BlindedPayload, BlockType, EthSpec, FullPayload, Graffiti, - PublicKeyBytes, SignedBlockContents, Slot, + PublicKeyBytes, Slot, }; #[derive(Debug)]