Append client version info to graffiti (#7558)

* #7201


  


Co-Authored-By: Tan Chee Keong <tanck@sigmaprime.io>

Co-Authored-By: chonghe <44791194+chong-he@users.noreply.github.com>

Co-Authored-By: Jimmy Chen <jimmy@sigmaprime.io>

Co-Authored-By: Tan Chee Keong <tanck2005@gmail.com>
This commit is contained in:
chonghe
2025-12-16 11:19:28 +08:00
committed by GitHub
parent afa6457acf
commit 86c2b7cfbe
14 changed files with 392 additions and 47 deletions

View File

@@ -6,6 +6,7 @@ use crate::{
add_ssz_content_type_header, beacon_response, inconsistent_fork_rejection,
},
};
use beacon_chain::graffiti_calculator::GraffitiSettings;
use beacon_chain::{
BeaconBlockResponseWrapper, BeaconChain, BeaconChainTypes, ProduceBlockVerification,
};
@@ -68,11 +69,13 @@ pub async fn produce_block_v3<T: BeaconChainTypes>(
query.builder_boost_factor
};
let graffiti_settings = GraffitiSettings::new(query.graffiti, query.graffiti_policy);
let block_response_type = chain
.produce_block_with_verification(
randao_reveal,
slot,
query.graffiti,
graffiti_settings,
randao_verification,
builder_boost_factor,
BlockProductionVersion::V3,
@@ -148,11 +151,13 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
})?;
let randao_verification = get_randao_verification(&query, randao_reveal.is_infinity())?;
let graffiti_settings = GraffitiSettings::new(query.graffiti, query.graffiti_policy);
let block_response_type = chain
.produce_block_with_verification(
randao_reveal,
slot,
query.graffiti,
graffiti_settings,
randao_verification,
None,
BlockProductionVersion::BlindedV2,
@@ -182,12 +187,13 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
})?;
let randao_verification = get_randao_verification(&query, randao_reveal.is_infinity())?;
let graffiti_settings = GraffitiSettings::new(query.graffiti, query.graffiti_policy);
let block_response_type = chain
.produce_block_with_verification(
randao_reveal,
slot,
query.graffiti,
graffiti_settings,
randao_verification,
None,
BlockProductionVersion::FullV2,

View File

@@ -640,7 +640,7 @@ pub async fn proposer_boost_re_org_test(
.into();
let (unsigned_block_type, _) = tester
.client
.get_validator_blocks_v3::<E>(slot_c, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot_c, &randao_reveal, None, None, None)
.await
.unwrap();

View File

@@ -3681,7 +3681,7 @@ impl ApiTester {
let (response, metadata) = self
.client
.get_validator_blocks_v3_ssz::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3_ssz::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
@@ -4646,7 +4646,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -4673,7 +4673,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(0))
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(0), None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -4701,7 +4701,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(u64::MAX))
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, Some(u64::MAX), None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -4858,7 +4858,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -4939,7 +4939,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5034,7 +5034,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5125,7 +5125,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5216,7 +5216,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5305,7 +5305,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5366,7 +5366,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5437,7 +5437,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5552,7 +5552,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5573,7 +5573,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5708,7 +5708,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5739,7 +5739,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(next_slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5821,7 +5821,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5895,7 +5895,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -5964,7 +5964,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -6033,7 +6033,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -6100,7 +6100,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -6174,7 +6174,7 @@ impl ApiTester {
let (payload_type, metadata) = self
.client
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None)
.get_validator_blocks_v3::<E>(slot, &randao_reveal, None, None, None)
.await
.unwrap();
Self::check_block_v3_metadata(&metadata, &payload_type);
@@ -6864,6 +6864,82 @@ impl ApiTester {
}
self
}
async fn get_validator_blocks_v3_path_graffiti_policy(self) -> Self {
let slot = self.chain.slot().unwrap();
let epoch = self.chain.epoch().unwrap();
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;
let graffiti = Some(Graffiti::from([0; GRAFFITI_BYTES_LEN]));
let builder_boost_factor = None;
// Default case where GraffitiPolicy is None
let default_path = self
.client
.get_validator_blocks_v3_path(
slot,
&randao_reveal,
graffiti.as_ref(),
SkipRandaoVerification::Yes,
builder_boost_factor,
None,
)
.await
.unwrap();
let query_default_path = default_path.query().unwrap_or("");
// When GraffitiPolicy is None, the HTTP API query path should not contain "graffiti_policy"
assert!(
!query_default_path.contains("graffiti_policy"),
"URL should not contain graffiti_policy parameter (same as PreserveUserGraffiti). URL is: {}",
query_default_path
);
let preserve_path = self
.client
.get_validator_blocks_v3_path(
slot,
&randao_reveal,
graffiti.as_ref(),
SkipRandaoVerification::Yes,
builder_boost_factor,
Some(GraffitiPolicy::PreserveUserGraffiti),
)
.await
.unwrap();
let query_preserve_path = preserve_path.query().unwrap_or("");
// When GraffitiPolicy is set to PreserveUserGraffiti, the HTTP API query path should not contain "graffiti_policy"
assert!(
!query_preserve_path.contains("graffiti_policy"),
"URL should not contain graffiti_policy parameter when using PreserveUserGraffiti. URL is: {}",
query_preserve_path
);
// The HTTP API query path for PreserveUserGraffiti should be the same as the default
assert_eq!(query_default_path, query_preserve_path);
let append_path = self
.client
.get_validator_blocks_v3_path(
slot,
&randao_reveal,
graffiti.as_ref(),
SkipRandaoVerification::No,
builder_boost_factor,
Some(GraffitiPolicy::AppendClientVersions),
)
.await
.unwrap();
let query_append_path = append_path.query().unwrap_or("");
// When GraffitiPolicy is AppendClientVersions, the HTTP API query path should contain "graffiti_policy"
assert!(
query_append_path.contains("graffiti_policy"),
"URL should contain graffiti_policy=AppendClientVersions parameter. URL is: {}",
query_append_path
);
self
}
}
async fn poll_events<S: Stream<Item = Result<EventKind<E>, eth2::Error>> + Unpin, E: EthSpec>(
@@ -8054,3 +8130,11 @@ async fn get_beacon_rewards_blocks_electra() {
.test_beacon_block_rewards_electra()
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn get_validator_blocks_v3_http_api_path() {
ApiTester::new()
.await
.get_validator_blocks_v3_path_graffiti_policy()
.await;
}