Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

distribute leftover lamports #7396

Merged
merged 3 commits into from
Dec 10, 2019

Conversation

ParthDesai
Copy link
Contributor

Problem

Currently, rent payment to validator is as a fraction of collected rent in accordance with their stake weight. Since lamports are atomic, the calculation results in leftover lamports (for N validators, maximum N lamports), which are then lost.

Proposed Solution

Distribute those leftover lamports among the validators from descending order of stake weight.
Each validator gets 1 lamport from the leftover lamports, until all leftover lamports are exhausted.

Fixes #7381

@codecov
Copy link

codecov bot commented Dec 10, 2019

Codecov Report

Merging #7396 into master will increase coverage by 12.2%.
The diff coverage is 96.9%.

@@            Coverage Diff            @@
##           master   #7396      +/-   ##
=========================================
+ Coverage    68.4%   80.6%   +12.2%     
=========================================
  Files         244     244              
  Lines       56475   47779    -8696     
=========================================
- Hits        38658   38548     -110     
+ Misses      17817    9231    -8586

mvines
mvines previously approved these changes Dec 10, 2019
});
// Sort first by stake and then by pubkey for determinism
node_stakes.sort_by(
|(pubkey1, staked1), (pubkey2, staked2)| match staked2.cmp(staked1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this sort doesn't need to be stable, does it? you should be safe sorting merely by stake...

Copy link
Contributor Author

@ParthDesai ParthDesai Dec 10, 2019

Choose a reason for hiding this comment

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

@rob-solana If I sort by stake only, it could lead to indeterminism, as the order might not be guaranteed for node with same stake amount. Which could result in rare cases, different distribution of leftover lamports.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, good point.

Copy link
Contributor

Choose a reason for hiding this comment

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

are you testing for that?

Copy link
Contributor Author

@ParthDesai ParthDesai Dec 10, 2019

Choose a reason for hiding this comment

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

@rob-solana not specifically. Let me add a separate test scenario for this, just for my assurance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rob-solana Added a scenario in test-case.

@mergify mergify bot dismissed mvines’s stale review December 10, 2019 19:34

Pull request has been modified.

let node_stakes_and_rent = node_stakes
.iter()
.map(|(pubkey, staked)| {
let rent_in_initial_round =
Copy link
Contributor

Choose a reason for hiding this comment

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

rent_to_be_paid was just as good a name

Copy link
Contributor

Choose a reason for hiding this comment

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

could also be rent_share

rob-solana
rob-solana previously approved these changes Dec 10, 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, nits are optional

@mergify mergify bot dismissed rob-solana’s stale review December 10, 2019 20:35

Pull request has been modified.

@ParthDesai ParthDesai merged commit feeb1cb into solana-labs:master Dec 10, 2019
@ParthDesai ParthDesai deleted the fix-rent-pay-calc branch December 10, 2019 21:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix rent payment to have no leftover lamports
3 participants