Skip to content

Commit

Permalink
feat: app clippy, ignore two warnings because its the simplest soluti…
Browse files Browse the repository at this point in the history
…on (#17)

* feat: app clippy, ignore two warnings because its the simplest solution

* fix: stop ignoring clippy
  • Loading branch information
sebasti810 committed Jul 30, 2024
1 parent 0467260 commit c4d31e1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Rust CI

on:
push:
branches:
- '**'
pull_request:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
rust:
- version: stable
profile: minimal
- version: beta
profile: default
- version: nightly
profile: default

steps:
- uses: actions/checkout@v4

- name: Setup Rust
run: |
rustup toolchain install ${{ matrix.rust.version }} --profile ${{ matrix.rust.profile }}
rustup default ${{ matrix.rust.version }}
- name: Install protoc
run: sudo apt-get install protobuf-compiler

- name: Cache cargo build
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ matrix.rust.version }}-${{ hashFiles('**/Cargo.lock') }}

- name: Install dependencies
run: cargo fetch

- name: Add clippy component if not stable
if: matrix.rust.version != 'stable'
run: rustup component add clippy

- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Build project
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose

- name: Install cargo-audit
run: cargo install cargo-audit

- name: Run cargo audit
run: cargo audit
2 changes: 1 addition & 1 deletion benches/tree_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn bench_non_membership_proof(c: &mut Criterion) {
group.bench_with_input(format!("size_{}", size), &size, |b, &size| {
// Setup: Create the tree and insert nodes once
let mut tree = IndexedMerkleTree::new_with_size(size).unwrap();
for i in 0..size / 2 {
for _ in 0..size / 2 {
let mut node = Node::new_leaf(
true,
create_random_test_hash(),
Expand Down
12 changes: 6 additions & 6 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ impl IndexedMerkleTree {
///
/// When called, this function expects the passed nodes to be leaf nodes.
/// It assumes these are the only nodes present in `self.nodes`.
fn rehash_inner_nodes(&mut self, current_layer: &[Node]) {
fn rehash_inner_nodes(&mut self, current_layer: Vec<Node>) {
for (index, node) in current_layer.chunks(2).enumerate() {
let new_node = Node::Inner(InnerNode::new(node[0].clone(), node[1].clone(), index));
self.nodes.push(new_node);
}

let remaining = current_layer.len() / 2;
if remaining > 1 {
self.rehash_inner_nodes(&self.nodes[self.nodes.len() - remaining..].to_vec());
self.rehash_inner_nodes(self.nodes[self.nodes.len() - remaining..].to_vec());
}
}

Expand All @@ -233,7 +233,7 @@ impl IndexedMerkleTree {
/// This is done when first initializing the tree, as well as when nodes are updated.
fn rebuild_tree_from_leaves(&mut self) {
self.nodes.retain(|node| matches!(node, Node::Leaf(_)));
self.rehash_inner_nodes(&self.nodes.clone());
self.rehash_inner_nodes(self.nodes.clone());
}

/// Calculates the root of an IndexedMerkleTree by aggregating the tree's nodes.
Expand Down Expand Up @@ -547,7 +547,7 @@ impl IndexedMerkleTree {
fn write_node(
f: &mut std::fmt::Formatter<'_>,
node: &Node,
depth: usize,
_depth: usize,
is_last: bool,
prefix: &str,
) -> std::fmt::Result {
Expand All @@ -558,8 +558,8 @@ impl IndexedMerkleTree {
Node::Inner(inner) => {
writeln!(f, "{}Inner Node (Hash: {})", node_prefix, inner.hash)?;
let new_prefix = format!("{}{} ", prefix, if is_last { " " } else { "│" });
write_node(f, &inner.left, depth + 1, false, &new_prefix)?;
write_node(f, &inner.right, depth + 1, true, &new_prefix)?;
write_node(f, &inner.left, _depth + 1, false, &new_prefix)?;
write_node(f, &inner.right, _depth + 1, true, &new_prefix)?;
}
Node::Leaf(leaf) => {
writeln!(
Expand Down

0 comments on commit c4d31e1

Please sign in to comment.