2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-03-17 13:41:11 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-03-17 13:41:11 +01:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-03-17 13:41:11 +01:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-03-17 13:41:11 +01:00
|
|
|
|
|
|
|
//! Spec params deserialization.
|
|
|
|
|
2018-02-19 10:36:34 +01:00
|
|
|
use uint::{self, Uint};
|
2017-05-30 11:52:33 +02:00
|
|
|
use hash::{H256, Address};
|
|
|
|
use bytes::Bytes;
|
2016-03-17 13:41:11 +01:00
|
|
|
|
|
|
|
/// Spec params.
|
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
2018-11-27 23:21:31 +01:00
|
|
|
#[serde(deny_unknown_fields)]
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2016-03-17 13:41:11 +01:00
|
|
|
pub struct Params {
|
2016-12-22 07:06:40 +01:00
|
|
|
/// Account start nonce, defaults to 0.
|
|
|
|
pub account_start_nonce: Option<Uint>,
|
2016-04-09 19:20:35 +02:00
|
|
|
/// Maximum size of extra data.
|
|
|
|
pub maximum_extra_data_size: Uint,
|
2016-11-03 22:22:25 +01:00
|
|
|
/// Minimum gas limit.
|
|
|
|
pub min_gas_limit: Uint,
|
|
|
|
|
2016-04-09 19:20:35 +02:00
|
|
|
/// Network id.
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename = "networkID")]
|
2016-04-09 19:20:35 +02:00
|
|
|
pub network_id: Uint,
|
2016-12-22 13:10:58 +01:00
|
|
|
/// Chain id.
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename = "chainID")]
|
2016-12-22 13:10:58 +01:00
|
|
|
pub chain_id: Option<Uint>,
|
|
|
|
|
2016-09-28 14:21:59 +02:00
|
|
|
/// Name of the main ("eth") subprotocol.
|
|
|
|
pub subprotocol_name: Option<String>,
|
2016-11-03 22:22:25 +01:00
|
|
|
|
2016-07-27 21:38:22 +02:00
|
|
|
/// Option fork block number to check.
|
|
|
|
pub fork_block: Option<Uint>,
|
|
|
|
/// Expected fork block hash.
|
2018-10-29 16:49:04 +01:00
|
|
|
#[serde(rename = "forkCanonHash")]
|
2016-07-27 21:38:22 +02:00
|
|
|
pub fork_hash: Option<H256>,
|
2017-01-25 20:22:48 +01:00
|
|
|
|
2018-05-22 06:24:09 +02:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub eip150_transition: Option<Uint>,
|
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub eip160_transition: Option<Uint>,
|
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub eip161abc_transition: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub eip161d_transition: Option<Uint>,
|
|
|
|
|
2017-01-25 20:22:48 +01:00
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip98_transition: Option<Uint>,
|
2017-03-14 11:41:56 +01:00
|
|
|
/// See `CommonParams` docs.
|
2017-07-31 12:34:29 +02:00
|
|
|
pub eip155_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2017-10-14 21:59:26 +02:00
|
|
|
pub validate_chain_id_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2017-03-28 10:46:52 +02:00
|
|
|
pub validate_receipts_transition: Option<Uint>,
|
2017-04-19 14:30:00 +02:00
|
|
|
/// See `CommonParams` docs.
|
2017-05-23 15:49:17 +02:00
|
|
|
pub eip140_transition: Option<Uint>,
|
2017-05-30 11:52:33 +02:00
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip210_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip210_contract_address: Option<Address>,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip210_contract_code: Option<Bytes>,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip210_contract_gas: Option<Uint>,
|
2017-06-06 17:47:12 +02:00
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip211_transition: Option<Uint>,
|
2017-06-19 11:41:46 +02:00
|
|
|
/// See `CommonParams` docs.
|
2018-05-05 10:23:50 +02:00
|
|
|
pub eip145_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2017-06-19 11:41:46 +02:00
|
|
|
pub eip214_transition: Option<Uint>,
|
2017-06-28 09:10:57 +02:00
|
|
|
/// See `CommonParams` docs.
|
2017-09-15 21:07:54 +02:00
|
|
|
pub eip658_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2018-07-31 07:27:57 +02:00
|
|
|
pub eip1052_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2018-09-07 12:51:08 +02:00
|
|
|
pub eip1283_transition: Option<Uint>,
|
2019-01-21 12:22:29 +01:00
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub eip1283_disable_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2019-08-29 21:31:52 +02:00
|
|
|
pub eip1283_reenable_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2018-08-31 17:43:51 +02:00
|
|
|
pub eip1014_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2019-08-29 21:31:52 +02:00
|
|
|
pub eip1706_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2019-08-28 16:15:50 +02:00
|
|
|
pub eip1344_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2019-08-29 13:19:55 +02:00
|
|
|
pub eip1884_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2019-08-23 14:13:02 +02:00
|
|
|
pub eip2028_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
2017-06-28 09:10:57 +02:00
|
|
|
pub dust_protection_transition: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub nonce_cap_increment: Option<Uint>,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub remove_dust_contracts : Option<bool>,
|
2017-07-31 12:34:29 +02:00
|
|
|
/// See `CommonParams` docs.
|
2018-02-19 10:36:34 +01:00
|
|
|
#[serde(deserialize_with="uint::validate_non_zero")]
|
2017-07-31 12:34:29 +02:00
|
|
|
pub gas_limit_bound_divisor: Uint,
|
|
|
|
/// See `CommonParams` docs.
|
|
|
|
pub registrar: Option<Address>,
|
2017-07-25 12:04:37 +02:00
|
|
|
/// Apply reward flag
|
|
|
|
pub apply_reward: Option<bool>,
|
2017-08-29 14:38:01 +02:00
|
|
|
/// Node permission contract address.
|
|
|
|
pub node_permission_contract: Option<Address>,
|
2017-09-26 14:19:08 +02:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub max_code_size: Option<Uint>,
|
2018-04-27 15:02:45 +02:00
|
|
|
/// Maximum size of transaction RLP payload.
|
|
|
|
pub max_transaction_size: Option<Uint>,
|
2018-03-07 15:11:09 +01:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
pub max_code_size_transition: Option<Uint>,
|
2017-09-05 11:39:50 +02:00
|
|
|
/// Transaction permission contract address.
|
|
|
|
pub transaction_permission_contract: Option<Address>,
|
2018-08-07 16:18:19 +02:00
|
|
|
/// Block at which the transaction permission contract should start being used.
|
|
|
|
pub transaction_permission_contract_transition: Option<Uint>,
|
2019-07-08 12:03:27 +02:00
|
|
|
/// Wasm activation block height, if not activated from start.
|
2018-02-19 12:27:42 +01:00
|
|
|
pub wasm_activation_transition: Option<Uint>,
|
2019-07-08 12:03:27 +02:00
|
|
|
/// Define a separate wasm version instead of using the prefix.
|
|
|
|
pub wasm_version: Option<Uint>,
|
2018-08-06 17:15:52 +02:00
|
|
|
/// KIP4 activiation block height.
|
|
|
|
pub kip4_transition: Option<Uint>,
|
2018-08-24 18:03:46 +02:00
|
|
|
/// KIP6 activiation block height.
|
|
|
|
pub kip6_transition: Option<Uint>,
|
2016-03-17 13:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use serde_json;
|
2017-05-14 16:40:15 +02:00
|
|
|
use uint::Uint;
|
2018-01-10 13:35:18 +01:00
|
|
|
use ethereum_types::U256;
|
2016-03-17 13:41:11 +01:00
|
|
|
use spec::params::Params;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn params_deserialization() {
|
|
|
|
let s = r#"{
|
|
|
|
"maximumExtraDataSize": "0x20",
|
2016-04-09 19:20:35 +02:00
|
|
|
"networkID" : "0x1",
|
2016-12-22 13:10:58 +01:00
|
|
|
"chainID" : "0x15",
|
2016-09-28 14:21:59 +02:00
|
|
|
"subprotocolName" : "exp",
|
2016-03-17 13:41:11 +01:00
|
|
|
"minGasLimit": "0x1388",
|
2017-07-31 12:34:29 +02:00
|
|
|
"accountStartNonce": "0x01",
|
2017-09-26 14:19:08 +02:00
|
|
|
"gasLimitBoundDivisor": "0x20",
|
2018-02-19 12:27:42 +01:00
|
|
|
"maxCodeSize": "0x1000",
|
|
|
|
"wasmActivationTransition": "0x1010"
|
2016-03-17 13:41:11 +01:00
|
|
|
}"#;
|
2016-04-09 19:20:35 +02:00
|
|
|
|
2017-05-14 16:40:15 +02:00
|
|
|
let deserialized: Params = serde_json::from_str(s).unwrap();
|
|
|
|
assert_eq!(deserialized.maximum_extra_data_size, Uint(U256::from(0x20)));
|
|
|
|
assert_eq!(deserialized.network_id, Uint(U256::from(0x1)));
|
|
|
|
assert_eq!(deserialized.chain_id, Some(Uint(U256::from(0x15))));
|
|
|
|
assert_eq!(deserialized.subprotocol_name, Some("exp".to_owned()));
|
|
|
|
assert_eq!(deserialized.min_gas_limit, Uint(U256::from(0x1388)));
|
|
|
|
assert_eq!(deserialized.account_start_nonce, Some(Uint(U256::from(0x01))));
|
2017-07-31 12:34:29 +02:00
|
|
|
assert_eq!(deserialized.gas_limit_bound_divisor, Uint(U256::from(0x20)));
|
2017-09-26 14:19:08 +02:00
|
|
|
assert_eq!(deserialized.max_code_size, Some(Uint(U256::from(0x1000))));
|
2018-02-19 12:27:42 +01:00
|
|
|
assert_eq!(deserialized.wasm_activation_transition, Some(Uint(U256::from(0x1010))));
|
2016-03-17 13:41:11 +01:00
|
|
|
}
|
2018-02-19 10:36:34 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "a non-zero value")]
|
|
|
|
fn test_zero_value_divisor() {
|
|
|
|
let s = r#"{
|
|
|
|
"maximumExtraDataSize": "0x20",
|
|
|
|
"networkID" : "0x1",
|
|
|
|
"chainID" : "0x15",
|
|
|
|
"subprotocolName" : "exp",
|
|
|
|
"minGasLimit": "0x1388",
|
|
|
|
"accountStartNonce": "0x01",
|
|
|
|
"gasLimitBoundDivisor": "0x0",
|
|
|
|
"maxCodeSize": "0x1000"
|
|
|
|
}"#;
|
|
|
|
|
|
|
|
let _deserialized: Params = serde_json::from_str(s).unwrap();
|
|
|
|
}
|
2016-03-17 13:41:11 +01:00
|
|
|
}
|