Skip to content

Commit 5d44eb0

Browse files
committed
Drop verify single RpcBlock fns
1 parent 6ab6eae commit 5d44eb0

File tree

8 files changed

+46
-164
lines changed

8 files changed

+46
-164
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: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -327,69 +327,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
327327
.remove_pending_components(block_root)
328328
}
329329

330-
/// Verifies kzg commitments for an RpcBlock, returns a `MaybeAvailableBlock` that may
331-
/// include the fully available block.
332-
///
333-
/// WARNING: This function assumes all required blobs are already present, it does NOT
334-
/// check if there are any missing blobs.
335-
pub fn verify_kzg_for_rpc_block(
336-
&self,
337-
block: RpcBlock<T::EthSpec>,
338-
) -> Result<MaybeAvailableBlock<T::EthSpec>, AvailabilityCheckError> {
339-
let (block_root, block, blobs, data_columns) = block.deconstruct();
340-
if self.blobs_required_for_block(&block) {
341-
return if let Some(blob_list) = blobs.as_ref() {
342-
verify_kzg_for_blob_list(blob_list.iter(), &self.kzg)
343-
.map_err(AvailabilityCheckError::InvalidBlobs)?;
344-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
345-
block_root,
346-
block,
347-
blobs,
348-
blobs_available_timestamp: None,
349-
data_columns: None,
350-
spec: self.spec.clone(),
351-
}))
352-
} else {
353-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
354-
};
355-
}
356-
if self.data_columns_required_for_block(&block) {
357-
return if let Some(data_column_list) = data_columns.as_ref() {
358-
verify_kzg_for_data_column_list_with_scoring(
359-
data_column_list
360-
.iter()
361-
.map(|custody_column| custody_column.as_data_column()),
362-
&self.kzg,
363-
)
364-
.map_err(AvailabilityCheckError::InvalidColumn)?;
365-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
366-
block_root,
367-
block,
368-
blobs: None,
369-
blobs_available_timestamp: None,
370-
data_columns: Some(
371-
data_column_list
372-
.into_iter()
373-
.map(|d| d.clone_arc())
374-
.collect(),
375-
),
376-
spec: self.spec.clone(),
377-
}))
378-
} else {
379-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
380-
};
381-
}
382-
383-
Ok(MaybeAvailableBlock::Available(AvailableBlock {
384-
block_root,
385-
block,
386-
blobs: None,
387-
blobs_available_timestamp: None,
388-
data_columns: None,
389-
spec: self.spec.clone(),
390-
}))
391-
}
392-
393330
/// Checks if a vector of blocks are available. Returns a vector of `MaybeAvailableBlock`
394331
/// This is more efficient than calling `verify_kzg_for_rpc_block` in a loop as it does
395332
/// all kzg verification at once
@@ -802,4 +739,23 @@ impl<E: EthSpec> MaybeAvailableBlock<E> {
802739
Self::AvailabilityPending { block, .. } => block.clone(),
803740
}
804741
}
742+
743+
pub fn from_block(
744+
block: Arc<SignedBeaconBlock<E>>,
745+
block_root: Hash256,
746+
spec: Arc<ChainSpec>,
747+
) -> Self {
748+
if block.num_expected_blobs() == 0 {
749+
MaybeAvailableBlock::Available(AvailableBlock {
750+
block_root,
751+
block,
752+
blobs: None,
753+
blobs_available_timestamp: None,
754+
data_columns: None,
755+
spec,
756+
})
757+
} else {
758+
MaybeAvailableBlock::AvailabilityPending { block_root, block }
759+
}
760+
}
805761
}

beacon_node/beacon_chain/src/test_utils.rs

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

23292312
pub async fn process_block_result(
@@ -2334,20 +2317,18 @@ where
23342317

23352318
let block_root = block.canonical_root();
23362319
let rpc_block = self.build_rpc_block_from_blobs(block_root, block, blob_items)?;
2337-
let block_hash: SignedBeaconBlockHash = self
2320+
match self
23382321
.chain
2339-
.process_block(
2340-
block_root,
2341-
rpc_block,
2342-
NotifyExecutionLayer::Yes,
2343-
BlockImportSource::RangeSync,
2344-
|| Ok(()),
2345-
)
2346-
.await?
2347-
.try_into()
2348-
.expect("block blobs are available");
2322+
.process_chain_segment(vec![rpc_block], NotifyExecutionLayer::Yes)
2323+
.await
2324+
{
2325+
crate::ChainSegmentResult::Successful { .. } => {}
2326+
crate::ChainSegmentResult::Failed { error, .. } => {
2327+
panic!("block import error {error:?}");
2328+
}
2329+
}
23492330
self.chain.recompute_head_at_current_slot().await;
2350-
Ok(block_hash)
2331+
Ok(block_root.into())
23512332
}
23522333

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

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

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
@@ -493,7 +493,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
493493
pub fn send_rpc_beacon_block(
494494
self: &Arc<Self>,
495495
block_root: Hash256,
496-
block: RpcBlock<T::EthSpec>,
496+
block: Arc<SignedBeaconBlock<T::EthSpec>>,
497497
seen_timestamp: Duration,
498498
process_type: BlockProcessType,
499499
) -> 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)