Skip to content

Commit 028fa7c

Browse files
authored
fix: default genesis minimum gas price (#7475)
Update the default value for `min_gas_price` when creating a new chain to the effective value we use in mainnet today. (10e9 ->10e8) This changes the gas price for new chains, localnet and sandbox. Also add some comments to `fn min_gas_price` to improve clarity. Resolves #7466
1 parent 6f332f7 commit 028fa7c

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

chain/chain/src/types.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,29 @@ impl BlockHeaderInfo {
161161
/// Block economics config taken from genesis config
162162
pub struct BlockEconomicsConfig {
163163
gas_price_adjustment_rate: Rational32,
164-
min_gas_price: Balance,
165-
max_gas_price: Balance,
164+
genesis_min_gas_price: Balance,
165+
genesis_max_gas_price: Balance,
166166
genesis_protocol_version: ProtocolVersion,
167167
}
168168

169169
impl BlockEconomicsConfig {
170170
/// Set max gas price to be this multiplier * min_gas_price
171171
const MAX_GAS_MULTIPLIER: u128 = 20;
172172
/// Compute min gas price according to protocol version and genesis protocol version.
173+
///
174+
/// This returns the effective minimum gas price for a block with the given
175+
/// protocol version. The base value is defined in genesis.config but has
176+
/// been overwritten at specific protocol versions. Chains with a genesis
177+
/// version higher than those changes are not overwritten and will instead
178+
/// respect the value defined in genesis.
173179
pub fn min_gas_price(&self, protocol_version: ProtocolVersion) -> Balance {
174180
if self.genesis_protocol_version < MIN_PROTOCOL_VERSION_NEP_92 {
175181
if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92_FIX {
176182
MIN_GAS_PRICE_NEP_92_FIX
177183
} else if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92 {
178184
MIN_GAS_PRICE_NEP_92
179185
} else {
180-
self.min_gas_price
186+
self.genesis_min_gas_price
181187
}
182188
} else if self.genesis_protocol_version < MIN_PROTOCOL_VERSION_NEP_92_FIX {
183189
if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92_FIX {
@@ -186,18 +192,18 @@ impl BlockEconomicsConfig {
186192
MIN_GAS_PRICE_NEP_92
187193
}
188194
} else {
189-
self.min_gas_price
195+
self.genesis_min_gas_price
190196
}
191197
}
192198

193199
pub fn max_gas_price(&self, protocol_version: ProtocolVersion) -> Balance {
194200
if checked_feature!("stable", CapMaxGasPrice, protocol_version) {
195201
std::cmp::min(
196-
self.max_gas_price,
202+
self.genesis_max_gas_price,
197203
Self::MAX_GAS_MULTIPLIER * self.min_gas_price(protocol_version),
198204
)
199205
} else {
200-
self.max_gas_price
206+
self.genesis_max_gas_price
201207
}
202208
}
203209

@@ -210,8 +216,8 @@ impl From<&ChainGenesis> for BlockEconomicsConfig {
210216
fn from(chain_genesis: &ChainGenesis) -> Self {
211217
BlockEconomicsConfig {
212218
gas_price_adjustment_rate: chain_genesis.gas_price_adjustment_rate,
213-
min_gas_price: chain_genesis.min_gas_price,
214-
max_gas_price: chain_genesis.max_gas_price,
219+
genesis_min_gas_price: chain_genesis.min_gas_price,
220+
genesis_max_gas_price: chain_genesis.max_gas_price,
215221
genesis_protocol_version: chain_genesis.protocol_version,
216222
}
217223
}

chain/jsonrpc/jsonrpc-tests/res/genesis_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"protocol_upgrade_num_epochs": 2,
1919
"epoch_length": 500,
2020
"gas_limit": 1000000000000000,
21-
"min_gas_price": "1000000000",
21+
"min_gas_price": "100000000",
2222
"max_gas_price": "10000000000000000000000",
2323
"block_producer_kickout_threshold": 90,
2424
"chunk_producer_kickout_threshold": 90,

nearcore/src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ pub const NUM_BLOCKS_PER_YEAR: u64 = 365 * 24 * 60 * 60;
107107
/// Initial gas limit.
108108
pub const INITIAL_GAS_LIMIT: Gas = 1_000_000_000_000_000;
109109

110-
/// Initial gas price.
111-
pub const MIN_GAS_PRICE: Balance = 1_000_000_000;
110+
/// Initial and minimum gas price.
111+
pub const MIN_GAS_PRICE: Balance = 100_000_000;
112112

113113
/// Protocol treasury account
114114
pub const PROTOCOL_TREASURY_ACCOUNT: &str = "near";

0 commit comments

Comments
 (0)