Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor pmmr functions, improve efficiency; panic on 0 pos1 #3663

Merged
merged 1 commit into from
Nov 12, 2021

Conversation

tromp
Copy link
Contributor

@tromp tromp commented Nov 10, 2021


name: fixmmr_part1
about: streamline MMR code
title: Fix MMR part 1
labels:
assignees: Yeastplume


This PR refactors pmmr.rs, improving efficiency and clarifying use of 0-based vs 1-based positions, introducing panics when passing 0 as a 1-based position, which makes no sense in normal use. The latter did require removal of corresponding test-cases.
A followup PR is planned to make all methods use 0-based positions, which are preferable for two reasons:

  1. they're baked into the consensus model through hash_with_index
  2. they simplify some computations, such as converting leaf to node index:
    node_index = 2 * leaf_index - count_ones(leaf_index)
    There appears to be no advantage to 1-based positions. The APIs use them though, so the API implementation is where all the conversion should take place.

@yeastplume
Copy link
Member

All looks good from my perspective. The panics should be replaced with proper error types, but moving all of the internals to be 0 based should remove the need from them. The API will remain 1-based, so we'll need to make sure all the error propagation is at that level.

@yeastplume yeastplume merged commit 4aaa334 into mimblewimble:master Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants