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

[ethash] chainspec validate ecip1017EraRounds non-zero #11123

Merged
merged 4 commits into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion ethcore/engines/ethash/src/lib.rs
Expand Up @@ -464,7 +464,18 @@ impl Ethash {
}
}

fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number:u64) -> (u64, U256) {

/// Calculates the number of eras and reward
///
/// # Panics
///
/// This function will panic if `era_rounds` is less than `2`
fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number: u64) -> (u64, U256) {
// NOTE(niklasad1): all numbers is divisible by 1, it will cause the if below
// to succeed except the first block. Thus, `era_rounds - 1 == 0` and cause `divide by zero`
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
//
// TODO(niklasad): We could set `eras` to zero if this occurs, but I'm not sure of the implications
ordian marked this conversation as resolved.
Show resolved Hide resolved
assert!(era_rounds > 1, "ecip1017EraRounds must be bigger than 1");
let eras = if block_number != 0 && block_number % era_rounds == 0 {
block_number / era_rounds - 1
} else {
Expand Down
2 changes: 1 addition & 1 deletion json/src/spec/ethash.rs
Expand Up @@ -91,6 +91,7 @@ pub struct EthashParams {
pub ecip1010_continue_transition: Option<Uint>,

/// See main EthashParams docs.
#[serde(default, deserialize_with="uint::validate_optional_non_zero")]
pub ecip1017_era_rounds: Option<Uint>,

/// Delays of difficulty bombs.
Expand All @@ -101,7 +102,6 @@ pub struct EthashParams {
/// EXPIP-2 duration limit
pub expip2_duration_limit: Option<Uint>,
/// Block to transition to progpow
#[serde(rename="progpowTransition")]
pub progpow_transition: Option<Uint>,
}

Expand Down