diff --git a/validator_client/src/block_service.rs b/validator_client/src/block_service.rs index 36ab8e81718..e632521d9b9 100644 --- a/validator_client/src/block_service.rs +++ b/validator_client/src/block_service.rs @@ -846,28 +846,24 @@ impl BlockService { Ok::<_, BlockError>(unsigned_block) } - /// Translate `builder_proposals``, `builder_boost_factor`` and `prefer_builder_proposals`` to a - /// boost factor. If `prefer_builder_proposals` is true, set boost factor to - /// u64::MAX to indicate a preference for builder payloads. If `builder_boost_factor` - /// is a value other than None, return its value as the boost factor. If `builder_proposals` - /// is set to false, set boost factor to 0 to indicate a preference for local payloads. - /// Else return None to indicate no preference between builder and local payloads. + /// Returns the builder boost factor of the given public key. + /// The priority order for fetching this value is: + /// + /// 1. validator_definitions.yml + /// 2. process level flag fn get_builder_boost_factor(&self, validator_pubkey: &PublicKeyBytes) -> Option { - let builder_proposals = self.validator_store.get_builder_proposals(validator_pubkey); - - let builder_boost_factor = self - .validator_store - .get_builder_boost_factor(validator_pubkey); - - let prefer_builder_proposals = self + // Apply per validator configuration first. + let validator_builder_boost_factor = self .validator_store - .get_prefer_builder_proposals(validator_pubkey); + .determine_validator_builder_boost_factor(validator_pubkey); - if prefer_builder_proposals { - return Some(u64::MAX); - } + // Fallback to process-wide configuration if needed. + let maybe_builder_boost_factor = validator_builder_boost_factor.or_else(|| { + self.validator_store + .determine_default_builder_boost_factor() + }); - if let Some(builder_boost_factor) = builder_boost_factor { + if let Some(builder_boost_factor) = maybe_builder_boost_factor { // if builder boost factor is set to 100 it should be treated // as None to prevent unnecessary calculations that could // lead to loss of information. @@ -877,10 +873,6 @@ impl BlockService { return Some(builder_boost_factor); } - if !builder_proposals { - return Some(0); - } - None } } diff --git a/validator_client/src/validator_store.rs b/validator_client/src/validator_store.rs index 4d28265abe1..f1a4a7aa984 100644 --- a/validator_client/src/validator_store.rs +++ b/validator_client/src/validator_store.rs @@ -99,6 +99,7 @@ pub struct ValidatorStore { builder_proposals: bool, produce_block_v3: bool, prefer_builder_proposals: bool, + builder_boost_factor: Option, task_executor: TaskExecutor, _phantom: PhantomData, } @@ -132,6 +133,7 @@ impl ValidatorStore { builder_proposals: config.builder_proposals, produce_block_v3: config.produce_block_v3, prefer_builder_proposals: config.prefer_builder_proposals, + builder_boost_factor: config.builder_boost_factor, task_executor, _phantom: PhantomData, } @@ -493,7 +495,7 @@ impl ValidatorStore { ) } - /// Returns a `u64` for the given public key that denotes the builder boost factor. The priority order for fetching this value is: + /// Returns a `u64` for the given public key that denotes the builder boost factor. /// /// 1. validator_definitions.yml /// 2. process level flag @@ -501,6 +503,7 @@ impl ValidatorStore { self.validators .read() .builder_boost_factor(validator_pubkey) + .or(self.builder_boost_factor) } /// Returns a `bool` for the given public key that denotes whether this validator should prefer a @@ -521,6 +524,62 @@ impl ValidatorStore { .unwrap_or(self.builder_proposals) } + /// Translate the per validator `builder_proposals`, `builder_boost_factor` and + /// `prefer_builder_proposals` to a boost factor, if available. + /// - If `prefer_builder_proposals` is true, set boost factor to `u64::MAX` to indicate a + /// preference for builder payloads. + /// - If `builder_boost_factor` is a value other than None, return its value as the boost factor. + /// - If `builder_proposals` is set to false, set boost factor to 0 to indicate a preference for + /// local payloads. + /// - Else return `None` to indicate no preference between builder and local payloads. + pub fn determine_validator_builder_boost_factor( + &self, + validator_pubkey: &PublicKeyBytes, + ) -> Option { + let validator_prefer_builder_proposals = self + .validators + .read() + .prefer_builder_proposals(validator_pubkey); + + if matches!(validator_prefer_builder_proposals, Some(true)) { + return Some(u64::MAX); + } + + self.validators + .read() + .builder_boost_factor(validator_pubkey) + .or_else(|| { + if matches!( + self.validators.read().builder_proposals(validator_pubkey), + Some(false) + ) { + return Some(0); + } + None + }) + } + + /// Translate the process-wide `builder_proposals`, `builder_boost_factor` and + /// `prefer_builder_proposals` configurations to a boost factor. + /// - If `prefer_builder_proposals` is true, set boost factor to `u64::MAX` to indicate a + /// preference for builder payloads. + /// - If `builder_boost_factor` is a value other than None, return its value as the boost factor. + /// - If `builder_proposals` is set to false, set boost factor to 0 to indicate a preference for + /// local payloads. + /// - Else return `None` to indicate no preference between builder and local payloads. + pub fn determine_default_builder_boost_factor(&self) -> Option { + if self.prefer_builder_proposals { + return Some(u64::MAX); + } + self.builder_boost_factor.or({ + if self.builder_proposals { + Some(0) + } else { + None + } + }) + } + pub async fn sign_block>( &self, validator_pubkey: PublicKeyBytes,