Skip to content

Commit

Permalink
feat(COP): only in testnet: reduce the number of block producers (#9563)
Browse files Browse the repository at this point in the history
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] <support@github.com>
Co-authored-by: Anton Puhach <anton@near.org>
Co-authored-by: Jakob Meier <mail@jakobmeier.ch>
Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me>
Co-authored-by: Saketh Are <saketh.are@gmail.com>
Co-authored-by: Shreyan Gupta <shreyan@near.org>
Co-authored-by: Ekleog-NEAR <96595974+Ekleog-NEAR@users.noreply.github.com>
Co-authored-by: Marcelo Diop-Gonzalez <marcelo827@gmail.com>
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: wacban <wacban@users.noreply.github.com>
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 <olyatelezhnaya@gmail.com>
Co-authored-by: i-fix-typos <146758284+i-fix-typos@users.noreply.github.com>
Co-authored-by: Aleksandr Logunov <alex.logunov@near.org>
Co-authored-by: Jure Bajic <jure@near.org>
Co-authored-by: dj8yf0μl <26653921+dj8yfo@users.noreply.github.com>
  • Loading branch information
18 people committed Oct 11, 2023
1 parent ae1c618 commit 6f324e8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chain/epoch-manager/src/shard_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion chain/epoch-manager/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion chain/epoch-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
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 @@ -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 {
Expand Down Expand Up @@ -181,6 +183,7 @@ impl ProtocolFeature {
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
ProtocolFeature::SimpleNightshadeV2 => 135,
ProtocolFeature::PostStateRoot => 136,
ProtocolFeature::TestnetFewerBlockProducers => 140,
}
}
}
Expand Down
32 changes: 28 additions & 4 deletions core/primitives/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/client/resharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6f324e8

Please sign in to comment.