Skip to content
Draft
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
4 changes: 2 additions & 2 deletions akd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.12.0-pre.12"
authors = ["akd contributors"]
description = "An implementation of an auditable key directory"
license = "MIT OR Apache-2.0"
edition = "2021"
edition = "2024"
keywords = ["key-transparency", "akd"]
repository = "https://github.com/facebook/akd"
readme = "../README.md"
Expand Down Expand Up @@ -68,7 +68,7 @@ colored = { version = "2", optional = true }
once_cell = { version = "1", optional = true }
paste = { version = "1", optional = true }
protobuf = { version = "3", optional = true }
rand = { version = "0.8", optional = true }
rand = { version = "0.9.2", optional = true }
serde = { version = "1", features = ["derive"], optional = true }
tracing = { version = "0.1.40", optional = true }

Expand Down
6 changes: 3 additions & 3 deletions akd/benches/azks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ extern crate criterion;

mod common;

use akd::NamedConfiguration;
use akd::append_only_zks::{AzksParallelismConfig, InsertMode};
use akd::auditor;
use akd::storage::manager::StorageManager;
use akd::storage::memory::AsyncInMemoryDatabase;
use akd::NamedConfiguration;
use akd::{Azks, AzksElement, AzksValue, NodeLabel};
use criterion::{BatchSize, Criterion};
use rand::rngs::StdRng;
Expand Down Expand Up @@ -203,10 +203,10 @@ fn gen_nodes(rng: &mut impl Rng, num_nodes: usize) -> Vec<AzksElement> {
(0..num_nodes)
.map(|_| {
let label = NodeLabel {
label_val: rng.gen::<[u8; 32]>(),
label_val: rng.random::<[u8; 32]>(),
label_len: 256,
};
let value = AzksValue(rng.gen::<[u8; 32]>());
let value = AzksValue(rng.random::<[u8; 32]>());
AzksElement { label, value }
})
.collect()
Expand Down
4 changes: 2 additions & 2 deletions akd/benches/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

mod common;

use akd::NamedConfiguration;
use akd::append_only_zks::AzksParallelismConfig;
use akd::ecvrf::HardCodedAkdVRF;
use akd::storage::manager::StorageManager;
use akd::storage::memory::AsyncInMemoryDatabase;
use akd::NamedConfiguration;
use akd::{AkdLabel, AkdValue, Directory};
use criterion::{BatchSize, Criterion};
use rand::distributions::Alphanumeric;
use rand::distr::Alphanumeric;
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};

Expand Down Expand Up @@ -63,7 +63,7 @@
.unwrap();

for _epoch in 1..num_updates {
let value: String = (0..rng.gen_range(10..20))

Check warning on line 66 in akd/benches/directory.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd benches, akd, -F bench)

use of deprecated method `rand::Rng::gen_range`: Renamed to `random_range`

Check warning on line 66 in akd/benches/directory.rs

View workflow job for this annotation

GitHub Actions / benches (Build the akd benches, akd, -F bench)

use of deprecated method `rand::Rng::gen_range`: Renamed to `random_range`
.map(|_| rng.sample(&Alphanumeric))
.map(char::from)
.collect();
Expand Down
30 changes: 15 additions & 15 deletions akd/src/append_only_zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

//! An implementation of an append-only zero knowledge set

use crate::Configuration;
use crate::hash::EMPTY_DIGEST;
use crate::helper_structs::LookupInfo;
use crate::log::{debug, info};
use crate::storage::manager::StorageManager;
use crate::storage::types::StorageType;
use crate::tree_node::{
new_interior_node, new_leaf_node, new_root_node, node_to_azks_value, node_to_label,
NodeHashingMode, NodeKey, TreeNode, TreeNodeType,
NodeHashingMode, NodeKey, TreeNode, TreeNodeType, new_interior_node, new_leaf_node,
new_root_node, node_to_azks_value, node_to_label,
};
use crate::Configuration;
use crate::{
ARITY, AppendOnlyProof, AzksElement, AzksValue, Digest, Direction, MembershipProof, NodeLabel,
NonMembershipProof, PrefixOrdering, SiblingProof, SingleAppendOnlyProof, SizeOf,
errors::{AkdError, DirectoryError, ParallelismError, TreeNodeError},
storage::{Database, Storable},
AppendOnlyProof, AzksElement, AzksValue, Digest, Direction, MembershipProof, NodeLabel,
NonMembershipProof, PrefixOrdering, SiblingProof, SingleAppendOnlyProof, SizeOf, ARITY,
};

use async_recursion::async_recursion;
Expand Down Expand Up @@ -1320,8 +1320,8 @@ type AppendOnlyHelper = (Vec<AzksElement>, Vec<AzksElement>);
#[cfg(test)]
mod tests {
use super::*;
use crate::storage::types::DbRecord;
use crate::storage::StorageUtil;
use crate::storage::types::DbRecord;
use crate::test_config;
use crate::tree_node::TreeNodeWithPreviousValue;
use crate::utils::byte_arr_from_u64;
Expand All @@ -1331,7 +1331,7 @@ mod tests {
storage::memory::AsyncInMemoryDatabase,
};
use itertools::Itertools;
use rand::{rngs::StdRng, seq::SliceRandom, RngCore, SeedableRng};
use rand::{RngCore, SeedableRng, rngs::StdRng, seq::SliceRandom};
use std::time::Duration;

#[cfg(feature = "greedy_lookup_preload")]
Expand Down Expand Up @@ -1460,9 +1460,9 @@ mod tests {
let right_child_hash = leaf_hashes[2 * i + 1].clone();
layer_1_hashes.push((
TC::compute_parent_hash_from_children(
&AzksValue(left_child_hash.0 .0),
&AzksValue(left_child_hash.0.0),
&left_child_hash.1,
&AzksValue(right_child_hash.0 .0),
&AzksValue(right_child_hash.0.0),
&right_child_hash.1,
),
NodeLabel::new(byte_arr_from_u64(j << 62), 2u32).value::<TC>(),
Expand All @@ -1475,19 +1475,19 @@ mod tests {
let right_child_hash = layer_1_hashes[2 * i + 1].clone();
layer_2_hashes.push((
TC::compute_parent_hash_from_children(
&AzksValue(left_child_hash.0 .0),
&AzksValue(left_child_hash.0.0),
&left_child_hash.1,
&AzksValue(right_child_hash.0 .0),
&AzksValue(right_child_hash.0.0),
&right_child_hash.1,
),
NodeLabel::new(byte_arr_from_u64(j << 63), 1u32).value::<TC>(),
));
}

let expected = TC::compute_root_hash_from_val(&TC::compute_parent_hash_from_children(
&AzksValue(layer_2_hashes[0].0 .0),
&AzksValue(layer_2_hashes[0].0.0),
&layer_2_hashes[0].1,
&AzksValue(layer_2_hashes[1].0 .0),
&AzksValue(layer_2_hashes[1].0.0),
&layer_2_hashes[1].1,
));

Expand Down Expand Up @@ -1813,8 +1813,8 @@ mod tests {
}

test_config!(test_azks_element_set_get_longest_common_prefix);
async fn test_azks_element_set_get_longest_common_prefix<TC: Configuration>(
) -> Result<(), AkdError> {
async fn test_azks_element_set_get_longest_common_prefix<TC: Configuration>()
-> Result<(), AkdError> {
let num_nodes = 10;
let database = AsyncInMemoryDatabase::new();
let db = StorageManager::new_no_cache(database);
Expand Down
6 changes: 3 additions & 3 deletions akd/src/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

//! Code for an auditor of a authenticated key directory

use akd_core::configuration::Configuration;
use akd_core::AzksElement;
use akd_core::configuration::Configuration;

use crate::append_only_zks::AzksParallelismConfig;
use crate::AzksValue;
use crate::append_only_zks::AzksParallelismConfig;
use crate::{
AppendOnlyProof, Azks, Digest, SingleAppendOnlyProof,
append_only_zks::InsertMode,
errors::{AkdError, AuditorError, AzksError},
storage::{manager::StorageManager, memory::AsyncInMemoryDatabase},
AppendOnlyProof, Azks, Digest, SingleAppendOnlyProof,
};

/// Verifies an audit proof, given start and end hashes for a merkle patricia tree.
Expand Down
14 changes: 10 additions & 4 deletions akd/src/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use crate::ecvrf::{VRFKeyStorage, VRFPublicKey};
use crate::errors::{AkdError, DirectoryError, StorageError};
use crate::helper_structs::LookupInfo;
use crate::log::{error, info};
use crate::storage::Database;
use crate::storage::manager::StorageManager;
use crate::storage::types::{DbRecord, ValueState, ValueStateRetrievalFlag};
use crate::storage::Database;
use crate::{
AkdLabel, AkdValue, AppendOnlyProof, AzksElement, Digest, EpochHash, HistoryProof, LookupProof,
UpdateProof,
Expand Down Expand Up @@ -207,7 +207,9 @@ where
}

if update_set.is_empty() {
info!("After filtering for duplicated user information, there is no publish which is necessary (0 updates)");
info!(
"After filtering for duplicated user information, there is no publish which is necessary (0 updates)"
);
// The AZKS has not been updated/mutated at this point, so we can just return the root hash from before
let root_hash = current_azks.get_root_hash::<TC, _>(&self.storage).await?;
return Ok(EpochHash(current_epoch, root_hash));
Expand Down Expand Up @@ -752,7 +754,9 @@ where
match got {
DbRecord::Azks(azks) => Ok(azks),
_ => {
error!("No AZKS can be found. You should re-initialize the directory to create a new one");
error!(
"No AZKS can be found. You should re-initialize the directory to create a new one"
);
Err(AkdError::Storage(StorageError::NotFound(
"AZKS not found".to_string(),
)))
Expand Down Expand Up @@ -1097,7 +1101,9 @@ impl<TC: Configuration, S: Database + 'static, V: VRFKeyStorage> Directory<TC, S
let azks_element_set: Vec<AzksElement> = update_set.to_vec();

if azks_element_set.is_empty() {
info!("After filtering for duplicated user information, there is no publish which is necessary (0 updates)");
info!(
"After filtering for duplicated user information, there is no publish which is necessary (0 updates)"
);
// The AZKS has not been updated/mutated at this point, so we can just return the root hash from before
let root_hash = current_azks.get_root_hash::<TC, _>(&self.storage).await?;
return Ok(EpochHash(current_epoch, root_hash));
Expand Down
2 changes: 1 addition & 1 deletion akd/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//! Errors for various data structure operations.
use core::fmt;

use crate::node_label::NodeLabel;
use crate::Direction;
use crate::node_label::NodeLabel;

/// Symbolizes a AkdError, thrown by the akd.
#[cfg_attr(test, derive(PartialEq, Eq))]
Expand Down
2 changes: 1 addition & 1 deletion akd/src/helper_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! to make it easier to pass arguments around.

use crate::Digest;
use crate::{storage::types::ValueState, NodeLabel};
use crate::{NodeLabel, storage::types::ValueState};

/// Root hash of the tree and its associated epoch
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down
4 changes: 2 additions & 2 deletions akd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ pub mod log {
pub mod local_auditing;

pub use akd_core::{
configuration, configuration::*, ecvrf, hash, hash::Digest, proto, types::*, verify,
verify::history::HistoryParams, ARITY,
ARITY, configuration, configuration::*, ecvrf, hash, hash::Digest, proto, types::*, verify,
verify::history::HistoryParams,
};

#[macro_use]
Expand Down
6 changes: 4 additions & 2 deletions akd/src/storage/cache/high_parallelism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use crate::storage::Storable;

use akd_core::SizeOf;
use dashmap::DashMap;
use std::sync::Arc;
#[cfg(feature = "runtime_metrics")]
use std::sync::atomic::AtomicU64;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;

Expand Down Expand Up @@ -86,7 +86,9 @@ impl TimedCache {
debug!("Retained cache size is {retained_size} bytes");

if retained_size > memory_limit_bytes {
info!("Retained cache size has exceeded the predefined limit, cleaning old entries");
info!(
"Retained cache size has exceeded the predefined limit, cleaning old entries"
);
// calculate the percentage we'd need to trim off to get to 100% utilization and take another 5%
let percent_clean =
0.05 + 1.0 - (memory_limit_bytes as f64) / (retained_size as f64);
Expand Down
2 changes: 1 addition & 1 deletion akd/src/storage/cache/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use super::*;
use std::time::Duration;

use crate::storage::types::{ValueState, ValueStateKey};
use crate::storage::DbRecord;
use crate::storage::types::{ValueState, ValueStateKey};
use crate::{AkdLabel, AkdValue, NodeLabel};

#[tokio::test]
Expand Down
14 changes: 7 additions & 7 deletions akd/src/storage/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
//! to manage interactions with the data layer to optimize things like caching and
//! transaction management

use crate::AkdLabel;
use crate::AkdValue;
use crate::log::debug;
#[cfg(feature = "runtime_metrics")]
use crate::log::info;
use crate::storage::Database;
use crate::storage::DbSetState;
use crate::storage::Storable;
use crate::storage::StorageError;
use crate::storage::cache::TimedCache;
use crate::storage::transaction::Transaction;
use crate::storage::types::DbRecord;
use crate::storage::types::KeyData;
use crate::storage::types::ValueState;
use crate::storage::Database;
use crate::storage::DbSetState;
use crate::storage::Storable;
use crate::storage::StorageError;
use crate::AkdLabel;
use crate::AkdValue;

use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
#[cfg(feature = "runtime_metrics")]
use std::sync::atomic::AtomicU64;
#[cfg(feature = "runtime_metrics")]
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::time::Duration;

use super::types::ValueStateRetrievalFlag;
Expand Down
2 changes: 1 addition & 1 deletion akd/src/storage/manager/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use akd_core::hash::EMPTY_DIGEST;

use super::*;
use crate::storage::memory::AsyncInMemoryDatabase;
use crate::storage::{types::*, StorageUtil};
use crate::storage::{StorageUtil, types::*};
use crate::tree_node::{NodeKey, TreeNodeWithPreviousValue};
use crate::*;

Expand Down
4 changes: 2 additions & 2 deletions akd/src/storage/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Database for AsyncInMemoryDatabase {
ValueStateRetrievalFlag::SpecificVersion(version)
if version == kvp.version =>
{
return Ok(kvp.clone())
return Ok(kvp.clone());
}
ValueStateRetrievalFlag::LeqEpoch(epoch) if epoch == kvp.epoch => {
return Ok(kvp.clone());
Expand All @@ -244,7 +244,7 @@ impl Database for AsyncInMemoryDatabase {
}
}
ValueStateRetrievalFlag::SpecificEpoch(epoch) if epoch == kvp.epoch => {
return Ok(kvp.clone())
return Ok(kvp.clone());
}
_ => continue,
}
Expand Down
2 changes: 1 addition & 1 deletion akd/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{AkdLabel, AkdValue};

use async_trait::async_trait;
#[cfg(feature = "serde_serialization")]
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};
use std::collections::HashMap;
use std::hash::Hash;
use std::marker::{Send, Sync};
Expand Down
Loading
Loading