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

rent collector improvments #6888

Merged
merged 20 commits into from
Nov 14, 2019

Conversation

ParthDesai
Copy link
Contributor

@ParthDesai ParthDesai commented Nov 12, 2019

Problem

  1. Rent collector copies account struct everytime .update is called, which is in-efficient
  2. We are not charging rent for zero data account

Summary of Changes

  1. Rent collector now takes mutable account reference
  2. Rent collection now takes rent in a format of (base rent + rent per data byte), where base rent could come from genesis.

Fixes #6864

tag: @mvines @aeyakovenko @rob-solana

@codecov
Copy link

codecov bot commented Nov 12, 2019

Codecov Report

Merging #6888 into master will decrease coverage by 5.6%.
The diff coverage is 90.9%.

@@           Coverage Diff            @@
##           master   #6888     +/-   ##
========================================
- Coverage    78.7%   73.1%   -5.7%     
========================================
  Files         222     222             
  Lines       42939   46215   +3276     
========================================
- Hits        33829   33817     -12     
- Misses       9110   12398   +3288

sdk/src/rent.rs Outdated
@@ -26,12 +28,16 @@ pub const DEFAULT_EXEMPTION_THRESHOLD: f64 = 2.0;
/// default amount of rent to burn, as a fraction of std::u8::MAX
pub const DEFAULT_BURN_PERCENT: u8 = ((50usize * std::u8::MAX as usize) / 100usize) as u8;

/// default base rent
pub const DEFAULT_BASE_RENT_PER_YEAR: u64 = 0;
Copy link
Member

Choose a reason for hiding this comment

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

What if we expressed this in terms of DEFAULT_LAMPORTS_PER_BYTE_YEAR? Say the base account overhead is whatever the current size of the Account structure currently is * DEFAULT_LAMPORTS_PER_BYTE_YEAR. That'll still be zero currently so no functional change to this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mvines We decided to detach this from current size of the Account structure right? Otherwise, we need to do hard fork in case size changes in future.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. I was just suggesting we use the current size of the Account structure as the value we hard code here (rather than randomly picking a value)

Copy link
Contributor Author

@ParthDesai ParthDesai Nov 12, 2019

Choose a reason for hiding this comment

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

@mvines hmm. This could work out. But, do you think hard coding it is a good idea compared to keeping it as default, and allowing us to overwrite it in future via gensis?

Copy link
Member

Choose a reason for hiding this comment

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

I just mean this:

-pub const DEFAULT_BASE_RENT_PER_YEAR: u64 = 0;
+pub const DEFAULT_BASE_RENT_PER_YEAR: u64 = 128 * DEFAULT_LAMPORTS_PER_BYTE_YEAR;

128 seems is approximately the current Account size.

Copy link
Member

Choose a reason for hiding this comment

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

maybe that's too much for a base rent 🤷‍♂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, I misunderstood. Cool, this works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mvines done.

@ParthDesai ParthDesai marked this pull request as ready for review November 12, 2019 18:11
@ParthDesai ParthDesai requested a review from mvines November 12, 2019 18:11
genesis/src/main.rs Outdated Show resolved Hide resolved
sdk/src/rent.rs Outdated Show resolved Hide resolved
@ParthDesai
Copy link
Contributor Author

hmm. On visualising, this design is less intuitive, instead we could do this:

  1. Define ACCOUNT_STORAGE_OVERHEAD, and assign it to some arbitrary value.
  2. Modify calculation in a way that by using lamports per byte per year, we can calculate how much rent is due for an account for bytes of (ACCOUNT_STORAGE_OVERHEAD + data.len())

@rob-solana
Copy link
Contributor

hmm. On visualising, this design is less intuitive, instead we could do this:

  1. Define ACCOUNT_STORAGE_OVERHEAD, and assign it to some arbitrary value.
  2. Modify calculation in a way that by using lamports per byte per year, we can calculate how much rent is due for an account for bytes of (ACCOUNT_STORAGE_OVERHEAD + data.len())

if you take approach 1), there are 2 variables that need to change in order to turn on rent... approach 2) means you only have to change lamports_per_byte_year

sdk/src/rent.rs Outdated Show resolved Hide resolved
sdk/src/rent.rs Outdated Show resolved Hide resolved
sdk/src/rent.rs Outdated Show resolved Hide resolved
@rob-solana
Copy link
Contributor

this is what I meant. the old test had an implicit "1" in the calculation that I've pulled out for more clarity

rob-solana
rob-solana previously approved these changes Nov 13, 2019
Copy link
Contributor

@rob-solana rob-solana left a comment

Choose a reason for hiding this comment

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

lgtm

@mergify mergify bot dismissed rob-solana’s stale review November 14, 2019 04:24

Pull request has been modified.

@ParthDesai ParthDesai force-pushed the rent-collector-updates branch from 4aaf911 to 17e2aa2 Compare November 14, 2019 04:29
@ParthDesai ParthDesai force-pushed the rent-collector-updates branch from 17e2aa2 to e9ca59a Compare November 14, 2019 04:31
@ParthDesai ParthDesai merged commit 7b05b3d into solana-labs:master Nov 14, 2019
@ParthDesai ParthDesai deleted the rent-collector-updates branch November 14, 2019 05:26
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.

Accounts with no data to not pay rent
3 participants