From 201dbc4eeee7ea32801dbfd99cb6fc90fb1b2a0a Mon Sep 17 00:00:00 2001 From: raychu86 <14917648+raychu86@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:44:17 -0400 Subject: [PATCH] Properly calculate the expected cumulative proof target --- ledger/block/src/verify.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ledger/block/src/verify.rs b/ledger/block/src/verify.rs index 40d681efa9..82d93e8bbd 100644 --- a/ledger/block/src/verify.rs +++ b/ledger/block/src/verify.rs @@ -268,9 +268,8 @@ impl Block { let height = self.height(); let timestamp = self.timestamp(); - let (combined_proof_target, expected_cumulative_proof_target, is_coinbase_target_reached) = match &self - .solutions - { + // Compute the combined proof target and the cumulative proof target. + let (combined_proof_target, cumulative_proof_target) = match &self.solutions { Some(coinbase) => { // Ensure the number of solutions is within the allowed range. ensure!( @@ -306,26 +305,27 @@ impl Block { // 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 block cumulative proof target (which cannot exceed the coinbase target). - let expected_cumulative_proof_target = match is_coinbase_target_reached { - true => 0u128, - false => cumulative_proof_target, - }; - - (combined_proof_target, expected_cumulative_proof_target, is_coinbase_target_reached) + + (combined_proof_target, cumulative_proof_target) } None => { // Set the combined proof target. let combined_proof_target = 0; // Determine the cumulative proof target. - let expected_cumulative_proof_target = previous_block.cumulative_proof_target(); + let cumulative_proof_target = previous_block.cumulative_proof_target(); - (combined_proof_target, expected_cumulative_proof_target, false) + (combined_proof_target, cumulative_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 block cumulative proof target (which cannot exceed the coinbase target). + let expected_cumulative_proof_target = match is_coinbase_target_reached { + true => 0u128, + false => cumulative_proof_target, + }; + // Compute the expected cumulative weight. let expected_cumulative_weight = previous_block.cumulative_weight().saturating_add(combined_proof_target);