From 7ffc61eccb3ee193a042a7d9198aba02bf6c8d05 Mon Sep 17 00:00:00 2001 From: nikurt <86772482+nikurt@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:07:52 +0200 Subject: [PATCH] fix: EXPERIMENTAL_protocol_config applies overrides from EpochConfig (#9692) Testing this PR on a testnet node, the diff with results from an rpc node is the following. Both changes look good to me. ``` 10c10 < "chunk_producer_kickout_threshold": 90, --- > "chunk_producer_kickout_threshold": 80, 28c28 < "num_block_producer_seats": 200, --- > "num_block_producer_seats": 100, ``` Proofs: * https://github.com/near/nearcore/blob/a5238cc70e268fe6da218c8367b053d53711ac6f/core/primitives/src/epoch_manager.rs#L134 * https://github.com/near/nearcore/blob/6f324e84a7a7162956f0b9985094ee146919f5ae/core/primitives/src/epoch_manager.rs#L149 Fix #9553 Also adds new fields to the response: * shard_layout * num_chunk_only_producer_seats * minimum_validators_per_shard * minimum_stake_ratio * max_kickout_stake_perc --------- Co-authored-by: Simonas Kazlauskas --- CHANGELOG.md | 1 + core/chain-configs/src/genesis_config.rs | 19 ++++++++++++++ nearcore/src/runtime/mod.rs | 32 ++++++++++++++++++------ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a9c5f2439c..4d0364b9df2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * The default config now enables TIER1 outbound connections by default. [#9349](https://github.com/near/nearcore/pull/9349) * State Sync from GCS is available for experimental use. [#9398](https://github.com/near/nearcore/pull/9398) * Add prometheus metrics for the internal state of the doomslug. [#9458](https://github.com/near/nearcore/pull/9458) +* Fix `EXPERIMENTAL_protocol_config` to apply overrides from `EpochConfig`. [#9692](https://github.com/near/nearcore/pull/9692) ## 1.35.0 diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index 247fd86c18d..09980702407 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -723,6 +723,9 @@ impl GenesisChangeConfig { // Ideally we should create `RuntimeConfigView`, but given the deeply nested nature and the number of fields inside // `RuntimeConfig`, it should be its own endeavor. // TODO: This has changed, there is now `RuntimeConfigView`. Reconsider if moving this is possible now. +// TODO: Consider replacing tens of fields with a combination of `GenesisConfig` +// and `EpochConfig` fields, similar to how `RuntimeConfig` is represented as a +// separate struct and not inlined. #[derive(serde::Serialize, serde::Deserialize, Debug)] pub struct ProtocolConfigView { /// Current Protocol Version @@ -781,6 +784,17 @@ pub struct ProtocolConfigView { pub fishermen_threshold: Balance, /// The minimum stake required for staking is last seat price divided by this number. pub minimum_stake_divisor: u64, + /// Max stake percentage of the validators we will kick out. + pub max_kickout_stake_perc: u8, + /// The lowest ratio s/s_total any block producer can have. + /// See for details + pub minimum_stake_ratio: Rational32, + /// The minimum number of validators each shard must have + pub minimum_validators_per_shard: NumSeats, + /// Number of validator seats for chunk only producers. + pub num_chunk_only_producer_seats: NumSeats, + /// Layout information regarding how to split accounts to shards + pub shard_layout: ShardLayout, } pub struct ProtocolConfig { @@ -820,6 +834,11 @@ impl From for ProtocolConfigView { protocol_treasury_account: genesis_config.protocol_treasury_account, fishermen_threshold: genesis_config.fishermen_threshold, minimum_stake_divisor: genesis_config.minimum_stake_divisor, + max_kickout_stake_perc: genesis_config.max_kickout_stake_perc, + minimum_stake_ratio: genesis_config.minimum_stake_ratio, + minimum_validators_per_shard: genesis_config.minimum_validators_per_shard, + num_chunk_only_producer_seats: genesis_config.num_chunk_only_producer_seats, + shard_layout: genesis_config.shard_layout, } } } diff --git a/nearcore/src/runtime/mod.rs b/nearcore/src/runtime/mod.rs index ef32a80b603..49da4960a26 100644 --- a/nearcore/src/runtime/mod.rs +++ b/nearcore/src/runtime/mod.rs @@ -1174,15 +1174,33 @@ impl RuntimeAdapter for NightshadeRuntime { let protocol_version = self.epoch_manager.get_epoch_protocol_version(epoch_id)?; let mut genesis_config = self.genesis_config.clone(); genesis_config.protocol_version = protocol_version; - let shard_config = { - let epoch_manager = self.epoch_manager.read(); - epoch_manager.get_shard_config(epoch_id)? - }; + + let epoch_config = self.epoch_manager.get_epoch_config(epoch_id)?; + genesis_config.epoch_length = epoch_config.epoch_length; + genesis_config.num_block_producer_seats = epoch_config.num_block_producer_seats; genesis_config.num_block_producer_seats_per_shard = - shard_config.num_block_producer_seats_per_shard; + epoch_config.num_block_producer_seats_per_shard; genesis_config.avg_hidden_validator_seats_per_shard = - shard_config.avg_hidden_validator_seats_per_shard; - genesis_config.shard_layout = shard_config.shard_layout; + epoch_config.avg_hidden_validator_seats_per_shard; + genesis_config.block_producer_kickout_threshold = + epoch_config.block_producer_kickout_threshold; + genesis_config.chunk_producer_kickout_threshold = + epoch_config.chunk_producer_kickout_threshold; + genesis_config.max_kickout_stake_perc = epoch_config.validator_max_kickout_stake_perc; + genesis_config.online_min_threshold = epoch_config.online_min_threshold; + genesis_config.online_max_threshold = epoch_config.online_max_threshold; + genesis_config.fishermen_threshold = epoch_config.fishermen_threshold; + genesis_config.minimum_stake_divisor = epoch_config.minimum_stake_divisor; + genesis_config.protocol_upgrade_stake_threshold = + epoch_config.protocol_upgrade_stake_threshold; + genesis_config.shard_layout = epoch_config.shard_layout; + genesis_config.num_chunk_only_producer_seats = + epoch_config.validator_selection_config.num_chunk_only_producer_seats; + genesis_config.minimum_validators_per_shard = + epoch_config.validator_selection_config.minimum_validators_per_shard; + genesis_config.minimum_stake_ratio = + epoch_config.validator_selection_config.minimum_stake_ratio; + let runtime_config = self.runtime_config_store.get_config(protocol_version).as_ref().clone(); Ok(ProtocolConfig { genesis_config, runtime_config })