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

[resharding] Add sections for receipt handling #578

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

shreyan-gupta
Copy link

This is complete except for section Handling buffered receipts that target parent shard which is still being discussed.

@shreyan-gupta shreyan-gupta requested a review from a team as a code owner November 20, 2024 13:45
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.

👍

What about POSTPONED_RECEIPT_ID and POSTPONED_RECEIPT, are these in scope of the receipt handling section?

@shreyan-gupta
Copy link
Author

👍

What about POSTPONED_RECEIPT_ID and POSTPONED_RECEIPT, are these in scope of the receipt handling section?

Both have the receiver_id/account_id so should be trivial to split. I don't think we need to mention them explicitly as there's no special handling but can check with the rest of the team for their thoughts

@shreyan-gupta shreyan-gupta merged commit 8ab6927 into resharding Nov 25, 2024
1 check passed
@shreyan-gupta shreyan-gupta deleted the shreyan/resharding/receipts branch November 25, 2024 17:14
github-merge-queue bot pushed a commit to near/nearcore that referenced this pull request Nov 28, 2024
This PR is the core of delayed receipt handling for resharding V3.

## Writeup from NEP

The delayed receipts queue contains all incoming receipts that could not
be executed as part of a block due to resource constraints like compute
cost, gas limits etc. The entries in the delayed receipt queue can
belong to any of the accounts as part of the shard. During a resharding
event, we ideally need to split the delayed receipts across both the
child shards according to the associated account_id with the receipt.

The singleton trie key DelayedReceiptIndices holds the start_index and
end_index associated with the delayed receipt entries for the shard. The
trie key DelayedReceipt { index } contains the actual delayed receipt
associated with some account_id. These are processed in a fifo queue
order during chunk execution.

Note that the delayed receipt trie keys do not have the account_id
prefix. In ReshardingV2, we followed the trivial solution of iterating
through all the delayed receipt queue entries and assigning them to the
appropriate child shard, however due to constraints on the state witness
size limits and instant resharding, this approach is no longer feasible
for ReshardingV3.

For ReshardingV3, we decided to handle the resharding by duplicating the
entries of the delayed receipt queue across both the child shards. This
is great from the perspective of state witness size and instant
resharding as we only need to access the delayed receipt queue root
entry in the trie, however it breaks the assumption that all delayed
receipts in a shard belong to the accounts within that shard.

To resolve this, with the new protocol version, we changed the
implementation of runtime to discard executing delayed receipts that
don't belong to the account_id on that shard.

Note that no delayed receipts are lost during resharding as all receipts
get executed exactly once based on which of the child shards does the
associated account_id belong to.

Source NEP [receipt handling
section](near/NEPs#578).

## Changes in this PR

- We change the implementation of `DelayedReceiptQueueWrapper` to add a
new filter function that filters out all delayed receipts that do not
belong to the current shard.
- `peek_iter` functions is updated appropriately to filter out delayed
receipts as well to ensure compatibility with pipelining.
- Main loop in `process_delayed_receipts` as updated from "while
processing_state.delayed_receipts.len() > 0" to something like "loop
while Some(delayed_receipt) in queue" as we no longer have a precise
count of the number of delayed receipts to process.

## Next steps

- Change memtrie split function to include delayed receipts in child
shards
- Testloop test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Shipped 🚀
Status: NEW
Development

Successfully merging this pull request may close these issues.

2 participants