Skip to content

Commit

Permalink
Merge branch 'unstable' into lore/feat/holesky-launch
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 31, 2024
2 parents 225f4d4 + 570ac35 commit eee25c7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 43 deletions.
109 changes: 67 additions & 42 deletions bolt-sidecar/src/chain_io/manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::str::FromStr;
use tracing::error;

use alloy::{
contract::Error as ContractError,
Expand All @@ -14,6 +13,7 @@ use eyre::bail;
use reqwest::{Client, Url};
use serde::Serialize;

use tracing::debug;
use BoltManagerContract::{
BoltManagerContractErrors, BoltManagerContractInstance, ProposerStatus, ValidatorDoesNotExist,
};
Expand All @@ -22,6 +22,8 @@ use crate::config::chain::Chain;

use super::utils::{self, CompressedHash};

const CHUNK_SIZE: usize = 1_000;

/// A wrapper over a BoltManagerContract that exposes various utility methods.
#[derive(Debug, Clone)]
pub struct BoltManager(BoltManagerContractInstance<Http<Client>, RootProvider<Http<Client>>>);
Expand Down Expand Up @@ -54,57 +56,79 @@ impl BoltManager {
commitment_signer_pubkey: Address,
) -> eyre::Result<Vec<ProposerStatus>> {
let hashes_with_preimages = utils::pubkey_hashes(keys);
let hashes = hashes_with_preimages.keys().cloned().collect::<Vec<_>>();

let returndata = self.0.getProposerStatuses(hashes).call().await;

// TODO: clean this after https://github.com/alloy-rs/alloy/issues/787 is merged
let error = match returndata.map(|data| data.statuses) {
Ok(statuses) => {
for status in &statuses {
if !status.active {
bail!(
let mut hashes = hashes_with_preimages.keys().cloned().collect::<Vec<_>>();

let mut proposers_statuses = Vec::with_capacity(hashes.len());

let mut i = 0;
while !hashes.is_empty() {
i += 1;

// No more than CHUNK_SIZE at a time to avoid EL config limits
//
// TODO: write an unsafe function that splits a vec into owned chunks without
// allocating
let hashes_chunk = hashes.drain(..CHUNK_SIZE.min(hashes.len())).collect::<Vec<_>>();

debug!(
"fetching proposer statuses for chunk {} of {}",
i,
hashes.len().div_ceil(CHUNK_SIZE)
);

let returndata = self.0.getProposerStatuses(hashes_chunk).call().await;

// TODO: clean this after https://github.com/alloy-rs/alloy/issues/787 is merged
let error = match returndata.map(|data| data.statuses) {
Ok(statuses) => {
for status in &statuses {
if !status.active {
bail!(
"validator with public key {:?} and public key hash {:?} is not active in Bolt",
hashes_with_preimages.get(&status.pubkeyHash),
status.pubkeyHash
);
} else if status.operator != commitment_signer_pubkey {
bail!(generate_operator_keys_mismatch_error(
status.pubkeyHash,
commitment_signer_pubkey,
status.operator
));
} else if status.operator != commitment_signer_pubkey {
bail!(generate_operator_keys_mismatch_error(
status.pubkeyHash,
commitment_signer_pubkey,
status.operator
));
}
}

proposers_statuses.extend(statuses);

continue;
}
Err(error) => match error {
ContractError::TransportError(TransportError::ErrorResp(err)) => {
let data = err.data.unwrap_or_default();
let data = data.get().trim_matches('"');
let data = Bytes::from_str(data)?;

return Ok(statuses);
}
Err(error) => match error {
ContractError::TransportError(TransportError::ErrorResp(err)) => {
error!("Error response from BoltManager contract: {:?}", err);
let data = err.data.unwrap_or_default();
let data = data.get().trim_matches('"');
let data = Bytes::from_str(data)?;

BoltManagerContractErrors::abi_decode(&data, true)?
BoltManagerContractErrors::abi_decode(&data, true)?
}
e => return Err(e)?,
},
};

match error {
BoltManagerContractErrors::ValidatorDoesNotExist(ValidatorDoesNotExist {
pubkeyHash: pubkey_hash,
}) => {
bail!("ValidatorDoesNotExist -- validator with public key {:?} and public key hash {:?} is not registered in Bolt", hashes_with_preimages.get(&pubkey_hash), pubkey_hash);
}
BoltManagerContractErrors::InvalidQuery(_) => {
bail!("InvalidQuery -- invalid zero public key hash");
}
BoltManagerContractErrors::KeyNotFound(_) => {
bail!("KeyNotFound -- operator associated with commitment signer public key {:?} is not registered in Bolt", commitment_signer_pubkey);
}
e => return Err(e)?,
},
};

match error {
BoltManagerContractErrors::ValidatorDoesNotExist(ValidatorDoesNotExist {
pubkeyHash: pubkey_hash,
}) => {
bail!("ValidatorDoesNotExist -- validator with public key {:?} and public key hash {:?} is not registered in Bolt", hashes_with_preimages.get(&pubkey_hash), pubkey_hash);
}
BoltManagerContractErrors::InvalidQuery(_) => {
bail!("InvalidQuery -- invalid zero public key hash");
}
BoltManagerContractErrors::KeyNotFound(_) => {
bail!("KeyNotFound -- operator associated with commitment signer public key {:?} is not registered in Bolt", commitment_signer_pubkey);
}
}

Ok(proposers_statuses)
}
}

Expand Down Expand Up @@ -161,6 +185,7 @@ mod tests {
use super::BoltManager;

#[tokio::test]
#[ignore = "requires Chainbound tailnet"]
async fn test_verify_validator_pubkeys() {
let url = Url::parse("http://remotebeast:48545").expect("valid url");
let manager =
Expand Down
7 changes: 6 additions & 1 deletion bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,18 @@ impl<C: StateFetcher, ECDSA: SignerECDSA> SidecarDriver<C, ECDSA> {
{
let commitment_signer_pubkey = commitment_signer.public_key();
let validator_public_keys_len = validator_public_keys.len();
info!(
validator_public_keys_len,
commitment_signer_pubkey = ?commitment_signer_pubkey,
"Verifying validators and operator keys with Bolt Manager, this may take a while..."
);
bolt_manager
.verify_validator_pubkeys(validator_public_keys, commitment_signer_pubkey)
.await?;
info!(
validator_public_keys_len,
commitment_signer_pubkey = ?commitment_signer_pubkey,
"Validators and operator keys verified with Bolt Manager successfully"
"Verified validators and operator keys verified with Bolt Manager successfully"
);
} else {
warn!(
Expand Down

0 comments on commit eee25c7

Please sign in to comment.