Skip to content

Commit b8e8b86

Browse files
committed
Restore separate budget for randomness tx in ExecutionTimeEstimate mode
Also includes some minor cleanups, most notably removing the absolute limit param for this mode since we always set it to u64::MAX. Stacked on PR #21466
1 parent 38b0c4b commit b8e8b86

File tree

4 files changed

+63
-20
lines changed

4 files changed

+63
-20
lines changed

crates/sui-core/src/authority/execution_time_estimator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ mod tests {
10121012

10131013
// Not used in this test.
10141014
allowed_txn_cost_overage_burst_limit_us: 0,
1015-
max_txn_cost_overage_per_object_in_commit_us: 0,
1015+
randomness_scalar: 0,
10161016
},
10171017
std::iter::empty(),
10181018
);

crates/sui-core/src/authority/shared_object_congestion_tracker.rs

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use tracing::trace;
1818
#[derive(PartialEq, Eq, Clone, Debug)]
1919
struct Params {
2020
mode: PerObjectCongestionControlMode,
21+
for_randomness: bool,
2122
max_accumulated_txn_cost_per_object_in_commit: u64,
2223
gas_budget_based_txn_cost_cap_factor: Option<u64>,
2324
gas_budget_based_txn_cost_absolute_cap: Option<u64>,
@@ -33,10 +34,17 @@ impl Params {
3334
PerObjectCongestionControlMode::ExecutionTimeEstimate(params) => {
3435
let estimated_commit_period = commit_info.estimated_commit_period();
3536
let commit_period_micros = estimated_commit_period.as_micros() as u64;
36-
commit_period_micros
37+
let mut budget = commit_period_micros
3738
.checked_mul(params.target_utilization)
3839
.unwrap_or(u64::MAX)
39-
/ 100
40+
/ 100;
41+
if self.for_randomness {
42+
budget = budget
43+
.checked_mul(params.randomness_scalar)
44+
.unwrap_or(u64::MAX)
45+
/ 100;
46+
}
47+
budget
4048
}
4149
_ => self.max_accumulated_txn_cost_per_object_in_commit,
4250
}
@@ -47,7 +55,14 @@ impl Params {
4755
pub fn max_burst(&self) -> u64 {
4856
match self.mode {
4957
PerObjectCongestionControlMode::ExecutionTimeEstimate(params) => {
50-
params.allowed_txn_cost_overage_burst_limit_us
58+
let mut burst = params.allowed_txn_cost_overage_burst_limit_us;
59+
if self.for_randomness {
60+
burst = burst
61+
.checked_mul(params.randomness_scalar)
62+
.unwrap_or(u64::MAX)
63+
/ 100;
64+
}
65+
burst
5166
}
5267
_ => self.allowed_txn_cost_overage_burst_per_object_in_commit,
5368
}
@@ -58,9 +73,7 @@ impl Params {
5873
// unschedulable regardless of congestion.
5974
pub fn max_overage(&self) -> u64 {
6075
match self.mode {
61-
PerObjectCongestionControlMode::ExecutionTimeEstimate(params) => {
62-
params.max_txn_cost_overage_per_object_in_commit_us
63-
}
76+
PerObjectCongestionControlMode::ExecutionTimeEstimate(_) => u64::MAX,
6477
_ => self.max_txn_cost_overage_per_object_in_commit,
6578
}
6679
}
@@ -110,6 +123,7 @@ impl SharedObjectCongestionTracker {
110123
pub fn new(
111124
initial_object_debts: impl IntoIterator<Item = (ObjectID, u64)>,
112125
mode: PerObjectCongestionControlMode,
126+
for_randomness: bool,
113127
max_accumulated_txn_cost_per_object_in_commit: Option<u64>,
114128
gas_budget_based_txn_cost_cap_factor: Option<u64>,
115129
gas_budget_based_txn_cost_absolute_cap_commit_count: Option<u64>,
@@ -148,6 +162,7 @@ impl SharedObjectCongestionTracker {
148162
object_execution_cost,
149163
params: Params {
150164
mode,
165+
for_randomness,
151166
max_accumulated_txn_cost_per_object_in_commit,
152167
gas_budget_based_txn_cost_cap_factor,
153168
gas_budget_based_txn_cost_absolute_cap,
@@ -167,6 +182,7 @@ impl SharedObjectCongestionTracker {
167182
Ok(Self::new(
168183
initial_object_debts,
169184
protocol_config.per_object_congestion_control_mode(),
185+
for_randomness,
170186
if for_randomness {
171187
protocol_config
172188
.max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit_as_option()
@@ -417,6 +433,7 @@ mod object_cost_tests {
417433
let shared_object_congestion_tracker = SharedObjectCongestionTracker::new(
418434
[(object_id_0, 5), (object_id_1, 10)],
419435
PerObjectCongestionControlMode::TotalGasBudget,
436+
false,
420437
Some(0), // not part of this test
421438
None,
422439
None,
@@ -545,7 +562,7 @@ mod object_cost_tests {
545562
PerObjectCongestionControlMode::ExecutionTimeEstimate(ExecutionTimeEstimateParams {
546563
target_utilization: 100,
547564
allowed_txn_cost_overage_burst_limit_us: 0,
548-
max_txn_cost_overage_per_object_in_commit_us: 0,
565+
randomness_scalar: 0,
549566
max_estimate_us: u64::MAX,
550567
}),
551568
)]
@@ -578,6 +595,7 @@ mod object_cost_tests {
578595
SharedObjectCongestionTracker::new(
579596
[(shared_obj_0, 10), (shared_obj_1, 1)],
580597
mode,
598+
false,
581599
Some(max_accumulated_txn_cost_per_object_in_commit),
582600
None,
583601
None,
@@ -593,6 +611,7 @@ mod object_cost_tests {
593611
SharedObjectCongestionTracker::new(
594612
[(shared_obj_0, 2), (shared_obj_1, 1)],
595613
mode,
614+
false,
596615
Some(max_accumulated_txn_cost_per_object_in_commit),
597616
None,
598617
None,
@@ -608,6 +627,7 @@ mod object_cost_tests {
608627
SharedObjectCongestionTracker::new(
609628
[(shared_obj_0, 10), (shared_obj_1, 1)],
610629
mode,
630+
false,
611631
Some(max_accumulated_txn_cost_per_object_in_commit),
612632
Some(45), // Make the cap just less than the gas budget, there are 1 objects in tx.
613633
None,
@@ -623,6 +643,7 @@ mod object_cost_tests {
623643
SharedObjectCongestionTracker::new(
624644
[(shared_obj_0, 750), (shared_obj_1, 0)],
625645
mode,
646+
false,
626647
Some(max_accumulated_txn_cost_per_object_in_commit),
627648
None,
628649
None,
@@ -737,8 +758,8 @@ mod object_cost_tests {
737758
PerObjectCongestionControlMode::ExecutionTimeEstimate(ExecutionTimeEstimateParams {
738759
target_utilization: 0, // Make should_defer_due_to_object_congestion always defer transactions.
739760
allowed_txn_cost_overage_burst_limit_us: 0,
740-
max_txn_cost_overage_per_object_in_commit_us: 0,
741761
max_estimate_us: u64::MAX,
762+
randomness_scalar: 0,
742763
}),
743764
)]
744765
mode: PerObjectCongestionControlMode,
@@ -751,6 +772,7 @@ mod object_cost_tests {
751772
let shared_object_congestion_tracker = SharedObjectCongestionTracker::new(
752773
[],
753774
mode,
775+
false,
754776
Some(0), // Make should_defer_due_to_object_congestion always defer transactions.
755777
Some(2),
756778
None,
@@ -864,7 +886,7 @@ mod object_cost_tests {
864886
PerObjectCongestionControlMode::ExecutionTimeEstimate(ExecutionTimeEstimateParams {
865887
target_utilization: 16,
866888
allowed_txn_cost_overage_burst_limit_us: 0,
867-
max_txn_cost_overage_per_object_in_commit_us: 10_000_000,
889+
randomness_scalar: 0,
868890
max_estimate_us: u64::MAX,
869891
}),
870892
)]
@@ -900,6 +922,7 @@ mod object_cost_tests {
900922
SharedObjectCongestionTracker::new(
901923
[(shared_obj_0, 102), (shared_obj_1, 90)],
902924
mode,
925+
false,
903926
Some(max_accumulated_txn_cost_per_object_in_commit),
904927
None,
905928
None,
@@ -915,6 +938,7 @@ mod object_cost_tests {
915938
SharedObjectCongestionTracker::new(
916939
[(shared_obj_0, 3), (shared_obj_1, 2)],
917940
mode,
941+
false,
918942
Some(max_accumulated_txn_cost_per_object_in_commit),
919943
None,
920944
None,
@@ -930,6 +954,7 @@ mod object_cost_tests {
930954
SharedObjectCongestionTracker::new(
931955
[(shared_obj_0, 100), (shared_obj_1, 90)],
932956
mode,
957+
false,
933958
Some(max_accumulated_txn_cost_per_object_in_commit),
934959
Some(45), // Make the cap just less than the gas budget, there are 1 objects in tx.
935960
None,
@@ -945,6 +970,7 @@ mod object_cost_tests {
945970
SharedObjectCongestionTracker::new(
946971
[(shared_obj_0, 1_700_000), (shared_obj_1, 300_000)],
947972
mode,
973+
false,
948974
Some(max_accumulated_txn_cost_per_object_in_commit),
949975
None,
950976
None,
@@ -1030,7 +1056,7 @@ mod object_cost_tests {
10301056
PerObjectCongestionControlMode::ExecutionTimeEstimate(ExecutionTimeEstimateParams {
10311057
target_utilization: 16,
10321058
allowed_txn_cost_overage_burst_limit_us: 1_500_000,
1033-
max_txn_cost_overage_per_object_in_commit_us: 10_000_000,
1059+
randomness_scalar: 0,
10341060
max_estimate_us: u64::MAX,
10351061
}),
10361062
)]
@@ -1077,6 +1103,7 @@ mod object_cost_tests {
10771103
SharedObjectCongestionTracker::new(
10781104
[(shared_obj_0, 301), (shared_obj_1, 199)],
10791105
mode,
1106+
false,
10801107
Some(max_accumulated_txn_cost_per_object_in_commit),
10811108
None,
10821109
None,
@@ -1095,6 +1122,7 @@ mod object_cost_tests {
10951122
SharedObjectCongestionTracker::new(
10961123
[(shared_obj_0, 5), (shared_obj_1, 4)],
10971124
mode,
1125+
false,
10981126
Some(max_accumulated_txn_cost_per_object_in_commit),
10991127
None,
11001128
None,
@@ -1113,6 +1141,7 @@ mod object_cost_tests {
11131141
SharedObjectCongestionTracker::new(
11141142
[(shared_obj_0, 301), (shared_obj_1, 250)],
11151143
mode,
1144+
false,
11161145
Some(max_accumulated_txn_cost_per_object_in_commit),
11171146
Some(45), // Make the cap just less than the gas budget, there are 1 objects in tx.
11181147
None,
@@ -1131,6 +1160,7 @@ mod object_cost_tests {
11311160
SharedObjectCongestionTracker::new(
11321161
[(shared_obj_0, 4_000_000), (shared_obj_1, 2_000_000)],
11331162
mode,
1163+
false,
11341164
Some(max_accumulated_txn_cost_per_object_in_commit),
11351165
None,
11361166
None,
@@ -1218,7 +1248,7 @@ mod object_cost_tests {
12181248
// all params ignored in this test
12191249
target_utilization: 0,
12201250
allowed_txn_cost_overage_burst_limit_us: 0,
1221-
max_txn_cost_overage_per_object_in_commit_us: 0,
1251+
randomness_scalar: 0,
12221252
max_estimate_us: u64::MAX,
12231253
}),
12241254
)]
@@ -1237,6 +1267,7 @@ mod object_cost_tests {
12371267
let mut shared_object_congestion_tracker = SharedObjectCongestionTracker::new(
12381268
[(object_id_0, 5), (object_id_1, 10)],
12391269
mode,
1270+
false,
12401271
Some(0), // not part of this test
12411272
cap_factor,
12421273
None,
@@ -1254,6 +1285,7 @@ mod object_cost_tests {
12541285
SharedObjectCongestionTracker::new(
12551286
[(object_id_0, 5), (object_id_1, 10)],
12561287
mode,
1288+
false,
12571289
Some(0), // not part of this test
12581290
cap_factor,
12591291
None,
@@ -1279,6 +1311,7 @@ mod object_cost_tests {
12791311
SharedObjectCongestionTracker::new(
12801312
[(object_id_0, expected_object_0_cost), (object_id_1, 10)],
12811313
mode,
1314+
false,
12821315
Some(0), // not part of this test
12831316
cap_factor,
12841317
None,
@@ -1318,6 +1351,7 @@ mod object_cost_tests {
13181351
(object_id_2, expected_object_cost)
13191352
],
13201353
mode,
1354+
false,
13211355
Some(0), // not part of this test
13221356
cap_factor,
13231357
None,
@@ -1359,6 +1393,7 @@ mod object_cost_tests {
13591393
(object_id_2, expected_object_cost)
13601394
],
13611395
mode,
1396+
false,
13621397
Some(0), // not part of this test
13631398
cap_factor,
13641399
None,
@@ -1382,7 +1417,7 @@ mod object_cost_tests {
13821417
target_utilization: 100,
13831418
// set a burst limit to verify that it does not affect debt calculation.
13841419
allowed_txn_cost_overage_burst_limit_us: 1_600 * 5,
1385-
max_txn_cost_overage_per_object_in_commit_us: 1_600 * 10,
1420+
randomness_scalar: 0,
13861421
max_estimate_us: u64::MAX,
13871422
}),
13881423
)]
@@ -1415,6 +1450,7 @@ mod object_cost_tests {
14151450
SharedObjectCongestionTracker::new(
14161451
[(shared_obj_0, 80), (shared_obj_1, 80)],
14171452
mode,
1453+
false,
14181454
Some(max_accumulated_txn_cost_per_object_in_commit),
14191455
None,
14201456
None,
@@ -1428,6 +1464,7 @@ mod object_cost_tests {
14281464
SharedObjectCongestionTracker::new(
14291465
[(shared_obj_0, 80), (shared_obj_1, 80)],
14301466
mode,
1467+
false,
14311468
Some(max_accumulated_txn_cost_per_object_in_commit),
14321469
Some(45),
14331470
None,
@@ -1441,6 +1478,7 @@ mod object_cost_tests {
14411478
SharedObjectCongestionTracker::new(
14421479
[(shared_obj_0, 2), (shared_obj_1, 2)],
14431480
mode,
1481+
false,
14441482
Some(max_accumulated_txn_cost_per_object_in_commit),
14451483
None,
14461484
None,
@@ -1454,6 +1492,7 @@ mod object_cost_tests {
14541492
SharedObjectCongestionTracker::new(
14551493
[(shared_obj_0, 500), (shared_obj_1, 500)],
14561494
mode,
1495+
false,
14571496
Some(max_accumulated_txn_cost_per_object_in_commit),
14581497
None,
14591498
None,
@@ -1503,6 +1542,7 @@ mod object_cost_tests {
15031542
let shared_object_congestion_tracker = SharedObjectCongestionTracker::new(
15041543
[(object_id_0, 5), (object_id_1, 10), (object_id_2, 100)],
15051544
PerObjectCongestionControlMode::TotalGasBudget,
1545+
false,
15061546
Some(100),
15071547
None,
15081548
None,
@@ -1529,6 +1569,7 @@ mod object_cost_tests {
15291569
let mut shared_object_congestion_tracker = SharedObjectCongestionTracker::new(
15301570
[(object_id_0, 5), (object_id_1, 10), (object_id_2, 100)],
15311571
PerObjectCongestionControlMode::TotalGasBudgetWithCap,
1572+
false,
15321573
Some(100),
15331574
Some(1000),
15341575
Some(2),

crates/sui-core/src/unit_tests/congestion_control_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ async fn test_congestion_control_execution_cancellation() {
295295
Some(SharedObjectCongestionTracker::new(
296296
[(shared_object_1.0, 10)],
297297
PerObjectCongestionControlMode::TotalGasBudget,
298+
false,
298299
Some(
299300
test_setup
300301
.protocol_config

crates/sui-protocol-config/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -674,16 +674,17 @@ impl ConsensusTransactionOrdering {
674674

675675
#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
676676
pub struct ExecutionTimeEstimateParams {
677-
// targeted per-object utilization as an integer percentage (1-100)
677+
// Targeted per-object utilization as an integer percentage (1-100).
678678
pub target_utilization: u64,
679679
// Schedule up to this much extra work (in microseconds) per object,
680-
// but don't allow the running debt to exceed this limit (unless we
681-
// are scheduling a single very large transaction, in which case the
682-
// absolute limit will be used).
680+
// but don't allow more than a single transaction to exceed this
681+
// burst limit.
683682
pub allowed_txn_cost_overage_burst_limit_us: u64,
684-
// absolute limit of how much estimated work to schedule in a commit,
685-
// even if it all comes from a single transaction
686-
pub max_txn_cost_overage_per_object_in_commit_us: u64,
683+
684+
// For separate budget for randomness-using tx, the above limits are
685+
// used with this integer-percentage scaling factor (1-100).
686+
pub randomness_scalar: u64,
687+
687688
// Absolute maximum allowed transaction duration estimate (in microseconds).
688689
pub max_estimate_us: u64,
689690
}

0 commit comments

Comments
 (0)