Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPERIMENTAL_protocol_config applies overrides from EpochConfig #9692

Merged
merged 7 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just return the epoch config? It doesn't make much sense to copy all of the fields over from one struct to another.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return the epoch config

That would probably be a better RPC design 🤔
I'd like to keep the scope of this PR to be a bug fix.
Added a TODO in the code to consider a backwards-incompatible change of ProtocolConfigView.

Expand Down