Skip to content

Commit

Permalink
merkle: Proof generation cleanup (#2578)
Browse files Browse the repository at this point in the history
This change switches internal proof generation code to use uint64, and removes
an unused error return value.
  • Loading branch information
pav-kv authored Jul 19, 2021
1 parent f5c368e commit 712722d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions merkle/log_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ func CalcConsistencyProofNodeAddresses(size1, size2 int64) ([]NodeFetch, error)
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter for consistency proof: size1 %d > size2 %d", size1, size2)
}

return consistencyNodes(size1, size2)
return consistencyNodes(uint64(size1), uint64(size2)), nil
}

// consistencyNodes returns node addresses for the consistency proof between
// the given tree sizes.
func consistencyNodes(size1, size2 int64) ([]NodeFetch, error) {
func consistencyNodes(size1, size2 uint64) []NodeFetch {
if size1 == size2 {
return []NodeFetch{}, nil
return []NodeFetch{}
}

// TODO(pavelkalinnikov): Make the capacity estimate accurate.
proof := make([]NodeFetch, 0, bits.Len64(uint64(size2))+1)
proof := make([]NodeFetch, 0, bits.Len64(size2)+1)

// Find the biggest perfect subtree that ends at size1.
level := uint(bits.TrailingZeros64(uint64(size1)))
index := uint64((size1 - 1)) >> level
level := uint(bits.TrailingZeros64(size1))
index := (size1 - 1) >> level
// If it does not cover the whole size1 tree, add this node to the proof.
if index != 0 {
n := compact.NewNodeID(level, index)
proof = append(proof, NodeFetch{ID: n})
}

// Now append the path from this node to the root of size2.
p := proofNodes(index, level, uint64(size2), true)
return append(proof, p...), nil
p := proofNodes(index, level, size2, true)
return append(proof, p...)
}

// proofNodes returns the node IDs necessary to prove that the (level, index)
Expand Down

0 comments on commit 712722d

Please sign in to comment.