diff --git a/Cargo.lock b/Cargo.lock index feb49859c8..4b05c3ccbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,16 +22,33 @@ dependencies = [ "memchr", ] +[[package]] +name = "aleo-std" +version = "0.1.0" +dependencies = [ + "aleo-std-storage 0.1.0", + "aleo-std-time 0.1.0", + "aleo-std-timed 0.1.0", + "aleo-std-timer 0.1.0", +] + [[package]] name = "aleo-std" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36881e97e954a112082ee4557998ede9a0ba0da10501e2b04e865e8f4ddd2da6" dependencies = [ - "aleo-std-storage", - "aleo-std-time", - "aleo-std-timed", - "aleo-std-timer", + "aleo-std-storage 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aleo-std-time 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aleo-std-timed 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "aleo-std-timer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "aleo-std-storage" +version = "0.1.0" +dependencies = [ + "dirs", ] [[package]] @@ -43,6 +60,15 @@ dependencies = [ "dirs", ] +[[package]] +name = "aleo-std-time" +version = "0.1.0" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "aleo-std-time" version = "0.1.0" @@ -54,6 +80,15 @@ dependencies = [ "syn 0.15.44", ] +[[package]] +name = "aleo-std-timed" +version = "0.1.0" +dependencies = [ + "proc-macro2 1.0.32", + "quote 1.0.10", + "syn 1.0.82", +] + [[package]] name = "aleo-std-timed" version = "0.1.0" @@ -65,6 +100,13 @@ dependencies = [ "syn 1.0.82", ] +[[package]] +name = "aleo-std-timer" +version = "0.1.0" +dependencies = [ + "colored", +] + [[package]] name = "aleo-std-timer" version = "0.1.0" @@ -1843,7 +1885,7 @@ checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" name = "snarkos" version = "2.0.0" dependencies = [ - "aleo-std", + "aleo-std 0.1.0", "anyhow", "async-trait", "bincode", @@ -2070,7 +2112,7 @@ dependencies = [ name = "snarkvm-parameters" version = "0.7.5" dependencies = [ - "aleo-std", + "aleo-std 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "anyhow", "cfg-if", "curl", diff --git a/Cargo.toml b/Cargo.toml index ad87535138..218dc3cefd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,8 @@ path = "./ledger" version = "2.0.0" [dependencies.aleo-std] -version = "0.1" +#version = "0.1" +path = "../aleo-std" [dependencies.anyhow] version = "1" diff --git a/README.md b/README.md index 2cb92a896d..23b4a1d016 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ USAGE: snarkos [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: + --dev If the flag is set, the node will start in development mode --display If the flag is set, the node will render a read-only display -h, --help Prints help information --norpc If the flag is set, the node will not initialize the RPC server @@ -136,7 +137,7 @@ FLAGS: OPTIONS: --connect Specify the IP address and port of a peer to connect to --miner Specify this as a mining node, with the given miner address - -n, --network Specify the network of this node [default: 2] + --network Specify the network of this node [default: 2] --node Specify the IP address and port for the node server [default: 0.0.0.0:4132] --rpc Specify the IP address and port for the RPC server [default: 0.0.0.0:3032] --password Specify the password for the RPC server [default: pass] @@ -144,6 +145,7 @@ OPTIONS: --verbosity Specify the verbosity of the node [options: 0, 1, 2, 3] [default: 2] SUBCOMMANDS: + clean Removes the ledger files from storage experimental Experimental features help Prints this message or the help of the given subcommand(s) update Updates snarkOS to the latest version @@ -153,12 +155,12 @@ SUBCOMMANDS: In one terminal, start the first node by running: ``` -cargo run --release -- --node 0.0.0.0:4135 --rpc 0.0.0.0:3035 --miner aleo1d5hg2z3ma00382pngntdp68e74zv54jdxy249qhaujhks9c72yrs33ddah +cargo run --release -- --dev --node 0.0.0.0:4135 --rpc 0.0.0.0:3035 --miner aleo1d5hg2z3ma00382pngntdp68e74zv54jdxy249qhaujhks9c72yrs33ddah ``` After the first node starts, in a second terminal, run: ``` -cargo run --release +cargo run --release --dev ``` We welcome all contributions to snarkOS. Please refer to the [license](#7-license) for the terms of contributions. diff --git a/src/node.rs b/src/node.rs index 51b4294a7a..e50643a7a8 100644 --- a/src/node.rs +++ b/src/node.rs @@ -62,6 +62,9 @@ pub struct Node { /// Specify the verbosity of the node [options: 0, 1, 2, 3] #[structopt(default_value = "2", long = "verbosity")] pub verbosity: u8, + /// If the flag is set, the node will start in development mode. + #[structopt(long)] + pub dev: bool, /// If the flag is set, the node will render a read-only display. #[structopt(long)] pub display: bool, @@ -98,19 +101,14 @@ impl Node { } /// Returns the storage path of the node. - pub(crate) fn storage_path(&self, _local_ip: SocketAddr) -> String { + pub(crate) fn storage_path(&self, _local_ip: SocketAddr) -> PathBuf { cfg_if::cfg_if! { if #[cfg(feature = "test")] { // Tests may use any available ports, and removes the storage artifacts afterwards, // so that there is no need to adhere to a specific number assignment logic. - format!("/tmp/snarkos-test-ledger-{}", _local_ip.port()) + PathBuf::from(format!("/tmp/snarkos-test-ledger-{}", _local_ip.port())) } else { - // TODO (howardwu): Remove this check after introducing proper configurations. - assert!( - self.node.port() >= 4130, - "Until configuration files are established, the node port must be at least 4130 or greater" - ); - format!(".ledger-{}", (self.node.port() - 4130)) + aleo_std::aleo_ledger_dir(self.network, self.dev) } } } @@ -189,7 +187,7 @@ pub fn initialize_logger(verbosity: u8, log_sender: Option> #[derive(StructOpt, Debug)] pub enum Command { - #[structopt(name = "clean", about = "Removes the ledger from storage")] + #[structopt(name = "clean", about = "Removes the ledger files from storage")] Clean(Clean), #[structopt(name = "update", about = "Updates snarkOS to the latest version")] Update(Update), @@ -257,31 +255,18 @@ impl Clean { /// Removes the specified ledger from storage. fn remove_ledger(network: u16, is_dev: bool) -> Result { - // Retrieve the starting directory. - let mut path = match is_dev { - // In development mode, the ledger is stored in the snarkOS root directory. - true => PathBuf::from(env!("CARGO_MANIFEST_DIR")), - // In production mode, the ledger is stored in the `~/.aleo/` directory. - false => aleo_std::aleo_dir() - }; - // Construct the path to the ledger in storage. - match is_dev { - // In development mode, the ledger files are stored in a hidden folder. - true => path.push(format!(".ledger-{}", network)), - // In production mode, the ledger files are stored in a visible folder. - false => { - path.push("storage"); - path.push(format!("ledger-{}", network)); - } - }; - + let path = aleo_std::aleo_ledger_dir(network, is_dev); // Check if the path to the ledger exists in storage. if path.exists() { // Remove the ledger files from storage. match std::fs::remove_dir_all(&path) { Ok(_) => Ok(format!("Successfully removed the ledger files from storage. ({})", path.display())), - Err(error) => Err(anyhow!("Failed to remove the ledger files from storage. ({})\n{}", path.display(), error)) + Err(error) => Err(anyhow!( + "Failed to remove the ledger files from storage. ({})\n{}", + path.display(), + error + )), } } else { Ok(format!("No ledger files were found in storage. ({})", path.display())) @@ -294,7 +279,6 @@ pub struct Update { /// Lists all available versions of snarkOS #[structopt(short = "l", long)] list: bool, - /// Suppress outputs to terminal #[structopt(short = "q", long)] quiet: bool,