Skip to content

Commit 17ddf90

Browse files
committed
ref: saturating ops and doc clarifications
1 parent df02d72 commit 17ddf90

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

node/bft/src/primary.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,18 @@ impl<N: Network> Primary<N> {
565565

566566
// Ensure the transaction doesn't bring the proposal above the spend limit.
567567
//
568-
// Validators start following the new consensus rules early, in order to guarantee a smooth transition.
568+
// Validators start following the new consensus rules early to guarantee a smooth transition.
569569
// The activation height is offset by the maximum number of blocks that can be produced within gc to
570570
// ensure honest validators can't mismatch due to differing views of the dag.
571-
let block_height =
572-
self.ledger.latest_block_height() + 1 + (BatchHeader::<N>::MAX_GC_ROUNDS as u32 / 2);
571+
let block_height = self
572+
.ledger
573+
.latest_block_height()
574+
// Add one to get the next block height.
575+
.saturating_add(1)
576+
// Estimate and upper bound the block height for the number of rounds within gc.
577+
// Blocks contain at least two dag rounds and in max_gc_rounds we'll produce max_gc_rounds / 2 blocks.
578+
.saturating_add((BatchHeader::<N>::MAX_GC_ROUNDS as u32).saturating_div(2));
579+
573580
if N::CONSENSUS_VERSION(block_height)? >= ConsensusVersion::V4 {
574581
match self.ledger.compute_cost(transaction_id, transaction) {
575582
Ok(cost) if proposal_cost + cost <= N::BATCH_SPEND_LIMIT => proposal_cost += cost,

0 commit comments

Comments
 (0)