Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autonomi): remove registers from user data #2535

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -452,36 +452,25 @@ jobs:
set -e
NUM_OF_PUBLIC_FILES=""
NUM_OF_PRIVATE_FILES=""
NUM_OF_REGISTERS=""
NUM_OF_PUBLIC_FILES_IN_VAULT=""
NUM_OF_PRIVATE_FILES_IN_VAULT=""
NUM_OF_REGISTERS_IN_VAULT=""

./target/release/ant --log-output-dest data-dir file list 2>&1 > file_list.txt

./target/release/ant register list | grep register > register_list.txt

NUM_OF_PUBLIC_FILES=`cat file_list.txt | grep "public" | grep -o '[0-9]\+'`
NUM_OF_PRIVATE_FILES=`cat file_list.txt | grep "private" | grep -o '[0-9]\+'`
NUM_OF_REGISTERS=`cat register_list.txt | grep "register" | grep -o '[0-9]\+'`
# when obtaining registers we get random garbage, this is the only hack that works.
NUM_OF_REGISTERS_first=${NUM_OF_REGISTERS%%[ $'\n']*}
echo "NUM_OF_REGISTERS is $NUM_OF_REGISTERS_first"
./target/release/ant --log-output-dest data-dir vault load 2>&1 > vault_data.txt

NUM_OF_PUBLIC_FILES_IN_VAULT=`cat vault_data.txt | grep "public" | grep -o '[0-9]\+'`
NUM_OF_PRIVATE_FILES_IN_VAULT=`cat vault_data.txt| grep "private" | grep -o '[0-9]\+'`
NUM_OF_REGISTERS_IN_VAULT=`cat vault_data.txt | grep "register" | grep -o '[0-9]\+'`

echo "Total Num of local public files is $NUM_OF_PUBLIC_FILES and in vault is $NUM_OF_PUBLIC_FILES_IN_VAULT"
echo "Total Num of local private files is $NUM_OF_PRIVATE_FILES and in vault is $NUM_OF_PRIVATE_FILES_IN_VAULT"
echo "Total Num of local registers is $NUM_OF_REGISTERS_first and in vault is $NUM_OF_REGISTERS_IN_VAULT"

rm -rf file_list.txt register_list.txt vault_data.txt
rm -rf file_list.txt vault_data.txt

python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: local data and vault in network dont match, Local public Files: {sys.argv[1]} and vault public files: {sys.argv[2]} are Not Equal"' $NUM_OF_PUBLIC_FILES $NUM_OF_PUBLIC_FILES_IN_VAULT
python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: local data and vault in network dont match, Local private Files: {sys.argv[1]} and vault private files: {sys.argv[2]} are Not Equal"' $NUM_OF_PRIVATE_FILES $NUM_OF_PRIVATE_FILES_IN_VAULT
python3 -c 'import sys; assert sys.argv[1] == sys.argv[2], f"Error: local data and vault in network dont match, Local registers: {sys.argv[1]} and vault registers: {sys.argv[2]} are Not Equal"' $NUM_OF_REGISTERS_first $NUM_OF_REGISTERS_IN_VAULT
echo "vault synced successfully!"
env:
ANT_LOG: "v"
Expand All @@ -493,7 +482,6 @@ jobs:
run: |
$ErrorActionPreference = "Stop"
./target/release/ant --log-output-dest data-dir file list > file_list.txt 2>&1
./target/release/ant register list > register_list.txt 2>&1
./target/release/ant --log-output-dest data-dir vault load > vault_data.txt 2>&1
env:
ANT_LOG: "v"
Expand Down Expand Up @@ -527,19 +515,14 @@ jobs:
print("NUM_OF_PUBLIC_FILES:", NUM_OF_PUBLIC_FILES)
NUM_OF_PRIVATE_FILES = find_number_before_word("file_list.txt", "private")
print("NUM_OF_PRIVATE_FILES:", NUM_OF_PRIVATE_FILES)
NUM_OF_REGISTERS_FILES = find_number_before_word("register_list.txt", "register")
print("NUM_OF_REGISTERS_FILES:", NUM_OF_REGISTERS_FILES)
NUM_OF_PUBLIC_FILES_IN_VAULT = find_number_before_word("vault_data.txt", "public")
print("NUM_OF_PUBLIC_FILES_IN_VAULT:", NUM_OF_PUBLIC_FILES_IN_VAULT)
NUM_OF_PRIVATE_FILES_IN_VAULT = find_number_before_word("vault_data.txt", "private")
print("NUM_OF_PRIVATE_FILES_IN_VAULT:", NUM_OF_PRIVATE_FILES_IN_VAULT)
NUM_OF_REGISTERS_IN_VAULT = find_number_before_word("vault_data.txt", "register")
print("NUM_OF_PRIVATE_FILES_IN_VAULT:", NUM_OF_PRIVATE_FILES_IN_VAULT)

# Assertions
assert NUM_OF_PUBLIC_FILES == NUM_OF_PUBLIC_FILES_IN_VAULT, f"Error: local data and vault in network dont match, Local public Files: {NUM_OF_PUBLIC_FILES} and vault public files: {NUM_OF_PUBLIC_FILES_IN_VAULT} are Not Equal"
assert NUM_OF_PRIVATE_FILES == NUM_OF_PRIVATE_FILES_IN_VAULT, f"Error: local data and vault in network dont match, Local private Files: {NUM_OF_PRIVATE_FILES} and vault private files: {NUM_OF_PRIVATE_FILES_IN_VAULT} are Not Equal"
assert NUM_OF_REGISTERS_FILES == NUM_OF_REGISTERS_IN_VAULT, f"Error: local data and vault in network dont match, Local registers: {NUM_OF_REGISTERS_FILES} and vault registers: {NUM_OF_REGISTERS_IN_VAULT} are Not Equal"
print("Vault synced successfully!")
env:
ANT_LOG: "v"
Expand Down
20 changes: 2 additions & 18 deletions ant-cli/src/access/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ use std::collections::HashMap;
use autonomi::client::{
address::{addr_to_str, str_to_addr},
files::{archive::PrivateArchiveAccess, archive_public::ArchiveAddr},
registers::{RegisterAddress, RegisterSecretKey},
registers::RegisterAddress,
vault::UserData,
};
use color_eyre::eyre::Result;

use super::{
data_dir::get_client_data_dir_path,
keys::{create_register_signing_key_file, get_register_signing_key},
};
use super::data_dir::get_client_data_dir_path;

use serde::{Deserialize, Serialize};

Expand All @@ -30,14 +27,10 @@ struct PrivateFileArchive {
}

pub fn get_local_user_data() -> Result<UserData> {
let register_sk = get_register_signing_key().map(|k| k.to_hex()).ok();
let registers = get_local_registers()?;
let file_archives = get_local_public_file_archives()?;
let private_file_archives = get_local_private_file_archives()?;

let user_data = UserData {
register_sk,
registers,
file_archives,
private_file_archives,
};
Expand Down Expand Up @@ -119,15 +112,6 @@ pub fn get_local_public_file_archives() -> Result<HashMap<ArchiveAddr, String>>
}

pub fn write_local_user_data(user_data: &UserData) -> Result<()> {
if let Some(register_key) = &user_data.register_sk {
let sk = RegisterSecretKey::from_hex(register_key)?;
create_register_signing_key_file(sk)?;
}

for (register, name) in user_data.registers.iter() {
write_local_register(register, name)?;
}

for (archive, name) in user_data.file_archives.iter() {
write_local_public_file_archive(addr_to_str(*archive), name)?;
}
Expand Down
5 changes: 0 additions & 5 deletions ant-cli/src/commands/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ pub async fn create(peers: Vec<Multiaddr>) -> Result<()> {
let local_user_data = crate::user_data::get_local_user_data()?;
let file_archives_len = local_user_data.file_archives.len();
let private_file_archives_len = local_user_data.private_file_archives.len();
let registers_len = local_user_data.registers.len();

println!("Pushing to network vault...");
let total_cost = client
Expand All @@ -53,7 +52,6 @@ pub async fn create(peers: Vec<Multiaddr>) -> Result<()> {
println!("Vault contains:");
println!("{file_archives_len} public file archive(s)");
println!("{private_file_archives_len} private file archive(s)");
println!("{registers_len} register(s)");
Ok(())
}

Expand All @@ -80,7 +78,6 @@ pub async fn sync(peers: Vec<Multiaddr>, force: bool) -> Result<()> {
let local_user_data = crate::user_data::get_local_user_data()?;
let file_archives_len = local_user_data.file_archives.len();
let private_file_archives_len = local_user_data.private_file_archives.len();
let registers_len = local_user_data.registers.len();
client
.put_user_data_to_vault(&vault_sk, wallet.into(), local_user_data)
.await?;
Expand All @@ -89,7 +86,6 @@ pub async fn sync(peers: Vec<Multiaddr>, force: bool) -> Result<()> {
println!("Vault contains:");
println!("{file_archives_len} public file archive(s)");
println!("{private_file_archives_len} private file archive(s)");
println!("{registers_len} register(s)");
Ok(())
}

Expand All @@ -108,6 +104,5 @@ pub async fn load(peers: Vec<Multiaddr>) -> Result<()> {
"{} private file archive(s)",
user_data.private_file_archives.len()
);
println!("{} register(s)", user_data.registers.len());
Ok(())
}
4 changes: 2 additions & 2 deletions autonomi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ default = ["vault"]
external-signer = ["ant-evm/external-signer"]
extension-module = ["pyo3/extension-module"]
fs = ["tokio/fs"]
full = ["registers", "vault", "fs"]
full = ["vault", "fs"]
local = ["ant-networking/local", "ant-evm/local"]
loud = []
registers = []
vault = ["registers"]
vault = []

[dependencies]
ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" }
Expand Down
5 changes: 0 additions & 5 deletions autonomi/src/client/vault/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::client::data::PutError;
use crate::client::files::archive::PrivateArchiveAccess;
use crate::client::files::archive_public::ArchiveAddr;
use crate::client::payment::PaymentOption;
use crate::client::registers::RegisterAddress;
use crate::client::vault::VaultError;
use crate::client::vault::{app_name_to_vault_content_type, VaultContentType, VaultSecretKey};
use crate::client::Client;
Expand All @@ -32,10 +31,6 @@ pub static USER_DATA_VAULT_CONTENT_IDENTIFIER: LazyLock<VaultContentType> =
/// Using User Data Vault is optional, one can decide to keep all their data locally instead.
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
pub struct UserData {
/// The register secret key hex encoded
pub register_sk: Option<String>,
/// Owned register addresses, along with their names (can be empty)
pub registers: HashMap<RegisterAddress, String>,
/// Owned file archive addresses, along with their names (can be empty)
pub file_archives: HashMap<ArchiveAddr, String>,
/// Owned private file archives, along with their names (can be empty)
Expand Down
Loading