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

ReshardingV3 memtrie #574

Merged
merged 4 commits into from
Nov 14, 2024
Merged

ReshardingV3 memtrie #574

merged 4 commits into from
Nov 14, 2024

Conversation

shreyan-gupta
Copy link

Adding memtrie section to resharding

@shreyan-gupta shreyan-gupta requested a review from a team as a code owner November 14, 2024 10:41
Copy link

@Trisfald Trisfald left a comment

Choose a reason for hiding this comment

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

🚀

Only a few suggestions about readability

neps/nep-0568.md Outdated

With ReshardingV3 design, there's no protocol change to the structure of MemTries, however the implementation constraints required us to introduce the concept of a Frozen MemTrie. More details are in the [implementation](#state-storage---memtrie-1) section below.

Based on the requirements above, we came up with an algorithm to efficiently split the parent trie into two child tries. Trie entries can be divided into three categories based on whether the trie keys have an account_id prefix and based on the total number of such trie keys. Splitting of these keys are handled in different ways.

Choose a reason for hiding this comment

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

nit: account_id -> account_id

(I guess) Splitting of these keys is handled in different ways.

Sentence above is not crystal clear to me. What about "Each category of keys has its own splitting logic, explained below."?


#### Singleton TrieKey

This category includes the trie keys `TrieKey::DelayedReceiptIndices`, `TrieKey::PromiseYieldIndices`, `TrieKey::BufferedReceiptIndices`. Notably, these are just a single entry (or O(num_shard) entries) in the trie and hence are small enough to read and modify for the children tries efficiently.

Choose a reason for hiding this comment

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

Should we say how these keys are split in practice? Or what happens to them in state witness?

Copy link
Author

Choose a reason for hiding this comment

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

You mean what exact values do we push into the children for these keys? Yes, we should do that, but I think it would be better as part of the delayed receipts, promise yield and buffered receipts section (which I plan to add soon).

Choose a reason for hiding this comment

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

Yeah, sounds good to me

neps/nep-0568.md Outdated

#### TrieKey with AccountID prefix

This category includes most of the trie keys like `TrieKey::Account`, `TrieKey::ContractCode`, `TrieKey::PostponedReceipt`. For these keys, we can efficiently split the trie based on the boundary account trie key. In the example below, "pass" was the split key, note that we only need to read all the intermediate nodes that form a part of the split key and nothing more. The accessed nodes form a part of the state witness. This limits the size of the witness to effectively O(depth) of trie.

Choose a reason for hiding this comment

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

"note that we only need to read all the intermediate nodes that form a part of the split key"
Is this needed for building the state witness proof? While I understand the idea, it would be great if the purpose can be made more explicit

Copy link
Contributor

@wacban wacban left a comment

Choose a reason for hiding this comment

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

LGTM

Can you also mention that memtrie will have to be enabled for the parent shard?

Can you also mention what will be the impact of maintaining the frozen parent and the hybrid arenas on memory consumption?

neps/nep-0568.md Outdated
Comment on lines 66 to 67
* Cross-Shard Traffic: Receipts and buffered receipts sent to the parent shard may
need to be reassigned to one of the child shards.
Copy link
Contributor

Choose a reason for hiding this comment

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

The point below already mentions buffered receipts. I think here we can focus on the cross shard receipts (outgoing / incoming) and describe the rest (delayed, buffered, postponed, yield-resume) in a dedicated section.

Copy link
Author

Choose a reason for hiding this comment

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

My bad, will revert.

@shreyan-gupta
Copy link
Author

LGTM

Can you also mention that memtrie will have to be enabled for the parent shard?

Can you also mention what will be the impact of maintaining the frozen parent and the hybrid arenas on memory consumption?

I added more details about the memory footprint and in-place swap of memtries.

@shreyan-gupta shreyan-gupta merged commit a7bbee7 into resharding Nov 14, 2024
1 check passed
@shreyan-gupta shreyan-gupta deleted the shreyan/resharding/memtrie branch November 14, 2024 16:34
@wacban
Copy link
Contributor

wacban commented Nov 14, 2024

Can you fix the lints on the main NEP PR please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: NEW
Development

Successfully merging this pull request may close these issues.

3 participants