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

clean feature: no_overflow_rent_distribution #34074

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7876,11 +7876,6 @@ impl Bank {
.shrink_ancient_slots(self.epoch_schedule())
}

pub fn no_overflow_rent_distribution_enabled(&self) -> bool {
self.feature_set
.is_active(&feature_set::no_overflow_rent_distribution::id())
}

pub fn prevent_rent_paying_rent_recipients(&self) -> bool {
self.feature_set
.is_active(&feature_set::prevent_rent_paying_rent_recipients::id())
Expand Down
70 changes: 6 additions & 64 deletions runtime/src/bank/fee_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,14 @@ impl Bank {
(staked1, pubkey1).cmp(&(staked2, pubkey2)).reverse()
});

let enforce_fix = self.no_overflow_rent_distribution_enabled();

let mut rent_distributed_in_initial_round = 0;
let validator_rent_shares = validator_stakes
.into_iter()
.map(|(pubkey, staked)| {
let rent_share = if !enforce_fix {
(((staked * rent_to_be_distributed) as f64) / (total_staked as f64)) as u64
} else {
(((staked as u128) * (rent_to_be_distributed as u128)) / (total_staked as u128))
.try_into()
.unwrap()
};
let rent_share = (((staked as u128) * (rent_to_be_distributed as u128))
/ (total_staked as u128))
.try_into()
.unwrap();
rent_distributed_in_initial_round += rent_share;
(pubkey, rent_share)
})
Expand All @@ -214,7 +209,7 @@ impl Bank {
} else {
rent_share
};
if !enforce_fix || rent_to_be_paid > 0 {
if rent_to_be_paid > 0 {
let check_account_owner = self.validate_fee_collector_account();
let check_rent_paying = self.prevent_rent_paying_rent_recipients();
match self.deposit_fees(
Expand Down Expand Up @@ -260,15 +255,7 @@ impl Bank {
);
}

if enforce_fix {
assert_eq!(leftover_lamports, 0);
} else if leftover_lamports != 0 {
warn!(
"There was leftover from rent distribution: {}",
leftover_lamports
);
self.capitalization.fetch_sub(leftover_lamports, Relaxed);
}
assert_eq!(leftover_lamports, 0);
}

pub(super) fn distribute_rent_fees(&self) {
Expand Down Expand Up @@ -308,7 +295,6 @@ pub mod tests {
create_genesis_config, create_genesis_config_with_leader,
create_genesis_config_with_vote_accounts, ValidatorVoteKeypairs,
},
log::info,
solana_sdk::{
account::AccountSharedData, feature_set, native_token::sol_to_lamports, pubkey,
rent::Rent, signature::Signer,
Expand Down Expand Up @@ -623,50 +609,6 @@ pub mod tests {
}
}

#[test]
fn test_distribute_rent_to_validators_overflow() {
solana_logger::setup();

// These values are taken from the real cluster (testnet)
const RENT_TO_BE_DISTRIBUTED: u64 = 120_525;
const VALIDATOR_STAKE: u64 = 374_999_998_287_840;

let validator_pubkey = solana_sdk::pubkey::new_rand();
let mut genesis_config =
create_genesis_config_with_leader(10, &validator_pubkey, VALIDATOR_STAKE)
.genesis_config;

let bank = Bank::new_for_tests(&genesis_config);
let old_validator_lamports = bank.get_balance(&validator_pubkey);
bank.distribute_rent_to_validators(&bank.vote_accounts(), RENT_TO_BE_DISTRIBUTED);
let new_validator_lamports = bank.get_balance(&validator_pubkey);
assert_eq!(
new_validator_lamports,
old_validator_lamports + RENT_TO_BE_DISTRIBUTED
);

genesis_config
.accounts
.remove(&feature_set::no_overflow_rent_distribution::id())
.unwrap();
let bank = std::panic::AssertUnwindSafe(Bank::new_for_tests(&genesis_config));
let old_validator_lamports = bank.get_balance(&validator_pubkey);
let new_validator_lamports = std::panic::catch_unwind(|| {
bank.distribute_rent_to_validators(&bank.vote_accounts(), RENT_TO_BE_DISTRIBUTED);
bank.get_balance(&validator_pubkey)
});

if let Ok(new_validator_lamports) = new_validator_lamports {
info!("asserting overflowing incorrect rent distribution");
assert_ne!(
new_validator_lamports,
old_validator_lamports + RENT_TO_BE_DISTRIBUTED
);
} else {
info!("NOT-asserting overflowing incorrect rent distribution");
}
}

#[test]
fn test_distribute_rent_to_validators_rent_paying() {
solana_logger::setup();
Expand Down