Skip to content

Commit

Permalink
ancestry_proof::{MerkleProof→NodeMerkleProof}
Browse files Browse the repository at this point in the history
More opaque wrt. code duplication, but less cognitive overhead for review.
  • Loading branch information
Lederstrumpf committed Mar 26, 2024
1 parent 14edd7c commit 899afaf
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/ancestry_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::marker::PhantomData;
use itertools::Itertools;

#[derive(Debug)]
pub struct MerkleProof<T, M> {
pub struct NodeMerkleProof<T, M> {
mmr_size: u64,
proof: Vec<(u64, T)>,
merge: PhantomData<M>,
Expand All @@ -20,7 +20,7 @@ pub struct MerkleProof<T, M> {
pub struct AncestryProof<T, M> {
pub prev_peaks: Vec<T>,
pub prev_size: u64,
pub proof: MerkleProof<T, M>,
pub proof: NodeMerkleProof<T, M>,
}

impl<T: PartialEq + Debug + Clone, M: Merge<Item = T>> AncestryProof<T, M> {
Expand Down Expand Up @@ -56,9 +56,9 @@ impl<T: PartialEq + Debug + Clone, M: Merge<Item = T>> AncestryProof<T, M> {
}
}

impl<T: Clone + PartialEq, M: Merge<Item = T>> MerkleProof<T, M> {
impl<T: Clone + PartialEq, M: Merge<Item = T>> NodeMerkleProof<T, M> {
pub fn new(mmr_size: u64, proof: Vec<(u64, T)>) -> Self {
MerkleProof {
NodeMerkleProof {
mmr_size,
proof,
merge: PhantomData,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod mmr_store;
mod tests;
pub mod util;

pub use ancestry_proof::{AncestryProof, MerkleProof as NodeMerkleProof};
pub use ancestry_proof::{AncestryProof, NodeMerkleProof};
pub use error::{Error, Result};
pub use helper::{leaf_index_to_mmr_size, leaf_index_to_pos};
pub use merge::Merge;
Expand Down
2 changes: 1 addition & 1 deletion src/mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! https://github.com/mimblewimble/grin/blob/master/doc/mmr.md#structure
//! https://github.com/mimblewimble/grin/blob/0ff6763ee64e5a14e70ddd4642b99789a1648a32/core/src/core/pmmr.rs#L606
use crate::ancestry_proof::{AncestryProof, MerkleProof as NodeMerkleProof};
use crate::ancestry_proof::{AncestryProof, NodeMerkleProof};
use crate::borrow::Cow;
use crate::collections::VecDeque;
use crate::helper::{
Expand Down
8 changes: 4 additions & 4 deletions src/tests/test_node_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ fn test_invalid_proof_verification(
// optionally handroll tampered proof from these positions
handrolled_tampered_proof_positions: Option<Vec<u64>>,
) {
use crate::{ancestry_proof::MerkleProof, Merge};
use crate::{ancestry_proof::NodeMerkleProof, Merge};
use std::fmt::{Debug, Formatter};

// Simple item struct to allow debugging the contents of MMR nodes/peaks
Expand Down Expand Up @@ -217,9 +217,9 @@ fn test_invalid_proof_verification(
)
});

let tampered_proof: Option<MerkleProof<MyItem, MyMerge>> =
let tampered_proof: Option<NodeMerkleProof<MyItem, MyMerge>> =
if let Some(tampered_proof_positions) = handrolled_tampered_proof_positions {
Some(MerkleProof::new(
Some(NodeMerkleProof::new(
mmr.mmr_size(),
tampered_proof_positions
.iter()
Expand All @@ -232,7 +232,7 @@ fn test_invalid_proof_verification(

// test with the proof generated by the library itself, or, if provided, a handrolled proof
let proof = if let Some(proof_positions) = handrolled_proof_positions {
MerkleProof::new(
NodeMerkleProof::new(
mmr.mmr_size(),
proof_positions
.iter()
Expand Down

0 comments on commit 899afaf

Please sign in to comment.