Skip to content

Commit

Permalink
Merge branch 'main' into 2318-deploy-essential-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
bzawisto committed Feb 13, 2025
2 parents 85f0281 + 3ed2e53 commit d0cdb94
Show file tree
Hide file tree
Showing 12 changed files with 688 additions and 221 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion z2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ reqwest = {version = "0.12.9", features = ["json", "rustls-tls", "http2", "chars
revm = {version = "19.4.0", features = ["optional_balance_check"]}
rs-leveldb = "0.1.5"
rustls = "0.23.22"
scopeguard = "1.2.0"
serde = {version = "1.0.217", features = ["derive"]}
serde_json = { version = "1.0.138", features = ["preserve_order"] }
serde_yaml = "0.9.34"
Expand All @@ -77,7 +78,6 @@ url = "2.5.4"
zilliqa = {path = "../zilliqa"}
zilliqa-rs = "0.3.2"
zqutils = {git = "https://github.com/zilliqa/zq-base"}
scopeguard = "1.2.0"

[build-dependencies]
prost-build = "0.13.3"
14 changes: 7 additions & 7 deletions z2/docs/staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ z2 deposit \
--signing-address <SIGNING_ADDRESS>


Usage: z2 deposit --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET_WITH_MIN_10_MIL_FUND> --public-key <BLS_PUBLIC_KEY> --peer-id <PEER_ID> --deposit-auth-signature <DEPOSIT_AUTH_SIGNATURE> --amount <AMOUNT_IN_ZIL> --reward-address <REWARD_ADDRESS_OF_VALIDATOR> --signing-address <SIGNING_ADDRESS_OF_VALIDATOR>
Usage: z2 deposit --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET_WITH_MIN_10_MIL_FUND> --public-key <BLS_PUBLIC_KEY> --peer-id <PEER_ID> --deposit-auth-signature <DEPOSIT_AUTH_SIGNATURE> --amount <AMOUNT_IN_MILLION_OF_ZIL> --reward-address <REWARD_ADDRESS_OF_VALIDATOR> --signing-address <SIGNING_ADDRESS_OF_VALIDATOR>
```
## Parameters
* `--chain <CHAIN_NAME>`: The name of the chain. Possible values are zq2-devnet, zq2-prototestnet, zq2-protomainnet, zq2-testnet, zq2-mainnet.
* `--private-key <PRIVATE_KEY_OF_WALLET_WITH_MIN_10_MIL_FUND>`: The private key of the wallet that has a minimum stake amount of 10 million.
* `--public-key <BLS_PUBLIC_KEY>`: The BLS public key of the validator node.
* `--peer-id <PEER_ID>`: The peer ID of the validator node.
* `--deposit-auth-signature <DEPOSIT_AUTH_SIGNATURE>`: BLS signature of the validator node signing over control address and chain Id.
* `--amount <AMOUNT_IN_MILLION_ZIL>`: The amount in ZIL to deposit. The valid range is from 10 million to 255 million ZIL, allowing a deposit of up to 255 million ZIL.
* `--amount <AMOUNT_IN_MILLION_ZIL>`: The amount in millions of ZIL to deposit. The valid range is from 10 million to 255 million ZIL, allowing a deposit of up to 255 million ZIL.
* `--reward-address <REWARD_ADDRESS>`: Specifies the address to receive rewards. You can generate a new wallet address to receive the rewards.
* `--signing-address <SIGNING_ADDRESS>`: Specifies the address which signs cross-chain events.

Expand Down Expand Up @@ -68,7 +68,7 @@ $ echo '{"secret_key":"96252e38af375be21d9eb30a6b88abc3836acecaeb2240731fb42e029
--private-key 96252e38af375be21d9eb30a6b88abc3836acecaeb2240731fb42e0299e14419 \
--reward-address 0xe29a3e99a6997B1571DA24d6517e7b3acaFB5d9e \
--signing-address 0x3946f9872247af2eb4fe44c81c463e801925b8d4 \
--amount 100 \
--amount 10 \
--public-key 825124961d51c99816848875fa505b75f2e62e69937fe9bfa5fa97711845abd667f05bdc3756f7dba6b7e9e0467a3804 \
--deposit-auth-signature b4770471f1b6b798b3a5cf19b6f574724777f2fbf7b7f520e75fc8461cafcfd84114316fe2aeaf35b52b9ca519310f8c0bf5cd941426e4a78cc7e10c6da80f245a9ddadc42de3f8a35db42d633b2b03847b33883f702eb13c332988d34d68d90
```
Expand All @@ -84,14 +84,14 @@ z2 deposit-top-up \
--public-key <PUBLIC_KEY>
--amount <AMOUNT>

Usage: z2 deposit-top-up --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET> --public-key <BLS_PUBLIC_KEY> --amount <AMOUNT_IN_ZIL>
Usage: z2 deposit-top-up --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET> --public-key <BLS_PUBLIC_KEY> --amount <AMOUNT_IN_MILLION_OF_ZIL>
```

## Parameters
* `--chain <CHAIN_NAME>`: The name of the chain. Possible values are zq2-devnet, zq2-prototestnet, zq2-protomainnet, zq2-testnet, zq2-mainnet.
* `--private-key <PRIVATE_KEY_OF_WALLET>`: The private key of the wallet.
* `--public-key <BLS_PUBLIC_KEY>`: The BLS public key of the validator node.
* `--amount <AMOUNT_IN_MILLION_ZIL>`: The amount in ZIL to top up.
* `--amount <AMOUNT_IN_MILLION_OF_ZIL>`: The amount in millions of ZILs to top up.

#### Sample run
```bash
Expand All @@ -112,14 +112,14 @@ z2 unstake \
--public-key <PUBLIC_KEY>
--amount <AMOUNT>

Usage: z2 deposit-top-up --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET> --public-key <BLS_PUBLIC_KEY> --amount <AMOUNT_IN_ZIL>
Usage: z2 deposit-top-up --chain <CHAIN_NAME> --private-key <PRIVATE_KEY_OF_WALLET> --public-key <BLS_PUBLIC_KEY> --amount <AMOUNT_IN_MILLION_OF_ZIL>
```

## Parameters
* `--chain <CHAIN_NAME>`: The name of the chain. Possible values are zq2-devnet, zq2-prototestnet, zq2-protomainnet, zq2-testnet, zq2-mainnet.
* `--private-key <PRIVATE_KEY_OF_WALLET>`: The private key of the wallet.
* `--public-key <BLS_PUBLIC_KEY>`: The BLS public key of the validator node.
* `--amount <AMOUNT_IN_MILLION_ZIL>`: The amount in ZIL to unstake.
* `--amount <AMOUNT_IN_MILLION_OF_ZIL>`: The amount in millions of ZILs to unstake.

#### Sample run
```bash
Expand Down
108 changes: 94 additions & 14 deletions z2/src/bin/z2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,16 @@ enum DeployerCommands {
GetConfigFile(DeployerConfigArgs),
/// Generate in output the commands to deposit stake amount to all the validators
GetDepositCommands(DeployerActionsArgs),
/// Deposit the stake amounts to all the validators
/// Deposit stake amounts to the internal validators
Deposit(DeployerActionsArgs),
/// Top up stake to the internal validators
DepositTopUp(DeployerStakingArgs),
/// Unstake funds of the internal validators
Unstake(DeployerStakingArgs),
/// Withdraw unstaked funds to the internal validators
Withdraw(DeployerActionsArgs),
/// Show network stake information
Stakers(DeployerStakersArgs),
/// Run RPC calls over the internal network nodes
Rpc(DeployerRpcArgs),
/// Run command over SSH in the internal network nodes
Expand Down Expand Up @@ -184,6 +192,24 @@ pub struct DeployerActionsArgs {
select: bool,
}

#[derive(Args, Debug)]
pub struct DeployerStakingArgs {
/// The network deployer config file
config_file: Option<String>,
/// Enable nodes selection
#[clap(long)]
select: bool,
/// Specify the amount in millions
#[clap(long)]
amount: u8,
}

#[derive(Args, Debug)]
pub struct DeployerStakersArgs {
/// The network deployer config file
config_file: Option<String>,
}

#[derive(Args, Debug)]
pub struct DeployerMonitorArgs {
/// The metric to display. Default: block-number
Expand Down Expand Up @@ -506,7 +532,7 @@ struct DepositStruct {
/// Specify the Validator deposit signature
#[clap(long)]
deposit_auth_signature: String,
/// Specify the stake amount you want provide
/// Specify the stake amount in millions you want provide
#[clap(long, short)]
amount: u8,
/// Specify the staking reward address
Expand All @@ -528,7 +554,7 @@ struct DepositTopUpStruct {
/// Specify the Validator Public Key
#[clap(long)]
public_key: String,
/// Specify the stake amount you want provide
/// Specify the stake amount in millions you want provide
#[clap(long, short)]
amount: u8,
}
Expand All @@ -538,13 +564,13 @@ struct UnstakeStruct {
/// Specify the ZQ2 deposit chain
#[clap(long = "chain")]
chain_name: chain::Chain,
/// Specify the private_key to fund the deposit
/// Specify the private_key that submitted the deposit transaction
#[clap(long, short)]
private_key: String,
/// Specify the Validator Public Key
#[clap(long)]
public_key: String,
/// Specify the stake amount you want provide
/// Specify the amount in millions you want to unstake
#[clap(long, short)]
amount: u8,
}
Expand All @@ -554,7 +580,7 @@ struct WithdrawStruct {
/// Specify the ZQ2 deposit chain
#[clap(long = "chain")]
chain_name: chain::Chain,
/// Specify the private_key to fund the deposit
/// Specify the private_key that submitted the deposit transaction
#[clap(long, short)]
private_key: String,
/// Specify the Validator Public Key
Expand Down Expand Up @@ -912,6 +938,19 @@ async fn main() -> Result<()> {
})?;
Ok(())
}
DeployerCommands::Stakers(ref arg) => {
let config_file = arg.config_file.clone().ok_or_else(|| {
anyhow::anyhow!(
"Provide a configuration file. [--config-file] mandatory argument"
)
})?;
plumbing::run_deployer_stakers(&config_file)
.await
.map_err(|err| {
anyhow::anyhow!("Failed to run deployer stakers command: {}", err)
})?;
Ok(())
}
DeployerCommands::Deposit(ref arg) => {
let config_file = arg.config_file.clone().ok_or_else(|| {
anyhow::anyhow!(
Expand All @@ -925,6 +964,45 @@ async fn main() -> Result<()> {
})?;
Ok(())
}
DeployerCommands::DepositTopUp(ref arg) => {
let config_file = arg.config_file.clone().ok_or_else(|| {
anyhow::anyhow!(
"Provide a configuration file. [--config-file] mandatory argument"
)
})?;
plumbing::run_deployer_deposit_top_up(&config_file, arg.select, arg.amount)
.await
.map_err(|err| {
anyhow::anyhow!("Failed to run deployer deposit-top-up command: {}", err)
})?;
Ok(())
}
DeployerCommands::Unstake(ref arg) => {
let config_file = arg.config_file.clone().ok_or_else(|| {
anyhow::anyhow!(
"Provide a configuration file. [--config-file] mandatory argument"
)
})?;
plumbing::run_deployer_unstake(&config_file, arg.select, arg.amount)
.await
.map_err(|err| {
anyhow::anyhow!("Failed to run deployer unstake command: {}", err)
})?;
Ok(())
}
DeployerCommands::Withdraw(ref arg) => {
let config_file = arg.config_file.clone().ok_or_else(|| {
anyhow::anyhow!(
"Provide a configuration file. [--config-file] mandatory argument"
)
})?;
plumbing::run_deployer_withdraw(&config_file, arg.select)
.await
.map_err(|err| {
anyhow::anyhow!("Failed to run deployer withdraw command: {}", err)
})?;
Ok(())
}
DeployerCommands::Rpc(ref args) => {
plumbing::run_deployer_rpc(
&args.method,
Expand Down Expand Up @@ -1137,7 +1215,7 @@ async fn main() -> Result<()> {
.unwrap(),
BlsSignature::from_string(&args.deposit_auth_signature).unwrap(),
)?;
let client_config = validators::ClientConfig::new(
let signer_client = validators::SignerClient::new(
&args.chain_name.get_api_endpoint()?,
&args.private_key,
)?;
Expand All @@ -1146,37 +1224,39 @@ async fn main() -> Result<()> {
&args.reward_address,
&args.signing_address,
)?;
validators::deposit(&node, &client_config, &deposit_params).await
signer_client.deposit(&node, &deposit_params).await
}
Commands::DepositTopUp(ref args) => {
let bls_public_key =
NodePublicKey::from_bytes(hex::decode(&args.public_key).unwrap().as_slice())
.unwrap();
let client_config = validators::ClientConfig::new(
let signer_client = validators::SignerClient::new(
&args.chain_name.get_api_endpoint()?,
&args.private_key,
)?;
validators::deposit_top_up(&client_config, &bls_public_key, args.amount).await
signer_client
.deposit_top_up(&bls_public_key, args.amount)
.await
}
Commands::Unstake(ref args) => {
let bls_public_key =
NodePublicKey::from_bytes(hex::decode(&args.public_key).unwrap().as_slice())
.unwrap();
let client_config = validators::ClientConfig::new(
let signer_client = validators::SignerClient::new(
&args.chain_name.get_api_endpoint()?,
&args.private_key,
)?;
validators::unstake(&client_config, &bls_public_key, args.amount).await
signer_client.unstake(&bls_public_key, args.amount).await
}
Commands::Withdraw(ref args) => {
let bls_public_key =
NodePublicKey::from_bytes(hex::decode(&args.public_key).unwrap().as_slice())
.unwrap();
let client_config = validators::ClientConfig::new(
let signer_client = validators::SignerClient::new(
&args.chain_name.get_api_endpoint()?,
&args.private_key,
)?;
validators::withdraw(&client_config, &bls_public_key, args.count).await
signer_client.withdraw(&bls_public_key, args.count).await
}
Commands::Nodes(ref args) => {
let spec = Composition::parse(&args.nodes)?;
Expand Down
13 changes: 7 additions & 6 deletions z2/src/chain/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ use clap::ValueEnum;
use cliclack::MultiProgress;
use colored::Colorize;
use ethers::{middleware::Middleware, prelude::TransactionRequest, types::Bytes};
use primitive_types::H160;
use primitive_types::{H160, U256};
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use tempfile::NamedTempFile;
use tera::{Context, Tera};
use tokio::{fs::File, io::AsyncWriteExt};
use zilliqa::exec::BLESSED_TRANSACTIONS;
use primitive_types::U256;

use super::instance::ChainInstance;
use crate::{address::EthereumAddress, chain::Chain, secret::Secret, validators::ClientConfig};
use crate::{address::EthereumAddress, chain::Chain, secret::Secret, validators::SignerClient};

#[derive(Clone, Debug, Default, ValueEnum, PartialEq)]
pub enum NodePort {
Expand Down Expand Up @@ -1421,7 +1420,8 @@ impl ChainNode {
}

pub async fn post_install(&self) -> Result<()> {
if self.chain.name().contains("prototestnet") || self.chain.name().contains("protomainnet") {
if self.chain.name().contains("prototestnet") || self.chain.name().contains("protomainnet")
{
log::info!("Skipping post install actions for chain: {}", self.name());
return Ok(());
}
Expand All @@ -1440,9 +1440,10 @@ impl ChainNode {

let genesis_address = EthereumAddress::from_private_key(&genesis_private_key)?;

let client_config = ClientConfig::new(&url, &genesis_private_key)?;
let client = SignerClient::new(&url, &genesis_private_key)?
.get_signer()
.await?;

let client = crate::validators::build_client(&client_config).await?;
let gas_price = client.get_gas_price().await?;

let mut start_nonce = client
Expand Down
8 changes: 2 additions & 6 deletions z2/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ pub async fn convert_persistence(
.get_tx_blocks_aux("MaxTxBlockNumber")?
.unwrap_or_default();

let current_block = zq2_db.get_finalized_view()?;
let current_block = zq2_db.get_finalized_view()?.unwrap_or(1);

let progress = ProgressBar::new(max_block)
.with_style(style.clone())
Expand All @@ -454,11 +454,7 @@ pub async fn convert_persistence(
.into_iter()
.progress_with(progress)
.skip_while(|(n, _)| {
if current_block.is_some() {
false
} else {
*n <= current_block.unwrap()
}
*n <= current_block
});

let mut parent_hash = Hash::ZERO;
Expand Down
Loading

0 comments on commit d0cdb94

Please sign in to comment.