This repository was archived by the owner on Jan 22, 2025. It is now read-only.
CPI Account Reuse#19762
Merged
Lichtso merged 8 commits intosolana-labs:masterfrom Sep 18, 2021
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19762 +/- ##
=========================================
+ Coverage 82.6% 82.8% +0.1%
=========================================
Files 478 487 +9
Lines 133547 134483 +936
=========================================
+ Hits 110369 111386 +1017
+ Misses 23178 23097 -81 |
691eb04 to
929c8b7
Compare
929c8b7 to
df1b07c
Compare
f0c0aa8 to
8840341
Compare
4a22aac to
78c468e
Compare
78c468e to
b10f302
Compare
b10f302 to
898c628
Compare
898c628 to
9357b39
Compare
jackcmay
reviewed
Sep 16, 2021
| pub fn deserialize_parameters_aligned( | ||
| keyed_accounts: &[KeyedAccount], | ||
| buffer: &[u8], | ||
| account_lengths: &[usize], |
Contributor
There was a problem hiding this comment.
This is neccessary because a CPI call will change the length of the account within this call?
Contributor
Author
There was a problem hiding this comment.
Yes, that was the missing puzzle piece I searched for the entire day.
The hidden purpose of the additional temporary account structs.
Because once the CPI calls recycle the existing account structs, it overwrites the length and so the deserialize of the caller program afterwards parses and writes back garbage.
jackcmay
reviewed
Sep 16, 2021
| } | ||
|
|
||
| /// Entrypoint for a cross-program invocation from a native program | ||
| pub fn native_invoke( |
Contributor
There was a problem hiding this comment.
This was mainly a copy-paste from the BPF version, thanks for cleaning it up
9357b39 to
f8e25ae
Compare
3787ae5 to
3f01613
Compare
… get_translated_accounts().
…structionProcessor::create_message().
… existing account structures.
3f01613 to
81b3ba9
Compare
Closed
dankelleher
pushed a commit
to identity-com/solana
that referenced
this pull request
Nov 24, 2021
* Removes two account copy steps from InstructionProcessor::native_invoke(). * Moves gathering of keyed_accounts, caller_write_privileges and program_indices into InstructionProcessor::create_message(). * Explicitly routes the serialized account lengths to enable sharing of existing account structures. * Recycles existing account structs in CPI syscall.
frits-metalogix
added a commit
to identity-com/solana
that referenced
this pull request
Nov 24, 2021
This reverts commit 69c052f.
This was referenced Aug 8, 2022
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
CPI needs an overhaul for inter-operation between the two ABI versions (see #19191).
native_invokeperforms two unnecessary account copy steps:Rc::new(keyed_account.account.clone())dst_keyed_account.try_account_ref_mut()?.set_data(src_keyed_account.data().to_vec());translate_accountscreates new Account structs as well:Rc::new(RefCell::new(AccountSharedData::from(Account { .. })))native_invokeshould be recycling the existing account structs instead of secretly having their own internally, in order to interoperate with ABI v2.Summary of Changes
callee_keyed_accounts,caller_write_privilegesandprogram_indicesof the CPI syscall andnative_invokeboth into one inInstructionProcessor::create_message().native_invoke.native_invoke.Fixes #