From da49e20e67db25acdb263f72efac173385094787 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 15 Nov 2017 23:51:49 +0100 Subject: [PATCH] Merge pull request #7006 from paritytech/no-uncles Disable uncles by default --- ethcore/res/ethereum/kovan.json | 5 +++-- ethcore/src/engines/authority_round/mod.rs | 10 +++++++++- ethcore/src/engines/mod.rs | 2 +- ethcore/src/engines/null_engine.rs | 2 ++ ethcore/src/ethereum/ethash.rs | 2 ++ json/src/spec/authority_round.rs | 2 ++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ethcore/res/ethereum/kovan.json b/ethcore/res/ethereum/kovan.json index 7cdb79e16aa..682143065ce 100644 --- a/ethcore/res/ethereum/kovan.json +++ b/ethcore/res/ethereum/kovan.json @@ -26,8 +26,9 @@ }, "validateScoreTransition": 1000000, "eip155Transition": 1000000, - "validateStepTransition": 1500000 - } + "validateStepTransition": 1500000, + "maximumUncleCount": 2 + } } }, "params": { diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index 83eadc422ad..6550c911b80 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -67,6 +67,8 @@ pub struct AuthorityRoundParams { pub validate_step_transition: u64, /// Immediate transitions. pub immediate_transitions: bool, + /// Number of accepted uncles. + pub maximum_uncle_count: usize, } impl From for AuthorityRoundParams { @@ -82,6 +84,7 @@ impl From for AuthorityRoundParams { eip155_transition: p.eip155_transition.map_or(0, Into::into), validate_step_transition: p.validate_step_transition.map_or(0, Into::into), immediate_transitions: p.immediate_transitions.unwrap_or(false), + maximum_uncle_count: p.maximum_uncle_count.map_or(0, Into::into), } } } @@ -229,6 +232,7 @@ pub struct AuthorityRound { validate_step_transition: u64, epoch_manager: Mutex, immediate_transitions: bool, + maximum_uncle_count: usize, } // header-chain validator. @@ -381,6 +385,7 @@ impl AuthorityRound { validate_step_transition: our_params.validate_step_transition, epoch_manager: Mutex::new(EpochManager::blank()), immediate_transitions: our_params.immediate_transitions, + maximum_uncle_count: our_params.maximum_uncle_count, }); // Do not initialize timeouts for tests. @@ -455,8 +460,9 @@ impl Engine for AuthorityRound { ] } + fn maximum_uncle_count(&self) -> usize { self.maximum_uncle_count } + fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, _gas_ceil_target: U256) { - // Chain scoring: total weight is sqrt(U256::max_value())*height - step let new_difficulty = U256::from(U128::max_value()) + header_step(parent).expect("Header has been verified; qed").into() - self.step.load().into(); header.set_difficulty(new_difficulty); header.set_gas_limit({ @@ -1027,7 +1033,9 @@ mod tests { validate_step_transition: 0, eip155_transition: 0, immediate_transitions: true, + maximum_uncle_count: 0, }; + let aura = AuthorityRound::new(Default::default(), params, Default::default()).unwrap(); let mut parent_header: Header = Header::default(); diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 4127662001d..cb12c2023ac 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -203,7 +203,7 @@ pub trait Engine : Sync + Send { /// Some intrinsic operation parameters; by default they take their value from the `spec()`'s `engine_params`. fn maximum_extra_data_size(&self) -> usize { self.params().maximum_extra_data_size } /// Maximum number of uncles a block is allowed to declare. - fn maximum_uncle_count(&self) -> usize { 2 } + fn maximum_uncle_count(&self) -> usize { 0 } /// The number of generations back that uncles can be. fn maximum_uncle_age(&self) -> usize { 6 } /// The nonce with which accounts begin at given block. diff --git a/ethcore/src/engines/null_engine.rs b/ethcore/src/engines/null_engine.rs index 55215458005..17d28504b0f 100644 --- a/ethcore/src/engines/null_engine.rs +++ b/ethcore/src/engines/null_engine.rs @@ -57,6 +57,8 @@ impl Engine for NullEngine { &self.builtins } + fn maximum_uncle_count(&self) -> usize { 2 } + fn schedule(&self, _block_number: BlockNumber) -> Schedule { Schedule::new_homestead() } diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 68c769c7c5b..0f8533c3079 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -238,6 +238,8 @@ impl Engine for Arc { } } + fn maximum_uncle_count(&self) -> usize { 2 } + fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, mut gas_ceil_target: U256) { let difficulty = self.calculate_difficulty(header, parent); if header.number() >= self.ethash_params.max_gas_limit_transition && gas_ceil_target > self.ethash_params.max_gas_limit { diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index 0fdbfbfb34c..f3c188bb5f4 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -52,6 +52,8 @@ pub struct AuthorityRoundParams { /// Whether transitions should be immediate. #[serde(rename="immediateTransitions")] pub immediate_transitions: Option, + #[serde(rename="maximumUncleCount")] + pub maximum_uncle_count: Option, } /// Authority engine deserialization.