Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
ethash: implement EIP-1234 (#9187)
Browse files Browse the repository at this point in the history
  • Loading branch information
5chdn authored and andresilva committed Oct 9, 2018
1 parent 710ac6e commit 04acb9c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ethcore/res/ethereum/byzantium_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"blockReward": "0x29A2241AF62C0000",
"homesteadTransition": "0x0",
"eip649Reward": "0x29A2241AF62C0000",
"eip100bTransition": "0x0",
"eip649Reward": "0x29A2241AF62C0000",
"eip649Transition": "0x0"
}
}
Expand Down
6 changes: 3 additions & 3 deletions ethcore/res/ethereum/constantinople_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"minimumDifficulty": "0x020000",
"difficultyBoundDivisor": "0x0800",
"durationLimit": "0x0d",
"blockReward": "0x4563918244F40000",
"blockReward": "0x29A2241AF62C0000",
"homesteadTransition": "0x0",
"eip649Reward": "0x29A2241AF62C0000",
"eip100bTransition": "0x0",
"eip649Transition": "0x0"
"eip649Transition": "0x0",
"eip649Reward": "0x29A2241AF62C0000"
}
}
},
Expand Down
24 changes: 21 additions & 3 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use machine::EthereumMachine;
const SNAPSHOT_BLOCKS: u64 = 5000;
/// Maximum number of blocks allowed in an ethash snapshot.
const MAX_SNAPSHOT_BLOCKS: u64 = 30000;

/// Default number of blocks the difficulty bomb is delayed in EIP-{649,1234}
const DEFAULT_EIP649_DELAY: u64 = 3_000_000;
const DEFAULT_EIP1234_DELAY: u64 = 2_000_000;

/// Ethash specific seal
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -120,6 +121,12 @@ pub struct EthashParams {
pub eip649_delay: u64,
/// EIP-649 base reward.
pub eip649_reward: Option<U256>,
/// EIP-1234 transition block.
pub eip1234_transition: u64,
/// EIP-1234 bomb delay.
pub eip1234_delay: u64,
/// EIP-1234 base reward.
pub eip1234_reward: Option<U256>,
/// EXPIP-2 block height
pub expip2_transition: u64,
/// EXPIP-2 duration limit
Expand Down Expand Up @@ -152,6 +159,9 @@ impl From<ethjson::spec::EthashParams> for EthashParams {
eip649_transition: p.eip649_transition.map_or(u64::max_value(), Into::into),
eip649_delay: p.eip649_delay.map_or(DEFAULT_EIP649_DELAY, Into::into),
eip649_reward: p.eip649_reward.map(Into::into),
eip1234_transition: p.eip1234_transition.map_or(u64::max_value(), Into::into),
eip1234_delay: p.eip1234_delay.map_or(DEFAULT_EIP1234_DELAY, Into::into),
eip1234_reward: p.eip1234_reward.map(Into::into),
expip2_transition: p.expip2_transition.map_or(u64::max_value(), Into::into),
expip2_duration_limit: p.expip2_duration_limit.map_or(30, Into::into),
}
Expand Down Expand Up @@ -233,8 +243,10 @@ impl Engine<EthereumMachine> for Arc<Ethash> {

let mut rewards = Vec::new();

// Applies EIP-649 reward.
let reward = if number >= self.ethash_params.eip649_transition {
// Applies EIP-{649,1234} reward, defaults to block_reward.
let reward = if number >= self.ethash_params.eip1234_transition {
self.ethash_params.eip1234_reward.unwrap_or(self.ethash_params.block_reward)
} else if number >= self.ethash_params.eip649_transition {
self.ethash_params.eip649_reward.unwrap_or(self.ethash_params.block_reward)
} else {
self.ethash_params.block_reward
Expand Down Expand Up @@ -427,6 +439,9 @@ impl Ethash {
if header.number() < self.ethash_params.bomb_defuse_transition {
if header.number() < self.ethash_params.ecip1010_pause_transition {
let mut number = header.number();
if number >= self.ethash_params.eip1234_transition {
number = number.saturating_sub(self.ethash_params.eip1234_delay);
}
if number >= self.ethash_params.eip649_transition {
number = number.saturating_sub(self.ethash_params.eip649_delay);
}
Expand Down Expand Up @@ -510,6 +525,9 @@ mod tests {
eip649_transition: u64::max_value(),
eip649_delay: 3_000_000,
eip649_reward: None,
eip1234_transition: u64::max_value(),
eip1234_delay: 2_000_000,
eip1234_reward: None,
expip2_transition: u64::max_value(),
expip2_duration_limit: 30,
}
Expand Down
18 changes: 18 additions & 0 deletions json/src/spec/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ pub struct EthashParams {
#[serde(rename="eip649Reward")]
pub eip649_reward: Option<Uint>,

/// EIP-1234 transition block.
#[serde(rename="eip1234Transition")]
pub eip1234_transition: Option<Uint>,

/// EIP-1234 bomb delay.
#[serde(rename="eip1234Delay")]
pub eip1234_delay: Option<Uint>,

/// EIP-1234 base reward.
#[serde(rename="eip1234Reward")]
pub eip1234_reward: Option<Uint>,

/// EXPIP-2 block height
#[serde(rename="expip2Transition")]
pub expip2_transition: Option<Uint>,
Expand Down Expand Up @@ -231,6 +243,9 @@ mod tests {
eip649_transition: None,
eip649_delay: None,
eip649_reward: None,
eip1234_transition: None,
eip1234_delay: None,
eip1234_reward: None,
expip2_transition: None,
expip2_duration_limit: None,
}
Expand Down Expand Up @@ -275,6 +290,9 @@ mod tests {
eip649_transition: None,
eip649_delay: None,
eip649_reward: None,
eip1234_transition: None,
eip1234_delay: None,
eip1234_reward: None,
expip2_transition: None,
expip2_duration_limit: None,
}
Expand Down

0 comments on commit 04acb9c

Please sign in to comment.