Skip to content

Commit

Permalink
feat: Introduce mechanism to load EpochConfigs for production chains …
Browse files Browse the repository at this point in the history
…from JSON files per version (#11896)

Issue: #11265

We introduce a mechanism for storing `EpochConfigs` for
mainnet/testnet/mocknet (forknet) in JSON files for various protocol
versions and retrieving them from a new library called
`EpochConfigStore`. The library parses JSON files containing the epoch
configs and loads them in a map from (chain-id x version) to
`EpochConfig`. The library is accessed from `AllEpochConfig` when
`use_production_config` is set to true AND outside of tests (for this we
explicitly set test overrides to default even if there is no explicit
override to distinguish cases where a test uses a mainnet/testnet chanin
id with a custom `EpochConfig`).

We change the existing `for_protocol_version` method of `AllEpochConfig`
to `generate_epoch_config` to indicate that it generates a config in
code. The new version of `for_protocol_version` internall calls the
config store or `generate_epoch_config` based on whether the config
store is initialized.

We will need to follow-up with more changes to this PR since there are
tests that use mainnet/testnet chain id with custom `EpochConfig` which
conflicts with the config store (which is supposed to use production
configs for these chains). Our eventual goal is to remove
`generate_epoch_config` and only have (1) explicitly documented
production configs in JSON files or (2) custom-built configs in test but
not using the hard-coded changes.
  • Loading branch information
tayfunelmas authored Aug 7, 2024
1 parent fd0af1b commit 3cc6691
Show file tree
Hide file tree
Showing 37 changed files with 2,600 additions and 21 deletions.
6 changes: 3 additions & 3 deletions chain/client/src/test_utils/test_env_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl TestEnvBuilder {
/// Constructs real EpochManager implementations for each instance.
pub fn epoch_managers_with_test_overrides(
self,
test_overrides: Option<AllEpochConfigTestOverrides>,
test_overrides: AllEpochConfigTestOverrides,
) -> Self {
assert!(
self.num_shards.is_none(),
Expand All @@ -261,7 +261,7 @@ impl TestEnvBuilder {
EpochManager::new_arc_handle_with_test_overrides(
ret.stores.as_ref().unwrap()[i].clone(),
&ret.genesis_config,
test_overrides.clone(),
Some(test_overrides.clone()),
)
})
.collect();
Expand All @@ -274,7 +274,7 @@ impl TestEnvBuilder {
if ret.epoch_managers.is_some() {
return ret;
}
ret.epoch_managers_with_test_overrides(None)
ret.epoch_managers_with_test_overrides(AllEpochConfigTestOverrides::default())
}

/// Constructs MockEpochManager implementations for each instance.
Expand Down
1 change: 1 addition & 0 deletions chain/epoch-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl EpochManager {
let initial_epoch_config = EpochConfig::from(genesis_config);
let epoch_config = AllEpochConfig::new_with_test_overrides(
genesis_config.use_production_config(),
genesis_config.protocol_version,
initial_epoch_config,
&genesis_config.chain_id,
test_overrides,
Expand Down
7 changes: 6 additions & 1 deletion chain/epoch-manager/src/shard_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,12 @@ mod tests {
};
EpochManager::new(
store,
AllEpochConfig::new(use_production_config, initial_epoch_config, "test-chain"),
AllEpochConfig::new(
use_production_config,
genesis_protocol_version,
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, "test-chain")
AllEpochConfig::new(use_production_config, PROTOCOL_VERSION, 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 @@ -2214,7 +2214,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, "test-chain");
let config = AllEpochConfig::new(false, PROTOCOL_VERSION, epoch_config, "test-chain");
let amount_staked = 1_000_000;
let validators = vec![
stake("test1".parse().unwrap(), amount_staked),
Expand Down
96 changes: 96 additions & 0 deletions core/primitives/res/epoch_configs/mainnet/100.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"epoch_length": 43200,
"num_block_producer_seats": 100,
"num_block_producer_seats_per_shard": [
100,
100,
100,
100,
100,
100,
100
],
"avg_hidden_validator_seats_per_shard": [
0,
0,
0,
0,
0,
0,
0
],
"block_producer_kickout_threshold": 80,
"chunk_producer_kickout_threshold": 80,
"chunk_validator_only_kickout_threshold": 80,
"target_validator_mandates_per_shard": 68,
"validator_max_kickout_stake_perc": 30,
"online_min_threshold": [
90,
100
],
"online_max_threshold": [
99,
100
],
"fishermen_threshold": 340282366920938463463374607431768211455,
"minimum_stake_divisor": 10,
"protocol_upgrade_stake_threshold": [
4,
5
],
"shard_layout": {
"V1": {
"boundary_accounts": [
"aurora",
"aurora-0",
"game.hot.tg",
"kkuuue2akv_1630967379.near",
"nightly",
"tge-lockup.sweat"
],
"shards_split_map": [
[
0
],
[
1
],
[
2
],
[
3
],
[
4,
5
],
[
6
]
],
"to_parent_shard_map": [
0,
1,
2,
3,
4,
4,
5
],
"version": 4
}
},
"validator_selection_config": {
"num_chunk_producer_seats": 100,
"num_chunk_validator_seats": 300,
"num_chunk_only_producer_seats": 0,
"minimum_validators_per_shard": 1,
"minimum_stake_ratio": [
1,
6250
],
"chunk_producer_assignment_changes_limit": 5,
"shuffle_shard_assignment_for_chunk_producers": false
}
}
89 changes: 89 additions & 0 deletions core/primitives/res/epoch_configs/mainnet/101.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"epoch_length": 43200,
"num_block_producer_seats": 100,
"num_block_producer_seats_per_shard": [
100,
100,
100,
100,
100,
100
],
"avg_hidden_validator_seats_per_shard": [
0,
0,
0,
0,
0,
0
],
"block_producer_kickout_threshold": 80,
"chunk_producer_kickout_threshold": 80,
"chunk_validator_only_kickout_threshold": 80,
"target_validator_mandates_per_shard": 68,
"validator_max_kickout_stake_perc": 30,
"online_min_threshold": [
90,
100
],
"online_max_threshold": [
99,
100
],
"fishermen_threshold": 340282366920938463463374607431768211455,
"minimum_stake_divisor": 10,
"protocol_upgrade_stake_threshold": [
4,
5
],
"shard_layout": {
"V1": {
"boundary_accounts": [
"aurora",
"aurora-0",
"game.hot.tg",
"kkuuue2akv_1630967379.near",
"tge-lockup.sweat"
],
"shards_split_map": [
[
0
],
[
1
],
[
2,
3
],
[
4
],
[
5
]
],
"to_parent_shard_map": [
0,
1,
2,
2,
3,
4
],
"version": 3
}
},
"validator_selection_config": {
"num_chunk_producer_seats": 100,
"num_chunk_validator_seats": 300,
"num_chunk_only_producer_seats": 0,
"minimum_validators_per_shard": 1,
"minimum_stake_ratio": [
1,
6250
],
"chunk_producer_assignment_changes_limit": 5,
"shuffle_shard_assignment_for_chunk_producers": false
}
}
89 changes: 89 additions & 0 deletions core/primitives/res/epoch_configs/mainnet/143.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"epoch_length": 43200,
"num_block_producer_seats": 100,
"num_block_producer_seats_per_shard": [
100,
100,
100,
100,
100,
100
],
"avg_hidden_validator_seats_per_shard": [
0,
0,
0,
0,
0,
0
],
"block_producer_kickout_threshold": 80,
"chunk_producer_kickout_threshold": 80,
"chunk_validator_only_kickout_threshold": 80,
"target_validator_mandates_per_shard": 68,
"validator_max_kickout_stake_perc": 30,
"online_min_threshold": [
90,
100
],
"online_max_threshold": [
99,
100
],
"fishermen_threshold": 340282366920938463463374607431768211455,
"minimum_stake_divisor": 10,
"protocol_upgrade_stake_threshold": [
4,
5
],
"shard_layout": {
"V1": {
"boundary_accounts": [
"aurora",
"aurora-0",
"game.hot.tg",
"kkuuue2akv_1630967379.near",
"tge-lockup.sweat"
],
"shards_split_map": [
[
0
],
[
1
],
[
2,
3
],
[
4
],
[
5
]
],
"to_parent_shard_map": [
0,
1,
2,
2,
3,
4
],
"version": 3
}
},
"validator_selection_config": {
"num_chunk_producer_seats": 100,
"num_chunk_validator_seats": 300,
"num_chunk_only_producer_seats": 0,
"minimum_validators_per_shard": 1,
"minimum_stake_ratio": [
1,
6250
],
"chunk_producer_assignment_changes_limit": 5,
"shuffle_shard_assignment_for_chunk_producers": true
}
}
47 changes: 47 additions & 0 deletions core/primitives/res/epoch_configs/mainnet/29.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"epoch_length": 43200,
"num_block_producer_seats": 100,
"num_block_producer_seats_per_shard": [
100
],
"avg_hidden_validator_seats_per_shard": [
0
],
"block_producer_kickout_threshold": 90,
"chunk_producer_kickout_threshold": 90,
"chunk_validator_only_kickout_threshold": 80,
"target_validator_mandates_per_shard": 68,
"validator_max_kickout_stake_perc": 100,
"online_min_threshold": [
90,
100
],
"online_max_threshold": [
99,
100
],
"fishermen_threshold": 340282366920938463463374607431768211455,
"minimum_stake_divisor": 10,
"protocol_upgrade_stake_threshold": [
4,
5
],
"shard_layout": {
"V0": {
"num_shards": 1,
"version": 0
}
},
"validator_selection_config": {
"num_chunk_producer_seats": 100,
"num_chunk_validator_seats": 300,
"num_chunk_only_producer_seats": 300,
"minimum_validators_per_shard": 1,
"minimum_stake_ratio": [
1,
6250
],
"chunk_producer_assignment_changes_limit": 5,
"shuffle_shard_assignment_for_chunk_producers": false
}
}
Loading

0 comments on commit 3cc6691

Please sign in to comment.