-
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
use cost model to limit new account creation #21369
Conversation
runtime/src/cost_model.rs
Outdated
space, | ||
owner: _owner, | ||
} => space, | ||
_ => 0, |
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.
I think we also need to consider SystemInstruction::Allocate{,WithSeed}
here, otherwise the checks can be sidestepped with a discrete Allocate
-> Assign
-> Transfer
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.
I added these 2 instructions.
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 what about the realloc instruction?
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.
Realloc is not an instruction, it is an operation that a program can do on accounts they own, from within the program:
solana/sdk/program/src/account_info.rs
Line 130 in 7da2df7
pub fn realloc(&self, new_len: usize, zero_init: bool) -> 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.
Realloc is not an instruction, it is an operation that a program can do on accounts they own, from within the program:
solana/sdk/program/src/account_info.rs
Line 130 in 7da2df7
pub fn realloc(&self, new_len: usize, zero_init: bool) -> Result<(), ProgramError> {
It doesn't seem like there's any runtime accounting of this operation? It'd be nice to consider its contributions to storage changes
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.
Curious because I do not know this part of the code yet; Is tracking realloc possible to do here?
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.
We could probably add some kind of limit to the number of bytes realloc'd, not sure where that would come from
Would this allow the creation of unlimited accounts without data? Since there is storage overhead per account, I think that should be factored into this model as well, as the size/size limit should reflect the requirements imposed on the validators instead of the account creator/holder. Or does |
@taozhu-chicago tells me that there is already a # acct limit per slot. |
c827d34
to
c9ae017
Compare
/// max len of account data in a slot (bytes) | ||
pub const MAX_ACCOUNT_DATA_LEN: u64 = 100_000_000; |
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 max account data len is 100 MB, then getting to 1 TB would only take a bit over 1 hour, is that right? I don't know what the right number should be here though... If a DoS was happening, would 1 hour be long enough to prevent/handle it?
Math used: 10^12 B / 10^8 B * 0.4 s per slot / 60 s per min / 60 min per hour
(double check in case I made dumb mistakes)
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.
@carllin ran these calculations in his head about 15 times last night.
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 comment was my invitation for him to 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.
Yeah about an hour. I think if we want to survive longer, we'll have to require validators have a lot more disk. Maybe 10TB minimum. How much space does it take to store 1 billion 10 MB accounts 😄 , 10 petabytes?
Also each account costs about $40, so if we factor that in, we could set the disk requirements based on the maximum economic attack we want to handle. 1 billion account would be 40 bil
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.
We would want more like a week. How does this max compare with the current mainnet-beta account data average written per slot?
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.
I've added the data len to the metrics. I'm waiting on the ability to start a validator with this to get the metrics of mnb. Keep in mind the current metrics ONLY measure the data size of account creation; not updates.
c9ae017
to
f71f232
Compare
number of writable accounts are counted into overall transaction cost, described in #20531. |
f17f7b3
to
7c03e67
Compare
@taozhu-chicago Is the solana/runtime/src/cost_model.rs Line 14 in cd6f931
And is solana/runtime/src/block_cost_limits.rs Line 58 in c4d6806
|
@taozhu-chicago It looks like solana/runtime/src/cost_tracker.rs Lines 82 to 91 in eb62faa
But it doesn't look like cost weight is used by either solana/runtime/src/cost_tracker.rs Lines 58 to 80 in eb62faa
Doing a quick grep tells me that neither P.S. I know this is unrelated to this PR specifically. |
It is currently used as capacity used to create |
@taozhu-chicago Gotcha. What I'm ultimately interested in is making sure that new accounts without data are also included in this tracking, since each account has storage overhead. (See #21369 (comment) for original comment.) Can you point me to where the number of new accounts is limited? |
For better parallelism, we discourage to packing too many transactions that write to same account. This limit is for this purpose. cost_tracker keeps tracking transaction cost per writable account in a block, transactions that would exceed any writable account limit are retried. |
Oh yeah. The |
Mmm, it does not limits number of |
93ce7fd
to
6aa0601
Compare
Overall this looks good to me. It is an incremental improvement, and further improvements can land in future PRs. I'd say mark this one as Ready For Review! |
9fc2947
to
34ef9e2
Compare
cb28622
to
e69a7d3
Compare
Codecov Report
@@ Coverage Diff @@
## master #21369 +/- ##
=========================================
- Coverage 81.6% 81.4% -0.2%
=========================================
Files 511 511
Lines 143320 143509 +189
=========================================
- Hits 116976 116878 -98
- Misses 26344 26631 +287 |
e69a7d3
to
435b1c6
Compare
435b1c6
to
e8e25b8
Compare
bench-tps #s I get locally are far lower than I expect, on 2 different colo machines, with both master and with this pr. The numbers seem similar, however. Will monitor overnight perf tests. |
This reverts commit 90f41fd.
Problem
Summary of Changes
Fixes #