Skip to content

Commit

Permalink
[aptos-genesis] Add extra configuration fields to genesis tooling
Browse files Browse the repository at this point in the history
Closes: #1393
  • Loading branch information
gregnazario authored and aptos-bot committed Jun 18, 2022
1 parent 93a2cd0 commit ed6c6d1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 12 deletions.
7 changes: 7 additions & 0 deletions crates/aptos-genesis/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 15 additions & 8 deletions crates/aptos-genesis/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use aptos_types::{
};
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
convert::TryFrom,
fs::File,
io::Read,
Expand All @@ -32,15 +31,23 @@ pub struct Layout {
pub users: Vec<String>,
/// 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<AccountAddress, u64>,
/// 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 {
Expand Down
32 changes: 32 additions & 0 deletions crates/aptos-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Validator>,
/// Compiled bytecode of framework modules
modules: Vec<Vec<u8>>,
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<Transaction>,
}

Expand All @@ -40,6 +58,13 @@ impl GenesisInfo {
configs: Vec<ValidatorConfiguration>,
modules: Vec<Vec<u8>>,
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<GenesisInfo> {
let mut validators = Vec::new();

Expand All @@ -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,
})
}
Expand Down
10 changes: 8 additions & 2 deletions crates/aptos/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -133,7 +132,14 @@ pub fn fetch_genesis_info(git_options: GitOptions) -> CliTypedResult<GenesisInfo
layout.root_key,
validators,
modules,
MIN_PRICE_PER_GAS_UNIT,
layout.min_price_per_gas_unit,
layout.allow_new_validators,
layout.min_stake,
layout.max_stake,
layout.min_lockup_duration_secs,
layout.max_lockup_duration_secs,
layout.epoch_duration_secs,
layout.initial_lockup_timestamp,
)?)
}

Expand Down
9 changes: 7 additions & 2 deletions crates/aptos/src/genesis/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,13 @@ fn create_layout_file(
users,
chain_id,
allow_new_validators: false,
initial_lockup_period_duration_secs: 0,
initial_balances: Default::default(),
min_stake: 0,
max_stake: u64::MAX,
min_lockup_duration_secs: 0,
max_lockup_duration_secs: 31536000, // One Year
epoch_duration_secs: 86400, // One Day
initial_lockup_timestamp: 0,
min_price_per_gas_unit: 1,
};
let file = TempPath::new();
file.create_as_file().unwrap();
Expand Down

0 comments on commit ed6c6d1

Please sign in to comment.