Move more params to the common section. (#6134)

* move common forks and parameters to common params

* port specs over to new format

* fix RPC tests
This commit is contained in:
Robert Habermeier
2017-07-31 12:34:29 +02:00
committed by Gav Wood
parent 9c5ef1f776
commit 003eef982b
55 changed files with 224 additions and 358 deletions

View File

@@ -50,7 +50,7 @@ mod tests {
use std::collections::BTreeMap;
use serde_json;
use spec::account::Account;
use util::U256;
use bigint::prelude::U256;
use uint::Uint;
use bytes::Bytes;

View File

@@ -17,25 +17,16 @@
//! Authority params deserialization.
use uint::Uint;
use hash::Address;
use super::ValidatorSet;
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct AuthorityRoundParams {
/// Gas limit divisor.
#[serde(rename="gasLimitBoundDivisor")]
pub gas_limit_bound_divisor: Uint,
/// Block duration.
#[serde(rename="stepDuration")]
pub step_duration: Uint,
/// Valid authorities
pub validators: ValidatorSet,
/// Block reward.
#[serde(rename="blockReward")]
pub block_reward: Option<Uint>,
/// Address of the registrar contract.
pub registrar: Option<Address>,
/// Starting step. Determined automatically if not specified.
/// To be used for testing only.
#[serde(rename="startStep")]
@@ -43,9 +34,6 @@ pub struct AuthorityRoundParams {
/// Block at which score validation should start.
#[serde(rename="validateScoreTransition")]
pub validate_score_transition: Option<Uint>,
/// See main AuthorityRoundParams docs.
#[serde(rename="eip155Transition")]
pub eip155_transition: Option<Uint>,
/// Block from which monotonic steps start.
#[serde(rename="validateStepTransition")]
pub validate_step_transition: Option<Uint>,
@@ -63,9 +51,8 @@ pub struct AuthorityRound {
#[cfg(test)]
mod tests {
use bigint::prelude::{U256, H160};
use uint::Uint;
use util::U256;
use util::H160;
use serde_json;
use hash::Address;
use spec::validator_set::ValidatorSet;
@@ -75,26 +62,19 @@ mod tests {
fn authority_round_deserialization() {
let s = r#"{
"params": {
"gasLimitBoundDivisor": "0x0400",
"stepDuration": "0x02",
"validators": {
"list" : ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
},
"blockReward": "0x50",
"startStep" : 24,
"eip155Transition": "0x42",
"validateStepTransition": 150
}
}"#;
let deserialized: AuthorityRound = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.gas_limit_bound_divisor, Uint(U256::from(0x0400)));
assert_eq!(deserialized.params.step_duration, Uint(U256::from(0x02)));
assert_eq!(deserialized.params.validators, ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))]));
assert_eq!(deserialized.params.block_reward, Some(Uint(U256::from(0x50))));
assert!(deserialized.params.registrar.is_none());
assert_eq!(deserialized.params.start_step, Some(Uint(U256::from(24))));
assert_eq!(deserialized.params.eip155_transition, Some(Uint(U256::from(0x42))));
assert_eq!(deserialized.params.immediate_transitions, None);
}
}

View File

@@ -22,9 +22,6 @@ use super::ValidatorSet;
/// Authority params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct BasicAuthorityParams {
/// Gas limit divisor.
#[serde(rename="gasLimitBoundDivisor")]
pub gas_limit_bound_divisor: Uint,
/// Block duration.
#[serde(rename="durationLimit")]
pub duration_limit: Uint,
@@ -43,9 +40,8 @@ pub struct BasicAuthority {
mod tests {
use serde_json;
use uint::Uint;
use util::U256;
use bigint::prelude::{U256, H160};
use hash::Address;
use util::hash::H160;
use spec::basic_authority::BasicAuthority;
use spec::validator_set::ValidatorSet;
@@ -53,7 +49,6 @@ mod tests {
fn basic_authority_deserialization() {
let s = r#"{
"params": {
"gasLimitBoundDivisor": "0x0400",
"durationLimit": "0x0d",
"validators" : {
"list": ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
@@ -63,7 +58,6 @@ mod tests {
let deserialized: BasicAuthority = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.gas_limit_bound_divisor, Uint(U256::from(0x0400)));
assert_eq!(deserialized.params.duration_limit, Uint(U256::from(0x0d)));
let vs = ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))]);
assert_eq!(deserialized.params.validators, vs);

View File

@@ -16,7 +16,7 @@
//! Engine deserialization.
use super::{Ethash, InstantSeal, BasicAuthority, AuthorityRound, Tendermint};
use super::{Ethash, BasicAuthority, AuthorityRound, Tendermint};
/// Engine deserialization.
#[derive(Debug, PartialEq, Deserialize)]
@@ -26,7 +26,7 @@ pub enum Engine {
Null,
/// Instantly sealing engine.
#[serde(rename="instantSeal")]
InstantSeal(InstantSeal),
InstantSeal,
/// Ethash engine.
Ethash(Ethash),
/// BasicAuthority engine.
@@ -55,23 +55,21 @@ mod tests {
assert_eq!(Engine::Null, deserialized);
let s = r#"{
"instantSeal": { "params": {} }
"instantSeal": null
}"#;
let deserialized: Engine = serde_json::from_str(s).unwrap();
match deserialized {
Engine::InstantSeal(_) => {}, // instant seal is unit tested in its own file.
Engine::InstantSeal => {}, // instant seal is unit tested in its own file.
_ => assert!(false),
};
let s = r#"{
"Ethash": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"homesteadTransition" : "0x",
"daoHardforkTransition": "0xffffffffffffffff",
@@ -90,7 +88,6 @@ mod tests {
let s = r#"{
"basicAuthority": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"durationLimit": "0x0d",
"validators" : {
"list": ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
@@ -107,14 +104,11 @@ mod tests {
let s = r#"{
"authorityRound": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"stepDuration": "0x02",
"validators": {
"list" : ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
},
"blockReward": "0x50",
"startStep" : 24,
"eip155Transition": "0x42",
"validateStepTransition": 150
}
}
@@ -128,11 +122,9 @@ mod tests {
let s = r#"{
"tendermint": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"validators": {
"list": ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
},
"blockReward": "0x50"
}
}
}
}"#;

View File

@@ -22,9 +22,6 @@ use hash::Address;
/// Deserializable doppelganger of EthashParams.
#[derive(Debug, PartialEq, Deserialize)]
pub struct EthashParams {
/// See main EthashParams docs.
#[serde(rename="gasLimitBoundDivisor")]
pub gas_limit_bound_divisor: Uint,
/// See main EthashParams docs.
#[serde(rename="minimumDifficulty")]
pub minimum_difficulty: Uint,
@@ -40,11 +37,6 @@ pub struct EthashParams {
/// See main EthashParams docs.
#[serde(rename="durationLimit")]
pub duration_limit: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="blockReward")]
pub block_reward: Uint,
/// See main EthashParams docs.
pub registrar: Option<Address>,
/// See main EthashParams docs.
#[serde(rename="homesteadTransition")]
@@ -78,10 +70,6 @@ pub struct EthashParams {
#[serde(rename="eip150Transition")]
pub eip150_transition: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="eip155Transition")]
pub eip155_transition: Option<Uint>,
/// See main EthashParams docs.
#[serde(rename="eip160Transition")]
pub eip160_transition: Option<Uint>,
@@ -136,21 +124,17 @@ pub struct Ethash {
mod tests {
use serde_json;
use uint::Uint;
use util::U256;
use bigint::prelude::{H160, U256};
use hash::Address;
use util::hash::H160;
use spec::ethash::{Ethash, EthashParams};
#[test]
fn ethash_deserialization() {
let s = r#"{
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar": "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"homesteadTransition": "0x42",
"daoHardforkTransition": "0x08",
"daoHardforkBeneficiary": "0xabcabcabcabcabcabcabcabcabcabcabcabcabca",
@@ -181,7 +165,6 @@ mod tests {
"bombDefuseTransition": "0x41",
"eip100bTransition": "0x42",
"eip150Transition": "0x43",
"eip155Transition": "0x44",
"eip160Transition": "0x45",
"eip161abcTransition": "0x46",
"eip161dTransition": "0x47"
@@ -190,16 +173,13 @@ mod tests {
let deserialized: Ethash = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, Ethash{
assert_eq!(deserialized, Ethash {
params: EthashParams{
gas_limit_bound_divisor: Uint(U256::from(0x0400)),
minimum_difficulty: Uint(U256::from(0x020000)),
difficulty_bound_divisor: Uint(U256::from(0x0800)),
difficulty_increment_divisor: None,
metropolis_difficulty_increment_divisor: None,
duration_limit: Some(Uint(U256::from(0x0d))),
block_reward: Uint(U256::from(0x4563918244F40000u64)),
registrar: Some(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))),
homestead_transition: Some(Uint(U256::from(0x42))),
dao_hardfork_transition: Some(Uint(U256::from(0x08))),
dao_hardfork_beneficiary: Some(Address(H160::from("0xabcabcabcabcabcabcabcabcabcabcabcabcabca"))),
@@ -230,7 +210,6 @@ mod tests {
bomb_defuse_transition: Some(Uint(U256::from(0x41))),
eip100b_transition: Some(Uint(U256::from(0x42))),
eip150_transition: Some(Uint(U256::from(0x43))),
eip155_transition: Some(Uint(U256::from(0x44))),
eip160_transition: Some(Uint(U256::from(0x45))),
eip161abc_transition: Some(Uint(U256::from(0x46))),
eip161d_transition: Some(Uint(U256::from(0x47))),
@@ -250,24 +229,19 @@ mod tests {
fn ethash_deserialization_missing_optionals() {
let s = r#"{
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"blockReward": "0x4563918244F40000"
"minimumDifficulty": "0x020000"
}
}"#;
let deserialized: Ethash = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, Ethash{
params: EthashParams{
gas_limit_bound_divisor: Uint(U256::from(0x0400)),
assert_eq!(deserialized, Ethash {
params: EthashParams {
minimum_difficulty: Uint(U256::from(0x020000)),
difficulty_bound_divisor: Uint(U256::from(0x0800)),
difficulty_increment_divisor: None,
metropolis_difficulty_increment_divisor: None,
duration_limit: None,
block_reward: Uint(U256::from(0x4563918244F40000u64)),
registrar: None,
homestead_transition: None,
dao_hardfork_transition: None,
dao_hardfork_beneficiary: None,
@@ -277,7 +251,6 @@ mod tests {
bomb_defuse_transition: None,
eip100b_transition: None,
eip150_transition: None,
eip155_transition: None,
eip160_transition: None,
eip161abc_transition: None,
eip161d_transition: None,

View File

@@ -60,10 +60,8 @@ mod tests {
use serde_json;
use bytes::Bytes;
use uint::Uint;
use util::U256;
use bigint::prelude::{U256, H160, H64 as Eth64, H256 as Eth256};
use hash::{H64, H256, Address};
use util::hash::H160;
use util::{H64 as Eth64, H256 as Eth256};
use spec::genesis::Genesis;
use spec::{Ethereum, Seal};
use std::str::FromStr;

View File

@@ -1,53 +0,0 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// 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.
// Parity is distributed in the hope that it will be useful,
// 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
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Instant params deserialization.
use hash::Address;
/// Instant params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct InstantSealParams {
/// Address of the registrar contract.
pub registrar: Option<Address>,
}
/// Instant engine deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct InstantSeal {
/// Instant Seal params.
pub params: InstantSealParams,
}
#[cfg(test)]
mod tests {
use serde_json;
use hash::Address;
use util::hash::H160;
use spec::instant_seal::InstantSeal;
#[test]
fn instant_seal_deserialization() {
let s = r#"{
"params": {
"registrar": "0xc6d9d2cd449a754c494264e1809c50e34d64562b"
}
}"#;
let deserialized: InstantSeal = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.registrar, Some(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))));
}
}

View File

@@ -26,7 +26,6 @@ pub mod engine;
pub mod state;
pub mod ethash;
pub mod validator_set;
pub mod instant_seal;
pub mod basic_authority;
pub mod authority_round;
pub mod tendermint;
@@ -41,7 +40,6 @@ pub use self::engine::Engine;
pub use self::state::State;
pub use self::ethash::{Ethash, EthashParams};
pub use self::validator_set::ValidatorSet;
pub use self::instant_seal::{InstantSeal, InstantSealParams};
pub use self::basic_authority::{BasicAuthority, BasicAuthorityParams};
pub use self::authority_round::{AuthorityRound, AuthorityRoundParams};
pub use self::tendermint::{Tendermint, TendermintParams};

View File

@@ -55,6 +55,9 @@ pub struct Params {
#[serde(rename="eip98Transition")]
pub eip98_transition: Option<Uint>,
/// See `CommonParams` docs.
#[serde(rename="eip155Transition")]
pub eip155_transition: Option<Uint>,
/// See `CommonParams` docs.
#[serde(rename="validateReceiptsTransition")]
pub validate_receipts_transition: Option<Uint>,
/// See `CommonParams` docs.
@@ -91,13 +94,21 @@ pub struct Params {
pub remove_dust_contracts : Option<bool>,
/// Wasm support flag
pub wasm: Option<bool>,
/// See `CommonParams` docs.
#[serde(rename="gasLimitBoundDivisor")]
pub gas_limit_bound_divisor: Uint,
/// See `CommonParams` docs.
#[serde(rename="blockReward")]
pub block_reward: Option<Uint>,
/// See `CommonParams` docs.
pub registrar: Option<Address>,
}
#[cfg(test)]
mod tests {
use serde_json;
use uint::Uint;
use util::U256;
use bigint::prelude::U256;
use spec::params::Params;
#[test]
@@ -108,7 +119,8 @@ mod tests {
"chainID" : "0x15",
"subprotocolName" : "exp",
"minGasLimit": "0x1388",
"accountStartNonce": "0x01"
"accountStartNonce": "0x01",
"gasLimitBoundDivisor": "0x20"
}"#;
let deserialized: Params = serde_json::from_str(s).unwrap();
@@ -118,5 +130,6 @@ mod tests {
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))));
assert_eq!(deserialized.gas_limit_bound_divisor, Uint(U256::from(0x20)));
}
}

View File

@@ -73,8 +73,7 @@ mod tests {
use hash::*;
use bytes::Bytes;
use uint::Uint;
use util::U256;
use util::{H64 as Eth64, H256 as Eth256, H520 as Eth520};
use bigint::prelude::{U256, H64 as Eth64, H256 as Eth256, H520 as Eth520};
use spec::{Ethereum, AuthorityRoundSeal, TendermintSeal, Seal};
#[test]

View File

@@ -61,12 +61,9 @@ mod tests {
"engine": {
"Ethash": {
"params": {
"gasLimitBoundDivisor": "0x0400",
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"registrar" : "0xc6d9d2cd449a754c494264e1809c50e34d64562b",
"homesteadTransition" : "0x",
"daoHardforkTransition": "0xffffffffffffffff",
"daoHardforkBeneficiary": "0x0000000000000000000000000000000000000000",
@@ -81,7 +78,8 @@ mod tests {
"minGasLimit": "0x1388",
"networkID" : "0x2",
"forkBlock": "0xffffffffffffffff",
"forkCanonHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
"forkCanonHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimitBoundDivisor": "0x20"
},
"genesis": {
"seal": {

View File

@@ -17,15 +17,11 @@
//! Tendermint params deserialization.
use uint::Uint;
use hash::Address;
use super::ValidatorSet;
/// Tendermint params deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct TendermintParams {
/// Gas limit divisor.
#[serde(rename="gasLimitBoundDivisor")]
pub gas_limit_bound_divisor: Uint,
/// Valid validators.
pub validators: ValidatorSet,
/// Propose step timeout in milliseconds.
@@ -40,11 +36,6 @@ pub struct TendermintParams {
/// Commit step timeout in milliseconds.
#[serde(rename="timeoutCommit")]
pub timeout_commit: Option<Uint>,
/// Block reward.
#[serde(rename="blockReward")]
pub block_reward: Option<Uint>,
/// Address of the registrar contract.
pub registrar: Option<Address>,
}
/// Tendermint engine deserialization.
@@ -57,10 +48,7 @@ pub struct Tendermint {
#[cfg(test)]
mod tests {
use serde_json;
use uint::Uint;
use util::U256;
use hash::Address;
use util::hash::H160;
use bigint::prelude::H160;
use spec::tendermint::Tendermint;
use spec::validator_set::ValidatorSet;
@@ -68,18 +56,14 @@ mod tests {
fn tendermint_deserialization() {
let s = r#"{
"params": {
"gasLimitBoundDivisor": "0x0400",
"validators": {
"list": ["0xc6d9d2cd449a754c494264e1809c50e34d64562b"]
},
"blockReward": "0x50"
}
}
}"#;
let deserialized: Tendermint = serde_json::from_str(s).unwrap();
assert_eq!(deserialized.params.gas_limit_bound_divisor, Uint(U256::from(0x0400)));
let vs = ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))]);
assert_eq!(deserialized.params.validators, vs);
assert_eq!(deserialized.params.block_reward, Some(Uint(U256::from(0x50))));
}
}

View File

@@ -41,9 +41,8 @@ pub enum ValidatorSet {
mod tests {
use serde_json;
use uint::Uint;
use util::U256;
use bigint::prelude::{H160, U256};
use hash::Address;
use util::hash::H160;
use spec::validator_set::ValidatorSet;
#[test]