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

NEP-508: Resharding v2 #508

Merged
merged 29 commits into from
Jan 22, 2024
Merged
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
746ea70
Create nep-0508.md
walnut-the-cat Sep 19, 2023
2d80281
Update nep-0508.md
walnut-the-cat Sep 19, 2023
c100504
Update nep-0508.md
walnut-the-cat Sep 19, 2023
396c426
Update nep-0508.md
walnut-the-cat Sep 19, 2023
1f1d107
Update nep-0508.md
walnut-the-cat Sep 21, 2023
1566509
Merge branch 'master' into resharding
walnut-the-cat Oct 25, 2023
68a9b62
Update nep-0508.md
walnut-the-cat Oct 25, 2023
051e5aa
Update nep-0508.md
wacban Oct 26, 2023
c0ae86d
reference implementation description and minor nits
wacban Oct 27, 2023
6a8fedc
fix lint
wacban Oct 27, 2023
3f850d2
alternatives
wacban Oct 27, 2023
b621aab
state sync and stateless validation
wacban Oct 31, 2023
1a0ffee
fix lint
wacban Oct 31, 2023
99a3845
remove state sync from dependencies
wacban Nov 1, 2023
26ec5a5
per comments
wacban Nov 1, 2023
0c3b123
Update nep-0508.md (#517)
Nov 14, 2023
bfe52db
Update nep-0508.md
walnut-the-cat Nov 14, 2023
26a88a3
Update nep-0508.md
walnut-the-cat Nov 15, 2023
2953391
Update nep-0508.md - per comments (#521)
wacban Dec 1, 2023
003fdef
Update nep-0508.md
wacban Dec 1, 2023
3f8d425
Update nep-0508.md
wacban Dec 1, 2023
2aa8dbe
lints
wacban Dec 1, 2023
f447163
Update nep-0508.md
walnut-the-cat Dec 1, 2023
2253fc5
Update nep-0508.md
walnut-the-cat Dec 1, 2023
d372e54
Apply suggestions from code review by mfornet
wacban Dec 7, 2023
be0ce88
Update nep-0508.md
wacban Dec 11, 2023
95b6d29
added the new shard layout and a note that more reshardings will happen
wacban Dec 12, 2023
b2ceb5e
better formatting
wacban Dec 12, 2023
4469e45
Added info about rpc to query the shard layout
wacban Dec 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions neps/nep-0508.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
NEP: 508
Title: Resharding v2
Authors: Waclaw Banasik, Shreyan Gupta, Yoon Hong
Status: Draft
DiscussionsTo: https://github.com/near/nearcore/issues/8992
Type: Protocol
Version: 1.0.0
Created: 2022-09-19
LastUpdated: 2023-09-19
---

## Summary
walnut-the-cat marked this conversation as resolved.
Show resolved Hide resolved

In essence, this NEP is extension of [NEP-40](https://github.com/near/NEPs/blob/master/specs/Proposals/0040-split-states.md), which focused splitting one shard into multiple shards.

We are introducing resharding v2, which supports one shard splitting into two within one epoch at pre-determined split boundary. The NEP includes performance improvement to make resharding feasible under the current state as well as actual resharding in mainnet and testnet (To be specific, spliting shard 3 into two).

While the new approach addresses critical limitations left unsolved in NEP-40 and is expected to remain valid for foreseable future, it does not serve all usecases, such as dynamic resharding.
wacban marked this conversation as resolved.
Show resolved Hide resolved



## Motivation

Currently, NEAR protocol has four shards. With more partners onboarding, we started seeing that some shards occasionally become over-crowded. In addition, with state sync and stateless validation, validators do not need to track all shards and validator hardware requirements can be greatly reduced with smaller shard size.

## Specification

### High level assumptions

* Some form of State sync (centralized or decentralized) is enabled.
* Flat state is enabled.
* Shard split boundary is predetermined. In other words, necessity of shard splitting is manually decided.
* Merkle Patricia Trie is the undelying data structure for the protocol state.
wacban marked this conversation as resolved.
Show resolved Hide resolved
* Minimal epoch gap between two resharding events is X.

### High level requirements

* Resharding should work even when validators stop tracking all shards.
* Resharding should work after stateless validation is enabled.
walnut-the-cat marked this conversation as resolved.
Show resolved Hide resolved
* Resharding should be fast enough so that both state sync and resharding can happen within one epoch.
* ~~Resharding should not require additional hardware from nodes.~~
* This needs to be assessed during test
* Resharding should be fault tolerant
* Chain must not stall in case of resharding failure.
* A validator should be able to recover in case they go offline during resharding.
wacban marked this conversation as resolved.
Show resolved Hide resolved
* For now, our aim is at least allowing a validator to join back after resharding is finished.
* No transaction or receipt should be lost during resharding.
* Resharding should work regardless of number of existing shards.
* There should be no more place (in any apps or tools) where number of shard is hardcoded.

### Out of scope

* Dynamic resharding
* automatically scheduling resharding based on shard usage/capacity
* automatically determining the shard layout
* merging shards
* shard reshuffling
* shard boundary adjustment
* Shard determination logic (shard boundary is still determined by string value)
* Advanced failure handling
* If a validator goes offline during resharding, it can join back immediately and move forward as long as enough time is left to reperform resharding.
* TBD
walnut-the-cat marked this conversation as resolved.
Show resolved Hide resolved

### Required protocol changes

TBD. e.g. configuration changes we have to introduce

### Required state changes

TBD. e.g. additional/updated data a node has to maintain

### Resharding flow

TBD. how resharding happens at the high level

## Reference Implementation
wacban marked this conversation as resolved.
Show resolved Hide resolved

TBD

## Security Implications

[Explicitly outline any security concerns in relation to the NEP, and potential ways to resolve or mitigate them. At the very least, well-known relevant threats must be covered, e.g. person-in-the-middle, double-spend, XSS, CSRF, etc.]

## Alternatives

* Why is this design the best in the space of possible designs?
* TBD
* What other designs have been considered and what is the rationale for not choosing them?
* TBD
* What is the impact of not doing this?
* TBD

## Future possibilities
wacban marked this conversation as resolved.
Show resolved Hide resolved

As noted above, dynamic resharding is out of scope for this NEP and should be implemented in the future. Dynamic resharding includes the following but not limited to:
* automatic determination of split boundary

Check failure on line 97 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines [Context: "* automatic determination of s..."]

neps/nep-0508.md:97 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "* automatic determination of s..."]
* automatic shard splitting and merging based on traffic

Other useful features that can be considered as a follow up:
* account colocation for low latency across account call

Check failure on line 101 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Lists should be surrounded by blank lines [Context: "* account colocation for low l..."]

neps/nep-0508.md:101 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "* account colocation for low l..."]
* shard on demand

## Consequences

### Positive

* Workload across shards will be more evenly distributed.
* Required space to maintain state (either in memory or in persistent disk) will be smaller.
* State sync overhead will be smaller.
* TBD

### Neutral

* Number of shards is expected to increase.
* Underlying trie structure and data structure are not going to change.
* Resharding will create dependency on flat storage and state sync.
wacban marked this conversation as resolved.
Show resolved Hide resolved

### Negative

* The resharding process is still not fully automated. Analyzing shard data, determining the split boundary, and triggering an actual shard split all need to be manually curated by a person.
* During resharding, a node is expected to do more work as it will have to apply changes twice (for the current shard and future shard).
wacban marked this conversation as resolved.
Show resolved Hide resolved
* Increased potential for apps and tools to break without proper shard layout change handling.

### Backwards Compatibility

We do not expect anything to break with this change. Yet, shard splitting can introduce additional complexity on replayability. For instance, as target shard of a receipt and belonging shard of an account can change with shard splitting, shard splitting must be replayed along with transactions at the exact epoch boundary.
wacban marked this conversation as resolved.
Show resolved Hide resolved

## Unresolved Issues (Optional)

[Explain any issues that warrant further discussion. Considerations

- What parts of the design do you expect to resolve through the NEP process before this gets merged?

Check failure on line 133 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Unordered list style [Expected: asterisk; Actual: dash]

neps/nep-0508.md:133:1 MD004/ul-style Unordered list style [Expected: asterisk; Actual: dash]
- What parts of the design do you expect to resolve through the implementation of this feature before stabilization?

Check failure on line 134 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Unordered list style [Expected: asterisk; Actual: dash]

neps/nep-0508.md:134:1 MD004/ul-style Unordered list style [Expected: asterisk; Actual: dash]
- What related issues do you consider out of scope for this NEP that could be addressed in the future independently of the solution that comes out of this NEP?]

Check failure on line 135 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Unordered list style [Expected: asterisk; Actual: dash]

neps/nep-0508.md:135:1 MD004/ul-style Unordered list style [Expected: asterisk; Actual: dash]

## Changelog

[The changelog section provides historical context for how the NEP developed over time. Initial NEP submission should start with version 1.0.0, and all subsequent NEP extensions must follow [Semantic Versioning](https://semver.org/). Every version should have the benefits and concerns raised during the review. The author does not need to fill out this section for the initial draft. Instead, the assigned reviewers (Subject Matter Experts) should create the first version during the first technical review. After the final public call, the author should then finalize the last version of the decision context.]

### 1.0.0 - Initial Version

> Placeholder for the context about when and who approved this NEP version.

#### Benefits

> List of benefits filled by the Subject Matter Experts while reviewing this version:

- Benefit 1

Check failure on line 149 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Unordered list style [Expected: asterisk; Actual: dash]

neps/nep-0508.md:149:1 MD004/ul-style Unordered list style [Expected: asterisk; Actual: dash]
- Benefit 2

Check failure on line 150 in neps/nep-0508.md

View workflow job for this annotation

GitHub Actions / markdown-lint

Unordered list style [Expected: asterisk; Actual: dash]

neps/nep-0508.md:150:1 MD004/ul-style Unordered list style [Expected: asterisk; Actual: dash]

#### Concerns

> Template for Subject Matter Experts review for this version:
> Status: New | Ongoing | Resolved

| # | Concern | Resolution | Status |
| --: | :------ | :--------- | -----: |
| 1 | | | |
| 2 | | | |

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
Loading