Skip to content

Commit

Permalink
feat: Move shard-assignment for chunk producers to nightly (#11203)
Browse files Browse the repository at this point in the history
Per #11190, move the shard-assignment shuffling feature for chunk
producers to nightly.

Also enable this feature for mocknet together with stateless validation
to exercise the state sync code path more often. Note that the guarding
for the feature in nightly/prod is different from mocknet, as we use
mocknet to exercise (stateless validation) features in between prod and
nightly.

After this change, shard shuffling will be activated in the following
cases:

1) In "nightly", it will be active by default, since we move the feature
among the set of nightly features and update the protocol version
accordingly (143).
2) In "mocknet", it will be active by default, as we enable it directly
when chain id == "mocknet".
3) In all other networks (including "mainnet", "testnet", and
"statelessnet"), it will be disabled by default and will only be enabled
(later) explicitly by moving the feature from nightly to stable protocol
version.

Compiling the binary with or without "statelessnet_protocol" will not
have any effect on the enablement of the feature (instead need to
compile with "nightly").
  • Loading branch information
tayfunelmas committed May 9, 2024
1 parent 92ee5d2 commit d4eb66f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
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,
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);

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

0 comments on commit d4eb66f

Please sign in to comment.