Skip to content

Commit

Permalink
fix(epoch config): Refactor validator assignment config (#12520)
Browse files Browse the repository at this point in the history
This PR does not change the `EpochConfig` functionality, it just flatten
the `EpochConfig` struct.
Cetralize the epoch config contructors.

This PR is a precursor to the config overriedes on `EpochConfigs`.
  • Loading branch information
VanBarbascu authored Dec 11, 2024
1 parent f4c7f53 commit e594174
Show file tree
Hide file tree
Showing 41 changed files with 715 additions and 767 deletions.
11 changes: 4 additions & 7 deletions chain/chain/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,14 +1199,11 @@ impl RuntimeAdapter for NightshadeRuntime {
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;
genesis_config.num_chunk_only_producer_seats = epoch_config.num_chunk_only_producer_seats;
genesis_config.minimum_validators_per_shard = epoch_config.minimum_validators_per_shard;
genesis_config.minimum_stake_ratio = epoch_config.minimum_stake_ratio;
genesis_config.shuffle_shard_assignment_for_chunk_producers =
epoch_config.validator_selection_config.shuffle_shard_assignment_for_chunk_producers;
epoch_config.shuffle_shard_assignment_for_chunk_producers;

let runtime_config =
self.runtime_config_store.get_config(protocol_version).as_ref().clone();
Expand Down
21 changes: 1 addition & 20 deletions chain/chain/src/test_utils/kv_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use near_primitives::epoch_block_info::BlockInfo;
use near_primitives::epoch_info::EpochInfo;
use near_primitives::epoch_manager::EpochConfig;
use near_primitives::epoch_manager::ShardConfig;
use near_primitives::epoch_manager::ValidatorSelectionConfig;
use near_primitives::errors::{EpochError, InvalidTxError};
use near_primitives::hash::{hash, CryptoHash};
use near_primitives::receipt::{ActionReceipt, Receipt, ReceiptEnum, ReceiptV0};
Expand Down Expand Up @@ -55,7 +54,6 @@ use near_store::{
TrieChanges, WrappedTrieChanges,
};
use near_vm_runner::{ContractCode, ContractRuntimeCache, NoContractRuntimeCache};
use num_rational::Ratio;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -496,24 +494,7 @@ impl EpochManagerAdapter for MockEpochManager {
}

fn get_epoch_config(&self, epoch_id: &EpochId) -> Result<EpochConfig, EpochError> {
Ok(EpochConfig {
epoch_length: self.epoch_length,
num_block_producer_seats: 2,
num_block_producer_seats_per_shard: vec![1, 1],
avg_hidden_validator_seats_per_shard: vec![1, 1],
block_producer_kickout_threshold: 0,
chunk_producer_kickout_threshold: 0,
chunk_validator_only_kickout_threshold: 0,
target_validator_mandates_per_shard: 1,
validator_max_kickout_stake_perc: 0,
online_min_threshold: Ratio::new(1i32, 4i32),
online_max_threshold: Ratio::new(3i32, 4i32),
fishermen_threshold: 1,
minimum_stake_divisor: 1,
protocol_upgrade_stake_threshold: Ratio::new(3i32, 4i32),
shard_layout: self.get_shard_layout(epoch_id).unwrap(),
validator_selection_config: ValidatorSelectionConfig::default(),
})
Ok(EpochConfig::mock(self.epoch_length, self.get_shard_layout(epoch_id).unwrap()))
}

/// Return the epoch info containing the mocked data.
Expand Down
8 changes: 7 additions & 1 deletion chain/epoch-manager/src/shard_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,13 @@ mod tests {
minimum_stake_divisor: 1,
protocol_upgrade_stake_threshold: Ratio::new(80, 100),
shard_layout: ShardLayout::multi_shard(num_shards, 0),
validator_selection_config: Default::default(),
num_chunk_producer_seats: 100,
num_chunk_validator_seats: 300,
num_chunk_only_producer_seats: 300,
minimum_validators_per_shard: 1,
minimum_stake_ratio: Ratio::new(160i32, 1_000_000i32),
chunk_producer_assignment_changes_limit: 5,
shuffle_shard_assignment_for_chunk_producers: false,
validator_max_kickout_stake_perc: 100,
};
let reward_calculator = RewardCalculator {
Expand Down
13 changes: 8 additions & 5 deletions chain/epoch-manager/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use near_crypto::{KeyType, SecretKey};
use near_primitives::challenge::SlashedValidator;
use near_primitives::epoch_block_info::BlockInfoV2;
use near_primitives::epoch_info::EpochInfo;
use near_primitives::epoch_manager::{AllEpochConfig, EpochConfig, ValidatorSelectionConfig};
use near_primitives::epoch_manager::{AllEpochConfig, EpochConfig};
use near_primitives::hash::{hash, CryptoHash};
use near_primitives::types::validator_stake::ValidatorStake;
use near_primitives::types::{
Expand Down Expand Up @@ -151,10 +151,13 @@ pub fn epoch_config_with_production_config(
online_max_threshold: Ratio::new(99, 100),
protocol_upgrade_stake_threshold: Ratio::new(80, 100),
minimum_stake_divisor: 1,
validator_selection_config: ValidatorSelectionConfig {
num_chunk_producer_seats,
..Default::default()
},
num_chunk_producer_seats,
num_chunk_validator_seats: 300,
num_chunk_only_producer_seats: 300,
minimum_validators_per_shard: 1,
minimum_stake_ratio: Ratio::new(160i32, 1_000_000i32),
chunk_producer_assignment_changes_limit: 5,
shuffle_shard_assignment_for_chunk_producers: false,
shard_layout: ShardLayout::multi_shard(num_shards, 0),
validator_max_kickout_stake_perc: 100,
};
Expand Down
8 changes: 7 additions & 1 deletion chain/epoch-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,13 @@ fn test_protocol_version_switch_with_many_seats() {
protocol_upgrade_stake_threshold: Ratio::new(80, 100),
minimum_stake_divisor: 1,
shard_layout: ShardLayout::single_shard(),
validator_selection_config: Default::default(),
num_chunk_producer_seats: 100,
num_chunk_validator_seats: 300,
num_chunk_only_producer_seats: 300,
minimum_validators_per_shard: 1,
minimum_stake_ratio: Ratio::new(160i32, 1_000_000i32),
chunk_producer_assignment_changes_limit: 5,
shuffle_shard_assignment_for_chunk_producers: false,
validator_max_kickout_stake_perc: 100,
};
let config = AllEpochConfig::new(false, PROTOCOL_VERSION, epoch_config, "test-chain");
Expand Down
Loading

0 comments on commit e594174

Please sign in to comment.