Skip to content

Commit

Permalink
feature: Structured parameters config (near#8384)
Browse files Browse the repository at this point in the history
This is a part of near#8264.

This PR introduces structured values for Rationals in the parameter config in the form
```yaml
burnt_gas_reward: {
  numerator: 3,
  denominator: 10,
}
```

To support this in the code, we now interpret parameter values as one of
```rust
enum ParameterValue {
    Null,
    U64(u64),
    Rational { numerator: isize, denominator: isize },
    String(String),
}
```

In the future the plan is to extend this to support Fee structure and Weighted parameters.

One open Rust-related question here:
- [ ] What is a good way to deduplicate code between `get_number`, `get_string`, `get_rational` methods?

Things to finish:
- [x] Tests for the Rational type
  • Loading branch information
aborg-dev authored and nikurt committed Jan 30, 2023
1 parent 1c31108 commit c92e6c1
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 140 deletions.
6 changes: 2 additions & 4 deletions core/primitives-core/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ use crate::config::ActionCosts;
#[strum(serialize_all = "snake_case")]
pub enum Parameter {
// Gas economics config
BurntGasRewardNumerator,
BurntGasRewardDenominator,
PessimisticGasPriceInflationNumerator,
PessimisticGasPriceInflationDenominator,
BurntGasReward,
PessimisticGasPriceInflation,

// Account creation config
MinAllowedTopLevelAccountLength,
Expand Down
12 changes: 8 additions & 4 deletions core/primitives/res/runtime_configs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# The diffs are stored in files named `NN.txt`, where `NN` is the version.

# Gas economics config
burnt_gas_reward_numerator: 3
burnt_gas_reward_denominator: 10
pessimistic_gas_price_inflation_numerator: 103
pessimistic_gas_price_inflation_denominator: 100
burnt_gas_reward: {
numerator: 3,
denominator: 10,
}
pessimistic_gas_price_inflation: {
numerator: 103,
denominator: 100,
}

# Account creation config
min_allowed_top_level_account_length: 32
Expand Down
12 changes: 8 additions & 4 deletions core/primitives/res/runtime_configs/parameters_testnet.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Gas economics config
burnt_gas_reward_numerator: 3
burnt_gas_reward_denominator: 10
pessimistic_gas_price_inflation_numerator: 103
pessimistic_gas_price_inflation_denominator: 100
burnt_gas_reward: {
numerator: 3,
denominator: 10,
}
pessimistic_gas_price_inflation: {
numerator: 103,
denominator: 100,
}

# Account creation config
min_allowed_top_level_account_length: 0
Expand Down
Loading

0 comments on commit c92e6c1

Please sign in to comment.