Skip to content
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

fix(runtime): disallow deletion of account with large state #4116

Merged
merged 5 commits into from
Mar 17, 2021

Conversation

bowenwang1996
Copy link
Collaborator

For account whose state is large, deleting them is not cheap and this PR prevents accounts with more than 10kb of state (excluding contracts) from being deleted. Contract developers should develop their own logic to delete part of the state if needed.

Test plan

  • test_delete_account_too_large
  • test_delete_account_with_contract_and_small_state
  • test_delete_account_with_contract_and_large_state
  • nayduck

runtime/runtime/src/actions.rs Outdated Show resolved Hide resolved
core/primitives/src/version.rs Outdated Show resolved Hide resolved
runtime/runtime/src/actions.rs Outdated Show resolved Hide resolved
core/primitives/src/errors.rs Outdated Show resolved Hide resolved
"num_block_producer_seats": 50,
"protocol_version": 43,
"genesis_time": "1970-01-01T00:00:00.000000000Z",
"chain_id": "sample",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing ws?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this file is auto generated

Comment on lines +450 to +451
if current_protocol_version
>= PROTOCOL_FEATURES_TO_VERSION_MAPPING[&ProtocolFeature::DeleteActionRestriction]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to PR, but feels like we can have a nicer API: current_protocol_version.has_feature(ProtocolFeature::DeleteActionRestriction)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good idea!

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
@@ -458,7 +457,7 @@ pub(crate) fn action_delete_account(
// account storage usage should be larger than code size
let code_len = code.code.len() as u64;
debug_assert!(account_storage_usage > code_len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't run debug_assert in prod, right? So it's only for tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@near-bulldozer near-bulldozer bot merged commit a6bb7b1 into master Mar 17, 2021
@near-bulldozer near-bulldozer bot deleted the temp-fix-delete-account branch March 17, 2021 00:18
bowenwang1996 added a commit that referenced this pull request Mar 17, 2021
For account whose state is large, deleting them is not cheap and this PR prevents accounts with more than 10kb of state (excluding contracts) from being deleted. Contract developers should develop their own logic to delete part of the state if needed.

Test plan
---------
* `test_delete_account_too_large`
* `test_delete_account_with_contract_and_small_state`
* `test_delete_account_with_contract_and_large_state`
*  nayduck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants