Skip to content

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

Merged
antiochp merged 3 commits into
mimblewimble:masterfrom
antiochp:less_hashing
Mar 4, 2020
Merged

no need to rehash with index to compare output with input spending it#3260
antiochp merged 3 commits into
mimblewimble:masterfrom
antiochp:less_hashing

Conversation

@antiochp
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread api/src/types.rs Outdated
@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