Skip to content

Commit

Permalink
[resharding] Nightshade V3 shard layout for protocol version 65 (near…
Browse files Browse the repository at this point in the history
…#10725)

This PR is to be cherry-picked into release 1.38.0 for splitting shard 2
into two parts.

Hot and kai-ching both fall on shard 2 which has been causing a lot of
congestion.

Zulip thread:
https://near.zulipchat.com/#narrow/stream/308695-nearone.2Fprivate/topic/constant.20congestion.20on.20shard.202/near/425367222

---------

Co-authored-by: wacban <wac.banasik@gmail.com>
  • Loading branch information
2 people authored and marcelo-gonzalez committed Mar 11, 2024
1 parent 77f40fa commit 1f98f92
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions chain/chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ impl ChainStore {
) -> Result<(), Error> {
tracing::trace!(target: "resharding", ?protocol_version, shard_id, receipts_shard_id, "reassign_outgoing_receipts_for_resharding");
// If simple nightshade v2 is enabled and stable use that.
// Same reassignment of outgoing receipts works for simple nightshade v3
if checked_feature!("stable", SimpleNightshadeV2, protocol_version) {
Self::reassign_outgoing_receipts_for_resharding_v2(
receipts,
Expand Down
3 changes: 3 additions & 0 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ pub enum ProtocolFeature {
/// Resharding V2. A new implementation for resharding and a new shard
/// layout for the production networks.
SimpleNightshadeV2,
/// Built on top of Resharding V2. Changes shard layout to V3 to split shard 2 into two parts.
SimpleNightshadeV3,
/// In case not all validator seats are occupied our algorithm provide incorrect minimal seat
/// price - it reports as alpha * sum_stake instead of alpha * sum_stake / (1 - alpha), where
/// alpha is min stake ratio
Expand Down Expand Up @@ -176,6 +178,7 @@ impl ProtocolFeature {
ProtocolFeature::RestrictTla
| ProtocolFeature::TestnetFewerBlockProducers
| ProtocolFeature::SimpleNightshadeV2 => 64,
ProtocolFeature::SimpleNightshadeV3 => 65,

// Nightly features
#[cfg(feature = "protocol_feature_fix_staking_threshold")]
Expand Down
5 changes: 5 additions & 0 deletions core/primitives/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ impl AllEpochConfig {
}

fn config_nightshade(config: &mut EpochConfig, protocol_version: ProtocolVersion) {
if checked_feature!("stable", SimpleNightshadeV3, protocol_version) {
Self::config_nightshade_impl(config, ShardLayout::get_simple_nightshade_layout_v3());
return;
}

if checked_feature!("stable", SimpleNightshadeV2, protocol_version) {
Self::config_nightshade_impl(config, ShardLayout::get_simple_nightshade_layout_v2());
return;
Expand Down
59 changes: 59 additions & 0 deletions core/primitives/src/shard_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ impl ShardLayout {
)
}

/// Returns the simple nightshade layout, version 3, that will be used in production.
pub fn get_simple_nightshade_layout_v3() -> ShardLayout {
ShardLayout::v1(
vec![
"aurora",
"aurora-0",
"game.hot.tg",
"kkuuue2akv_1630967379.near",
"tge-lockup.sweat",
]
.into_iter()
.map(|s| s.parse().unwrap())
.collect(),
Some(vec![vec![0], vec![1], vec![2, 3], vec![4], vec![5]]),
3,
)
}

/// Given a parent shard id, return the shard uids for the shards in the current shard layout that
/// are split from this parent shard. If this shard layout has no parent shard layout, return None
pub fn get_children_shards_uids(&self, parent_shard_id: ShardId) -> Option<Vec<ShardUId>> {
Expand Down Expand Up @@ -568,6 +586,7 @@ mod tests {
let v0 = ShardLayout::v0(1, 0);
let v1 = ShardLayout::get_simple_nightshade_layout();
let v2 = ShardLayout::get_simple_nightshade_layout_v2();
let v3 = ShardLayout::get_simple_nightshade_layout_v3();

insta::assert_snapshot!(serde_json::to_string_pretty(&v0).unwrap(), @r###"
{
Expand Down Expand Up @@ -638,5 +657,45 @@ mod tests {
}
}
"###);
insta::assert_snapshot!(serde_json::to_string_pretty(&v3).unwrap(), @r###"
{
"V1": {
"boundary_accounts": [
"aurora",
"aurora-0",
"game.hot.tg",
"kkuuue2akv_1630967379.near",
"tge-lockup.sweat"
],
"shards_split_map": [
[
0
],
[
1
],
[
2,
3
],
[
4
],
[
5
]
],
"to_parent_shard_map": [
0,
1,
2,
2,
3,
4
],
"version": 3
}
}
"###);
}
}
3 changes: 3 additions & 0 deletions core/store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,13 @@ impl Default for StoreConfig {
(ShardUId { version: 1, shard_id: 3 }, 3_000_000_000),
// In simple nightshade v2 the heavy contract "token.sweat" is in shard 4
(ShardUId { version: 2, shard_id: 4 }, 3_000_000_000),
// In simple nightshade v3 the heavy contract "token.sweat" is in shard 5
(ShardUId { version: 3, shard_id: 5 }, 3_000_000_000),
// Shard 1 is dedicated to aurora and it had very few cache
// misses even with cache size of only 50MB
(ShardUId { version: 1, shard_id: 1 }, 50_000_000),
(ShardUId { version: 2, shard_id: 1 }, 50_000_000),
(ShardUId { version: 3, shard_id: 1 }, 50_000_000),
]),
shard_cache_deletions_queue_capacity: DEFAULT_SHARD_CACHE_DELETIONS_QUEUE_CAPACITY,
},
Expand Down

0 comments on commit 1f98f92

Please sign in to comment.