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

feat: Move shard-assignment for chunk producers to nightly #11203

Merged
merged 15 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -32,7 +32,7 @@ fn build_chain() {
// cargo insta test --accept -p near-chain --features nightly -- tests::simple_chain::build_chain
let hash = chain.head().unwrap().last_block_hash;
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"CJaRGRZy7GE3KkSp55HE8VheYHzPr11nRpsh9rK9F1ag");
insta::assert_snapshot!(hash, @"C3zeKRZubVungxfrSdq379TSCYnuz2YzjEkcJTdm3pU4");
} else {
insta::assert_snapshot!(hash, @"2WHohfYksQnwKwSEoTKpkseu2RWthbGf9kmGetgHgfQQ");
}
Expand All @@ -50,7 +50,7 @@ fn build_chain() {

let hash = chain.head().unwrap().last_block_hash;
if cfg!(feature = "nightly") {
insta::assert_snapshot!(hash, @"HoQty43QCe2RPp3iZWv61TaJWW18pTqaHu2t5hWtnVir");
insta::assert_snapshot!(hash, @"EjLaoHRiAdRp2NcDqwbMcAYYxGfcv5R7GuYUNfRpaJvB");
} else {
insta::assert_snapshot!(hash, @"HJuuENeSwwikoR9BZA7cSonxAPZgY5mKQWL2pSXwjAwZ");
}
Expand Down
3 changes: 3 additions & 0 deletions core/primitives-core/src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pub const TESTNET: &str = "testnet";

/// Temporary StatelessNet active from 2024-02-01.
pub const STATELESSNET: &str = "statelessnet";

/// Pre-release testing environment.
pub const MOCKNET: &str = "mocknet";
11 changes: 6 additions & 5 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ pub enum ProtocolFeature {
SingleShardTracking,
// Stateless validation: state witness size limits.
StateWitnessSizeLimit,
// Stateless validation: in statelessnet, shuffle shard assignments for chunk producers every
// epoch.
StatelessnetShuffleShardAssignmentsForChunkProducers,
// Shuffle shard assignments for chunk producers at every epoch.
ShuffleShardAssignments,
// Stateless validation: limit the size of storage proof generated by a single receipt.
// Receipts which generate storage proofs larger than this limit will be rejected.
// Protocol 85 also decreased the soft per-chunk storage proof limit to 3MB.
Expand Down Expand Up @@ -222,7 +221,6 @@ impl ProtocolFeature {
ProtocolFeature::LowerValidatorKickoutPercentForDebugging => 81,
ProtocolFeature::SingleShardTracking => 82,
ProtocolFeature::StateWitnessSizeLimit => 83,
ProtocolFeature::StatelessnetShuffleShardAssignmentsForChunkProducers => 84,
ProtocolFeature::PerReceiptHardStorageProofLimit => 85,
wacban marked this conversation as resolved.
Show resolved Hide resolved
ProtocolFeature::PartialEncodedStateWitness => 86,

Expand All @@ -237,6 +235,9 @@ impl ProtocolFeature {
#[cfg(feature = "protocol_feature_nonrefundable_transfer_nep491")]
ProtocolFeature::NonrefundableStorage => 140,
ProtocolFeature::CongestionControl => 142,
// 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,
}
}

Expand All @@ -256,7 +257,7 @@ pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "statelessnet_pr
86
} else if cfg!(feature = "nightly_protocol") {
// On nightly, pick big enough version to support all features.
142
143
} else {
// Enable all stable features.
STABLE_PROTOCOL_VERSION
Expand Down
59 changes: 37 additions & 22 deletions core/primitives/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ impl AllEpochConfig {
pub fn for_protocol_version(&self, protocol_version: ProtocolVersion) -> EpochConfig {
let mut config = self.genesis_epoch_config.clone();

Self::config_mocknet(&mut config, &self.chain_id);

Self::config_stateless_net(&mut config, &self.chain_id, protocol_version);

if !self.use_production_config {
return config;
}

Self::config_validator_selection(&mut config, protocol_version);
tayfunelmas marked this conversation as resolved.
Show resolved Hide resolved

Self::config_nightshade(&mut config, protocol_version);

Self::config_chunk_only_producers(&mut config, &self.chain_id, protocol_version);
Expand All @@ -153,33 +157,44 @@ impl AllEpochConfig {
&self.chain_id
}

/// Configures mocknet-specific features only.
fn config_mocknet(config: &mut EpochConfig, chain_id: &str) {
if chain_id != near_primitives_core::chains::MOCKNET {
return;
}
// In production (mainnet/testnet) and nightly environments this setting is guarded by
// ProtocolFeature::ShuffleShardAssignments. (see config_validator_selection function).
// For pre-release environment such as mocknet, which uses features between production and nightly
// (eg. stateless validation) we enable it by default with stateless validation in order to exercise
// the codepaths for state sync more often.
// TODO(#11201): When stabilizing "ShuffleShardAssignments" in mainnet,
// also remove this temporary code and always rely on ShuffleShardAssignments.
config.validator_selection_config.shuffle_shard_assignment_for_chunk_producers = true;
}

/// Configures statelessnet-specific features only.
fn config_stateless_net(
config: &mut EpochConfig,
chain_id: &str,
protocol_version: ProtocolVersion,
) {
// StatelessNet only.
if chain_id == near_primitives_core::chains::STATELESSNET {
// Lower the kickout threshold so the network is more stable while
// we figure out issues with block and chunk production.
if checked_feature!(
"stable",
LowerValidatorKickoutPercentForDebugging,
protocol_version
) {
config.block_producer_kickout_threshold = 50;
config.chunk_producer_kickout_threshold = 50;
}
// Shuffle shard assignments every epoch, to trigger state sync more
// frequently to exercise that code path.
if checked_feature!(
"stable",
StatelessnetShuffleShardAssignmentsForChunkProducers,
protocol_version
) {
config.validator_selection_config.shuffle_shard_assignment_for_chunk_producers =
true;
}
if chain_id != near_primitives_core::chains::STATELESSNET {
return;
}
// Lower the kickout threshold so the network is more stable while
// we figure out issues with block and chunk production.
if checked_feature!("stable", LowerValidatorKickoutPercentForDebugging, protocol_version) {
config.block_producer_kickout_threshold = 50;
config.chunk_producer_kickout_threshold = 50;
}
}

/// Configures validator-selection related features.
fn config_validator_selection(config: &mut EpochConfig, protocol_version: ProtocolVersion) {
// Shuffle shard assignments every epoch, to trigger state sync more
// frequently to exercise that code path.
if checked_feature!("stable", ShuffleShardAssignments, protocol_version) {
config.validator_selection_config.shuffle_shard_assignment_for_chunk_producers = true;
}
}

Expand Down
Loading