Skip to content

Commit

Permalink
feat(sidecar): add keystore signer to driver
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Oct 10, 2024
1 parent 6582236 commit c05ba79
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
11 changes: 10 additions & 1 deletion bolt-sidecar/bin/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ async fn main() -> Result<()> {
if opts.signing.private_key.is_some() {
match SidecarDriver::with_local_signer(&opts).await {
Ok(driver) => driver.run_forever().await,
Err(err) => bail!("Failed to initialize the sidecar driver: {:?}", err),
Err(err) => {
bail!("Failed to initialize the sidecar driver with local signer: {:?}", err)
}
}
} else if opts.signing.keystore_password.is_some() {
match SidecarDriver::with_keystore_signer(&opts).await {
Ok(driver) => driver.run_forever().await,
Err(err) => {
bail!("Failed to initialize the sidecar driver with keystore signer: {:?}", err)
}
}
} else {
match SidecarDriver::with_commit_boost_signer(&opts).await {
Expand Down
25 changes: 22 additions & 3 deletions bolt-sidecar/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
CommitmentRequest, ConstraintsMessage, FetchPayloadRequest, LocalPayloadFetcher,
SignedConstraints, TransactionExt,
},
signer::local::LocalSigner,
signer::{keystore::KeystoreSigner, local::LocalSigner},
start_builder_proxy_server,
state::{fetcher::StateFetcher, ConsensusState, ExecutionState, HeadTracker, StateClient},
telemetry::ApiMetrics,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl fmt::Debug for SidecarDriver<StateClient, PrivateKeySigner> {
}

impl SidecarDriver<StateClient, PrivateKeySigner> {
/// Create a new sidecar driver with the given [Config] and private key signer.
/// Create a new sidecar driver with the given [Opts] and private key signer.
pub async fn with_local_signer(opts: &Opts) -> eyre::Result<Self> {
// The default state client simply uses the execution API URL to fetch state updates.
let state_client = StateClient::new(opts.execution_api_url.clone());
Expand All @@ -80,8 +80,27 @@ impl SidecarDriver<StateClient, PrivateKeySigner> {
}
}

impl SidecarDriver<StateClient, PrivateKeySigner> {
/// Create a new sidecar driver with the given [Opts] and keystore signer.
pub async fn with_keystore_signer(opts: &Opts) -> eyre::Result<Self> {
// The default state client simply uses the execution API URL to fetch state updates.
let state_client = StateClient::new(opts.execution_api_url.clone());

let keystore_signer = SignerBLS::Keystore(KeystoreSigner::new(
None,
opts.signing.keystore_password.as_ref().expect("keystore password").as_ref(),
)?);

// Commitment responses are signed with a regular Ethereum wallet private key.
// This is now generated randomly because slashing is not yet implemented.
let commitment_signer = PrivateKeySigner::random();

Self::from_components(opts, keystore_signer, commitment_signer, state_client).await
}
}

impl SidecarDriver<StateClient, CommitBoostSigner> {
/// Create a new sidecar driver with the given [Config] and commit-boost signer.
/// Create a new sidecar driver with the given [Opts] and commit-boost signer.
pub async fn with_commit_boost_signer(opts: &Opts) -> eyre::Result<Self> {
// The default state client simply uses the execution API URL to fetch state updates.
let state_client = StateClient::new(opts.execution_api_url.clone());
Expand Down
4 changes: 3 additions & 1 deletion bolt-sidecar/src/signer/keystore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use lighthouse_eth2_keystore::Keystore;

use crate::crypto::bls::BLSSig;

pub const KEYSTORES_DEFAULT_PATH: &str = "keys";

#[derive(Clone)]
pub struct KeystoreSigner {
keypairs: Vec<Keypair>,
Expand Down Expand Up @@ -84,7 +86,7 @@ impl Debug for KeystoreSigner {
fn keystore_paths(keys_path: Option<&str>) -> Result<Vec<PathBuf>, eyre::Error> {
// Create the path to the keystore directory, starting from the root of the project
let project_root = env!("CARGO_MANIFEST_DIR");
let keys_path = Path::new(project_root).join(keys_path.unwrap_or("keys"));
let keys_path = Path::new(project_root).join(keys_path.unwrap_or(KEYSTORES_DEFAULT_PATH));

let json_extension = OsString::from("json");

Expand Down

0 comments on commit c05ba79

Please sign in to comment.