From 53f77ee225d9e2fb7f3bab093dc46b58b43305ae Mon Sep 17 00:00:00 2001 From: Victor Gao Date: Thu, 28 Mar 2024 23:47:52 +0000 Subject: [PATCH] [release-builder] allow gas feature version to be overridden --- Cargo.lock | 1 + .../aptos-gas-schedule-updator/src/lib.rs | 15 +++-- .../tests/gen_tests.rs | 1 + aptos-move/aptos-release-builder/Cargo.toml | 1 + .../aptos-release-builder/data/release.yaml | 9 ++- .../src/components/mod.rs | 55 ++++++++++++++++--- 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb612b5c70121..86c0eb14febc1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3347,6 +3347,7 @@ dependencies = [ "aptos-build-info", "aptos-crypto", "aptos-framework", + "aptos-gas-schedule", "aptos-gas-schedule-updator", "aptos-genesis", "aptos-keygen", diff --git a/aptos-move/aptos-gas-schedule-updator/src/lib.rs b/aptos-move/aptos-gas-schedule-updator/src/lib.rs index fc42bd3943e73..6383cca98dc05 100644 --- a/aptos-move/aptos-gas-schedule-updator/src/lib.rs +++ b/aptos-move/aptos-gas-schedule-updator/src/lib.rs @@ -107,13 +107,16 @@ fn aptos_framework_path() -> PathBuf { pub struct GenArgs { #[clap(short, long)] pub output: Option, + + #[clap(short, long)] + pub gas_feature_version: Option, } /// 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), } } @@ -121,9 +124,13 @@ pub fn current_gas_schedule() -> GasScheduleV2 { 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(¤t_gas_schedule())?, + &generate_script(¤t_gas_schedule(feature_version))?, ); // TODO: use relative path here pack.add_local_dep("AptosFramework", &aptos_framework_path().to_string_lossy()); diff --git a/aptos-move/aptos-gas-schedule-updator/tests/gen_tests.rs b/aptos-move/aptos-gas-schedule-updator/tests/gen_tests.rs index e5f1974a38d10..d53b5538a380a 100644 --- a/aptos-move/aptos-gas-schedule-updator/tests/gen_tests.rs +++ b/aptos-move/aptos-gas-schedule-updator/tests/gen_tests.rs @@ -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(); diff --git a/aptos-move/aptos-release-builder/Cargo.toml b/aptos-move/aptos-release-builder/Cargo.toml index e8a54d54b782e..e596c44335d9c 100644 --- a/aptos-move/aptos-release-builder/Cargo.toml +++ b/aptos-move/aptos-release-builder/Cargo.toml @@ -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 } diff --git a/aptos-move/aptos-release-builder/data/release.yaml b/aptos-move/aptos-release-builder/data/release.yaml index 3d8b8f5794088..dc1121e69f81e 100644 --- a/aptos-move/aptos-release-builder/data/release.yaml +++ b/aptos-move/aptos-release-builder/data/release.yaml @@ -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" @@ -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" diff --git a/aptos-move/aptos-release-builder/src/components/mod.rs b/aptos-move/aptos-release-builder/src/components/mod.rs index e7e2ef5c08ac2..5f6dcffe86c9d 100644 --- a/aptos-move/aptos-release-builder/src/components/mod.rs +++ b/aptos-move/aptos-release-builder/src/components/mod.rs @@ -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::{ @@ -96,6 +97,12 @@ pub enum ExecutionMode { RootSigner, } +#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] +pub struct GasOverrideConfig { + feature_version: Option, + overrides: Option>, +} + #[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)] pub struct GasOverride { name: String, @@ -107,7 +114,7 @@ pub enum ReleaseEntry { Framework(FrameworkReleaseConfig), CustomGas(GasScheduleV2), DefaultGas, - DefaultGasWithOverride(Vec), + DefaultGasWithOverride(GasOverrideConfig), Version(Version), FeatureFlag(Features), Consensus(OnChainConsensusConfig), @@ -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::(client, &gas_schedule)? { result.append(&mut gas::generate_gas_upgrade_proposal( &gas_schedule, @@ -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::(client, &gas_schedule)? { result.append(&mut gas::generate_gas_upgrade_proposal( &gas_schedule, @@ -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"); } }, @@ -369,8 +403,11 @@ impl ReleaseEntry { } } -fn gas_override_default(gas_overrides: &[GasOverride]) -> Result { - let mut gas_schedule = aptos_gas_schedule_updator::current_gas_schedule(); +fn gas_override_default( + feature_version: u64, + gas_overrides: &[GasOverride], +) -> Result { + 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 {