From 6f324e84a7a7162956f0b9985094ee146919f5ae Mon Sep 17 00:00:00 2001 From: nikurt <86772482+nikurt@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:52:55 +0200 Subject: [PATCH] feat(COP): only in testnet: reduce the number of block producers (#9563) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In chains that are not `mainnet`: * Decrease the number of block producers to 20 * Decrease the number of chunk only producers to 100 This change lets testnet in its current state perform testing of chunk-only producers. --------- Signed-off-by: dependabot[bot] Co-authored-by: Anton Puhach Co-authored-by: Jakob Meier Co-authored-by: Simonas Kazlauskas Co-authored-by: Saketh Are Co-authored-by: Shreyan Gupta Co-authored-by: Ekleog-NEAR <96595974+Ekleog-NEAR@users.noreply.github.com> Co-authored-by: Marcelo Diop-Gonzalez Co-authored-by: Bowen Wang Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: wacban Co-authored-by: Adam Chudaś <18039094+staffik@users.noreply.github.com> Co-authored-by: robin-near <111538878+robin-near@users.noreply.github.com> Co-authored-by: Olga Telezhnaya Co-authored-by: i-fix-typos <146758284+i-fix-typos@users.noreply.github.com> Co-authored-by: Aleksandr Logunov Co-authored-by: Jure Bajic Co-authored-by: dj8yf0μl <26653921+dj8yfo@users.noreply.github.com> --- CHANGELOG.md | 1 + chain/epoch-manager/src/shard_tracker.rs | 2 +- chain/epoch-manager/src/test_utils.rs | 2 +- chain/epoch-manager/src/tests/mod.rs | 2 +- core/chain-configs/src/genesis_config.rs | 6 +++- core/primitives-core/src/version.rs | 3 ++ core/primitives/src/epoch_manager.rs | 32 ++++++++++++++++--- .../src/tests/client/resharding.rs | 2 +- 8 files changed, 41 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f58ce2bd522..6a9c5f2439c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Protocol Changes * The support for fixed shards in shard layout was removed. [#9219](https://github.com/near/nearcore/pull/9219) * Restrict the creation of non-implicit top-level account that are longer than 32 bytes. Only the registrar account can create them. [#9589](https://github.com/near/nearcore/pull/9589) +* Adjust the number of block producers and chunk producers on testnet to facilitate testing of chunk-only producers [#9563](https://github.com/near/nearcore/pull/9563) ### Non-protocol Changes diff --git a/chain/epoch-manager/src/shard_tracker.rs b/chain/epoch-manager/src/shard_tracker.rs index 2cbf5a71caf..c541647f71b 100644 --- a/chain/epoch-manager/src/shard_tracker.rs +++ b/chain/epoch-manager/src/shard_tracker.rs @@ -237,7 +237,7 @@ mod tests { }; EpochManager::new( store, - AllEpochConfig::new(use_production_config, initial_epoch_config), + AllEpochConfig::new(use_production_config, initial_epoch_config, "test-chain"), genesis_protocol_version, reward_calculator, vec![ValidatorStake::new( diff --git a/chain/epoch-manager/src/test_utils.rs b/chain/epoch-manager/src/test_utils.rs index 5e236fbbabe..1fde5aaabc3 100644 --- a/chain/epoch-manager/src/test_utils.rs +++ b/chain/epoch-manager/src/test_utils.rs @@ -154,7 +154,7 @@ pub fn epoch_config_with_production_config( shard_layout: ShardLayout::v0(num_shards, 0), validator_max_kickout_stake_perc: 100, }; - AllEpochConfig::new(use_production_config, epoch_config) + AllEpochConfig::new(use_production_config, epoch_config, "test-chain") } pub fn epoch_config( diff --git a/chain/epoch-manager/src/tests/mod.rs b/chain/epoch-manager/src/tests/mod.rs index 581aa563e08..83470815584 100644 --- a/chain/epoch-manager/src/tests/mod.rs +++ b/chain/epoch-manager/src/tests/mod.rs @@ -2207,7 +2207,7 @@ fn test_protocol_version_switch_with_many_seats() { validator_selection_config: Default::default(), validator_max_kickout_stake_perc: 100, }; - let config = AllEpochConfig::new(false, epoch_config); + let config = AllEpochConfig::new(false, epoch_config, "test-chain"); let amount_staked = 1_000_000; let validators = vec![ stake("test1".parse().unwrap(), amount_staked), diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index c9bfe4b4c15..247fd86c18d 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -219,7 +219,11 @@ impl From<&GenesisConfig> for EpochConfig { impl From<&GenesisConfig> for AllEpochConfig { fn from(genesis_config: &GenesisConfig) -> Self { let initial_epoch_config = EpochConfig::from(genesis_config); - let epoch_config = Self::new(genesis_config.use_production_config(), initial_epoch_config); + let epoch_config = Self::new( + genesis_config.use_production_config(), + initial_epoch_config, + &genesis_config.chain_id, + ); epoch_config } } diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index e35f41ffd84..8c8c41957f4 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -126,6 +126,8 @@ pub enum ProtocolFeature { /// Enables block production with post-state-root. /// NEP: https://github.com/near/NEPs/pull/507 PostStateRoot, + /// Increases the number of chunk producers. + TestnetFewerBlockProducers, } impl ProtocolFeature { @@ -181,6 +183,7 @@ impl ProtocolFeature { #[cfg(feature = "protocol_feature_simple_nightshade_v2")] ProtocolFeature::SimpleNightshadeV2 => 135, ProtocolFeature::PostStateRoot => 136, + ProtocolFeature::TestnetFewerBlockProducers => 140, } } } diff --git a/core/primitives/src/epoch_manager.rs b/core/primitives/src/epoch_manager.rs index 5f7175a0d89..9744e39a1d8 100644 --- a/core/primitives/src/epoch_manager.rs +++ b/core/primitives/src/epoch_manager.rs @@ -83,11 +83,17 @@ pub struct AllEpochConfig { use_production_config: bool, /// EpochConfig from genesis genesis_epoch_config: EpochConfig, + /// Chain Id. Some parameters are specific to certain chains. + chain_id: String, } impl AllEpochConfig { - pub fn new(use_production_config: bool, genesis_epoch_config: EpochConfig) -> Self { - Self { use_production_config, genesis_epoch_config } + pub fn new( + use_production_config: bool, + genesis_epoch_config: EpochConfig, + chain_id: &str, + ) -> Self { + Self { use_production_config, genesis_epoch_config, chain_id: chain_id.to_string() } } pub fn for_protocol_version(&self, protocol_version: ProtocolVersion) -> EpochConfig { @@ -98,7 +104,7 @@ impl AllEpochConfig { Self::config_nightshade(&mut config, protocol_version); - Self::config_chunk_only_producers(&mut config, protocol_version); + Self::config_chunk_only_producers(&mut config, &self.chain_id, protocol_version); Self::config_max_kickout_stake(&mut config, protocol_version); @@ -126,7 +132,11 @@ impl AllEpochConfig { config.avg_hidden_validator_seats_per_shard = vec![0; num_shards]; } - fn config_chunk_only_producers(config: &mut EpochConfig, protocol_version: u32) { + fn config_chunk_only_producers( + config: &mut EpochConfig, + chain_id: &str, + protocol_version: u32, + ) { if checked_feature!("stable", ChunkOnlyProducers, protocol_version) { let num_shards = config.shard_layout.num_shards() as usize; // On testnet, genesis config set num_block_producer_seats to 200 @@ -139,6 +149,20 @@ impl AllEpochConfig { config.chunk_producer_kickout_threshold = 80; config.validator_selection_config.num_chunk_only_producer_seats = 200; } + + // Adjust the number of block and chunk producers for all chains except + // mainnet, to make it easier to test the change. + if chain_id != crate::chains::MAINNET + && checked_feature!("stable", TestnetFewerBlockProducers, protocol_version) + { + let num_shards = config.shard_layout.num_shards() as usize; + // Decrease the number of block producers from 100 to 20. + config.num_block_producer_seats = 20; + config.num_block_producer_seats_per_shard = + vec![config.num_block_producer_seats; num_shards]; + // Decrease the number of chunk producers. + config.validator_selection_config.num_chunk_only_producer_seats = 100; + } } fn config_max_kickout_stake(config: &mut EpochConfig, protocol_version: u32) { diff --git a/integration-tests/src/tests/client/resharding.rs b/integration-tests/src/tests/client/resharding.rs index 94aedcf2364..238e8df0b76 100644 --- a/integration-tests/src/tests/client/resharding.rs +++ b/integration-tests/src/tests/client/resharding.rs @@ -742,7 +742,7 @@ fn setup_genesis( genesis.config.protocol_upgrade_stake_threshold = Rational32::new(7, 10); let default_epoch_config = EpochConfig::from(&genesis.config); - let all_epoch_config = AllEpochConfig::new(true, default_epoch_config); + let all_epoch_config = AllEpochConfig::new(true, default_epoch_config, "test-chain"); let epoch_config = all_epoch_config.for_protocol_version(genesis_protocol_version); genesis.config.shard_layout = epoch_config.shard_layout;