From ee7bd78e389854d990cf2d4c90502f43e51cd5da Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Tue, 8 Sep 2020 22:24:18 +0900 Subject: [PATCH 1/2] Reduce cap by rent's leftover as temporary measure --- runtime/src/bank.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index df0d746db9d152..5692c892d93539 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2027,7 +2027,7 @@ impl Bank { &self, vote_account_hashmap: &HashMap, rent_to_be_distributed: u64, - ) { + ) -> u64 { let mut total_staked = 0; let mut rent_distributed_in_initial_round = 0; @@ -2083,6 +2083,7 @@ impl Bank { account.lamports += rent_to_be_paid; self.store_account(&pubkey, &account); }); + leftover_lamports } fn distribute_rent(&self) { @@ -2100,7 +2101,9 @@ impl Bank { return; } - self.distribute_rent_to_validators(&self.vote_accounts(), rent_to_be_distributed); + let leftover = + self.distribute_rent_to_validators(&self.vote_accounts(), rent_to_be_distributed); + self.capitalization.fetch_sub(leftover, Ordering::Relaxed); } fn collect_rent( From b00f1a51b87ee86a8545f71f065464a35115e1ea Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 9 Sep 2020 01:53:32 +0900 Subject: [PATCH 2/2] Reset testnet cap. on start and more logs --- runtime/src/bank.rs | 5 ++++- runtime/src/snapshot_utils.rs | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 5692c892d93539..f886bbcbe8aa7e 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2103,7 +2103,10 @@ impl Bank { let leftover = self.distribute_rent_to_validators(&self.vote_accounts(), rent_to_be_distributed); - self.capitalization.fetch_sub(leftover, Ordering::Relaxed); + if leftover != 0 { + warn!("There was leftover from rent distribution: {}", leftover); + self.capitalization.fetch_sub(leftover, Ordering::Relaxed); + } } fn collect_rent( diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index cb74aa582ca091..6b609dae73fc5a 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -14,7 +14,12 @@ use fs_extra::dir::CopyOptions; use log::*; use regex::Regex; use solana_measure::measure::Measure; -use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash, pubkey::Pubkey}; +use solana_sdk::{ + clock::Slot, + genesis_config::{ClusterType, GenesisConfig}, + hash::Hash, + pubkey::Pubkey, +}; use std::{ cmp::Ordering, fmt, @@ -591,6 +596,17 @@ pub fn bank_from_archive>( if !bank.verify_snapshot_bank() { panic!("Snapshot bank for slot {} failed to verify", bank.slot()); } + if genesis_config.cluster_type == ClusterType::Testnet { + let old = bank.set_capitalization(); + if old != bank.capitalization() { + warn!( + "Capitalization was recalculated: {} => {}", + old, + bank.capitalization() + ) + } + } + measure.stop(); info!("{}", measure);