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

Feature - Recompile loaded programs before epoch boundary #32172

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ pub fn program(ledger_path: &Path, matches: &ArgMatches<'_>) {
.clone(),
);
for key in cached_account_keys {
loaded_programs.replenish(key, bank.load_program(&key, false));
loaded_programs.replenish(key, bank.load_program(&key, false, None));
debug!("Loaded program {}", key);
}
invoke_context.programs_loaded_for_tx_batch = &loaded_programs;
Expand Down
27 changes: 18 additions & 9 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use {
},
};

const MAX_LOADED_ENTRY_COUNT: usize = 256;
pub type ProgramRuntimeEnvironment = Arc<BuiltinProgram<InvokeContext<'static>>>;
pub const MAX_LOADED_ENTRY_COUNT: usize = 256;
pub const DELAY_VISIBILITY_SLOT_OFFSET: Slot = 1;

/// Relationship between two fork IDs
Expand Down Expand Up @@ -62,17 +63,17 @@ pub trait WorkingSlot {
#[derive(Default)]
pub enum LoadedProgramType {
/// Tombstone for undeployed, closed or unloadable programs
FailedVerification(Arc<BuiltinProgram<InvokeContext<'static>>>),
FailedVerification(ProgramRuntimeEnvironment),
#[default]
Closed,
DelayVisibility,
/// Successfully verified but not currently compiled, used to track usage statistics when a compiled program is evicted from memory.
Unloaded(Arc<BuiltinProgram<InvokeContext<'static>>>),
Unloaded(ProgramRuntimeEnvironment),
LegacyV0(Executable<InvokeContext<'static>>),
LegacyV1(Executable<InvokeContext<'static>>),
Typed(Executable<InvokeContext<'static>>),
#[cfg(test)]
TestLoaded(Arc<BuiltinProgram<InvokeContext<'static>>>),
TestLoaded(ProgramRuntimeEnvironment),
Builtin(BuiltinProgram<InvokeContext<'static>>),
}

Expand Down Expand Up @@ -221,7 +222,7 @@ impl LoadedProgram {
/// Creates a new user program
pub fn new(
loader_key: &Pubkey,
program_runtime_environment: Arc<BuiltinProgram<InvokeContext<'static>>>,
program_runtime_environment: ProgramRuntimeEnvironment,
deployment_slot: Slot,
effective_slot: Slot,
maybe_expiration_slot: Option<Slot>,
Expand Down Expand Up @@ -407,10 +408,14 @@ impl LoadedProgram {

#[derive(Clone, Debug)]
pub struct ProgramRuntimeEnvironments {
/// Globally shared RBPF config and syscall registry
pub program_runtime_v1: Arc<BuiltinProgram<InvokeContext<'static>>>,
/// Globally shared RBPF config and syscall registry for runtime V1
pub program_runtime_v1: ProgramRuntimeEnvironment,
/// Globally shared RBPF config and syscall registry for runtime V2
pub program_runtime_v2: Arc<BuiltinProgram<InvokeContext<'static>>>,
pub program_runtime_v2: ProgramRuntimeEnvironment,
/// Anticipated replacement for `program_runtime_v1` at the next epoch
pub upcoming_program_runtime_v1: Option<ProgramRuntimeEnvironment>,
/// Anticipated replacement for `program_runtime_v2` at the next epoch
pub upcoming_program_runtime_v2: Option<ProgramRuntimeEnvironment>,
}

impl Default for ProgramRuntimeEnvironments {
Expand All @@ -421,7 +426,9 @@ impl Default for ProgramRuntimeEnvironments {
));
Self {
program_runtime_v1: empty_loader.clone(),
program_runtime_v2: empty_loader,
program_runtime_v2: empty_loader.clone(),
upcoming_program_runtime_v1: Some(empty_loader.clone()),
upcoming_program_runtime_v2: Some(empty_loader),
}
}
}
Expand All @@ -433,6 +440,8 @@ pub struct LoadedPrograms {
/// Pubkey is the address of a program, multiple versions can coexists simultaneously under the same address (in different slots).
entries: HashMap<Pubkey, Vec<Arc<LoadedProgram>>>,
pub environments: ProgramRuntimeEnvironments,
/// List of loaded programs which should be recompiled before the next epoch (but don't have to).
pub programs_to_recompile: Vec<(Pubkey, Arc<LoadedProgram>)>,
latest_root: Slot,
pub stats: Stats,
}
Expand Down
Loading