Update engine_api to latest version (#4223)

* Update Engine API to Latest

* Get Mock EE Working

* Fix Mock EE

* Update Engine API Again

* Rip out get_blobs_bundle Stuff

* Fix Test Harness

* Fix Clippy Complaints

* Fix Beacon Chain Tests
This commit is contained in:
ethDreamer
2023-04-27 13:18:21 -05:00
committed by GitHub
parent aa34339298
commit c1d47da02d
24 changed files with 449 additions and 159 deletions

View File

@@ -4711,7 +4711,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
bls_to_execution_changes,
} = partial_beacon_block;
let (inner_block, blobs_opt) = match &state {
let (inner_block, blobs_opt, proofs_opt) = match &state {
BeaconState::Base(_) => (
BeaconBlock::Base(BeaconBlockBase {
slot,
@@ -4731,6 +4731,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
},
}),
None,
None,
),
BeaconState::Altair(_) => (
BeaconBlock::Altair(BeaconBlockAltair {
@@ -4753,9 +4754,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
},
}),
None,
None,
),
BeaconState::Merge(_) => {
let (payload, _, _) = block_contents
let (payload, _, _, _) = block_contents
.ok_or(BlockProductionError::MissingExecutionPayload)?
.deconstruct();
(
@@ -4781,10 +4783,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
},
}),
None,
None,
)
}
BeaconState::Capella(_) => {
let (payload, _, _) = block_contents
let (payload, _, _, _) = block_contents
.ok_or(BlockProductionError::MissingExecutionPayload)?
.deconstruct();
(
@@ -4811,10 +4814,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
},
}),
None,
None,
)
}
BeaconState::Deneb(_) => {
let (payload, kzg_commitments, blobs) = block_contents
let (payload, kzg_commitments, blobs, proofs) = block_contents
.ok_or(BlockProductionError::MissingExecutionPayload)?
.deconstruct();
(
@@ -4843,6 +4847,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
},
}),
blobs,
proofs,
)
}
};
@@ -4915,8 +4920,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
)));
}
let kzg_proofs =
Self::compute_blob_kzg_proofs(kzg, &blobs, expected_kzg_commitments, slot)?;
let kzg_proofs = if let Some(proofs) = proofs_opt {
Vec::from(proofs)
} else {
Self::compute_blob_kzg_proofs(kzg, &blobs, expected_kzg_commitments, slot)?
};
kzg_utils::validate_blobs::<T::EthSpec>(
kzg,

View File

@@ -12,13 +12,14 @@ use crate::data_availability_checker::{
};
use crate::kzg_utils::{validate_blob, validate_blobs};
use crate::BeaconChainError;
use eth2::types::BlockContentsTuple;
use kzg::Kzg;
use slog::{debug, warn};
use std::borrow::Cow;
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, BlobSidecar, BlobSidecarList, ChainSpec,
CloneConfig, Epoch, EthSpec, Hash256, KzgCommitment, RelativeEpoch, SignedBeaconBlock,
SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
CloneConfig, Epoch, EthSpec, FullPayload, Hash256, KzgCommitment, RelativeEpoch,
SignedBeaconBlock, SignedBeaconBlockHeader, SignedBlobSidecar, Slot,
};
#[derive(Debug)]
@@ -659,3 +660,18 @@ impl<E: EthSpec> From<SignedBeaconBlock<E>> for BlockWrapper<E> {
Self::Block(Arc::new(value))
}
}
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<_>>(),
),
None => Self::Block(Arc::new(value.0)),
}
}
}

View File

@@ -1,3 +1,4 @@
use crate::blob_verification::{AsBlock, BlockWrapper};
pub use crate::persisted_beacon_chain::PersistedBeaconChain;
pub use crate::{
beacon_chain::{BEACON_CHAIN_DB_KEY, ETH1_CACHE_DB_KEY, FORK_CHOICE_DB_KEY, OP_POOL_DB_KEY},
@@ -13,6 +14,7 @@ use crate::{
StateSkipConfig,
};
use bls::get_withdrawal_credentials;
use eth2::types::BlockContentsTuple;
use execution_layer::{
auth::JwtKey,
test_utils::{
@@ -25,7 +27,7 @@ use fork_choice::CountUnrealized;
use futures::channel::mpsc::Receiver;
pub use genesis::{interop_genesis_state_with_eth1, DEFAULT_ETH1_BLOCK_HASH};
use int_to_bytes::int_to_bytes32;
use kzg::TrustedSetup;
use kzg::{Kzg, TrustedSetup};
use merkle_proof::MerkleTree;
use parking_lot::Mutex;
use parking_lot::RwLockWriteGuard;
@@ -446,6 +448,13 @@ where
let deneb_time = spec.deneb_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
});
let trusted_setup: TrustedSetup =
serde_json::from_reader(eth2_network_config::TRUSTED_SETUP)
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
.expect("should have trusted setup");
let kzg = Kzg::new_from_trusted_setup(trusted_setup).expect("should create kzg");
let mock = MockExecutionLayer::new(
self.runtime.task_executor.clone(),
DEFAULT_TERMINAL_BLOCK,
@@ -455,6 +464,7 @@ where
Some(JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap()),
spec,
None,
Some(kzg),
);
self.execution_layer = Some(mock.el.clone());
self.mock_execution_layer = Some(mock);
@@ -477,6 +487,11 @@ where
let deneb_time = spec.deneb_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
});
let trusted_setup: TrustedSetup =
serde_json::from_reader(eth2_network_config::TRUSTED_SETUP)
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
.expect("should have trusted setup");
let kzg = Kzg::new_from_trusted_setup(trusted_setup).expect("should create kzg");
let mock_el = MockExecutionLayer::new(
self.runtime.task_executor.clone(),
DEFAULT_TERMINAL_BLOCK,
@@ -486,6 +501,7 @@ where
Some(JwtKey::from_slice(&DEFAULT_JWT_SECRET).unwrap()),
spec.clone(),
Some(builder_url.clone()),
Some(kzg),
)
.move_to_terminal_block();
@@ -755,7 +771,7 @@ where
&self,
mut state: BeaconState<E>,
slot: Slot,
) -> (SignedBeaconBlock<E>, BeaconState<E>) {
) -> (BlockContentsTuple<E, FullPayload<E>>, BeaconState<E>) {
assert_ne!(slot, 0, "can't produce a block at slot 0");
assert!(slot >= state.slot());
@@ -795,7 +811,37 @@ where
&self.spec,
);
(signed_block, state)
let block_contents: BlockContentsTuple<E, FullPayload<E>> = match &signed_block {
SignedBeaconBlock::Base(_)
| SignedBeaconBlock::Altair(_)
| SignedBeaconBlock::Merge(_)
| SignedBeaconBlock::Capella(_) => (signed_block, None),
SignedBeaconBlock::Deneb(_) => {
if let Some(blobs) = self
.chain
.proposal_blob_cache
.pop(&signed_block.canonical_root())
{
let signed_blobs = Vec::from(blobs)
.into_iter()
.map(|blob| {
blob.sign(
&self.validator_keypairs[proposer_index].sk,
&state.fork(),
state.genesis_validators_root(),
&self.spec,
)
})
.collect::<Vec<_>>()
.into();
(signed_block, Some(signed_blobs))
} else {
(signed_block, None)
}
}
};
(block_contents, state)
}
/// Useful for the `per_block_processing` tests. Creates a block, and returns the state after
@@ -1663,18 +1709,18 @@ where
(deposits, state)
}
pub async fn process_block(
pub async fn process_block<B: Into<BlockWrapper<E>>>(
&self,
slot: Slot,
block_root: Hash256,
block: SignedBeaconBlock<E>,
block: B,
) -> Result<SignedBeaconBlockHash, BlockError<E>> {
self.set_current_slot(slot);
let block_hash: SignedBeaconBlockHash = self
.chain
.process_block(
block_root,
Arc::new(block),
block.into(),
CountUnrealized::True,
NotifyExecutionLayer::Yes,
)
@@ -1685,15 +1731,16 @@ where
Ok(block_hash)
}
pub async fn process_block_result(
pub async fn process_block_result<B: Into<BlockWrapper<E>>>(
&self,
block: SignedBeaconBlock<E>,
block: B,
) -> Result<SignedBeaconBlockHash, BlockError<E>> {
let wrapped_block = block.into();
let block_hash: SignedBeaconBlockHash = self
.chain
.process_block(
block.canonical_root(),
Arc::new(block),
wrapped_block.canonical_root(),
wrapped_block,
CountUnrealized::True,
NotifyExecutionLayer::Yes,
)
@@ -1759,11 +1806,18 @@ where
&self,
slot: Slot,
state: BeaconState<E>,
) -> Result<(SignedBeaconBlockHash, SignedBeaconBlock<E>, BeaconState<E>), BlockError<E>> {
) -> Result<
(
SignedBeaconBlockHash,
BlockContentsTuple<E, FullPayload<E>>,
BeaconState<E>,
),
BlockError<E>,
> {
self.set_current_slot(slot);
let (block, new_state) = self.make_block(state, slot).await;
let block_hash = self
.process_block(slot, block.canonical_root(), block.clone())
.process_block(slot, block.0.canonical_root(), block.clone())
.await?;
Ok((block_hash, block, new_state))
}
@@ -1819,7 +1873,7 @@ where
sync_committee_strategy: SyncCommitteeStrategy,
) -> Result<(SignedBeaconBlockHash, BeaconState<E>), BlockError<E>> {
let (block_hash, block, state) = self.add_block_at_slot(slot, state).await?;
self.attest_block(&state, state_root, block_hash, &block, validators);
self.attest_block(&state, state_root, block_hash, &block.0, validators);
if sync_committee_strategy == SyncCommitteeStrategy::AllValidators
&& state.current_sync_committee().is_ok()
@@ -2047,7 +2101,7 @@ where
state: BeaconState<E>,
slot: Slot,
_block_strategy: BlockStrategy,
) -> (SignedBeaconBlock<E>, BeaconState<E>) {
) -> (BlockContentsTuple<E, FullPayload<E>>, BeaconState<E>) {
self.make_block(state, slot).await
}