Skip to content

Commit

Permalink
feat: DEVOPS-1568 replace consensus deposit with a validator
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmeds committed Sep 24, 2024
1 parent 45fbc7e commit 570baf5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion z2/resources/chain-specs/zq2-devnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ eth_chain_id = 33469
allowed_timestamp_skew = { secs = 60, nanos = 0 }
data_dir = "/data"
consensus.genesis_accounts = [ ["0x977a797a0546cdb1082c2368921af455dfdc7a5a", "21_000_000_000_000_000_000_000_000_000"] ]
consensus.genesis_deposits = [ ["8a968db895dc1f17d1e13bbf1582078f82657247820411ad3fe4f5816a75566cd9a4ba9f8e73f6306d7a7b7086e4e8a6", "12D3KooWJNUNgs1UM9mw1Pfskxk4o3VWz37cpneSHZsUecGGZgkb", "100_000_000_000_000_000_000_000_000", "0x977a797a0546cdb1082c2368921af455dfdc7a5a"] ]
consensus.genesis_deposits = [ ["b0447d886f8499bc0fd4aa21da63d71a0175ddd005d217a00c5304e1272e4a79a7df0ecb878a343582c9f2ca78c8c17f", "12D3KooWE4sUhynBXB99BciBuXDiMXWLACcqRq4ggXWdCsWxrvn3", "100_000_000_000_000_000_000_000_000", "0x977a797a0546cdb1082c2368921af455dfdc7a5a"] ]

# Reward parameters
consensus.rewards_per_hour = "51_000_000_000_000_000_000_000"
Expand Down
2 changes: 1 addition & 1 deletion z2/resources/chain-specs/zq2-prototestnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ eth_chain_id = 33103
allowed_timestamp_skew = { secs = 60, nanos = 0 }
data_dir = "/data"
consensus.genesis_accounts = [ ["0x3b5cf50bb3ed8d77d1895084092156c7549be7df", "21_000_000_000_000_000_000_000_000_000"] ]
consensus.genesis_deposits = [ ["b95bb5b3669baa33ebedd784bcab7e281deba89537ccabbe2bbb81c7bdbbd11c8a8118dfc3fd8af17077c4636c52b508", "12D3KooWEpeCSbza6zYXJ8PY8v6iEZYzYD4mhk4QbmHGbjx186dS", "100_000_000_000_000_000_000_000_000", "0x3b5cf50bb3ed8d77d1895084092156c7549be7df"] ]
consensus.genesis_deposits = [ ["89058ecd0c6f01b841f330a0c279a6061bd6cd4a446e04004b1c8169faec766374c46769a766566483e8370541b2b549", "12D3KooWPBc68cwv23Zikeuaqv8Lmqu9VNnfuYsmWFqsFD9rs91e", "100_000_000_000_000_000_000_000_000", "0x3b5cf50bb3ed8d77d1895084092156c7549be7df"] ]

# Reward parameters
consensus.rewards_per_hour = "51_000_000_000_000_000_000_000"
Expand Down
2 changes: 1 addition & 1 deletion z2/resources/config.tera.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ eth_chain_id = {{ eth_chain_id }}
allowed_timestamp_skew = { secs = 60, nanos = 0 }
data_dir = "/data"
consensus.genesis_accounts = [ ["{{ genesis_address }}", "21_000_000_000_000_000_000_000_000_000"] ]
consensus.genesis_deposits = [ ["{{ bootstrap_bls_public_key }}", "{{ bootstrap_peer_id }}", "100_000_000_000_000_000_000_000_000", "{{ genesis_address }}"] ]
consensus.genesis_deposits = [ ["{{ validator_0_bls_public_key }}", "{{ validator_0_peer_id }}", "100_000_000_000_000_000_000_000_000", "{{ genesis_address }}"] ]

# Reward parameters
consensus.rewards_per_hour = "51_000_000_000_000_000_000_000"
Expand Down
17 changes: 17 additions & 0 deletions z2/src/chain/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl ChainInstance {
let bootstrap_public_ip = self.bootstrap_public_ip()?;
let bootstrap_private_key = self.bootstrap_private_key().await?;
let genesis_wallet_private_key = self.genesis_wallet_private_key().await?;
let validator_private_keys = self.validator_private_keys().await?;

for node_role in node_roles {
let instances = self.machines_by_role(node_role.clone());
Expand All @@ -135,6 +136,7 @@ impl ChainInstance {
bootstrap_public_ip.clone(),
bootstrap_private_key.clone(),
genesis_wallet_private_key.clone(),
validator_private_keys.clone(),
)
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -172,6 +174,21 @@ impl ChainInstance {
}
}

pub async fn validator_private_keys(&self) -> Result<Vec<String>> {
let private_keys =
retrieve_secret_by_role(&self.config.name, &self.config.project_id, "validator")
.await?;

if private_keys.is_empty() {
return Err(anyhow!(
"No secrets with role validator found in the network {}",
&self.name()
));
}

Ok(private_keys)
}

pub async fn genesis_wallet_private_key(&self) -> Result<String> {
let private_keys =
retrieve_secret_by_role(&self.config.name, &self.config.project_id, "genesis").await?;
Expand Down
12 changes: 11 additions & 1 deletion z2/src/chain/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ pub struct ChainNode {
bootstrap_public_ip: String,
bootstrap_private_key: String,
genesis_wallet_private_key: String,
validator_private_keys: Vec<String>,
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -250,6 +251,7 @@ impl ChainNode {
bootstrap_public_ip: String,
bootstrap_private_key: String,
genesis_wallet_private_key: String,
validator_private_keys: Vec<String>,
) -> Self {
Self {
chain_name,
Expand All @@ -260,6 +262,7 @@ impl ChainNode {
bootstrap_public_ip,
bootstrap_private_key,
genesis_wallet_private_key,
validator_private_keys,
}
}

Expand Down Expand Up @@ -498,6 +501,12 @@ impl ChainNode {
pub fn get_config_toml(&self) -> Result<String> {
let spec_config = include_str!("../../resources/config.tera.toml");

let validator_node = if let Some(pk) = self.validator_private_keys.first() {
EthereumAddress::from_private_key(pk)?
} else {
return Err(anyhow!("Validator private keys not found"));
};

let genesis_wallet = EthereumAddress::from_private_key(&self.genesis_wallet_private_key)?;
let bootstrap_node = EthereumAddress::from_private_key(&self.bootstrap_private_key)?;
let role_name = self.role.to_string();
Expand All @@ -508,8 +517,9 @@ impl ChainNode {
var_map.insert("eth_chain_id", &eth_chain_id);
var_map.insert("bootstrap_public_ip", &self.bootstrap_public_ip);
var_map.insert("bootstrap_peer_id", &bootstrap_node.peer_id);
var_map.insert("bootstrap_bls_public_key", &bootstrap_node.bls_public_key);
var_map.insert("genesis_address", &genesis_wallet.address);
var_map.insert("validator_0_bls_public_key", &validator_node.bls_public_key);
var_map.insert("validator_0_peer_id", &validator_node.peer_id);

let ctx = Context::from_serialize(var_map)?;
Ok(Tera::one_off(spec_config, &ctx, false)?)
Expand Down

0 comments on commit 570baf5

Please sign in to comment.