Skip to content

Commit 3820519

Browse files
authored
Fix http api tests ci (#7943)
Co-Authored-By: Jimmy Chen <[email protected]> Co-Authored-By: Michael Sproul <[email protected]> Co-Authored-By: Michael Sproul <[email protected]> Co-Authored-By: hopinheimer <[email protected]>
1 parent 811eccd commit 3820519

File tree

15 files changed

+714
-342
lines changed

15 files changed

+714
-342
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ test-beacon-chain: $(patsubst %,test-beacon-chain-%,$(FORKS))
193193
test-beacon-chain-%:
194194
env FORK_NAME=$* cargo nextest run --release --features "fork_from_env,slasher/lmdb,$(TEST_FEATURES)" -p beacon_chain
195195

196-
# Run the tests in the `beacon_chain` crate for all known forks.
197-
test-http-api: $(patsubst %,test-beacon-chain-%,$(RECENT_FORKS))
196+
# Run the tests in the `http_api` crate for recent forks.
197+
test-http-api: $(patsubst %,test-http-api-%,$(RECENT_FORKS))
198198

199199
test-http-api-%:
200-
env FORK_NAME=$* cargo nextest run --release --features "fork_from_env,slasher/lmdb,$(TEST_FEATURES)" -p http_api
200+
env FORK_NAME=$* cargo nextest run --release --features "beacon_chain/fork_from_env" -p http_api
201201

202202

203203
# Run the tests in the `operation_pool` crate for all known forks.

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub enum GossipBlobError {
9696
/// ## Peer scoring
9797
///
9898
/// We cannot process the blob without validating its parent, the peer isn't necessarily faulty.
99-
BlobParentUnknown { parent_root: Hash256 },
99+
ParentUnknown { parent_root: Hash256 },
100100

101101
/// Invalid kzg commitment inclusion proof
102102
/// ## Peer scoring
@@ -474,7 +474,7 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
474474
// We have already verified that the blob is past finalization, so we can
475475
// just check fork choice for the block's parent.
476476
let Some(parent_block) = fork_choice.get_block(&block_parent_root) else {
477-
return Err(GossipBlobError::BlobParentUnknown {
477+
return Err(GossipBlobError::ParentUnknown {
478478
parent_root: block_parent_root,
479479
});
480480
};

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,10 @@ where
715715
pub fn set_mock_builder(
716716
&mut self,
717717
beacon_url: SensitiveUrl,
718-
) -> impl futures::Future<Output = ()> + 'static {
718+
strict_registrations: bool,
719+
apply_operations: bool,
720+
broadcast_to_bn: bool,
721+
) -> impl futures::Future<Output = ()> + use<E, Hot, Cold> {
719722
let mock_el = self
720723
.mock_execution_layer
721724
.as_ref()
@@ -727,6 +730,9 @@ where
727730
let (mock_builder, (addr, mock_builder_server)) = MockBuilder::new_for_testing(
728731
mock_el_url,
729732
beacon_url,
733+
strict_registrations,
734+
apply_operations,
735+
broadcast_to_bn,
730736
self.spec.clone(),
731737
self.runtime.task_executor.clone(),
732738
);
@@ -903,8 +909,65 @@ where
903909
state: BeaconState<E>,
904910
slot: Slot,
905911
) -> (SignedBlindedBeaconBlock<E>, BeaconState<E>) {
906-
let (unblinded, new_state) = self.make_block(state, slot).await;
907-
((*unblinded.0).clone().into(), new_state)
912+
self.make_blinded_block_with_modifier(state, slot, |_| {})
913+
.await
914+
}
915+
916+
pub async fn make_blinded_block_with_modifier(
917+
&self,
918+
mut state: BeaconState<E>,
919+
slot: Slot,
920+
block_modifier: impl FnOnce(&mut BlindedBeaconBlock<E>),
921+
) -> (SignedBlindedBeaconBlock<E>, BeaconState<E>) {
922+
assert_ne!(slot, 0, "can't produce a block at slot 0");
923+
assert!(slot >= state.slot());
924+
925+
complete_state_advance(&mut state, None, slot, &self.spec)
926+
.expect("should be able to advance state to slot");
927+
928+
state.build_caches(&self.spec).expect("should build caches");
929+
930+
let proposer_index = state.get_beacon_proposer_index(slot, &self.spec).unwrap();
931+
932+
// If we produce two blocks for the same slot, they hash up to the same value and
933+
// BeaconChain errors out with `DuplicateFullyImported`. Vary the graffiti so that we produce
934+
// different blocks each time.
935+
let graffiti = Graffiti::from(self.rng.lock().random::<[u8; 32]>());
936+
937+
let randao_reveal = self.sign_randao_reveal(&state, proposer_index, slot);
938+
939+
// Always use the builder, so that we produce a "real" blinded payload.
940+
let builder_boost_factor = Some(u64::MAX);
941+
942+
let BeaconBlockResponseWrapper::Blinded(block_response) = self
943+
.chain
944+
.produce_block_on_state(
945+
state,
946+
None,
947+
slot,
948+
randao_reveal,
949+
Some(graffiti),
950+
ProduceBlockVerification::VerifyRandao,
951+
builder_boost_factor,
952+
BlockProductionVersion::V3,
953+
)
954+
.await
955+
.unwrap()
956+
else {
957+
panic!("Should always be a blinded payload response");
958+
};
959+
960+
let mut block = block_response.block;
961+
block_modifier(&mut block);
962+
963+
let signed_block = block.sign(
964+
&self.validator_keypairs[proposer_index].sk,
965+
&block_response.state.fork(),
966+
block_response.state.genesis_validators_root(),
967+
&self.spec,
968+
);
969+
970+
(signed_block, block_response.state)
908971
}
909972

910973
/// Returns a newly created block, signed by the proposer for the given slot.

beacon_node/builder_client/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use eth2::types::{
88
use eth2::types::{FullPayloadContents, SignedBlindedBeaconBlock};
99
use eth2::{
1010
CONSENSUS_VERSION_HEADER, CONTENT_TYPE_HEADER, JSON_CONTENT_TYPE_HEADER,
11-
SSZ_CONTENT_TYPE_HEADER, StatusCode, ok_or_error,
11+
SSZ_CONTENT_TYPE_HEADER, StatusCode, ok_or_error, success_or_error,
1212
};
1313
use reqwest::header::{ACCEPT, HeaderMap, HeaderValue};
1414
use reqwest::{IntoUrl, Response};
@@ -249,7 +249,7 @@ impl BuilderHttpClient {
249249
.send()
250250
.await
251251
.map_err(Error::from)?;
252-
ok_or_error(response).await
252+
success_or_error(response).await
253253
}
254254

255255
async fn post_with_raw_response<T: Serialize, U: IntoUrl>(
@@ -270,7 +270,7 @@ impl BuilderHttpClient {
270270
.send()
271271
.await
272272
.map_err(Error::from)?;
273-
ok_or_error(response).await
273+
success_or_error(response).await
274274
}
275275

276276
/// `POST /eth/v1/builder/validators`

beacon_node/execution_layer/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,9 @@ impl<E: EthSpec> ExecutionLayer<E> {
20322032
relay_response_ms = duration.as_millis(),
20332033
?block_root,
20342034
"Successfully submitted blinded block to the builder"
2035-
)
2035+
);
2036+
2037+
Ok(())
20362038
}
20372039
Err(e) => {
20382040
metrics::inc_counter_vec(
@@ -2045,11 +2047,10 @@ impl<E: EthSpec> ExecutionLayer<E> {
20452047
relay_response_ms = duration.as_millis(),
20462048
?block_root,
20472049
"Failed to submit blinded block to the builder"
2048-
)
2050+
);
2051+
Err(e)
20492052
}
20502053
}
2051-
2052-
Ok(())
20532054
} else {
20542055
Err(Error::NoPayloadBuilder)
20552056
}

0 commit comments

Comments
 (0)