-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Conversation
Changes Unknown when pulling 380f5b6 on chain-score into ** on master**. |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like + height
instead of * height
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use saturating_add
to avoid overflows.
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.
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 comment
The 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 comment
The 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 u64
anyway :)
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use saturating_add
to avoid overflows.
@@ -867,7 +862,7 @@ impl BlockChain { | |||
let number = header.number(); | |||
let parent_hash = header.parent_hash(); | |||
let parent_details = self.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash)); | |||
let is_new_best = self.engine.is_new_best_block(self.best_block_total_difficulty(), self.best_block_header().view(), &parent_details, header); | |||
let is_new_best = parent_details.total_difficulty + header.difficulty() > self.best_block_total_difficulty(); |
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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably use saturating_add
to avoid overflows.
Not sure about renaming
difficulty
toweight
yet since the overall usage is stillEthash
centric.