Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into docs-autonomi-rustdoc…
Browse files Browse the repository at this point in the history
…-add
  • Loading branch information
b-zee committed Dec 6, 2024
2 parents 57dd082 + a9110b1 commit 1f27152
Show file tree
Hide file tree
Showing 25 changed files with 107 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metrics/prometheus/prometheus.yml
.DS_Store
*.dot

sn_node_manager/.vagrant
ant-node-manager/.vagrant

# Python
.venv/
Expand Down
2 changes: 1 addition & 1 deletion ant-networking/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::target_arch::Instant;

const MAX_CONTINUOUS_HDD_WRITE_ERROR: usize = 5;

// Shall be synced with `sn_node::PERIODIC_REPLICATION_INTERVAL_MAX_S`
// Shall be synced with `ant_node::PERIODIC_REPLICATION_INTERVAL_MAX_S`
const REPLICATION_TIMEOUT: Duration = Duration::from_secs(45);

// Throttles replication to at most once every 30 seconds
Expand Down
2 changes: 1 addition & 1 deletion ant-networking/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ impl NetworkBuilder {
let metrics_recorder = NetworkMetricsRecorder::new(&mut metrics_registries);
let metadata_sub_reg = metrics_registries
.metadata
.sub_registry_with_prefix("ant-networking");
.sub_registry_with_prefix("ant_networking");

metadata_sub_reg.register(
"peer_id",
Expand Down
4 changes: 2 additions & 2 deletions ant-networking/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl NetworkMetricsRecorder {
let libp2p_metrics = Libp2pMetrics::new(&mut registries.standard_metrics);
let sub_registry = registries
.standard_metrics
.sub_registry_with_prefix("ant-networking");
.sub_registry_with_prefix("ant_networking");

let records_stored = Gauge::default();
sub_registry.register(
Expand Down Expand Up @@ -199,7 +199,7 @@ impl NetworkMetricsRecorder {

let extended_metrics_sub_registry = registries
.extended_metrics
.sub_registry_with_prefix("ant-networking");
.sub_registry_with_prefix("ant_networking");
let shunned_count_across_time_frames = Family::default();
extended_metrics_sub_registry.register(
"shunned_count_across_time_frames",
Expand Down
2 changes: 1 addition & 1 deletion ant-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ default_dir = AntNode.get_default_root_dir(peer_id)

## Testing

To run tests, navigate to the `sn_node` directory and execute:
To run tests, navigate to the `ant-node` directory and execute:

```bash
cargo test
Expand Down
2 changes: 1 addition & 1 deletion ant-node/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl NodeEventsChannel {
self.0.subscribe()
}

// Broadcast a new event, meant to be a helper only used by the sn_node's internals.
// Broadcast a new event, meant to be a helper only used by the ant-node's internals.
pub(crate) fn broadcast(&self, event: NodeEvent) {
let event_string = format!("{event:?}");
if let Err(err) = self.0.send(event) {
Expand Down
8 changes: 4 additions & 4 deletions ant-node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ enum RecordType {

impl NodeMetricsRecorder {
pub(crate) fn new(registries: &mut MetricsRegistries) -> Self {
let node_metadata_sub_registry = registries.metadata.sub_registry_with_prefix("sn_node");
let node_metadata_sub_registry = registries.metadata.sub_registry_with_prefix("ant_node");
node_metadata_sub_registry.register(
"safenode_version",
"antnode_version",
"The version of the safe node",
Info::new(vec![(
"safenode_version".to_string(),
"antnode_version".to_string(),
env!("CARGO_PKG_VERSION").to_string(),
)]),
);

let sub_registry = registries
.standard_metrics
.sub_registry_with_prefix("sn_node");
.sub_registry_with_prefix("ant_node");

let put_record_ok = Family::default();
sub_registry.register(
Expand Down
6 changes: 5 additions & 1 deletion ant-node/tests/verify_data_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ async fn verify_location(all_peers: &Vec<PeerId>, node_rpc_addresses: &[SocketAd
}
}

if !failed.is_empty() {
// The retry will take long time, result in the overall test failed due to timedout.
// Hence need an early bail out here.
let just_missed_one = failed.values().all(|failed_peers| failed_peers.len() <= 1);

if !(failed.is_empty() || just_missed_one) {
error!("Verification failed for {:?} entries", failed.len());
println!("Verification failed for {:?} entries", failed.len());

Expand Down
8 changes: 4 additions & 4 deletions ant-protocol/src/storage/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub type TransactionContent = [u8; 32];
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, Ord, PartialOrd)]
pub struct Transaction {
pub owner: PublicKey,
pub parent: Vec<PublicKey>,
pub parents: Vec<PublicKey>,
pub content: TransactionContent,
pub outputs: Vec<(PublicKey, TransactionContent)>,
/// signs the above 4 fields with the owners key
Expand All @@ -29,14 +29,14 @@ pub struct Transaction {
impl Transaction {
pub fn new(
owner: PublicKey,
parent: Vec<PublicKey>,
parents: Vec<PublicKey>,
content: TransactionContent,
outputs: Vec<(PublicKey, TransactionContent)>,
signature: Signature,
) -> Self {
Self {
owner,
parent,
parents,
content,
outputs,
signature,
Expand All @@ -53,7 +53,7 @@ impl Transaction {
bytes.extend_from_slice("parent".as_bytes());
bytes.extend_from_slice(
&self
.parent
.parents
.iter()
.map(|p| p.to_bytes())
.collect::<Vec<_>>()
Expand Down
12 changes: 9 additions & 3 deletions autonomi/src/client/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ impl Archive {
.as_secs();
meta.modified = now;
self.map.insert(new_path.to_path_buf(), (data_addr, meta));
debug!("Renamed file successfully in the archive, old path: {old_path:?} new_path: {new_path:?}");
Ok(())
}

/// Add a file to a local archive
/// Note that this does not upload the archive to the network
pub fn add_file(&mut self, path: PathBuf, data_addr: DataAddr, meta: Metadata) {
self.map.insert(path, (data_addr, meta));
self.map.insert(path.clone(), (data_addr, meta));
debug!("Added a new file to the archive, path: {:?}", path);
}

/// List all files in the archive
Expand Down Expand Up @@ -192,14 +194,18 @@ impl Client {
let bytes = archive
.into_bytes()
.map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.data_put(bytes, wallet.into()).await
let result = self.data_put(bytes, wallet.into()).await;
debug!("Uploaded archive {archive:?} to the network and the address is {result:?}");
result
}

/// Get the cost to upload an archive
pub async fn archive_cost(&self, archive: Archive) -> Result<AttoTokens, CostError> {
let bytes = archive
.into_bytes()
.map_err(|e| CostError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.data_cost(bytes).await
let result = self.data_cost(bytes).await;
debug!("Calculated the cost to upload archive {archive:?} is {result:?}");
result
}
}
8 changes: 6 additions & 2 deletions autonomi/src/client/archive_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ impl PrivateArchive {
.as_secs();
meta.modified = now;
self.map.insert(new_path.to_path_buf(), (data_addr, meta));
debug!("Renamed file successfully in the private archive, old path: {old_path:?} new_path: {new_path:?}");
Ok(())
}

/// Add a file to a local archive
/// Note that this does not upload the archive to the network
pub fn add_file(&mut self, path: PathBuf, data_map: PrivateDataAccess, meta: Metadata) {
self.map.insert(path, (data_map, meta));
self.map.insert(path.clone(), (data_map, meta));
debug!("Added a new file to the archive, path: {:?}", path);
}

/// List all files in the archive
Expand Down Expand Up @@ -129,6 +131,8 @@ impl Client {
let bytes = archive
.into_bytes()
.map_err(|e| PutError::Serialization(format!("Failed to serialize archive: {e:?}")))?;
self.private_data_put(bytes, payment_option).await
let result = self.private_data_put(bytes, payment_option).await;
debug!("Uploaded private archive {archive:?} to the network and address is {result:?}");
result
}
}
8 changes: 7 additions & 1 deletion autonomi/src/client/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl Client {
.fetch_from_data_map_chunk(data_map_chunk.value())
.await?;

debug!("Successfully fetched a blob of data from the network");
Ok(data)
}

Expand Down Expand Up @@ -214,7 +215,7 @@ impl Client {
info!("Getting chunk: {addr:?}");

let key = NetworkAddress::from_chunk_address(ChunkAddress::new(addr)).to_record_key();

debug!("Fetching chunk from network at: {key:?}");
let get_cfg = GetRecordCfg {
get_quorum: Quorum::One,
retry_strategy: None,
Expand All @@ -234,6 +235,10 @@ impl Client {
let chunk: Chunk = try_deserialize_record(&record)?;
Ok(chunk)
} else {
error!(
"Record kind mismatch: expected Chunk, got {:?}",
header.kind
);
Err(NetworkError::RecordKindMismatch(RecordKind::Chunk).into())
}
}
Expand Down Expand Up @@ -267,6 +272,7 @@ impl Client {
.map(|quote| quote.2.cost.as_atto())
.sum::<Amount>(),
);
debug!("Total cost calculated: {total_cost:?}");
Ok(total_cost)
}

Expand Down
1 change: 1 addition & 0 deletions autonomi/src/client/data_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Client {
);
let data = self.fetch_from_data_map_chunk(data_map.0.value()).await?;

debug!("Successfully fetched a blob of private data from the network");
Ok(data)
}

Expand Down
4 changes: 4 additions & 0 deletions autonomi/src/client/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ impl Client {
let (quote_payments, free_chunks) = extract_quote_payments(&cost_map);
let quotes = cost_map_to_quotes(cost_map);

debug!(
"Got the quotes , quote_payments and freechunks from the network {:?}",
(quotes.clone(), quote_payments.clone(), free_chunks.clone())
);
Ok((quotes, quote_payments, free_chunks))
}
}
Expand Down
15 changes: 13 additions & 2 deletions autonomi/src/client/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ impl Client {
let data = self.data_get(data_addr).await?;
if let Some(parent) = to_dest.parent() {
tokio::fs::create_dir_all(parent).await?;
debug!("Created parent directories {parent:?} for {to_dest:?}");
}
tokio::fs::write(to_dest, data).await?;
tokio::fs::write(to_dest.clone(), data).await?;
debug!("Downloaded file to {to_dest:?} from the network address {data_addr:?}");
Ok(())
}

Expand All @@ -98,9 +100,15 @@ impl Client {
to_dest: PathBuf,
) -> Result<(), DownloadError> {
let archive = self.archive_get(archive_addr).await?;
debug!("Downloaded archive for the directory from the network at {archive_addr:?}");
for (path, addr, _meta) in archive.iter() {
self.file_download(*addr, to_dest.join(path)).await?;
}
debug!(
"All files in the directory downloaded to {:?} from the network address {:?}",
to_dest.parent(),
archive_addr
);
Ok(())
}

Expand Down Expand Up @@ -156,6 +164,7 @@ impl Client {
info!("Complete archive upload completed in {:?}", start.elapsed());
#[cfg(feature = "loud")]
println!("Upload completed in {:?}", start.elapsed());
debug!("Directory uploaded to the network at {arch_addr:?}");
Ok(arch_addr)
}

Expand All @@ -170,9 +179,10 @@ impl Client {
#[cfg(feature = "loud")]
println!("Uploading file: {path:?}");

let data = tokio::fs::read(path).await?;
let data = tokio::fs::read(path.clone()).await?;
let data = Bytes::from(data);
let addr = self.data_put(data, wallet.into()).await?;
debug!("File {path:?} uploaded to the network at {addr:?}");
Ok(addr)
}

Expand Down Expand Up @@ -214,6 +224,7 @@ impl Client {
let archive_cost = self.data_cost(Bytes::from(root_serialized)).await?;

total_cost += archive_cost.as_atto();
debug!("Total cost for the directory: {total_cost:?}");
Ok(total_cost.into())
}
}
Expand Down
6 changes: 5 additions & 1 deletion autonomi/src/client/fs_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ impl Client {
let data = self.private_data_get(data_access).await?;
if let Some(parent) = to_dest.parent() {
tokio::fs::create_dir_all(parent).await?;
debug!("Created parent directories for {to_dest:?}");
}
tokio::fs::write(to_dest, data).await?;
tokio::fs::write(to_dest.clone(), data).await?;
debug!("Downloaded file to {to_dest:?}");
Ok(())
}

Expand All @@ -52,6 +54,7 @@ impl Client {
self.private_file_download(addr.clone(), to_dest.join(path))
.await?;
}
debug!("Downloaded directory to {to_dest:?}");
Ok(())
}

Expand Down Expand Up @@ -129,6 +132,7 @@ impl Client {
let data = tokio::fs::read(path).await?;
let data = Bytes::from(data);
let addr = self.private_data_put(data, wallet.into()).await?;
debug!("Uploaded file successfully in the privateAchive: {addr:?}");
Ok(addr)
}
}
4 changes: 4 additions & 0 deletions autonomi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl Client {
ant_networking::target_arch::spawn(handle_event_receiver(event_receiver, sender));

receiver.await.expect("sender should not close")?;
debug!("Client is connected to the network");

Ok(Self {
network,
Expand All @@ -131,6 +132,8 @@ impl Client {
let (client_event_sender, client_event_receiver) =
tokio::sync::mpsc::channel(CLIENT_EVENT_CHANNEL_SIZE);
self.client_event_sender = Arc::new(Some(client_event_sender));
debug!("All events to the clients are enabled");

client_event_receiver
}
}
Expand All @@ -144,6 +147,7 @@ fn build_client_and_run_swarm(local: bool) -> (Network, mpsc::Receiver<NetworkEv
network_builder.build_client().expect("mdns to succeed");

let _swarm_driver = ant_networking::target_arch::spawn(swarm_driver.run());
debug!("Client swarm driver is running");

(network, event_receiver)
}
Expand Down
4 changes: 4 additions & 0 deletions autonomi/src/client/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ impl Client {
match payment_option {
PaymentOption::Wallet(wallet) => {
let (receipt, _) = self.pay(content_addrs, &wallet).await?;
debug!(
"Paid for content addresses with wallet and the receipt is {:?}",
receipt
);
Ok(receipt)
}
PaymentOption::Receipt(receipt) => Ok(receipt),
Expand Down
Loading

0 comments on commit 1f27152

Please sign in to comment.