Skip to content

Commit

Permalink
[rust] rescue mode transaction generation and db write (#64)
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 8, 2024
1 parent 1de06bb commit 5c14458
Show file tree
Hide file tree
Showing 59 changed files with 1,324 additions and 283 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cleanliness.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: setup env
uses: ./.github/actions/build_env

Expand Down
347 changes: 190 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

71 changes: 37 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"tools/config",
"tools/genesis",
"tools/query",
"tools/rescue",
"tools/tower",
"tools/txs",
"tools/wallet",
Expand Down Expand Up @@ -40,37 +41,37 @@ libra-txs = { path = "tools/txs" }
libra-wallet = { path = "tools/wallet" }
vdf = { git = "https://github.com/0o-de-lally/verifiable_delay.git" }

diem-api-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-debugger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-db = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-forge = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-transactional-test-harness = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
smoke-test = { package = "smoke-test", git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-api-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-debugger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-db = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-forge = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-transactional-test-harness = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
smoke-test = { package = "smoke-test", git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }

diem = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-build-info = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-node = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-rest-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-sdk = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-config = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-global-constants = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-keygen = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-logger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-gas = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-vm = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-vm-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-executor = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-framework = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-cached-packages = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-github-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-release-builder = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-language-e2e-tests = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-state-view = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-storage-interface = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-temppath = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-build-info = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-node = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-rest-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-sdk = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-config = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-global-constants = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-keygen = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-logger = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-gas = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-vm = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-vm-genesis = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-executor = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-framework = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-cached-packages = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-github-client = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-release-builder = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-language-e2e-tests = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-state-view = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-storage-interface = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
diem-temppath = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }

### External crate dependencies.
# 0L NOTE: most of these are not used. But we leave the entire block here
Expand Down Expand Up @@ -313,10 +314,12 @@ serde_with = "^3"
# move-abigen = { path = "third_party/move/move-prover/move-abigen" }
# move-binary-format = { path = "third_party/move/move-binary-format" }
# ... see full list in Aptos repo
move-binary-format = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-core-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-command-line-common = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-model = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
move-binary-format = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-core-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-command-line-common = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-compiler = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-model = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-vm-test-utils = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }

# uses a profile similar to `cli` in Diem/Cargo.toml
# optimized for performance and size
Expand Down
2 changes: 1 addition & 1 deletion framework/cached-packages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = { workspace = true }
[dependencies]
bcs = { workspace = true }
# Note the generated SDK code uses hard coded `diemtypes`
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "release" }
diem-types = { git = "https://github.com/0LNetworkCommunity/diem.git", branch = "test-writeset" }
move-core-types = { workspace = true }
once_cell = { workspace = true }

Expand Down
68 changes: 0 additions & 68 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@ pub enum EntryFunctionCall {
id: u64,
},

DummyUseFnFromDiemFramework {},

DummyUseFnFromDiemStd {
account_public_key_bytes: Vec<u8>,
},

/// Only a Voucher of the validator can flip the unjail bit.
/// This is a way to make sure the validator is ready to rejoin.
JailUnjailByVoucher {
Expand Down Expand Up @@ -730,10 +724,6 @@ impl EntryFunctionCall {
multisig_address,
id,
} => donor_directed_vote_veto_tx(multisig_address, id),
DummyUseFnFromDiemFramework {} => dummy_use_fn_from_diem_framework(),
DummyUseFnFromDiemStd {
account_public_key_bytes,
} => dummy_use_fn_from_diem_std(account_public_key_bytes),
JailUnjailByVoucher { addr } => jail_unjail_by_voucher(addr),
GasCoinClaimMintCapability {} => gas_coin_claim_mint_capability(),
GasCoinDelegateMintCapability { to } => gas_coin_delegate_mint_capability(to),
Expand Down Expand Up @@ -1529,36 +1519,6 @@ pub fn donor_directed_vote_veto_tx(
))
}

pub fn dummy_use_fn_from_diem_framework() -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("dummy").to_owned(),
),
ident_str!("use_fn_from_diem_framework").to_owned(),
vec![],
vec![],
))
}

pub fn dummy_use_fn_from_diem_std(account_public_key_bytes: Vec<u8>) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("dummy").to_owned(),
),
ident_str!("use_fn_from_diem_std").to_owned(),
vec![],
vec![bcs::to_bytes(&account_public_key_bytes).unwrap()],
))
}

/// Only a Voucher of the validator can flip the unjail bit.
/// This is a way to make sure the validator is ready to rejoin.
pub fn jail_unjail_by_voucher(addr: AccountAddress) -> TransactionPayload {
Expand Down Expand Up @@ -2820,26 +2780,6 @@ mod decoder {
}
}

pub fn dummy_use_fn_from_diem_framework(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::DummyUseFnFromDiemFramework {})
} else {
None
}
}

pub fn dummy_use_fn_from_diem_std(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::DummyUseFnFromDiemStd {
account_public_key_bytes: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
None
}
}

pub fn jail_unjail_by_voucher(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::JailUnjailByVoucher {
Expand Down Expand Up @@ -3477,14 +3417,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"donor_directed_vote_veto_tx".to_string(),
Box::new(decoder::donor_directed_vote_veto_tx),
);
map.insert(
"dummy_use_fn_from_diem_framework".to_string(),
Box::new(decoder::dummy_use_fn_from_diem_framework),
);
map.insert(
"dummy_use_fn_from_diem_std".to_string(),
Box::new(decoder::dummy_use_fn_from_diem_std),
);
map.insert(
"jail_unjail_by_voucher".to_string(),
Box::new(decoder::jail_unjail_by_voucher),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@ module diem_framework::reconfiguration {
);
}

/// For rescue missions
public fun reconfigure_for_rescue(vm: &signer) acquires Configuration {
system_addresses::assert_ol(vm);

let config_ref = borrow_global_mut<Configuration>(@diem_framework);

storage_gas::on_reconfig();

config_ref.epoch = config_ref.epoch + 1;

epoch_helper::set_epoch(config_ref.epoch);

event::emit_event<NewEpochEvent>(
&mut config_ref.events,
NewEpochEvent {
epoch: config_ref.epoch,
},
);
}

#[test_only]
public fun reconfigure_for_test() acquires Configuration {
reconfigure();
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
8 changes: 3 additions & 5 deletions framework/src/builder/framework_generate_upgrade_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use diem_framework::{BuildOptions, BuiltPackage, ReleasePackage};
use diem_types::account_address::AccountAddress;
use std::path::{Path, PathBuf};
// use serde::{Serialize, Deserialize};
use crate::builder::framework_release_bundle::libra_author_script_file;
use crate::{builder::framework_release_bundle::libra_author_script_file, BYTECODE_VERSION};

/// Core modules address to deploy to
// NOTE: we are always usin 0x1 here. So if that ever changes in the future then this can't be hard coded.
Expand Down Expand Up @@ -74,7 +74,7 @@ pub fn make_framework_upgrade_artifacts(
with_source_maps: false,
with_error_map: true,
skip_fetch_latest_git_deps: false,
bytecode_version: Some(6),
bytecode_version: Some(BYTECODE_VERSION),
..BuildOptions::default()
};

Expand Down Expand Up @@ -172,10 +172,8 @@ pub fn init_move_dir_wrapper(
}

pub fn libra_compile_script(
// skip_fetch_latest_git_deps: bool,
script_package_dir: &Path,
_is_module: bool,
// bytecode_version: Option<u32>,
) -> Result<(Vec<u8>, HashValue)> {
println!("compiling governance script...");
// these are the options only for the upgrade SCRIPT
Expand All @@ -187,7 +185,7 @@ pub fn libra_compile_script(
with_source_maps: false,
with_error_map: false,
skip_fetch_latest_git_deps: true,
bytecode_version: Some(6),
bytecode_version: Some(BYTECODE_VERSION),

..BuildOptions::default()
};
Expand Down
9 changes: 6 additions & 3 deletions framework/src/framework_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl GovernanceScript {
))
.interact()?
{
make_template_files(&package_dir, &self.framework_local_dir, script_name)?;
make_template_files(&package_dir, &self.framework_local_dir, script_name, None)?;
}
return Ok(());
}
Expand All @@ -115,10 +115,12 @@ impl GovernanceScript {
}
}

fn make_template_files(
/// make governance script template package
pub fn make_template_files(
package_dir: &Path,
framework_local_dir: &Path,
script_name: &str,
script_source: Option<String>,
) -> anyhow::Result<()> {
std::fs::create_dir_all(package_dir)
.context("could not create the output directory {new_path:?}")?;
Expand All @@ -128,6 +130,7 @@ fn make_template_files(
script_name,
framework_local_dir.to_owned(),
)?;

let t = r#"
script {
// THIS IS A TEMPLATE GOVERNANCE SCRIPT
Expand All @@ -147,7 +150,7 @@ script {
.join("sources")
.join(format!("{}.move", script_name));

std::fs::write(filename, t)?;
std::fs::write(filename, script_source.unwrap_or(t.to_string()))?;
println!("success: governance template created");

println!("\nBefore submitting the governance action you must compile the script. Simply run this command again.");
Expand Down
2 changes: 2 additions & 0 deletions framework/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub fn head_release_bundle() -> diem_framework::ReleaseBundle {
.load_bundle()
.expect("release build failed")
}

const BYTECODE_VERSION: u32 = 6;
2 changes: 1 addition & 1 deletion framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libra_framework::framework_cli::{FrameworkUpgrade, GenesisRelease, Governanc
enum Commands {
/// Creates a .mrb move framework release
Release(GenesisRelease),
/// Creates all artifacts for a network governance upgrade
/// Creates the script payload for a governance script
Governance(GovernanceScript),
/// Creates all artifacts for a network governance upgrade
Upgrade(FrameworkUpgrade),
Expand Down
6 changes: 4 additions & 2 deletions framework/src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use move_command_line_common::address::NumericalAddress;
use once_cell::sync::Lazy;
use std::{collections::BTreeMap, fmt::Display, path::PathBuf, str::FromStr};

use crate::BYTECODE_VERSION;

// ===============================================================================================
// Release Targets

Expand Down Expand Up @@ -119,7 +121,7 @@ impl ReleaseTarget {
references_file: Some("doc_template/references.md".to_string()),
}),
skip_fetch_latest_git_deps: false,
bytecode_version: None,
bytecode_version: Some(BYTECODE_VERSION),
},
packages: packages.iter().map(|(path, _)| path.to_owned()).collect(),
rust_bindings: packages
Expand Down Expand Up @@ -185,7 +187,7 @@ static NAMED_ADDRESSES: Lazy<BTreeMap<String, NumericalAddress>> = Lazy::new(||
result.insert("diem_token_objects".to_owned(), four);
result.insert("core_resources".to_owned(), resources);
result.insert("vm_reserved".to_owned(), zero);
result.insert("ol_framework".to_owned(), four); /////// 0L /////////
result.insert("ol_framework".to_owned(), one); /////// 0L /////////
result
});

Expand Down
4 changes: 4 additions & 0 deletions smoke-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ smoke-test = { workspace = true }
tokio = { workspace = true }
url = { workspace = true }

[dev-dependencies]
diem-config = { workspace = true }
diem-logger = { workspace = true }

[features]
#default = ["testing"]
testing = []
4 changes: 2 additions & 2 deletions smoke-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod configure_validator;
pub mod helpers;
pub mod libra_smoke;
#[cfg(test)]
mod tests;
// #[cfg(test)]
// mod tests;
pub mod upgrade_fixtures;
4 changes: 0 additions & 4 deletions smoke-tests/src/tests/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion smoke-tests/src/upgrade_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use libra_framework::builder::framework_generate_upgrade_proposal::make_framewor

pub fn fixtures_path() -> PathBuf {
let this_crate = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap();
this_crate.join("src").join("tests").join("fixtures")
this_crate.join("tests").join("fixtures")
}

pub fn insert_test_file(core_module_name: &str, remove: bool) -> anyhow::Result<()> {
Expand Down
Loading

0 comments on commit 5c14458

Please sign in to comment.