Skip to content

Commit e8f7169

Browse files
committed
randomize tx limits in test per epoch
1 parent b7de19a commit e8f7169

File tree

5 files changed

+40
-13
lines changed

5 files changed

+40
-13
lines changed

crates/mysten-common/src/random.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
// Copyright (c) Mysten Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use rand::SeedableRng;
5+
use rand::rngs::StdRng;
6+
47
use crate::in_antithesis;
58

9+
pub fn seeded_rng(seed: &[u8; 32]) -> StdRng {
10+
StdRng::from_seed(*seed)
11+
}
12+
613
/// Get a random number generator.
714
///
815
/// If we are running in antithesis mode, use the antithesis RNG.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,9 @@ impl AuthorityPerEpochStore {
11111111
chain_from_id, chain.1
11121112
);
11131113

1114-
let protocol_config = ProtocolConfig::get_for_version(protocol_version, chain.1);
1114+
let mut protocol_config = ProtocolConfig::get_for_version(protocol_version, chain.1);
1115+
protocol_config
1116+
.apply_seeded_test_overrides(epoch_start_configuration.epoch_digest().inner());
11151117

11161118
let execution_component = ExecutionComponents::new(
11171119
&protocol_config,

crates/sui-core/src/consensus_handler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ impl CheckpointQueue {
644644
let next_tx_count = queued.roots.tx_roots.len();
645645

646646
if current_tx_count + next_tx_count > max_tx && !current_roots.is_empty() {
647+
info!(
648+
"Splitting checkpoint: current_tx_count={}, next_tx_count={}, max_tx={}",
649+
current_tx_count, next_tx_count, max_tx
650+
);
647651
assert_reachable!("checkpoint split due to transaction limit");
648652
let details = current_details.unwrap();
649653
pending_checkpoints.push(PendingCheckpointV2 {
@@ -1710,7 +1714,17 @@ impl<C: CheckpointServiceNotify + Send + Sync> ConsensusHandler<C> {
17101714
.collect()
17111715
};
17121716

1717+
let num_schedulables = schedulables.len();
17131718
let chunked_schedulables = build_chunks(schedulables, &mut checkpoint_queue);
1719+
if chunked_schedulables.len() > 1 {
1720+
info!(
1721+
"Splitting transactions into {} checkpoint chunks (num_schedulables={}, max_tx={})",
1722+
chunked_schedulables.len(),
1723+
num_schedulables,
1724+
max_transactions_per_checkpoint
1725+
);
1726+
assert_reachable!("checkpoint split due to transaction limit");
1727+
}
17141728
let chunked_randomness_schedulables = if should_write_random_checkpoint {
17151729
build_chunks(randomness_schedulables, &mut checkpoint_queue)
17161730
} else {

crates/sui-protocol-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fastcrypto = { workspace = true }
2222
move-core-types.workspace = true
2323
move-binary-format.workspace = true
2424
mysten-common.workspace = true
25+
rand.workspace = true
2526

2627
[dev-dependencies]
2728
insta.workspace = true

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,21 +4542,24 @@ impl ProtocolConfig {
45424542
}
45434543
}
45444544

4545-
// Simtest specific overrides.
4546-
if cfg!(msim) {
4547-
// Trigger checkpoint splitting more often.
4548-
// cfg.max_transactions_per_checkpoint = Some(10);
4549-
// FIXME: Re-introduce this once we resolve the checkpoint splitting issue
4550-
// in the quarantine output.
4551-
}
4545+
cfg
4546+
}
45524547

4553-
// Antithesis specific overrides.
4554-
#[cfg(not(msim))]
4555-
if mysten_common::in_antithesis() {
4556-
cfg.max_transactions_per_checkpoint = Some(100);
4548+
pub fn apply_seeded_test_overrides(&mut self, seed: &[u8; 32]) {
4549+
let should_apply = if cfg!(msim) {
4550+
true
4551+
} else {
4552+
mysten_common::in_antithesis()
4553+
};
4554+
if !should_apply {
4555+
return;
45574556
}
45584557

4559-
cfg
4558+
use rand::Rng;
4559+
let mut rng = mysten_common::random::seeded_rng(seed);
4560+
let max_txns = rng.gen_range(1..=100u64);
4561+
info!("seeded test override: max_transactions_per_checkpoint = {max_txns}");
4562+
self.max_transactions_per_checkpoint = Some(max_txns);
45604563
}
45614564

45624565
// Extract the bytecode verifier config from this protocol config.

0 commit comments

Comments
 (0)