Merge pull request #7006 from paritytech/no-uncles

Disable uncles by default
This commit is contained in:
Marek Kotewicz 2017-11-15 23:51:49 +01:00 committed by Tomasz Drwięga
parent c7621b9bbf
commit d60fe51553
No known key found for this signature in database
GPG Key ID: D066F497E62CAF66
6 changed files with 17 additions and 2 deletions

View File

@ -23,7 +23,8 @@
] ]
}, },
"validateScoreTransition": 1000000, "validateScoreTransition": 1000000,
"validateStepTransition": 1500000 "validateStepTransition": 1500000,
"maximumUncleCount": 2
} }
} }
}, },

View File

@ -65,6 +65,8 @@ pub struct AuthorityRoundParams {
pub immediate_transitions: bool, pub immediate_transitions: bool,
/// Block reward in base units. /// Block reward in base units.
pub block_reward: U256, pub block_reward: U256,
/// Number of accepted uncles.
pub maximum_uncle_count: usize,
} }
impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams { impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
@ -77,6 +79,7 @@ impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
validate_step_transition: p.validate_step_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), immediate_transitions: p.immediate_transitions.unwrap_or(false),
block_reward: p.block_reward.map_or_else(Default::default, Into::into), block_reward: p.block_reward.map_or_else(Default::default, Into::into),
maximum_uncle_count: p.maximum_uncle_count.map_or(0, Into::into),
} }
} }
} }
@ -218,6 +221,7 @@ pub struct AuthorityRound {
epoch_manager: Mutex<EpochManager>, epoch_manager: Mutex<EpochManager>,
immediate_transitions: bool, immediate_transitions: bool,
block_reward: U256, block_reward: U256,
maximum_uncle_count: usize,
machine: EthereumMachine, machine: EthereumMachine,
} }
@ -365,6 +369,7 @@ impl AuthorityRound {
epoch_manager: Mutex::new(EpochManager::blank()), epoch_manager: Mutex::new(EpochManager::blank()),
immediate_transitions: our_params.immediate_transitions, immediate_transitions: our_params.immediate_transitions,
block_reward: our_params.block_reward, block_reward: our_params.block_reward,
maximum_uncle_count: our_params.maximum_uncle_count,
machine: machine, machine: machine,
}); });
@ -436,6 +441,8 @@ impl Engine<EthereumMachine> for AuthorityRound {
] ]
} }
fn maximum_uncle_count(&self) -> usize { self.maximum_uncle_count }
fn populate_from_parent(&self, header: &mut Header, parent: &Header) { fn populate_from_parent(&self, header: &mut Header, parent: &Header) {
// Chain scoring: total weight is sqrt(U256::max_value())*height - step // 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(); let new_difficulty = U256::from(U128::max_value()) + header_step(parent).expect("Header has been verified; qed").into() - self.step.load().into();
@ -949,6 +956,7 @@ mod tests {
validate_score_transition: 0, validate_score_transition: 0,
validate_step_transition: 0, validate_step_transition: 0,
immediate_transitions: true, immediate_transitions: true,
maximum_uncle_count: 0,
block_reward: Default::default(), block_reward: Default::default(),
}; };

View File

@ -192,7 +192,7 @@ pub trait Engine<M: Machine>: Sync + Send {
fn extra_info(&self, _header: &M::Header) -> BTreeMap<String, String> { BTreeMap::new() } fn extra_info(&self, _header: &M::Header) -> BTreeMap<String, String> { BTreeMap::new() }
/// Maximum number of uncles a block is allowed to declare. /// 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. /// The number of generations back that uncles can be.
fn maximum_uncle_age(&self) -> usize { 6 } fn maximum_uncle_age(&self) -> usize { 6 }

View File

@ -95,6 +95,8 @@ impl<M: WithBalances> Engine<M> for NullEngine<M> {
self.machine.note_rewards(block, &[(author, result_block_reward)], &uncle_rewards) self.machine.note_rewards(block, &[(author, result_block_reward)], &uncle_rewards)
} }
fn maximum_uncle_count(&self) -> usize { 2 }
fn verify_local_seal(&self, _header: &M::Header) -> Result<(), M::Error> { fn verify_local_seal(&self, _header: &M::Header) -> Result<(), M::Error> {
Ok(()) Ok(())
} }

View File

@ -181,6 +181,8 @@ impl Engine<EthereumMachine> for Arc<Ethash> {
} }
} }
fn maximum_uncle_count(&self) -> usize { 2 }
fn populate_from_parent(&self, header: &mut Header, parent: &Header) { fn populate_from_parent(&self, header: &mut Header, parent: &Header) {
let difficulty = self.calculate_difficulty(header, parent); let difficulty = self.calculate_difficulty(header, parent);
header.set_difficulty(difficulty); header.set_difficulty(difficulty);

View File

@ -43,6 +43,8 @@ pub struct AuthorityRoundParams {
/// Reward per block in wei. /// Reward per block in wei.
#[serde(rename="blockReward")] #[serde(rename="blockReward")]
pub block_reward: Option<Uint>, pub block_reward: Option<Uint>,
#[serde(rename="maximumUncleCount")]
pub maximum_uncle_count: Option<Uint>,
} }
/// Authority engine deserialization. /// Authority engine deserialization.