Skip to content

Commit

Permalink
[aptos-release-tooling] Add an option to compare release binary with …
Browse files Browse the repository at this point in the history
…on chain configs
  • Loading branch information
runtian-zhou committed Dec 7, 2022
1 parent 1118252 commit e7fa88e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions aptos-move/aptos-release-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ rust-version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
aptos-gas = { workspace = true }
aptos-rest-client = { workspace = true }
aptos-temppath = { workspace = true }
aptos-types = { workspace = true }
bcs = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
move-core-types = { workspace = true }
move-model = { workspace = true }
serde = { workspace = true }
serde_yaml = { workspace = true }
tempfile = { workspace = true }
url = { workspace = true }

[[bin]]
name = "aptos-release-builder"
Expand Down
14 changes: 13 additions & 1 deletion aptos-move/aptos-release-builder/src/components/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::utils::*;
use anyhow::Result;
use aptos_types::on_chain_config::FeatureFlag as AFeatureFlag;
use aptos_types::on_chain_config::{FeatureFlag as AFeatureFlag, Features as AFeatures};
use move_model::{code_writer::CodeWriter, emit, emitln, model::Loc};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -98,3 +98,15 @@ impl From<AFeatureFlag> for FeatureFlag {
}
}
}

impl Features {
pub(crate) fn has_modified(&self, on_chain_features: &AFeatures) -> bool {
self.enabled
.iter()
.any(|f| !on_chain_features.is_enabled(AFeatureFlag::from(f.clone())))
|| self
.disabled
.iter()
.any(|f| on_chain_features.is_enabled(AFeatureFlag::from(f.clone())))
}
}
91 changes: 74 additions & 17 deletions aptos-move/aptos-release-builder/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

use crate::components::feature_flags::Features;
use anyhow::{anyhow, Result};
use aptos_types::on_chain_config::{GasScheduleV2, OnChainConsensusConfig, Version};
use aptos_rest_client::Client;
use aptos_types::{
account_config::CORE_CODE_ADDRESS,
on_chain_config::{GasScheduleV2, OnChainConfig, OnChainConsensusConfig, Version},
};
use futures::executor::block_on;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Write},
path::Path,
};
use url::Url;

pub mod consensus_config;
pub mod feature_flags;
Expand All @@ -20,6 +26,7 @@ pub mod version;
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq)]
pub struct ReleaseConfig {
pub testnet: bool,
pub remote_endpoint: Option<Url>,
pub framework_release: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gas_schedule: Option<GasScheduleV2>,
Expand All @@ -31,41 +38,90 @@ pub struct ReleaseConfig {
pub consensus_config: Option<OnChainConsensusConfig>,
}

fn fetch_and_compare<T: OnChainConfig + PartialEq>(
client: &Option<Client>,
expected: &T,
) -> Result<bool> {
match client {
Some(client) => Ok(block_on(async {
client
.get_account_resource_bcs::<T>(
CORE_CODE_ADDRESS,
format!(
"{:?}::{:?}::{:?}",
T::ADDRESS,
T::MODULE_IDENTIFIER,
T::TYPE_IDENTIFIER
)
.as_str(),
)
.await
})?
.inner()
== expected),
None => Ok(false),
}
}

impl ReleaseConfig {
pub fn generate_release_proposal_scripts(&self, base_path: &Path) -> Result<()> {
let mut result = vec![];
let client = self
.remote_endpoint
.as_ref()
.map(|url| Client::new(url.clone()));

// First create framework releases
if self.framework_release {
result.append(&mut framework::generate_upgrade_proposals(self.testnet)?);
}

if let Some(gas_schedule) = &self.gas_schedule {
result.append(&mut gas::generate_gas_upgrade_proposal(
gas_schedule,
self.testnet,
)?);
if !fetch_and_compare::<GasScheduleV2>(&client, &gas_schedule)? {
result.append(&mut gas::generate_gas_upgrade_proposal(
gas_schedule,
self.testnet,
)?);
}
}

if let Some(version) = &self.version {
result.append(&mut version::generate_version_upgrade_proposal(
version,
self.testnet,
)?);
if !fetch_and_compare::<Version>(&client, &version)? {
result.append(&mut version::generate_version_upgrade_proposal(
version,
self.testnet,
)?);
}
}

if let Some(feature_flags) = &self.feature_flags {
result.append(&mut feature_flags::generate_feature_upgrade_proposal(
feature_flags,
self.testnet,
)?);
let mut needs_update = false;
if let Some(client) = &client {
let features = block_on(async {
client
.get_account_resource_bcs::<aptos_types::on_chain_config::Features>(
CORE_CODE_ADDRESS,
"0x1::features::Features",
)
.await
})?;
needs_update = feature_flags.has_modified(features.inner());
}
if needs_update {
result.append(&mut feature_flags::generate_feature_upgrade_proposal(
feature_flags,
self.testnet,
)?);
}
}

if let Some(consensus_config) = &self.consensus_config {
result.append(&mut consensus_config::generate_consensus_upgrade_proposal(
consensus_config,
self.testnet,
)?);
if !fetch_and_compare::<OnChainConsensusConfig>(&client, consensus_config)? {
result.append(&mut consensus_config::generate_consensus_upgrade_proposal(
consensus_config,
self.testnet,
)?);
}
}

for (idx, (script_name, script)) in result.into_iter().enumerate() {
Expand Down Expand Up @@ -127,6 +183,7 @@ impl Default for ReleaseConfig {
version: None,
feature_flags: None,
consensus_config: Some(OnChainConsensusConfig::default()),
remote_endpoint: None,
}
}
}

0 comments on commit e7fa88e

Please sign in to comment.