-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPI Account Reuse #19762
CPI Account Reuse #19762
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
@@ -247,9 +260,14 @@ pub fn serialize_parameters_aligned( | |||
pub fn deserialize_parameters_aligned( | |||
keyed_accounts: &[KeyedAccount], | |||
buffer: &[u8], | |||
account_lengths: &[usize], |
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.
This is neccessary because a CPI call will change the length of the account within this call?
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, 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.
let program_id_index = message.instructions[0].program_id_index as usize; | ||
|
||
Ok((message, program_id, program_id_index)) | ||
Ok((message, caller_write_privileges, program_indices)) | ||
} | ||
|
||
/// Entrypoint for a cross-program invocation from a native program | ||
pub fn native_invoke( |
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.
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
* 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.
This reverts commit 69c052f.
Problem
CPI needs an overhaul for inter-operation between the two ABI versions (see #19191).
native_invoke
performs 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_accounts
creates new Account structs as well:Rc::new(RefCell::new(AccountSharedData::from(Account { .. })))
native_invoke
should 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_privileges
andprogram_indices
of the CPI syscall andnative_invoke
both into one inInstructionProcessor::create_message()
.native_invoke
.native_invoke
.Fixes #