Skip to content

Commit

Permalink
fix: EXPERIMENTAL_protocol_config applies overrides from EpochConfig (#…
Browse files Browse the repository at this point in the history
…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 <git@kazlauskas.me>
  • Loading branch information
nikurt and nagisa committed Oct 20, 2023
1 parent 60be619 commit 7dc75e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions core/chain-configs/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <https://github.com/near/NEPs/pull/167> 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 {
Expand Down Expand Up @@ -820,6 +834,11 @@ impl From<ProtocolConfig> 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,
}
}
}
Expand Down
32 changes: 25 additions & 7 deletions nearcore/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 7dc75e4

Please sign in to comment.