Skip to content

Commit

Permalink
complete all features of genesis wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Mar 3, 2023
1 parent b66a1d5 commit 2363875
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 117 deletions.
102 changes: 99 additions & 3 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions config/management/genesis/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub struct Verify {
}

impl Verify {
pub fn new(validator_backend: &ValidatorBackend, genesis_path: PathBuf) -> Self {
Self {
config: ConfigPath { config: None },
backend: validator_backend.to_owned(),
genesis_path: Some(genesis_path),
}
}
pub fn execute(self) -> Result<String, Error> {
let config = self
.config
Expand Down
3 changes: 2 additions & 1 deletion ol/cli/src/commands/restore_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `restore-cmd` subcommand

use crate::mgmt;
use crate::{mgmt, application::app_config};
use abscissa_core::{Command, Options, Runnable};

/// `restore-cmd` subcommand
Expand Down Expand Up @@ -39,6 +39,7 @@ impl Runnable for RestoreCmd {
self.epoch,
self.version,
self.latest_version,
&app_config().clone(),
) {
Ok(_) => {
println!("SUCCESS")
Expand Down
71 changes: 44 additions & 27 deletions ol/cli/src/mgmt/restore.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! `restore` functions

use crate::application::app_config;
use abscissa_core::status_ok;
use anyhow::{anyhow, bail, Error};
use diem_global_constants::WAYPOINT;
use diem_secure_storage::KVStorage;
use diem_secure_storage::{self, Namespaced, OnDiskStorage};
use diem_types::waypoint::Waypoint;
use glob::glob;
use ol_types::OLProgress;
use ol_types::config::AppCfg;
use once_cell::sync::Lazy;
use reqwest;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -54,8 +54,9 @@ pub fn fast_forward_db(
epoch: Option<u64>,
version_opt: Option<u64>,
highest_version: bool,
conf: &AppCfg,
) -> Result<(), Error> {
let mut backup = Backup::new(epoch);
let mut backup = Backup::new(epoch, conf);

println!("fetching latest epoch backup from epoch archive");
backup.fetch_backup(verbose)?;
Expand Down Expand Up @@ -92,7 +93,7 @@ static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_P
/// Backup metadata
#[derive(Debug)]
pub struct Backup {
version_number: u64,
epoch: u64,
archive_url: String,
home_path: PathBuf,
restore_path: PathBuf,
Expand All @@ -103,8 +104,8 @@ pub struct Backup {

impl Backup {
/// Creates a backup info instance
pub fn new(epoch: Option<u64>) -> Self {
let conf = app_config().to_owned();
pub fn new(epoch: Option<u64>, conf: &AppCfg) -> Self {
// let conf = app_config().to_owned();
let (restore_epoch, archive_url) = if let Some(e) = epoch {
(e, get_archive_url(e).unwrap())
} else {
Expand All @@ -118,12 +119,9 @@ impl Backup {
.workspace
.node_home
.join(format!("restore/{}", restore_epoch));
fs::create_dir_all(&restore_path).unwrap();

println!("DB fast forward to epoch: {}", &restore_epoch);

Backup {
version_number: restore_epoch,
epoch: restore_epoch,
archive_url,
home_path: conf.workspace.node_home.clone(),
restore_path: restore_path.clone(),
Expand All @@ -137,6 +135,8 @@ impl Backup {
}
/// Fetch backups
pub fn fetch_backup(&self, verbose: bool) -> Result<(), Error> {
fs::create_dir_all(&self.restore_path).unwrap();

let mut resp =
reqwest::blocking::get(&self.archive_url).expect("epoch archive http request failed");
let mut out = File::create(&self.archive_path).expect("cannot create tar.gz archive");
Expand Down Expand Up @@ -169,7 +169,8 @@ impl Backup {

assert!(ecode.success());

status_ok!("\nArchive downloaded", "\n...........................\n");
OLProgress::complete("Database snapshot downloaded to");


Ok(())
}
Expand Down Expand Up @@ -227,7 +228,7 @@ impl Backup {
let manifest_path = self.restore_path.to_str().unwrap();
for entry in glob(&format!("{}/**/epoch_ending.manifest", manifest_path))
.expect("Failed to read glob pattern")
{
{
match entry {
Ok(path) => {
println!("{:?}", path.display());
Expand Down Expand Up @@ -260,8 +261,8 @@ impl Backup {
// ns_storage.set(GENESIS_WAYPOINT, waypoint)?;
ns_storage.set(WAYPOINT, waypoint)?;

println!("waypoint retrieve, updated key_store.json");
status_ok!("\nWaypoint set", "\n...........................\n");
println!("waypoint retrieved, updated key_store.json");
OLProgress::complete("Waypoint set");

Ok(waypoint)
}
Expand All @@ -287,13 +288,31 @@ impl Backup {
"fullnode yaml created, file saved to: {:?}",
yaml_path.to_str().unwrap()
);
status_ok!(
"\nFullnode config written",
"\n...........................\n"
);

OLProgress::complete("Fullnode config written");

Ok(())
}

/// helper to get path to manifest file
pub fn manifest_path(&self) -> Result<PathBuf, Error> {
let glob_format = &format!("{}/**/epoch_ending.manifest", &self.restore_path.to_str().expect("no restore path provided"));
let manifest_path = match glob(glob_format)
.expect("Failed to read glob pattern")
.next()
{
Some(Ok(p)) => p,
_ => bail!("no path found for {:?}", glob_format),
};

if !manifest_path.exists() {
let msg = format!("manifest path does not exist at: {:?}", &manifest_path);
println!("{}", &msg);
bail!(msg);
} else {
Ok(manifest_path)
}
}
}

fn get_highest_epoch_archive() -> Result<(u64, String), Error> {
Expand Down Expand Up @@ -340,6 +359,7 @@ fn get_archive_url(epoch: u64) -> Result<String, Error> {
))
}


/// Restores transaction epoch backups
pub fn restore_epoch(db_path: &PathBuf, restore_path: &str, verbose: bool) -> Result<(), Error> {
let glob_format = &format!("{}/**/epoch_ending.manifest", restore_path);
Expand Down Expand Up @@ -387,10 +407,8 @@ pub fn restore_epoch(db_path: &PathBuf, restore_path: &str, verbose: bool) -> Re
"epoch metadata restored from epoch archive, files saved to: {:?}",
restore_path
);
status_ok!(
"\nEpoch metadata restored",
"\n...........................\n"
);

OLProgress::complete("Epoch metadata restored");

Ok(())
}
Expand Down Expand Up @@ -443,7 +461,8 @@ pub fn restore_transaction(
assert!(ecode.success());

println!("transactions restored from epoch archive,");
status_ok!("\nTransactions restored", "\n...........................\n");

OLProgress::complete("Transactions restored");

Ok(())
}
Expand Down Expand Up @@ -484,10 +503,8 @@ pub fn restore_snapshot(

assert!(ecode.success());
println!("state snapshot restored from epoch archive,");
status_ok!(
"\nState snapshot restored",
"\n...........................\n"
);

OLProgress::complete("State snapshot restored");

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion ol/genesis-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ diem-vm = { path = "../../diem-move/diem-vm", version = "0.1.0" }
diem-framework-releases = { path = "../../diem-move/diem-framework/DPN/releases" }
ol-smoke-tests = { path = "../smoke-tests/"}
diem-management = { path = "../../config/management" }
diem-global-constants = { path = "../../config/global-constants" }
indicatif = "0.17.3"
dialoguer = "0.8.0"
dirs = "4.0.0"
onboard = { path = "../onboard" }
diem-github-client = { path = "../../secure/storage/github" }

chrono = "0.4.23"

[dev-dependencies]
tokio-test = "*"
Expand Down
2 changes: 1 addition & 1 deletion ol/genesis-tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() -> Result<()> {
let mut w = wizard::GenesisWizard::default();
w.repo_name = opts.genesis_repo_name.as_ref().unwrap().clone();
w.repo_owner = opts.genesis_repo_owner.as_ref().unwrap().clone();
w.epoch = opts.genesis_restore_epoch.unwrap();
w.epoch = opts.genesis_restore_epoch;
w.start_wizard()?;
return Ok(()); // exit
}
Expand Down
Loading

0 comments on commit 2363875

Please sign in to comment.