From 0ec35d9ac5c64b9c3ae023b39596472461104fd9 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 24 Nov 2017 15:49:33 +0100 Subject: [PATCH] Merge pull request #7067 from sorpaas/patch-1 ECIP-1039: Monetary policy rounding specification --- ethcore/src/ethereum/ethash.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index a49ba2e2a..161278ba1 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -447,9 +447,12 @@ fn ecip1017_eras_block_reward(era_rounds: u64, mut reward: U256, block_number:u6 } else { block_number / era_rounds }; + let mut divi = U256::from(1); for _ in 0..eras { - reward = reward / U256::from(5) * U256::from(4); + reward = reward * U256::from(4); + divi = divi * U256::from(5); } + reward = reward / divi; (eras, reward) } @@ -515,6 +518,11 @@ mod tests { let (eras, reward) = ecip1017_eras_block_reward(eras_rounds, start_reward, block_number); assert_eq!(15, eras); assert_eq!(U256::from_str("271000000000000").unwrap(), reward); + + let block_number = 250000000; + let (eras, reward) = ecip1017_eras_block_reward(eras_rounds, start_reward, block_number); + assert_eq!(49, eras); + assert_eq!(U256::from_str("51212FFBAF0A").unwrap(), reward); } #[test]