Skip to content

Commit

Permalink
[release-builder] allow gas feature version to be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
vgao1996 committed Mar 29, 2024
1 parent 785188c commit 53f77ee
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 11 additions & 4 deletions aptos-move/aptos-gas-schedule-updator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,30 @@ fn aptos_framework_path() -> PathBuf {
pub struct GenArgs {
#[clap(short, long)]
pub output: Option<String>,

#[clap(short, long)]
pub gas_feature_version: Option<u64>,
}

/// Constructs the current gas schedule in on-chain format.
pub fn current_gas_schedule() -> GasScheduleV2 {
pub fn current_gas_schedule(feature_version: u64) -> GasScheduleV2 {
GasScheduleV2 {
feature_version: LATEST_GAS_FEATURE_VERSION,
entries: AptosGasParameters::initial().to_on_chain_gas_schedule(LATEST_GAS_FEATURE_VERSION),
feature_version,
entries: AptosGasParameters::initial().to_on_chain_gas_schedule(feature_version),
}
}

/// Entrypoint for the update proposal generation tool.
pub fn generate_update_proposal(args: &GenArgs) -> Result<()> {
let mut pack = PackageBuilder::new("GasScheduleUpdate");

let feature_version = args
.gas_feature_version
.unwrap_or(LATEST_GAS_FEATURE_VERSION);

pack.add_source(
"update_gas_schedule.move",
&generate_script(&current_gas_schedule())?,
&generate_script(&current_gas_schedule(feature_version))?,
);
// TODO: use relative path here
pack.add_local_dep("AptosFramework", &aptos_framework_path().to_string_lossy());
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-gas-schedule-updator/tests/gen_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fn can_generate_and_build_update_proposal() {
let output_dir = tempfile::tempdir().unwrap();

generate_update_proposal(&GenArgs {
gas_feature_version: None,
output: Some(output_dir.path().to_string_lossy().to_string()),
})
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-release-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aptos-api-types = { workspace = true }
aptos-build-info = { workspace = true }
aptos-crypto = { workspace = true }
aptos-framework = { workspace = true }
aptos-gas-schedule = { workspace = true }
aptos-gas-schedule-updator = { workspace = true }
aptos-genesis = { workspace = true }
aptos-keygen = { workspace = true }
Expand Down
9 changes: 6 additions & 3 deletions aptos-move/aptos-release-builder/data/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ proposals:
execution_mode: MultiStep
update_sequence:
- DefaultGasWithOverride:
- name: "txn.max_execution_gas"
value: 3676000000
feature_version: 13
overrides:
- name: "txn.max_execution_gas"
value: 3676000000
- name: step_2_upgrade_framework
metadata:
title: "Multi-step proposal to upgrade mainnet framework to v1.10"
Expand All @@ -20,7 +22,8 @@ proposals:
- Framework:
bytecode_version: 6
git_hash: ~
- DefaultGas
- DefaultGasWithOverride:
feature_version: 13
- name: step_3_storage_fee_for_state_bytes_refundable
metadata:
title: "AIP-65: Storage Fee for State Bytes refundable"
Expand Down
55 changes: 46 additions & 9 deletions aptos-move/aptos-release-builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use self::framework::FrameworkReleaseConfig;
use crate::{aptos_core_path, aptos_framework_path, components::feature_flags::Features};
use anyhow::{anyhow, bail, Context, Result};
use aptos::governance::GenerateExecutionHash;
use aptos_gas_schedule::LATEST_GAS_FEATURE_VERSION;
use aptos_rest_client::Client;
use aptos_temppath::TempPath;
use aptos_types::{
Expand Down Expand Up @@ -96,6 +97,12 @@ pub enum ExecutionMode {
RootSigner,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct GasOverrideConfig {
feature_version: Option<u64>,
overrides: Option<Vec<GasOverride>>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct GasOverride {
name: String,
Expand All @@ -107,7 +114,7 @@ pub enum ReleaseEntry {
Framework(FrameworkReleaseConfig),
CustomGas(GasScheduleV2),
DefaultGas,
DefaultGasWithOverride(Vec<GasOverride>),
DefaultGasWithOverride(GasOverrideConfig),
Version(Version),
FeatureFlag(Features),
Consensus(OnChainConsensusConfig),
Expand Down Expand Up @@ -155,7 +162,8 @@ impl ReleaseEntry {
}
},
ReleaseEntry::DefaultGas => {
let gas_schedule = aptos_gas_schedule_updator::current_gas_schedule();
let gas_schedule =
aptos_gas_schedule_updator::current_gas_schedule(LATEST_GAS_FEATURE_VERSION);
if !fetch_and_equals::<GasScheduleV2>(client, &gas_schedule)? {
result.append(&mut gas::generate_gas_upgrade_proposal(
&gas_schedule,
Expand All @@ -168,8 +176,18 @@ impl ReleaseEntry {
)?);
}
},
ReleaseEntry::DefaultGasWithOverride(gas_overrides) => {
let gas_schedule = gas_override_default(gas_overrides)?;
ReleaseEntry::DefaultGasWithOverride(GasOverrideConfig {
feature_version,
overrides,
}) => {
let feature_version = feature_version.unwrap_or(LATEST_GAS_FEATURE_VERSION);
let gas_schedule = gas_override_default(
feature_version,
overrides
.as_ref()
.map(|overrides| overrides.as_slice())
.unwrap_or(&[]),
)?;
if !fetch_and_equals::<GasScheduleV2>(client, &gas_schedule)? {
result.append(&mut gas::generate_gas_upgrade_proposal(
&gas_schedule,
Expand Down Expand Up @@ -309,13 +327,29 @@ impl ReleaseEntry {
ReleaseEntry::DefaultGas => {
if !fetch_and_equals(
client_opt,
&aptos_gas_schedule_updator::current_gas_schedule(),
&aptos_gas_schedule_updator::current_gas_schedule(LATEST_GAS_FEATURE_VERSION),
)? {
bail!("Gas schedule config mismatch: Expected Default");
}
},
ReleaseEntry::DefaultGasWithOverride(gas_overrides) => {
if !fetch_and_equals(client_opt, &gas_override_default(gas_overrides)?)? {
ReleaseEntry::DefaultGasWithOverride(config) => {
let GasOverrideConfig {
overrides,
feature_version,
} = config;

let feature_version = feature_version.unwrap_or(LATEST_GAS_FEATURE_VERSION);

if !fetch_and_equals(
client_opt,
&gas_override_default(
feature_version,
overrides
.as_ref()
.map(|overrides| overrides.as_slice())
.unwrap_or(&[]),
)?,
)? {
bail!("Gas schedule config mismatch: Expected Default");
}
},
Expand Down Expand Up @@ -369,8 +403,11 @@ impl ReleaseEntry {
}
}

fn gas_override_default(gas_overrides: &[GasOverride]) -> Result<GasScheduleV2> {
let mut gas_schedule = aptos_gas_schedule_updator::current_gas_schedule();
fn gas_override_default(
feature_version: u64,
gas_overrides: &[GasOverride],
) -> Result<GasScheduleV2> {
let mut gas_schedule = aptos_gas_schedule_updator::current_gas_schedule(feature_version);
for gas_override in gas_overrides {
let mut found = false;
for (name, value) in &mut gas_schedule.entries {
Expand Down

0 comments on commit 53f77ee

Please sign in to comment.