From ed6c6d1134000e0c15edc46e05cb5013e41f3e69 Mon Sep 17 00:00:00 2001 From: Greg Date: Fri, 17 Jun 2022 14:05:50 -0400 Subject: [PATCH] [aptos-genesis] Add extra configuration fields to genesis tooling Closes: #1393 --- crates/aptos-genesis/src/builder.rs | 7 +++++++ crates/aptos-genesis/src/config.rs | 23 +++++++++++++-------- crates/aptos-genesis/src/lib.rs | 32 +++++++++++++++++++++++++++++ crates/aptos/src/genesis/mod.rs | 10 +++++++-- crates/aptos/src/genesis/tests.rs | 9 ++++++-- 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/crates/aptos-genesis/src/builder.rs b/crates/aptos-genesis/src/builder.rs index d20e211b815f3..82f2f01df61fa 100644 --- a/crates/aptos-genesis/src/builder.rs +++ b/crates/aptos-genesis/src/builder.rs @@ -505,6 +505,13 @@ impl Builder { configs, self.move_modules.clone(), self.min_price_per_gas_unit, + false, + 0, + u64::MAX, + 86400, // 1 day + 31536000, // 1 year + 0, + 0, )?; let waypoint = genesis_info.generate_waypoint()?; let genesis = genesis_info.get_genesis(); diff --git a/crates/aptos-genesis/src/config.rs b/crates/aptos-genesis/src/config.rs index 29be59ee919d9..c1e2156b3078f 100644 --- a/crates/aptos-genesis/src/config.rs +++ b/crates/aptos-genesis/src/config.rs @@ -11,7 +11,6 @@ use aptos_types::{ }; use serde::{Deserialize, Serialize}; use std::{ - collections::HashMap, convert::TryFrom, fs::File, io::Read, @@ -32,15 +31,23 @@ pub struct Layout { pub users: Vec, /// ChainId for the target network pub chain_id: ChainId, - /// Whether to allow validators to join post genesis + /// Whether to allow new validators to join the set after genesis #[serde(default)] pub allow_new_validators: bool, - /// Initial lockup period for genesis validators - #[serde(default)] - pub initial_lockup_period_duration_secs: u64, - /// Initial balances for the target network - #[serde(default)] - pub initial_balances: HashMap, + /// Minimum stake to be in the validator set + pub min_stake: u64, + /// Maximum stake to be in the validator set + pub max_stake: u64, + /// Minimum number of seconds to lockup staked coins + pub min_lockup_duration_secs: u64, + /// Maximum number of seconds to lockup staked coins + pub max_lockup_duration_secs: u64, + /// Duration of an epoch + pub epoch_duration_secs: u64, + /// Initial timestamp for genesis validators to be locked up + pub initial_lockup_timestamp: u64, + /// Min price per gas unit + pub min_price_per_gas_unit: u64, } impl Layout { diff --git a/crates/aptos-genesis/src/lib.rs b/crates/aptos-genesis/src/lib.rs index 9c89d3c55284d..5ede03fcfaf6d 100644 --- a/crates/aptos-genesis/src/lib.rs +++ b/crates/aptos-genesis/src/lib.rs @@ -24,12 +24,30 @@ use vm_genesis::Validator; /// Holder object for all pieces needed to generate a genesis transaction #[derive(Clone)] pub struct GenesisInfo { + /// ChainId for identifying the network chain_id: ChainId, + /// Key used for minting tokens root_key: Ed25519PublicKey, + /// Set of configurations for validators on the network validators: Vec, /// Compiled bytecode of framework modules modules: Vec>, min_price_per_gas_unit: u64, + /// Whether to allow new validators to join the set after genesis + pub allow_new_validators: bool, + /// Minimum stake to be in the validator set + pub min_stake: u64, + /// Maximum stake to be in the validator set + pub max_stake: u64, + /// Minimum number of seconds to lockup staked coins + pub min_lockup_duration_secs: u64, + /// Maximum number of seconds to lockup staked coins + pub max_lockup_duration_secs: u64, + /// Duration of an epoch + pub epoch_duration_secs: u64, + /// Initial timestamp for genesis validators to be locked up + pub initial_lockup_timestamp: u64, + /// The genesis transaction, once it's been generated genesis: Option, } @@ -40,6 +58,13 @@ impl GenesisInfo { configs: Vec, modules: Vec>, min_price_per_gas_unit: u64, + allow_new_validators: bool, + min_stake: u64, + max_stake: u64, + min_lockup_duration_secs: u64, + max_lockup_duration_secs: u64, + epoch_duration_secs: u64, + initial_lockup_timestamp: u64, ) -> anyhow::Result { let mut validators = Vec::new(); @@ -53,6 +78,13 @@ impl GenesisInfo { validators, modules, min_price_per_gas_unit, + allow_new_validators, + min_stake, + max_stake, + min_lockup_duration_secs, + max_lockup_duration_secs, + epoch_duration_secs, + initial_lockup_timestamp, genesis: None, }) } diff --git a/crates/aptos/src/genesis/mod.rs b/crates/aptos/src/genesis/mod.rs index 55514be3f25cb..472a4844b498f 100644 --- a/crates/aptos/src/genesis/mod.rs +++ b/crates/aptos/src/genesis/mod.rs @@ -25,7 +25,6 @@ use clap::Parser; use serde::{Deserialize, Serialize}; use std::{path::PathBuf, str::FromStr}; -const MIN_PRICE_PER_GAS_UNIT: u64 = 1; const WAYPOINT_FILE: &str = "waypoint.txt"; const GENESIS_FILE: &str = "genesis.blob"; @@ -133,7 +132,14 @@ pub fn fetch_genesis_info(git_options: GitOptions) -> CliTypedResult