Skip to content

Commit

Permalink
Prioritise per validator builder boost configurations over CLI flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed Jan 24, 2024
1 parent c852a51 commit b225328
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
36 changes: 14 additions & 22 deletions validator_client/src/block_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,28 +846,24 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
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<u64> {
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.
Expand All @@ -877,10 +873,6 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
return Some(builder_boost_factor);
}

if !builder_proposals {
return Some(0);
}

None
}
}
Expand Down
61 changes: 60 additions & 1 deletion validator_client/src/validator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub struct ValidatorStore<T, E: EthSpec> {
builder_proposals: bool,
produce_block_v3: bool,
prefer_builder_proposals: bool,
builder_boost_factor: Option<u64>,
task_executor: TaskExecutor,
_phantom: PhantomData<E>,
}
Expand Down Expand Up @@ -132,6 +133,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
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,
}
Expand Down Expand Up @@ -493,14 +495,15 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
)
}

/// 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
pub fn get_builder_boost_factor(&self, validator_pubkey: &PublicKeyBytes) -> Option<u64> {
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
Expand All @@ -521,6 +524,62 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
.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<u64> {
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<u64> {
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<Payload: AbstractExecPayload<E>>(
&self,
validator_pubkey: PublicKeyBytes,
Expand Down

0 comments on commit b225328

Please sign in to comment.