From 782a53ad9d0748f957cdc67a6d522a9bea22bd72 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Tue, 11 Jul 2023 16:05:05 -0400 Subject: [PATCH] fix compile --- .../beacon_chain/src/blob_verification.rs | 1 - .../beacon_chain/src/block_verification.rs | 44 ++++-- .../src/data_availability_checker.rs | 11 ++ beacon_node/beacon_chain/src/lib.rs | 2 +- beacon_node/beacon_chain/src/test_utils.rs | 48 ++++++- beacon_node/http_api/src/publish_blocks.rs | 45 +++---- .../tests/broadcast_validation_tests.rs | 125 +++++++++++------- beacon_node/http_api/tests/tests.rs | 2 +- common/eth2/src/lib.rs | 7 +- common/eth2/src/types.rs | 17 +++ .../src/per_block_processing/tests.rs | 10 +- testing/state_transition_vectors/src/exit.rs | 2 +- 12 files changed, 212 insertions(+), 102 deletions(-) diff --git a/beacon_node/beacon_chain/src/blob_verification.rs b/beacon_node/beacon_chain/src/blob_verification.rs index 8e7c4dc07..501e0ae59 100644 --- a/beacon_node/beacon_chain/src/blob_verification.rs +++ b/beacon_node/beacon_chain/src/blob_verification.rs @@ -511,7 +511,6 @@ pub fn verify_kzg_for_blob_list( let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_list .clone() .into_iter() - //TODO(sean) remove clone .map(|blob| (blob.blob.clone(), (blob.kzg_commitment, blob.kzg_proof))) .unzip(); if validate_blobs::( diff --git a/beacon_node/beacon_chain/src/block_verification.rs b/beacon_node/beacon_chain/src/block_verification.rs index 819b3e68c..5881ee7d9 100644 --- a/beacon_node/beacon_chain/src/block_verification.rs +++ b/beacon_node/beacon_chain/src/block_verification.rs @@ -69,7 +69,7 @@ use crate::{ metrics, BeaconChain, BeaconChainError, BeaconChainTypes, }; use derivative::Derivative; -use eth2::types::EventKind; +use eth2::types::{ArcBlockContentsTuple, EventKind, SignedBlockContents}; use execution_layer::PayloadStatus; pub use fork_choice::{AttestationFromBlock, PayloadVerificationStatus}; use parking_lot::RwLockReadGuard; @@ -92,7 +92,7 @@ use std::fs; use std::io::Write; use std::sync::Arc; use std::time::Duration; -use store::{Error as DBError, HotStateSummary, KeyValueStore, StoreOp}; +use store::{Error as DBError, HotStateSummary, KeyValueStore, SignedBlobSidecarList, StoreOp}; use task_executor::JoinHandle; use tree_hash::TreeHash; use types::blob_sidecar::BlobIdentifier; @@ -627,6 +627,13 @@ pub struct GossipVerifiedBlock { consensus_context: ConsensusContext, } +impl GossipVerifiedBlock { + /// Useful for publishing after gossip verification. + pub fn into_block_wrapper(self) -> BlockWrapper { + self.block.into_block_wrapper() + } +} + /// A wrapper around a `SignedBeaconBlock` that indicates that all signatures (except the deposit /// signatures) have been verified. pub struct SignatureVerifiedBlock { @@ -801,32 +808,45 @@ pub trait IntoGossipVerifiedBlock: Sized { self, chain: &BeaconChain, ) -> Result, BlockError>; - fn inner(&self) -> Arc>; + fn inner(&self) -> &SignedBeaconBlock; + fn parts(self) -> ArcBlockContentsTuple; } -impl IntoGossipVerifiedBlock for GossipVerifiedBlock { +impl IntoGossipVerifiedBlock + for ( + GossipVerifiedBlock, + Option>, + ) +{ fn into_gossip_verified_block( self, _chain: &BeaconChain, ) -> Result, BlockError> { - Ok(self) + Ok(self.0) } - - fn inner(&self) -> Arc> { - self.block.clone() + fn inner(&self) -> &SignedBeaconBlock { + self.0.block.as_block() + } + fn parts(self) -> ArcBlockContentsTuple { + (self.0.block.block_cloned(), self.1) } } -impl IntoGossipVerifiedBlock for Arc> { +impl IntoGossipVerifiedBlock for SignedBlockContents { fn into_gossip_verified_block( self, chain: &BeaconChain, ) -> Result, BlockError> { - GossipVerifiedBlock::new(self, chain) + GossipVerifiedBlock::new(self.deconstruct().into(), chain) } - fn inner(&self) -> Arc> { - self.clone() + fn inner(&self) -> &SignedBeaconBlock { + self.signed_block() + } + + fn parts(self) -> ArcBlockContentsTuple { + let (block, blobs) = self.deconstruct(); + (Arc::new(block), blobs) } } diff --git a/beacon_node/beacon_chain/src/data_availability_checker.rs b/beacon_node/beacon_chain/src/data_availability_checker.rs index 4d2d23f9e..ed5e04e07 100644 --- a/beacon_node/beacon_chain/src/data_availability_checker.rs +++ b/beacon_node/beacon_chain/src/data_availability_checker.rs @@ -531,6 +531,17 @@ pub enum VerifiedBlobs { PreDeneb, } +impl VerifiedBlobs { + pub fn to_blobs(self) -> Option> { + match self { + Self::Available(blobs) => Some(blobs), + Self::NotRequired => None, + Self::EmptyBlobs => None, + Self::PreDeneb => None, + } + } +} + /// A fully available block that is ready to be imported into fork choice. #[derive(Clone, Debug, PartialEq)] pub struct AvailableBlock { diff --git a/beacon_node/beacon_chain/src/lib.rs b/beacon_node/beacon_chain/src/lib.rs index 9b4519f6f..09981de8d 100644 --- a/beacon_node/beacon_chain/src/lib.rs +++ b/beacon_node/beacon_chain/src/lib.rs @@ -71,7 +71,7 @@ pub use beacon_fork_choice_store::{BeaconForkChoiceStore, Error as ForkChoiceSto pub use block_verification::{ get_block_root, AvailabilityPendingExecutedBlock, BlockError, ExecutedBlock, ExecutionPayloadError, ExecutionPendingBlock, GossipVerifiedBlock, IntoExecutionPendingBlock, - PayloadVerificationOutcome, PayloadVerificationStatus,IntoGossipVerifiedBlock, + IntoGossipVerifiedBlock, PayloadVerificationOutcome, PayloadVerificationStatus, }; pub use canonical_head::{CachedHead, CanonicalHead, CanonicalHeadRwLock}; pub use eth1_chain::{Eth1Chain, Eth1ChainBackend}; diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index 125ff471d..15331313b 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -906,7 +906,7 @@ where &self, mut state: BeaconState, slot: Slot, - ) -> (SignedBeaconBlock, BeaconState) { + ) -> (BlockContentsTuple>, BeaconState) { assert_ne!(slot, 0, "can't produce a block at slot 0"); assert!(slot >= state.slot()); @@ -946,7 +946,44 @@ where &self.spec, ); - (signed_block, pre_state) + let block_contents: BlockContentsTuple> = match &signed_block { + SignedBeaconBlock::Base(_) + | SignedBeaconBlock::Altair(_) + | SignedBeaconBlock::Merge(_) + | SignedBeaconBlock::Capella(_) => (signed_block, None), + SignedBeaconBlock::Deneb(_) => { + if let Some(blobs) = self + .chain + .proposal_blob_cache + .pop(&signed_block.canonical_root()) + { + let signed_blobs: SignedBlobSidecarList = Vec::from(blobs) + .into_iter() + .map(|blob| { + blob.sign( + &self.validator_keypairs[proposer_index].sk, + &state.fork(), + state.genesis_validators_root(), + &self.spec, + ) + }) + .collect::>() + .into(); + let mut guard = self.blob_signature_cache.write(); + for blob in &signed_blobs { + guard.insert( + BlobSignatureKey::new(blob.message.block_root, blob.message.index), + blob.signature.clone(), + ); + } + (signed_block, Some(signed_blobs)) + } else { + (signed_block, None) + } + } + }; + + (block_contents, pre_state) } /// Create a randao reveal for a block at `slot`. @@ -1737,11 +1774,12 @@ where state: BeaconState, slot: Slot, block_modifier: impl FnOnce(&mut BeaconBlock), - ) -> (SignedBeaconBlock, BeaconState) { + ) -> (BlockContentsTuple>, BeaconState) { assert_ne!(slot, 0, "can't produce a block at slot 0"); assert!(slot >= state.slot()); - let (block, state) = self.make_block_return_pre_state(state, slot).await; + let ((block, blobs), state) = self.make_block_return_pre_state(state, slot).await; + let (mut block, _) = block.deconstruct(); block_modifier(&mut block); @@ -1754,7 +1792,7 @@ where state.genesis_validators_root(), &self.spec, ); - (signed_block, state) + ((signed_block, blobs), state) } pub fn make_deposits<'a>( diff --git a/beacon_node/http_api/src/publish_blocks.rs b/beacon_node/http_api/src/publish_blocks.rs index 569497aad..ed472e0bf 100644 --- a/beacon_node/http_api/src/publish_blocks.rs +++ b/beacon_node/http_api/src/publish_blocks.rs @@ -3,8 +3,8 @@ use crate::metrics; use beacon_chain::blob_verification::BlockWrapper; use beacon_chain::validator_monitor::{get_block_delay_ms, timestamp_now}; use beacon_chain::{ - AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError,IntoGossipVerifiedBlock, - GossipVerifiedBlock, NotifyExecutionLayer, + AvailabilityProcessingStatus, BeaconChain, BeaconChainError, BeaconChainTypes, BlockError, + GossipVerifiedBlock, IntoGossipVerifiedBlock, NotifyExecutionLayer, }; use eth2::types::BroadcastValidation; use eth2::types::SignedBlockContents; @@ -53,16 +53,11 @@ pub async fn publish_block>( ) -> Result<(), Rejection> { let seen_timestamp = timestamp_now(); - let (block, blobs_opt, is_locally_built_block) = match provenanced_block { - ProvenancedBlock::Local(block_contents, _) => { - let (block, maybe_blobs, ) = block_contents.deconstruct(); - (Arc::new(block), maybe_blobs, true) - } - ProvenancedBlock::Builder(block_contents, _) => { - let (block, maybe_blobs) = block_contents.deconstruct(); - (Arc::new(block), maybe_blobs, false) - } + let (block_contents, is_locally_built_block) = match provenanced_block { + ProvenancedBlock::Local(block_contents, _) => (block_contents, true), + ProvenancedBlock::Builder(block_contents, _) => (block_contents, false), }; + let block = block_contents.inner(); let delay = get_block_delay_ms(seen_timestamp, block.message(), &chain.slot_clock); debug!(log, "Signed block received in HTTP API"; "slot" => block.slot()); @@ -107,6 +102,15 @@ pub async fn publish_block>( Ok(()) }; + /* only publish if gossip- and consensus-valid and equivocation-free */ + let chain_clone = chain.clone(); + let slot = block.message().slot(); + let proposer_index = block.message().proposer_index(); + let sender_clone = network_tx.clone(); + let log_clone = log.clone(); + + let (block, blobs_opt) = block_contents.parts(); + let mapped_blobs = blobs_opt.clone().map(|blobs| { VariableList::from( blobs @@ -116,17 +120,9 @@ pub async fn publish_block>( ) }); - /* only publish if gossip- and consensus-valid and equivocation-free */ - let chain_clone = chain.clone(); - let slot = block.message().slot(); - let block_clone = block.clone(); - let proposer_index = block.message().proposer_index(); - let sender_clone = network_tx.clone(); - let log_clone = log.clone(); - /* if we can form a `GossipVerifiedBlock`, we've passed our basic gossip checks */ - let gossip_verified_block = - BlockWrapper::new(block.clone(), mapped_blobs).into_gossip_verified_block( + let gossip_verified_block = GossipVerifiedBlock::new( + BlockWrapper::new(block.clone(), mapped_blobs), &chain, ) .map_err(|e| { @@ -147,6 +143,8 @@ pub async fn publish_block>( .map_err(|_| warp_utils::reject::custom_server_error("unable to publish".into()))?; } + let block_clone = block.clone(); + let publish_fn = move || match validation_level { BroadcastValidation::Gossip => Ok(()), BroadcastValidation::Consensus => publish_block( @@ -271,7 +269,8 @@ pub async fn publish_blinded_block( validation_level: BroadcastValidation, ) -> Result<(), Rejection> { let block_root = block.signed_block().canonical_root(); - let full_block: ProvenancedBlock> = reconstruct_block(chain.clone(), block_root, block, log.clone()).await?; + let full_block: ProvenancedBlock> = + reconstruct_block(chain.clone(), block_root, block, log.clone()).await?; publish_block::( Some(block_root), full_block, @@ -291,7 +290,7 @@ pub async fn reconstruct_block( block_root: Hash256, block: SignedBlockContents>, log: Logger, -) -> Result>, Rejection> { +) -> Result>, Rejection> { let full_payload_opt = if let Ok(payload_header) = block.signed_block().message().body().execution_payload() { diff --git a/beacon_node/http_api/tests/broadcast_validation_tests.rs b/beacon_node/http_api/tests/broadcast_validation_tests.rs index 4819dd99e..ccf7439b1 100644 --- a/beacon_node/http_api/tests/broadcast_validation_tests.rs +++ b/beacon_node/http_api/tests/broadcast_validation_tests.rs @@ -2,7 +2,9 @@ use beacon_chain::{ test_utils::{AttestationStrategy, BlockStrategy}, GossipVerifiedBlock, }; -use eth2::types::{BroadcastValidation, SignedBeaconBlock, SignedBlindedBeaconBlock}; +use eth2::types::{ + BroadcastValidation, SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlockContents, +}; use http_api::test_utils::InteractiveTester; use http_api::{publish_blinded_block, publish_block, reconstruct_block, ProvenancedBlock}; use tree_hash::TreeHash; @@ -63,7 +65,7 @@ pub async fn gossip_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -73,7 +75,7 @@ pub async fn gossip_invalid() { let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -115,7 +117,7 @@ pub async fn gossip_partial_pass() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::random() @@ -124,7 +126,7 @@ pub async fn gossip_partial_pass() { let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -161,11 +163,15 @@ pub async fn gossip_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester.harness.make_block(state_a, slot_b).await; + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = + tester.harness.make_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block.clone(), blobs), + validation_level, + ) .await; assert!(response.is_ok()); @@ -202,7 +208,7 @@ pub async fn consensus_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -212,7 +218,7 @@ pub async fn consensus_invalid() { let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -254,14 +260,14 @@ pub async fn consensus_gossip() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero()) .await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -304,9 +310,9 @@ pub async fn consensus_partial_pass_only_consensus() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block_a, state_after_a): (SignedBeaconBlock, _) = + let ((block_a, _), state_after_a): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a.clone(), slot_b).await; - let (block_b, state_after_b): (SignedBeaconBlock, _) = + let ((block_b, blobs_b), state_after_b): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a, slot_b).await; /* check for `make_block` curios */ @@ -324,7 +330,7 @@ pub async fn consensus_partial_pass_only_consensus() { let publication_result: Result<(), Rejection> = publish_block( None, - ProvenancedBlock::local(gossip_block_b.unwrap()), + ProvenancedBlock::local((gossip_block_b.unwrap(), blobs_b)), tester.harness.chain.clone(), &channel.0, test_logger, @@ -367,11 +373,15 @@ pub async fn consensus_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester.harness.make_block(state_a, slot_b).await; + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = + tester.harness.make_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block.clone(), blobs), + validation_level, + ) .await; assert!(response.is_ok()); @@ -410,7 +420,7 @@ pub async fn equivocation_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -420,7 +430,7 @@ pub async fn equivocation_invalid() { let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -463,9 +473,9 @@ pub async fn equivocation_consensus_early_equivocation() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block_a, state_after_a): (SignedBeaconBlock, _) = + let ((block_a, blobs_a), state_after_a): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a.clone(), slot_b).await; - let (block_b, state_after_b): (SignedBeaconBlock, _) = + let ((block_b, blobs_b), state_after_b): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a, slot_b).await; /* check for `make_block` curios */ @@ -476,7 +486,10 @@ pub async fn equivocation_consensus_early_equivocation() { /* submit `block_a` as valid */ assert!(tester .client - .post_beacon_blocks_v2(&block_a, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block_a.clone(), blobs_a), + validation_level + ) .await .is_ok()); assert!(tester @@ -487,7 +500,10 @@ pub async fn equivocation_consensus_early_equivocation() { /* submit `block_b` which should induce equivocation */ let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block_b, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block_b.clone(), blobs_b), + validation_level, + ) .await; assert!(response.is_err()); @@ -529,14 +545,14 @@ pub async fn equivocation_gossip() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero()) .await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2(&SignedBlockContents::new(block, blobs), validation_level) .await; assert!(response.is_err()); @@ -582,9 +598,9 @@ pub async fn equivocation_consensus_late_equivocation() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block_a, state_after_a): (SignedBeaconBlock, _) = + let ((block_a, _), state_after_a): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a.clone(), slot_b).await; - let (block_b, state_after_b): (SignedBeaconBlock, _) = + let ((block_b, blobs_b), state_after_b): ((SignedBeaconBlock, _), _) = tester.harness.make_block(state_a, slot_b).await; /* check for `make_block` curios */ @@ -601,7 +617,7 @@ pub async fn equivocation_consensus_late_equivocation() { let publication_result: Result<(), Rejection> = publish_block( None, - ProvenancedBlock::local(gossip_block_b.unwrap()), + ProvenancedBlock::local((gossip_block_b.unwrap(), blobs_b)), tester.harness.chain, &channel.0, test_logger, @@ -650,11 +666,15 @@ pub async fn equivocation_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester.harness.make_block(state_a, slot_b).await; + let ((block, blobs), _): ((SignedBeaconBlock, _), _) = + tester.harness.make_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block.clone(), blobs), + validation_level, + ) .await; assert!(response.is_ok()); @@ -692,7 +712,7 @@ pub async fn blinded_gossip_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -746,7 +766,7 @@ pub async fn blinded_gossip_partial_pass() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero() @@ -794,7 +814,7 @@ pub async fn blinded_gossip_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBlindedBeaconBlock, _) = + let ((block, _), _): ((SignedBlindedBeaconBlock, _), _) = tester.harness.make_blinded_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester @@ -837,7 +857,7 @@ pub async fn blinded_consensus_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -891,7 +911,7 @@ pub async fn blinded_consensus_gossip() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero()) .await; @@ -942,7 +962,7 @@ pub async fn blinded_consensus_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBlindedBeaconBlock, _) = + let ((block, _), _): ((SignedBlindedBeaconBlock, _), _) = tester.harness.make_blinded_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester @@ -986,7 +1006,7 @@ pub async fn blinded_equivocation_invalid() { tester.harness.advance_slot(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(chain_state_before, slot, |b| { *b.state_root_mut() = Hash256::zero(); @@ -1041,11 +1061,11 @@ pub async fn blinded_equivocation_consensus_early_equivocation() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block_a, state_after_a): (SignedBlindedBeaconBlock, _) = tester + let ((block_a, _), state_after_a): ((SignedBlindedBeaconBlock, _), _) = tester .harness .make_blinded_block(state_a.clone(), slot_b) .await; - let (block_b, state_after_b): (SignedBlindedBeaconBlock, _) = + let ((block_b, _), state_after_b): ((SignedBlindedBeaconBlock, _), _) = tester.harness.make_blinded_block(state_a, slot_b).await; /* check for `make_blinded_block` curios */ @@ -1109,7 +1129,7 @@ pub async fn blinded_equivocation_gossip() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBeaconBlock, _) = tester + let ((block, _), _): ((SignedBeaconBlock, _), _) = tester .harness .make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero()) .await; @@ -1164,11 +1184,11 @@ pub async fn blinded_equivocation_consensus_late_equivocation() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block_a, state_after_a): (SignedBlindedBeaconBlock, _) = tester + let ((block_a, blobs_a), state_after_a): ((SignedBlindedBeaconBlock, _), _) = tester .harness .make_blinded_block(state_a.clone(), slot_b) .await; - let (block_b, state_after_b): (SignedBlindedBeaconBlock, _) = + let ((block_b, blobs_b), state_after_b): ((SignedBlindedBeaconBlock, _), _) = tester.harness.make_blinded_block(state_a, slot_b).await; /* check for `make_blinded_block` curios */ @@ -1178,16 +1198,16 @@ pub async fn blinded_equivocation_consensus_late_equivocation() { let unblinded_block_a = reconstruct_block( tester.harness.chain.clone(), - block_a.state_root(), - block_a, + block_a.canonical_root(), + SignedBlockContents::new(block_a, blobs_a), test_logger.clone(), ) .await .unwrap(); let unblinded_block_b = reconstruct_block( tester.harness.chain.clone(), - block_b.clone().state_root(), - block_b.clone(), + block_b.canonical_root(), + SignedBlockContents::new(block_b.clone(), blobs_b.clone()), test_logger.clone(), ) .await @@ -1202,15 +1222,17 @@ pub async fn blinded_equivocation_consensus_late_equivocation() { ProvenancedBlock::Builder(b, _) => b, }; - let gossip_block_b = GossipVerifiedBlock::new(inner_block_b, &tester.harness.chain); + let gossip_block_b = + GossipVerifiedBlock::new(inner_block_b.deconstruct().into(), &tester.harness.chain); assert!(gossip_block_b.is_ok()); - let gossip_block_a = GossipVerifiedBlock::new(inner_block_a, &tester.harness.chain); + let gossip_block_a = + GossipVerifiedBlock::new(inner_block_a.deconstruct().into(), &tester.harness.chain); assert!(gossip_block_a.is_err()); let channel = tokio::sync::mpsc::unbounded_channel(); let publication_result: Result<(), Rejection> = publish_blinded_block( - block_b, + SignedBlockContents::new(block_b, blobs_b), tester.harness.chain, &channel.0, test_logger, @@ -1254,12 +1276,15 @@ pub async fn blinded_equivocation_full_pass() { let slot_b = slot_a + 1; let state_a = tester.harness.get_current_state(); - let (block, _): (SignedBlindedBeaconBlock, _) = + let ((block, blobs), _): ((SignedBlindedBeaconBlock, _), _) = tester.harness.make_blinded_block(state_a, slot_b).await; let response: Result<(), eth2::Error> = tester .client - .post_beacon_blocks_v2(&block, validation_level) + .post_beacon_blocks_v2( + &SignedBlockContents::new(block.clone(), blobs), + validation_level, + ) .await; assert!(response.is_ok()); diff --git a/beacon_node/http_api/tests/tests.rs b/beacon_node/http_api/tests/tests.rs index 2bcb13133..f5a5d74e2 100644 --- a/beacon_node/http_api/tests/tests.rs +++ b/beacon_node/http_api/tests/tests.rs @@ -4157,7 +4157,7 @@ impl ApiTester { .unwrap(); let expected_reorg = EventKind::ChainReorg(SseChainReorg { - slot: self.reorg_block.slot(), + slot: self.reorg_block.signed_block().slot(), depth: 1, old_head_block: self.next_block.signed_block().canonical_root(), old_head_state: self.next_block.signed_block().state_root(), diff --git a/common/eth2/src/lib.rs b/common/eth2/src/lib.rs index ba5f6016b..1a961769e 100644 --- a/common/eth2/src/lib.rs +++ b/common/eth2/src/lib.rs @@ -713,14 +713,14 @@ impl BeaconNodeHttpClient { /// `POST v2/beacon/blocks` pub async fn post_beacon_blocks_v2>( &self, - block: &SignedBeaconBlock, + block_contents: &SignedBlockContents, validation_level: Option, ) -> Result<(), Error> { self.post_generic_with_consensus_version( self.post_beacon_blocks_v2_path(validation_level)?, - block, + block_contents, Some(self.timeouts.proposal), - block.message().body().fork_name(), + block_contents.signed_block().message().body().fork_name(), ) .await?; @@ -728,6 +728,7 @@ impl BeaconNodeHttpClient { } /// `POST v2/beacon/blinded_blocks` + //TODO(sean) update this along with builder updates pub async fn post_beacon_blinded_blocks_v2( &self, block: &SignedBlindedBeaconBlock, diff --git a/common/eth2/src/types.rs b/common/eth2/src/types.rs index b7fc67304..9caf827ed 100644 --- a/common/eth2/src/types.rs +++ b/common/eth2/src/types.rs @@ -9,6 +9,7 @@ use ssz_derive::Encode; use std::convert::TryFrom; use std::fmt::{self, Display}; use std::str::{from_utf8, FromStr}; +use std::sync::Arc; use std::time::Duration; pub use types::*; @@ -1409,6 +1410,8 @@ pub type BlockContentsTuple = ( Option>, ); +pub type ArcBlockContentsTuple = (Arc>, Option>); + /// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobSidecars`]. #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(untagged)] @@ -1419,6 +1422,20 @@ pub enum SignedBlockContents = FullP } impl> SignedBlockContents { + pub fn new( + block: SignedBeaconBlock, + blobs: Option>, + ) -> Self { + if let Some(blobs) = blobs { + Self::BlockAndBlobSidecars(SignedBeaconBlockAndBlobSidecars { + signed_block: block, + signed_blob_sidecars: blobs, + }) + } else { + Self::Block(block) + } + } + pub fn signed_block(&self) -> &SignedBeaconBlock { match self { SignedBlockContents::BlockAndBlobSidecars(block_and_sidecars) => { diff --git a/consensus/state_processing/src/per_block_processing/tests.rs b/consensus/state_processing/src/per_block_processing/tests.rs index 81641b590..011d4d0cc 100644 --- a/consensus/state_processing/src/per_block_processing/tests.rs +++ b/consensus/state_processing/src/per_block_processing/tests.rs @@ -63,7 +63,7 @@ async fn valid_block_ok() { let state = harness.get_current_state(); let slot = state.slot(); - let (block, mut state) = harness + let ((block, _), mut state) = harness .make_block_return_pre_state(state, slot + Slot::new(1)) .await; @@ -89,7 +89,7 @@ async fn invalid_block_header_state_slot() { let state = harness.get_current_state(); let slot = state.slot() + Slot::new(1); - let (signed_block, mut state) = harness.make_block_return_pre_state(state, slot).await; + let ((signed_block, _), mut state) = harness.make_block_return_pre_state(state, slot).await; let (mut block, signature) = signed_block.deconstruct(); *block.slot_mut() = slot + Slot::new(1); @@ -120,7 +120,7 @@ async fn invalid_parent_block_root() { let state = harness.get_current_state(); let slot = state.slot(); - let (signed_block, mut state) = harness + let ((signed_block, _), mut state) = harness .make_block_return_pre_state(state, slot + Slot::new(1)) .await; let (mut block, signature) = signed_block.deconstruct(); @@ -155,7 +155,7 @@ async fn invalid_block_signature() { let state = harness.get_current_state(); let slot = state.slot(); - let (signed_block, mut state) = harness + let ((signed_block, _), mut state) = harness .make_block_return_pre_state(state, slot + Slot::new(1)) .await; let (block, _) = signed_block.deconstruct(); @@ -188,7 +188,7 @@ async fn invalid_randao_reveal_signature() { let state = harness.get_current_state(); let slot = state.slot(); - let (signed_block, mut state) = harness + let ((signed_block, _), mut state) = harness .make_block_with_modifier(state, slot + 1, |block| { *block.body_mut().randao_reveal_mut() = Signature::empty(); }) diff --git a/testing/state_transition_vectors/src/exit.rs b/testing/state_transition_vectors/src/exit.rs index 7e7fd23e0..3b9235cc4 100644 --- a/testing/state_transition_vectors/src/exit.rs +++ b/testing/state_transition_vectors/src/exit.rs @@ -57,7 +57,7 @@ impl ExitTest { block_modifier(&harness, block); }) .await; - (signed_block, state) + (signed_block.0, state) } fn process(