Skip to content

no need to rehash with index to compare output with input spending it #3260

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

Merged
merged 3 commits into from
Mar 4, 2020

Conversation

antiochp
Copy link
Member

@antiochp antiochp commented Mar 2, 2020

When validating an input (that it spends an unspent output) we do not need to re-hash the features+commit and compare against the hash in the output MMR.

We can simply compare the OutputIdentifier (features+commit) directly.

Comparing 32 bytes of a commitment will be cheaper than hashing the commitment and then comparing 32 bytes of the resulting hash.
Reading the commitment from the data file will be no more expensive than reading the hash from the hash file.

Implement From<Input> for OutputIdentifier to keep the code clean here.

TODO -

  • implement the same equality check in is_unspent()

@antiochp antiochp marked this pull request as ready for review March 2, 2020 17:29
@antiochp antiochp changed the title [DNM] no need to rehash with index to compare output with input spending it no need to rehash with index to compare output with input spending it Mar 2, 2020
@antiochp
Copy link
Member Author

antiochp commented Mar 2, 2020

Related - #3256 (touches the same code).

We also do a hash_with_index() in txhashet.is_unspent(). We should make the same change there.

@antiochp antiochp requested a review from jaspervdm March 2, 2020 17:37
Copy link
Contributor

@jaspervdm jaspervdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one small comment

@antiochp antiochp merged commit 5f5b1d2 into mimblewimble:master Mar 4, 2020
@antiochp antiochp deleted the less_hashing branch March 4, 2020 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants