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

Initialize and store PRv2 environment in cache #32812

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
clap::{App, AppSettings, Arg, ArgMatches, SubCommand},
log::*,
solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig},
solana_bpf_loader_program::syscalls::create_program_runtime_environment,
solana_bpf_loader_program::syscalls::create_program_runtime_v1_environment,
solana_clap_utils::{
self, hidden_unless_forced, input_parsers::*, input_validators::*, keypair::*,
},
Expand Down Expand Up @@ -2022,7 +2022,7 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
.map_err(|err| format!("Unable to read program file: {err}"))?;

// Verify the program
let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&FeatureSet::all_enabled(),
&ComputeBudget::default(),
true,
Expand Down
4 changes: 2 additions & 2 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
serde_json::Result,
solana_bpf_loader_program::{
create_vm, load_program_from_bytes, serialization::serialize_parameters,
syscalls::create_program_runtime_environment,
syscalls::create_program_runtime_v1_environment,
},
solana_clap_utils::input_parsers::pubkeys_of,
solana_ledger::{
Expand Down Expand Up @@ -346,7 +346,7 @@ fn load_program<'a>(
..LoadProgramMetrics::default()
};
let account_size = contents.len();
let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&invoke_context.feature_set,
invoke_context.get_compute_budget(),
false, /* deployment */
Expand Down
13 changes: 12 additions & 1 deletion program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ pub struct LoadedPrograms {
entries: HashMap<Pubkey, Vec<Arc<LoadedProgram>>>,
/// Globally shared RBPF config and syscall registry
pub program_runtime_environment_v1: Arc<BuiltinProgram<InvokeContext<'static>>>,
/// Globally shared RBPF config and syscall registry for runtime V2
pub program_runtime_environment_v2: Arc<BuiltinProgram<InvokeContext<'static>>>,
latest_root: Slot,
pub stats: Stats,
}
Expand Down Expand Up @@ -501,7 +503,16 @@ impl LoadedPrograms {
}
LoadedProgramType::Unloaded(environment)
| LoadedProgramType::FailedVerification(environment)
if Arc::ptr_eq(environment, &self.program_runtime_environment_v1) =>
if Arc::ptr_eq(environment, &self.program_runtime_environment_v1)
|| Arc::ptr_eq(environment, &self.program_runtime_environment_v2) =>
{
true
}
LoadedProgramType::Typed(program)
if Arc::ptr_eq(
program.get_loader(),
&self.program_runtime_environment_v2,
) =>
{
true
}
Expand Down
6 changes: 3 additions & 3 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use {
rc::Rc,
sync::{atomic::Ordering, Arc},
},
syscalls::create_program_runtime_environment,
syscalls::create_program_runtime_v1_environment,
};

pub const DEFAULT_LOADER_COMPUTE_UNITS: u64 = 570;
Expand Down Expand Up @@ -116,7 +116,7 @@ macro_rules! deploy_program {
$account_size:expr, $slot:expr, $drop:expr, $new_programdata:expr $(,)?) => {{
let mut load_program_metrics = LoadProgramMetrics::default();
let mut register_syscalls_time = Measure::start("register_syscalls_time");
let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&$invoke_context.feature_set,
$invoke_context.get_compute_budget(),
true, /* deployment */
Expand Down Expand Up @@ -1654,7 +1654,7 @@ pub mod test_utils {

pub fn load_all_invoked_programs(invoke_context: &mut InvokeContext) {
let mut load_program_metrics = LoadProgramMetrics::default();
let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&invoke_context.feature_set,
invoke_context.get_compute_budget(),
false, /* deployment */
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ macro_rules! register_feature_gated_function {
};
}

pub fn create_program_runtime_environment<'a>(
pub fn create_program_runtime_v1_environment<'a>(
pgarg66 marked this conversation as resolved.
Show resolved Hide resolved
feature_set: &FeatureSet,
compute_budget: &ComputeBudget,
reject_deployment_of_broken_elfs: bool,
Expand Down
31 changes: 20 additions & 11 deletions programs/loader-v4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,10 @@ fn get_state_mut(data: &mut [u8]) -> Result<&mut LoaderV4State, InstructionError
}
}

pub fn load_program_from_account(
_feature_set: &FeatureSet,
pub fn create_program_runtime_v2_environment<'a>(
compute_budget: &ComputeBudget,
log_collector: Option<Rc<RefCell<LogCollector>>>,
program: &BorrowedAccount,
debugging_features: bool,
) -> Result<(Arc<LoadedProgram>, LoadProgramMetrics), InstructionError> {
let mut load_program_metrics = LoadProgramMetrics {
program_id: program.get_key().to_string(),
..LoadProgramMetrics::default()
};
) -> BuiltinProgram<InvokeContext<'a>> {
let config = Config {
max_call_depth: compute_budget.max_call_depth,
stack_frame_size: compute_budget.stack_frame_size,
Expand All @@ -104,15 +97,31 @@ pub fn load_program_from_account(
aligned_memory_mapping: true,
// Warning, do not use `Config::default()` so that configuration here is explicit.
};
let loader = BuiltinProgram::new_loader(config);
BuiltinProgram::new_loader(config)
}

pub fn load_program_from_account(
_feature_set: &FeatureSet,
compute_budget: &ComputeBudget,
log_collector: Option<Rc<RefCell<LogCollector>>>,
program: &BorrowedAccount,
debugging_features: bool,
) -> Result<(Arc<LoadedProgram>, LoadProgramMetrics), InstructionError> {
let mut load_program_metrics = LoadProgramMetrics {
program_id: program.get_key().to_string(),
..LoadProgramMetrics::default()
};
let state = get_state(program.get_data())?;
let programdata = program
.get_data()
.get(LoaderV4State::program_data_offset()..)
.ok_or(InstructionError::AccountDataTooSmall)?;
let loaded_program = LoadedProgram::new(
&loader_v4::id(),
Arc::new(loader),
Arc::new(create_program_runtime_v2_environment(
Lichtso marked this conversation as resolved.
Show resolved Hide resolved
compute_budget,
debugging_features,
)),
state.slot,
state.slot.saturating_add(1),
None,
Expand Down
10 changes: 5 additions & 5 deletions programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use {
byteorder::{ByteOrder, LittleEndian, WriteBytesExt},
solana_bpf_loader_program::{
create_vm, serialization::serialize_parameters,
syscalls::create_program_runtime_environment,
syscalls::create_program_runtime_v1_environment,
},
solana_measure::measure::Measure,
solana_program_runtime::{compute_budget::ComputeBudget, invoke_context::InvokeContext},
Expand Down Expand Up @@ -90,7 +90,7 @@ macro_rules! with_mock_invoke_context {
fn bench_program_create_executable(bencher: &mut Bencher) {
let elf = load_program_from_file("bench_alu");

let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&FeatureSet::default(),
&ComputeBudget::default(),
true,
Expand Down Expand Up @@ -118,7 +118,7 @@ fn bench_program_alu(bencher: &mut Bencher) {
let elf = load_program_from_file("bench_alu");
with_mock_invoke_context!(invoke_context, bpf_loader::id(), 10000001);

let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
true,
Expand Down Expand Up @@ -237,7 +237,7 @@ fn bench_create_vm(bencher: &mut Bencher) {
let direct_mapping = invoke_context
.feature_set
.is_active(&bpf_account_data_direct_mapping::id());
let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
true,
Expand Down Expand Up @@ -299,7 +299,7 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
)
.unwrap();

let program_runtime_environment = create_program_runtime_environment(
let program_runtime_environment = create_program_runtime_v1_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
true,
Expand Down
15 changes: 13 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ use {
TransactionResults,
},
},
solana_bpf_loader_program::syscalls::create_program_runtime_environment,
solana_bpf_loader_program::syscalls::create_program_runtime_v1_environment,
solana_cost_model::cost_tracker::CostTracker,
solana_measure::{measure, measure::Measure, measure_us},
solana_perf::perf_libs,
Expand Down Expand Up @@ -7996,7 +7996,7 @@ impl Bank {
.iter()
.any(|key| new_feature_activations.contains(key))
{
let program_runtime_environment_v1 = create_program_runtime_environment(
let program_runtime_environment_v1 = create_program_runtime_v1_environment(
&self.feature_set,
&self.runtime_config.compute_budget.unwrap_or_default(),
false, /* deployment */
Expand All @@ -8010,6 +8010,17 @@ impl Bank {
loaded_programs_cache.program_runtime_environment_v1 =
Arc::new(program_runtime_environment_v1);
}
let program_runtime_environment_v2 =
solana_loader_v4_program::create_program_runtime_v2_environment(
&self.runtime_config.compute_budget.unwrap_or_default(),
false, /* deployment */
pgarg66 marked this conversation as resolved.
Show resolved Hide resolved
);
if *loaded_programs_cache.program_runtime_environment_v2
!= program_runtime_environment_v2
{
loaded_programs_cache.program_runtime_environment_v2 =
Arc::new(program_runtime_environment_v2);
}
loaded_programs_cache.prune_feature_set_transition();
}
for builtin in BUILTINS.iter() {
Expand Down