Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup - program runtime #34318

Merged
merged 8 commits into from
Dec 6, 2023
2 changes: 1 addition & 1 deletion program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ impl<'a> InvokeContext<'a> {
pub fn get_syscall_context(&self) -> Result<&SyscallContext, InstructionError> {
self.syscall_context
.last()
.and_then(|syscall_context| syscall_context.as_ref())
.and_then(std::option::Option::as_ref)
.ok_or(InstructionError::CallDepth)
}

Expand Down
24 changes: 7 additions & 17 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub struct LoadedProgram {
pub maybe_expiration_slot: Option<Slot>,
/// How often this entry was used by a transaction
pub tx_usage_counter: AtomicU64,
/// How often this entry was used by a transaction
/// How often this entry was used by an instruction
pub ix_usage_counter: AtomicU64,
}

Expand Down Expand Up @@ -371,7 +371,7 @@ impl LoadedProgram {
effective_slot: self.effective_slot,
maybe_expiration_slot: self.maybe_expiration_slot,
tx_usage_counter: AtomicU64::new(self.tx_usage_counter.load(Ordering::Relaxed)),
ix_usage_counter: AtomicU64::new(self.tx_usage_counter.load(Ordering::Relaxed)),
ix_usage_counter: AtomicU64::new(self.ix_usage_counter.load(Ordering::Relaxed)),
})
}

Expand Down Expand Up @@ -648,14 +648,9 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
}

pub fn prune_by_deployment_slot(&mut self, slot: Slot) {
self.entries.retain(|_key, second_level| {
*second_level = second_level
.iter()
.filter(|entry| entry.deployment_slot != slot)
.cloned()
.collect();
!second_level.is_empty()
});
for second_level in self.entries.values_mut() {
second_level.retain(|entry| entry.deployment_slot != slot);
}
self.remove_programs_with_no_entries();
}

Expand Down Expand Up @@ -919,7 +914,6 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
.len()
.saturating_sub(shrink_to.apply_to(MAX_LOADED_ENTRY_COUNT));
self.unload_program_entries(sorted_candidates.iter().take(num_to_unload));
self.remove_programs_with_no_entries();
}

/// Removes all the entries at the given keys, if they exist
Expand All @@ -931,7 +925,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {

fn unload_program(&mut self, id: &Pubkey) {
if let Some(entries) = self.entries.get_mut(id) {
entries.iter_mut().for_each(|entry| {
for entry in entries.iter_mut() {
if let Some(unloaded) = entry.to_unloaded() {
*entry = Arc::new(unloaded);
self.stats
Expand All @@ -940,7 +934,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
.and_modify(|c| saturating_add_assign!(*c, 1))
.or_insert(1);
}
});
}
}
}

Expand Down Expand Up @@ -1133,7 +1127,6 @@ mod tests {
#[test]
fn test_eviction() {
let mut programs = vec![];
let mut num_total_programs: usize = 0;

let mut cache = new_mock_cache::<TestForkGraph>();

Expand All @@ -1153,7 +1146,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program1, *deployment_slot, usage_counter));
});

Expand Down Expand Up @@ -1187,7 +1179,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program2, *deployment_slot, usage_counter));
});

Expand Down Expand Up @@ -1220,7 +1211,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program3, *deployment_slot, usage_counter));
});

Expand Down