Skip to content

Commit

Permalink
remove hardcode strings and uncomment PKSigningClient
Browse files Browse the repository at this point in the history
  • Loading branch information
JayT106 committed Jun 24, 2024
1 parent f8eafe1 commit d93c2ca
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 110 deletions.
6 changes: 5 additions & 1 deletion core/lib/eth_client/src/clients/http/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ impl GKMSSigningClient {
SigningClient::new(
query_client,
hyperchain_contract(),
Address::default(),
signer.get_address().await.unwrap(),
signer,
diamond_proxy_addr,
default_priority_fee_per_gas.into(),
l1_chain_id,
)
}

pub fn get_address(&self) -> Address {
self.inner.sender_account
}
}

/// Gas limit value to be used in transaction if for some reason
Expand Down
308 changes: 203 additions & 105 deletions core/lib/zksync_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ use zksync_config::{
},
consensus::ConsensusConfig,
database::{MerkleTreeConfig, MerkleTreeMode},
wallets,
wallets::Wallets,
wallets::{self, Wallets},
ContractsConfig, GeneralConfig,
},
ApiConfig, DBConfig, EthWatchConfig, GenesisConfig, PostgresConfig,
Expand All @@ -47,7 +46,7 @@ use zksync_contracts::governance_contract;
use zksync_dal::{metrics::PostgresMetrics, ConnectionPool, Core, CoreDal};
use zksync_db_connection::healthcheck::ConnectionPoolHealthCheck;
use zksync_eth_client::{
clients::{GKMSSigningClient, QueryClient},
clients::{GKMSSigningClient, PKSigningClient, QueryClient},
BoundEthInterface, EthInterface,
};
use zksync_eth_sender::{
Expand Down Expand Up @@ -103,10 +102,6 @@ use crate::{
utils::ensure_l1_batch_commit_data_generation_mode,
};

// hardcoded for now
const OP_KEY_NAME: &'static str = "projects/zkevm-research/locations/northamerica-northeast2/keyRings/gkms_signer_test/cryptoKeys/gkms_signer_op/cryptoKeyVersions/3";
const OP_BLOB_KEY_NAME: &'static str = "projects/zkevm-research/locations/northamerica-northeast2/keyRings/gkms_signer_test/cryptoKeys/gkms_signer_op_blob/cryptoKeyVersions/2";

pub mod api_server;
pub mod consensus;
pub mod consistency_checker;
Expand Down Expand Up @@ -644,7 +639,7 @@ pub async fn initialize_components(
.context("failed to build eth_sender_pool")?;

let eth_sender_wallets = wallets.eth_sender.clone().context("eth_sender")?;
//let operator_private_key = eth_sender_wallets.operator.private_key();
let operator_private_key = eth_sender_wallets.operator.private_key();
let diamond_proxy_addr = contracts_config.diamond_proxy_addr;
let default_priority_fee_per_gas = eth
.gas_adjuster
Expand All @@ -653,63 +648,138 @@ pub async fn initialize_components(
.default_priority_fee_per_gas;
let l1_chain_id = genesis_config.l1_chain_id;

// let eth_client = PKSigningClient::new_raw(
// operator_private_key.clone(),
// diamond_proxy_addr,
// default_priority_fee_per_gas,
// l1_chain_id,
// query_client.clone(),
// );

let eth_client = GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
OP_KEY_NAME.to_string(),
)
.await;
let gkms_op_key_name = std::env::var("GOOGLE_KMS_OP_KEY_NAME").ok();
tracing::info!(
"KMS op key name: {:?}",
std::env::var("GOOGLE_KMS_OP_KEY_NAME")
);

let l1_batch_commit_data_generator_mode =
genesis_config.l1_batch_commit_data_generator_mode;
ensure_l1_batch_commit_data_generation_mode(
l1_batch_commit_data_generator_mode,
contracts_config.diamond_proxy_addr,
eth_client.as_ref(),
)
.await?;
let use_gkms_signing_client = gkms_op_key_name.is_some();

let l1_batch_commit_data_generator: Arc<dyn L1BatchCommitDataGenerator> =
match l1_batch_commit_data_generator_mode {
L1BatchCommitDataGeneratorMode::Rollup => {
Arc::new(RollupModeL1BatchCommitDataGenerator {})
}
L1BatchCommitDataGeneratorMode::Validium => {
Arc::new(ValidiumModeL1BatchCommitDataGenerator {})
}
let eth_tx_aggregator_actor;
if use_gkms_signing_client {
let eth_client = GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
gkms_op_key_name
.expect("gkms_op_key_name is required but was None")
.to_string(),
)
.await;

let l1_batch_commit_data_generator_mode =
genesis_config.l1_batch_commit_data_generator_mode;
ensure_l1_batch_commit_data_generation_mode(
l1_batch_commit_data_generator_mode,
contracts_config.diamond_proxy_addr,
eth_client.as_ref(),
)
.await?;

let l1_batch_commit_data_generator: Arc<dyn L1BatchCommitDataGenerator> =
match l1_batch_commit_data_generator_mode {
L1BatchCommitDataGeneratorMode::Rollup => {
Arc::new(RollupModeL1BatchCommitDataGenerator {})
}
L1BatchCommitDataGeneratorMode::Validium => {
Arc::new(ValidiumModeL1BatchCommitDataGenerator {})
}
};

let gkms_op_blob_key_name = std::env::var("GOOGLE_KMS_OP_BLOB_KEY_NAME").ok();
tracing::info!(
"KMS op blob key name: {:?}",
std::env::var("GOOGLE_KMS_OP_BLOB_KEY_NAME")
);
let operator_blobs_address = if gkms_op_blob_key_name.is_some() {
let eth_blob_client = GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
gkms_op_blob_key_name
.expect("gkms_op_blob_key_name is required but was None")
.to_string(),
)
.await;

Some(eth_blob_client.sender_account())
} else {
None
};

let operator_blobs_address = eth_sender_wallets.blob_operator.map(|x| x.address());
let sender_config = eth.sender.clone().context("eth_sender")?;
eth_tx_aggregator_actor = EthTxAggregator::new(
eth_sender_pool,
sender_config.clone(),
Aggregator::new(
sender_config.clone(),
store_factory.create_store().await,
operator_blobs_address.is_some(),
l1_batch_commit_data_generator.clone(),
),
Box::new(eth_client),
contracts_config.validator_timelock_addr,
contracts_config.l1_multicall3_addr,
diamond_proxy_addr,
l2_chain_id,
operator_blobs_address,
l1_batch_commit_data_generator,
)
.await;
} else {
let eth_client = PKSigningClient::new_raw(
operator_private_key.clone(),
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
);

let l1_batch_commit_data_generator_mode =
genesis_config.l1_batch_commit_data_generator_mode;
ensure_l1_batch_commit_data_generation_mode(
l1_batch_commit_data_generator_mode,
contracts_config.diamond_proxy_addr,
eth_client.as_ref(),
)
.await?;

let sender_config = eth.sender.clone().context("eth_sender")?;
let eth_tx_aggregator_actor = EthTxAggregator::new(
eth_sender_pool,
sender_config.clone(),
Aggregator::new(
let l1_batch_commit_data_generator: Arc<dyn L1BatchCommitDataGenerator> =
match l1_batch_commit_data_generator_mode {
L1BatchCommitDataGeneratorMode::Rollup => {
Arc::new(RollupModeL1BatchCommitDataGenerator {})
}
L1BatchCommitDataGeneratorMode::Validium => {
Arc::new(ValidiumModeL1BatchCommitDataGenerator {})
}
};

let operator_blobs_address = eth_sender_wallets.blob_operator.map(|x| x.address());

let sender_config = eth.sender.clone().context("eth_sender")?;
eth_tx_aggregator_actor = EthTxAggregator::new(
eth_sender_pool,
sender_config.clone(),
store_factory.create_store().await,
operator_blobs_address.is_some(),
l1_batch_commit_data_generator.clone(),
),
Box::new(eth_client),
contracts_config.validator_timelock_addr,
contracts_config.l1_multicall3_addr,
diamond_proxy_addr,
l2_chain_id,
operator_blobs_address,
l1_batch_commit_data_generator,
)
.await;
Aggregator::new(
sender_config.clone(),
store_factory.create_store().await,
operator_blobs_address.is_some(),
l1_batch_commit_data_generator.clone(),
),
Box::new(eth_client),
contracts_config.validator_timelock_addr,
contracts_config.l1_multicall3_addr,
diamond_proxy_addr,
l2_chain_id,
operator_blobs_address,
l1_batch_commit_data_generator,
)
.await;
}

task_futures.push(tokio::spawn(
eth_tx_aggregator_actor.run(stop_receiver.clone()),
));
Expand All @@ -727,7 +797,6 @@ pub async fn initialize_components(
.context("failed to build eth_manager_pool")?;
let eth_sender = configs.eth.clone().context("eth_sender_config")?;
let eth_sender_wallets = wallets.eth_sender.clone().context("eth_sender")?;
//let operator_private_key = eth_sender_wallets.operator.private_key();
let diamond_proxy_addr = contracts_config.diamond_proxy_addr;
let default_priority_fee_per_gas = eth
.gas_adjuster
Expand All @@ -736,57 +805,86 @@ pub async fn initialize_components(
.default_priority_fee_per_gas;
let l1_chain_id = genesis_config.l1_chain_id;

// let eth_client = PKSigningClient::new_raw(
// operator_private_key.clone(),
// diamond_proxy_addr,
// default_priority_fee_per_gas,
// l1_chain_id,
// query_client.clone(),
// );

let eth_client = GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
OP_KEY_NAME.to_string(),
)
.await;
let gkms_op_key_name = std::env::var("GOOGLE_KMS_OP_KEY_NAME").ok();
let use_gkms_signing_client = gkms_op_key_name.is_some();

let eth_tx_manager_actor;
if use_gkms_signing_client {
let eth_client = GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
gkms_op_key_name
.expect("gkms_op_key_name is required but was None")
.to_string(),
)
.await;

let gkms_op_blob_key_name = std::env::var("GOOGLE_KMS_OP_BLOB_KEY_NAME").ok();
let eth_client_blobs = if gkms_op_blob_key_name.is_some() {
let client = Box::new(
GKMSSigningClient::new_raw(
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
gkms_op_blob_key_name
.expect("gkms_op_blob_key_name is required but was None")
.to_string(),
)
.await,
);
Some(client as Box<dyn BoundEthInterface>)
} else {
None
};

let eth_client_blobs = if let Some(blob_operator) = eth_sender_wallets.blob_operator {
// let operator_blob_private_key = blob_operator.private_key().clone();
// let client = Box::new(PKSigningClient::new_raw(
// operator_blob_private_key,
// diamond_proxy_addr,
// default_priority_fee_per_gas,
// l1_chain_id,
// query_client,
// ));
let client = Box::new(
GKMSSigningClient::new_raw(
eth_tx_manager_actor = EthTxManager::new(
eth_manager_pool,
eth_sender.sender.clone().context("eth_sender")?,
gas_adjuster
.get_or_init()
.await
.context("gas_adjuster.get_or_init()")?,
Box::new(eth_client),
eth_client_blobs,
);
} else {
let operator_private_key = eth_sender_wallets.operator.private_key();
let eth_client = PKSigningClient::new_raw(
operator_private_key.clone(),
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
);
let eth_client_blobs = if let Some(blob_operator) = eth_sender_wallets.blob_operator {
let operator_blob_private_key = blob_operator.private_key().clone();
let client = Box::new(PKSigningClient::new_raw(
operator_blob_private_key,
diamond_proxy_addr,
default_priority_fee_per_gas,
l1_chain_id,
query_client.clone(),
OP_BLOB_KEY_NAME.to_string(),
)
.await,
query_client,
));
Some(client as Box<dyn BoundEthInterface>)
} else {
None
};

eth_tx_manager_actor = EthTxManager::new(
eth_manager_pool,
eth_sender.sender.clone().context("eth_sender")?,
gas_adjuster
.get_or_init()
.await
.context("gas_adjuster.get_or_init()")?,
Box::new(eth_client),
eth_client_blobs,
);
Some(client as Box<dyn BoundEthInterface>)
} else {
None
};
}

let eth_tx_manager_actor = EthTxManager::new(
eth_manager_pool,
eth_sender.sender.clone().context("eth_sender")?,
gas_adjuster
.get_or_init()
.await
.context("gas_adjuster.get_or_init()")?,
Box::new(eth_client),
eth_client_blobs,
);
task_futures.extend([tokio::spawn(
eth_tx_manager_actor.run(stop_receiver.clone()),
)]);
Expand Down
Loading

0 comments on commit d93c2ca

Please sign in to comment.