Skip to content

Commit

Permalink
[testsuite] upgrade compatibility smoke test & dynamic upgrade payloa…
Browse files Browse the repository at this point in the history
…ds (#195)
  • Loading branch information
0o-de-lally committed Mar 1, 2024
1 parent 013d687 commit 1e1a4ae
Show file tree
Hide file tree
Showing 31 changed files with 237 additions and 13,361 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Cargo.lock
**/build
**/doc
**/framework_upgrade
# upgrade fixtures
**/framework/src/upgrade_fixtures/fixtures/upgrade*

sccache.log

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

56 changes: 30 additions & 26 deletions framework/libra-framework/sources/code.move
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,29 @@ module diem_framework::code {
// If you need a specific functionality or program on the Layer 1,
// submit a pull request for module "Ascension" (for more info see: https://www.youtube.com/watch?v=jDwqPCAw_7k).

// If it is not a reserved address this must not be chain ID 1 (mainnet)
assert!(system_addresses::is_framework_reserved_address(signer::address_of(owner)) ||
testnet::is_testnet(),
ENOT_A_COMPUTE_PLATFORM
// Rise up this mornin',
// Smiled with the risin' sun,
// Three little birds
// Pitch by my doorstep
// Singin' sweet songs
// Of melodies pure and true,
// Sayin', ("This is my message to you-ou-ou:")
);
let addr = signer::address_of(owner);

// Disallow incompatible upgrade mode. Governance can decide later if
// this should be reconsidered.
// If it is not a reserved address this must not be chain ID 1 (mainnet)
assert!(
pack.upgrade_policy.policy > upgrade_policy_arbitrary().policy,
error::invalid_argument(EINCOMPATIBLE_POLICY_DISABLED),
is_policy_exempted_address(addr) ||
testnet::is_testnet(),
ENOT_A_COMPUTE_PLATFORM
// Rise up this mornin',
// Smiled with the risin' sun,
// Three little birds
// Pitch by my doorstep
// Singin' sweet songs
// Of melodies pure and true,
// Sayin', ("This is my message to you-ou-ou:")
);

let addr = signer::address_of(owner);
// // Disallow incompatible upgrade mode. Governance can decide later if
// // this should be reconsidered.
// assert!(
// pack.upgrade_policy.policy > upgrade_policy_arbitrary().policy,
// error::invalid_argument(EINCOMPATIBLE_POLICY_DISABLED),
// );

if (!exists<PackageRegistry>(addr)) {
move_to(owner, PackageRegistry { packages: vector::empty() })
};
Expand Down Expand Up @@ -232,13 +234,15 @@ module diem_framework::code {

/// Checks whether the given package is upgradable, and returns true if a compatibility check is needed.
fun check_upgradability(
old_pack: &PackageMetadata, new_pack: &PackageMetadata, new_modules:
old_pack: &PackageMetadata, _new_pack: &PackageMetadata, new_modules:
&vector<String>) {

assert!(old_pack.upgrade_policy.policy < upgrade_policy_immutable().policy,
error::invalid_argument(EUPGRADE_IMMUTABLE));
assert!(can_change_upgrade_policy_to(old_pack.upgrade_policy, new_pack.upgrade_policy),
error::invalid_argument(EUPGRADE_WEAKER_POLICY));
// system can change policy to stronger or weaker

// assert!(old_pack.upgrade_policy.policy < upgrade_policy_immutable().policy,
// error::invalid_argument(EUPGRADE_IMMUTABLE));
// assert!(can_change_upgrade_policy_to(old_pack.upgrade_policy, new_pack.upgrade_policy),
// error::invalid_argument(EUPGRADE_WEAKER_POLICY));
let old_modules = get_module_names(old_pack);
let i = 0;
while (i < vector::length(&old_modules)) {
Expand Down Expand Up @@ -295,10 +299,10 @@ module diem_framework::code {
if (dep_pack.name == dep.package_name) {
found = true;
// Check policy
assert!(
dep_pack.upgrade_policy.policy >= pack.upgrade_policy.policy,
error::invalid_argument(EDEP_WEAKER_POLICY)
);
// assert!(
// dep_pack.upgrade_policy.policy >= pack.upgrade_policy.policy,
// error::invalid_argument(EDEP_WEAKER_POLICY)
// );
if (dep_pack.upgrade_policy == upgrade_policy_arbitrary()) {
assert!(
dep.account == publish_address,
Expand Down
2 changes: 1 addition & 1 deletion framework/libra-framework/sources/code.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec diem_framework::code {
pragma verify = false;
}

spec check_upgradability(old_pack: &PackageMetadata, new_pack: &PackageMetadata, new_modules: &vector<String>) {
spec check_upgradability(old_pack: &PackageMetadata, _new_pack: &PackageMetadata, new_modules: &vector<String>) {
// TODO: Can't `aborts_if` in a loop.
pragma verify = false;
}
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
Binary file added framework/releases/mainnet.mrb
Binary file not shown.
8 changes: 7 additions & 1 deletion framework/src/builder/framework_generate_upgrade_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn make_framework_upgrade_artifacts(
proposal_move_package_dir: &Path,
framework_local_dir: &Path,
core_modules: &Option<Vec<String>>,
force_incompatible_upgrade: bool,
) -> Result<Vec<(String, String)>> {
let framework_git_hash =
&get_framework_git_head(framework_local_dir).unwrap_or("none".to_owned());
Expand Down Expand Up @@ -73,7 +74,12 @@ pub fn make_framework_upgrade_artifacts(
);

let compiled_core_module_pack = BuiltPackage::build(core_module_dir.clone(), options)?;
let release = ReleasePackage::new(compiled_core_module_pack)?;
let mut release = ReleasePackage::new(compiled_core_module_pack)?;

// DANGER: if 0x1 needs to force an incompatible upgrade
if force_incompatible_upgrade {
release.metadata.upgrade_policy.policy = 0;
}

// Each GOVERNANCE SCRIPT needs its own Move module directory even if temporarily, to compile the code for later submission (and getting the transaction hash, more below).

Expand Down
6 changes: 6 additions & 0 deletions framework/src/framework_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ pub struct FrameworkUpgrade {
/// optional, list of core module directory names to compile. It will default to this order: move-stdlib, vendor-stdlib, libra-framework
#[clap(long)]
pub core_modules: Option<Vec<String>>,

/// optional, DANGER: force the upgrade, and ignore all compatibility checks
/// I hope to god you know what you are doing.
#[clap(long)]
pub danger_force_upgrade: bool,
}

impl FrameworkUpgrade {
Expand All @@ -63,6 +68,7 @@ impl FrameworkUpgrade {
&self.output_dir,
&self.framework_local_dir,
&self.core_modules,
self.danger_force_upgrade,
)?;

Ok(())
Expand Down
9 changes: 0 additions & 9 deletions framework/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use diem_framework::{
docgen::DocgenOptions, BuildOptions, ReleaseBundle, ReleaseOptions, RELEASE_BUNDLE_EXTENSION,
};
// use clap::Args;
use move_command_line_common::address::NumericalAddress;
use once_cell::sync::Lazy;
use std::{collections::BTreeMap, fmt::Display, path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -64,14 +63,6 @@ impl ReleaseTarget {
"libra-framework",
Some("cached-packages/src/libra_framework_sdk_builder.rs"),
),
// (
// "diem-token",
// Some("cached-packages/src/diem_token_sdk_builder.rs"),
// ),
// (
// "diem-token-objects",
// Some("cached-packages/src/diem_token_objects_sdk_builder.rs"),
// ),
];
// Currently we don't have experimental packages only included in particular targets.
result
Expand Down

This file was deleted.

Binary file not shown.

This file was deleted.

Loading

0 comments on commit 1e1a4ae

Please sign in to comment.