Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single blob lookups #4152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
8d80200
some blob reprocessing work
realbigsean Mar 28, 2023
9642ec0
remove ForceBlockLookup
realbigsean Mar 29, 2023
b78a6e8
reorder enum match arms in sync manager
realbigsean Mar 29, 2023
8403402
a lot more reprocessing work
realbigsean Mar 31, 2023
a17405a
impl logic for triggerng blob lookups along with block lookups
realbigsean Mar 31, 2023
22694d1
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 4, 2023
6f12df3
deal with rpc blobs in groups per block in the da checker. don't cach…
realbigsean Apr 4, 2023
38e0994
make single block lookup generic
realbigsean Apr 4, 2023
66e09f4
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 6, 2023
25ff6e8
more work
realbigsean Apr 11, 2023
2f8c885
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 12, 2023
8618c30
add delayed processing logic and combine some requests
realbigsean Apr 14, 2023
195d802
start fixing some compile errors
realbigsean Apr 17, 2023
0ad9fdf
fix compilation in main block lookup mod
realbigsean Apr 19, 2023
374ec48
much work
realbigsean Apr 19, 2023
c714249
get things compiling
realbigsean Apr 20, 2023
0cc1704
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 20, 2023
bacec52
parent blob lookups
realbigsean Apr 20, 2023
3e854ae
fix compile
realbigsean Apr 21, 2023
d8ed811
revert red/stevie changes
pawanjay176 Apr 21, 2023
b2a4c4e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 22, 2023
269122f
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Apr 22, 2023
03de817
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 24, 2023
93df0f5
fix up sync manager delay message logic
realbigsean Apr 24, 2023
381044a
add peer usefulness enum
realbigsean Apr 24, 2023
b6531aa
should remove lookup refactor
realbigsean Apr 24, 2023
274aba9
consolidate retry error handling
realbigsean Apr 24, 2023
0560b7d
improve peer scoring during certain failures in parent lookups
realbigsean Apr 24, 2023
1d18756
improve retry code
realbigsean Apr 24, 2023
76c09de
drop parent lookup if either req has a peer disconnect during download
realbigsean Apr 24, 2023
91594ad
refactor single block processed method
realbigsean Apr 25, 2023
b8708e3
processing peer refactor
realbigsean Apr 25, 2023
53c0356
smol bugfix
realbigsean Apr 25, 2023
9c2acee
fix some todos
realbigsean Apr 25, 2023
b5440f7
fix lints
realbigsean Apr 25, 2023
14e5bfa
fix lints
realbigsean Apr 25, 2023
ff58698
fix compile in lookup tests
realbigsean Apr 26, 2023
83c3ee1
fix lints
realbigsean Apr 26, 2023
46a9b3a
fix lints
realbigsean Apr 26, 2023
4390036
fix existing block lookup tests
realbigsean Apr 26, 2023
69e5e00
renamings
realbigsean Apr 26, 2023
13f7217
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 26, 2023
d850788
fix after merge
realbigsean Apr 26, 2023
0978848
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 26, 2023
2cad638
cargo fmt
realbigsean Apr 26, 2023
3c9fb78
compilation fix in beacon chain tests
realbigsean Apr 26, 2023
7614abf
fix
realbigsean Apr 26, 2023
f226721
refactor lookup tests to work with multiple forks and response types
realbigsean Apr 27, 2023
8e9c98e
make tests into macros
realbigsean Apr 27, 2023
d224fce
wrap availability check error
realbigsean Apr 27, 2023
eadf293
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Apr 27, 2023
185b761
fix compile after merge
realbigsean Apr 27, 2023
a9b24bb
add random blobs
realbigsean Apr 27, 2023
bfb5242
start fixing up lookup verify error handling
realbigsean Apr 28, 2023
93bcd62
some bug fixes and the start of deneb only tests
realbigsean Apr 28, 2023
8edefb7
make tests work for all forks
realbigsean May 2, 2023
56b2365
track information about peer source
realbigsean May 2, 2023
e3f4218
error refactoring
realbigsean May 2, 2023
af15789
improve peer scoring
realbigsean May 2, 2023
f5facd6
fix test compilation
realbigsean May 2, 2023
a0f6159
make sure blobs are sent for processing after stream termination, del…
realbigsean May 3, 2023
6aff52c
add some tests and fix a bug
realbigsean May 8, 2023
51c4506
smol bugfixes and moar tests
realbigsean May 9, 2023
542e3c1
add tests and fix some things
realbigsean May 18, 2023
4dd1184
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean May 18, 2023
bef63e4
compile after merge
realbigsean May 18, 2023
c7aad77
lots of refactoring
realbigsean May 19, 2023
c59a3fc
retry on invalid block/blob
realbigsean May 22, 2023
8ea98c5
merge unknown parent messages before current slot lookup
realbigsean May 23, 2023
98d7a10
get tests compiling
realbigsean May 23, 2023
944c973
penalize blob peer on invalid blobs
realbigsean May 23, 2023
dc20155
Check disk on in-memory cache miss
ethDreamer May 27, 2023
4c17993
Update beacon_node/beacon_chain/src/data_availability_checker/overflo…
realbigsean May 30, 2023
2bcdfc6
Merge pull request #30 from ethDreamer/check_disk
realbigsean May 30, 2023
4ba3849
Update beacon_node/network/src/sync/network_context.rs
realbigsean Jun 1, 2023
8c5c92b
fix bug in matching blocks and blobs in range sync
realbigsean Jun 1, 2023
f31c551
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 1, 2023
28b92cd
pr feedback
realbigsean Jun 1, 2023
e503c8e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 2, 2023
e617486
fix conflicts
realbigsean Jun 2, 2023
844920c
upgrade logs from warn to crit when we receive incorrect response in …
realbigsean Jun 2, 2023
4b687c9
synced_and_connected_within_tolerance -> should_search_for_block
realbigsean Jun 2, 2023
e6b0754
remove todo
realbigsean Jun 6, 2023
ee9578f
Fix Broken Overflow Tests
ethDreamer Jun 7, 2023
584eb6e
Merge pull request #31 from ethDreamer/fix_overflow_tests
realbigsean Jun 7, 2023
ad422c3
Merge branch 'some-blob-reprocessing-work' of https://github.com/real…
realbigsean Jun 7, 2023
c9727ae
merge upstream
realbigsean Jun 7, 2023
185aecb
fix merge conflicts
realbigsean Jun 7, 2023
28576c9
checkpoint sync without alignment
realbigsean Jun 9, 2023
da25512
add import
realbigsean Jun 9, 2023
5fda708
query for checkpoint state by slot rather than state root (teku doesn…
realbigsean Jun 9, 2023
1ddd335
get state first and query by most recent block root
realbigsean Jun 12, 2023
d656d4b
simplify delay logic
realbigsean Jun 13, 2023
7461731
rename unknown parent sync message variants
realbigsean Jun 13, 2023
453e038
rename parameter, block_slot -> slot
realbigsean Jun 13, 2023
c39ae51
add some docs to the lookup module
realbigsean Jun 13, 2023
61b1a11
use interval instead of sleep
realbigsean Jun 13, 2023
a69b4af
drop request if blocks and blobs requests both return `None` for `Id`
realbigsean Jun 13, 2023
ef8630c
clean up `find_single_lookup` logic
realbigsean Jun 13, 2023
2a1ea23
add lookup source enum
realbigsean Jun 13, 2023
2d5a256
clean up `find_single_lookup` logic
realbigsean Jun 13, 2023
59df842
add docs to find_single_lookup_request
realbigsean Jun 13, 2023
3b84894
move LookupSource our of param where unnecessary
realbigsean Jun 13, 2023
db20e2e
remove unnecessary todo
realbigsean Jun 13, 2023
52ed9ab
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 13, 2023
36309d3
query for block by `state.latest_block_header.slot`
realbigsean Jun 13, 2023
b61772e
Merge branch 'deneb-free-blobs' of https://github.com/sigp/lighthouse…
realbigsean Jun 13, 2023
1c240fc
fix lint
realbigsean Jun 13, 2023
4dd2130
fix test
realbigsean Jun 13, 2023
5a2026a
fix test
realbigsean Jun 13, 2023
7887d40
Merge branch 'checkpoint-sync-without-alignment' of https://github.co…
realbigsean Jun 13, 2023
cf875ba
fix observed blob sidecars test
realbigsean Jun 13, 2023
b62e046
PR updates
realbigsean Jun 14, 2023
bd1280c
use optional params instead of a closure
realbigsean Jun 14, 2023
dd3cc28
create lookup and trigger request in separate method calls
realbigsean Jun 15, 2023
6af5171
remove `LookupSource`
realbigsean Jun 15, 2023
46eeb18
make sure duplicate lookups are not dropped
realbigsean Jun 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run operation_pool tests for all known forks
run: make test-op-pool
network-minimal-tests:
name: network-minimal-tests
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
- uses: actions/checkout@v3
- name: Get latest version of stable Rust
run: rustup update stable
- name: Install Protoc
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run network tests for all known forks using the minimal spec
run: make test-network-minimal
slasher-tests:
name: slasher-tests
runs-on: ubuntu-latest
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ build-release-tarballs:
# Runs the full workspace tests in **release**, without downloading any additional
# test vectors.
test-release:
cargo test --workspace --release --exclude ef_tests --exclude beacon_chain --exclude slasher
cargo test --workspace --release --exclude ef_tests --exclude beacon_chain --exclude slasher

# Runs the full workspace tests in **debug**, without downloading any additional test
# vectors.
Expand Down Expand Up @@ -143,6 +143,13 @@ test-op-pool-%:
--features 'beacon_chain/fork_from_env'\
-p operation_pool

test-network-minimal: $(patsubst %,test-network-minimal-%,$(FORKS))

test-network-minimal-%:
env FORK_NAME=$* cargo test --release \
--features 'fork_from_env,spec-minimal'\
-p network

# Run the tests in the `slasher` crate for all supported database backends.
test-slasher:
cargo test --release -p slasher --features lmdb
Expand Down
42 changes: 28 additions & 14 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ use tokio_stream::Stream;
use tree_hash::TreeHash;
use types::beacon_block_body::KzgCommitments;
use types::beacon_state::CloneConfig;
use types::blob_sidecar::{BlobIdentifier, BlobSidecarList, Blobs};
use types::blob_sidecar::{BlobSidecarList, Blobs};
use types::consts::deneb::MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS;
use types::*;

Expand Down Expand Up @@ -185,12 +185,10 @@ pub enum WhenSlotSkipped {

#[derive(Debug, PartialEq)]
pub enum AvailabilityProcessingStatus {
PendingBlobs(Vec<BlobIdentifier>),
PendingBlock(Hash256),
MissingComponents(Slot, Hash256),
Imported(Hash256),
}

//TODO(sean) using this in tests for now
impl TryInto<SignedBeaconBlockHash> for AvailabilityProcessingStatus {
type Error = ();

Expand Down Expand Up @@ -468,7 +466,7 @@ pub struct BeaconChain<T: BeaconChainTypes> {
/// The slot at which blocks are downloaded back to.
pub genesis_backfill_slot: Slot,
pub proposal_blob_cache: BlobCache<T::EthSpec>,
pub data_availability_checker: DataAvailabilityChecker<T>,
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
pub kzg: Option<Arc<Kzg>>,
}

Expand Down Expand Up @@ -1985,8 +1983,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self: &Arc<Self>,
blob_sidecar: SignedBlobSidecar<T::EthSpec>,
subnet_id: u64,
) -> Result<GossipVerifiedBlob<T::EthSpec>, BlobError> // TODO(pawan): make a GossipVerifedBlob type
{
) -> Result<GossipVerifiedBlob<T::EthSpec>, BlobError<T::EthSpec>> {
blob_verification::validate_blob_sidecar_for_gossip(blob_sidecar, subnet_id, self)
}

Expand Down Expand Up @@ -2674,7 +2671,24 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)
.await
{
Ok(_) => imported_blocks += 1,
Ok(status) => {
match status {
AvailabilityProcessingStatus::Imported(_) => {
// The block was imported successfully.
imported_blocks += 1;
}
AvailabilityProcessingStatus::MissingComponents(slot, block_root) => {
warn!(self.log, "Blobs missing in response to range request";
"block_root" => ?block_root, "slot" => slot);
return ChainSegmentResult::Failed {
imported_blocks,
error: BlockError::AvailabilityCheck(
AvailabilityCheckError::MissingBlobs,
),
};
}
}
}
Err(error) => {
return ChainSegmentResult::Failed {
imported_blocks,
Expand Down Expand Up @@ -2748,6 +2762,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
count_unrealized: CountUnrealized,
) -> Result<AvailabilityProcessingStatus, BlockError<T::EthSpec>> {
self.check_availability_and_maybe_import(
blob.slot(),
|chain| chain.data_availability_checker.put_gossip_blob(blob),
count_unrealized,
)
Expand Down Expand Up @@ -2804,6 +2819,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
ExecutedBlock::AvailabilityPending(block) => {
self.check_availability_and_maybe_import(
block.block.slot(),
|chain| {
chain
.data_availability_checker
Expand Down Expand Up @@ -2907,6 +2923,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// (i.e., this function is not atomic).
pub async fn check_availability_and_maybe_import(
self: &Arc<Self>,
slot: Slot,
cache_fn: impl FnOnce(Arc<Self>) -> Result<Availability<T::EthSpec>, AvailabilityCheckError>,
count_unrealized: CountUnrealized,
) -> Result<AvailabilityProcessingStatus, BlockError<T::EthSpec>> {
Expand All @@ -2915,12 +2932,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Availability::Available(block) => {
self.import_available_block(block, count_unrealized).await
}
Availability::PendingBlock(block_root) => {
Ok(AvailabilityProcessingStatus::PendingBlock(block_root))
}
Availability::PendingBlobs(blob_ids) => {
Ok(AvailabilityProcessingStatus::PendingBlobs(blob_ids))
}
Availability::MissingComponents(block_root) => Ok(
AvailabilityProcessingStatus::MissingComponents(slot, block_root),
),
}
}

Expand Down
83 changes: 47 additions & 36 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ use eth2::types::BlockContentsTuple;
use kzg::Kzg;
use slog::{debug, warn};
use ssz_derive::{Decode, Encode};
use ssz_types::FixedVector;
use std::borrow::Cow;
use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList};
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecar, BlobSidecarList, ChainSpec,
CloneConfig, Epoch, EthSpec, FullPayload, Hash256, KzgCommitment, RelativeEpoch,
SignedBeaconBlock, SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecar, ChainSpec, CloneConfig, Epoch,
EthSpec, FullPayload, Hash256, KzgCommitment, RelativeEpoch, SignedBeaconBlock,
SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
};

#[derive(Debug)]
pub enum BlobError {
pub enum BlobError<T: EthSpec> {
/// The blob sidecar is from a slot that is later than the current slot (with respect to the
/// gossip clock disparity).
///
Expand Down Expand Up @@ -96,10 +98,7 @@ pub enum BlobError {
/// ## Peer scoring
///
/// We cannot process the blob without validating its parent, the peer isn't necessarily faulty.
BlobParentUnknown {
blob_root: Hash256,
blob_parent_root: Hash256,
},
BlobParentUnknown(Arc<BlobSidecar<T>>),

/// A blob has already been seen for the given `(sidecar.block_root, sidecar.index)` tuple
/// over gossip or no gossip sources.
Expand All @@ -114,41 +113,50 @@ pub enum BlobError {
},
}

impl From<BeaconChainError> for BlobError {
impl<T: EthSpec> From<BeaconChainError> for BlobError<T> {
fn from(e: BeaconChainError) -> Self {
BlobError::BeaconChainError(e)
}
}

impl From<BeaconStateError> for BlobError {
impl<T: EthSpec> From<BeaconStateError> for BlobError<T> {
fn from(e: BeaconStateError) -> Self {
BlobError::BeaconChainError(BeaconChainError::BeaconStateError(e))
}
}

/// A wrapper around a `BlobSidecar` that indicates it has been approved for re-gossiping on
/// the p2p network.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct GossipVerifiedBlob<T: EthSpec> {
blob: Arc<BlobSidecar<T>>,
}

impl<T: EthSpec> GossipVerifiedBlob<T> {
pub fn id(&self) -> BlobIdentifier {
self.blob.id()
}
pub fn block_root(&self) -> Hash256 {
self.blob.block_root
}
pub fn to_blob(self) -> Arc<BlobSidecar<T>> {
self.blob
}
pub fn slot(&self) -> Slot {
self.blob.slot
}
}

pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
signed_blob_sidecar: SignedBlobSidecar<T::EthSpec>,
subnet: u64,
chain: &BeaconChain<T>,
) -> Result<GossipVerifiedBlob<T::EthSpec>, BlobError> {
) -> Result<GossipVerifiedBlob<T::EthSpec>, BlobError<T::EthSpec>> {
let blob_slot = signed_blob_sidecar.message.slot;
let blob_index = signed_blob_sidecar.message.index;
let block_root = signed_blob_sidecar.message.block_root;
let block_parent_root = signed_blob_sidecar.message.block_parent_root;
let blob_proposer_index = signed_blob_sidecar.message.proposer_index;
let block_root = signed_blob_sidecar.message.block_root;

// Verify that the blob_sidecar was received on the correct subnet.
if blob_index != subnet {
Expand Down Expand Up @@ -211,10 +219,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes>(
});
}
} else {
return Err(BlobError::BlobParentUnknown {
blob_root: block_root,
blob_parent_root: block_parent_root,
});
return Err(BlobError::BlobParentUnknown(signed_blob_sidecar.message));
}

// Note: We check that the proposer_index matches against the shuffling first to avoid
Expand Down Expand Up @@ -366,7 +371,7 @@ fn cheap_state_advance_to_obtain_committees<'a, E: EthSpec>(
state_root_opt: Option<Hash256>,
blob_slot: Slot,
spec: &ChainSpec,
) -> Result<Cow<'a, BeaconState<E>>, BlobError> {
) -> Result<Cow<'a, BeaconState<E>>, BlobError<E>> {
let block_epoch = blob_slot.epoch(E::slots_per_epoch());

if state.current_epoch() == block_epoch {
Expand Down Expand Up @@ -443,19 +448,14 @@ impl<T: EthSpec> KzgVerifiedBlob<T> {
///
/// Returns an error if the kzg verification check fails.
pub fn verify_kzg_for_blob<T: EthSpec>(
blob: GossipVerifiedBlob<T>,
blob: Arc<BlobSidecar<T>>,
kzg: &Kzg,
) -> Result<KzgVerifiedBlob<T>, AvailabilityCheckError> {
//TODO(sean) remove clone
if validate_blob::<T>(
kzg,
blob.blob.blob.clone(),
blob.blob.kzg_commitment,
blob.blob.kzg_proof,
)
.map_err(AvailabilityCheckError::Kzg)?
if validate_blob::<T>(kzg, blob.blob.clone(), blob.kzg_commitment, blob.kzg_proof)
.map_err(AvailabilityCheckError::Kzg)?
{
Ok(KzgVerifiedBlob { blob: blob.blob })
Ok(KzgVerifiedBlob { blob })
} else {
Err(AvailabilityCheckError::KzgVerificationFailed)
}
Expand All @@ -467,7 +467,7 @@ pub fn verify_kzg_for_blob<T: EthSpec>(
/// Note: This function should be preferred over calling `verify_kzg_for_blob`
/// in a loop since this function kzg verifies a list of blobs more efficiently.
pub fn verify_kzg_for_blob_list<T: EthSpec>(
blob_list: BlobSidecarList<T>,
blob_list: Vec<Arc<BlobSidecar<T>>>,
kzg: &Kzg,
) -> Result<KzgVerifiedBlobList<T>, AvailabilityCheckError> {
let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_list
Expand Down Expand Up @@ -608,7 +608,16 @@ impl<E: EthSpec> AsBlock<E> for &MaybeAvailableBlock<E> {
#[derivative(Hash(bound = "E: EthSpec"))]
pub enum BlockWrapper<E: EthSpec> {
Block(Arc<SignedBeaconBlock<E>>),
BlockAndBlobs(Arc<SignedBeaconBlock<E>>, Vec<Arc<BlobSidecar<E>>>),
BlockAndBlobs(Arc<SignedBeaconBlock<E>>, FixedBlobSidecarList<E>),
}

impl<E: EthSpec> BlockWrapper<E> {
pub fn deconstruct(self) -> (Arc<SignedBeaconBlock<E>>, Option<FixedBlobSidecarList<E>>) {
match self {
BlockWrapper::Block(block) => (block, None),
BlockWrapper::BlockAndBlobs(block, blobs) => (block, Some(blobs)),
}
}
}

impl<E: EthSpec> AsBlock<E> for BlockWrapper<E> {
Expand Down Expand Up @@ -675,13 +684,15 @@ impl<E: EthSpec> From<SignedBeaconBlock<E>> for BlockWrapper<E> {
impl<E: EthSpec> From<BlockContentsTuple<E, FullPayload<E>>> for BlockWrapper<E> {
fn from(value: BlockContentsTuple<E, FullPayload<E>>) -> Self {
match value.1 {
Some(variable_list) => Self::BlockAndBlobs(
Arc::new(value.0),
Vec::from(variable_list)
.into_iter()
.map(|signed_blob| signed_blob.message)
.collect::<Vec<_>>(),
),
Some(variable_list) => {
let mut blobs = Vec::with_capacity(E::max_blobs_per_block());
for blob in variable_list {
if blob.message.index < E::max_blobs_per_block() as u64 {
blobs.insert(blob.message.index as usize, Some(blob.message));
}
}
Self::BlockAndBlobs(Arc::new(value.0), FixedVector::from(blobs))
}
None => Self::Block(Arc::new(value.0)),
}
}
Expand Down
Loading