Skip to content

Commit

Permalink
[tools] refactor rescue cli 6.9.1 (0LNetworkCommunity#137)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <[email protected]>
  • Loading branch information
0xzoz and 0o-de-lally committed Aug 16, 2024
1 parent ef3bfbc commit d51a0ee
Show file tree
Hide file tree
Showing 111 changed files with 35,476 additions and 17,952 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:

jobs:
build-framework:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -34,6 +35,7 @@ jobs:
name: framework-build
path: framework/*
types:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -46,6 +48,7 @@ jobs:
working-directory: ./types
run: cargo test --no-fail-fast
wallet:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -59,6 +62,7 @@ jobs:

# NOTE: all jobs below need the fresh framework build
smoke:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -75,9 +79,10 @@ jobs:
- name: smoke-tests # NOTE: needs working DIEM_FORGE_NODE_BIN_PATH
if: always()
working-directory: ./smoke-tests
run: cargo test --no-fail-fast
run: cargo test --no-fail-fast -- --test-threads=1

query:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -96,6 +101,7 @@ jobs:
run: cargo test --no-fail-fast

genesis:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -110,8 +116,8 @@ jobs:
if: always()
working-directory: ./tools/genesis
run: cargo test --no-fail-fast

tower:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -128,6 +134,7 @@ jobs:
run: cargo test --no-fail-fast

txs:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
Expand All @@ -143,3 +150,20 @@ jobs:
working-directory: ./tools/txs
# NOTE: upgrade tests which compile Move code, and then submit in the same thread will cause a stack overflow with the default rust stack size.
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast

rescue:
timeout-minutes: 60
needs: [build-framework]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: setup env
uses: ./.github/actions/build_env
- uses: actions/download-artifact@master
with:
name: framework-build
path: framework/
- name: rescue
if: always()
working-directory: ./tools/rescue
run: RUST_MIN_STACK=104857600 cargo test --no-fail-fast -- --test-threads=1
63 changes: 54 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,69 @@
// target/debug/ol-genesis-tools --fork --output-path /opt/genesis_from_snapshot.blob --snapshot-path /Users/gsimsek/code/libra-main/ol/devnet/snapshot/state_ver_267.54ab`
"configurations": [
{
"name": "framework-upgrade",
"name": "rescue-script",
"type": "lldb",
"request": "launch",
"cargo": {
"args": [
"build",
// "--release",
"-p",
"libra-framework"
"rescue"
],
},
"args": [
"upgrade",
"-o",
"${workspaceFolder}/framework/releases/framework_upgrade",
"--core-modules", "move-stdlib",
"-f",
"${workspaceFolder}/framework",
"rescue-tx",
"--data-path",
// "/root/test-db/db",
"/root/dbarchive/data_bak_2023-12-11/db",
// "--script-path",
// "${workspaceFolder}/tools/rescue/fixtures/rescue_framework_script",
"--framework-upgrade"
],
"cwd": "${workspaceFolder}"
},
{
"name": "rescue-verify",
"type": "lldb",
"request": "launch",
"cargo": {
"args": [
"build",
"-p",
"rescue"
],
},
"args": [
"bootstrap",
// "/root/test-db/db",
"/root/dbarchive/data_bak_2023-12-11/db",
"--genesis-txn-file",
"/root/dbarchive/data_bak_2023-12-11/db/rescue.blob",
"--waypoint-to-verify",
"2471146:3d54561e00f0dccaf696467ec2ea47f9bf6149536e9e4e66f4bf742742f5a0cc"
],
"cwd": "${workspaceFolder}"
},
{
"name": "rescue-apply",
"type": "lldb",
"request": "launch",
"cargo": {
"args": [
"build",
"-p",
"rescue"
],
},
"args": [
"bootstrap",
// "/root/test-db/db",
"/root/dbarchive/data_bak_2023-12-11/db",
"--genesis-txn-file",
"/root/dbarchive/data_bak_2023-12-11/db/rescue.blob",
"--waypoint-to-verify",
"2471146:3d54561e00f0dccaf696467ec2ea47f9bf6149536e9e4e66f4bf742742f5a0cc",
"--commit",
],
"cwd": "${workspaceFolder}"
},
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rust-version = "1.70.0"
libra-cached-packages = { path = "framework/cached-packages" }
libra-config = { path = "tools/config" }
libra-framework = { path = "framework" }
libra-genesis-tools = { path = "tools/genesis" }
libra-query = { path = "tools/query" }
libra-smoke-tests = { path = "smoke-tests" }
libra-tower = { path = "tools/tower" }
Expand Down Expand Up @@ -63,6 +64,7 @@ diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db
diem-gas = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-vm = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-vm-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-vm-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-executor = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-framework = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
diem-cached-packages = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
Expand Down Expand Up @@ -320,6 +322,7 @@ move-command-line-common = { git = "https://github.com/0LNetworkCommunity/diem.g
move-compiler = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
move-model = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
move-vm-test-utils = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }
move-vm-types = { git = "https://github.com/0LNetworkCommunity/diem.git", rev = "db1137ba1" }

# uses a profile similar to `cli` in Diem/Cargo.toml
# optimized for performance and size
Expand All @@ -342,8 +345,11 @@ split-debuginfo = "unpacked"
lto = false
incremental = true

[profile.test]
inherits = "dev"

# # This is a temporary workaround to avoid multiple library
# # definitions for LZ4 (caused by rust-rocksdb).
# # This will be removed once our pull requests land.
[patch.crates-io]
serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "839aed62a20ddccf043c08961cfe74875741ccba" }
serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "839aed62a20ddccf043c08961cfe74875741ccba" }
53 changes: 34 additions & 19 deletions framework/libra-framework/sources/code.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module diem_framework::code {
use std::error;
use std::signer;
use std::vector;
use std::features;

use diem_framework::util;
use diem_framework::system_addresses;
use diem_std::copyable_any::Any;
Expand Down Expand Up @@ -130,7 +128,8 @@ module diem_framework::code {
/// Publishes a package at the given signer's address. The caller must provide package metadata describing the
/// package.
public fun publish_package(owner: &signer, pack: PackageMetadata, code: vector<vector<u8>>) acquires PackageRegistry {
// Disallow incompatible upgrade mode. Governance can decide later if this should be reconsidered.
// 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),
Expand All @@ -146,15 +145,24 @@ module diem_framework::code {

// Check package against conflicts
let module_names = get_module_names(&pack);
let packages = &mut borrow_global_mut<PackageRegistry>(addr).packages;
let len = vector::length(packages);
let index = len;

// E.g (stdlib, diem-stdlib, libra-framework)
let current_packages = &mut borrow_global_mut<PackageRegistry>(addr).packages;
let current_package_len = vector::length(current_packages);

let index = current_package_len;
let i = 0;
let upgrade_number = 0;
while (i < len) {
let old = vector::borrow(packages, i);
// for every package (e.g. stdlib, libra-framework) we have installed (old)
// let's check to see if the package can either:
// a) be upgraded to new using same namespace
// b) can coexist with new existing installation
while (i < current_package_len) {
let old = vector::borrow(current_packages, i);
if (old.name == pack.name) {

upgrade_number = old.upgrade_number + 1;

check_upgradability(old, &pack, &module_names);
index = i;
} else {
Expand All @@ -168,19 +176,15 @@ module diem_framework::code {

// Update registry
let policy = pack.upgrade_policy;
if (index < len) {
*vector::borrow_mut(packages, index) = pack
if (index < current_package_len) {
*vector::borrow_mut(current_packages, index) = pack
} else {
vector::push_back(packages, pack)
vector::push_back(current_packages, pack)
};

// Request publish
if (features::code_dependency_check_enabled())
request_publish_with_allowed_deps(addr, module_names, allowed_deps, code, policy.policy)
else
// The new `request_publish_with_allowed_deps` has not yet rolled out, so call downwards
// compatible code.
request_publish(addr, module_names, code, policy.policy)
// Commit note: there is only this option since other `request_publish`
// is deprecated
request_publish_with_allowed_deps(addr, module_names, allowed_deps,code, policy.policy);
}

/// Same as `publish_package` but as an entry function which can be called as a transaction. Because
Expand All @@ -195,7 +199,9 @@ 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: &vector<String>) {
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),
Expand Down Expand Up @@ -304,6 +310,15 @@ module diem_framework::code {
module_names
}

#[view]
public fun get_module_names_for_package_index(addr: address, idx: u64): vector<String>
acquires PackageRegistry {
let current_packages =
&borrow_global<PackageRegistry>(addr).packages;
let pack = vector::borrow(current_packages, idx);
get_module_names(pack)
}

/// Native function to initiate module loading
native fun request_publish(
owner: address,
Expand Down
Loading

0 comments on commit d51a0ee

Please sign in to comment.