From 7c5c2bd9b8459b9b93d3699da3c58c5fd257be74 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 15 Jan 2016 01:53:52 +0100 Subject: [PATCH] Ethash populate_from_parent implementation. --- src/ethereum/ethash.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ethereum/ethash.rs b/src/ethereum/ethash.rs index f2f5eeafd..80ebcb4a2 100644 --- a/src/ethereum/ethash.rs +++ b/src/ethereum/ethash.rs @@ -14,6 +14,8 @@ impl Ethash { pub fn new_boxed(spec: Spec) -> Box { Box::new(Ethash{spec: spec}) } + + fn u256_param(&self, name: &str) -> U256 { self.spec().engine_params.get(name).map(|a| decode(&a)).unwrap_or(U256::from(0u64)) } } impl Engine for Ethash { @@ -29,6 +31,20 @@ impl Engine for Ethash { fn spec(&self) -> &Spec { &self.spec } fn schedule(&self, _env_info: &EnvInfo) -> Schedule { Schedule::new_frontier() } + fn populate_from_parent(&self, header: &mut Header, parent: &Header) { + header.difficulty = self.calculate_difficuty(header, parent); + header.gas_limit = { + let gas_floor_target: U256 = x!(3141562); + let gas_limit = parent.gas_limit; + let bound_divisor = self.u256_param("gasLimitBoundDivisor"); + if gas_limit < gas_floor_target { + min(gas_floor_target, gas_limit + gas_limit / bound_divisor - x!(1)) + } else { + max(gas_floor_target, gas_limit - gas_limit / bound_divisor + x!(1) + (header.gas_used * x!(6) / x!(5)) / bound_divisor) + } + }; + } + /// Apply the block reward on finalisation of the block. /// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current). fn on_close_block(&self, block: &mut Block) { @@ -45,7 +61,6 @@ impl Engine for Ethash { } } - fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> result::Result<(), Error> { let min_difficulty = decode(self.spec().engine_params.get("minimumDifficulty").unwrap()); if header.difficulty < min_difficulty {