Skip to content

Commit

Permalink
[release-builder] local simulation of governance proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
vgao1996 committed Jul 17, 2024
1 parent d98b854 commit b09f03d
Show file tree
Hide file tree
Showing 9 changed files with 679 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions aptos-move/aptos-release-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ aptos-gas-schedule-updator = { workspace = true }
aptos-genesis = { workspace = true }
aptos-infallible = { workspace = true }
aptos-keygen = { workspace = true }
aptos-language-e2e-tests = { workspace = true }
aptos-move-debugger = { workspace = true }
aptos-rest-client = { workspace = true }
aptos-temppath = { workspace = true }
aptos-types = { workspace = true }
aptos-vm = { workspace = true }
aptos-vm-logging = { workspace = true }
bcs = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
git2 = { workspace = true }
handlebars = { workspace = true }
hex = { workspace = true }
move-binary-format = { workspace = true }
move-bytecode-verifier = { workspace = true }
move-core-types = { workspace = true }
move-model = { workspace = true }
move-vm-types = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
reqwest = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
3 changes: 0 additions & 3 deletions aptos-move/aptos-release-builder/data/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ proposals:
description: "This includes changes in https://github.com/aptos-labs/aptos-core/commits/aptos-release-v1.13"
execution_mode: MultiStep
update_sequence:
- Framework:
bytecode_version: 6
git_hash: ~
- Gas:
new: current
- FeatureFlag:
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-release-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

pub mod components;
pub mod simulate;
mod utils;
pub mod validate;

Expand Down
60 changes: 60 additions & 0 deletions aptos-move/aptos-release-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use aptos_gas_schedule::LATEST_GAS_FEATURE_VERSION;
use aptos_release_builder::{
components::fetch_config,
initialize_aptos_core_path,
simulate::simulate_multistep_proposal,
validate::{DEFAULT_RESOLUTION_TIME, FAST_RESOLUTION_TIME},
};
use aptos_types::{
Expand All @@ -17,6 +18,7 @@ use aptos_types::{
};
use clap::{Parser, Subcommand};
use std::{path::PathBuf, str::FromStr};
use url::Url;

#[derive(Parser)]
pub struct Argument {
Expand All @@ -26,6 +28,43 @@ pub struct Argument {
aptos_core_path: Option<PathBuf>,
}

// TODO: unify with ReplayNetworkSelection in the `aptos` crate.
#[derive(Clone, Debug)]
pub enum NetworkSelection {
Mainnet,
Testnet,
Devnet,
RestEndpoint(String),
}

impl FromStr for NetworkSelection {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, anyhow::Error> {
Ok(match s {
"mainnet" => Self::Mainnet,
"testnet" => Self::Testnet,
"devnet" => Self::Devnet,
_ => Self::RestEndpoint(s.to_owned()),
})
}
}

impl NetworkSelection {
fn to_url(&self) -> anyhow::Result<Url> {
use NetworkSelection::*;

let s = match &self {
Mainnet => "https://fullnode.mainnet.aptoslabs.com",
Testnet => "https://fullnode.testnet.aptoslabs.com",
Devnet => "https://fullnode.devnet.aptoslabs.com",
RestEndpoint(url) => url,
};

Ok(Url::parse(s)?)
}
}

#[derive(Subcommand, Debug)]
pub enum Commands {
/// Generate sets of governance proposals based on the release_config file passed in
Expand All @@ -35,6 +74,20 @@ pub enum Commands {
#[clap(short, long)]
output_dir: PathBuf,
},
/// Simulate a multi-step proposal on the specified network, using its current states.
/// The simulation will execute the governance scripts, as if the proposal is already
/// approved.
SimulateMultiStepProposal {
/// Path to the directory storing the scripts (steps) belonging to the proposal.
#[clap(short, long)]
proposal_dir: PathBuf,

/// The network to simulate on.
///
/// Possible values: devnet, testnet, mainnet, <url to rest endpoint>
#[clap(long)]
network: NetworkSelection,
},
/// Generate sets of governance proposals with default release config.
WriteDefault {
#[clap(short, long)]
Expand Down Expand Up @@ -134,6 +187,13 @@ async fn main() -> anyhow::Result<()> {
.with_context(|| "Failed to generate release proposal scripts".to_string())?;
Ok(())
},
Commands::SimulateMultiStepProposal {
network,
proposal_dir,
} => {
simulate_multistep_proposal(network.to_url()?, &proposal_dir).await?;
Ok(())
},
Commands::WriteDefault { output_path } => {
aptos_release_builder::ReleaseConfig::default().save_config(output_path.as_path())
},
Expand Down
Loading

0 comments on commit b09f03d

Please sign in to comment.