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.7k
Fix #21397 #21535
Merged
Merged
Fix #21397 #21535
Changes from all commits
Commits
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
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 | ||
|---|---|---|---|---|
|
|
@@ -277,6 +277,8 @@ pub trait InvokeContext { | |||
| fn remove_first_keyed_account(&mut self) -> Result<(), InstructionError>; | ||||
| /// Get the list of keyed accounts | ||||
| fn get_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError>; | ||||
| /// Get the list of keyed accounts skipping `first_instruction_account` many entries | ||||
| fn get_instruction_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError>; | ||||
| /// Get this invocation's LogCollector | ||||
| fn get_log_collector(&self) -> Option<Rc<RefCell<LogCollector>>>; | ||||
| /// Get this invocation's ComputeMeter | ||||
|
|
@@ -621,7 +623,7 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> { | |||
| let message = Message::new(&[instruction.clone()], None); | ||||
|
|
||||
| // Gather keyed_accounts in the order of message.account_keys | ||||
| let caller_keyed_accounts = self.get_keyed_accounts()?; | ||||
| let caller_keyed_accounts = self.get_instruction_keyed_accounts()?; | ||||
| let callee_keyed_accounts = message | ||||
| .account_keys | ||||
| .iter() | ||||
|
|
@@ -815,6 +817,17 @@ impl<'a> InvokeContext for ThisInvokeContext<'a> { | |||
| .map(|frame| &frame.keyed_accounts[frame.keyed_accounts_range.clone()]) | ||||
| .ok_or(InstructionError::CallDepth) | ||||
| } | ||||
| fn get_instruction_keyed_accounts(&self) -> Result<&[KeyedAccount], InstructionError> { | ||||
| let frame = self | ||||
| .invoke_stack | ||||
| .last() | ||||
| .ok_or(InstructionError::CallDepth)?; | ||||
| let first_instruction_account = frame | ||||
| .number_of_program_accounts | ||||
| .checked_sub(1) | ||||
|
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. @Lichtso why do you subtract 1 here?
Contributor
Author
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. Because the
solana/program-runtime/src/invoke_context.rs Line 132 in c9bfc99
|
||||
| .ok_or(InstructionError::CallDepth)?; | ||||
| Ok(&frame.keyed_accounts[first_instruction_account..]) | ||||
| } | ||||
| fn get_log_collector(&self) -> Option<Rc<RefCell<LogCollector>>> { | ||||
| self.log_collector.clone() | ||||
| } | ||||
|
|
||||
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
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.
If the intent is to also include the instruction program keyed account in this list, can you update the comment to say so? The comment right now indicates that this will return a list of instruction account inputs (excluding the program account)
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.
Yes, it includes the
program_id(at index 0).And good point, I will update the comment.
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.
Thanks! It would be really helpful if the comment made it clearer what the breakdown of invoke context keyed accounts is and when it's appropriate to use
get_instruction_keyed_accountsoverget_keyed_accounts.