-
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
Refactoring: Move KeyedAccounts to InvokeContext #15410
Merged
Lichtso
merged 33 commits into
solana-labs:master
from
Lichtso:refactor/Move_KeyedAccounts_to_InvokeContext
Apr 19, 2021
Merged
Refactoring: Move KeyedAccounts to InvokeContext #15410
Lichtso
merged 33 commits into
solana-labs:master
from
Lichtso:refactor/Move_KeyedAccounts_to_InvokeContext
Apr 19, 2021
Conversation
This file contains 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
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
from
February 18, 2021 19:16
c9e3da2
to
84fbeb5
Compare
Codecov Report
@@ Coverage Diff @@
## master #15410 +/- ##
=========================================
- Coverage 83.0% 83.0% -0.1%
=========================================
Files 415 415
Lines 114701 114852 +151
=========================================
+ Hits 95265 95375 +110
- Misses 19436 19477 +41 |
(I'm mailed Travis CI support about the missing status here, no need to block this PR on them) |
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
6 times, most recently
from
February 26, 2021 09:05
dde5ee0
to
9e6812d
Compare
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
7 times, most recently
from
March 2, 2021 15:26
47625d8
to
4f27d01
Compare
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
2 times, most recently
from
March 2, 2021 16:35
0f8ac54
to
0f9652c
Compare
Lichtso
added
CI
Pull Request is ready to enter CI
and removed
CI
Pull Request is ready to enter CI
labels
Mar 2, 2021
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
from
March 2, 2021 17:55
0f9652c
to
2571c4f
Compare
Lichtso
added
CI
Pull Request is ready to enter CI
and removed
CI
Pull Request is ready to enter CI
labels
Mar 2, 2021
mvines
added
CI
Pull Request is ready to enter CI
and removed
CI
Pull Request is ready to enter CI
labels
Mar 2, 2021
…ader_upgradeable_instruction().
…ader_instruction() and in bpf_loader::Executor::execute().
…struction(), bpf_loader::process_instruction_jit() and bpf_loader::process_instruction_common().
…al to the keyed_accounts parameter.
…:create_pre_accounts() in InvokeContext::new().
…ccounts() into create_keyed_accounts_unified(). Throws instead CallDepth of GenericError at invoke_stack.last().ok_or(). Renames program => executable.
Lichtso
force-pushed
the
refactor/Move_KeyedAccounts_to_InvokeContext
branch
from
April 19, 2021 11:45
41aec06
to
0689763
Compare
This was referenced Jun 2, 2021
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
keyed_accounts
are currently passed as a parameter everywhere, but they need to be managed in one place so that their allocation scheme can be changed.Summary of Changes
Collects all parametric occurrences and the construction of
keyed_accounts
and puts them intoInvokeContext
.Progress and Open Issues
next_keyed_account()
vs.keyed_account_at_index()
The replacement of
next_keyed_account
bykeyed_account_at_index
is necessary in order to drop references ofkeyed_accounts
and retrieve them after function calls which involve passinginvoke_context
. The reference inside the iterator ofkeyed_accounts
would lead to a collision of borrows otherwise. Ideas of alternative approaches are welcome!Pro
Indices are better because they:
.next()
.Contra
Quoting @garious:
Neutral
Quoting @jackcmay:
The tale of MessageProcessor::process_cross_program_instruction
The main problem is getting the
KeyedAccount
s into theInvokeContext
through the stack push. This is hard as there are two references inside theKeyedAccount
struct:key: &'a Pubkey
account: &'a RefCell<AccountSharedData>
Both give the
KeyedAccount
struct the lifetime'a
. Now, in oder to push the newKeyedAccount
s into theInvokeContext
we need to prove to the borrow checker that the newKeyedAccount
s will live as long asInvokeContext
does. We can't just recycle the existingKeyedAccount
s, as they also have two other fieldsis_signer
andis_writable
which can be different at every invocation level.Lifetime of KeyedAccounts
Because the
InvokeContext
is a trait we can not alias the lifetime of its implementation with thepush
method directly. Instead the constructor of theKeyedAccount
s has to be called from inside the specific implementations of the trait so that the two lifetimes correctly alias.Lifetime of Account keys
The
key
s can not be borrowed fromVec<PreAccount>
as theVec
is owned byself
inside ofThisInvokeContext
. Instead they must be borrowed frommessage.account_keys
like it is done in create_keyed_accounts.Lifetime of Account RefCells
While the
key
s of theKeyedAccount
s can be borrowed from the existing ones, theAccount
s are created on the Rust stack at these three locations:So we have to
unsafe { transmute }
the lifetime to get them into theInvokeContext
. This is possible as we know that the stack frame will be popped again before the original reference goes out of scope.Otherwise, if we instead correctly bind the existing
Account
s to the newKeyedAccount
s verify_and_update will sound alarm as the inner instruction supposedly changed theAccount
s of the outer one.Future Work (for subsequent PRs)
Account
s into the BPF VM usingMemoryRegion
sKeyedAccount
sis_writable
flag to make some readonlyPreAccount
s from theInvokeContext
as theAccount
s are readonly anywaysunsafe { transmute }
which was introduced in this PR