2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-04-09 19:20:35 +02:00
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
//! Ethash params deserialization.
|
|
|
|
|
|
|
|
use uint::Uint;
|
|
|
|
use hash::Address;
|
|
|
|
|
2016-07-16 13:02:56 +02:00
|
|
|
/// Deserializable doppelganger of EthashParams.
|
2017-09-26 14:19:08 +02:00
|
|
|
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
2016-04-09 19:20:35 +02:00
|
|
|
pub struct EthashParams {
|
2016-07-16 13:02:56 +02:00
|
|
|
/// See main EthashParams docs.
|
2016-04-09 19:20:35 +02:00
|
|
|
#[serde(rename="minimumDifficulty")]
|
|
|
|
pub minimum_difficulty: Uint,
|
2016-07-16 13:02:56 +02:00
|
|
|
/// See main EthashParams docs.
|
2016-04-09 19:20:35 +02:00
|
|
|
#[serde(rename="difficultyBoundDivisor")]
|
|
|
|
pub difficulty_bound_divisor: Uint,
|
2016-07-16 13:02:56 +02:00
|
|
|
/// See main EthashParams docs.
|
2016-09-28 14:21:59 +02:00
|
|
|
#[serde(rename="difficultyIncrementDivisor")]
|
|
|
|
pub difficulty_increment_divisor: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
2017-03-27 11:42:40 +02:00
|
|
|
#[serde(rename="metropolisDifficultyIncrementDivisor")]
|
|
|
|
pub metropolis_difficulty_increment_divisor: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
2016-04-09 19:20:35 +02:00
|
|
|
#[serde(rename="durationLimit")]
|
2017-06-09 12:24:23 +02:00
|
|
|
pub duration_limit: Option<Uint>,
|
2016-09-28 14:21:59 +02:00
|
|
|
|
2016-07-16 13:02:56 +02:00
|
|
|
/// See main EthashParams docs.
|
2016-10-15 14:39:15 +02:00
|
|
|
#[serde(rename="homesteadTransition")]
|
|
|
|
pub homestead_transition: Option<Uint>,
|
2017-09-26 14:19:08 +02:00
|
|
|
/// Reward per block in wei.
|
|
|
|
#[serde(rename="blockReward")]
|
|
|
|
pub block_reward: Option<Uint>,
|
2016-09-28 14:21:59 +02:00
|
|
|
|
2016-07-16 13:02:56 +02:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="daoHardforkTransition")]
|
|
|
|
pub dao_hardfork_transition: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="daoHardforkBeneficiary")]
|
|
|
|
pub dao_hardfork_beneficiary: Option<Address>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="daoHardforkAccounts")]
|
|
|
|
pub dao_hardfork_accounts: Option<Vec<Address>>,
|
2016-09-28 14:21:59 +02:00
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="difficultyHardforkTransition")]
|
|
|
|
pub difficulty_hardfork_transition: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="difficultyHardforkBoundDivisor")]
|
|
|
|
pub difficulty_hardfork_bound_divisor: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="bombDefuseTransition")]
|
|
|
|
pub bomb_defuse_transition: Option<Uint>,
|
2016-10-15 14:39:15 +02:00
|
|
|
|
2017-03-27 11:42:40 +02:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="eip100bTransition")]
|
|
|
|
pub eip100b_transition: Option<Uint>,
|
|
|
|
|
2016-10-15 14:39:15 +02:00
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="eip150Transition")]
|
|
|
|
pub eip150_transition: Option<Uint>,
|
2016-11-03 22:22:25 +01:00
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="eip160Transition")]
|
|
|
|
pub eip160_transition: Option<Uint>,
|
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="eip161abcTransition")]
|
|
|
|
pub eip161abc_transition: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="eip161dTransition")]
|
|
|
|
pub eip161d_transition: Option<Uint>,
|
2016-11-04 23:09:23 +01:00
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="ecip1010PauseTransition")]
|
|
|
|
pub ecip1010_pause_transition: Option<Uint>,
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="ecip1010ContinueTransition")]
|
|
|
|
pub ecip1010_continue_transition: Option<Uint>,
|
2017-06-19 18:56:37 +02:00
|
|
|
|
|
|
|
/// See main EthashParams docs.
|
|
|
|
#[serde(rename="ecip1017EraRounds")]
|
|
|
|
pub ecip1017_era_rounds: Option<Uint>,
|
2017-09-15 21:07:54 +02:00
|
|
|
/// EIP-649 transition block.
|
|
|
|
#[serde(rename="eip649Transition")]
|
|
|
|
pub eip649_transition: Option<Uint>,
|
|
|
|
|
|
|
|
/// EIP-649 bomb delay.
|
|
|
|
#[serde(rename="eip649Delay")]
|
|
|
|
pub eip649_delay: Option<Uint>,
|
|
|
|
|
|
|
|
/// EIP-649 base reward.
|
|
|
|
#[serde(rename="eip649Reward")]
|
|
|
|
pub eip649_reward: Option<Uint>,
|
2016-04-09 19:20:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Ethash engine deserialization.
|
|
|
|
#[derive(Debug, PartialEq, Deserialize)]
|
|
|
|
pub struct Ethash {
|
|
|
|
/// Ethash params.
|
|
|
|
pub params: EthashParams,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use serde_json;
|
2017-05-20 06:11:59 +02:00
|
|
|
use uint::Uint;
|
2017-07-31 12:34:29 +02:00
|
|
|
use bigint::prelude::{H160, U256};
|
2017-05-20 06:11:59 +02:00
|
|
|
use hash::Address;
|
|
|
|
use spec::ethash::{Ethash, EthashParams};
|
2016-04-09 19:20:35 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ethash_deserialization() {
|
|
|
|
let s = r#"{
|
|
|
|
"params": {
|
|
|
|
"minimumDifficulty": "0x020000",
|
|
|
|
"difficultyBoundDivisor": "0x0800",
|
|
|
|
"durationLimit": "0x0d",
|
2016-10-15 14:39:15 +02:00
|
|
|
"homesteadTransition": "0x42",
|
2017-09-26 14:19:08 +02:00
|
|
|
"blockReward": "0x100",
|
2016-07-16 13:02:56 +02:00
|
|
|
"daoHardforkTransition": "0x08",
|
|
|
|
"daoHardforkBeneficiary": "0xabcabcabcabcabcabcabcabcabcabcabcabcabca",
|
|
|
|
"daoHardforkAccounts": [
|
|
|
|
"0x304a554a310c7e546dfe434669c62820b7d83490",
|
|
|
|
"0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79",
|
|
|
|
"0xfe24cdd8648121a43a7c86d289be4dd2951ed49f",
|
|
|
|
"0x17802f43a0137c506ba92291391a8a8f207f487d",
|
|
|
|
"0xb136707642a4ea12fb4bae820f03d2562ebff487",
|
|
|
|
"0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940",
|
|
|
|
"0xf14c14075d6c4ed84b86798af0956deef67365b5",
|
|
|
|
"0xca544e5c4687d109611d0f8f928b53a25af72448",
|
|
|
|
"0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c",
|
|
|
|
"0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7",
|
|
|
|
"0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6",
|
|
|
|
"0x2b3455ec7fedf16e646268bf88846bd7a2319bb2",
|
|
|
|
"0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a",
|
|
|
|
"0xd343b217de44030afaa275f54d31a9317c7f441e",
|
|
|
|
"0x84ef4b2357079cd7a7c69fd7a37cd0609a679106",
|
|
|
|
"0xda2fef9e4a3230988ff17df2165440f37e8b1708",
|
|
|
|
"0xf4c64518ea10f995918a454158c6b61407ea345c",
|
|
|
|
"0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97",
|
|
|
|
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
|
|
|
|
"0x807640a13483f8ac783c557fcdf27be11ea4ac7a"
|
2016-09-28 14:21:59 +02:00
|
|
|
],
|
|
|
|
"difficultyHardforkTransition": "0x59d9",
|
|
|
|
"difficultyHardforkBoundDivisor": "0x0200",
|
2017-05-20 06:11:59 +02:00
|
|
|
"bombDefuseTransition": "0x41",
|
2017-03-27 11:42:40 +02:00
|
|
|
"eip100bTransition": "0x42",
|
2017-05-20 06:11:59 +02:00
|
|
|
"eip150Transition": "0x43",
|
|
|
|
"eip160Transition": "0x45",
|
|
|
|
"eip161abcTransition": "0x46",
|
|
|
|
"eip161dTransition": "0x47"
|
2016-07-16 13:02:56 +02:00
|
|
|
}
|
|
|
|
}"#;
|
|
|
|
|
2017-05-20 06:11:59 +02:00
|
|
|
let deserialized: Ethash = serde_json::from_str(s).unwrap();
|
|
|
|
|
2017-07-31 12:34:29 +02:00
|
|
|
assert_eq!(deserialized, Ethash {
|
2017-05-20 06:11:59 +02:00
|
|
|
params: EthashParams{
|
|
|
|
minimum_difficulty: Uint(U256::from(0x020000)),
|
|
|
|
difficulty_bound_divisor: Uint(U256::from(0x0800)),
|
|
|
|
difficulty_increment_divisor: None,
|
|
|
|
metropolis_difficulty_increment_divisor: None,
|
2017-06-09 12:24:23 +02:00
|
|
|
duration_limit: Some(Uint(U256::from(0x0d))),
|
2017-05-20 06:11:59 +02:00
|
|
|
homestead_transition: Some(Uint(U256::from(0x42))),
|
2017-09-26 14:19:08 +02:00
|
|
|
block_reward: Some(Uint(U256::from(0x100))),
|
2017-05-20 06:11:59 +02:00
|
|
|
dao_hardfork_transition: Some(Uint(U256::from(0x08))),
|
|
|
|
dao_hardfork_beneficiary: Some(Address(H160::from("0xabcabcabcabcabcabcabcabcabcabcabcabcabca"))),
|
|
|
|
dao_hardfork_accounts: Some(vec![
|
|
|
|
Address(H160::from("0x304a554a310c7e546dfe434669c62820b7d83490")),
|
|
|
|
Address(H160::from("0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79")),
|
|
|
|
Address(H160::from("0xfe24cdd8648121a43a7c86d289be4dd2951ed49f")),
|
|
|
|
Address(H160::from("0x17802f43a0137c506ba92291391a8a8f207f487d")),
|
|
|
|
Address(H160::from("0xb136707642a4ea12fb4bae820f03d2562ebff487")),
|
|
|
|
Address(H160::from("0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940")),
|
|
|
|
Address(H160::from("0xf14c14075d6c4ed84b86798af0956deef67365b5")),
|
|
|
|
Address(H160::from("0xca544e5c4687d109611d0f8f928b53a25af72448")),
|
|
|
|
Address(H160::from("0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c")),
|
|
|
|
Address(H160::from("0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7")),
|
|
|
|
Address(H160::from("0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6")),
|
|
|
|
Address(H160::from("0x2b3455ec7fedf16e646268bf88846bd7a2319bb2")),
|
|
|
|
Address(H160::from("0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a")),
|
|
|
|
Address(H160::from("0xd343b217de44030afaa275f54d31a9317c7f441e")),
|
|
|
|
Address(H160::from("0x84ef4b2357079cd7a7c69fd7a37cd0609a679106")),
|
|
|
|
Address(H160::from("0xda2fef9e4a3230988ff17df2165440f37e8b1708")),
|
|
|
|
Address(H160::from("0xf4c64518ea10f995918a454158c6b61407ea345c")),
|
|
|
|
Address(H160::from("0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97")),
|
|
|
|
Address(H160::from("0xbb9bc244d798123fde783fcc1c72d3bb8c189413")),
|
|
|
|
Address(H160::from("0x807640a13483f8ac783c557fcdf27be11ea4ac7a")),
|
|
|
|
]),
|
|
|
|
difficulty_hardfork_transition: Some(Uint(U256::from(0x59d9))),
|
|
|
|
difficulty_hardfork_bound_divisor: Some(Uint(U256::from(0x0200))),
|
|
|
|
bomb_defuse_transition: Some(Uint(U256::from(0x41))),
|
|
|
|
eip100b_transition: Some(Uint(U256::from(0x42))),
|
|
|
|
eip150_transition: Some(Uint(U256::from(0x43))),
|
|
|
|
eip160_transition: Some(Uint(U256::from(0x45))),
|
|
|
|
eip161abc_transition: Some(Uint(U256::from(0x46))),
|
|
|
|
eip161d_transition: Some(Uint(U256::from(0x47))),
|
|
|
|
ecip1010_pause_transition: None,
|
|
|
|
ecip1010_continue_transition: None,
|
2017-07-06 11:36:15 +02:00
|
|
|
ecip1017_era_rounds: None,
|
2017-09-15 21:07:54 +02:00
|
|
|
eip649_transition: None,
|
|
|
|
eip649_delay: None,
|
|
|
|
eip649_reward: None,
|
2017-05-20 06:11:59 +02:00
|
|
|
}
|
|
|
|
});
|
2016-07-16 13:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ethash_deserialization_missing_optionals() {
|
|
|
|
let s = r#"{
|
|
|
|
"params": {
|
|
|
|
"difficultyBoundDivisor": "0x0800",
|
2017-07-31 12:34:29 +02:00
|
|
|
"minimumDifficulty": "0x020000"
|
2016-04-09 19:20:35 +02:00
|
|
|
}
|
|
|
|
}"#;
|
|
|
|
|
2017-05-20 06:11:59 +02:00
|
|
|
let deserialized: Ethash = serde_json::from_str(s).unwrap();
|
2017-07-31 12:34:29 +02:00
|
|
|
assert_eq!(deserialized, Ethash {
|
|
|
|
params: EthashParams {
|
2017-05-20 06:11:59 +02:00
|
|
|
minimum_difficulty: Uint(U256::from(0x020000)),
|
|
|
|
difficulty_bound_divisor: Uint(U256::from(0x0800)),
|
|
|
|
difficulty_increment_divisor: None,
|
|
|
|
metropolis_difficulty_increment_divisor: None,
|
2017-06-09 12:24:23 +02:00
|
|
|
duration_limit: None,
|
2017-05-20 06:11:59 +02:00
|
|
|
homestead_transition: None,
|
2017-09-26 14:19:08 +02:00
|
|
|
block_reward: None,
|
2017-05-20 06:11:59 +02:00
|
|
|
dao_hardfork_transition: None,
|
|
|
|
dao_hardfork_beneficiary: None,
|
|
|
|
dao_hardfork_accounts: None,
|
|
|
|
difficulty_hardfork_transition: None,
|
|
|
|
difficulty_hardfork_bound_divisor: None,
|
|
|
|
bomb_defuse_transition: None,
|
|
|
|
eip100b_transition: None,
|
|
|
|
eip150_transition: None,
|
|
|
|
eip160_transition: None,
|
|
|
|
eip161abc_transition: None,
|
|
|
|
eip161d_transition: None,
|
|
|
|
ecip1010_pause_transition: None,
|
|
|
|
ecip1010_continue_transition: None,
|
2017-07-06 11:36:15 +02:00
|
|
|
ecip1017_era_rounds: None,
|
2017-09-15 21:07:54 +02:00
|
|
|
eip649_transition: None,
|
|
|
|
eip649_delay: None,
|
|
|
|
eip649_reward: None,
|
2017-05-20 06:11:59 +02:00
|
|
|
}
|
|
|
|
});
|
2016-04-09 19:20:35 +02:00
|
|
|
}
|
|
|
|
}
|