Skip to content

Commit

Permalink
refactor: Add iter_from() method in CyclicBoundedVec
Browse files Browse the repository at this point in the history
`ConcurrentMerkleTree` uses `CyclicBoundedVec` for storing changelog
entries. And it often needs to iterate over changelogs which are full
and started overwriting elements from the start.

Even though `CyclicBoundedVec` was doing good job in preserving the
bounds, before this change, it didn't provide any safe way of iterating
over elements with a custom index as a start.

That unfortunately resulted in attempts to solve that problem in the
code of `ConcurrentMerkleTree`, which eventually resulted in bugs.
The bugs were harder to spot, because mixing the logic of Merkle proof
patching with leaked internals of `CyclicBoundedVec` made it confusing
to read, debug and test.

To avoid such issues, introduce the `iter_from()` method which allows
iteration from the given index and simplify the `ConcurrentMerkleTree` to
just use that iterator.

Other changes:

* Stop returning `Result` in `push()`. `push()` can never panic, unless
  we have a bug in the implementation. Our tests should make sure that
  the structure is bulletproof.
  • Loading branch information
vadorovsky committed May 8, 2024
1 parent 459318e commit bfc8c26
Show file tree
Hide file tree
Showing 7 changed files with 393 additions and 122 deletions.
Loading

0 comments on commit bfc8c26

Please sign in to comment.