@@ -18,6 +18,7 @@ use tracing::trace;
18
18
#[ derive( PartialEq , Eq , Clone , Debug ) ]
19
19
struct Params {
20
20
mode : PerObjectCongestionControlMode ,
21
+ for_randomness : bool ,
21
22
max_accumulated_txn_cost_per_object_in_commit : u64 ,
22
23
gas_budget_based_txn_cost_cap_factor : Option < u64 > ,
23
24
gas_budget_based_txn_cost_absolute_cap : Option < u64 > ,
@@ -33,10 +34,17 @@ impl Params {
33
34
PerObjectCongestionControlMode :: ExecutionTimeEstimate ( params) => {
34
35
let estimated_commit_period = commit_info. estimated_commit_period ( ) ;
35
36
let commit_period_micros = estimated_commit_period. as_micros ( ) as u64 ;
36
- commit_period_micros
37
+ let mut budget = commit_period_micros
37
38
. checked_mul ( params. target_utilization )
38
39
. 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
40
48
}
41
49
_ => self . max_accumulated_txn_cost_per_object_in_commit ,
42
50
}
@@ -47,7 +55,14 @@ impl Params {
47
55
pub fn max_burst ( & self ) -> u64 {
48
56
match self . mode {
49
57
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
51
66
}
52
67
_ => self . allowed_txn_cost_overage_burst_per_object_in_commit ,
53
68
}
@@ -58,9 +73,7 @@ impl Params {
58
73
// unschedulable regardless of congestion.
59
74
pub fn max_overage ( & self ) -> u64 {
60
75
match self . mode {
61
- PerObjectCongestionControlMode :: ExecutionTimeEstimate ( params) => {
62
- params. max_txn_cost_overage_per_object_in_commit_us
63
- }
76
+ PerObjectCongestionControlMode :: ExecutionTimeEstimate ( _) => u64:: MAX ,
64
77
_ => self . max_txn_cost_overage_per_object_in_commit ,
65
78
}
66
79
}
@@ -110,6 +123,7 @@ impl SharedObjectCongestionTracker {
110
123
pub fn new (
111
124
initial_object_debts : impl IntoIterator < Item = ( ObjectID , u64 ) > ,
112
125
mode : PerObjectCongestionControlMode ,
126
+ for_randomness : bool ,
113
127
max_accumulated_txn_cost_per_object_in_commit : Option < u64 > ,
114
128
gas_budget_based_txn_cost_cap_factor : Option < u64 > ,
115
129
gas_budget_based_txn_cost_absolute_cap_commit_count : Option < u64 > ,
@@ -148,6 +162,7 @@ impl SharedObjectCongestionTracker {
148
162
object_execution_cost,
149
163
params : Params {
150
164
mode,
165
+ for_randomness,
151
166
max_accumulated_txn_cost_per_object_in_commit,
152
167
gas_budget_based_txn_cost_cap_factor,
153
168
gas_budget_based_txn_cost_absolute_cap,
@@ -167,6 +182,7 @@ impl SharedObjectCongestionTracker {
167
182
Ok ( Self :: new (
168
183
initial_object_debts,
169
184
protocol_config. per_object_congestion_control_mode ( ) ,
185
+ for_randomness,
170
186
if for_randomness {
171
187
protocol_config
172
188
. max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit_as_option ( )
@@ -417,6 +433,7 @@ mod object_cost_tests {
417
433
let shared_object_congestion_tracker = SharedObjectCongestionTracker :: new (
418
434
[ ( object_id_0, 5 ) , ( object_id_1, 10 ) ] ,
419
435
PerObjectCongestionControlMode :: TotalGasBudget ,
436
+ false ,
420
437
Some ( 0 ) , // not part of this test
421
438
None ,
422
439
None ,
@@ -545,7 +562,7 @@ mod object_cost_tests {
545
562
PerObjectCongestionControlMode :: ExecutionTimeEstimate ( ExecutionTimeEstimateParams {
546
563
target_utilization: 100 ,
547
564
allowed_txn_cost_overage_burst_limit_us: 0 ,
548
- max_txn_cost_overage_per_object_in_commit_us : 0 ,
565
+ randomness_scalar : 0 ,
549
566
max_estimate_us: u64 :: MAX ,
550
567
} ) ,
551
568
) ]
@@ -578,6 +595,7 @@ mod object_cost_tests {
578
595
SharedObjectCongestionTracker :: new (
579
596
[ ( shared_obj_0, 10 ) , ( shared_obj_1, 1 ) ] ,
580
597
mode,
598
+ false ,
581
599
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
582
600
None ,
583
601
None ,
@@ -593,6 +611,7 @@ mod object_cost_tests {
593
611
SharedObjectCongestionTracker :: new (
594
612
[ ( shared_obj_0, 2 ) , ( shared_obj_1, 1 ) ] ,
595
613
mode,
614
+ false ,
596
615
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
597
616
None ,
598
617
None ,
@@ -608,6 +627,7 @@ mod object_cost_tests {
608
627
SharedObjectCongestionTracker :: new (
609
628
[ ( shared_obj_0, 10 ) , ( shared_obj_1, 1 ) ] ,
610
629
mode,
630
+ false ,
611
631
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
612
632
Some ( 45 ) , // Make the cap just less than the gas budget, there are 1 objects in tx.
613
633
None ,
@@ -623,6 +643,7 @@ mod object_cost_tests {
623
643
SharedObjectCongestionTracker :: new (
624
644
[ ( shared_obj_0, 750 ) , ( shared_obj_1, 0 ) ] ,
625
645
mode,
646
+ false ,
626
647
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
627
648
None ,
628
649
None ,
@@ -737,8 +758,8 @@ mod object_cost_tests {
737
758
PerObjectCongestionControlMode :: ExecutionTimeEstimate ( ExecutionTimeEstimateParams {
738
759
target_utilization: 0 , // Make should_defer_due_to_object_congestion always defer transactions.
739
760
allowed_txn_cost_overage_burst_limit_us: 0 ,
740
- max_txn_cost_overage_per_object_in_commit_us: 0 ,
741
761
max_estimate_us: u64 :: MAX ,
762
+ randomness_scalar: 0 ,
742
763
} ) ,
743
764
) ]
744
765
mode : PerObjectCongestionControlMode ,
@@ -751,6 +772,7 @@ mod object_cost_tests {
751
772
let shared_object_congestion_tracker = SharedObjectCongestionTracker :: new (
752
773
[ ] ,
753
774
mode,
775
+ false ,
754
776
Some ( 0 ) , // Make should_defer_due_to_object_congestion always defer transactions.
755
777
Some ( 2 ) ,
756
778
None ,
@@ -864,7 +886,7 @@ mod object_cost_tests {
864
886
PerObjectCongestionControlMode :: ExecutionTimeEstimate ( ExecutionTimeEstimateParams {
865
887
target_utilization: 16 ,
866
888
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 ,
868
890
max_estimate_us: u64 :: MAX ,
869
891
} ) ,
870
892
) ]
@@ -900,6 +922,7 @@ mod object_cost_tests {
900
922
SharedObjectCongestionTracker :: new (
901
923
[ ( shared_obj_0, 102 ) , ( shared_obj_1, 90 ) ] ,
902
924
mode,
925
+ false ,
903
926
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
904
927
None ,
905
928
None ,
@@ -915,6 +938,7 @@ mod object_cost_tests {
915
938
SharedObjectCongestionTracker :: new (
916
939
[ ( shared_obj_0, 3 ) , ( shared_obj_1, 2 ) ] ,
917
940
mode,
941
+ false ,
918
942
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
919
943
None ,
920
944
None ,
@@ -930,6 +954,7 @@ mod object_cost_tests {
930
954
SharedObjectCongestionTracker :: new (
931
955
[ ( shared_obj_0, 100 ) , ( shared_obj_1, 90 ) ] ,
932
956
mode,
957
+ false ,
933
958
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
934
959
Some ( 45 ) , // Make the cap just less than the gas budget, there are 1 objects in tx.
935
960
None ,
@@ -945,6 +970,7 @@ mod object_cost_tests {
945
970
SharedObjectCongestionTracker :: new (
946
971
[ ( shared_obj_0, 1_700_000 ) , ( shared_obj_1, 300_000 ) ] ,
947
972
mode,
973
+ false ,
948
974
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
949
975
None ,
950
976
None ,
@@ -1030,7 +1056,7 @@ mod object_cost_tests {
1030
1056
PerObjectCongestionControlMode :: ExecutionTimeEstimate ( ExecutionTimeEstimateParams {
1031
1057
target_utilization: 16 ,
1032
1058
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 ,
1034
1060
max_estimate_us: u64 :: MAX ,
1035
1061
} ) ,
1036
1062
) ]
@@ -1077,6 +1103,7 @@ mod object_cost_tests {
1077
1103
SharedObjectCongestionTracker :: new (
1078
1104
[ ( shared_obj_0, 301 ) , ( shared_obj_1, 199 ) ] ,
1079
1105
mode,
1106
+ false ,
1080
1107
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1081
1108
None ,
1082
1109
None ,
@@ -1095,6 +1122,7 @@ mod object_cost_tests {
1095
1122
SharedObjectCongestionTracker :: new (
1096
1123
[ ( shared_obj_0, 5 ) , ( shared_obj_1, 4 ) ] ,
1097
1124
mode,
1125
+ false ,
1098
1126
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1099
1127
None ,
1100
1128
None ,
@@ -1113,6 +1141,7 @@ mod object_cost_tests {
1113
1141
SharedObjectCongestionTracker :: new (
1114
1142
[ ( shared_obj_0, 301 ) , ( shared_obj_1, 250 ) ] ,
1115
1143
mode,
1144
+ false ,
1116
1145
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1117
1146
Some ( 45 ) , // Make the cap just less than the gas budget, there are 1 objects in tx.
1118
1147
None ,
@@ -1131,6 +1160,7 @@ mod object_cost_tests {
1131
1160
SharedObjectCongestionTracker :: new (
1132
1161
[ ( shared_obj_0, 4_000_000 ) , ( shared_obj_1, 2_000_000 ) ] ,
1133
1162
mode,
1163
+ false ,
1134
1164
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1135
1165
None ,
1136
1166
None ,
@@ -1218,7 +1248,7 @@ mod object_cost_tests {
1218
1248
// all params ignored in this test
1219
1249
target_utilization: 0 ,
1220
1250
allowed_txn_cost_overage_burst_limit_us: 0 ,
1221
- max_txn_cost_overage_per_object_in_commit_us : 0 ,
1251
+ randomness_scalar : 0 ,
1222
1252
max_estimate_us: u64 :: MAX ,
1223
1253
} ) ,
1224
1254
) ]
@@ -1237,6 +1267,7 @@ mod object_cost_tests {
1237
1267
let mut shared_object_congestion_tracker = SharedObjectCongestionTracker :: new (
1238
1268
[ ( object_id_0, 5 ) , ( object_id_1, 10 ) ] ,
1239
1269
mode,
1270
+ false ,
1240
1271
Some ( 0 ) , // not part of this test
1241
1272
cap_factor,
1242
1273
None ,
@@ -1254,6 +1285,7 @@ mod object_cost_tests {
1254
1285
SharedObjectCongestionTracker :: new(
1255
1286
[ ( object_id_0, 5 ) , ( object_id_1, 10 ) ] ,
1256
1287
mode,
1288
+ false ,
1257
1289
Some ( 0 ) , // not part of this test
1258
1290
cap_factor,
1259
1291
None ,
@@ -1279,6 +1311,7 @@ mod object_cost_tests {
1279
1311
SharedObjectCongestionTracker :: new(
1280
1312
[ ( object_id_0, expected_object_0_cost) , ( object_id_1, 10 ) ] ,
1281
1313
mode,
1314
+ false ,
1282
1315
Some ( 0 ) , // not part of this test
1283
1316
cap_factor,
1284
1317
None ,
@@ -1318,6 +1351,7 @@ mod object_cost_tests {
1318
1351
( object_id_2, expected_object_cost)
1319
1352
] ,
1320
1353
mode,
1354
+ false ,
1321
1355
Some ( 0 ) , // not part of this test
1322
1356
cap_factor,
1323
1357
None ,
@@ -1359,6 +1393,7 @@ mod object_cost_tests {
1359
1393
( object_id_2, expected_object_cost)
1360
1394
] ,
1361
1395
mode,
1396
+ false ,
1362
1397
Some ( 0 ) , // not part of this test
1363
1398
cap_factor,
1364
1399
None ,
@@ -1382,7 +1417,7 @@ mod object_cost_tests {
1382
1417
target_utilization: 100 ,
1383
1418
// set a burst limit to verify that it does not affect debt calculation.
1384
1419
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 ,
1386
1421
max_estimate_us: u64 :: MAX ,
1387
1422
} ) ,
1388
1423
) ]
@@ -1415,6 +1450,7 @@ mod object_cost_tests {
1415
1450
SharedObjectCongestionTracker :: new (
1416
1451
[ ( shared_obj_0, 80 ) , ( shared_obj_1, 80 ) ] ,
1417
1452
mode,
1453
+ false ,
1418
1454
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1419
1455
None ,
1420
1456
None ,
@@ -1428,6 +1464,7 @@ mod object_cost_tests {
1428
1464
SharedObjectCongestionTracker :: new (
1429
1465
[ ( shared_obj_0, 80 ) , ( shared_obj_1, 80 ) ] ,
1430
1466
mode,
1467
+ false ,
1431
1468
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1432
1469
Some ( 45 ) ,
1433
1470
None ,
@@ -1441,6 +1478,7 @@ mod object_cost_tests {
1441
1478
SharedObjectCongestionTracker :: new (
1442
1479
[ ( shared_obj_0, 2 ) , ( shared_obj_1, 2 ) ] ,
1443
1480
mode,
1481
+ false ,
1444
1482
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1445
1483
None ,
1446
1484
None ,
@@ -1454,6 +1492,7 @@ mod object_cost_tests {
1454
1492
SharedObjectCongestionTracker :: new (
1455
1493
[ ( shared_obj_0, 500 ) , ( shared_obj_1, 500 ) ] ,
1456
1494
mode,
1495
+ false ,
1457
1496
Some ( max_accumulated_txn_cost_per_object_in_commit) ,
1458
1497
None ,
1459
1498
None ,
@@ -1503,6 +1542,7 @@ mod object_cost_tests {
1503
1542
let shared_object_congestion_tracker = SharedObjectCongestionTracker :: new (
1504
1543
[ ( object_id_0, 5 ) , ( object_id_1, 10 ) , ( object_id_2, 100 ) ] ,
1505
1544
PerObjectCongestionControlMode :: TotalGasBudget ,
1545
+ false ,
1506
1546
Some ( 100 ) ,
1507
1547
None ,
1508
1548
None ,
@@ -1529,6 +1569,7 @@ mod object_cost_tests {
1529
1569
let mut shared_object_congestion_tracker = SharedObjectCongestionTracker :: new (
1530
1570
[ ( object_id_0, 5 ) , ( object_id_1, 10 ) , ( object_id_2, 100 ) ] ,
1531
1571
PerObjectCongestionControlMode :: TotalGasBudgetWithCap ,
1572
+ false ,
1532
1573
Some ( 100 ) ,
1533
1574
Some ( 1000 ) ,
1534
1575
Some ( 2 ) ,
0 commit comments