Skip to content

Commit d1273da

Browse files
committed
Drop verify single RpcBlock fns
1 parent f23f984 commit d1273da

File tree

8 files changed

+45
-161
lines changed

8 files changed

+45
-161
lines changed

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,15 +1254,8 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for Arc<SignedBeaconBlock
12541254
// Perform an early check to prevent wasting time on irrelevant blocks.
12551255
let block_root = check_block_relevancy(&self, block_root, chain)
12561256
.map_err(|e| BlockSlashInfo::SignatureNotChecked(self.signed_block_header(), e))?;
1257-
let maybe_available = chain
1258-
.data_availability_checker
1259-
.verify_kzg_for_rpc_block(RpcBlock::new_without_blobs(Some(block_root), self.clone()))
1260-
.map_err(|e| {
1261-
BlockSlashInfo::SignatureNotChecked(
1262-
self.signed_block_header(),
1263-
BlockError::AvailabilityCheck(e),
1264-
)
1265-
})?;
1257+
let maybe_available =
1258+
MaybeAvailableBlock::from_block(self.clone(), block_root, chain.spec.clone());
12661259
SignatureVerifiedBlock::check_slashable(maybe_available, block_root, chain)?
12671260
.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
12681261
}
@@ -1276,40 +1269,6 @@ impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for Arc<SignedBeaconBlock
12761269
}
12771270
}
12781271

1279-
impl<T: BeaconChainTypes> IntoExecutionPendingBlock<T> for RpcBlock<T::EthSpec> {
1280-
/// Verifies the `SignedBeaconBlock` by first transforming it into a `SignatureVerifiedBlock`
1281-
/// and then using that implementation of `IntoExecutionPendingBlock` to complete verification.
1282-
fn into_execution_pending_block_slashable(
1283-
self,
1284-
block_root: Hash256,
1285-
chain: &Arc<BeaconChain<T>>,
1286-
notify_execution_layer: NotifyExecutionLayer,
1287-
) -> Result<ExecutionPendingBlock<T>, BlockSlashInfo<BlockError>> {
1288-
// Perform an early check to prevent wasting time on irrelevant blocks.
1289-
let block_root = check_block_relevancy(self.as_block(), block_root, chain)
1290-
.map_err(|e| BlockSlashInfo::SignatureNotChecked(self.signed_block_header(), e))?;
1291-
let maybe_available = chain
1292-
.data_availability_checker
1293-
.verify_kzg_for_rpc_block(self.clone())
1294-
.map_err(|e| {
1295-
BlockSlashInfo::SignatureNotChecked(
1296-
self.signed_block_header(),
1297-
BlockError::AvailabilityCheck(e),
1298-
)
1299-
})?;
1300-
SignatureVerifiedBlock::check_slashable(maybe_available, block_root, chain)?
1301-
.into_execution_pending_block_slashable(block_root, chain, notify_execution_layer)
1302-
}
1303-
1304-
fn block(&self) -> &SignedBeaconBlock<T::EthSpec> {
1305-
self.as_block()
1306-
}
1307-
1308-
fn block_cloned(&self) -> Arc<SignedBeaconBlock<T::EthSpec>> {
1309-
self.block_cloned()
1310-
}
1311-
}
1312-
13131272
impl<T: BeaconChainTypes> ExecutionPendingBlock<T> {
13141273
/// Instantiates `Self`, a wrapper that indicates that the given `block` is fully valid. See
13151274
/// the struct-level documentation for more information.

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -331,66 +331,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
331331
.remove_pending_components(block_root)
332332
}
333333

334-
/// Verifies kzg commitments for an RpcBlock, returns a `MaybeAvailableBlock` that may
335-
/// include the fully available block.
336-
///
337-
/// WARNING: This function assumes all required blobs are already present, it does NOT
338-
/// check if there are any missing blobs.
339-
pub fn verify_kzg_for_rpc_block(
340-
&self,
341-
block: RpcBlock<T::EthSpec>,
342-
) -> Result<MaybeAvailableBlock<T::EthSpec>, AvailabilityCheckError> {
343-
let (block_root, block, blobs, data_columns) = block.deconstruct();
344-
if self.blobs_required_for_block(&block) {
345-
return if let Some(blob_list) = blobs {
346-
verify_kzg_for_blob_list(blob_list.iter(), &self.kzg)
347-
.map_err(AvailabilityCheckError::InvalidBlobs)?;
348-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
349-
block_root,
350-
block,
351-
blob_data: AvailableBlockData::Blobs(blob_list),
352-
blobs_available_timestamp: None,
353-
spec: self.spec.clone(),
354-
}))
355-
} else {
356-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
357-
};
358-
}
359-
if self.data_columns_required_for_block(&block) {
360-
return if let Some(data_column_list) = data_columns.as_ref() {
361-
verify_kzg_for_data_column_list_with_scoring(
362-
data_column_list
363-
.iter()
364-
.map(|custody_column| custody_column.as_data_column()),
365-
&self.kzg,
366-
)
367-
.map_err(AvailabilityCheckError::InvalidColumn)?;
368-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
369-
block_root,
370-
block,
371-
blob_data: AvailableBlockData::DataColumns(
372-
data_column_list
373-
.into_iter()
374-
.map(|d| d.clone_arc())
375-
.collect(),
376-
),
377-
blobs_available_timestamp: None,
378-
spec: self.spec.clone(),
379-
}))
380-
} else {
381-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
382-
};
383-
}
384-
385-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
386-
block_root,
387-
block,
388-
blob_data: AvailableBlockData::NoData,
389-
blobs_available_timestamp: None,
390-
spec: self.spec.clone(),
391-
}))
392-
}
393-
394334
/// Checks if a vector of blocks are available. Returns a vector of `MaybeAvailableBlock`
395335
/// This is more efficient than calling `verify_kzg_for_rpc_block` in a loop as it does
396336
/// all kzg verification at once
@@ -827,4 +767,22 @@ impl<E: EthSpec> MaybeAvailableBlock<E> {
827767
Self::AvailabilityPending { block, .. } => block.clone(),
828768
}
829769
}
770+
771+
pub fn from_block(
772+
block: Arc<SignedBeaconBlock<E>>,
773+
block_root: Hash256,
774+
spec: Arc<ChainSpec>,
775+
) -> Self {
776+
if block.num_expected_blobs() == 0 {
777+
MaybeAvailableBlock::Available(AvailableBlock {
778+
block_root,
779+
block,
780+
blob_data: AvailableBlockData::NoData,
781+
blobs_available_timestamp: None,
782+
spec,
783+
})
784+
} else {
785+
MaybeAvailableBlock::AvailabilityPending { block_root, block }
786+
}
787+
}
830788
}

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,27 +2304,10 @@ where
23042304
pub async fn process_block(
23052305
&self,
23062306
slot: Slot,
2307-
block_root: Hash256,
23082307
block_contents: SignedBlockContentsTuple<E>,
23092308
) -> Result<SignedBeaconBlockHash, BlockError> {
23102309
self.set_current_slot(slot);
2311-
let (block, blob_items) = block_contents;
2312-
2313-
let rpc_block = self.build_rpc_block_from_blobs(block_root, block, blob_items)?;
2314-
let block_hash: SignedBeaconBlockHash = self
2315-
.chain
2316-
.process_block(
2317-
block_root,
2318-
rpc_block,
2319-
NotifyExecutionLayer::Yes,
2320-
BlockImportSource::RangeSync,
2321-
|| Ok(()),
2322-
)
2323-
.await?
2324-
.try_into()
2325-
.expect("block blobs are available");
2326-
self.chain.recompute_head_at_current_slot().await;
2327-
Ok(block_hash)
2310+
self.process_block_result(block_contents).await
23282311
}
23292312

23302313
pub async fn process_block_result(
@@ -2335,20 +2318,18 @@ where
23352318

23362319
let block_root = block.canonical_root();
23372320
let rpc_block = self.build_rpc_block_from_blobs(block_root, block, blob_items)?;
2338-
let block_hash: SignedBeaconBlockHash = self
2321+
match self
23392322
.chain
2340-
.process_block(
2341-
block_root,
2342-
rpc_block,
2343-
NotifyExecutionLayer::Yes,
2344-
BlockImportSource::RangeSync,
2345-
|| Ok(()),
2346-
)
2347-
.await?
2348-
.try_into()
2349-
.expect("block blobs are available");
2323+
.process_chain_segment(vec![rpc_block], NotifyExecutionLayer::Yes)
2324+
.await
2325+
{
2326+
crate::ChainSegmentResult::Successful { .. } => {}
2327+
crate::ChainSegmentResult::Failed { error, .. } => {
2328+
panic!("block import error {error:?}");
2329+
}
2330+
}
23502331
self.chain.recompute_head_at_current_slot().await;
2351-
Ok(block_hash)
2332+
Ok(block_root.into())
23522333
}
23532334

23542335
/// Builds an `Rpc` block from a `SignedBeaconBlock` and blobs or data columns retrieved from
@@ -2486,13 +2467,7 @@ where
24862467
self.set_current_slot(slot);
24872468
let (block_contents, new_state) = self.make_block(state, slot).await;
24882469

2489-
let block_hash = self
2490-
.process_block(
2491-
slot,
2492-
block_contents.0.canonical_root(),
2493-
block_contents.clone(),
2494-
)
2495-
.await?;
2470+
let block_hash = self.process_block_result(block_contents.clone()).await?;
24962471
Ok((block_hash, block_contents, new_state))
24972472
}
24982473

beacon_node/beacon_chain/tests/rewards.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,15 @@ async fn test_rewards_base_multi_inclusion() {
310310
// funky hack: on first try, the state root will mismatch due to our modification
311311
// thankfully, the correct state root is reported back, so we just take that one :^)
312312
// there probably is a better way...
313-
let Err(BlockError::StateRootMismatch { local, .. }) = harness
314-
.process_block(slot, block.0.canonical_root(), block.clone())
315-
.await
313+
let Err(BlockError::StateRootMismatch { local, .. }) =
314+
harness.process_block(slot, block.clone()).await
316315
else {
317316
panic!("unexpected match of state root");
318317
};
319318
let mut new_block = block.0.message_base().unwrap().clone();
320319
new_block.state_root = local;
321320
block.0 = Arc::new(harness.sign_beacon_block(new_block.into(), &harness.get_current_state()));
322-
harness
323-
.process_block(slot, block.0.canonical_root(), block.clone())
324-
.await
325-
.unwrap();
321+
harness.process_block(slot, block.clone()).await.unwrap();
326322

327323
harness
328324
.extend_slots(E::slots_per_epoch() as usize * 2 - 4)

beacon_node/network/src/network_beacon_processor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
491491
pub fn send_rpc_beacon_block(
492492
self: &Arc<Self>,
493493
block_root: Hash256,
494-
block: RpcBlock<T::EthSpec>,
494+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
495495
seen_timestamp: Duration,
496496
process_type: BlockProcessType,
497497
) -> Result<(), Error<T::EthSpec>> {

beacon_node/network/src/network_beacon_processor/sync_methods.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ use store::KzgCommitment;
2525
use tokio::sync::mpsc;
2626
use types::beacon_block_body::format_kzg_commitments;
2727
use types::blob_sidecar::FixedBlobSidecarList;
28-
use types::{BlockImportSource, DataColumnSidecar, DataColumnSidecarList, Epoch, Hash256};
28+
use types::{
29+
BlockImportSource, DataColumnSidecar, DataColumnSidecarList, Epoch, Hash256, SignedBeaconBlock,
30+
};
2931

3032
/// Id associated to a batch processing request, either a sync batch or a parent lookup.
3133
#[derive(Clone, Debug, PartialEq)]
@@ -52,7 +54,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
5254
pub fn generate_rpc_beacon_block_process_fn(
5355
self: Arc<Self>,
5456
block_root: Hash256,
55-
block: RpcBlock<T::EthSpec>,
57+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
5658
seen_timestamp: Duration,
5759
process_type: BlockProcessType,
5860
) -> AsyncFn {
@@ -76,7 +78,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
7678
pub fn generate_rpc_beacon_block_fns(
7779
self: Arc<Self>,
7880
block_root: Hash256,
79-
block: RpcBlock<T::EthSpec>,
81+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
8082
seen_timestamp: Duration,
8183
process_type: BlockProcessType,
8284
) -> (AsyncFn, BlockingFn) {
@@ -103,7 +105,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
103105
pub async fn process_rpc_block(
104106
self: Arc<NetworkBeaconProcessor<T>>,
105107
block_root: Hash256,
106-
block: RpcBlock<T::EthSpec>,
108+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
107109
seen_timestamp: Duration,
108110
process_type: BlockProcessType,
109111
reprocess_tx: mpsc::Sender<ReprocessQueueMessage>,

beacon_node/network/src/sync/block_lookups/common.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::sync::block_lookups::{
66
};
77
use crate::sync::manager::BlockProcessType;
88
use crate::sync::network_context::{LookupRequestResult, SyncNetworkContext};
9-
use beacon_chain::block_verification_types::RpcBlock;
109
use beacon_chain::BeaconChainTypes;
1110
use lighthouse_network::service::api_types::Id;
1211
use parking_lot::RwLock;
@@ -97,13 +96,8 @@ impl<T: BeaconChainTypes> RequestState<T> for BlockRequestState<T::EthSpec> {
9796
seen_timestamp,
9897
..
9998
} = download_result;
100-
cx.send_block_for_processing(
101-
id,
102-
block_root,
103-
RpcBlock::new_without_blobs(Some(block_root), value),
104-
seen_timestamp,
105-
)
106-
.map_err(LookupRequestError::SendFailedProcessor)
99+
cx.send_block_for_processing(id, block_root, value, seen_timestamp)
100+
.map_err(LookupRequestError::SendFailedProcessor)
107101
}
108102

109103
fn response_type() -> ResponseType {

beacon_node/network/src/sync/network_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ impl<T: BeaconChainTypes> SyncNetworkContext<T> {
12091209
&self,
12101210
id: Id,
12111211
block_root: Hash256,
1212-
block: RpcBlock<T::EthSpec>,
1212+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
12131213
seen_timestamp: Duration,
12141214
) -> Result<(), SendErrorProcessor> {
12151215
let beacon_processor = self

0 commit comments

Comments
 (0)