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

Optimize WalletDB.loadNoteHash() to avoid hitting the database if the note nullifier is known to be absent #5135

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

andiflabs
Copy link
Contributor

Summary

This commit adds an in-memory bloom filter to remember which nullifiers are stored in the database. The bloom filter is used by WalletDB.loadNoteHash() to avoid querying the database if the given nullifier is known to be not present.

While at it, WalletDB.getTransactionHashFromNullifier() was optimized in the same way.

Testing Plan

  • unit tests
  • wallet:rescan

Documentation

N/A

Breaking Change

N/A

@andiflabs andiflabs requested a review from a team as a code owner July 16, 2024 00:32
Copy link
Contributor

@hughy hughy left a comment

Choose a reason for hiding this comment

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

👍 👍

ironfish/src/wallet/walletdb/walletdb.ts Show resolved Hide resolved
Comment on lines 1297 to 1298
// TODO: maybe keep a count of how many times this method was called, and
// reset the bloom filter after a certain threshold
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to worry about nullifiers here. Entries in nullifierToTransactionHash are only deleted if a pending transaction expires. The nullifier is still valid for that account, but that transaction isn't.

Comment on lines 817 to 818
// TODO: maybe keep a count of how many times this method was called, and
// reset the bloom filter after a certain threshold
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that nullifiers are deleted so infrequently that it might not be worth the added complexity to reset the bloom filter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, that's why I did not implement it. I might turn this "TODO" into a simple comment saying that the bloom filter is unchanged after a delete, and that's by design, because <explanation>.

…he note nullifier is known to be absent

This commit adds an in-memory bloom filter to remember which nullifiers
are stored in the database. The bloom filter is used by
`WalletDB.loadNoteHash()` to avoid querying the database if the given
nullifier is known to be not present.

While at it, `WalletDB.getTransactionHashFromNullifier()` was optimized
in the same way.
@andiflabs andiflabs force-pushed the andrea/bloom-filter-for-spent-notes branch from 115dcb3 to 6207960 Compare July 16, 2024 22:59
@andiflabs andiflabs merged commit 6207960 into staging Jul 16, 2024
4 checks passed
@andiflabs andiflabs deleted the andrea/bloom-filter-for-spent-notes branch July 16, 2024 23:13
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