From 689cdaef61e417a83c648f9dc3e13358c19c7322 Mon Sep 17 00:00:00 2001 From: Mac L Date: Thu, 2 May 2024 11:05:03 +1000 Subject: [PATCH] Rename to has_feature --- beacon_node/beacon_chain/src/beacon_chain.rs | 19 +++++++++---------- beacon_node/execution_layer/src/engine_api.rs | 4 ++-- .../execution_layer/src/engine_api/http.rs | 4 ++-- .../src/engine_api/new_payload_request.rs | 2 +- .../src/test_utils/mock_builder.rs | 2 +- beacon_node/http_api/src/lib.rs | 2 +- beacon_node/store/src/partial_beacon_state.rs | 2 +- consensus/types/src/beacon_block.rs | 2 +- consensus/types/src/beacon_block_body.rs | 2 +- consensus/types/src/beacon_state.rs | 2 +- consensus/types/src/builder_bid.rs | 2 +- consensus/types/src/chain_spec.rs | 18 +++++++++--------- consensus/types/src/config_and_preset.rs | 2 +- consensus/types/src/execution_payload.rs | 2 +- .../types/src/execution_payload_header.rs | 2 +- consensus/types/src/fork_name.rs | 2 +- consensus/types/src/light_client_header.rs | 2 +- consensus/types/src/payload.rs | 4 ++-- consensus/types/src/voluntary_exit.rs | 2 +- validator_client/src/validator_store.rs | 2 +- 20 files changed, 39 insertions(+), 40 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 7e73d9150b..bbbae1365a 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -739,9 +739,9 @@ impl BeaconChain { } /// Checks if a feature is enabled on the current fork. - pub fn is_feature_enabled(&self, feature: FeatureName) -> bool { + pub fn has_feature(&self, feature: FeatureName) -> bool { if let Ok(current_fork) = self.current_fork() { - current_fork.is_feature_enabled(feature) + current_fork.has_feature(feature) } else { false } @@ -2537,7 +2537,7 @@ impl BeaconChain { bls_to_execution_change: SignedBlsToExecutionChange, ) -> Result, Error> { // Ignore BLS to execution changes on gossip prior to Capella. - if !self.is_feature_enabled(FeatureName::Capella) { + if !self.has_feature(FeatureName::Capella) { return Err(Error::BlsToExecutionPriorToCapella); } self.verify_bls_to_execution_change_for_http_api(bls_to_execution_change) @@ -5556,7 +5556,7 @@ impl BeaconChain { payload_attributes } else { let prepare_slot_fork = self.spec.fork_name_at_slot::(prepare_slot); - let withdrawals = if prepare_slot_fork.is_feature_enabled(FeatureName::Capella) { + let withdrawals = if prepare_slot_fork.has_feature(FeatureName::Capella) { let chain = self.clone(); self.spawn_blocking_handle( move || chain.get_expected_withdrawals(&forkchoice_update_params, prepare_slot), @@ -5568,12 +5568,11 @@ impl BeaconChain { None }; - let parent_beacon_block_root = - if prepare_slot_fork.is_feature_enabled(FeatureName::Deneb) { - Some(pre_payload_attributes.parent_beacon_block_root) - } else { - None - }; + let parent_beacon_block_root = if prepare_slot_fork.has_feature(FeatureName::Deneb) { + Some(pre_payload_attributes.parent_beacon_block_root) + } else { + None + }; //let parent_beacon_block_root = match prepare_slot_fork { // ForkName::Base | ForkName::Altair | ForkName::Bellatrix | ForkName::Capella => None, diff --git a/beacon_node/execution_layer/src/engine_api.rs b/beacon_node/execution_layer/src/engine_api.rs index 6391dea23b..60fc73b66a 100644 --- a/beacon_node/execution_layer/src/engine_api.rs +++ b/beacon_node/execution_layer/src/engine_api.rs @@ -162,7 +162,7 @@ pub struct ExecutionBlock { feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive(Clone, Debug, PartialEq, Serialize, Deserialize,), @@ -440,7 +440,7 @@ pub struct ProposeBlindedBlockResponse { feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes(derive(Clone, Debug, PartialEq),), map_into(ExecutionPayload), diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index 76d98b2d63..85ef3a0d92 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -1217,13 +1217,13 @@ impl HttpJsonRpc { payload_id: PayloadId, ) -> Result, Error> { let engine_capabilities = self.get_engine_capabilities(None).await?; - if fork_name.is_feature_enabled(FeatureName::Deneb) { + if fork_name.has_feature(FeatureName::Deneb) { if engine_capabilities.get_payload_v3 { self.get_payload_v3(fork_name, payload_id).await } else { Err(Error::RequiredMethodUnsupported("engine_getPayloadV3")) } - } else if fork_name.is_feature_enabled(FeatureName::Bellatrix) { + } else if fork_name.has_feature(FeatureName::Bellatrix) { if engine_capabilities.get_payload_v2 { self.get_payload_v2(fork_name, payload_id).await } else if engine_capabilities.new_payload_v1 { diff --git a/beacon_node/execution_layer/src/engine_api/new_payload_request.rs b/beacon_node/execution_layer/src/engine_api/new_payload_request.rs index aaa87c5476..552bb659dc 100644 --- a/beacon_node/execution_layer/src/engine_api/new_payload_request.rs +++ b/beacon_node/execution_layer/src/engine_api/new_payload_request.rs @@ -20,7 +20,7 @@ use types::{ feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes(derive(Clone, Debug, PartialEq),), map_into(ExecutionPayload), diff --git a/beacon_node/execution_layer/src/test_utils/mock_builder.rs b/beacon_node/execution_layer/src/test_utils/mock_builder.rs index a57563e24f..d385769cfb 100644 --- a/beacon_node/execution_layer/src/test_utils/mock_builder.rs +++ b/beacon_node/execution_layer/src/test_utils/mock_builder.rs @@ -479,7 +479,7 @@ pub fn serve( let prev_randao = head_state .get_randao_mix(head_state.current_epoch()) .map_err(|_| reject("couldn't get prev randao"))?; - let expected_withdrawals = if fork.is_feature_enabled(FeatureName::Capella) { + let expected_withdrawals = if fork.has_feature(FeatureName::Capella) { Some( builder .beacon_client diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 9bf4cf3c0a..f7957fd6ad 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -2046,7 +2046,7 @@ pub fn serve( .to_execution_address; // New to P2P *and* op pool, gossip immediately if post-Capella. - let received_pre_capella = if chain.is_feature_enabled(FeatureName::Capella) { + let received_pre_capella = if chain.has_feature(FeatureName::Capella) { ReceivedPreCapella::No } else { ReceivedPreCapella::Yes diff --git a/beacon_node/store/src/partial_beacon_state.rs b/beacon_node/store/src/partial_beacon_state.rs index c43ac3553a..b3059b5beb 100644 --- a/beacon_node/store/src/partial_beacon_state.rs +++ b/beacon_node/store/src/partial_beacon_state.rs @@ -20,7 +20,7 @@ use types::*; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes(derive(Debug, PartialEq, Clone, Encode, Decode)) )] diff --git a/consensus/types/src/beacon_block.rs b/consensus/types/src/beacon_block.rs index e548ac4040..b37fa342a2 100644 --- a/consensus/types/src/beacon_block.rs +++ b/consensus/types/src/beacon_block.rs @@ -18,7 +18,7 @@ use tree_hash_derive::TreeHash; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/beacon_block_body.rs b/consensus/types/src/beacon_block_body.rs index 381a13941f..55cc490db6 100644 --- a/consensus/types/src/beacon_block_body.rs +++ b/consensus/types/src/beacon_block_body.rs @@ -35,7 +35,7 @@ pub const BLOB_KZG_COMMITMENTS_INDEX: usize = 11; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 03a4fdc0f2..abf91f5483 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -212,7 +212,7 @@ impl From for Hash256 { feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/builder_bid.rs b/consensus/types/src/builder_bid.rs index bd65fb76cc..3ea5e3273f 100644 --- a/consensus/types/src/builder_bid.rs +++ b/consensus/types/src/builder_bid.rs @@ -19,7 +19,7 @@ use tree_hash_derive::TreeHash; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive(PartialEq, Debug, Serialize, Deserialize, TreeHash, Clone), diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 4bc7f2d8d6..23e25ba2fb 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -338,9 +338,9 @@ impl ChainSpec { pub fn inactivity_penalty_quotient_for_fork(&self, fork_name: ForkName) -> u64 { // TODO(superstruct_features) Is this a better pattern? - if fork_name.is_feature_enabled(FeatureName::Bellatrix) { + if fork_name.has_feature(FeatureName::Bellatrix) { self.inactivity_penalty_quotient_bellatrix - } else if fork_name.is_feature_enabled(FeatureName::Altair) { + } else if fork_name.has_feature(FeatureName::Altair) { self.inactivity_penalty_quotient_altair } else { self.inactivity_penalty_quotient @@ -353,9 +353,9 @@ impl ChainSpec { state: &BeaconState, ) -> u64 { let fork_name = state.fork_name_unchecked(); - if fork_name >= ForkName::Bellatrix { + if fork_name.has_feature(FeatureName::Bellatrix) { self.proportional_slashing_multiplier_bellatrix - } else if fork_name >= ForkName::Altair { + } else if fork_name.has_feature(FeatureName::Altair) { self.proportional_slashing_multiplier_altair } else { self.proportional_slashing_multiplier @@ -368,11 +368,11 @@ impl ChainSpec { state: &BeaconState, ) -> u64 { let fork_name = state.fork_name_unchecked(); - if fork_name >= ForkName::Electra { + if fork_name.has_feature(FeatureName::Electra) { self.min_slashing_penalty_quotient_electra - } else if fork_name >= ForkName::Bellatrix { + } else if fork_name.has_feature(FeatureName::Bellatrix) { self.min_slashing_penalty_quotient_bellatrix - } else if fork_name >= ForkName::Altair { + } else if fork_name.has_feature(FeatureName::Altair) { self.min_slashing_penalty_quotient_altair } else { self.min_slashing_penalty_quotient @@ -538,7 +538,7 @@ impl ChainSpec { } pub fn max_blocks_by_root_request(&self, fork_name: ForkName) -> usize { - if fork_name >= ForkName::Deneb { + if fork_name.has_feature(FeatureName::Deneb) { self.max_blocks_by_root_request_deneb } else { self.max_blocks_by_root_request @@ -546,7 +546,7 @@ impl ChainSpec { } pub fn max_request_blocks(&self, fork_name: ForkName) -> usize { - if fork_name >= ForkName::Deneb { + if fork_name.has_feature(FeatureName::Deneb) { self.max_request_blocks_deneb as usize } else { self.max_request_blocks as usize diff --git a/consensus/types/src/config_and_preset.rs b/consensus/types/src/config_and_preset.rs index a59108226c..3d1ea42646 100644 --- a/consensus/types/src/config_and_preset.rs +++ b/consensus/types/src/config_and_preset.rs @@ -19,7 +19,7 @@ use superstruct::superstruct; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes(derive(Serialize, Deserialize, Debug, PartialEq, Clone)) )] diff --git a/consensus/types/src/execution_payload.rs b/consensus/types/src/execution_payload.rs index a7c4da65ea..d7a6b314ce 100644 --- a/consensus/types/src/execution_payload.rs +++ b/consensus/types/src/execution_payload.rs @@ -22,7 +22,7 @@ pub type Withdrawals = VariableList::MaxWithdrawal feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/execution_payload_header.rs b/consensus/types/src/execution_payload_header.rs index 1dc7b5f95a..c9837a83cf 100644 --- a/consensus/types/src/execution_payload_header.rs +++ b/consensus/types/src/execution_payload_header.rs @@ -15,7 +15,7 @@ use tree_hash_derive::TreeHash; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/fork_name.rs b/consensus/types/src/fork_name.rs index 4b073f1a49..980f26a31d 100644 --- a/consensus/types/src/fork_name.rs +++ b/consensus/types/src/fork_name.rs @@ -59,7 +59,7 @@ impl ForkName { res } - pub fn is_feature_enabled(self, feature: FeatureName) -> bool { + pub fn has_feature(self, feature: FeatureName) -> bool { self.list_all_enabled_features().contains(&feature) } diff --git a/consensus/types/src/light_client_header.rs b/consensus/types/src/light_client_header.rs index 3ad5bcc64d..45a309e381 100644 --- a/consensus/types/src/light_client_header.rs +++ b/consensus/types/src/light_client_header.rs @@ -24,7 +24,7 @@ use tree_hash_derive::TreeHash; feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/payload.rs b/consensus/types/src/payload.rs index c985e6e01f..85a3437cae 100644 --- a/consensus/types/src/payload.rs +++ b/consensus/types/src/payload.rs @@ -117,7 +117,7 @@ pub trait AbstractExecPayload: feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( @@ -462,7 +462,7 @@ impl TryFrom> for FullPayload { feature_type( name = "FeatureName", list = "list_all_features", - check = "is_feature_enabled" + check = "has_feature" ), variant_attributes( derive( diff --git a/consensus/types/src/voluntary_exit.rs b/consensus/types/src/voluntary_exit.rs index fe80b3602a..ce7be8a900 100644 --- a/consensus/types/src/voluntary_exit.rs +++ b/consensus/types/src/voluntary_exit.rs @@ -42,7 +42,7 @@ impl VoluntaryExit { ) -> SignedVoluntaryExit { let fork_name = spec.fork_name_at_epoch(self.epoch); // EIP-7044 - let fork_version = if fork_name.is_feature_enabled(FeatureName::Deneb) { + let fork_version = if fork_name.has_feature(FeatureName::Deneb) { spec.fork_version_for_name(ForkName::Capella) } else { spec.fork_version_for_name(fork_name) diff --git a/validator_client/src/validator_store.rs b/validator_client/src/validator_store.rs index 168a172c1f..3552ac5d8f 100644 --- a/validator_client/src/validator_store.rs +++ b/validator_client/src/validator_store.rs @@ -363,7 +363,7 @@ impl ValidatorStore { if self .spec .fork_name_at_epoch(signing_epoch) - .is_feature_enabled(FeatureName::Deneb) + .has_feature(FeatureName::Deneb) { SigningContext { domain,