This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Bump solana_rbpf to v0.8.0 #33679
Merged
Merged
Bump solana_rbpf to v0.8.0 #33679
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,9 +12,10 @@ use { | |
| solana_measure::measure::Measure, | ||
| solana_rbpf::{ | ||
| ebpf::MM_HEAP_START, | ||
| elf::SBPFVersion, | ||
| error::{EbpfError, ProgramResult}, | ||
| memory_region::MemoryMapping, | ||
| vm::{BuiltinFunction, Config, ContextObject, ProgramResult}, | ||
| program::{BuiltinFunction, SBPFVersion}, | ||
| vm::{Config, ContextObject, EbpfVm}, | ||
| }, | ||
| solana_sdk::{ | ||
| account::AccountSharedData, | ||
|
|
@@ -39,44 +40,46 @@ use { | |
| }, | ||
| }; | ||
|
|
||
| pub type ProcessInstructionWithContext = BuiltinFunction<InvokeContext<'static>>; | ||
| pub type BuiltinFunctionWithContext = BuiltinFunction<InvokeContext<'static>>; | ||
|
|
||
| /// Adapter so we can unify the interfaces of built-in programs and syscalls | ||
| #[macro_export] | ||
| macro_rules! declare_process_instruction { | ||
| ($process_instruction:ident, $cu_to_consume:expr, |$invoke_context:ident| $inner:tt) => { | ||
| pub fn $process_instruction( | ||
| invoke_context: &mut $crate::invoke_context::InvokeContext, | ||
| _arg0: u64, | ||
| _arg1: u64, | ||
| _arg2: u64, | ||
| _arg3: u64, | ||
| _arg4: u64, | ||
| _memory_mapping: &mut $crate::solana_rbpf::memory_region::MemoryMapping, | ||
| result: &mut $crate::solana_rbpf::vm::ProgramResult, | ||
| ) { | ||
| fn process_instruction_inner( | ||
| $invoke_context: &mut $crate::invoke_context::InvokeContext, | ||
| ) -> std::result::Result<(), solana_sdk::instruction::InstructionError> { | ||
| $inner | ||
| $crate::solana_rbpf::declare_builtin_function!( | ||
| $process_instruction, | ||
| fn rust( | ||
| invoke_context: &mut $crate::invoke_context::InvokeContext, | ||
| _arg0: u64, | ||
| _arg1: u64, | ||
| _arg2: u64, | ||
| _arg3: u64, | ||
| _arg4: u64, | ||
| _memory_mapping: &mut $crate::solana_rbpf::memory_region::MemoryMapping, | ||
| ) -> std::result::Result<u64, Box<dyn std::error::Error>> { | ||
| fn process_instruction_inner( | ||
| $invoke_context: &mut $crate::invoke_context::InvokeContext, | ||
| ) -> std::result::Result<(), solana_sdk::instruction::InstructionError> { | ||
| $inner | ||
| } | ||
| let consumption_result = if $cu_to_consume > 0 | ||
| && invoke_context | ||
| .feature_set | ||
| .is_active(&solana_sdk::feature_set::native_programs_consume_cu::id()) | ||
| { | ||
| invoke_context.consume_checked($cu_to_consume) | ||
| } else { | ||
| Ok(()) | ||
| }; | ||
| consumption_result | ||
| .and_then(|_| { | ||
| process_instruction_inner(invoke_context) | ||
| .map(|_| 0) | ||
| .map_err(|err| Box::new(err) as Box<dyn std::error::Error>) | ||
| }) | ||
| .into() | ||
| } | ||
| let consumption_result = if $cu_to_consume > 0 | ||
| && invoke_context | ||
| .feature_set | ||
| .is_active(&solana_sdk::feature_set::native_programs_consume_cu::id()) | ||
| { | ||
| invoke_context.consume_checked($cu_to_consume) | ||
| } else { | ||
| Ok(()) | ||
| }; | ||
| *result = consumption_result | ||
| .and_then(|_| { | ||
| process_instruction_inner(invoke_context) | ||
| .map(|_| 0) | ||
| .map_err(|err| Box::new(err) as Box<dyn std::error::Error>) | ||
| }) | ||
| .into(); | ||
| } | ||
| ); | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -468,11 +471,11 @@ impl<'a> InvokeContext<'a> { | |
| .programs_loaded_for_tx_batch | ||
| .find(&builtin_id) | ||
| .ok_or(InstructionError::UnsupportedProgramId)?; | ||
| let process_instruction = match &entry.program { | ||
| let function = match &entry.program { | ||
| LoadedProgramType::Builtin(program) => program | ||
| .get_function_registry() | ||
| .lookup_by_key(ENTRYPOINT_KEY) | ||
| .map(|(_name, process_instruction)| process_instruction), | ||
| .map(|(_name, function)| function), | ||
| _ => None, | ||
| } | ||
| .ok_or(InstructionError::UnsupportedProgramId)?; | ||
|
|
@@ -484,31 +487,41 @@ impl<'a> InvokeContext<'a> { | |
| let logger = self.get_log_collector(); | ||
| stable_log::program_invoke(&logger, &program_id, self.get_stack_height()); | ||
| let pre_remaining_units = self.get_remaining(); | ||
| // In program-runtime v2 we will create this VM instance only once per transaction. | ||
| // `program_runtime_environment_v2.get_config()` will be used instead of `mock_config`. | ||
| // For now, only built-ins are invoked from here, so the VM and its Config are irrelevant. | ||
| let mock_config = Config::default(); | ||
| let mut mock_memory_mapping = | ||
| MemoryMapping::new(Vec::new(), &mock_config, &SBPFVersion::V2).unwrap(); | ||
| let mut result = ProgramResult::Ok(0); | ||
| process_instruction( | ||
| let empty_memory_mapping = | ||
| MemoryMapping::new(Vec::new(), &mock_config, &SBPFVersion::V1).unwrap(); | ||
| let mut vm = EbpfVm::new( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on slack please add a comment explaining why it's ok to hardcode |
||
| self.programs_loaded_for_tx_batch | ||
| .environments | ||
| .program_runtime_v2 | ||
| .clone(), | ||
| &SBPFVersion::V1, | ||
| // Removes lifetime tracking | ||
| unsafe { std::mem::transmute::<&mut InvokeContext, &mut InvokeContext>(self) }, | ||
| empty_memory_mapping, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| &mut mock_memory_mapping, | ||
| &mut result, | ||
| ); | ||
| let result = match result { | ||
| vm.invoke_function(function); | ||
| let result = match vm.program_result { | ||
| ProgramResult::Ok(_) => { | ||
| stable_log::program_success(&logger, &program_id); | ||
| Ok(()) | ||
| } | ||
| ProgramResult::Err(err) => { | ||
| stable_log::program_failure(&logger, &program_id, err.as_ref()); | ||
| if let Some(err) = err.downcast_ref::<InstructionError>() { | ||
| Err(err.clone()) | ||
| ProgramResult::Err(ref err) => { | ||
| if let EbpfError::SyscallError(syscall_error) = err { | ||
| if let Some(instruction_err) = syscall_error.downcast_ref::<InstructionError>() | ||
| { | ||
| stable_log::program_failure(&logger, &program_id, instruction_err); | ||
| Err(instruction_err.clone()) | ||
| } else { | ||
| stable_log::program_failure(&logger, &program_id, syscall_error); | ||
| Err(InstructionError::ProgramFailedToComplete) | ||
| } | ||
| } else { | ||
| stable_log::program_failure(&logger, &program_id, err); | ||
| Err(InstructionError::ProgramFailedToComplete) | ||
| } | ||
| } | ||
|
|
@@ -699,7 +712,7 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo | |
| mut transaction_accounts: Vec<TransactionAccount>, | ||
| instruction_account_metas: Vec<AccountMeta>, | ||
| expected_result: Result<(), InstructionError>, | ||
| process_instruction: ProcessInstructionWithContext, | ||
| builtin_function: BuiltinFunctionWithContext, | ||
| mut pre_adjustments: F, | ||
| mut post_adjustments: G, | ||
| ) -> Vec<AccountSharedData> { | ||
|
|
@@ -734,7 +747,7 @@ pub fn mock_process_instruction<F: FnMut(&mut InvokeContext), G: FnMut(&mut Invo | |
| let mut programs_loaded_for_tx_batch = LoadedProgramsForTxBatch::default(); | ||
| programs_loaded_for_tx_batch.replenish( | ||
| *loader_id, | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, process_instruction)), | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, builtin_function)), | ||
| ); | ||
| invoke_context.programs_loaded_for_tx_batch = &programs_loaded_for_tx_batch; | ||
| pre_adjustments(&mut invoke_context); | ||
|
|
@@ -782,7 +795,7 @@ mod tests { | |
| const MOCK_BUILTIN_COMPUTE_UNIT_COST: u64 = 1; | ||
|
|
||
| declare_process_instruction!( | ||
| process_instruction, | ||
| MockBuiltin, | ||
| MOCK_BUILTIN_COMPUTE_UNIT_COST, | ||
| |invoke_context| { | ||
| let transaction_context = &invoke_context.transaction_context; | ||
|
|
@@ -988,7 +1001,7 @@ mod tests { | |
| let mut programs_loaded_for_tx_batch = LoadedProgramsForTxBatch::default(); | ||
| programs_loaded_for_tx_batch.replenish( | ||
| callee_program_id, | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, process_instruction)), | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, MockBuiltin::vm)), | ||
| ); | ||
| invoke_context.programs_loaded_for_tx_batch = &programs_loaded_for_tx_batch; | ||
|
|
||
|
|
@@ -1134,7 +1147,7 @@ mod tests { | |
| let mut programs_loaded_for_tx_batch = LoadedProgramsForTxBatch::default(); | ||
| programs_loaded_for_tx_batch.replenish( | ||
| program_key, | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, process_instruction)), | ||
| Arc::new(LoadedProgram::new_builtin(0, 0, MockBuiltin::vm)), | ||
| ); | ||
| invoke_context.programs_loaded_for_tx_batch = &programs_loaded_for_tx_batch; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this macro and its callers would look less weird if the macro had a pattern where the
the ident is optional and defaults to Entrypoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename a lot of things, but want to do that in different PRs.
"Entrypoint" is bad because in PRv2 every function can be an entrypoint.