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: gas price #3067

Merged
merged 5 commits into from Aug 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions chain/chain/src/types.rs
Expand Up @@ -20,7 +20,8 @@ use near_primitives::types::{
NumBlocks, ShardId, StateRoot, StateRootNode, ValidatorStake,
};
use near_primitives::version::{
ProtocolVersion, MIN_GAS_PRICE_NEP_92, MIN_PROTOCOL_VERSION_NEP_92,
ProtocolVersion, MIN_GAS_PRICE_NEP_92, MIN_GAS_PRICE_NEP_92_FIX, MIN_PROTOCOL_VERSION_NEP_92,
MIN_PROTOCOL_VERSION_NEP_92_FIX,
};
use near_primitives::views::{EpochValidatorInfo, QueryRequest, QueryResponse};
use near_store::{PartialStorage, ShardTries, Store, Trie, WrappedTrieChanges};
Expand Down Expand Up @@ -141,13 +142,22 @@ pub struct BlockEconomicsConfig {
}

impl BlockEconomicsConfig {
/// Compute min gas price according to protocol version and chain id. We only upgrade gas price
/// for betanet, testnet and mainnet.
/// Compute min gas price according to protocol version and genesis protocol version.
pub fn min_gas_price(&self, protocol_version: ProtocolVersion) -> Balance {
if self.genesis_protocol_version < MIN_PROTOCOL_VERSION_NEP_92
&& protocol_version >= MIN_PROTOCOL_VERSION_NEP_92
{
MIN_GAS_PRICE_NEP_92
if self.genesis_protocol_version < MIN_PROTOCOL_VERSION_NEP_92 {
if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92_FIX {
MIN_GAS_PRICE_NEP_92_FIX
} else if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92 {
MIN_GAS_PRICE_NEP_92
} else {
self.min_gas_price
}
} else if self.genesis_protocol_version < MIN_PROTOCOL_VERSION_NEP_92_FIX {
if protocol_version >= MIN_PROTOCOL_VERSION_NEP_92_FIX {
MIN_GAS_PRICE_NEP_92_FIX
} else {
MIN_GAS_PRICE_NEP_92
}
} else {
self.min_gas_price
}
Expand Down
6 changes: 5 additions & 1 deletion core/primitives/src/version.rs
Expand Up @@ -18,10 +18,14 @@ pub const DB_VERSION: DbVersion = 5;
pub type ProtocolVersion = u32;

/// Current latest version of the protocol.
pub const PROTOCOL_VERSION: ProtocolVersion = 31;
pub const PROTOCOL_VERSION: ProtocolVersion = 32;

pub const FIRST_BACKWARD_COMPATIBLE_PROTOCOL_VERSION: ProtocolVersion = 29;

/// Minimum gas price proposed in NEP 92 and the associated protocol version
pub const MIN_GAS_PRICE_NEP_92: Balance = 1_000_000_000;
pub const MIN_PROTOCOL_VERSION_NEP_92: ProtocolVersion = 31;

/// Minimum gas price proposed in NEP 92 (fixed) and the associated protocol version
pub const MIN_GAS_PRICE_NEP_92_FIX: Balance = 100_000_000;
pub const MIN_PROTOCOL_VERSION_NEP_92_FIX: ProtocolVersion = 32;
2 changes: 1 addition & 1 deletion neard/res/genesis_config.json
@@ -1,5 +1,5 @@
{
"protocol_version": 31,
"protocol_version": 32,
"genesis_time": "1970-01-01T00:00:00.000000000Z",
"chain_id": "sample",
"genesis_height": 0,
Expand Down
4 changes: 3 additions & 1 deletion pytest/tests/sanity/upgradable.py
Expand Up @@ -88,7 +88,9 @@ def main():
"Latest protocol version %d should match active protocol version %d" % (latest_protocol_version, protocol_version)

gas_price = nodes[0].json_rpc('gas_price', [None])
assert gas_price['result']['gas_price'] == '1000000000', gas_price
gas_price = int(gas_price['result']['gas_price'])
assert gas_price < 1000000000, gas_price
assert gas_price > 100000000, gas_price


if __name__ == "__main__":
Expand Down