mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-29 20:27:14 +00:00
ContextDeserialize and Beacon API Improvements (#7372)
* #7286 * BeaconAPI is not returning a versioned response when it should for some V1 endpoints * these [strange functions with vX in the name that still accept `endpoint_version` arguments](https://github.com/sigp/lighthouse/blob/stable/beacon_node/http_api/src/produce_block.rs#L192) This refactor is a prerequisite to get the fulu EF tests running.
This commit is contained in:
@@ -682,7 +682,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata
|
||||
.metadata()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
@@ -719,7 +719,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata
|
||||
.metadata()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
@@ -757,7 +757,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.metadata
|
||||
.metadata()
|
||||
.finalized
|
||||
.unwrap();
|
||||
|
||||
@@ -1597,9 +1597,9 @@ impl ApiTester {
|
||||
let json_result = self.client.get_beacon_blocks(block_id.0).await.unwrap();
|
||||
|
||||
if let (Some(json), Some(expected)) = (&json_result, &expected) {
|
||||
assert_eq!(&json.data, expected.as_ref(), "{:?}", block_id);
|
||||
assert_eq!(json.data(), expected.as_ref(), "{:?}", block_id);
|
||||
assert_eq!(
|
||||
json.version,
|
||||
json.version(),
|
||||
Some(expected.fork_name(&self.chain.spec).unwrap())
|
||||
);
|
||||
} else {
|
||||
@@ -1623,8 +1623,8 @@ impl ApiTester {
|
||||
// Check that the legacy v1 API still works but doesn't return a version field.
|
||||
let v1_result = self.client.get_beacon_blocks_v1(block_id.0).await.unwrap();
|
||||
if let (Some(v1_result), Some(expected)) = (&v1_result, &expected) {
|
||||
assert_eq!(v1_result.version, None);
|
||||
assert_eq!(&v1_result.data, expected.as_ref());
|
||||
assert_eq!(v1_result.version(), None);
|
||||
assert_eq!(v1_result.data(), expected.as_ref());
|
||||
} else {
|
||||
assert_eq!(v1_result, None);
|
||||
assert_eq!(expected, None);
|
||||
@@ -1685,9 +1685,9 @@ impl ApiTester {
|
||||
.unwrap();
|
||||
|
||||
if let (Some(json), Some(expected)) = (&json_result, &expected) {
|
||||
assert_eq!(&json.data, expected, "{:?}", block_id);
|
||||
assert_eq!(json.data(), expected, "{:?}", block_id);
|
||||
assert_eq!(
|
||||
json.version,
|
||||
json.version(),
|
||||
Some(expected.fork_name(&self.chain.spec).unwrap())
|
||||
);
|
||||
} else {
|
||||
@@ -1750,10 +1750,14 @@ impl ApiTester {
|
||||
};
|
||||
let result = match self
|
||||
.client
|
||||
.get_blobs::<E>(CoreBlockId::Root(block_root), blob_indices.as_deref())
|
||||
.get_blobs::<E>(
|
||||
CoreBlockId::Root(block_root),
|
||||
blob_indices.as_deref(),
|
||||
&self.chain.spec,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => result.unwrap().data,
|
||||
Ok(result) => result.unwrap().into_data(),
|
||||
Err(e) => panic!("query failed incorrectly: {e:?}"),
|
||||
};
|
||||
|
||||
@@ -1806,13 +1810,13 @@ impl ApiTester {
|
||||
|
||||
match self
|
||||
.client
|
||||
.get_blobs::<E>(CoreBlockId::Slot(test_slot), None)
|
||||
.get_blobs::<E>(CoreBlockId::Slot(test_slot), None, &self.chain.spec)
|
||||
.await
|
||||
{
|
||||
Ok(result) => {
|
||||
if zero_blobs {
|
||||
assert_eq!(
|
||||
&result.unwrap().data[..],
|
||||
&result.unwrap().into_data()[..],
|
||||
&[],
|
||||
"empty blobs are always available"
|
||||
);
|
||||
@@ -1844,7 +1848,7 @@ impl ApiTester {
|
||||
|
||||
match self
|
||||
.client
|
||||
.get_blobs::<E>(CoreBlockId::Slot(test_slot), None)
|
||||
.get_blobs::<E>(CoreBlockId::Slot(test_slot), None, &self.chain.spec)
|
||||
.await
|
||||
{
|
||||
Ok(result) => panic!("queries for pre-Deneb slots should fail. got: {result:?}"),
|
||||
@@ -1861,7 +1865,7 @@ impl ApiTester {
|
||||
.get_beacon_blocks_attestations_v2(block_id.0)
|
||||
.await
|
||||
.unwrap()
|
||||
.map(|res| res.data);
|
||||
.map(|res| res.into_data());
|
||||
|
||||
let expected = block_id.full_block(&self.chain).await.ok().map(
|
||||
|(block, _execution_optimistic, _finalized)| {
|
||||
@@ -2071,7 +2075,7 @@ impl ApiTester {
|
||||
.get_light_client_bootstrap(&self.chain.store, &block_root, 1u64, &self.chain.spec);
|
||||
|
||||
assert!(expected.is_ok());
|
||||
assert_eq!(result.unwrap().data, expected.unwrap().unwrap().0);
|
||||
assert_eq!(result.unwrap().data(), &expected.unwrap().unwrap().0);
|
||||
|
||||
self
|
||||
}
|
||||
@@ -2083,7 +2087,7 @@ impl ApiTester {
|
||||
.get_beacon_light_client_optimistic_update::<E>()
|
||||
.await
|
||||
{
|
||||
Ok(result) => result.map(|res| res.data),
|
||||
Ok(result) => result.map(|res| res.into_data()),
|
||||
Err(e) => panic!("query failed incorrectly: {e:?}"),
|
||||
};
|
||||
|
||||
@@ -2102,7 +2106,7 @@ impl ApiTester {
|
||||
.get_beacon_light_client_finality_update::<E>()
|
||||
.await
|
||||
{
|
||||
Ok(result) => result.map(|res| res.data),
|
||||
Ok(result) => result.map(|res| res.into_data()),
|
||||
Err(e) => panic!("query failed incorrectly: {e:?}"),
|
||||
};
|
||||
|
||||
@@ -2133,7 +2137,7 @@ impl ApiTester {
|
||||
.get_beacon_pool_attestations_v2(None, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
assert_eq!(result, expected);
|
||||
|
||||
@@ -2195,7 +2199,7 @@ impl ApiTester {
|
||||
.get_beacon_pool_attestations_v2(None, Some(0))
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
let mut expected = self.chain.op_pool.get_all_attestations();
|
||||
expected.extend(self.chain.naive_aggregation_pool.read().iter().cloned());
|
||||
let expected_committee_index_filtered = expected
|
||||
@@ -2311,7 +2315,7 @@ impl ApiTester {
|
||||
.get_beacon_pool_attester_slashings_v2()
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
assert_eq!(result, expected);
|
||||
|
||||
self
|
||||
@@ -2649,9 +2653,9 @@ impl ApiTester {
|
||||
expected.as_mut().map(|state| state.drop_all_caches());
|
||||
|
||||
if let (Some(json), Some(expected)) = (&result_json, &expected) {
|
||||
assert_eq!(json.data, *expected, "{:?}", state_id);
|
||||
assert_eq!(json.data(), expected, "{:?}", state_id);
|
||||
assert_eq!(
|
||||
json.version,
|
||||
json.version(),
|
||||
Some(expected.fork_name(&self.chain.spec).unwrap())
|
||||
);
|
||||
} else {
|
||||
@@ -3157,7 +3161,7 @@ impl ApiTester {
|
||||
.get_validator_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.deconstruct()
|
||||
.0;
|
||||
|
||||
@@ -3254,7 +3258,7 @@ impl ApiTester {
|
||||
) {
|
||||
// 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!(metadata.consensus_version, response.version);
|
||||
assert_eq!(ForkName::Base, response.metadata.consensus_version);
|
||||
assert_eq!(
|
||||
metadata.execution_payload_blinded,
|
||||
@@ -3380,7 +3384,7 @@ impl ApiTester {
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.deconstruct()
|
||||
.0;
|
||||
assert_eq!(block.slot(), slot);
|
||||
@@ -3494,7 +3498,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
let signed_block = block.sign(&sk, &fork, genesis_validators_root, &self.chain.spec);
|
||||
|
||||
@@ -3509,7 +3513,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
assert_eq!(head_block.clone_as_blinded(), signed_block);
|
||||
|
||||
@@ -3582,7 +3586,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
|
||||
let signed_block = signed_block_contents.signed_block();
|
||||
assert_eq!(head_block, **signed_block);
|
||||
@@ -3605,7 +3609,7 @@ impl ApiTester {
|
||||
)
|
||||
.await
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
assert_eq!(blinded_block.slot(), slot);
|
||||
self.chain.slot_clock.set_slot(slot.as_u64() + 1);
|
||||
}
|
||||
@@ -3749,7 +3753,7 @@ impl ApiTester {
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.data;
|
||||
.into_data();
|
||||
let expected = attestation;
|
||||
|
||||
assert_eq!(result, expected);
|
||||
@@ -4323,7 +4327,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4369,7 +4373,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4413,7 +4417,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4487,7 +4491,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4573,7 +4577,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4665,7 +4669,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4755,7 +4759,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4844,7 +4848,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4919,7 +4923,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -4982,7 +4986,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5058,7 +5062,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5089,7 +5093,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5197,7 +5201,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5238,7 +5242,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(next_slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5354,7 +5358,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5435,7 +5439,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5503,7 +5507,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5571,7 +5575,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5638,7 +5642,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
@@ -5709,7 +5713,7 @@ impl ApiTester {
|
||||
.get_validator_blinded_blocks::<E>(slot, &randao_reveal, None)
|
||||
.await
|
||||
.unwrap()
|
||||
.data
|
||||
.into_data()
|
||||
.body()
|
||||
.execution_payload()
|
||||
.unwrap()
|
||||
|
||||
Reference in New Issue
Block a user