diff --git a/bolt-sidecar/src/client/constraints_client.rs b/bolt-sidecar/src/client/constraints_client.rs index cb15c2c2a..747961bda 100644 --- a/bolt-sidecar/src/client/constraints_client.rs +++ b/bolt-sidecar/src/client/constraints_client.rs @@ -50,11 +50,11 @@ impl ConstraintsClient { } /// Finds all delegations for the given public key. - pub fn find_delegatees(&self, pubkey: &BlsPublicKey) -> Vec<&BlsPublicKey> { + pub fn find_delegatees(&self, pubkey: &BlsPublicKey) -> Vec { self.delegations .iter() .filter(|d| d.message.delegatee_pubkey == *pubkey) - .map(|d| &d.message.delegatee_pubkey) + .map(|d| d.message.delegatee_pubkey.clone()) .collect::>() } diff --git a/bolt-sidecar/src/driver.rs b/bolt-sidecar/src/driver.rs index de2a023ed..a1d7d85b9 100644 --- a/bolt-sidecar/src/driver.rs +++ b/bolt-sidecar/src/driver.rs @@ -8,6 +8,7 @@ use alloy::{rpc::types::beacon::events::HeadEvent, signers::local::PrivateKeySig use beacon_api_client::mainnet::Client as BeaconClient; use ethereum_consensus::{ clock::{self, SlotStream, SystemTimeProvider}, + crypto::bls::PublicKey as BlsPublicKey, phase0::mainnet::SLOTS_PER_EPOCH, }; use futures::StreamExt; @@ -280,18 +281,8 @@ impl SidecarDriver { // Rationale: // - If there are no delegatee keys, try to use the validator key directly if available. // - If there are delegatee keys, try to use the first one that is available in the list. - let pubkey = if delegatees.is_empty() { - if available_pubkeys.contains(&validator_pubkey) { - validator_pubkey.clone() - } else { - error!(%target_slot, %validator_pubkey, "No authorized private key available to sign constraints"); - let _ = response.send(Err(CommitmentError::Internal)); - return; - } - } else if let Some(delegatee) = available_pubkeys.iter().find(|k| delegatees.contains(k)) { - delegatee.clone() - } else { - error!(%target_slot, "No delegatee key found, unable to sign constraints"); + let Some(pubkey) = pick_public_key(validator_pubkey, available_pubkeys, delegatees) else { + error!(%target_slot, "No available public key to sign constraints with"); let _ = response.send(Err(CommitmentError::Internal)); return; }; @@ -399,3 +390,29 @@ impl SidecarDriver { } } } + +/// Pick a pubkey to sign constraints with. +/// +/// Rationale: +/// - If there are no delegatee keys, try to use the validator key directly if available. +/// - If there are delegatee keys, try to use the first one that is available in the list. +fn pick_public_key( + validator: BlsPublicKey, + available: Vec, + delegatees: Vec, +) -> Option { + if delegatees.is_empty() { + if available.contains(&validator) { + return Some(validator); + } else { + return None; + } + } else { + for delegatee in delegatees { + if available.contains(&delegatee) { + return Some(delegatee); + } + } + } + None +}