From c05ba79e4b33e0c44bea97492ee26e5299d45099 Mon Sep 17 00:00:00 2001 From: thedevbirb Date: Thu, 10 Oct 2024 11:41:44 +0200 Subject: [PATCH] feat(sidecar): add keystore signer to driver --- bolt-sidecar/bin/sidecar.rs | 11 ++++++++++- bolt-sidecar/src/driver.rs | 25 ++++++++++++++++++++++--- bolt-sidecar/src/signer/keystore.rs | 4 +++- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/bolt-sidecar/bin/sidecar.rs b/bolt-sidecar/bin/sidecar.rs index ab63b2ee5..909d4e402 100644 --- a/bolt-sidecar/bin/sidecar.rs +++ b/bolt-sidecar/bin/sidecar.rs @@ -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 { diff --git a/bolt-sidecar/src/driver.rs b/bolt-sidecar/src/driver.rs index 4ce5c43db..060120671 100644 --- a/bolt-sidecar/src/driver.rs +++ b/bolt-sidecar/src/driver.rs @@ -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, @@ -61,7 +61,7 @@ impl fmt::Debug for SidecarDriver { } impl SidecarDriver { - /// 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 { // The default state client simply uses the execution API URL to fetch state updates. let state_client = StateClient::new(opts.execution_api_url.clone()); @@ -80,8 +80,27 @@ impl SidecarDriver { } } +impl SidecarDriver { + /// Create a new sidecar driver with the given [Opts] and keystore signer. + pub async fn with_keystore_signer(opts: &Opts) -> eyre::Result { + // 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 { - /// 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 { // The default state client simply uses the execution API URL to fetch state updates. let state_client = StateClient::new(opts.execution_api_url.clone()); diff --git a/bolt-sidecar/src/signer/keystore.rs b/bolt-sidecar/src/signer/keystore.rs index 9652a603a..e05373503 100644 --- a/bolt-sidecar/src/signer/keystore.rs +++ b/bolt-sidecar/src/signer/keystore.rs @@ -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, @@ -84,7 +86,7 @@ impl Debug for KeystoreSigner { fn keystore_paths(keys_path: Option<&str>) -> Result, 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");