From 7d926f9f67469d7fc7d270932600878434107144 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 9 Nov 2023 10:48:28 +0100 Subject: [PATCH 1/5] rusk: change `Makefile` - Add `recovery-keys` recipe - Add `recovery-state` recipe - Change `clippy` to cover all features --- rusk/Makefile | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/rusk/Makefile b/rusk/Makefile index 5447167d34..c3d1b62db5 100644 --- a/rusk/Makefile +++ b/rusk/Makefile @@ -1,3 +1,5 @@ +INITFILE?=../rusk-recovery/config/localnet.toml + help: ## Display this help screen @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' @@ -10,8 +12,17 @@ test: ## Run Rusk tests clippy: ## Run clippy @cargo clippy --all-features --release -- -D warnings @cargo clippy --no-default-features --release -- -D warnings + @cargo clippy --no-default-features --features ephemeral --release -- -D warnings + @cargo clippy --no-default-features --features recovery-keys --release -- -D warnings + @cargo clippy --no-default-features --features recovery-state --release -- -D warnings build: ## Build rusk binary @cargo build --release -.PHONY: test help clippy build +recovery-keys: ## Build circuit keys + @cargo r --no-default-features --features recovery-keys --release -- recovery-keys + +recovery-state: ## Build network state + @cargo r --no-default-features --features recovery-state --release -- recovery-state --init $(INITFILE) + +.PHONY: test help clippy build recovery-keys recovery-state From f67366d7a5a8abec887fb0e3059654494b5b0b09 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 9 Nov 2023 10:49:14 +0100 Subject: [PATCH 2/5] workspace: change `Makefile` to use rusk binaries in recovery --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4e9ffd539e..503e532f2b 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ circuits: ## Compress and store all circuits $(MAKE) -C ./circuits $@ keys: circuits ## Create the keys for the circuits - $(MAKE) -C ./rusk-recovery keys + $(MAKE) -C ./rusk recovery-keys state: keys wasm ## Create the network state - $(MAKE) -C ./rusk-recovery state + $(MAKE) -C ./rusk recovery-state wasm: ## Generate the WASM for all the contracts $(MAKE) -C ./contracts $@ From 7dbfda097f87fbe4cba751cd2c90e9c235ad002a Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 9 Nov 2023 12:20:15 +0100 Subject: [PATCH 3/5] workspace: update `README.md` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a8f88165f..3818352183 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Run a single-node cluster with example's data ```bash # Generate genesis state -cargo r --release -p rusk-recovery --features state --bin rusk-recovery-state -- --init examples/genesis.toml -o /tmp/example.state +cargo r --release -p rusk -- recovery-state --init examples/genesis.toml -o /tmp/example.state # Launch a local ephemeral node DUSK_CONSENSUS_KEYS_PASS=password cargo r --release -p rusk -- -s /tmp/example.state From 8aefbae336d6dca8fad543f0af3ef393cde2dd2c Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 9 Nov 2023 12:20:34 +0100 Subject: [PATCH 4/5] workspace: update `Dockerfile` --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02bebda63f..2bde899851 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ RUN ARCH="$(echo $TARGETPLATFORM | sed 's/linux\///')" && \ # Generate keys, compile genesis contracts and generate genesis state RUN make keys && make wasm RUN mkdir -p /.dusk/rusk && cp examples/consensus.keys /.dusk/rusk/consensus.keys -RUN cargo r --release -p rusk-recovery --features state --bin rusk-recovery-state -- --init examples/genesis.toml -o /tmp/example.state +RUN cargo r --release -p rusk -- recovery-state --init examples/genesis.toml -o /tmp/example.state RUN cargo b --release -p rusk # --- Run stage --- @@ -44,8 +44,6 @@ EXPOSE 9000/udp # Copy only the necessary files from the build stage COPY --from=build-stage /.dusk/rusk /.dusk/rusk COPY --from=build-stage /opt/rusk/target/release/rusk /opt/rusk/ -COPY --from=build-stage /opt/rusk/target/release/rusk-recovery-keys /opt/rusk/ -COPY --from=build-stage /opt/rusk/target/release/rusk-recovery-state /opt/rusk/ COPY --from=build-stage /opt/rusk/examples/consensus.keys /.dusk/rusk/consensus.keys COPY --from=build-stage /tmp/example.state /tmp/example.state From df0a10f9a5bfa42e5a7e6a9b00e9f6b78625aca6 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Thu, 9 Nov 2023 10:51:18 +0100 Subject: [PATCH 5/5] rusk-recovery: remove binaries - Remove `rusk-recovery-keys` - Remove `rusk-recovery-state` Resolves #1128 --- rusk-recovery/Cargo.toml | 17 --- rusk-recovery/Makefile | 17 ++- rusk-recovery/build.rs | 20 ---- rusk-recovery/config/example.toml | 2 +- rusk-recovery/src/bin/keys.rs | 45 -------- rusk-recovery/src/bin/state.rs | 157 ---------------------------- rusk-recovery/src/bin/task.rs | 75 ------------- rusk-recovery/src/bin/version.rs | 29 ----- rusk-recovery/src/state/snapshot.rs | 1 - 9 files changed, 7 insertions(+), 356 deletions(-) delete mode 100644 rusk-recovery/build.rs delete mode 100644 rusk-recovery/src/bin/keys.rs delete mode 100644 rusk-recovery/src/bin/state.rs delete mode 100644 rusk-recovery/src/bin/task.rs delete mode 100644 rusk-recovery/src/bin/version.rs diff --git a/rusk-recovery/Cargo.toml b/rusk-recovery/Cargo.toml index 57524fb66a..3c6436b64f 100644 --- a/rusk-recovery/Cargo.toml +++ b/rusk-recovery/Cargo.toml @@ -9,37 +9,20 @@ description = "Tool to restore Rusk to factory settings" name = "rusk_recovery_tools" path = "src/lib.rs" -[[bin]] -name = "rusk-recovery-keys" -path = "src/bin/keys.rs" -required-features = ["keys"] - -[[bin]] -name = "rusk-recovery-state" -path = "src/bin/state.rs" -required-features = ["state"] - -[build-dependencies] -rustc_tools_util = "=0.2.0" [dependencies] hex = "0.4" -rustc_tools_util = "0.2" dusk-plonk = { version = "0.16", features = ["rkyv-impl"] } dusk-pki ="0.13" phoenix-core = { version = "0.21", features = ["rkyv-impl", "alloc"] } rand = "0.8" -dusk-merkle = "0.5" rusk-profile = { version = "0.6", path = "../rusk-profile" } rusk-abi = { version = "0.11", path = "../rusk-abi", default-features = false, features = ["host"] } once_cell = "1.13" dusk-bytes = "0.1" dusk-bls12_381 = "0.12" dusk-bls12_381-sign = "0.5" -clap = { version = "4", features = ["env", "derive"] } -thiserror = "1.0" tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.2.0", features = ["fmt"] } http_req = "0.8" zip = "0.5" url = "2.3" diff --git a/rusk-recovery/Makefile b/rusk-recovery/Makefile index ccef2e14c7..59b4387778 100644 --- a/rusk-recovery/Makefile +++ b/rusk-recovery/Makefile @@ -1,15 +1,7 @@ -INITFILE?=./config/localnet.toml - help: ## Display this help screen @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' -keys: ## Build circuit keys - cargo run --release --bin rusk-recovery-keys --features keys - -state: ## Build network state - cargo run --release --bin rusk-recovery-state --features state -- --init $(INITFILE) - -test: ## Run Rusk tests +test: ## Run tests @cargo test \ --release \ --all-features \ @@ -17,6 +9,9 @@ test: ## Run Rusk tests --test-threads 1 clippy: ## Run clippy - @cargo clippy --all-features --release -- -D warnings + @cargo clippy --release --all-features -- -D warnings + @cargo clippy --release --no-default-features -- -D warnings + @cargo clippy --release --no-default-features --features state -- -D warnings + @cargo clippy --release --no-default-features --features keys -- -D warnings -.PHONY: keys state test help +.PHONY: test clippy help diff --git a/rusk-recovery/build.rs b/rusk-recovery/build.rs deleted file mode 100644 index 7c6b4f1c7f..0000000000 --- a/rusk-recovery/build.rs +++ /dev/null @@ -1,20 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -fn main() { - println!( - "cargo:rustc-env=GIT_HASH={}", - rustc_tools_util::get_commit_hash().unwrap_or_default() - ); - println!( - "cargo:rustc-env=COMMIT_DATE={}", - rustc_tools_util::get_commit_date().unwrap_or_default() - ); - println!( - "cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", - rustc_tools_util::get_channel().unwrap_or_default() - ); -} diff --git a/rusk-recovery/config/example.toml b/rusk-recovery/config/example.toml index c25ca1c4e8..9ae9f82d23 100644 --- a/rusk-recovery/config/example.toml +++ b/rusk-recovery/config/example.toml @@ -2,7 +2,7 @@ # # The url can be either remote or local (eg: file:///path/state.zip) # The content of the file shall be the same format generated -# by `rusk-recovery-state --output ` command +# by `rusk recovery-state --output ` command # If no base_state is specified a local one will be generated base_state = "https://dusk-infra.ams3.digitaloceanspaces.com/keys/genesis.zip" diff --git a/rusk-recovery/src/bin/keys.rs b/rusk-recovery/src/bin/keys.rs deleted file mode 100644 index 816f49f4e6..0000000000 --- a/rusk-recovery/src/bin/keys.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -mod task; -mod version; - -use clap::builder::BoolishValueParser; -use clap::{ArgAction, Parser}; -use std::path::PathBuf; -use version::VERSION_BUILD; - -#[derive(Parser, Debug)] -#[clap(name = "rusk-recovery-keys")] -#[clap(author, version = &VERSION_BUILD[..], about, long_about = None)] -struct Cli { - /// Sets the profile path - #[clap( - short, - long, - value_parser, - value_name = "PATH", - env = "RUSK_PROFILE_PATH" - )] - profile: Option, - - /// Keeps untracked keys - #[clap(short, long, value_parser = BoolishValueParser::new(), env = "RUSK_KEEP_KEYS")] - keep: bool, - - /// Sets different levels of verbosity - #[clap(short, long, action = ArgAction::Count)] - verbose: usize, -} - -fn main() -> Result<(), Box> { - let args = Cli::parse(); - task::run( - || rusk_recovery_tools::keys::exec(args.keep), - args.profile, - args.verbose, - ) -} diff --git a/rusk-recovery/src/bin/state.rs b/rusk-recovery/src/bin/state.rs deleted file mode 100644 index 868c46883b..0000000000 --- a/rusk-recovery/src/bin/state.rs +++ /dev/null @@ -1,157 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -mod task; -mod version; - -use clap::builder::{ArgAction, BoolishValueParser}; -use clap::Parser; -use rusk_recovery_tools::Theme; -use std::error::Error; -use std::{env, io}; -use std::{fs, path::PathBuf}; -use tracing::info; -use version::VERSION_BUILD; - -use rusk_recovery_tools::state::{ - deploy, restore_state, tar, Snapshot, DEFAULT_SNAPSHOT, -}; - -#[derive(Parser, Debug)] -#[clap(name = "rusk-recovery-state")] -#[clap(author, version = &VERSION_BUILD[..], about, long_about = None)] -struct Cli { - /// Sets the profile path - #[clap( - short, - long, - value_parser, - value_name = "PATH", - env = "RUSK_PROFILE_PATH" - )] - profile: Option, - - /// Forces a build/download even if the state is in the profile path. - #[clap(short = 'f', value_parser = BoolishValueParser::new(), long, env = "RUSK_FORCE_STATE")] - force: bool, - - /// Create a state applying the init config specified in this file. - #[clap(short, long, value_parser, env = "RUSK_RECOVERY_INPUT")] - init: Option, - - /// Sets different levels of verbosity - #[clap(short, long, action = ArgAction::Count)] - verbose: usize, - - /// If specified, the generated state is written on this file instead of - /// save the state in the profile path. - #[clap(short, long, value_parser, num_args(1))] - output: Option, -} - -fn main() -> Result<(), Box> { - let args = Cli::parse(); - - let config = match args.init { - Some(path) => fs::read_to_string(path)?, - None => DEFAULT_SNAPSHOT.into(), - }; - let snapshot = toml::from_str(&config)?; - - task::run( - || { - exec(ExecConfig { - init: &snapshot, - force: args.force, - output_file: args.output.clone(), - }) - }, - args.profile, - args.verbose, - ) -} - -pub struct ExecConfig<'a> { - pub init: &'a Snapshot, - pub force: bool, - pub output_file: Option, -} - -pub fn exec(config: ExecConfig) -> Result<(), Box> { - let theme = Theme::default(); - info!("{} Network state", theme.action("Checking")); - - let _tmpdir = match config.output_file.clone() { - Some(output) if output.exists() => Err("Output already exists")?, - Some(_) => { - let tmp_dir = tempfile::tempdir()?; - env::set_var("RUSK_STATE_PATH", tmp_dir.path()); - Some(tmp_dir) - } - None => None, - }; - - if config.force { - clean_state()?; - } - - let state_dir = rusk_profile::get_rusk_state_dir()?; - let state_id_path = rusk_profile::to_rusk_state_id_path(&state_dir); - - let _ = rusk_abi::new_vm(&state_dir)?; - - // if the state already exists in the expected path, stop early. - if state_dir.exists() && state_id_path.exists() { - info!("{} existing state", theme.info("Found")); - - let (_, commit_id) = restore_state(state_dir)?; - info!( - "{} state id at {}", - theme.success("Checked"), - state_id_path.display() - ); - info!("{} {}", theme.action("Root"), hex::encode(commit_id)); - - return Ok(()); - } - - info!("{} new state", theme.info("Building")); - - let (_, commit_id) = deploy(&state_dir, config.init)?; - - info!("{} {}", theme.action("Final Root"), hex::encode(commit_id)); - - info!( - "{} network state at {}", - theme.success("Stored"), - state_dir.display() - ); - info!( - "{} persisted id at {}", - theme.success("Stored"), - state_id_path.display() - ); - - if let Some(output) = config.output_file { - let state_folder = rusk_profile::get_rusk_state_dir()?; - info!("{} state into the output file", theme.info("Zipping"),); - tar::archive(&state_folder, &output)?; - } - - Ok(()) -} - -fn clean_state() -> Result<(), io::Error> { - let state_path = rusk_profile::get_rusk_state_dir()?; - - fs::remove_dir_all(state_path).or_else(|e| { - if e.kind() == io::ErrorKind::NotFound { - Ok(()) - } else { - Err(e) - } - }) -} diff --git a/rusk-recovery/src/bin/task.rs b/rusk-recovery/src/bin/task.rs deleted file mode 100644 index 8cf20acb15..0000000000 --- a/rusk-recovery/src/bin/task.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use rusk_recovery_tools::Theme; -use std::env; -use std::path::PathBuf; -use std::time::Instant; -use tracing::info; -use tracing_subscriber::prelude::*; - -pub fn run( - task: impl Fn() -> Result<(), Box>, - profile: Option, - verbose: usize, -) -> Result<(), Box> { - let begin = Instant::now(); - - if let Some(profile) = profile { - env::set_var("RUSK_PROFILE_PATH", profile.to_str().unwrap()); - } - - if verbose > 0 { - let fmt_layer = tracing_subscriber::fmt::layer() - .with_target(true) - .with_level(true) - .compact(); - - tracing_subscriber::registry().with(fmt_layer).init(); - } else { - let fmt_layer = tracing_subscriber::fmt::layer() - .without_time() - .with_target(false) - .with_level(false) - .compact(); - - tracing_subscriber::registry().with(fmt_layer).init(); - } - - let theme = Theme::default(); - info!( - "{} {} as profile path", - theme.action("Using"), - rusk_profile::get_rusk_profile_dir()?.to_str().unwrap() - ); - - info!( - "{} {} as circuits path", - theme.action("Using"), - rusk_profile::get_rusk_circuits_dir()?.to_str().unwrap() - ); - - info!( - "{} {} as keys path", - theme.action("Using"), - rusk_profile::get_rusk_keys_dir()?.to_str().unwrap() - ); - - info!( - "{} {} as state path", - theme.action("Using"), - rusk_profile::get_rusk_state_dir()?.to_str().unwrap() - ); - - task()?; - - info!( - "{} task in {:.2}s", - theme.action("Finished"), - begin.elapsed().as_secs_f32() - ); - Ok(()) -} diff --git a/rusk-recovery/src/bin/version.rs b/rusk-recovery/src/bin/version.rs deleted file mode 100644 index fac00c4f8c..0000000000 --- a/rusk-recovery/src/bin/version.rs +++ /dev/null @@ -1,29 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use once_cell::sync::Lazy; -use rustc_tools_util::*; - -#[inline] -pub fn version(info: &VersionInfo) -> String { - let version = format!("{}.{}.{}", info.major, info.minor, info.patch); - let build = format!( - "{} {}", - info.commit_hash.as_ref().unwrap_or(&"".to_string()), - info.commit_date.as_ref().unwrap_or(&"".to_string()) - ); - - if build.len() > 1 { - format!("{version} ({build})") - } else { - version - } -} - -pub static VERSION_BUILD: Lazy = Lazy::new(|| { - let info = rustc_tools_util::get_version_info!(); - version(&info) -}); diff --git a/rusk-recovery/src/state/snapshot.rs b/rusk-recovery/src/state/snapshot.rs index 301f1240bc..8a71a1aa98 100644 --- a/rusk-recovery/src/state/snapshot.rs +++ b/rusk-recovery/src/state/snapshot.rs @@ -107,7 +107,6 @@ mod tests { use super::*; use crate::state; - use rusk_abi::dusk::{dusk, Dusk}; pub(crate) fn testnet_from_file() -> Result> { let toml = include_str!("../../config/testnet.toml");