From 23099757963a67e65b6b6af18ef6dc082331119a Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Wed, 16 Oct 2024 12:46:33 +0530 Subject: [PATCH 1/2] fix: use the correct client cli name and paths --- .github/workflows/benchmark-prs.yml | 2 +- .github/workflows/generate-benchmark-charts.yml | 8 ++++---- .github/workflows/memcheck.yml | 2 +- .github/workflows/merge.yml | 12 ++++++------ .github/workflows/nightly_wan.yml | 8 ++++---- .github/workflows/nightly_wan_churn.yml | 2 +- README.md | 4 ++-- autonomi-cli/README.md | 2 +- autonomi-cli/benches/files.rs | 2 +- autonomi-cli/src/access/data_dir.rs | 2 +- autonomi-cli/src/opt.rs | 6 +++--- sn_logging/src/layers.rs | 6 +----- 12 files changed, 26 insertions(+), 30 deletions(-) diff --git a/.github/workflows/benchmark-prs.yml b/.github/workflows/benchmark-prs.yml index af1b3ce0fe..8c6dab409e 100644 --- a/.github/workflows/benchmark-prs.yml +++ b/.github/workflows/benchmark-prs.yml @@ -5,7 +5,7 @@ on: pull_request env: CARGO_INCREMENTAL: "0" RUST_BACKTRACE: 1 - CLIENT_DATA_PATH: /home/runner/.local/share/safe/client + CLIENT_DATA_PATH: /home/runner/.local/share/safe/autonomi NODE_DATA_PATH: /home/runner/.local/share/safe/node jobs: diff --git a/.github/workflows/generate-benchmark-charts.yml b/.github/workflows/generate-benchmark-charts.yml index 27a737a7a7..b8c6a10ffe 100644 --- a/.github/workflows/generate-benchmark-charts.yml +++ b/.github/workflows/generate-benchmark-charts.yml @@ -67,7 +67,7 @@ jobs: # Criterion outputs the actual bench results to stderr "2>&1 tee output.txt" takes stderr, # passes to tee which displays it in the terminal and writes to output.txt run: | - cargo criterion --features=local --message-format=json 2>&1 -p autonomi | tee -a output.txt + cargo criterion --features=local --message-format=json 2>&1 -p autonomi-cli | tee -a output.txt cat output.txt | rg benchmark-complete | jq -s 'map({ name: (.id | split("/"))[-1], unit: "MiB/s", @@ -158,17 +158,17 @@ jobs: shell: bash run: | peak_mem_usage=$( - rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs --glob safe.* -o --no-line-number --no-filename | + rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs/*/*.log -o --no-line-number --no-filename | awk -F':' '/"memory_used_mb":/{print $2}' | sort -n | tail -n 1 ) total_mem=$( - rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs --glob safe.* -o --no-line-number --no-filename | + rg '"memory_used_mb":[^,]*' $CLIENT_DATA_PATH/logs/*/*.log -o --no-line-number --no-filename | awk -F':' '/"memory_used_mb":/ {sum += $2} END {printf "%.0f\n", sum}' ) num_of_times=$( - rg "\"memory_used_mb\"" $CLIENT_DATA_PATH/logs --glob safe.* -c --stats | + rg "\"memory_used_mb\"" $CLIENT_DATA_PATH/logs/*/*.log -c --stats | rg "(\d+) matches" | rg "\d+" -o ) diff --git a/.github/workflows/memcheck.yml b/.github/workflows/memcheck.yml index 55d3790bb5..20116e6149 100644 --- a/.github/workflows/memcheck.yml +++ b/.github/workflows/memcheck.yml @@ -11,7 +11,7 @@ on: env: SAFE_DATA_PATH: /home/runner/.local/share/safe - CLIENT_DATA_PATH: /home/runner/.local/share/safe/client + CLIENT_DATA_PATH: /home/runner/.local/share/safe/autonomi NODE_DATA_PATH: /home/runner/.local/share/safe/node BOOTSTRAP_NODE_DATA_PATH: /home/runner/.local/share/safe/bootstrap_node RESTART_TEST_NODE_DATA_PATH: /home/runner/.local/share/safe/restart_node diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 1b5395b028..3c50891759 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -313,7 +313,7 @@ jobs: - name: Delete current register signing key shell: bash - run: rm -rf ${{ matrix.safe_path }}/client + run: rm -rf ${{ matrix.safe_path }}/autonomi - name: Generate new register signing key run: ./target/release/autonomi --log-output-dest=data-dir register generate-key @@ -932,7 +932,7 @@ jobs: # ls -l /home/runner/.local/share/safe # rm -rf /home/runner/.local/share/safe/test_faucet # rm -rf /home/runner/.local/share/safe/test_genesis - # rm -rf /home/runner/.local/share/safe/client + # rm -rf /home/runner/.local/share/safe/autonomi # env: # SN_LOG: "all" # timeout-minutes: 5 @@ -973,7 +973,7 @@ jobs: # ls -l /home/runner/.local/share/safe # rm -rf /home/runner/.local/share/safe/test_faucet # rm -rf /home/runner/.local/share/safe/test_genesis - # rm -rf /home/runner/.local/share/safe/client + # rm -rf /home/runner/.local/share/safe/autonomi # ~/safe --log-output-dest=data-dir wallet create --no-password # if GENESIS_PK=a9925296499299fdbf4412509d342a92e015f5b996e9acd1d2ab7f2326e3ad05934326efdc345345a95e973ac1bb6637 GENESIS_SK=40f6bbc870355c68138ac70b450b6425af02b49874df3f141b7018378ceaac66 nohup ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1); then # echo "Faucet with different genesis key not rejected!" @@ -995,7 +995,7 @@ jobs: # ls -l /home/runner/.local/share/safe # rm -rf /home/runner/.local/share/safe/test_faucet # rm -rf /home/runner/.local/share/safe/test_genesis - # rm -rf /home/runner/.local/share/safe/client + # rm -rf /home/runner/.local/share/safe/autonomi # target/release/faucet server & # sleep 60 # env: @@ -1161,7 +1161,7 @@ jobs: # ls $CLIENT_DATA_PATH/wallet/confirmed_spends -l # ls $CLIENT_DATA_PATH/logs -l # env: - # CLIENT_DATA_PATH: /home/runner/.local/share/safe/client + # CLIENT_DATA_PATH: /home/runner/.local/share/safe/autonomi # timeout-minutes: 1 # replication_bench_with_heavy_upload: @@ -1169,7 +1169,7 @@ jobs: # name: Replication bench with heavy upload # runs-on: ubuntu-latest # env: - # CLIENT_DATA_PATH: /home/runner/.local/share/safe/client + # CLIENT_DATA_PATH: /home/runner/.local/share/safe/autonomi # steps: # - uses: actions/checkout@v4 diff --git a/.github/workflows/nightly_wan.yml b/.github/workflows/nightly_wan.yml index 9c84f58488..e5f4a42511 100644 --- a/.github/workflows/nightly_wan.yml +++ b/.github/workflows/nightly_wan.yml @@ -129,7 +129,7 @@ jobs: path: | ~/.local/share/safe/node/*/logs/*.log* ~/.local/share/safe/*/*/*.log* - ~/.local/share/safe/client/logs/*/*.log* + ~/.local/share/safe/autonomi/logs/*/*.log* - name: destroy network if: always() @@ -235,7 +235,7 @@ jobs: # path: | # ~/.local/share/safe/node/*/logs/*.log* # ~/.local/share/safe/*/*/*.log* - # ~/.local/share/safe/client/logs/*/*.log* + # ~/.local/share/safe/autonomi/logs/*/*.log* # - name: destroy network # uses: maidsafe/sn-testnet-control-action/destroy-network@main @@ -349,7 +349,7 @@ jobs: # path: | # ~/.local/share/safe/node/*/logs/*.log* # ~/.local/share/safe/*/*/*.log* - # ~/.local/share/safe/client/logs/*/*.log* + # ~/.local/share/safe/autonomi/logs/*/*.log* # # - name: Stop the WAN network # if: always() @@ -555,7 +555,7 @@ jobs: # path: | # ~/.local/share/safe/node/*/logs/*.log* # ~/.local/share/safe/*/*/*.log* - # ~/.local/share/safe/client/logs/*/*.log* + # ~/.local/share/safe/autonomi/logs/*/*.log* # # - name: Stop the WAN network # if: always() diff --git a/.github/workflows/nightly_wan_churn.yml b/.github/workflows/nightly_wan_churn.yml index 5101f8fdd6..2cbf72fd8c 100644 --- a/.github/workflows/nightly_wan_churn.yml +++ b/.github/workflows/nightly_wan_churn.yml @@ -127,7 +127,7 @@ jobs: path: | ~/.local/share/safe/node/*/logs/*.log* ~/.local/share/safe/*/*/*.log* - ~/.local/share/safe/client/logs/*/*.log* + ~/.local/share/safe/autonomi/logs/*/*.log* - name: Stop the WAN network if: always() diff --git a/README.md b/README.md index 31d6c73e43..e591b0ca1b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Libp2p.
### For Users -- [CLI](https://github.com/maidsafe/safe_network/blob/main/autonomi_cli/README.md) The Command Line +- [CLI](https://github.com/maidsafe/safe_network/blob/main/autonomi-cli/README.md) The Command Line Interface, allowing users to interact with the network from their terminal. - [Node](https://github.com/maidsafe//safe_network/blob/main/sn_node/README.md) The backbone of the safe network. Nodes can be run on commodity hardware and provide storage space and validation of @@ -65,7 +65,7 @@ cargo build --release --features=network-contacts --bin safenode - [Autonomi API](https://github.com/maidsafe/safe_network/blob/main/autonomi/README.md) The client APIs allowing use of the Autonomi Network to users and developers. -- [Autonomi CLI](https://github.com/maidsafe/safe_network/blob/main/autonomi_cli/README.md) The Command Line +- [Autonomi CLI](https://github.com/maidsafe/safe_network/blob/main/autonomi-cli/README.md) The Command Line Interface, allowing users to interact with the network from their terminal. - [Node](https://github.com/maidsafe/safe_network/blob/main/sn_node/README.md) The backbone of the autonomi network. Nodes can be run on commodity hardware and run the Network. diff --git a/autonomi-cli/README.md b/autonomi-cli/README.md index b10d2128fb..42a487bd38 100644 --- a/autonomi-cli/README.md +++ b/autonomi-cli/README.md @@ -1,7 +1,7 @@ # A CLI for the Autonomi Network ``` -Usage: autonomi_cli [OPTIONS] +Usage: autonomi [OPTIONS] Commands: file Operations related to file handling diff --git a/autonomi-cli/benches/files.rs b/autonomi-cli/benches/files.rs index f545936334..4b4794c16e 100644 --- a/autonomi-cli/benches/files.rs +++ b/autonomi-cli/benches/files.rs @@ -99,7 +99,7 @@ fn get_cli_path() -> PathBuf { path.push("target"); } path.push("release"); - path.push("autonomi_cli"); + path.push("autonomi"); path } diff --git a/autonomi-cli/src/access/data_dir.rs b/autonomi-cli/src/access/data_dir.rs index af0db16c2c..b694d3f6fb 100644 --- a/autonomi-cli/src/access/data_dir.rs +++ b/autonomi-cli/src/access/data_dir.rs @@ -13,7 +13,7 @@ pub fn get_client_data_dir_path() -> Result { let mut home_dirs = dirs_next::data_dir() .ok_or_else(|| eyre!("Failed to obtain data dir, your OS might not be supported."))?; home_dirs.push("safe"); - home_dirs.push("client"); + home_dirs.push("autonomi"); std::fs::create_dir_all(home_dirs.as_path()).wrap_err("Failed to create data dir")?; Ok(home_dirs) } diff --git a/autonomi-cli/src/opt.rs b/autonomi-cli/src/opt.rs index 8f3fb20967..a49f6029b1 100644 --- a/autonomi-cli/src/opt.rs +++ b/autonomi-cli/src/opt.rs @@ -27,9 +27,9 @@ pub(crate) struct Opt { /// `data-dir` is the default value. /// /// The data directory location is platform specific: - /// - Linux: $HOME/.local/share/safe/client/logs - /// - macOS: $HOME/Library/Application Support/safe/client/logs - /// - Windows: C:\Users\\AppData\Roaming\safe\client\logs + /// - Linux: $HOME/.local/share/safe/autonomi/logs + /// - macOS: $HOME/Library/Application Support/safe/autonomi/logs + /// - Windows: C:\Users\\AppData\Roaming\safe\autonomi\logs #[allow(rustdoc::invalid_html_tags)] #[clap(long, value_parser = LogOutputDest::parse_from_str, verbatim_doc_comment, default_value = "data-dir")] pub log_output_dest: LogOutputDest, diff --git a/sn_logging/src/layers.rs b/sn_logging/src/layers.rs index 91f771e6b9..4bc1f46996 100644 --- a/sn_logging/src/layers.rs +++ b/sn_logging/src/layers.rs @@ -266,12 +266,10 @@ fn get_logging_targets(logging_env_value: &str) -> Result> if contains_keyword_all_sn_logs || contains_keyword_verbose_sn_logs { let mut t = BTreeMap::from_iter(vec![ // bins - ("autonomi_cli".to_string(), Level::TRACE), + ("autonomi-cli".to_string(), Level::TRACE), ("evm_testnet".to_string(), Level::TRACE), - ("faucet".to_string(), Level::TRACE), ("safenode".to_string(), Level::TRACE), ("safenode_rpc_client".to_string(), Level::TRACE), - ("safe".to_string(), Level::TRACE), ("safenode_manager".to_string(), Level::TRACE), ("safenodemand".to_string(), Level::TRACE), // libs @@ -279,8 +277,6 @@ fn get_logging_targets(logging_env_value: &str) -> Result> ("evmlib".to_string(), Level::TRACE), ("sn_evm".to_string(), Level::TRACE), ("sn_build_info".to_string(), Level::TRACE), - ("sn_client".to_string(), Level::TRACE), - ("sn_faucet".to_string(), Level::TRACE), ("sn_logging".to_string(), Level::TRACE), ("sn_node_manager".to_string(), Level::TRACE), ("sn_node_rpc_client".to_string(), Level::TRACE), From 8fb0c1ff93ceb2552b596277ce60ec4de91eb195 Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Thu, 17 Oct 2024 00:26:36 +0530 Subject: [PATCH 2/2] chore: more logging for the cli --- autonomi-cli/src/actions/connect.rs | 2 ++ autonomi-cli/src/actions/download.rs | 2 ++ autonomi-cli/src/commands/file.rs | 5 +++++ autonomi-cli/src/commands/register.rs | 16 +++++++++++++++- autonomi/src/client/mod.rs | 2 ++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/autonomi-cli/src/actions/connect.rs b/autonomi-cli/src/actions/connect.rs index 9eccb3bbfb..cfe971d14e 100644 --- a/autonomi-cli/src/actions/connect.rs +++ b/autonomi-cli/src/actions/connect.rs @@ -24,10 +24,12 @@ pub async fn connect_to_network(peers: Vec) -> Result { match Client::connect(&peers).await { Ok(client) => { + info!("Connected to the Network"); progress_bar.finish_with_message("Connected to the Network"); Ok(client) } Err(e) => { + error!("Failed to connect to the network: {e}"); progress_bar.finish_with_message("Failed to connect to the network"); bail!("Failed to connect to the network: {e}") } diff --git a/autonomi-cli/src/actions/download.rs b/autonomi-cli/src/actions/download.rs index ba004930e3..cd8e37615e 100644 --- a/autonomi-cli/src/actions/download.rs +++ b/autonomi-cli/src/actions/download.rs @@ -41,12 +41,14 @@ pub async fn download(addr: &str, dest_path: &str, client: &mut Client) -> Resul progress_bar.finish_and_clear(); if all_errs.is_empty() { + info!("Successfully downloaded data at: {addr}"); println!("Successfully downloaded data at: {addr}"); Ok(()) } else { let err_no = all_errs.len(); eprintln!("{err_no} errors while downloading data at: {addr}"); eprintln!("{all_errs:#?}"); + error!("Errors while downloading data at {addr}: {all_errs:#?}"); Err(eyre!("Errors while downloading data")) } } diff --git a/autonomi-cli/src/commands/file.rs b/autonomi-cli/src/commands/file.rs index d99a848214..f3c49d8cb4 100644 --- a/autonomi-cli/src/commands/file.rs +++ b/autonomi-cli/src/commands/file.rs @@ -17,6 +17,7 @@ pub async fn cost(file: &str, peers: Vec) -> Result<()> { let client = crate::actions::connect_to_network(peers).await?; println!("Getting upload cost..."); + info!("Calculating cost for file: {file}"); let cost = client .file_cost(&PathBuf::from(file)) .await @@ -24,6 +25,7 @@ pub async fn cost(file: &str, peers: Vec) -> Result<()> { println!("Estimate cost to upload file: {file}"); println!("Total cost: {cost}"); + info!("Total cost: {cost} for file: {file}"); Ok(()) } pub async fn upload(file: &str, peers: Vec) -> Result<()> { @@ -33,6 +35,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { let (upload_summary_thread, upload_completed_tx) = collect_upload_summary(event_receiver); println!("Uploading data to network..."); + info!("Uploading file: {file}"); let xor_name = client .dir_upload(PathBuf::from(file), &wallet) @@ -42,6 +45,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { println!("Successfully uploaded: {file}"); println!("At address: {addr}"); + info!("Successfully uploaded: {file} at address: {addr}"); if let Ok(()) = upload_completed_tx.send(()) { let summary = upload_summary_thread.await?; if summary.record_count == 0 { @@ -50,6 +54,7 @@ pub async fn upload(file: &str, peers: Vec) -> Result<()> { println!("Number of chunks uploaded: {}", summary.record_count); println!("Total cost: {} AttoTokens", summary.tokens_spent); } + info!("Summary for upload of file {file} at {addr:?}: {summary:?}"); } Ok(()) diff --git a/autonomi-cli/src/commands/register.rs b/autonomi-cli/src/commands/register.rs index d559e6cc55..b5be4f0230 100644 --- a/autonomi-cli/src/commands/register.rs +++ b/autonomi-cli/src/commands/register.rs @@ -21,6 +21,7 @@ pub fn generate_key(overwrite: bool) -> Result<()> { // check if the key already exists let key_path = crate::keys::get_register_signing_key_path()?; if key_path.exists() && !overwrite { + error!("Register key already exists at: {key_path:?}"); return Err(eyre!("Register key already exists at: {}", key_path.display())) .with_suggestion(|| "if you want to overwrite the existing key, run the command with the --overwrite flag") .with_warning(|| "overwriting the existing key might result in loss of access to any existing registers created using that key"); @@ -30,6 +31,7 @@ pub fn generate_key(overwrite: bool) -> Result<()> { let key = RegisterSecretKey::random(); let path = crate::keys::create_register_signing_key_file(key) .wrap_err("Failed to create new register key")?; + info!("Created new register key at: {path:?}"); println!("✅ Created new register key at: {}", path.display()); Ok(()) } @@ -43,6 +45,7 @@ pub async fn cost(name: &str, peers: Vec) -> Result<()> { .register_cost(name.to_string(), register_key) .await .wrap_err("Failed to get cost for register")?; + info!("Estimated cost to create a register with name {name}: {cost}"); println!("✅ The estimated cost to create a register with name {name} is: {cost}"); Ok(()) } @@ -56,8 +59,10 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec let (upload_summary_thread, upload_completed_tx) = collect_upload_summary(event_receiver); println!("Creating register with name: {name}"); + info!("Creating register with name: {name}"); let register = if public { println!("With public write access"); + info!("With public write access"); let permissions = RegisterPermissions::new_anyone_can_write(); client .register_create_with_permissions( @@ -71,6 +76,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec .wrap_err("Failed to create register")? } else { println!("With private write access"); + info!("With private write access"); client .register_create( value.as_bytes().to_vec().into(), @@ -87,6 +93,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec println!("✅ Register created at address: {address}"); println!("With name: {name}"); println!("And initial value: [{value}]"); + info!("✅ Register created at address: {address} with name: {name}"); if let Ok(()) = upload_completed_tx.send(()) { let summary = upload_summary_thread.await?; @@ -95,6 +102,7 @@ pub async fn create(name: &str, value: &str, public: bool, peers: Vec } else { println!("Total cost: {} AttoTokens", summary.tokens_spent); } + info!("Summary of register creation: {summary:?}"); } Ok(()) @@ -116,13 +124,16 @@ pub async fn edit(address: String, name: bool, value: &str, peers: Vec) -> Result<( }; println!("Getting register at address: {address}"); + info!("Getting register at address: {address}"); let register = client .register_get(address) .await @@ -157,6 +170,7 @@ pub async fn get(address: String, name: bool, peers: Vec) -> Result<( let values = register.values(); println!("✅ Register found at address: {address}"); + info!("Register found at address: {address}"); match values.as_slice() { [one] => println!("With value: [{:?}]", String::from_utf8_lossy(one)), _ => { diff --git a/autonomi/src/client/mod.rs b/autonomi/src/client/mod.rs index f19216fe84..df5dab4ec0 100644 --- a/autonomi/src/client/mod.rs +++ b/autonomi/src/client/mod.rs @@ -197,11 +197,13 @@ async fn handle_event_receiver( } /// Events that can be broadcasted by the client. +#[derive(Debug, Clone)] pub enum ClientEvent { UploadComplete(UploadSummary), } /// Summary of an upload operation. +#[derive(Debug, Clone)] pub struct UploadSummary { pub record_count: usize, pub tokens_spent: Amount,