Skip to content

Commit

Permalink
feat(resharding) - Stabilize Resharding V3 (#12792)
Browse files Browse the repository at this point in the history
# Feature to stabilize

This PR stabilizes Resharding V3. It introduces a new implementation for
resharding and two new shard layouts for the production networks.

# Context

- NEP: near/NEPs#568
- Implementation: #11881

# Testing and QA
This feature was extensively tested in unit tests, testloop tests and in
forknet.

# Checklist
- [ ] Link to nightly nayduck run https://nayduck.nearone.org/#/run/1142
- [x] Update CHANGELOG.md to include this protocol feature in the
`Unreleased` section.
  • Loading branch information
wacban authored Jan 24, 2025
1 parent 02494d7 commit 09022ca
Show file tree
Hide file tree
Showing 17 changed files with 568 additions and 191 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
* Add cross-shard bandwidth scheduler which manages transferring receipts between shards,
enabling higher throughput of cross-shard receipts and better horizontal scalability.
NEP-584 (https://github.com/near/NEPs/pull/584)
* Resharding V3 - a new implementation for resharding and two new shard layouts
for the production networks.
NEP-568 (https://github.com/near/NEPs/pull/568)

### Non-protocol Changes
* Parallelize transaction validation (including signature checks) before `verify_and_charge_transaction`,
significantly improving throughput for transaction processing on the nodes. [#12654](https://github.com/near/nearcore/pull/12654)
* Current Epoch State Sync - Moves the sync point from the previous epoch to the
current epoch. [#12102](https://github.com/near/nearcore/pull/12102)

## 2.4.0

Expand Down Expand Up @@ -225,7 +230,7 @@ to pay for the storage of their accounts.
* `/debug` page now has client_config linked.
You can also check your client_config directly at /debug/client_config
[#8400](https://github.com/near/nearcore/pull/8400)
* Added cold store loop - a background thread that copies data from hot to cold storage and a new json rpc endpoing - split_storage_info - that
* Added cold store loop - a background thread that copies data from hot to cold storage and a new json rpc endpoint - split_storage_info - that
exposes debug info about the split storage.
[#8432](https://github.com/near/nearcore/pull/8432)
* `ClientConfig` can be updated while the node is running.
Expand Down Expand Up @@ -443,7 +448,7 @@ to pay for the storage of their accounts.
### Protocol Changes

* Enable access key nonce range for implicit accounts to prevent tx hash collisions.
* Upgraded our version of pwasm-utils to 0.18 -- the old one severely undercounted stack usage in some cases.
* Upgraded our version of pwasm-utils to 0.18 -- the old one severely under-counted stack usage in some cases.

### Non-protocol Changes

Expand Down
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"GARF4HBtQJ41quFA9fvjHpbVYT4o15syhL3FkH1o7poT");
} else {
insta::assert_snapshot!(hash, @"3JFsPBWs2CmNmvDD49ytuk26H6d4gryBueLBgeD2YojF");
insta::assert_snapshot!(hash, @"3e2u5p2hUijQd7o5Dg1pK9QAHGZ9uCK19KDV86TJW78f");
}

for i in 1..5 {
Expand All @@ -53,7 +53,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"HiXuBfW5Xd6e8ZTbMhwtPEXeZxe7macc8DvaWryNdvcf");
} else {
insta::assert_snapshot!(hash, @"5pEwiJcPbEExts9j2fmVSLUYCVRYHbhMDiyaa1LqpxcU");
insta::assert_snapshot!(hash, @"Gh5KqeboPbLh2ZwTqQLY2n5FQdPasFAEkPVfnM66LGjn");
}
}

Expand Down
9 changes: 8 additions & 1 deletion chain/epoch-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,9 +1293,16 @@ impl EpochManager {
let next_epoch_id = self.get_next_epoch_id_from_prev_block(parent_hash)?;
if self.will_shard_layout_change(parent_hash)? {
let shard_layout = self.get_shard_layout(&next_epoch_id)?;
// The expect below may be triggered when the protocol version
// changes by multiple versions at once and multiple shard layout
// changes are captured. In this case the shards from the original
// shard layout are not valid parents in the final shard layout.
//
// This typically occurs in tests that are pegged to start at a
// certain protocol version and then upgrade to stable.
let split_shards = shard_layout
.get_children_shards_ids(shard_id)
.expect("all shard layouts expect the first one must have a split map");
.unwrap_or_else(|| panic!("all shard layouts expect the first one must have a split map, shard_id={shard_id}, shard_layout={shard_layout:?}"));
for next_shard_id in split_shards {
if self.cares_about_shard_in_epoch(&next_epoch_id, account_id, next_shard_id)? {
return Ok(true);
Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc/jsonrpc-tests/res/genesis_config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"protocol_version": 74,
"protocol_version": 76,
"genesis_time": "1970-01-01T00:00:00.000000000Z",
"chain_id": "sample",
"genesis_height": 0,
Expand Down Expand Up @@ -86,4 +86,4 @@
"num_chunk_validator_seats": 300,
"chunk_producer_assignment_changes_limit": 5,
"records": []
}
}
30 changes: 11 additions & 19 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ pub enum ProtocolFeature {
/// Increases main_storage_proof_size_soft_limit parameter from 3mb to 4mb
IncreaseStorageProofSizeSoftLimit,

/// Protocol version reserved for use in resharding tests.
SimpleNightshadeTestonly,

// Shuffle shard assignments for chunk producers at every epoch.
ShuffleShardAssignments,
/// Cross-shard congestion control according to <https://github.com/near/NEPs/pull/539>.
Expand All @@ -174,8 +171,10 @@ pub enum ProtocolFeature {
ChunkEndorsementsInBlockHeader,
/// Store receipts in State in the StateStoredReceipt format.
StateStoredReceipt,
/// Resharding V3
/// Resharding V3 - Adding "game.hot.tg-0" boundary.
SimpleNightshadeV4,
/// Resharding V3 - Adding "earn.kaiching" boundary.
SimpleNightshadeV5,
/// Exclude contract code from the chunk state witness and distribute it to chunk validators separately.
ExcludeContractCodeFromStateWitness,
/// A scheduler which limits bandwidth for sending receipts between shards.
Expand Down Expand Up @@ -261,15 +260,13 @@ impl ProtocolFeature {
| ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions
| ProtocolFeature::FixChunkProducerStakingThreshold
| ProtocolFeature::RelaxedChunkValidation
// BandwidthScheduler must be enabled before ReshardingV3! When
// releasing this feature please make sure to schedule separate
// protocol upgrades for those features!
| ProtocolFeature::BandwidthScheduler => 74,

// This protocol version is reserved for use in resharding tests. An extra resharding
// is simulated on top of the latest shard layout in production. Note that later
// protocol versions will still have the production layout.
ProtocolFeature::SimpleNightshadeTestonly => 100,
// BandwidthScheduler and CurrentEpochStateSync must be enabled
// before ReshardingV3! When releasing this feature please make sure
// to schedule separate protocol upgrades for these features.
| ProtocolFeature::BandwidthScheduler
| ProtocolFeature::CurrentEpochStateSync => 74,
ProtocolFeature::SimpleNightshadeV4 => 75,
ProtocolFeature::SimpleNightshadeV5 => 76,

// Nightly features:
#[cfg(feature = "protocol_feature_fix_contract_loading_cost")]
Expand All @@ -279,11 +276,6 @@ impl ProtocolFeature {
// TODO(#11201): When stabilizing this feature in mainnet, also remove the temporary code
// that always enables this for mocknet (see config_mocknet function).
ProtocolFeature::ShuffleShardAssignments => 143,
// CurrentEpochStateSync must be enabled before ReshardingV3! When
// releasing this feature please make sure to schedule separate
// protocol upgrades for those features!
ProtocolFeature::CurrentEpochStateSync => 144,
ProtocolFeature::SimpleNightshadeV4 => 146,
ProtocolFeature::ExcludeExistingCodeFromWitnessForCodeLen => 148,
ProtocolFeature::BlockHeightForReceiptId | ProtocolFeature::ProduceOptimisticBlock => {
149
Expand All @@ -299,7 +291,7 @@ impl ProtocolFeature {
}

/// Current protocol version used on the mainnet with all stable features.
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 74;
const STABLE_PROTOCOL_VERSION: ProtocolVersion = 76;

// On nightly, pick big enough version to support all features.
const NIGHTLY_PROTOCOL_VERSION: ProtocolVersion = 149;
Expand Down
80 changes: 62 additions & 18 deletions core/primitives/res/epoch_configs/mainnet/143.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
100,
100,
100,
100,
100,
100
],
"avg_hidden_validator_seats_per_shard": [
Expand All @@ -15,6 +17,8 @@
0,
0,
0,
0,
0,
0
],
"block_producer_kickout_threshold": 80,
Expand All @@ -37,40 +41,80 @@
5
],
"shard_layout": {
"V1": {
"V2": {
"boundary_accounts": [
"aurora",
"aurora-0",
"earn.kaiching",
"game.hot.tg",
"game.hot.tg-0",
"kkuuue2akv_1630967379.near",
"tge-lockup.sweat"
],
"shards_split_map": [
[
"shard_ids": [
0,
1,
8,
9,
6,
7,
4,
5
],
"id_to_index_map": {
"0": 0,
"1": 1,
"4": 6,
"5": 7,
"6": 4,
"7": 5,
"8": 2,
"9": 3
},
"index_to_id_map": {
"0": 0,
"1": 1,
"2": 8,
"3": 9,
"4": 6,
"5": 7,
"6": 4,
"7": 5
},
"shards_split_map": {
"0": [
0
],
[
"1": [
1
],
[
2,
3
"2": [
8,
9
],
[
"4": [
4
],
[
"5": [
5
],
"6": [
6
],
"7": [
7
]
],
"to_parent_shard_map": [
0,
1,
2,
2,
3,
4
],
},
"shards_parent_map": {
"0": 0,
"1": 1,
"4": 4,
"5": 5,
"6": 6,
"7": 7,
"8": 2,
"9": 2
},
"version": 3
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,73 @@
5
],
"shard_layout": {
"V1": {
"V2": {
"boundary_accounts": [
"aurora",
"aurora-0",
"game.hot.tg",
"game.hot.tg-0",
"kkuuue2akv_1630967379.near",
"nightly",
"tge-lockup.sweat"
],
"shards_split_map": [
[
"shard_ids": [
0,
1,
2,
6,
7,
4,
5
],
"id_to_index_map": {
"0": 0,
"1": 1,
"2": 2,
"4": 5,
"5": 6,
"6": 3,
"7": 4
},
"index_to_id_map": {
"0": 0,
"1": 1,
"2": 2,
"3": 6,
"4": 7,
"5": 4,
"6": 5
},
"shards_split_map": {
"0": [
0
],
[
"1": [
1
],
[
"2": [
2
],
[
3
"3": [
6,
7
],
[
4,
5
"4": [
4
],
[
6
"5": [
5
]
],
"to_parent_shard_map": [
0,
1,
2,
3,
4,
4,
5
],
"version": 4
},
"shards_parent_map": {
"0": 0,
"1": 1,
"2": 2,
"4": 4,
"5": 5,
"6": 3,
"7": 3
},
"version": 3
}
},
"num_chunk_producer_seats": 100,
Expand All @@ -91,4 +118,4 @@
],
"chunk_producer_assignment_changes_limit": 5,
"shuffle_shard_assignment_for_chunk_producers": false
}
}
Loading

0 comments on commit 09022ca

Please sign in to comment.