Skip to content

Commit

Permalink
Adds parameter previous_runtime_environment to create_program_runtime…
Browse files Browse the repository at this point in the history
…_environment().
  • Loading branch information
Lichtso committed Jul 25, 2023
1 parent b519477 commit 02583fb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,8 +2025,9 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
let program_runtime_environment = create_program_runtime_environment(
&FeatureSet::all_enabled(),
&ComputeBudget::default(),
true,
false,
None, /* prev_runtime_environment */
true, /* deployment */
false, /* debugging_features */
)
.unwrap();
let executable = Executable::<TautologyVerifier, InvokeContext>::from_elf(
Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ fn load_program<'a>(
let program_runtime_environment = create_program_runtime_environment(
&invoke_context.feature_set,
invoke_context.get_compute_budget(),
None, /* prev_runtime_environment */
false, /* deployment */
true, /* debugging_features */
)
Expand Down
2 changes: 2 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ macro_rules! deploy_program {
let program_runtime_environment = create_program_runtime_environment(
&$invoke_context.feature_set,
$invoke_context.get_compute_budget(),
None, /* prev_runtime_environment */
true, /* deployment */
false, /* debugging_features */
).map_err(|e| {
Expand Down Expand Up @@ -1642,6 +1643,7 @@ pub mod test_utils {
let program_runtime_environment = create_program_runtime_environment(
&invoke_context.feature_set,
invoke_context.get_compute_budget(),
None, /* prev_runtime_environment */
false, /* deployment */
false, /* debugging_features */
);
Expand Down
13 changes: 9 additions & 4 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ macro_rules! register_feature_gated_function {
pub fn create_program_runtime_environment<'a>(
feature_set: &FeatureSet,
compute_budget: &ComputeBudget,
previous_runtime_environment: Option<&BuiltinProgram<InvokeContext<'a>>>,
reject_deployment_of_broken_elfs: bool,
debugging_features: bool,
) -> Result<BuiltinProgram<InvokeContext<'a>>, Error> {
Expand Down Expand Up @@ -172,10 +173,14 @@ pub fn create_program_runtime_environment<'a>(
reject_broken_elfs: reject_deployment_of_broken_elfs,
noop_instruction_rate: 256,
sanitize_user_provided_values: true,
runtime_environment_key: rand::thread_rng()
.gen::<i32>()
.checked_shr(PROGRAM_ENVIRONMENT_KEY_SHIFT)
.unwrap_or(0),
runtime_environment_key: if let Some(previous) = previous_runtime_environment {
previous.get_config().runtime_environment_key
} else {
rand::thread_rng()
.gen::<i32>()
.checked_shr(PROGRAM_ENVIRONMENT_KEY_SHIFT)
.unwrap_or(0)
},
external_internal_function_hash_collision: feature_set
.is_active(&error_on_syscall_bpf_function_hash_collisions::id()),
reject_callx_r10: feature_set.is_active(&reject_callx_r10::id()),
Expand Down
4 changes: 4 additions & 0 deletions programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) {
let program_runtime_environment = create_program_runtime_environment(
&FeatureSet::default(),
&ComputeBudget::default(),
None,
true,
false,
);
Expand Down Expand Up @@ -121,6 +122,7 @@ fn bench_program_alu(bencher: &mut Bencher) {
let program_runtime_environment = create_program_runtime_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
None,
true,
false,
);
Expand Down Expand Up @@ -240,6 +242,7 @@ fn bench_create_vm(bencher: &mut Bencher) {
let program_runtime_environment = create_program_runtime_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
None,
true,
false,
);
Expand Down Expand Up @@ -302,6 +305,7 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
let program_runtime_environment = create_program_runtime_environment(
&invoke_context.feature_set,
&ComputeBudget::default(),
None,
true,
false,
);
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ impl Bank {
let program_runtime_environment_v1 = create_program_runtime_environment(
&feature_set,
&new.runtime_config.compute_budget.unwrap_or_default(),
Some(&loaded_programs_cache.program_runtime_environment_v1),
false, /* deployment */
false, /* debugging_features */
)
Expand Down Expand Up @@ -8035,6 +8036,7 @@ impl Bank {
let program_runtime_environment_v1 = create_program_runtime_environment(
&self.feature_set,
&self.runtime_config.compute_budget.unwrap_or_default(),
Some(&loaded_programs_cache.program_runtime_environment_v1),
false, /* deployment */
false, /* debugging_features */
)
Expand Down

0 comments on commit 02583fb

Please sign in to comment.