Add Deneb builder test & update mock builder (#4607)

* Update mock builder, mev-rs dependencies, eth2 lib to support deneb builder flow

* Replace `sharingForkTime` with `cancunTime`

* Patch `ethereum-consensus` to include some deneb-devnet-8 changes

* Add deneb builder test and fix block contents deserialization

* Fix builder bid encoding issue and passing deneb builder test \o/

* Fix test compilation

* Revert `cancunTime` change in genesis to pass doppelganger tests
This commit is contained in:
Jimmy Chen
2023-08-19 10:12:09 +10:00
committed by GitHub
parent f031a570ce
commit 4898430330
18 changed files with 440 additions and 130 deletions

View File

@@ -4,12 +4,16 @@ use beacon_chain::{
};
use eth2::types::{
BroadcastValidation, SignedBeaconBlock, SignedBlindedBeaconBlock, SignedBlockContents,
SignedBlockContentsTuple,
};
use http_api::test_utils::InteractiveTester;
use http_api::{publish_blinded_block, publish_block, reconstruct_block, ProvenancedBlock};
use std::sync::Arc;
use tree_hash::TreeHash;
use types::{Hash256, MainnetEthSpec, Slot};
use types::{
BlindedBlobSidecar, BlindedPayload, BlobSidecar, FullPayload, Hash256, MainnetEthSpec,
SignedSidecarList, Slot,
};
use warp::Rejection;
use warp_utils::reject::CustomBadRequest;
@@ -762,7 +766,7 @@ pub async fn blinded_gossip_invalid() {
tester.harness.advance_slot();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(chain_state_before, slot, |b| {
*b.state_root_mut() = Hash256::zero();
@@ -770,11 +774,11 @@ pub async fn blinded_gossip_invalid() {
})
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -816,18 +820,18 @@ pub async fn blinded_gossip_partial_pass() {
tester.harness.advance_slot();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(chain_state_before, slot, |b| {
*b.state_root_mut() = Hash256::zero()
})
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -864,19 +868,18 @@ pub async fn blinded_gossip_full_pass() {
let slot_b = slot_a + 1;
let state_a = tester.harness.get_current_state();
let ((block, _), _): ((SignedBlindedBeaconBlock<E>, _), _) =
tester.harness.make_blinded_block(state_a, slot_b).await;
let (block_contents_tuple, _) = tester.harness.make_blinded_block(state_a, slot_b).await;
let block_contents = block_contents_tuple.into();
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&block, validation_level)
.post_beacon_blinded_blocks_v2(&block_contents, validation_level)
.await;
assert!(response.is_ok());
assert!(tester
.harness
.chain
.block_is_known_to_fork_choice(&block.canonical_root()));
.block_is_known_to_fork_choice(&block_contents.signed_block().canonical_root()));
}
// This test checks that a block that is valid from both a gossip and consensus perspective is accepted when using `broadcast_validation=gossip`.
@@ -950,7 +953,7 @@ pub async fn blinded_consensus_invalid() {
tester.harness.advance_slot();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(chain_state_before, slot, |b| {
*b.state_root_mut() = Hash256::zero();
@@ -958,11 +961,11 @@ pub async fn blinded_consensus_invalid() {
})
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -1004,16 +1007,16 @@ pub async fn blinded_consensus_gossip() {
let slot_b = slot_a + 1;
let state_a = tester.harness.get_current_state();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero())
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -1055,19 +1058,19 @@ pub async fn blinded_consensus_full_pass() {
let slot_b = slot_a + 1;
let state_a = tester.harness.get_current_state();
let ((block, _), _): ((SignedBlindedBeaconBlock<E>, _), _) =
tester.harness.make_blinded_block(state_a, slot_b).await;
let (block_contents_tuple, _) = tester.harness.make_blinded_block(state_a, slot_b).await;
let block_contents = block_contents_tuple.into();
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&block, validation_level)
.post_beacon_blinded_blocks_v2(&block_contents, validation_level)
.await;
assert!(response.is_ok());
assert!(tester
.harness
.chain
.block_is_known_to_fork_choice(&block.canonical_root()));
.block_is_known_to_fork_choice(&block_contents.signed_block().canonical_root()));
}
/// This test checks that a block that is **invalid** from a gossip perspective gets rejected when using `broadcast_validation=consensus_and_equivocation`.
@@ -1099,7 +1102,7 @@ pub async fn blinded_equivocation_invalid() {
tester.harness.advance_slot();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(chain_state_before, slot, |b| {
*b.state_root_mut() = Hash256::zero();
@@ -1107,11 +1110,11 @@ pub async fn blinded_equivocation_invalid() {
})
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -1154,14 +1157,18 @@ pub async fn blinded_equivocation_consensus_early_equivocation() {
let slot_b = slot_a + 1;
let state_a = tester.harness.get_current_state();
let ((block_a, _), state_after_a): ((SignedBlindedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple_a, state_after_a) = tester
.harness
.make_blinded_block(state_a.clone(), slot_b)
.await;
let ((block_b, _), state_after_b): ((SignedBlindedBeaconBlock<E>, _), _) =
let (block_contents_tuple_b, state_after_b) =
tester.harness.make_blinded_block(state_a, slot_b).await;
/* check for `make_blinded_block` curios */
let block_contents_a: SignedBlockContents<E, BlindedPayload<E>> = block_contents_tuple_a.into();
let block_contents_b: SignedBlockContents<E, BlindedPayload<E>> = block_contents_tuple_b.into();
let block_a = block_contents_a.signed_block();
let block_b = block_contents_b.signed_block();
assert_eq!(block_a.state_root(), state_after_a.tree_hash_root());
assert_eq!(block_b.state_root(), state_after_b.tree_hash_root());
assert_ne!(block_a.state_root(), block_b.state_root());
@@ -1169,7 +1176,7 @@ pub async fn blinded_equivocation_consensus_early_equivocation() {
/* submit `block_a` as valid */
assert!(tester
.client
.post_beacon_blinded_blocks_v2(&block_a, validation_level)
.post_beacon_blinded_blocks_v2(&block_contents_a, validation_level)
.await
.is_ok());
assert!(tester
@@ -1180,7 +1187,7 @@ pub async fn blinded_equivocation_consensus_early_equivocation() {
/* submit `block_b` which should induce equivocation */
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&block_b, validation_level)
.post_beacon_blinded_blocks_v2(&block_contents_b, validation_level)
.await;
assert!(response.is_err());
@@ -1222,16 +1229,16 @@ pub async fn blinded_equivocation_gossip() {
let slot_b = slot_a + 1;
let state_a = tester.harness.get_current_state();
let ((block, _), _): ((SignedBeaconBlock<E>, _), _) = tester
let (block_contents_tuple, _) = tester
.harness
.make_block_with_modifier(state_a, slot_b, |b| *b.state_root_mut() = Hash256::zero())
.await;
let blinded_block: SignedBlindedBeaconBlock<E> = block.into();
let blinded_block_contents = into_signed_blinded_block_contents(block_contents_tuple);
let response: Result<(), eth2::Error> = tester
.client
.post_beacon_blinded_blocks_v2(&blinded_block, validation_level)
.post_beacon_blinded_blocks_v2(&blinded_block_contents, validation_level)
.await;
assert!(response.is_err());
@@ -1390,3 +1397,20 @@ pub async fn blinded_equivocation_full_pass() {
.chain
.block_is_known_to_fork_choice(&block.canonical_root()));
}
fn into_signed_blinded_block_contents(
block_contents_tuple: SignedBlockContentsTuple<E, FullPayload<E>>,
) -> SignedBlockContents<E, BlindedPayload<E>> {
let (block, maybe_blobs) = block_contents_tuple;
SignedBlockContents::new(block.into(), maybe_blobs.map(into_blinded_blob_sidecars))
}
fn into_blinded_blob_sidecars(
blobs: SignedSidecarList<E, BlobSidecar<E>>,
) -> SignedSidecarList<E, BlindedBlobSidecar> {
blobs
.into_iter()
.map(|blob| blob.into())
.collect::<Vec<_>>()
.into()
}