Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix block v3 header decoding #5366

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 67 additions & 21 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2721,6 +2721,31 @@ impl ApiTester {
self
}

/// Check that the metadata from the headers & JSON response body are consistent, and that the
/// consensus block value is non-zero.
fn check_block_v3_metadata(
metadata: &ProduceBlockV3Metadata,
response: &JsonProduceBlockV3Response<E>,
) {
// Compare fork name to ForkVersionedResponse rather than metadata consensus_version, which
// is deserialized to a dummy value.
assert_eq!(Some(metadata.consensus_version), response.version);
assert_eq!(ForkName::Base, response.metadata.consensus_version);
assert_eq!(
metadata.execution_payload_blinded,
response.metadata.execution_payload_blinded
);
assert_eq!(
metadata.execution_payload_value,
response.metadata.execution_payload_value
);
assert_eq!(
metadata.consensus_block_value,
response.metadata.consensus_block_value
);
assert!(!metadata.consensus_block_value.is_zero());
}

pub async fn test_block_production_v3_ssz(self) -> Self {
let fork = self.chain.canonical_head.cached_head().head_fork();
let genesis_validators_root = self.chain.genesis_validators_root;
Expand Down Expand Up @@ -3582,11 +3607,12 @@ impl ApiTester {

let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: BlindedPayload<E> = match payload_type.data {
ProduceBlockV3Response::Blinded(payload) => {
Expand All @@ -3608,11 +3634,12 @@ impl ApiTester {

let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(0))
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand All @@ -3634,11 +3661,12 @@ impl ApiTester {

let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(u64::MAX))
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: BlindedPayload<E> = match payload_type.data {
ProduceBlockV3Response::Blinded(payload) => {
Expand Down Expand Up @@ -3738,11 +3766,12 @@ impl ApiTester {

let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: BlindedPayload<E> = match payload_type.data {
ProduceBlockV3Response::Blinded(payload) => {
Expand Down Expand Up @@ -3814,11 +3843,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: BlindedPayload<E> = match payload_type.data {
ProduceBlockV3Response::Blinded(payload) => {
Expand Down Expand Up @@ -3904,11 +3934,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand Down Expand Up @@ -3990,11 +4021,12 @@ impl ApiTester {
.unwrap();
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand Down Expand Up @@ -4076,11 +4108,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand Down Expand Up @@ -4160,11 +4193,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand Down Expand Up @@ -4216,11 +4250,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down Expand Up @@ -4282,11 +4317,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down Expand Up @@ -4390,11 +4426,12 @@ impl ApiTester {
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
.await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Blinded(_) => (),
Expand All @@ -4410,11 +4447,12 @@ impl ApiTester {
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
.await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down Expand Up @@ -4538,11 +4576,12 @@ impl ApiTester {
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
.await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand All @@ -4568,11 +4607,12 @@ impl ApiTester {
.get_test_randao(next_slot, next_slot.epoch(E::slots_per_epoch()))
.await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Blinded(_) => (),
Expand Down Expand Up @@ -4648,11 +4688,12 @@ impl ApiTester {

let (proposer_index, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let payload: FullPayload<E> = match payload_type.data {
ProduceBlockV3Response::Full(payload) => {
Expand Down Expand Up @@ -4717,11 +4758,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Blinded(_) => (),
Expand Down Expand Up @@ -4781,11 +4823,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down Expand Up @@ -4845,11 +4888,12 @@ impl ApiTester {

let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down Expand Up @@ -4907,11 +4951,12 @@ impl ApiTester {
let epoch = self.chain.epoch().unwrap();
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

let _block_contents = match payload_type.data {
ProduceBlockV3Response::Blinded(payload) => payload,
Expand Down Expand Up @@ -4979,11 +5024,12 @@ impl ApiTester {
let epoch = self.chain.epoch().unwrap();
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;

let (payload_type, _) = self
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);

match payload_type.data {
ProduceBlockV3Response::Full(_) => (),
Expand Down
4 changes: 2 additions & 2 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1710,12 +1710,12 @@ impl TryFrom<&HeaderMap> for ProduceBlockV3Metadata {
})?;
let execution_payload_value =
parse_required_header(headers, EXECUTION_PAYLOAD_VALUE_HEADER, |s| {
s.parse::<Uint256>()
Uint256::from_dec_str(s)
.map_err(|e| format!("invalid {EXECUTION_PAYLOAD_VALUE_HEADER}: {e:?}"))
})?;
let consensus_block_value =
parse_required_header(headers, CONSENSUS_BLOCK_VALUE_HEADER, |s| {
s.parse::<Uint256>()
Uint256::from_dec_str(s)
.map_err(|e| format!("invalid {CONSENSUS_BLOCK_VALUE_HEADER}: {e:?}"))
})?;

Expand Down
Loading