Skip to content

Commit c161333

Browse files
committed
I just yeeted a bunch of code
1 parent 1ef3ce7 commit c161333

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1221
-994
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ use safe_arith::SafeArith;
102102
use slasher::Slasher;
103103
use slot_clock::SlotClock;
104104
use ssz::Encode;
105+
use ssz_types::RuntimeVariableList;
105106
use state_processing::{
106107
BlockSignatureStrategy, ConsensusContext, SigVerifiedOp, VerifyBlockRoot, VerifyOperation,
107108
common::get_attesting_indices_from_state,
@@ -1130,19 +1131,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
11301131
if let Some(mut all_cached_columns) = all_cached_columns_opt {
11311132
all_cached_columns.retain(|col| indices.contains(col.index()));
11321133
Ok(all_cached_columns)
1133-
} else {
1134-
if let Some(block) = self.get_blinded_block(&block_root)? {
1135-
indices
1134+
} else if let Some(block) = self.get_blinded_block(&block_root)? {
1135+
indices
11361136
.iter()
11371137
.filter_map(|index| {
11381138
self.get_data_column(&block_root, index, block.fork_name_unchecked())
11391139
.transpose()
11401140
})
11411141
.collect::<Result<_, _>>()
1142-
} else {
1143-
Ok(vec![])
1144-
}
1145-
1142+
} else {
1143+
Ok(vec![])
11461144
}
11471145
}
11481146

@@ -1269,7 +1267,19 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
12691267
Ok(None)
12701268
}
12711269
} else {
1272-
self.get_blobs(block_root).map(|b| b.blobs())
1270+
let max_blobs = self.spec.max_blobs_per_block(block.epoch());
1271+
let blobs = self.get_blobs(block_root)?.blobs();
1272+
match blobs {
1273+
Some(blobs) => {
1274+
let list: Vec<_> = blobs
1275+
.into_iter()
1276+
.map(|blob| Arc::new(BlobSidecar::Deneb((*blob).clone())))
1277+
.collect();
1278+
let blob_sidecar_list = RuntimeVariableList::new(list, max_blobs as usize)?;
1279+
Ok(Some(blob_sidecar_list))
1280+
}
1281+
None => Ok(None),
1282+
}
12731283
}
12741284
}
12751285

@@ -3064,24 +3074,18 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30643074
}
30653075

30663076
for blob in &blobs {
3067-
if let Some(blob) = blob {
3068-
match blob.as_ref() {
3069-
// Reject RPC blobs referencing unknown parents. Otherwise we allow potentially invalid data
3070-
// into the da_checker, where invalid = descendant of invalid blocks.
3071-
// Note: blobs should have at least one item and all items have the same parent root.
3072-
BlobSidecar::Deneb(blob) => {
3073-
if !self
3074-
.canonical_head
3075-
.fork_choice_read_lock()
3076-
.contains_block(&blob.block_parent_root())
3077-
{
3078-
return Err(BlockError::ParentUnknown {
3079-
parent_root: blob.block_parent_root(),
3080-
});
3081-
}
3082-
}
3083-
// Dont need to handle the Gloas variant, since blobs wont be served over RPC post-Fulu
3084-
_ => {}
3077+
if let Some(blob) = blob.as_ref() {
3078+
// Reject RPC blobs referencing unknown parents. Otherwise we allow potentially invalid data
3079+
// into the da_checker, where invalid = descendant of invalid blocks.
3080+
// Note: blobs should have at least one item and all items have the same parent root.
3081+
if !self
3082+
.canonical_head
3083+
.fork_choice_read_lock()
3084+
.contains_block(&blob.block_parent_root())
3085+
{
3086+
return Err(BlockError::ParentUnknown {
3087+
parent_root: blob.block_parent_root(),
3088+
});
30853089
}
30863090
}
30873091
}
@@ -3124,7 +3128,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
31243128

31253129
fn emit_sse_blob_sidecar_events<'a, I>(self: &Arc<Self>, block_root: &Hash256, blobs_iter: I)
31263130
where
3127-
I: Iterator<Item = &'a BlobSidecar<T::EthSpec>>,
3131+
I: Iterator<Item = &'a BlobSidecarDeneb<T::EthSpec>>,
31283132
{
31293133
if let Some(event_handler) = self.event_handler.as_ref()
31303134
&& event_handler.has_blob_sidecar_subscribers()
@@ -3133,7 +3137,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
31333137
.data_availability_checker
31343138
.cached_blob_indexes(block_root)
31353139
.unwrap_or_default();
3136-
let new_blobs = blobs_iter.filter(|b| !imported_blobs.contains(b.index()));
3140+
let new_blobs = blobs_iter.filter(|b| !imported_blobs.contains(&b.index));
31373141

31383142
for blob in new_blobs {
31393143
event_handler.register(EventKind::BlobSidecar(SseBlobSidecar::from_blob_sidecar(
@@ -3561,10 +3565,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
35613565
) -> Result<AvailabilityProcessingStatus, BlockError> {
35623566
self.check_blob_header_signature_and_slashability(
35633567
block_root,
3564-
blobs.iter().flatten().filter_map(|b| match b.as_ref() {
3565-
BlobSidecar::Deneb(blob) => Some(blob),
3566-
_ => None,
3567-
}),
3568+
blobs.iter().flatten().map(|b| b.as_ref()),
35683569
)?;
35693570
let availability = self
35703571
.data_availability_checker
@@ -7347,7 +7348,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
73477348
}
73487349

73497350
/// Retrieves block roots (in ascending slot order) within some slot range from fork choice.
7350-
pub fn block_roots_from_fork_choice(&self, start_slot: u64, count: u64) -> Vec<Hash256> {
7351+
pub fn block_roots_from_fork_choice(
7352+
&self,
7353+
start_slot: u64,
7354+
count: u64,
7355+
) -> Vec<(Hash256, Slot)> {
73517356
let head_block_root = self.canonical_head.cached_head().head_block_root();
73527357
let fork_choice_read_lock = self.canonical_head.fork_choice_read_lock();
73537358
let block_roots_iter = fork_choice_read_lock
@@ -7358,7 +7363,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
73587363

73597364
for (root, slot) in block_roots_iter {
73607365
if slot < end_slot && slot >= start_slot {
7361-
roots.push(root);
7366+
roots.push((root, slot));
73627367
}
73637368
if slot < start_slot {
73647369
break;

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
use educe::Educe;
2-
use slot_clock::SlotClock;
3-
use std::marker::PhantomData;
4-
use std::sync::Arc;
5-
6-
use crate::beacon_chain::{BeaconChain, BeaconChainTypes};
7-
use crate::block_verification::{
8-
BlockSlashInfo, get_validator_pubkey_cache, process_block_slash_info,
9-
};
101
use crate::kzg_utils::{validate_blob, validate_blobs};
11-
use crate::observed_data_sidecars::{ObservationStrategy, Observe};
122
use crate::{BeaconChainError, metrics};
3+
use educe::Educe;
134
use kzg::{Error as KzgError, Kzg, KzgCommitment};
145
use ssz_derive::{Decode, Encode};
6+
use std::sync::Arc;
157
use std::time::Duration;
16-
use tracing::{debug, instrument};
8+
use tracing::instrument;
179
use tree_hash::TreeHash;
18-
use types::data::BlobIdentifier;
19-
use types::{
20-
BeaconStateError, BlobSidecar, Epoch, EthSpec, Hash256, SignedBeaconBlockHeader, Slot,
21-
};
10+
use types::{BeaconStateError, BlobSidecar, BlobSidecarDeneb, EthSpec, Hash256, Slot};
2211

2312
/// An error occurred while validating a gossip blob.
2413
#[derive(Debug)]
@@ -162,7 +151,7 @@ impl From<BeaconStateError> for GossipBlobError {
162151
#[educe(PartialEq, Eq)]
163152
#[ssz(struct_behaviour = "transparent")]
164153
pub struct KzgVerifiedBlob<E: EthSpec> {
165-
blob: Arc<BlobSidecar<E>>,
154+
blob: Arc<BlobSidecarDeneb<E>>,
166155
#[ssz(skip_serializing, skip_deserializing)]
167156
seen_timestamp: Duration,
168157
}
@@ -181,27 +170,27 @@ impl<E: EthSpec> Ord for KzgVerifiedBlob<E> {
181170

182171
impl<E: EthSpec> KzgVerifiedBlob<E> {
183172
pub fn new(
184-
blob: Arc<BlobSidecar<E>>,
173+
blob: Arc<BlobSidecarDeneb<E>>,
185174
kzg: &Kzg,
186175
seen_timestamp: Duration,
187176
) -> Result<Self, KzgError> {
188177
verify_kzg_for_blob(blob, kzg, seen_timestamp)
189178
}
190-
pub fn to_blob(self) -> Arc<BlobSidecar<E>> {
179+
pub fn to_blob(self) -> Arc<BlobSidecarDeneb<E>> {
191180
self.blob
192181
}
193-
pub fn as_blob(&self) -> &BlobSidecar<E> {
182+
pub fn as_blob(&self) -> &BlobSidecarDeneb<E> {
194183
&self.blob
195184
}
196185
pub fn get_commitment(&self) -> &KzgCommitment {
197-
&self.blob.kzg_commitment()
186+
&self.blob.kzg_commitment
198187
}
199188
/// This is cheap as we're calling clone on an Arc
200-
pub fn clone_blob(&self) -> Arc<BlobSidecar<E>> {
189+
pub fn clone_blob(&self) -> Arc<BlobSidecarDeneb<E>> {
201190
self.blob.clone()
202191
}
203192
pub fn blob_index(&self) -> u64 {
204-
*self.blob.index()
193+
self.blob.index
205194
}
206195
pub fn seen_timestamp(&self) -> Duration {
207196
self.seen_timestamp
@@ -210,15 +199,18 @@ impl<E: EthSpec> KzgVerifiedBlob<E> {
210199
///
211200
/// This should ONLY be used for testing.
212201
#[cfg(test)]
213-
pub fn __assumed_valid(blob: Arc<BlobSidecar<E>>) -> Self {
202+
pub fn __assumed_valid(blob: Arc<BlobSidecarDeneb<E>>) -> Self {
214203
Self {
215204
blob,
216205
seen_timestamp: Duration::from_secs(0),
217206
}
218207
}
219208
/// Mark a blob as KZG verified. Caller must ONLY use this on blob sidecars constructed
220209
/// from EL blobs.
221-
pub fn from_execution_verified(blob: Arc<BlobSidecar<E>>, seen_timestamp: Duration) -> Self {
210+
pub fn from_execution_verified(
211+
blob: Arc<BlobSidecarDeneb<E>>,
212+
seen_timestamp: Duration,
213+
) -> Self {
222214
Self {
223215
blob,
224216
seen_timestamp,
@@ -230,11 +222,11 @@ impl<E: EthSpec> KzgVerifiedBlob<E> {
230222
///
231223
/// Returns an error if the kzg verification check fails.
232224
pub fn verify_kzg_for_blob<E: EthSpec>(
233-
blob: Arc<BlobSidecar<E>>,
225+
blob: Arc<BlobSidecarDeneb<E>>,
234226
kzg: &Kzg,
235227
seen_timestamp: Duration,
236228
) -> Result<KzgVerifiedBlob<E>, KzgError> {
237-
validate_blob::<E>(kzg, blob.blob(), *blob.kzg_commitment(), *blob.kzg_proof())?;
229+
validate_blob::<E>(kzg, &blob.blob, blob.kzg_commitment, blob.kzg_proof)?;
238230
Ok(KzgVerifiedBlob {
239231
blob,
240232
seen_timestamp,
@@ -246,7 +238,7 @@ pub struct KzgVerifiedBlobList<E: EthSpec> {
246238
}
247239

248240
impl<E: EthSpec> KzgVerifiedBlobList<E> {
249-
pub fn new<I: IntoIterator<Item = Arc<BlobSidecar<E>>>>(
241+
pub fn new<I: IntoIterator<Item = Arc<BlobSidecarDeneb<E>>>>(
250242
blob_list: I,
251243
kzg: &Kzg,
252244
seen_timestamp: Duration,
@@ -292,10 +284,10 @@ pub fn verify_kzg_for_blob_list<'a, E: EthSpec, I>(
292284
kzg: &'a Kzg,
293285
) -> Result<(), KzgError>
294286
where
295-
I: Iterator<Item = &'a Arc<BlobSidecar<E>>>,
287+
I: Iterator<Item = &'a Arc<BlobSidecarDeneb<E>>>,
296288
{
297289
let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_iter
298-
.map(|blob| (blob.blob(), (*blob.kzg_commitment(), *blob.kzg_proof())))
290+
.map(|blob| (&blob.blob, (blob.kzg_commitment, blob.kzg_proof)))
299291
.unzip();
300292
validate_blobs::<E>(kzg, commitments.as_slice(), blobs, proofs.as_slice())
301293
}

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::fmt::{Debug, Formatter};
99
use std::sync::Arc;
1010
use types::data::BlobIdentifier;
1111
use types::{
12-
BeaconBlockRef, BeaconState, BlindedPayload, BlobSidecarList, Epoch, EthSpec, Hash256,
12+
BeaconBlockRef, BeaconState, BlindedPayload, BlobSidecarListDeneb, Epoch, EthSpec, Hash256,
1313
SignedBeaconBlock, SignedBeaconBlockHeader, Slot,
1414
};
1515

@@ -60,7 +60,7 @@ impl<E: EthSpec> RpcBlock<E> {
6060
}
6161
}
6262

63-
pub fn blobs(&self) -> Option<&BlobSidecarList<E>> {
63+
pub fn blobs(&self) -> Option<&BlobSidecarListDeneb<E>> {
6464
match &self.block {
6565
RpcBlockInner::Block(_) => None,
6666
RpcBlockInner::BlockAndBlobs(_, blobs) => Some(blobs),
@@ -87,7 +87,7 @@ enum RpcBlockInner<E: EthSpec> {
8787
Block(Arc<SignedBeaconBlock<E>>),
8888
/// This variant is used with parent lookups and by-range responses. It should have all blobs
8989
/// ordered, all block roots matching, and the correct number of blobs for this block.
90-
BlockAndBlobs(Arc<SignedBeaconBlock<E>>, BlobSidecarList<E>),
90+
BlockAndBlobs(Arc<SignedBeaconBlock<E>>, BlobSidecarListDeneb<E>),
9191
/// This variant is used with parent lookups and by-range responses. It should have all
9292
/// requested data columns, all block roots matching for this block.
9393
BlockAndCustodyColumns(Arc<SignedBeaconBlock<E>>, CustodyDataColumnList<E>),
@@ -115,7 +115,7 @@ impl<E: EthSpec> RpcBlock<E> {
115115
pub fn new(
116116
block_root: Option<Hash256>,
117117
block: Arc<SignedBeaconBlock<E>>,
118-
blobs: Option<BlobSidecarList<E>>,
118+
blobs: Option<BlobSidecarListDeneb<E>>,
119119
) -> Result<Self, AvailabilityCheckError> {
120120
let block_root = block_root.unwrap_or_else(|| get_block_root(&block));
121121
// Treat empty blob lists as if they are missing.
@@ -129,7 +129,7 @@ impl<E: EthSpec> RpcBlock<E> {
129129
return Err(AvailabilityCheckError::MissingBlobs);
130130
}
131131
for (blob, &block_commitment) in blobs.iter().zip(block_commitments.iter()) {
132-
let blob_commitment = *blob.kzg_commitment();
132+
let blob_commitment = blob.kzg_commitment;
133133
if blob_commitment != block_commitment {
134134
return Err(AvailabilityCheckError::KzgCommitmentMismatch {
135135
block_commitment,
@@ -177,7 +177,7 @@ impl<E: EthSpec> RpcBlock<E> {
177177
) -> (
178178
Hash256,
179179
Arc<SignedBeaconBlock<E>>,
180-
Option<BlobSidecarList<E>>,
180+
Option<BlobSidecarListDeneb<E>>,
181181
Option<CustodyDataColumnList<E>>,
182182
) {
183183
let block_root = self.block_root();

beacon_node/beacon_chain/src/builder.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ use rand::RngCore;
3535
use rayon::prelude::*;
3636
use slasher::Slasher;
3737
use slot_clock::{SlotClock, TestingSlotClock};
38+
use ssz_types::RuntimeVariableList;
3839
use state_processing::{AllCaches, per_slot_processing};
3940
use std::marker::PhantomData;
4041
use std::sync::Arc;
4142
use std::time::Duration;
4243
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
4344
use task_executor::{ShutdownReason, TaskExecutor};
4445
use tracing::{debug, error, info};
46+
use types::BlobSidecar;
4547
use types::data::CustodyIndex;
4648
use types::{
4749
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, ColumnIndex, DataColumnSidecarList,
@@ -595,6 +597,18 @@ where
595597
.put_data_columns(&weak_subj_block_root, data_columns)
596598
.map_err(|e| format!("Failed to store weak subjectivity data_column: {e:?}"))?;
597599
} else {
600+
let blobs = blobs
601+
.into_iter()
602+
.filter_map(|b| match b.as_ref() {
603+
BlobSidecar::Deneb(blob) => Some(Arc::new(blob.clone())),
604+
BlobSidecar::Gloas(_) => None,
605+
})
606+
.collect::<Vec<_>>();
607+
608+
let max_blobs = self.spec.max_blobs_per_block(weak_subj_block.epoch()) as usize;
609+
let blobs = RuntimeVariableList::new(blobs, max_blobs)
610+
.map_err(|e| format!("failed to store weak subjectivity blobs: {e:?}"))?;
611+
598612
store
599613
.put_blobs(&weak_subj_block_root, blobs)
600614
.map_err(|e| format!("Failed to store weak subjectivity blobs: {e:?}"))?;

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use std::sync::Arc;
1717
use std::time::Duration;
1818
use task_executor::TaskExecutor;
1919
use tracing::{debug, error, instrument};
20-
use types::data::{BlobIdentifier, BlobSidecar, FixedBlobSidecarList};
20+
use types::data::{BlobIdentifier, FixedBlobSidecarList};
2121
use types::{
22-
BlobSidecarList, BlockImportSource, ChainSpec, DataColumnSidecar, DataColumnSidecarList, Epoch,
23-
EthSpec, Hash256, SignedBeaconBlock, Slot,
22+
BlobSidecarDeneb, BlobSidecarListDeneb, BlockImportSource, ChainSpec, DataColumnSidecar,
23+
DataColumnSidecarList, Epoch, EthSpec, Hash256, SignedBeaconBlock, Slot,
2424
};
2525

2626
mod error;
@@ -195,7 +195,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
195195
pub fn get_blob(
196196
&self,
197197
blob_id: &BlobIdentifier,
198-
) -> Result<Option<Arc<BlobSidecar<T::EthSpec>>>, AvailabilityCheckError> {
198+
) -> Result<Option<Arc<BlobSidecarDeneb<T::EthSpec>>>, AvailabilityCheckError> {
199199
self.availability_cache.peek_blob(blob_id)
200200
}
201201

@@ -734,7 +734,7 @@ pub enum AvailableBlockData<E: EthSpec> {
734734
/// Block is pre-Deneb or has zero blobs
735735
NoData,
736736
/// Block is post-Deneb, pre-PeerDAS and has more than zero blobs
737-
Blobs(BlobSidecarList<E>),
737+
Blobs(BlobSidecarListDeneb<E>),
738738
/// Block is post-PeerDAS and has more than zero blobs
739739
DataColumns(DataColumnSidecarList<E>),
740740
}

0 commit comments

Comments
 (0)