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

Commit

Permalink
Adjust to use the installed prefix consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Apr 20, 2023
1 parent 3597dfb commit a8d66fa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
10 changes: 5 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use {
epoch_accounts_hash::{self, EpochAccountsHash},
epoch_stakes::{EpochStakes, NodeVoteAccounts},
inline_spl_associated_token_account, inline_spl_token,
installed_scheduler_pool::InstalledSchedulerBox,
installed_scheduler_pool::InstalledSchedulerBoxInBank,
message_processor::MessageProcessor,
rent_collector::{CollectedInfo, RentCollector},
rent_debits::RentDebits,
Expand Down Expand Up @@ -1101,7 +1101,7 @@ pub struct Bank {

/// true when the bank's freezing or destruction has completed
bank_freeze_or_destruction_incremented: AtomicBool,
pub(crate) scheduler: RwLock<InstalledSchedulerBox>,
pub(crate) scheduler: RwLock<InstalledSchedulerBoxInBank>,
}

struct VoteWithStakeDelegations {
Expand Down Expand Up @@ -1323,7 +1323,7 @@ impl Bank {
accounts_data_size_delta_off_chain: AtomicI64::new(0),
fee_structure: FeeStructure::default(),
loaded_programs_cache: Arc::<RwLock<LoadedPrograms>>::default(),
scheduler: RwLock::<InstalledSchedulerBox>::default(),
scheduler: RwLock::<InstalledSchedulerBoxInBank>::default(),
};

bank.bank_created();
Expand Down Expand Up @@ -1622,7 +1622,7 @@ impl Bank {
accounts_data_size_delta_off_chain: AtomicI64::new(0),
fee_structure: parent.fee_structure.clone(),
loaded_programs_cache: parent.loaded_programs_cache.clone(),
scheduler: RwLock::<InstalledSchedulerBox>::default(),
scheduler: RwLock::<InstalledSchedulerBoxInBank>::default(),
};

let (_, ancestors_time_us) = measure_us!({
Expand Down Expand Up @@ -1949,7 +1949,7 @@ impl Bank {
accounts_data_size_delta_off_chain: AtomicI64::new(0),
fee_structure: FeeStructure::default(),
loaded_programs_cache: Arc::<RwLock<LoadedPrograms>>::default(),
scheduler: RwLock::<InstalledSchedulerBox>::default(),
scheduler: RwLock::<InstalledSchedulerBoxInBank>::default(),
};
bank.bank_created();

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank_forks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct BankForks {
pub accounts_hash_interval_slots: Slot,
last_accounts_hash_slot: Slot,
in_vote_only_mode: Arc<AtomicBool>,
pub(crate) scheduler_pool: InstalledSchedulerPoolArc,
pub(crate) scheduler_pool: Option<InstalledSchedulerPoolArc>,
}

impl Index<u64> for BankForks {
Expand Down Expand Up @@ -190,7 +190,7 @@ impl BankForks {
accounts_hash_interval_slots: std::u64::MAX,
last_accounts_hash_slot: root,
in_vote_only_mode: Arc::new(AtomicBool::new(false)),
scheduler_pool: InstalledSchedulerPoolArc::default(),
scheduler_pool: None,
}
}

Expand Down
27 changes: 14 additions & 13 deletions runtime/src/installed_scheduler_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use {
// Send + Sync is needed to be a field of BankForks
#[cfg_attr(any(test, feature = "test-in-workspace"), automock)]
pub trait InstalledSchedulerPool: Send + Sync + Debug {
fn take_from_pool(&self, context: SchedulingContext) -> SchedulerBox;
fn return_to_pool(&self, scheduler: SchedulerBox);
fn take_from_pool(&self, context: SchedulingContext) -> InstalledSchedulerBox;
fn return_to_pool(&self, scheduler: InstalledSchedulerBox);
}

#[cfg_attr(any(test, feature = "test-in-workspace"), automock)]
Expand All @@ -49,7 +49,7 @@ pub trait InstalledSchedulerPool: Send + Sync + Debug {
// Send + Sync is needed to be a field of Bank
pub trait InstalledScheduler: Send + Sync + Debug {
fn scheduler_id(&self) -> SchedulerId;
fn scheduler_pool(&self) -> SchedulerPoolArc;
fn scheduler_pool(&self) -> InstalledSchedulerPoolArc;

// Calling this is illegal as soon as schedule_termiantion is called on &self.
fn schedule_execution(&self, sanitized_tx: &SanitizedTransaction, index: usize);
Expand All @@ -70,8 +70,7 @@ pub trait InstalledScheduler: Send + Sync + Debug {
fn replace_scheduler_context(&mut self, context: SchedulingContext);
}

pub type SchedulerPoolArc = Arc<dyn InstalledSchedulerPool>;
pub(crate) type InstalledSchedulerPoolArc = Option<SchedulerPoolArc>;
pub type InstalledSchedulerPoolArc = Arc<dyn InstalledSchedulerPool>;

pub type SchedulerId = u64;

Expand All @@ -88,16 +87,16 @@ pub enum WaitReason {
ReinitializedForRecentBlockhash,
}

pub type SchedulerBox = Box<dyn InstalledScheduler>;
pub type InstalledSchedulerBox = Box<dyn InstalledScheduler>;
// somewhat arbitrary new type just to pacify Bank's frozen_abi...
#[derive(Debug, Default)]
pub(crate) struct InstalledSchedulerBox(Option<SchedulerBox>);
pub(crate) struct InstalledSchedulerBoxInBank(Option<InstalledSchedulerBox>);

#[cfg(RUSTC_WITH_SPECIALIZATION)]
use solana_frozen_abi::abi_example::AbiExample;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
impl AbiExample for InstalledSchedulerBox {
impl AbiExample for InstalledSchedulerBoxInBank {
fn example() -> Self {
Self(None)
}
Expand Down Expand Up @@ -182,7 +181,7 @@ impl Deref for BankWithScheduler {
}

impl BankForks {
pub fn install_scheduler_pool(&mut self, pool: SchedulerPoolArc) {
pub fn install_scheduler_pool(&mut self, pool: InstalledSchedulerPoolArc) {
info!("Installed new scheduler_pool into bank_forks: {:?}", pool);
assert!(self.scheduler_pool.replace(pool).is_none());
}
Expand All @@ -196,7 +195,7 @@ impl BankForks {
}

impl Bank {
pub fn install_scheduler(&self, scheduler: SchedulerBox) {
pub fn install_scheduler(&self, scheduler: InstalledSchedulerBox) {
let mut scheduler_guard = self.scheduler.write().expect("not poisoned");
assert!(scheduler_guard.0.replace(scheduler).is_none());
}
Expand Down Expand Up @@ -318,7 +317,7 @@ mod tests {
solana_sdk::system_transaction,
};

fn setup_mocked_scheduler_pool(seq: &mut Sequence) -> SchedulerPoolArc {
fn setup_mocked_scheduler_pool(seq: &mut Sequence) -> InstalledSchedulerPoolArc {
let mut mock = MockInstalledSchedulerPool::new();
mock.expect_return_to_pool()
.times(1)
Expand All @@ -330,7 +329,7 @@ mod tests {
fn setup_mocked_scheduler_with_extra(
wait_reasons: impl Iterator<Item = WaitReason>,
f: Option<impl Fn(&mut MockInstalledScheduler)>,
) -> SchedulerBox {
) -> InstalledSchedulerBox {
let mut mock = MockInstalledScheduler::new();
let mut seq = Sequence::new();

Expand All @@ -353,7 +352,9 @@ mod tests {
Box::new(mock)
}

fn setup_mocked_scheduler(wait_reasons: impl Iterator<Item = WaitReason>) -> SchedulerBox {
fn setup_mocked_scheduler(
wait_reasons: impl Iterator<Item = WaitReason>,
) -> InstalledSchedulerBox {
setup_mocked_scheduler_with_extra(
wait_reasons,
None::<fn(&mut MockInstalledScheduler) -> ()>,
Expand Down
25 changes: 13 additions & 12 deletions scheduler-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use {
solana_program_runtime::timings::ExecuteTimings,
solana_runtime::{
installed_scheduler_pool::{
InstalledScheduler, InstalledSchedulerPool, ResultWithTimings, SchedulerBox,
SchedulerId, SchedulerPoolArc, SchedulingContext, WaitReason,
InstalledScheduler, InstalledSchedulerBox, InstalledSchedulerPool,
InstalledSchedulerPoolArc, ResultWithTimings, SchedulerId, SchedulingContext,
WaitReason,
},
prioritization_fee_cache::PrioritizationFeeCache,
vote_sender_types::ReplayVoteSender,
Expand All @@ -31,7 +32,7 @@ use {
// types aren't available there...
#[derive(Debug)]
pub struct SchedulerPool {
schedulers: Mutex<Vec<SchedulerBox>>,
schedulers: Mutex<Vec<InstalledSchedulerBox>>,
log_messages_bytes_limit: Option<usize>,
transaction_status_sender: Option<TransactionStatusSender>,
replay_vote_sender: Option<ReplayVoteSender>,
Expand All @@ -45,9 +46,9 @@ impl SchedulerPool {
transaction_status_sender: Option<TransactionStatusSender>,
replay_vote_sender: Option<ReplayVoteSender>,
prioritization_fee_cache: Arc<PrioritizationFeeCache>,
) -> SchedulerPoolArc {
) -> InstalledSchedulerPoolArc {
Arc::new_cyclic(|weak_self| Self {
schedulers: Mutex::<Vec<SchedulerBox>>::default(),
schedulers: Mutex::<Vec<InstalledSchedulerBox>>::default(),
log_messages_bytes_limit,
transaction_status_sender,
replay_vote_sender,
Expand All @@ -64,7 +65,7 @@ impl SchedulerPool {
}

impl InstalledSchedulerPool for SchedulerPool {
fn take_from_pool(&self, context: SchedulingContext) -> SchedulerBox {
fn take_from_pool(&self, context: SchedulingContext) -> InstalledSchedulerBox {
assert!(!context.bank().with_scheduler());

let mut schedulers = self.schedulers.lock().expect("not poisoned");
Expand All @@ -75,11 +76,11 @@ impl InstalledSchedulerPool for SchedulerPool {
scheduler.replace_scheduler_context(context);
scheduler
} else {
Box::new(Scheduler::spawn(self.self_arc(), context))
Box::new(PooledScheduler::spawn(self.self_arc(), context))
}
}

fn return_to_pool(&self, scheduler: SchedulerBox) {
fn return_to_pool(&self, scheduler: InstalledSchedulerBox) {
assert!(scheduler.scheduling_context().is_none());

self.schedulers
Expand All @@ -93,14 +94,14 @@ impl InstalledSchedulerPool for SchedulerPool {
// this will be replaced with more proper implementation...
// not usable at all, especially for mainnet-beta
#[derive(Debug)]
struct Scheduler {
struct PooledScheduler {
id: SchedulerId,
pool: Arc<SchedulerPool>,
context: Option<SchedulingContext>,
result_with_timings: Mutex<Option<ResultWithTimings>>,
}

impl Scheduler {
impl PooledScheduler {
fn spawn(pool: Arc<SchedulerPool>, initial_context: SchedulingContext) -> Self {
Self {
id: thread_rng().gen::<SchedulerId>(),
Expand All @@ -110,12 +111,12 @@ impl Scheduler {
}
}
}
impl InstalledScheduler for Scheduler {
impl InstalledScheduler for PooledScheduler {
fn scheduler_id(&self) -> SchedulerId {
self.id
}

fn scheduler_pool(&self) -> SchedulerPoolArc {
fn scheduler_pool(&self) -> InstalledSchedulerPoolArc {
self.pool.clone()
}

Expand Down

0 comments on commit a8d66fa

Please sign in to comment.