-
Notifications
You must be signed in to change notification settings - Fork 111
Description
In the MMR code, we have a notion of "position" and "location". A node's position is its index within the MMR. Its location is its index within the list of MMR leaves.
This MMR has nodes at positions 0, 1, 2, 3.
The mapping of location to position is:
0 --> 0
1 --> 1
2 --> 3
(Note that position 2 does not correspond to a location -- it isn't a leaf.)
2
/ \
0 1 3
We use the position/location to index into MMRs, etc.
We use u64
to represent both locations and positions. This can be error prone -- it's easy to mistake a location for a position and vice versa.
We could make this less error prone by introducing Position
and Location
types. These could alias (or wrap) u64. This would allow functions to be parameterized on one type or the other, reducing the likelihood that they are misused. We can trivially implement From
on these types to allow for ergonomic conversions between the types. This would replace helper functions leaf_num_to_pos
and leaf_pos_to_num
.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status