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

Put accounts data len updates behind feature gate #22918

Conversation

brooksprumo
Copy link
Contributor

@brooksprumo brooksprumo commented Feb 3, 2022

Problem

Updates to the Bank's accounts_data_len when collecting rent is not feature gated behind cap_accounts_data_len. This should've been feature-gated when it was first merged in #22412.

See here and here for existing usage of the feature.

Summary of Changes

Put the update behind the feature gate.

Related to #21604

@brooksprumo brooksprumo force-pushed the accounts-data-len/feature-gate-rent-collection branch from 4d515f5 to 43cd01a Compare February 3, 2022 19:15
@brooksprumo brooksprumo marked this pull request as ready for review February 3, 2022 20:45
@brooksprumo brooksprumo requested a review from jstarry February 3, 2022 20:45
@codecov
Copy link

codecov bot commented Feb 3, 2022

Codecov Report

Merging #22918 (43cd01a) into master (75563f6) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@           Coverage Diff           @@
##           master   #22918   +/-   ##
=======================================
  Coverage    81.3%    81.3%           
=======================================
  Files         560      560           
  Lines      152043   152045    +2     
=======================================
+ Hits       123623   123625    +2     
  Misses      28420    28420           

@jstarry
Copy link
Member

jstarry commented Feb 7, 2022

@brooksprumo I was surprised that updating the accounts data len with a delta is only done for rent collection. Could it be used for transaction execution as well so that the feature switch can be moved inside there? Also, since transactions can be executed in parallel, isn't it possible that there is a data race when two txs load the account data len independently before storing it?

@brooksprumo
Copy link
Contributor Author

brooksprumo commented Feb 7, 2022

@jstarry

I was surprised that updating the accounts data len with a delta is only done for rent collection. Could it be used for transaction execution as well so that the feature switch can be moved inside there?

So here's where the accounts data len is tracked/used within the invoke context:

if cap_accounts_data_len {
let pre_data_len = pre_account.data().len() as i64;
let post_data_len = account.data().len() as i64;
let data_len_delta = post_data_len.saturating_sub(pre_data_len);
self.accounts_data_meter.consume(data_len_delta)?;
}

It has a feature gate around it there, and that cannot be removed since it could cause instructions to fail that exceed the accounts data budget.

Yes, I could move this PR's feature gate into update_accounts_data_len(). Would that be your preference? I purposely wanted to keep the update_accounts_data_len()/load_accounts_data_len()/store_accounts_data_len() functions as simple wrappers around the atomic with safe memory orderings. And then the places that pertain to tracking accounts data len (txn processing and rent collection) have the feature gate. Wdyt?

Also, since transactions can be executed in parallel, isn't it possible that there is a data race when two txs load the account data len independently before storing it?

This is good to know! Hah! I was observing discrepancies in the accounts_data_len vs the value computed during generate_index() (Discord link), so maybe this is the reason why. However, I currently see Bank::accounts_data_len as being always larger than generate_index(), and if there is a race, I would expect always-or-mostly lower. (Edit: I mixed up my columns, Bank::accounts_data_len is indeed always lower.) In either case, I'm working on a fix to get the delta and call update() instead of store().

@brooksprumo
Copy link
Contributor Author

In either case, I'm working on a fix to get the delta and call update() instead of store().

PR is here: #22986

@brooksprumo brooksprumo merged commit f0f4042 into solana-labs:master Feb 8, 2022
@brooksprumo brooksprumo deleted the accounts-data-len/feature-gate-rent-collection branch February 8, 2022 14:51
@jstarry
Copy link
Member

jstarry commented Feb 8, 2022

In either case, I'm working on a fix to get the delta and call update() instead of store().

PR is here: #22986

Sweet, sounds good!

mergify bot pushed a commit that referenced this pull request Feb 8, 2022
mergify bot added a commit that referenced this pull request Feb 8, 2022
jeffwashington pushed a commit to jeffwashington/solana that referenced this pull request Feb 24, 2022
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.

2 participants