-
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
Allow programs to realloc their accounts within limits #19475
Allow programs to realloc their accounts within limits #19475
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19475 +/- ##
=========================================
- Coverage 82.8% 82.8% -0.1%
=========================================
Files 487 487
Lines 135451 135528 +77
=========================================
+ Hits 112237 112265 +28
- Misses 23214 23263 +49 |
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 will make a bunch of people very happy 🙂
9c3cdf0
to
329d660
Compare
Dumb sleepy Saturday question: How does a BPF program take advantage of this again? |
Helpers and some tests added |
67a3fc6
to
eab8eb8
Compare
As discussed offline, are there any remaining blockers from allowing a program at depth 2+ to reallocate a non-empty account? solana/programs/bpf_loader/src/syscalls.rs Lines 2420 to 2423 in 622a6fb
Seems like the issue is that we would need to prevent sequentially invoked CPI's from each bumping the data size? |
Working on it, looks doable 😁
… |
1f9c8ba
to
c1d60f4
Compare
No featurization yet but lots of test cases, any other test scenarios folks can think of for account reallocs? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
c1d60f4
to
feab313
Compare
feab313
to
89c4b8a
Compare
89c4b8a
to
675630f
Compare
675630f
to
f6cf6d3
Compare
f6cf6d3
to
7a63e4b
Compare
programs/bpf_loader/src/syscalls.rs
Outdated
account.set_executable(account_ref.executable); | ||
account.set_rent_epoch(account_ref.rent_epoch); | ||
account.copy_into_owner_from_slice(caller_account.owner.as_ref()); | ||
caller_account.original_data_len = account.data().len(); |
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 account.data
could have already changed in an earlier CPI so we can't trust it as the original data length. The original data length has to come from the time of serializing account parameters.
sdk/program/src/account_info.rs
Outdated
@@ -114,6 +114,29 @@ impl<'a> AccountInfo<'a> { | |||
.map_err(|_| ProgramError::AccountBorrowFailed) | |||
} | |||
|
|||
pub fn realloc(&self, new_len: usize) -> Result<(), ProgramError> { |
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.
@jackcmay I still think we need to zero in this sdk method. If a program deallocs and then reallocs, it shouldn't be already filled with data.
@jstarry I'd like to avoid calling memset here, for most it will be a waste of compute units. How about clearly documenting the behavior instead? |
Ah sure, can we have an opt-in bool param to |
c652e94
to
a9eebf5
Compare
a9eebf5
to
3c40b5a
Compare
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.
orig_data_lens change looks good!
sdk/program/src/account_info.rs
Outdated
@@ -114,6 +114,29 @@ impl<'a> AccountInfo<'a> { | |||
.map_err(|_| ProgramError::AccountBorrowFailed) | |||
} | |||
|
|||
pub fn realloc(&self, new_len: usize) -> Result<(), ProgramError> { |
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.
@jackcmay still working on adding a zero_freed_data
param here?
Yup, almost done, but question, what do you think of:
vs
|
3c40b5a
to
924e597
Compare
Looking good so far.
I like the parameter flag better than two methods as you might decide to add even more parameters later on. Btw, account realloc in ABI v2 is not designed yet and something I would like to discuss on Monday. |
924e597
to
fee60ca
Compare
fee60ca
to
01cbf8f
Compare
01cbf8f
to
80e599c
Compare
…a-labs#19475)" This reverts commit b7dda1b.
Problem
Programs can only allocate account data via
SystemInstruction::Allocate
which only supports new account allocations (account owned by system program and alloc from 0 to x bytes).Summary of Changes
Allow programs to realloc the data size of accounts they own. They are still limited by the BPF serialization cap of 10k and the maximum account size of 10M.
This is a proof-of-concept meant to start a conversation as to the safety of allowing these types of operations so these changes don't contain any featurization or testing yet.
Thoughts?
Fixes #14694