-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Chain scoring #4218
Chain scoring #4218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,13 @@ use std::sync::Weak; | |
use std::time::{UNIX_EPOCH, Duration}; | ||
use util::*; | ||
use ethkey::{verify_address, Signature}; | ||
use rlp::{UntrustedRlp, Rlp, View, encode}; | ||
use rlp::{UntrustedRlp, View, encode}; | ||
use account_provider::AccountProvider; | ||
use block::*; | ||
use spec::CommonParams; | ||
use engines::{Engine, Seal, EngineError}; | ||
use header::Header; | ||
use error::{Error, BlockError}; | ||
use blockchain::extras::BlockDetails; | ||
use views::HeaderView; | ||
use evm::Schedule; | ||
use ethjson; | ||
use io::{IoContext, IoHandler, TimerToken, IoService}; | ||
|
@@ -209,7 +207,9 @@ impl Engine for AuthorityRound { | |
} | ||
|
||
fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, _gas_ceil_target: U256) { | ||
header.set_difficulty(parent.difficulty().clone()); | ||
// 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(AtomicOrdering::SeqCst).into(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The formula above is for total weight, populating the block gives weight to an individual block. Summing blocks gives the total. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consensus is broken if any of these overflow, so it does not matter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But no need to worry, releasing billion blocks every second it will last us until the death of the galaxy many times anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, just noticed that it's basically a block number and it's |
||
header.set_difficulty(new_difficulty); | ||
header.set_gas_limit({ | ||
let gas_limit = parent.gas_limit().clone(); | ||
let bound_divisor = self.gas_limit_bound_divisor; | ||
|
@@ -311,19 +311,6 @@ impl Engine for AuthorityRound { | |
Ok(()) | ||
} | ||
|
||
fn is_new_best_block(&self, _best_total_difficulty: U256, best_header: HeaderView, _parent_details: &BlockDetails, new_header: &HeaderView) -> bool { | ||
let new_number = new_header.number(); | ||
let best_number = best_header.number(); | ||
if new_number != best_number { | ||
new_number > best_number | ||
} else { | ||
// Take the oldest step at given height. | ||
let new_step: usize = Rlp::new(&new_header.seal()[0]).as_val(); | ||
let best_step: usize = Rlp::new(&best_header.seal()[0]).as_val(); | ||
new_step < best_step | ||
} | ||
} | ||
|
||
fn register_client(&self, client: Weak<Client>) { | ||
*self.client.write() = Some(client.clone()); | ||
self.validators.register_call_contract(client); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,6 @@ use account_provider::AccountProvider; | |
use block::*; | ||
use spec::CommonParams; | ||
use engines::{Engine, Seal, EngineError}; | ||
use blockchain::extras::BlockDetails; | ||
use views::HeaderView; | ||
use evm::Schedule; | ||
use state::CleanupMode; | ||
use io::IoService; | ||
|
@@ -397,7 +395,9 @@ impl Engine for Tendermint { | |
} | ||
|
||
fn populate_from_parent(&self, header: &mut Header, parent: &Header, gas_floor_target: U256, _gas_ceil_target: U256) { | ||
header.set_difficulty(parent.difficulty().clone()); | ||
// Chain scoring: total weight is sqrt(U256::max_value())*height - round | ||
let new_difficulty = U256::from(U128::max_value()) + consensus_round(parent).expect("Header has been verified; qed").into() - self.round.load(AtomicOrdering::SeqCst).into(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use |
||
header.set_difficulty(new_difficulty); | ||
header.set_gas_limit({ | ||
let gas_limit = parent.gas_limit().clone(); | ||
let bound_divisor = self.gas_limit_bound_divisor; | ||
|
@@ -568,27 +568,6 @@ impl Engine for Tendermint { | |
self.step_service.stop() | ||
} | ||
|
||
fn is_new_best_block(&self, _best_total_difficulty: U256, best_header: HeaderView, _parent_details: &BlockDetails, new_header: &HeaderView) -> bool { | ||
let new_number = new_header.number(); | ||
let best_number = best_header.number(); | ||
trace!(target: "poa", "new_header: {}, best_header: {}", new_number, best_number); | ||
if new_number != best_number { | ||
new_number > best_number | ||
} else { | ||
let new_seal = new_header.seal(); | ||
let best_seal = best_header.seal(); | ||
let new_signatures = new_seal.get(2).expect("Tendermint seal should have three elements.").len(); | ||
let best_signatures = best_seal.get(2).expect("Tendermint seal should have three elements.").len(); | ||
if new_signatures > best_signatures { | ||
true | ||
} else { | ||
let new_round: Round = ::rlp::Rlp::new(&new_seal.get(0).expect("Tendermint seal should have three elements.")).as_val(); | ||
let best_round: Round = ::rlp::Rlp::new(&best_seal.get(0).expect("Tendermint seal should have three elements.")).as_val(); | ||
new_round > best_round | ||
} | ||
} | ||
} | ||
|
||
fn is_proposal(&self, header: &Header) -> bool { | ||
let signatures_len = header.seal()[2].len(); | ||
// Signatures have to be an empty list rlp. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use
saturating_add
to avoid overflows.