-
Notifications
You must be signed in to change notification settings - Fork 986
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
MASP storage optimization #2343
Comments
@cwgoes for reference |
Thanks for the writeup. I think we should definitely fix 1 & 2. Regarding 3, I'm not too worried about memory consumption, as long as we have a reasonable understanding of the bounds and total Namada memory usage does not exceed single-digit GBs. Do we have a sense of how large (concretely) this struct would be? |
I've tried to run some approximate calculations. So the
Here are some estimations on the size of the types involved (these are based only on the types, I'm not taking into account optimizations/paddings that the compiler might perform, e.g. to align types in memory):
So I believe the cost in memory of the conversion state could be divided into two parts: a constant (or semi-constant) part and a variable part that gets updated with every epoch change. The constant part would be the cost of the The epoch-variable part (at a given epoch And the delta increase of the frozen tree compared to its value at the previous epoch will be: The variable part can then be expressed as: Ignoring the constant parts, the increase in memory consumption given by the variable part would be approximately 59800 bytes per token address per epoch, so ~ 58kB |
Thanks! Excellent write-up. I think that those memory costs are fine for the foreseeable future. |
Closing as completed |
Currently the MASP storage is managed in a suboptimal way. More specifically, the following can be observed:
subspace
, meaning they are subject to diffs and merklization which is unneeded because we only need the most updated value of the masp keys and we already manage the masp merkle trees in a separate wayTransfer
andTransaction
objects (plus some other metadata) into storage to allow clients to scan the history of masp transactions and construct their internal states to correctly produce future transactionsconversion_state
namada/core/src/ledger/masp_conversions.rs
Lines 25 to 38 in 6c6b3bf
Storage
objectIssue 1 should be solved by #2265.
Issue 2 could be solved by not writing this data to storage since we already have it in the block storage. Clients could query the blocks instead (possibly with the help of an indexer), to get the same results. We should also make sure to keep the blocks around in case of a chain upgrade (see discussion at #2248 (comment)).
Issue 3 is probably not as major as the previous two. The
ConversionState
is effectively only queried by clients and updated in protocol once per epoch, so we could probably move it to storage to reduce the memory consumption (hopefully without increasing the query time too much because of the need to retrieve data from storage first)The text was updated successfully, but these errors were encountered: