Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Flat Storage #399
Flat Storage #399
Changes from 5 commits
a651a7d
9004d02
34ae994
8fa49ee
9b73a71
3fa77c9
548e33d
8515b1b
181b65b
51e35ab
79f324e
dabaea3
a9ccf71
4ce8b60
809095e
32b878b
210318a
d7c88f5
b8dcf87
f2a22fc
855492a
db247a0
1ad54cd
9222c43
066290f
da383fa
c36593e
a886279
aeb999a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing some concrete values here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires some understanding from reader, mentioned in "Storage Reads" subsection.
But we don't expect big difference in costs, the main goal is to solve undercharging issue.
There is also no big difference for different contracts. I could mention caching and read_cached_trie_node but the document is already quite big.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to add a discussion about the following here:
Flat storage conceptually makes a tradeoff between making reads cheaper and simpler to charge gas fees for by making writes more expensive because writes have to keep the flat state up-to-date as well. The assertion of this work is that this tradeoff is a good one to make.
For a read heavy workload, the above tradeoff should be good. But this work should also demonstrate that the tradeoff is acceptable for write heavy workloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is too early to mention in this section. Mentioned this in "Drawbacks" session together with other tradeoffs we make ("we have to keep it up-to-date, which results in 1 extra disk write for changed key, and 1 auxiliary disk write + removal for each FSD...")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one other alternative would be to change the tree type. (for example by moving to something like AVL or B-trees) -
let's mention pros&cons of this vs flat storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, changed this subsection significantly by listing other ideas: getting rid of state root, increasing TTN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move the 'drawbacks' section here.
And also mention the (rough) new storage costs after we have flat storage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the "drawbacks" section is in the end by NEP design, and it makes sense there - I counted 6 different drawbacks, most of them require prior understanding how everything works. Costs go to "Storage Reads" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO needs to be resolved (or removed) before accepting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to write separate NEP for this. WIP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the additional NEP will cover this topic in detail. I am curious about the case where
h
or one its children has many outgoing branches vs.h
has a single deep branch. Will the proposal below work just fine in both cases and ensure that we do not store too many FSD in memory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will precisely happen in such case:
If it is the second, then do you need any special handling to identify that you have already processed an empty block or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an open question, should be answered in NEP like #460.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance on abnormal conditions of the network (maybe during an attack), that this value of
X
is not large enough, and the client will return a different value after reading than the one expected?As I understand, we are fetching this value from a non-finalized block, so there is a chance for this to happen, even if highly improbable. How would the system react in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question! This is actually the part that I left out about the proposal to set gas limit to zero for blocks with height larger than the latest final block’s height + X. If we implement that proposal, blocks that are further than X blocks away from the last final block can't include any new chunks, in other words, they are just empty blocks. This is a way to allow the blockchain to recover in case of some abnormal conditions. With that change, FlatStorage only need to store deltas for blocks from the last final block to last final block + X, thus at most X blocks. Any other block further than last final block + X will just have an empty delta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FlatStateDelta
. They are also persisted on disk, but we don't read from disk during block processing. We only read from disk for this column when node first starts and FlatStorage loads deltas for all blocks after the flat head into memory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where to add this so just picking a random point. How do you propose to handle the case where a node is not tracking all shards. I imagine that you would want to garbage collect state from shards that you are no longer tracking. Will state for each shard be stored in a separate column?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. There is no need to store state in separate column. For now we can afford naive removals, I added more details to "Drawbacks" section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is also a higher risk of database corruption -- as with TRIEs the rows were only appended (or deleted) - while with flat storage, we do read-modify-write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, added paragraph for that - together with replayability becoming more challenging.