Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer overflow and underflow in DeferralKey methods and add corresponding tests #20387

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions crates/sui-core/src/authority/transaction_deferral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use narwhal_types::Round;
use serde::{Deserialize, Serialize};
use mysten_common::debug_fatal;
use sui_types::base_types::ObjectID;

#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
Expand All @@ -29,6 +30,15 @@ impl DeferralKey {
}

pub fn new_for_consensus_round(future_round: Round, deferred_from_round: Round) -> Self {
if future_round < deferred_from_round {
debug_fatal!("future_round must be greater than or equal to deferred_from_round ");

return Self::ConsensusRound {
future_round: deferred_from_round,
deferred_from_round,
};
}

Self::ConsensusRound {
future_round,
deferred_from_round,
Expand Down Expand Up @@ -90,11 +100,13 @@ pub fn transaction_deferral_within_limit(
deferred_from_round,
} = deferral_key
{
return (future_round - deferred_from_round) <= max_deferral_rounds_for_congestion_control;
debug_assert!(future_round >= deferred_from_round);

let diff = future_round.saturating_sub(*deferred_from_round);
return diff <= max_deferral_rounds_for_congestion_control;
}

// TODO: drop transactions at the end of the queue if the queue is too long.

true
}

Expand Down
Loading