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 note storage #662

Open
1 of 5 tasks
SantiagoPittella opened this issue Jan 31, 2025 · 3 comments
Open
1 of 5 tasks

Optimize note storage #662

SantiagoPittella opened this issue Jan 31, 2025 · 3 comments
Milestone

Comments

@SantiagoPittella
Copy link
Collaborator

Node's components affected by this task

  • RPC
  • Block producer
  • Store
  • Protobuf messages
  • Testing

What should be done?

With the new miden-node-stress-testing CLI, and in particular running the command miden-node-stress-testing seed-store, we saw that each note takes too much space in the DB (4.5KB). For ~100k notes means ~460.816384 MB. And, in our use case, represented more than 90% of the DB.

How should it be done?

Investigate and improve the notes tables to shrink.
According to Bobbin (#657 (comment)), it should be possible to reduce ~10x the size.

When is this task done?

The task can be considered done when the size of each note in the store is reduced.

Additional context

No response

@bobbinth
Copy link
Contributor

bobbinth commented Feb 2, 2025

By my estimate, all fields in the notes table, except for the merkle_path and details, should required about 72 bytes of storage. merkle_path should be about 0.5KB, and details should be about 2.5KB. This gives us about 3.1KB - so, not sure what else is there to get it to 4.5KB on average - but we should find this out.

For the 3.1KB, optimization opportunities are:

  • Move details field into a separate table. In this table, don't record the metadata (we already have it in the notes table) and don't store note script separately for every note. Instead, we can have note_scripts table, and store every unique script there. This way, for things like P2ID notes, we should reduce the size of note details from 2.5KB to about 100 bytes.
  • Use compact representation of Merkle paths. This should cut down storage from 0.5KB to about 200 bytes per path.

All in all, with these optimizations we should be able to go from 3.1KB to about 400 bytes. So, the big question will be is where the 1.4KB (i.e., 4.5 - 3.1) is coming from.

@SantiagoPittella
Copy link
Collaborator Author

@bobbinth Should we add this issue to the milestone or it isn't planned for the current one?

@bobbinth
Copy link
Contributor

bobbinth commented Feb 5, 2025

I think we can leave it for the next milestone. One of the tasks, btw, is actually in the miden-crypto repo (specifically, 0xPolygonMiden/crypto#215 for introducing SparseMerklePath struct).

@bobbinth bobbinth added this to the v0.9 milestone Feb 5, 2025
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

No branches or pull requests

2 participants