Fixes after rebasing eip4844

This commit is contained in:
Emilia Hane 2023-01-26 22:18:29 +01:00
parent 5437dcae9c
commit 4d3ff347a3
No known key found for this signature in database
GPG Key ID: E73394F9C09206FA
9 changed files with 65 additions and 32 deletions

View File

@ -958,9 +958,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
block_root: &Hash256, block_root: &Hash256,
) -> Result<Option<SignedBeaconBlockAndBlobsSidecar<T::EthSpec>>, Error> { ) -> Result<Option<SignedBeaconBlockAndBlobsSidecar<T::EthSpec>>, Error> {
// If there is no data availability boundary, the Eip4844 fork is disabled. // If there is no data availability boundary, the Eip4844 fork is disabled.
if let Some(finalized_data_availability_boundary) = if self.finalized_data_availability_boundary().is_some() {
self.finalized_data_availability_boundary()
{
// Only use the attester cache if we can find both the block and blob // Only use the attester cache if we can find both the block and blob
if let (Some(block), Some(blobs)) = ( if let (Some(block), Some(blobs)) = (
self.early_attester_cache.get_block(*block_root), self.early_attester_cache.get_block(*block_root),
@ -972,9 +970,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
})) }))
// Attempt to get the block and blobs from the database // Attempt to get the block and blobs from the database
} else if let Some(block) = self.get_block(block_root).await?.map(Arc::new) { } else if let Some(block) = self.get_block(block_root).await?.map(Arc::new) {
let blobs = self let blobs = self.get_blobs(block_root)?.map(Arc::new);
.get_blobs(block_root, finalized_data_availability_boundary)?
.map(Arc::new);
Ok(blobs.map(|blobs| SignedBeaconBlockAndBlobsSidecar { Ok(blobs.map(|blobs| SignedBeaconBlockAndBlobsSidecar {
beacon_block: block, beacon_block: block,
blobs_sidecar: blobs, blobs_sidecar: blobs,
@ -1070,7 +1066,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
pub fn get_blobs( pub fn get_blobs(
&self, &self,
block_root: &Hash256, block_root: &Hash256,
data_availability_boundary: Epoch,
) -> Result<Option<BlobsSidecar<T::EthSpec>>, Error> { ) -> Result<Option<BlobsSidecar<T::EthSpec>>, Error> {
match self.store.get_blobs(block_root)? { match self.store.get_blobs(block_root)? {
Some(blobs) => Ok(Some(blobs)), Some(blobs) => Ok(Some(blobs)),

View File

@ -292,12 +292,12 @@ impl<E: EthSpec> AvailableBlock<E> {
let blobs_sidecar = beacon_block let blobs_sidecar = beacon_block
.reconstruct_empty_blobs(Some(block_root)) .reconstruct_empty_blobs(Some(block_root))
.map(Arc::new)?; .map(Arc::new)?;
return Ok(AvailableBlock(AvailableBlockInner::BlockAndBlob( Ok(AvailableBlock(AvailableBlockInner::BlockAndBlob(
SignedBeaconBlockAndBlobsSidecar { SignedBeaconBlockAndBlobsSidecar {
beacon_block, beacon_block,
blobs_sidecar, blobs_sidecar,
}, },
))); )))
} }
DataAvailabilityCheckRequired::No => { DataAvailabilityCheckRequired::No => {
Ok(AvailableBlock(AvailableBlockInner::Block(beacon_block))) Ok(AvailableBlock(AvailableBlockInner::Block(beacon_block)))
@ -391,6 +391,7 @@ pub trait AsBlock<E: EthSpec> {
fn message(&self) -> BeaconBlockRef<E>; fn message(&self) -> BeaconBlockRef<E>;
fn as_block(&self) -> &SignedBeaconBlock<E>; fn as_block(&self) -> &SignedBeaconBlock<E>;
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>>; fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>>;
fn canonical_root(&self) -> Hash256;
} }
impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> { impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> {
@ -432,8 +433,8 @@ impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> {
} }
fn as_block(&self) -> &SignedBeaconBlock<E> { fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self { match &self {
BlockWrapper::Block(block) => &block, BlockWrapper::Block(block) => block,
BlockWrapper::BlockAndBlob(block, _) => &block, BlockWrapper::BlockAndBlob(block, _) => block,
} }
} }
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> { fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {
@ -442,6 +443,12 @@ impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> {
BlockWrapper::BlockAndBlob(block, _) => block.clone(), BlockWrapper::BlockAndBlob(block, _) => block.clone(),
} }
} }
fn canonical_root(&self) -> Hash256 {
match &self {
BlockWrapper::Block(block) => block.canonical_root(),
BlockWrapper::BlockAndBlob(block, _) => block.canonical_root(),
}
}
} }
impl<E: EthSpec> AsBlock<E> for &BlockWrapper<E> { impl<E: EthSpec> AsBlock<E> for &BlockWrapper<E> {
@ -483,8 +490,8 @@ impl<E: EthSpec> AsBlock<E> for &BlockWrapper<E> {
} }
fn as_block(&self) -> &SignedBeaconBlock<E> { fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self { match &self {
BlockWrapper::Block(block) => &block, BlockWrapper::Block(block) => block,
BlockWrapper::BlockAndBlob(block, _) => &block, BlockWrapper::BlockAndBlob(block, _) => block,
} }
} }
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> { fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {
@ -493,6 +500,12 @@ impl<E: EthSpec> AsBlock<E> for &BlockWrapper<E> {
BlockWrapper::BlockAndBlob(block, _) => block.clone(), BlockWrapper::BlockAndBlob(block, _) => block.clone(),
} }
} }
fn canonical_root(&self) -> Hash256 {
match &self {
BlockWrapper::Block(block) => block.canonical_root(),
BlockWrapper::BlockAndBlob(block, _) => block.canonical_root(),
}
}
} }
impl<E: EthSpec> AsBlock<E> for AvailableBlock<E> { impl<E: EthSpec> AsBlock<E> for AvailableBlock<E> {
@ -546,7 +559,7 @@ impl<E: EthSpec> AsBlock<E> for AvailableBlock<E> {
} }
fn as_block(&self) -> &SignedBeaconBlock<E> { fn as_block(&self) -> &SignedBeaconBlock<E> {
match &self.0 { match &self.0 {
AvailableBlockInner::Block(block) => &block, AvailableBlockInner::Block(block) => block,
AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => { AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => {
&block_sidecar_pair.beacon_block &block_sidecar_pair.beacon_block
} }
@ -560,4 +573,12 @@ impl<E: EthSpec> AsBlock<E> for AvailableBlock<E> {
} }
} }
} }
fn canonical_root(&self) -> Hash256 {
match &self.0 {
AvailableBlockInner::Block(block) => block.canonical_root(),
AvailableBlockInner::BlockAndBlob(block_sidecar_pair) => {
block_sidecar_pair.beacon_block.canonical_root()
}
}
}
} }

View File

@ -1120,7 +1120,7 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for SignatureVerifiedBloc
} }
fn block(&self) -> &SignedBeaconBlock<T::EthSpec> { fn block(&self) -> &SignedBeaconBlock<T::EthSpec> {
&self.block.as_block() self.block.as_block()
} }
} }

View File

@ -1,6 +1,9 @@
#![cfg(not(debug_assertions))] #![cfg(not(debug_assertions))]
use beacon_chain::test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy}; use beacon_chain::{
blob_verification::{BlockWrapper, IntoAvailableBlock},
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy},
};
use beacon_chain::{StateSkipConfig, WhenSlotSkipped}; use beacon_chain::{StateSkipConfig, WhenSlotSkipped};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::sync::Arc; use std::sync::Arc;
@ -131,6 +134,8 @@ async fn produces_attestations() {
assert_eq!(data.target.epoch, state.current_epoch(), "bad target epoch"); assert_eq!(data.target.epoch, state.current_epoch(), "bad target epoch");
assert_eq!(data.target.root, target_root, "bad target root"); assert_eq!(data.target.root, target_root, "bad target root");
let block_wrapper: BlockWrapper<MainnetEthSpec> = Arc::new(block.clone()).into();
let early_attestation = { let early_attestation = {
let proto_block = chain let proto_block = chain
.canonical_head .canonical_head
@ -141,7 +146,9 @@ async fn produces_attestations() {
.early_attester_cache .early_attester_cache
.add_head_block( .add_head_block(
block_root, block_root,
Arc::new(block.clone()).into(), block_wrapper
.into_available_block(block_root, chain)
.expect("should wrap into available block"),
proto_block, proto_block,
&state, &state,
&chain.spec, &chain.spec,
@ -192,12 +199,18 @@ async fn early_attester_cache_old_request() {
.get_block(&head.beacon_block_root) .get_block(&head.beacon_block_root)
.unwrap(); .unwrap();
let block: BlockWrapper<MainnetEthSpec> = head.beacon_block.clone().into();
let chain = &harness.chain;
harness harness
.chain .chain
.early_attester_cache .early_attester_cache
.add_head_block( .add_head_block(
head.beacon_block_root, head.beacon_block_root,
head.beacon_block.clone().into(), block
.clone()
.into_available_block(head.beacon_block_root, &chain)
.expect("should wrap into available block"),
head_proto_block, head_proto_block,
&head.beacon_state, &head.beacon_state,
&harness.chain.spec, &harness.chain.spec,

View File

@ -1,7 +1,11 @@
#![cfg(not(debug_assertions))] #![cfg(not(debug_assertions))]
use beacon_chain::test_utils::{ use beacon_chain::{
AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralTestingSlotClockHarnessType, blob_verification::{AsBlock, BlockWrapper},
test_utils::{
AttestationStrategy, BeaconChainHarness, BlockStrategy,
EphemeralTestingSlotClockHarnessType,
},
}; };
use beacon_chain::{BeaconSnapshot, BlockError, ChainSegmentResult, NotifyExecutionLayer}; use beacon_chain::{BeaconSnapshot, BlockError, ChainSegmentResult, NotifyExecutionLayer};
use fork_choice::CountUnrealized; use fork_choice::CountUnrealized;
@ -16,7 +20,6 @@ use state_processing::{
use std::marker::PhantomData; use std::marker::PhantomData;
use std::sync::Arc; use std::sync::Arc;
use tempfile::tempdir; use tempfile::tempdir;
use types::signed_block_and_blobs::BlockWrapper;
use types::{test_utils::generate_deterministic_keypair, *}; use types::{test_utils::generate_deterministic_keypair, *};
type E = MainnetEthSpec; type E = MainnetEthSpec;
@ -173,7 +176,7 @@ async fn chain_segment_full_segment() {
assert_eq!( assert_eq!(
harness.head_block_root(), harness.head_block_root(),
blocks.last().unwrap().block().canonical_root(), blocks.last().unwrap().canonical_root(),
"harness should have last block as head" "harness should have last block as head"
); );
} }
@ -210,7 +213,7 @@ async fn chain_segment_varying_chunk_size() {
assert_eq!( assert_eq!(
harness.head_block_root(), harness.head_block_root(),
blocks.last().unwrap().block().canonical_root(), blocks.last().unwrap().canonical_root(),
"harness should have last block as head" "harness should have last block as head"
); );
} }
@ -254,7 +257,8 @@ async fn chain_segment_non_linear_parent_roots() {
.into_iter() .into_iter()
.map(|block| block.into()) .map(|block| block.into())
.collect(); .collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct();
let (mut block, signature) = blocks[3].as_block().clone().deconstruct();
*block.parent_root_mut() = Hash256::zero(); *block.parent_root_mut() = Hash256::zero();
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into(); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();
@ -288,7 +292,7 @@ async fn chain_segment_non_linear_slots() {
.into_iter() .into_iter()
.map(|block| block.into()) .map(|block| block.into())
.collect(); .collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct(); let (mut block, signature) = blocks[3].as_block().clone().deconstruct();
*block.slot_mut() = Slot::new(0); *block.slot_mut() = Slot::new(0);
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into(); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();
@ -312,7 +316,7 @@ async fn chain_segment_non_linear_slots() {
.into_iter() .into_iter()
.map(|block| block.into()) .map(|block| block.into())
.collect(); .collect();
let (mut block, signature) = blocks[3].block().clone().deconstruct(); let (mut block, signature) = blocks[3].as_block().clone().deconstruct();
*block.slot_mut() = blocks[2].slot(); *block.slot_mut() = blocks[2].slot();
blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into(); blocks[3] = Arc::new(SignedBeaconBlock::from_block(block, signature)).into();

View File

@ -38,13 +38,13 @@ use tokio::{
time::sleep, time::sleep,
}; };
use tokio_stream::wrappers::WatchStream; use tokio_stream::wrappers::WatchStream;
use types::consts::eip4844::BLOB_TX_TYPE;
use types::transaction::{AccessTuple, BlobTransaction};
use types::{ use types::{
blobs_sidecar::{Blobs, KzgCommitments}, blobs_sidecar::{Blobs, KzgCommitments},
ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadEip4844, ExecutionPayloadMerge, ExecutionPayload, ExecutionPayloadCapella, ExecutionPayloadEip4844, ExecutionPayloadMerge,
}; };
use types::{AbstractExecPayload, BeaconStateError, ExecPayload}; use types::{AbstractExecPayload, BeaconStateError, ExecPayload};
use types::consts::eip4844::BLOB_TX_TYPE;
use types::transaction::{AccessTuple, BlobTransaction};
use types::{ use types::{
BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ForkName, BlindedPayload, BlockType, ChainSpec, Epoch, ExecutionBlockHash, ForkName,
ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction, ProposerPreparationData, PublicKeyBytes, Signature, SignedBeaconBlock, Slot, Transaction,

View File

@ -799,7 +799,7 @@ impl<T: BeaconChainTypes> Worker<T> {
let mut send_response = true; let mut send_response = true;
for root in block_roots { for root in block_roots {
match self.chain.get_blobs(&root, data_availability_boundary) { match self.chain.get_blobs(&root) {
Ok(Some(blobs)) => { Ok(Some(blobs)) => {
blobs_sent += 1; blobs_sent += 1;
self.send_network_message(NetworkMessage::SendResponse { self.send_network_message(NetworkMessage::SendResponse {

View File

@ -177,8 +177,8 @@ pub use crate::signed_beacon_block::{
SignedBlindedBeaconBlock, SignedBlindedBeaconBlock,
}; };
pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader; pub use crate::signed_beacon_block_header::SignedBeaconBlockHeader;
pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecar;
pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecarDecode; pub use crate::signed_block_and_blobs::SignedBeaconBlockAndBlobsSidecarDecode;
pub use crate::signed_block_and_blobs::{BlockWrapper, SignedBeaconBlockAndBlobsSidecar};
pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange; pub use crate::signed_bls_to_execution_change::SignedBlsToExecutionChange;
pub use crate::signed_contribution_and_proof::SignedContributionAndProof; pub use crate::signed_contribution_and_proof::SignedContributionAndProof;
pub use crate::signed_voluntary_exit::SignedVoluntaryExit; pub use crate::signed_voluntary_exit::SignedVoluntaryExit;

View File

@ -265,7 +265,7 @@ impl<E: EthSpec, Payload: AbstractExecPayload<E>> SignedBeaconBlock<E, Payload>
.map_err(|_| BlobReconstructionError::InconsistentFork)?; .map_err(|_| BlobReconstructionError::InconsistentFork)?;
if kzg_commitments.is_empty() { if kzg_commitments.is_empty() {
Ok(BlobsSidecar::empty_from_parts( Ok(BlobsSidecar::empty_from_parts(
block_root_opt.unwrap_or(self.canonical_root()), block_root_opt.unwrap_or_else(|| self.canonical_root()),
self.slot(), self.slot(),
)) ))
} else { } else {