Skip to content

Commit

Permalink
[release] 7.0.0 (0LNetworkCommunity#223)
Browse files Browse the repository at this point in the history
Co-authored-by: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
Co-authored-by: coin1111 <celticsnow123@gmail.com>
Co-authored-by: sirouk <8901571+sirouk@users.noreply.github.com>
  • Loading branch information
4 people committed Apr 17, 2024
1 parent 37c7e0d commit 82f3eab
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ module ol_framework::community_wallet_init {
/// qualify
public fun check_proposed_auths(initial_authorities: vector<address>, num_signers:
u64): bool {
// // enforce n/m multi auth

// TODO: enforce n/m multi auth such as:
// let n = if (len == 3) { 2 }
// else {
// (MINIMUM_SIGS * len) / MINIMUM_AUTH
Expand Down
Binary file modified tools/genesis/tests/fixtures/genesis.blob
Binary file not shown.
29 changes: 29 additions & 0 deletions tools/storage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,41 @@ use clap::Parser;
use diem_db_tool::DBTool;
use diem_logger::{Level, Logger};
use diem_push_metrics::MetricsPusher;
use std::path::PathBuf;
use storage::read_snapshot::manifest_to_json;

#[derive(Parser)]
#[clap(name = "libra storage", author, version)]
#[allow(clippy::large_enum_variant)]
enum StorageCli {
#[clap(subcommand)]
Db(DBTool),
ExportSnapshot {
#[clap(short, long)]
manifest_path: PathBuf,
#[clap(short, long)]
out_path: Option<PathBuf>,
},
}

#[tokio::main]
async fn main() -> Result<()> {
Logger::new().level(Level::Info).init();
let _mp = MetricsPusher::start(vec![]);

match StorageCli::parse() {
StorageCli::Db(tool) => {
tool.run().await?;
}
StorageCli::ExportSnapshot {
manifest_path,
out_path,
} => {
manifest_to_json(manifest_path, out_path).await;
}
}

DBTool::parse().run().await?;

Ok(())
}
44 changes: 32 additions & 12 deletions tools/storage/src/read_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ use diem_backup_cli::{
},
storage::{FileHandle, FileHandleRef},
};

use tokio::{fs::OpenOptions, io::AsyncRead};

use diem_types::account_address::AccountAddress;
use diem_types::account_state::AccountState;
use diem_types::state_store::state_key::{StateKey, StateKeyInner};
use diem_types::state_store::state_value::StateValue;

use libra_types::legacy_types::legacy_recovery_v6;
use serde_json::json;
use std::collections::HashMap;
use std::{
fs,
path::{Path, PathBuf},
};
use tokio::{fs::OpenOptions, io::AsyncRead};

#[cfg(test)]
use libra_types::legacy_types::legacy_recovery_v6::{get_legacy_recovery, AccountRole};
Expand Down Expand Up @@ -135,6 +134,34 @@ fn test_parse_manifest() {
// dbg!(&r.epoch);
}

pub async fn manifest_to_json(manifest_path: PathBuf, out_path: Option<PathBuf>) {
let snapshot_manifest = load_snapshot_manifest(&manifest_path).expect("parse manifest");
let archive_path = manifest_path.parent().unwrap();
let account_states = accounts_from_snapshot_backup(snapshot_manifest, archive_path)
.await
.expect("could not parse snapshot");
let mut legacy_recovery_vec = Vec::new();
for account_state in account_states.iter() {
let legacy_recovery = legacy_recovery_v6::get_legacy_recovery(account_state)
.expect("could not get legacy recovery");

legacy_recovery_vec.push(legacy_recovery);
}

let json = json!(&legacy_recovery_vec);
let out = out_path.unwrap_or(manifest_path.parent().unwrap().join("migration.json"));
fs::write(out, json.to_string()).expect("could not save file");
}

#[tokio::test]
async fn test_export() {
use std::str::FromStr;
let this_path = PathBuf::from_str(env!("CARGO_MANIFEST_DIR")).unwrap();
let manifest_path = this_path.join("fixtures/state_epoch_79_ver_33217173.795d/state.manifest");
let export_path = this_path.join("json/v6_migration.json");
manifest_to_json(manifest_path, Some(export_path)).await;
}

#[tokio::test]
async fn test_deserialize_account() {
use std::str::FromStr;
Expand All @@ -147,19 +174,12 @@ async fn test_deserialize_account() {
.expect("could not parse snapshot");
let mut legacy_recovery_vec = Vec::new();
for account_state in account_states.iter() {
// println!("----------------------------------------------------");
// println!("account_address: {:?}", account_state.get_account_address());
let legacy_recovery =
get_legacy_recovery(account_state).expect("could not get legacy recovery");
//println!("legacy_recovery: {:?}", legacy_recovery);

legacy_recovery_vec.push(legacy_recovery);
}

// let legacy_recovery_vec_json =
// serde_json::to_string(&legacy_recovery_vec).expect("could not create json for state");

// println!("{}", legacy_recovery_vec_json);

// basic validation of the account state
let account_count = 23634;
assert_eq!(account_states.len(), account_count);
Expand Down

0 comments on commit 82f3eab

Please sign in to comment.