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

Commit

Permalink
Merge pull request #7006 from paritytech/no-uncles
Browse files Browse the repository at this point in the history
Disable uncles by default
  • Loading branch information
debris authored and tomusdrw committed Dec 5, 2017
1 parent 4d1b892 commit da49e20
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions ethcore/res/ethereum/kovan.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
},
"validateScoreTransition": 1000000,
"eip155Transition": 1000000,
"validateStepTransition": 1500000
}
"validateStepTransition": 1500000,
"maximumUncleCount": 2
}
}
},
"params": {
Expand Down
10 changes: 9 additions & 1 deletion ethcore/src/engines/authority_round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
Expand All @@ -82,6 +84,7 @@ impl From<ethjson::spec::AuthorityRoundParams> 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),
}
}
}
Expand Down Expand Up @@ -229,6 +232,7 @@ pub struct AuthorityRound {
validate_step_transition: u64,
epoch_manager: Mutex<EpochManager>,
immediate_transitions: bool,
maximum_uncle_count: usize,
}

// header-chain validator.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ethcore/src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/engines/null_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions ethcore/src/ethereum/ethash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ impl Engine for Arc<Ethash> {
}
}

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 {
Expand Down
2 changes: 2 additions & 0 deletions json/src/spec/authority_round.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct AuthorityRoundParams {
/// Whether transitions should be immediate.
#[serde(rename="immediateTransitions")]
pub immediate_transitions: Option<bool>,
#[serde(rename="maximumUncleCount")]
pub maximum_uncle_count: Option<Uint>,
}

/// Authority engine deserialization.
Expand Down

0 comments on commit da49e20

Please sign in to comment.