Skip to content

Commit

Permalink
refactor: finalization_delay_length
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Jun 11, 2019
1 parent 0e78463 commit 7cc291e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 13 additions & 9 deletions spec/src/consensus.rs
Expand Up @@ -207,9 +207,22 @@ impl Consensus {
}

pub fn foundation_reserve_number(&self) -> BlockNumber {
self.finalization_delay_length()
}

pub fn finalization_delay_length(&self) -> BlockNumber {
self.tx_proposal_window.farthest() + 1
}

pub fn finalize_target(&self, block_number: BlockNumber) -> Option<BlockNumber> {
let finalize_target = block_number.checked_sub(self.finalization_delay_length())?;
// we should not reward genesis
if finalize_target < 1 {
return None;
}
Some(finalize_target)
}

pub fn genesis_hash(&self) -> &H256 {
&self.genesis_hash
}
Expand Down Expand Up @@ -392,13 +405,4 @@ impl Consensus {

Some(epoch_ext)
}

pub fn finalize_target(&self, block_number: BlockNumber) -> Option<BlockNumber> {
let finalize_target = block_number.checked_sub(self.foundation_reserve_number())?;
// we should not reward genesis
if finalize_target < 1 {
return None;
}
Some(finalize_target)
}
}
5 changes: 2 additions & 3 deletions util/reward-calculator/src/lib.rs
Expand Up @@ -30,7 +30,7 @@ impl<'a, P: ChainProvider> RewardCalculator<'a, P> {
}

/// `RewardCalculator` is used to calculate block reward according to the parent header.
/// block reward
/// block reward
pub fn block_reward(&self, parent: &Header) -> Result<(Script, Capacity), FailureError> {
let consensus = self.provider.consensus();
let store = self.provider.store();
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'a, P: ChainProvider> RewardCalculator<'a, P> {
.map_err(Into::into)
}

/// Earliest proposer get 40% of tx fee as reward when tx committed
/// Earliest proposer get 40% of tx fee as reward when tx committed
pub fn proposal_reward(
&self,
parent: &Header,
Expand All @@ -101,7 +101,6 @@ impl<'a, P: ChainProvider> RewardCalculator<'a, P> {

let mut reward = Capacity::zero();


let commit_start = cmp::max(
block_number.saturating_sub(proposal_window.length()),
1 + proposal_window.closest(),
Expand Down

0 comments on commit 7cc291e

Please sign in to comment.