From adf5f462d5bea99bcc3d603398d295bcf6769319 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Fri, 23 Dec 2022 12:59:04 -0500 Subject: [PATCH] fix blob validation for empty blobs when using --- beacon_node/beacon_chain/src/attester_cache.rs | 1 + beacon_node/beacon_chain/src/beacon_chain.rs | 2 +- beacon_node/beacon_chain/src/early_attester_cache.rs | 4 ++-- consensus/types/src/signed_block_and_blobs.rs | 11 +++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/beacon_node/beacon_chain/src/attester_cache.rs b/beacon_node/beacon_chain/src/attester_cache.rs index 24963a125..8e2dfdab8 100644 --- a/beacon_node/beacon_chain/src/attester_cache.rs +++ b/beacon_node/beacon_chain/src/attester_cache.rs @@ -42,6 +42,7 @@ pub enum Error { // Boxed to avoid an infinite-size recursion issue. BeaconChain(Box), MissingBeaconState(Hash256), + MissingBlobs, FailedToTransitionState(StateAdvanceError), CannotAttestToFutureState { state_slot: Slot, diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index a8ed70561..3e2be9202 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2935,7 +2935,7 @@ impl BeaconChain { // If the write fails, revert fork choice to the version from disk, else we can // end up with blocks in fork choice that are missing from disk. // See https://github.com/sigp/lighthouse/issues/2028 - let (signed_block, blobs) = signed_block.deconstruct(); + let (signed_block, blobs) = signed_block.deconstruct(Some(block_root)); let block = signed_block.message(); let mut ops: Vec<_> = confirmed_state_roots .into_iter() diff --git a/beacon_node/beacon_chain/src/early_attester_cache.rs b/beacon_node/beacon_chain/src/early_attester_cache.rs index 9254a3eb3..d8382481f 100644 --- a/beacon_node/beacon_chain/src/early_attester_cache.rs +++ b/beacon_node/beacon_chain/src/early_attester_cache.rs @@ -69,7 +69,7 @@ impl EarlyAttesterCache { }, }; - let (block, blobs) = block.deconstruct(); + let (block, blobs) = block.deconstruct(Some(beacon_block_root)); let item = CacheItem { epoch, committee_lengths, @@ -77,7 +77,7 @@ impl EarlyAttesterCache { source, target, block, - blobs: blobs?, + blobs: blobs.map_err(|_|Error::MissingBlobs)?, proto_block, }; diff --git a/consensus/types/src/signed_block_and_blobs.rs b/consensus/types/src/signed_block_and_blobs.rs index 2c9955bdb..fead50f38 100644 --- a/consensus/types/src/signed_block_and_blobs.rs +++ b/consensus/types/src/signed_block_and_blobs.rs @@ -93,11 +93,14 @@ impl BlockWrapper { self.block().parent_root() } - pub fn deconstruct(self) -> (Arc>, Result>>, BlobReconstructionError>) { + pub fn deconstruct(self, block_root: Option) -> (Arc>, Result>>, BlobReconstructionError>) { match self { - BlockWrapper::Block(block) => (block, block - .reconstruct_empty_blobs(block_root) - .map(|blob_opt| blob_opt.map(Arc::new))), + BlockWrapper::Block(block) => { + let blobs = block + .reconstruct_empty_blobs(block_root) + .map(|blob_opt| blob_opt.map(Arc::new)); + (block,blobs) + } , BlockWrapper::BlockAndBlob(block_sidecar_pair) => { let SignedBeaconBlockAndBlobsSidecar { beacon_block,