Skip to content

Commit

Permalink
Update the coinbase_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
raychu86 committed Mar 25, 2024
1 parent 0029b6a commit b4dd9ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 9 additions & 7 deletions ledger/block/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<N: Network> Block<N> {
None => 0u128,
};

let (expected_cumulative_proof_target, is_coinbase_target_reached) = match self.solutions.deref() {
let (expected_cumulative_proof_target, is_coinbase_threshold_reached) = match self.solutions.deref() {
Some(coinbase) => {
// Ensure the puzzle proof is valid.
if let Err(e) =
Expand All @@ -369,15 +369,17 @@ impl<N: Network> Block<N> {
// Compute the actual cumulative proof target (which can exceed the coinbase target).
let cumulative_proof_target =
previous_block.cumulative_proof_target().saturating_add(combined_proof_target);
// Determine if the coinbase target is reached.
let is_coinbase_target_reached = cumulative_proof_target >= previous_block.coinbase_target() as u128;
// Compute the coinbase target threshold.
let coinbase_threshold = previous_block.coinbase_target().saturating_div(2) as u128;
// Determine if the coinbase target threshold is reached.
let is_coinbase_threshold_reached = cumulative_proof_target >= coinbase_threshold;
// Compute the block cumulative proof target (which cannot exceed the coinbase target).
let expected_cumulative_proof_target = match is_coinbase_target_reached {
let expected_cumulative_proof_target = match is_coinbase_threshold_reached {
true => 0u128,
false => cumulative_proof_target,
};

(expected_cumulative_proof_target, is_coinbase_target_reached)
(expected_cumulative_proof_target, is_coinbase_threshold_reached)
}
None => {
// Determine the cumulative proof target.
Expand All @@ -404,12 +406,12 @@ impl<N: Network> Block<N> {
proof_target(expected_coinbase_target, N::GENESIS_PROOF_TARGET, N::MAX_SOLUTIONS_AS_POWER_OF_TWO);

// Determine the expected last coinbase target.
let expected_last_coinbase_target = match is_coinbase_target_reached {
let expected_last_coinbase_target = match is_coinbase_threshold_reached {
true => expected_coinbase_target,
false => previous_block.last_coinbase_target(),
};
// Determine the expected last coinbase timestamp.
let expected_last_coinbase_timestamp = match is_coinbase_target_reached {
let expected_last_coinbase_timestamp = match is_coinbase_threshold_reached {
true => timestamp,
false => previous_block.last_coinbase_timestamp(),
};
Expand Down
10 changes: 6 additions & 4 deletions ledger/src/advance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,12 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
let next_cumulative_weight = previous_block.cumulative_weight().saturating_add(combined_proof_target);
// Compute the next cumulative proof target.
let next_cumulative_proof_target = latest_cumulative_proof_target.saturating_add(combined_proof_target);
// Determine if the coinbase target is reached.
let is_coinbase_target_reached = next_cumulative_proof_target >= latest_coinbase_target as u128;
// Compute the coinbase target threshold.
let latest_coinbase_threshold = latest_coinbase_target.saturating_div(2) as u128;
// Determine if the coinbase target threshold is reached.
let is_coinbase_threshold_reached = next_cumulative_proof_target >= latest_coinbase_threshold;
// Update the next cumulative proof target, if necessary.
let next_cumulative_proof_target = match is_coinbase_target_reached {
let next_cumulative_proof_target = match is_coinbase_threshold_reached {
true => 0,
false => next_cumulative_proof_target,
};
Expand All @@ -282,7 +284,7 @@ impl<N: Network, C: ConsensusStorage<N>> Ledger<N, C> {
proof_target(next_coinbase_target, N::GENESIS_PROOF_TARGET, N::MAX_SOLUTIONS_AS_POWER_OF_TWO);

// Construct the next last coinbase target and next last coinbase timestamp.
let (next_last_coinbase_target, next_last_coinbase_timestamp) = match is_coinbase_target_reached {
let (next_last_coinbase_target, next_last_coinbase_timestamp) = match is_coinbase_threshold_reached {
true => (next_coinbase_target, next_timestamp),
false => (previous_block.last_coinbase_target(), previous_block.last_coinbase_timestamp()),
};
Expand Down

0 comments on commit b4dd9ae

Please sign in to comment.