Refactor deneb block processing (#4511)

* Revert "fix merge"

This reverts commit 405e95b0ce.

* refactor deneb block processing

* cargo fmt

* fix ci
This commit is contained in:
realbigsean
2023-07-25 10:51:10 -04:00
committed by GitHub
parent 3735450749
commit 33dd13c798
33 changed files with 931 additions and 952 deletions

View File

@@ -1,4 +1,4 @@
use crate::blob_verification::{AsBlock, BlockWrapper};
use crate::block_verification_types::{AsBlock, RpcBlock};
use crate::observed_operations::ObservationOutcome;
pub use crate::persisted_beacon_chain::PersistedBeaconChain;
pub use crate::{
@@ -694,18 +694,18 @@ where
.execution_block_generator()
}
pub fn get_head_block(&self) -> BlockWrapper<E> {
pub fn get_head_block(&self) -> RpcBlock<E> {
let block = self.chain.head_beacon_block();
let block_root = block.canonical_root();
let blobs = self.chain.get_blobs(&block_root).unwrap();
BlockWrapper::new(block, blobs)
RpcBlock::new(block, blobs).unwrap()
}
pub fn get_full_block(&self, block_root: &Hash256) -> BlockWrapper<E> {
pub fn get_full_block(&self, block_root: &Hash256) -> RpcBlock<E> {
let block = self.chain.get_blinded_block(block_root).unwrap().unwrap();
let full_block = self.chain.store.make_full_block(block_root, block).unwrap();
let blobs = self.chain.get_blobs(block_root).unwrap();
BlockWrapper::new(Arc::new(full_block), blobs)
RpcBlock::new(Arc::new(full_block), blobs).unwrap()
}
pub fn get_all_validators(&self) -> Vec<usize> {
@@ -1873,18 +1873,31 @@ where
(deposits, state)
}
pub async fn process_block<B: Into<BlockWrapper<E>>>(
pub async fn process_block(
&self,
slot: Slot,
block_root: Hash256,
block: B,
block_contents: BlockContentsTuple<E, FullPayload<E>>,
) -> Result<SignedBeaconBlockHash, BlockError<E>> {
self.set_current_slot(slot);
let (block, blobs) = block_contents;
// Note: we are just dropping signatures here and skipping signature verification.
let blobs_without_signatures = blobs.as_ref().map(|blobs| {
VariableList::from(
blobs
.into_iter()
.map(|blob| blob.message.clone())
.collect::<Vec<_>>(),
)
});
let block_hash: SignedBeaconBlockHash = self
.chain
.process_block(block_root, block.into(), NotifyExecutionLayer::Yes, || {
Ok(())
})
.process_block(
block_root,
RpcBlock::new(Arc::new(block), blobs_without_signatures).unwrap(),
NotifyExecutionLayer::Yes,
|| Ok(()),
)
.await?
.try_into()
.unwrap();
@@ -1892,16 +1905,25 @@ where
Ok(block_hash)
}
pub async fn process_block_result<B: Into<BlockWrapper<E>>>(
pub async fn process_block_result(
&self,
block: B,
block_contents: BlockContentsTuple<E, FullPayload<E>>,
) -> Result<SignedBeaconBlockHash, BlockError<E>> {
let wrapped_block = block.into();
let (block, blobs) = block_contents;
// Note: we are just dropping signatures here and skipping signature verification.
let blobs_without_signatures = blobs.as_ref().map(|blobs| {
VariableList::from(
blobs
.into_iter()
.map(|blob| blob.message.clone())
.collect::<Vec<_>>(),
)
});
let block_hash: SignedBeaconBlockHash = self
.chain
.process_block(
wrapped_block.canonical_root(),
wrapped_block,
block.canonical_root(),
RpcBlock::new(Arc::new(block), blobs_without_signatures).unwrap(),
NotifyExecutionLayer::Yes,
|| Ok(()),
)
@@ -1976,11 +1998,16 @@ where
BlockError<E>,
> {
self.set_current_slot(slot);
let (block, new_state) = self.make_block(state, slot).await;
let (block_contents, new_state) = self.make_block(state, slot).await;
let block_hash = self
.process_block(slot, block.0.canonical_root(), block.clone())
.process_block(
slot,
block_contents.0.canonical_root(),
block_contents.clone(),
)
.await?;
Ok((block_hash, block, new_state))
Ok((block_hash, block_contents, new_state))
}
pub fn attest_block(