Skip to content
Open
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
5 changes: 3 additions & 2 deletions benchtop/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl Backend {
// If reset is true, then erase any previous backend's database
// and restart from an empty database.
// Otherwise, use the already present database.
#[allow(clippy::too_many_arguments)]
pub fn instantiate(
&self,
reset: bool,
Expand Down Expand Up @@ -93,7 +94,7 @@ impl DB {
while !workload.is_done() {
if timeout
.as_ref()
.map_or(false, |t| std::time::Instant::now() > *t)
.is_some_and(|t| std::time::Instant::now() > *t)
{
break;
}
Expand Down Expand Up @@ -121,7 +122,7 @@ impl DB {
while workloads.iter().any(|w| !w.is_done()) {
if timeout
.as_ref()
.map_or(false, |t| std::time::Instant::now() > *t)
.is_some_and(|t| std::time::Instant::now() > *t)
{
break;
}
Expand Down
1 change: 1 addition & 0 deletions benchtop/src/custom_workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn encode_id(id: u64) -> [u8; 8] {
}

/// Build N `RwWorkload`s, one for each thread.
#[allow(clippy::too_many_arguments)]
pub fn build(
reads: u8,
writes: u8,
Expand Down
4 changes: 2 additions & 2 deletions benchtop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn main() -> Result<()> {

pub fn init(params: InitParams) -> Result<()> {
let workload_params = params.workload;
let (mut init, _) = workload::parse(&workload_params, u64::max_value(), 0)?;
let (mut init, _) = workload::parse(&workload_params, u64::MAX, 0)?;

let mut db = params.backend.instantiate(
true,
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn run(params: RunParams) -> Result<()> {
);
let (mut init, mut workloads) = workload::parse(
&workload_params,
params.limits.ops.unwrap_or(u64::max_value()),
params.limits.ops.unwrap_or(u64::MAX),
seeder.random(),
)?;

Expand Down
10 changes: 5 additions & 5 deletions benchtop/src/nomt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct NomtDB {
}

impl NomtDB {
#[allow(clippy::too_many_arguments)]
pub fn open(
reset: bool,
commit_concurrency: usize,
Expand Down Expand Up @@ -99,7 +100,7 @@ impl NomtDB {
}
let _timer_guard_total = timer.as_mut().map(|t| t.record_span("workload"));

self.commit_overlay(&mut overlay_window, timer.as_mut().map(|t| &mut **t));
self.commit_overlay(&mut overlay_window, timer.as_deref_mut());

let session_params = SessionParams::default().witness_mode(WitnessMode::read_write());

Expand Down Expand Up @@ -152,7 +153,7 @@ impl NomtDB {

let _timer_guard_total = timer.as_mut().map(|t| t.record_span("workload"));

self.commit_overlay(&mut overlay_window, timer.as_mut().map(|t| &mut **t));
self.commit_overlay(&mut overlay_window, timer.as_deref_mut());

let session_params = SessionParams::default().witness_mode(WitnessMode::read_write());

Expand All @@ -166,7 +167,7 @@ impl NomtDB {

let use_timer = timer.is_some();
thread_pool.in_place_scope(|scope| {
for (workload, result) in workloads.into_iter().zip(results.iter_mut()) {
for (workload, result) in workloads.iter_mut().zip(results.iter_mut()) {
let session = &session;
scope.spawn(move |_| {
let mut workload_timer = if use_timer {
Expand Down Expand Up @@ -196,8 +197,7 @@ impl NomtDB {
let mut actual_access: Vec<_> = results
.into_iter()
.flatten()
.map(|(access, _)| access)
.flatten()
.flat_map(|(access, _)| access)
.collect();
actual_access.sort_by_key(|(k, _)| *k);

Expand Down
2 changes: 1 addition & 1 deletion benchtop/src/transfer_workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl Workload for TransferWorkload {
} else {
// odds of two threads generating the same random account here are
// incredibly low.
rng.random_range(self.num_accounts..u64::max_value())
rng.random_range(self.num_accounts..u64::MAX)
};

let send_balance = decode_balance(
Expand Down
1 change: 1 addition & 0 deletions benchtop/src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub trait Workload: Send {
fn is_done(&self) -> bool;
}

#[allow(clippy::type_complexity)]
pub fn parse(
workload_params: &WorkloadParams,
op_limit: u64,
Expand Down
2 changes: 1 addition & 1 deletion core/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const DEPTH: usize = 6;
// Total number of nodes stored in one Page. It depends on the `DEPTH`
// of the rootless sub-binary tree stored in a page following this formula:
// (2^(DEPTH + 1)) - 2
pub const NODES_PER_PAGE: usize = (1 << DEPTH + 1) - 2;
pub const NODES_PER_PAGE: usize = (1 << (DEPTH + 1)) - 2;

/// A raw, unsized page data slice.
pub type RawPage = [[u8; 32]];
2 changes: 1 addition & 1 deletion core/src/page_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl PageId {

let leading_zeros = uint.leading_zeros();
let bit_count = 256 - leading_zeros;
let sextets = (bit_count + 5) / 6;
let sextets = bit_count.div_ceil(6);

if bit_count == 0 {
return Ok(ROOT_PAGE_ID);
Expand Down
32 changes: 16 additions & 16 deletions core/src/proof/multi_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl MultiProof {
match proof_range.step(&path_proofs) {
PathProofRangeStep::Bisect { left, right } => {
// insert collected common siblings
siblings.extend(common_siblings.drain(..));
siblings.append(&mut common_siblings);

// push into the stack the right Bisection and work on the left one
proof_range = left;
Expand Down Expand Up @@ -341,7 +341,7 @@ impl VerifiedMultiProof {
/// Fails if the key is out of the scope of this proof.
pub fn confirm_value(&self, expected_leaf: &LeafData) -> Result<bool, KeyOutOfScope> {
let index = self.find_index_for(&expected_leaf.key_path)?;
Ok(self.confirm_value_inner(&expected_leaf, index))
Ok(self.confirm_value_inner(expected_leaf, index))
}

/// Check whether the specific path with index `index` proves that a key has no value in
Expand Down Expand Up @@ -395,7 +395,7 @@ impl VerifiedMultiProof {
path.terminal.path()[..depth] == expected_leaf.key_path.view_bits::<Msb0>()[..depth];

if in_scope {
Ok(self.confirm_value_inner(&expected_leaf, index))
Ok(self.confirm_value_inner(expected_leaf, index))
} else {
Err(KeyOutOfScope)
}
Expand Down Expand Up @@ -468,7 +468,7 @@ pub fn verify<H: NodeHasher>(
inner: verified_paths,
bisections: verified_bisections,
siblings: multi_proof.siblings.clone(),
root: root,
root,
})
}

Expand Down Expand Up @@ -670,12 +670,12 @@ impl CommonSiblings {
while self
.bisection_stack
.last()
.map_or(false, |b| b.start_depth >= depth)
.is_some_and(|b| b.start_depth >= depth)
{
let _ = self.bisection_stack.pop();
}

while self.stack.last().map_or(false, |(d, _)| *d >= depth) {
while self.stack.last().is_some_and(|(d, _)| *d >= depth) {
let _ = self.stack.pop();
}
}
Expand All @@ -689,7 +689,7 @@ impl CommonSiblings {
}

fn pop_if_at_depth(&mut self, depth: usize) -> Option<Node> {
if self.stack.last().map_or(false, |(d, _)| *d == depth) {
if self.stack.last().is_some_and(|(d, _)| *d == depth) {
self.stack.pop().map(|(_, n)| n)
} else {
None
Expand Down Expand Up @@ -752,7 +752,7 @@ pub fn verify_update<H: NodeHasher>(
&[]
};

common_siblings.advance(&proof);
common_siblings.advance(proof);
hash_and_compact_terminal::<H>(
&mut pending_siblings,
terminal,
Expand Down Expand Up @@ -784,7 +784,7 @@ pub fn verify_update<H: NodeHasher>(
}

// if this is either the first op or this has the same terminal as the previous op...
if last_terminal_index.map_or(true, |x| x == next_terminal_index) {
if last_terminal_index.is_none_or(|x| x == next_terminal_index) {
last_terminal_index = Some(next_terminal_index);
working_ops.push((key, op));
continue;
Expand All @@ -801,7 +801,7 @@ pub fn verify_update<H: NodeHasher>(
let terminal = &proof.inner[terminal_index];
let next_terminal = Some(&proof.inner[terminal_index + 1]);

common_siblings.advance(&proof);
common_siblings.advance(proof);
hash_and_compact_terminal::<H>(
&mut pending_siblings,
terminal,
Expand All @@ -812,12 +812,12 @@ pub fn verify_update<H: NodeHasher>(
}

// ingest the currently updated terminal.
let ops = core::mem::replace(&mut working_ops, Vec::new());
let ops = core::mem::take(&mut working_ops);
working_ops.push((key, op));

let terminal = &proof.inner[updated_index];
let next_terminal = proof.inner.get(updated_index + 1);
common_siblings.advance(&proof);
common_siblings.advance(proof);

hash_and_compact_terminal::<H>(
&mut pending_siblings,
Expand Down Expand Up @@ -862,7 +862,7 @@ fn hash_and_compact_terminal<H: NodeHasher>(
skip // go to root
};

let ops = crate::update::leaf_ops_spliced(leaf, &ops);
let ops = crate::update::leaf_ops_spliced(leaf, ops);
let sub_root = crate::update::build_trie::<H>(skip, ops, |_| {});

let mut cur_node = sub_root;
Expand All @@ -878,7 +878,7 @@ fn hash_and_compact_terminal<H: NodeHasher>(
.rev()
.take(up_layers)
{
let sibling = if pending_siblings.last().map_or(false, |p| p.1 == cur_layer) {
let sibling = if pending_siblings.last().is_some_and(|p| p.1 == cur_layer) {
// is this even possible? maybe not. but being extra cautious...
let _ = common_siblings.pop_if_at_depth(cur_layer);
// UNWRAP: guaranteed to exist.
Expand Down Expand Up @@ -1409,7 +1409,7 @@ mod tests {
let v1 = Blake3Hasher::hash_leaf(&leaf_1);
let v2 = Blake3Hasher::hash_leaf(&leaf_2);
let s3 = Blake3Hasher::hash_internal(&InternalData {
left: v0.clone(),
left: v0,
right: v2,
});
let root = Blake3Hasher::hash_internal(&InternalData {
Expand Down Expand Up @@ -1472,7 +1472,7 @@ mod tests {
let v1 = Blake3Hasher::hash_leaf(&leaf_1);
let v2 = Blake3Hasher::hash_leaf(&leaf_2);
let s3 = Blake3Hasher::hash_internal(&InternalData {
left: v0.clone(),
left: v0,
right: v2,
});
let root = Blake3Hasher::hash_internal(&InternalData {
Expand Down
13 changes: 5 additions & 8 deletions core/src/proof/path_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl PathProofTerminal {
/// Return the bit-path to the Terminal Node
pub fn path(&self) -> &BitSlice<u8, Msb0> {
match self {
Self::Leaf(leaf_data) => &leaf_data.key_path.view_bits(),
Self::Leaf(leaf_data) => leaf_data.key_path.view_bits(),
Self::Terminator(key_path) => key_path.path(),
}
}
Expand Down Expand Up @@ -117,10 +117,7 @@ pub fn hash_path<H: NodeHasher>(
(node, sibling)
};

let next = InternalData {
left: left.clone(),
right: right.clone(),
};
let next = InternalData { left, right };
node = H::hash_internal(&next);
}

Expand Down Expand Up @@ -197,7 +194,7 @@ impl VerifiedPathProof {
self.in_scope(key_path).map(|_| {
self.terminal()
.as_ref()
.map_or(true, |d| &d.key_path != key_path)
.is_none_or(|d| &d.key_path != key_path)
})
}

Expand Down Expand Up @@ -303,7 +300,7 @@ pub fn verify_update<H: NodeHasher>(
// left frontier
let mut pending_siblings: Vec<(Node, usize)> = Vec::new();
for (i, path) in paths.iter().enumerate() {
let leaf = path.inner.terminal().map(|x| x.clone());
let leaf = path.inner.terminal().cloned();
let ops = &path.ops;
let skip = path.inner.path().len();

Expand Down Expand Up @@ -335,7 +332,7 @@ pub fn verify_update<H: NodeHasher>(
.take(up_layers)
.zip(path.inner.siblings.iter().rev())
{
let sibling = if pending_siblings.last().map_or(false, |p| p.1 == cur_layer) {
let sibling = if pending_siblings.last().is_some_and(|p| p.1 == cur_layer) {
// unwrap: checked above
pending_siblings.pop().unwrap().0
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
//!
//! All nodes are 256 bits. There are three kinds of nodes.
//! 1. Internal nodes, which each have two children. The value of an internal node is
//! given by hashing the concatenation of the two child nodes and setting the MSB to 0.
//! given by hashing the concatenation of the two child nodes and setting the MSB to 0.
//! 2. Leaf nodes, which have zero children. The value of a leaf node is given by hashing
//! the concatenation of the 256-bit lookup path and the hash of the value stored at the leaf,
//! and setting the MSB to 1.
//! the concatenation of the 256-bit lookup path and the hash of the value stored at the leaf,
//! and setting the MSB to 1.
//! 3. [`TERMINATOR`] nodes, which have the special value of all 0s. These nodes have no children
//! and serve as a stand-in for an empty sub-trie at any height. Terminator nodes enable the
//! trie to be tractably represented.
Expand Down
13 changes: 7 additions & 6 deletions core/src/trie_pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bitvec::prelude::*;
///
/// Deserialization rejects positions that no constructor could produce: a depth beyond 256, or a
/// node index that does not match the path and depth.
#[derive(Clone)]
#[derive(Clone, Default)]
#[cfg_attr(feature = "borsh", derive(borsh::BorshSerialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct TriePosition {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl TriePosition {
TriePosition {
path,
depth,
node_index: node_index(&page_path),
node_index: node_index(page_path),
}
}

Expand All @@ -116,6 +116,7 @@ impl TriePosition {

/// Parse a `TriePosition` from a bit string.
#[cfg(test)]
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Self {
let mut bitvec = BitVec::<u8, Msb0>::new();
if s.len() > 256 {
Expand Down Expand Up @@ -170,7 +171,7 @@ impl TriePosition {
#[inline]
pub fn down(&mut self, bit: bool) {
assert_ne!(self.depth, 256, "can't descend past 256 bits");
if self.depth as usize % DEPTH == 0 {
if (self.depth as usize).is_multiple_of(DEPTH) {
self.node_index = bit as usize;
} else {
let children = self.child_node_indices();
Expand Down Expand Up @@ -201,8 +202,8 @@ impl TriePosition {
}

self.depth = new_depth;
let prev_page_depth = (prev_depth as usize + DEPTH - 1) / DEPTH;
let new_page_depth = (self.depth as usize + DEPTH - 1) / DEPTH;
let prev_page_depth = (prev_depth as usize).div_ceil(DEPTH);
let new_page_depth = (self.depth as usize).div_ceil(DEPTH);
if prev_page_depth == new_page_depth {
for _ in 0..d {
self.node_index = parent_node_index(self.node_index);
Expand Down Expand Up @@ -364,7 +365,7 @@ fn bottom_node_index(node_index: usize) -> u8 {

/// Given a node index, get the index of the sibling.
fn sibling_index(node_index: usize) -> usize {
if node_index % 2 == 0 {
if node_index.is_multiple_of(2) {
node_index + 1
} else {
node_index - 1
Expand Down
Loading