Use empty_uninitialized and fix warnings

This commit is contained in:
Pawan Dhananjay
2024-08-30 15:54:00 -07:00
parent 4dc6e6515e
commit a9cb329a22
11 changed files with 24 additions and 29 deletions

View File

@@ -12,7 +12,6 @@ use crate::{metrics, BeaconChainError};
use kzg::{Error as KzgError, Kzg, KzgCommitment};
use slog::debug;
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use std::time::Duration;
use tree_hash::TreeHash;
use types::blob_sidecar::BlobIdentifier;

View File

@@ -81,7 +81,6 @@ use slog::{debug, error, warn, Logger};
use slot_clock::SlotClock;
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use state_processing::per_block_processing::{errors::IntoWithIndex, is_merge_transition_block};
use state_processing::{
block_signature_verifier::{BlockSignatureVerifier, Error as BlockSignatureVerifierError},

View File

@@ -8,11 +8,10 @@ use crate::data_column_verification::{
use crate::eth1_finalization_cache::Eth1FinalizationData;
use crate::{get_block_root, GossipVerifiedBlock, PayloadVerificationOutcome};
use derivative::Derivative;
use ssz_types::VariableList;
use state_processing::ConsensusContext;
use std::fmt::{Debug, Formatter};
use std::sync::Arc;
use types::blob_sidecar::{self, BlobIdentifier, FixedBlobSidecarList};
use types::blob_sidecar::{self, BlobIdentifier};
use types::data_column_sidecar::{self};
use types::{
BeaconBlockRef, BeaconState, BlindedPayload, BlobSidecarList, ChainSpec, Epoch, EthSpec,

View File

@@ -11,7 +11,6 @@ use crate::BeaconChainTypes;
use kzg::Kzg;
use lru::LruCache;
use parking_lot::RwLock;
use ssz_types::{FixedVector, VariableList};
use std::collections::HashSet;
use std::num::NonZeroUsize;
use std::sync::Arc;

View File

@@ -37,7 +37,6 @@ use network::{NetworkConfig, NetworkSenders, NetworkService};
use slasher::Slasher;
use slasher_service::SlasherService;
use slog::{debug, info, warn, Logger};
use ssz::Decode;
use std::net::TcpListener;
use std::path::{Path, PathBuf};
use std::sync::Arc;

View File

@@ -279,15 +279,21 @@ impl BlockId {
.get_blobs(&root)
.map_err(warp_utils::reject::beacon_chain_error)?;
let max_len = blob_sidecar_list.max_len();
let blob_sidecar_list_filtered = match indices.indices {
Some(vec) => {
let list = blob_sidecar_list
let list: Vec<_> = blob_sidecar_list
.into_iter()
.filter(|blob_sidecar| vec.contains(&blob_sidecar.index))
.collect();
BlobSidecarList::new(list, max_len)
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))?
if let Some(max_len) = list
.first()
.map(|sidecar| chain.spec.max_blobs_per_block(sidecar.epoch()))
{
BlobSidecarList::new(list, max_len as usize)
.map_err(|e| warp_utils::reject::custom_server_error(format!("{:?}", e)))?
} else {
BlobSidecarList::empty_uninitialized()
}
}
None => blob_sidecar_list,
};

View File

@@ -23,7 +23,7 @@ use types::{
AbstractExecPayload, BeaconBlockRef, BlobSidecarList, BlockImportSource, DataColumnSidecarList,
DataColumnSubnetId, EthSpec, ExecPayload, ExecutionBlockHash, ForkName, FullPayload,
FullPayloadBellatrix, Hash256, RuntimeVariableList, SignedBeaconBlock,
SignedBlindedBeaconBlock, VariableList,
SignedBlindedBeaconBlock,
};
use warp::http::StatusCode;
use warp::{reply::Response, Rejection, Reply};

View File

@@ -2,7 +2,6 @@ use beacon_chain::{
block_verification_types::RpcBlock, data_column_verification::CustodyDataColumn, get_block_root,
};
use lighthouse_network::PeerId;
use ssz_types::VariableList;
use std::{
collections::{HashMap, VecDeque},
sync::Arc,

View File

@@ -36,8 +36,8 @@ use std::time::Duration;
use tokio::sync::mpsc;
use types::blob_sidecar::FixedBlobSidecarList;
use types::{
chain_spec, BlobSidecar, ChainSpec, ColumnIndex, DataColumnSidecar, DataColumnSidecarList,
EthSpec, Hash256, SignedBeaconBlock, Slot,
BlobSidecar, ColumnIndex, DataColumnSidecar, DataColumnSidecarList, EthSpec,
Hash256, SignedBeaconBlock, Slot,
};
pub mod custody;

View File

@@ -1673,19 +1673,16 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
// a plain vec since we don't know the length limit of the list without
// knowing the slot.
// The encoding of a VariableList is same as a regular vec.
let blobs = BlobSidecarVec::from_ssz_bytes(blobs_bytes)?;
let max_blobs_per_block = blobs
let blobs: Vec<Arc<BlobSidecar<E>>> = Vec::<_>::from_ssz_bytes(blobs_bytes)?;
let blobs = if let Some(max_blobs_per_block) = blobs
.first()
.map(|blob| {
self.spec
.max_blobs_per_block(blob.slot().epoch(E::slots_per_epoch()))
})
// This is the case where we have no blobs for the slot, doesn't matter what value we keep for max here
// TODO(pawan): double check that this is the case
// we could also potentially deal with just vecs in the db since we only add length validated sidecar
// lists to the db
.unwrap_or(6);
let blobs = BlobSidecarList::from_vec(blobs, max_blobs_per_block as usize);
.map(|blob| self.spec.max_blobs_per_block(blob.epoch()))
{
BlobSidecarList::from_vec(blobs, max_blobs_per_block as usize)
} else {
// This always implies that there were no blobs for this block_root
BlobSidecarList::empty_uninitialized()
};
self.block_cache
.lock()
.put_blobs(*block_root, blobs.clone());