Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit a4a6602

Browse files
authored
Introduce InstalledSchedulerPool trait (#33934)
* Introduce InstalledSchedulerPool * Use type alias * Remove log_prefix for now... * Simplify return_to_pool() * Simplify InstalledScheduler's context methods * Reorder trait methods semantically * Simplify Arc<Bank> handling
1 parent 1c00d5d commit a4a6602

File tree

7 files changed

+242
-9
lines changed

7 files changed

+242
-9
lines changed

Cargo.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ edition = "2021"
132132

133133
[workspace.dependencies]
134134
Inflector = "0.11.4"
135+
aquamarine = "0.3.2"
135136
aes-gcm-siv = "0.10.3"
136137
ahash = "0.8.6"
137138
anyhow = "1.0.75"

ledger/src/blockstore_processor.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ pub mod tests {
19451945
genesis_utils::{
19461946
self, create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
19471947
},
1948-
installed_scheduler_pool::{MockInstalledScheduler, WaitReason},
1948+
installed_scheduler_pool::{MockInstalledScheduler, SchedulingContext, WaitReason},
19491949
},
19501950
solana_sdk::{
19511951
account::{AccountSharedData, WritableAccount},
@@ -4527,11 +4527,17 @@ pub mod tests {
45274527
..
45284528
} = create_genesis_config_with_leader(500, &dummy_leader_pubkey, 100);
45294529
let bank = Arc::new(Bank::new_for_tests(&genesis_config));
4530+
let context = SchedulingContext::new(bank.clone());
45304531

45314532
let txs = create_test_transactions(&mint_keypair, &genesis_config.hash());
45324533

45334534
let mut mocked_scheduler = MockInstalledScheduler::new();
45344535
let mut seq = mockall::Sequence::new();
4536+
mocked_scheduler
4537+
.expect_context()
4538+
.times(1)
4539+
.in_sequence(&mut seq)
4540+
.return_const(context);
45354541
mocked_scheduler
45364542
.expect_schedule_execution()
45374543
.times(txs.len())
@@ -4542,6 +4548,11 @@ pub mod tests {
45424548
.times(1)
45434549
.in_sequence(&mut seq)
45444550
.returning(|_| None);
4551+
mocked_scheduler
4552+
.expect_return_to_pool()
4553+
.times(1)
4554+
.in_sequence(&mut seq)
4555+
.returning(|| ());
45454556
let bank = BankWithScheduler::new(bank, Some(Box::new(mocked_scheduler)));
45464557

45474558
let batch = bank.prepare_sanitized_batch(&txs);

programs/sbf/Cargo.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = { workspace = true }
1010
edition = { workspace = true }
1111

1212
[dependencies]
13+
aquamarine = { workspace = true }
1314
arrayref = { workspace = true }
1415
base64 = { workspace = true }
1516
bincode = { workspace = true }

runtime/src/bank_forks.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use {
44
crate::{
55
accounts_background_service::{AbsRequestSender, SnapshotRequest, SnapshotRequestKind},
66
bank::{epoch_accounts_hash_utils, Bank, SquashTiming},
7-
installed_scheduler_pool::BankWithScheduler,
7+
installed_scheduler_pool::{
8+
BankWithScheduler, InstalledSchedulerPoolArc, SchedulingContext,
9+
},
810
snapshot_config::SnapshotConfig,
911
},
1012
log::*,
@@ -72,6 +74,7 @@ pub struct BankForks {
7274
last_accounts_hash_slot: Slot,
7375
in_vote_only_mode: Arc<AtomicBool>,
7476
highest_slot_at_startup: Slot,
77+
scheduler_pool: Option<InstalledSchedulerPoolArc>,
7578
}
7679

7780
impl Index<u64> for BankForks {
@@ -203,6 +206,7 @@ impl BankForks {
203206
last_accounts_hash_slot: root,
204207
in_vote_only_mode: Arc::new(AtomicBool::new(false)),
205208
highest_slot_at_startup: 0,
209+
scheduler_pool: None,
206210
}));
207211

208212
for bank in bank_forks.read().unwrap().banks.values() {
@@ -215,11 +219,26 @@ impl BankForks {
215219
bank_forks
216220
}
217221

222+
pub fn install_scheduler_pool(&mut self, pool: InstalledSchedulerPoolArc) {
223+
info!("Installed new scheduler_pool into bank_forks: {:?}", pool);
224+
assert!(
225+
self.scheduler_pool.replace(pool).is_none(),
226+
"Reinstalling scheduler pool isn't supported"
227+
);
228+
}
229+
218230
pub fn insert(&mut self, mut bank: Bank) -> BankWithScheduler {
219231
bank.check_program_modification_slot =
220232
self.root.load(Ordering::Relaxed) < self.highest_slot_at_startup;
221233

222-
let bank = BankWithScheduler::new_without_scheduler(Arc::new(bank));
234+
let bank = Arc::new(bank);
235+
let bank = if let Some(scheduler_pool) = &self.scheduler_pool {
236+
let context = SchedulingContext::new(bank.clone());
237+
let scheduler = scheduler_pool.take_scheduler(context);
238+
BankWithScheduler::new(bank, Some(scheduler))
239+
} else {
240+
BankWithScheduler::new_without_scheduler(bank)
241+
};
223242
let prev = self.banks.insert(bank.slot(), bank.clone_with_scheduler());
224243
assert!(prev.is_none());
225244
let slot = bank.slot();

0 commit comments

Comments
 (0)