Refactor EIP150, EIP160 and EIP161 forks to be specified in CommonParams (#8614)

* Allow post-homestead forks to be specified in CommonParams

* Fix all json configs

* Fix test in json crate

* Fix test in ethcore

* Fix all chain configs to use tabs

Given we use tabs in .editorconfig and the majority of chain configs.
This change is done in Emacs using `mark-whole-buffer` and `indent-region`.
This commit is contained in:
Wei Tang
2018-05-22 12:24:09 +08:00
committed by Marek Kotewicz
parent 3c2f13f88b
commit 3fde07b2e1
25 changed files with 9664 additions and 9680 deletions

View File

@@ -46,14 +46,6 @@ pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]);
pub struct EthashExtensions {
/// Homestead transition block number.
pub homestead_transition: BlockNumber,
/// EIP150 transition block number.
pub eip150_transition: BlockNumber,
/// Number of first block where EIP-160 rules begin.
pub eip160_transition: u64,
/// Number of first block where EIP-161.abc begin.
pub eip161abc_transition: u64,
/// Number of first block where EIP-161.d begins.
pub eip161d_transition: u64,
/// DAO hard-fork transition block (X).
pub dao_hardfork_transition: u64,
/// DAO hard-fork refund contract address (C).
@@ -66,10 +58,6 @@ impl From<::ethjson::spec::EthashParams> for EthashExtensions {
fn from(p: ::ethjson::spec::EthashParams) -> Self {
EthashExtensions {
homestead_transition: p.homestead_transition.map_or(0, Into::into),
eip150_transition: p.eip150_transition.map_or(0, Into::into),
eip160_transition: p.eip160_transition.map_or(0, Into::into),
eip161abc_transition: p.eip161abc_transition.map_or(0, Into::into),
eip161d_transition: p.eip161d_transition.map_or(u64::max_value(), Into::into),
dao_hardfork_transition: p.dao_hardfork_transition.map_or(u64::max_value(), Into::into),
dao_hardfork_beneficiary: p.dao_hardfork_beneficiary.map_or_else(Address::new, Into::into),
dao_hardfork_accounts: p.dao_hardfork_accounts.unwrap_or_else(Vec::new).into_iter().map(Into::into).collect(),
@@ -267,19 +255,8 @@ impl EthereumMachine {
Some(ref ext) => {
if block_number < ext.homestead_transition {
Schedule::new_frontier()
} else if block_number < ext.eip150_transition {
Schedule::new_homestead()
} else {
let max_code_size = self.params.max_code_size(block_number);
let mut schedule = Schedule::new_post_eip150(
max_code_size as _,
block_number >= ext.eip160_transition,
block_number >= ext.eip161abc_transition,
block_number >= ext.eip161d_transition
);
self.params.update_schedule(block_number, &mut schedule);
schedule
self.params.schedule(block_number)
}
}
};
@@ -503,10 +480,6 @@ mod tests {
fn get_default_ethash_extensions() -> EthashExtensions {
EthashExtensions {
homestead_transition: 1150000,
eip150_transition: u64::max_value(),
eip160_transition: u64::max_value(),
eip161abc_transition: u64::max_value(),
eip161d_transition: u64::max_value(),
dao_hardfork_transition: u64::max_value(),
dao_hardfork_beneficiary: "0000000000000000000000000000000000000001".into(),
dao_hardfork_accounts: Vec::new(),

View File

@@ -78,6 +78,14 @@ pub struct CommonParams {
pub min_gas_limit: U256,
/// Fork block to check.
pub fork_block: Option<(BlockNumber, H256)>,
/// EIP150 transition block number.
pub eip150_transition: BlockNumber,
/// Number of first block where EIP-160 rules begin.
pub eip160_transition: u64,
/// Number of first block where EIP-161.abc begin.
pub eip161abc_transition: u64,
/// Number of first block where EIP-161.d begins.
pub eip161d_transition: u64,
/// Number of first block where EIP-98 rules begin.
pub eip98_transition: BlockNumber,
/// Number of first block where EIP-658 rules begin.
@@ -134,9 +142,20 @@ pub struct CommonParams {
impl CommonParams {
/// Schedule for an EVM in the post-EIP-150-era of the Ethereum main net.
pub fn schedule(&self, block_number: u64) -> ::vm::Schedule {
let mut schedule = ::vm::Schedule::new_post_eip150(self.max_code_size(block_number) as _, true, true, true);
self.update_schedule(block_number, &mut schedule);
schedule
if block_number < self.eip150_transition {
::vm::Schedule::new_homestead()
} else {
let max_code_size = self.max_code_size(block_number);
let mut schedule = ::vm::Schedule::new_post_eip150(
max_code_size as _,
block_number >= self.eip160_transition,
block_number >= self.eip161abc_transition,
block_number >= self.eip161d_transition
);
self.update_schedule(block_number, &mut schedule);
schedule
}
}
/// Returns max code size at given block.
@@ -197,6 +216,10 @@ impl From<ethjson::spec::Params> for CommonParams {
} else {
None
},
eip150_transition: p.eip150_transition.map_or(0, Into::into),
eip160_transition: p.eip160_transition.map_or(0, Into::into),
eip161abc_transition: p.eip161abc_transition.map_or(0, Into::into),
eip161d_transition: p.eip161d_transition.map_or(0, Into::into),
eip98_transition: p.eip98_transition.map_or(0, Into::into),
eip155_transition: p.eip155_transition.map_or(0, Into::into),
validate_receipts_transition: p.validate_receipts_transition.map_or(0, Into::into),