* Make rewards tracer async friendly (#20452)
(cherry picked from commit 250a8503fe
)
# Conflicts:
# Cargo.lock
# ledger-tool/Cargo.toml
# ledger-tool/src/main.rs
# programs/stake/src/stake_state.rs
# runtime/src/bank.rs
* fix conflicts
Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4781,6 +4781,7 @@ dependencies = [
|
|||||||
"bytecount",
|
"bytecount",
|
||||||
"clap",
|
"clap",
|
||||||
"csv",
|
"csv",
|
||||||
|
"dashmap",
|
||||||
"futures 0.3.8",
|
"futures 0.3.8",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"histogram",
|
"histogram",
|
||||||
|
@@ -14,6 +14,7 @@ bs58 = "0.3.1"
|
|||||||
bytecount = "0.6.0"
|
bytecount = "0.6.0"
|
||||||
clap = "2.33.1"
|
clap = "2.33.1"
|
||||||
csv = "1.1.3"
|
csv = "1.1.3"
|
||||||
|
dashmap = "4.0.2"
|
||||||
futures = "0.3.8"
|
futures = "0.3.8"
|
||||||
futures-util = "0.3.5"
|
futures-util = "0.3.5"
|
||||||
histogram = "*"
|
histogram = "*"
|
||||||
|
@@ -3,6 +3,7 @@ use clap::{
|
|||||||
crate_description, crate_name, value_t, value_t_or_exit, values_t_or_exit, App, AppSettings,
|
crate_description, crate_name, value_t, value_t_or_exit, values_t_or_exit, App, AppSettings,
|
||||||
Arg, ArgMatches, SubCommand,
|
Arg, ArgMatches, SubCommand,
|
||||||
};
|
};
|
||||||
|
use dashmap::DashMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::*;
|
use log::*;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
@@ -57,7 +58,7 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::{exit, Command, Stdio},
|
process::{exit, Command, Stdio},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
sync::Arc,
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod bigtable;
|
mod bigtable;
|
||||||
@@ -2362,15 +2363,16 @@ fn main() {
|
|||||||
skipped_reasons: String,
|
skipped_reasons: String,
|
||||||
}
|
}
|
||||||
use solana_stake_program::stake_state::InflationPointCalculationEvent;
|
use solana_stake_program::stake_state::InflationPointCalculationEvent;
|
||||||
let mut stake_calcuration_details: HashMap<Pubkey, CalculationDetail> =
|
let stake_calculation_details: DashMap<Pubkey, CalculationDetail> =
|
||||||
HashMap::new();
|
DashMap::new();
|
||||||
let mut last_point_value = None;
|
let last_point_value = Arc::new(RwLock::new(None));
|
||||||
let tracer = |event: &RewardCalculationEvent| {
|
let tracer = |event: &RewardCalculationEvent| {
|
||||||
// Currently RewardCalculationEvent enum has only Staking variant
|
// Currently RewardCalculationEvent enum has only Staking variant
|
||||||
// because only staking tracing is supported!
|
// because only staking tracing is supported!
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
if let RewardCalculationEvent::Staking(pubkey, event) = event {
|
if let RewardCalculationEvent::Staking(pubkey, event) = event {
|
||||||
let detail = stake_calcuration_details.entry(**pubkey).or_default();
|
let mut detail =
|
||||||
|
stake_calculation_details.entry(**pubkey).or_default();
|
||||||
match event {
|
match event {
|
||||||
InflationPointCalculationEvent::CalculatedPoints(
|
InflationPointCalculationEvent::CalculatedPoints(
|
||||||
epoch,
|
epoch,
|
||||||
@@ -2395,12 +2397,11 @@ fn main() {
|
|||||||
detail.point_value = Some(point_value.clone());
|
detail.point_value = Some(point_value.clone());
|
||||||
// we have duplicate copies of `PointValue`s for possible
|
// we have duplicate copies of `PointValue`s for possible
|
||||||
// miscalculation; do some minimum sanity check
|
// miscalculation; do some minimum sanity check
|
||||||
let point_value = detail.point_value.clone();
|
let mut last_point_value = last_point_value.write().unwrap();
|
||||||
if point_value.is_some() {
|
if let Some(last_point_value) = last_point_value.as_ref() {
|
||||||
if last_point_value.is_some() {
|
assert_eq!(last_point_value, point_value);
|
||||||
assert_eq!(last_point_value, point_value,);
|
} else {
|
||||||
}
|
*last_point_value = Some(point_value.clone());
|
||||||
last_point_value = point_value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InflationPointCalculationEvent::EffectiveStakeAtRewardedEpoch(stake) => {
|
InflationPointCalculationEvent::EffectiveStakeAtRewardedEpoch(stake) => {
|
||||||
@@ -2505,16 +2506,17 @@ fn main() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut unchanged_accounts = stake_calcuration_details
|
let mut unchanged_accounts = stake_calculation_details
|
||||||
.keys()
|
.iter()
|
||||||
|
.map(|entry| *entry.key())
|
||||||
.collect::<HashSet<_>>()
|
.collect::<HashSet<_>>()
|
||||||
.difference(
|
.difference(
|
||||||
&rewarded_accounts
|
&rewarded_accounts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(pubkey, ..)| *pubkey)
|
.map(|(pubkey, ..)| **pubkey)
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
.map(|pubkey| (**pubkey, warped_bank.get_account(pubkey).unwrap()))
|
.map(|pubkey| (*pubkey, warped_bank.get_account(pubkey).unwrap()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
unchanged_accounts.sort_unstable_by_key(|(pubkey, account)| {
|
unchanged_accounts.sort_unstable_by_key(|(pubkey, account)| {
|
||||||
(account.owner, account.lamports, *pubkey)
|
(account.owner, account.lamports, *pubkey)
|
||||||
@@ -2535,7 +2537,9 @@ fn main() {
|
|||||||
|
|
||||||
if let Some(base_account) = base_bank.get_account(&pubkey) {
|
if let Some(base_account) = base_bank.get_account(&pubkey) {
|
||||||
let delta = warped_account.lamports - base_account.lamports;
|
let delta = warped_account.lamports - base_account.lamports;
|
||||||
let detail = stake_calcuration_details.get(&pubkey);
|
let detail_ref = stake_calculation_details.get(&pubkey);
|
||||||
|
let detail: Option<&CalculationDetail> =
|
||||||
|
detail_ref.as_ref().map(|detail_ref| detail_ref.value());
|
||||||
println!(
|
println!(
|
||||||
"{:<45}({}): {} => {} (+{} {:>4.9}%) {:?}",
|
"{:<45}({}): {} => {} (+{} {:>4.9}%) {:?}",
|
||||||
format!("{}", pubkey), // format! is needed to pad/justify correctly.
|
format!("{}", pubkey), // format! is needed to pad/justify correctly.
|
||||||
@@ -2658,10 +2662,18 @@ fn main() {
|
|||||||
),
|
),
|
||||||
commission: format_or_na(detail.map(|d| d.commission)),
|
commission: format_or_na(detail.map(|d| d.commission)),
|
||||||
cluster_rewards: format_or_na(
|
cluster_rewards: format_or_na(
|
||||||
last_point_value.as_ref().map(|pv| pv.rewards),
|
last_point_value
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.clone()
|
||||||
|
.map(|pv| pv.rewards),
|
||||||
),
|
),
|
||||||
cluster_points: format_or_na(
|
cluster_points: format_or_na(
|
||||||
last_point_value.as_ref().map(|pv| pv.points),
|
last_point_value
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.clone()
|
||||||
|
.map(|pv| pv.points),
|
||||||
),
|
),
|
||||||
old_capitalization: base_bank.capitalization(),
|
old_capitalization: base_bank.capitalization(),
|
||||||
new_capitalization: warped_bank.capitalization(),
|
new_capitalization: warped_bank.capitalization(),
|
||||||
|
@@ -60,7 +60,7 @@ pub enum InflationPointCalculationEvent {
|
|||||||
Skipped(SkippedReason),
|
Skipped(SkippedReason),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn null_tracer() -> Option<impl FnMut(&InflationPointCalculationEvent)> {
|
pub(crate) fn null_tracer() -> Option<impl Fn(&InflationPointCalculationEvent)> {
|
||||||
None::<fn(&_)>
|
None::<fn(&_)>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,10 +575,10 @@ impl Stake {
|
|||||||
point_value: &PointValue,
|
point_value: &PointValue,
|
||||||
vote_state: &VoteState,
|
vote_state: &VoteState,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> Option<(u64, u64)> {
|
) -> Option<(u64, u64)> {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&InflationPointCalculationEvent::CreditsObserved(
|
inflation_point_calc_tracer(&InflationPointCalculationEvent::CreditsObserved(
|
||||||
self.credits_observed,
|
self.credits_observed,
|
||||||
None,
|
None,
|
||||||
@@ -588,7 +588,7 @@ impl Stake {
|
|||||||
point_value,
|
point_value,
|
||||||
vote_state,
|
vote_state,
|
||||||
stake_history,
|
stake_history,
|
||||||
inflation_point_calc_tracer,
|
inflation_point_calc_tracer.as_ref(),
|
||||||
fix_stake_deactivate,
|
fix_stake_deactivate,
|
||||||
)
|
)
|
||||||
.map(|(stakers_reward, voters_reward, credits_observed)| {
|
.map(|(stakers_reward, voters_reward, credits_observed)| {
|
||||||
@@ -608,7 +608,7 @@ impl Stake {
|
|||||||
&self,
|
&self,
|
||||||
vote_state: &VoteState,
|
vote_state: &VoteState,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> u128 {
|
) -> u128 {
|
||||||
self.calculate_points_and_credits(
|
self.calculate_points_and_credits(
|
||||||
@@ -627,18 +627,18 @@ impl Stake {
|
|||||||
&self,
|
&self,
|
||||||
new_vote_state: &VoteState,
|
new_vote_state: &VoteState,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> (u128, u64) {
|
) -> (u128, u64) {
|
||||||
// if there is no newer credits since observed, return no point
|
// if there is no newer credits since observed, return no point
|
||||||
if new_vote_state.credits() <= self.credits_observed {
|
if new_vote_state.credits() <= self.credits_observed {
|
||||||
if fix_stake_deactivate {
|
if fix_stake_deactivate {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&SkippedReason::ZeroCreditsAndReturnCurrent.into());
|
inflation_point_calc_tracer(&SkippedReason::ZeroCreditsAndReturnCurrent.into());
|
||||||
}
|
}
|
||||||
return (0, self.credits_observed);
|
return (0, self.credits_observed);
|
||||||
} else {
|
} else {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&SkippedReason::ZeroCreditsAndReturnZero.into());
|
inflation_point_calc_tracer(&SkippedReason::ZeroCreditsAndReturnZero.into());
|
||||||
}
|
}
|
||||||
return (0, 0);
|
return (0, 0);
|
||||||
@@ -679,7 +679,7 @@ impl Stake {
|
|||||||
let earned_points = stake * earned_credits;
|
let earned_points = stake * earned_credits;
|
||||||
points += earned_points;
|
points += earned_points;
|
||||||
|
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&InflationPointCalculationEvent::CalculatedPoints(
|
inflation_point_calc_tracer(&InflationPointCalculationEvent::CalculatedPoints(
|
||||||
epoch,
|
epoch,
|
||||||
stake,
|
stake,
|
||||||
@@ -703,13 +703,13 @@ impl Stake {
|
|||||||
point_value: &PointValue,
|
point_value: &PointValue,
|
||||||
vote_state: &VoteState,
|
vote_state: &VoteState,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> Option<(u64, u64, u64)> {
|
) -> Option<(u64, u64, u64)> {
|
||||||
let (points, credits_observed) = self.calculate_points_and_credits(
|
let (points, credits_observed) = self.calculate_points_and_credits(
|
||||||
vote_state,
|
vote_state,
|
||||||
stake_history,
|
stake_history,
|
||||||
inflation_point_calc_tracer,
|
inflation_point_calc_tracer.as_ref(),
|
||||||
fix_stake_deactivate,
|
fix_stake_deactivate,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -719,13 +719,13 @@ impl Stake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if points == 0 {
|
if points == 0 {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&SkippedReason::ZeroPoints.into());
|
inflation_point_calc_tracer(&SkippedReason::ZeroPoints.into());
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
if point_value.points == 0 {
|
if point_value.points == 0 {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&SkippedReason::ZeroPointValue.into());
|
inflation_point_calc_tracer(&SkippedReason::ZeroPointValue.into());
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
@@ -741,7 +741,7 @@ impl Stake {
|
|||||||
|
|
||||||
// don't bother trying to split if fractional lamports got truncated
|
// don't bother trying to split if fractional lamports got truncated
|
||||||
if rewards == 0 {
|
if rewards == 0 {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(&SkippedReason::ZeroReward.into());
|
inflation_point_calc_tracer(&SkippedReason::ZeroReward.into());
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
@@ -1526,11 +1526,11 @@ pub fn redeem_rewards(
|
|||||||
vote_state: &VoteState,
|
vote_state: &VoteState,
|
||||||
point_value: &PointValue,
|
point_value: &PointValue,
|
||||||
stake_history: Option<&StakeHistory>,
|
stake_history: Option<&StakeHistory>,
|
||||||
inflation_point_calc_tracer: &mut Option<impl FnMut(&InflationPointCalculationEvent)>,
|
inflation_point_calc_tracer: Option<impl Fn(&InflationPointCalculationEvent)>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> Result<(u64, u64), InstructionError> {
|
) -> Result<(u64, u64), InstructionError> {
|
||||||
if let StakeState::Stake(meta, mut stake) = stake_account.state()? {
|
if let StakeState::Stake(meta, mut stake) = stake_account.state()? {
|
||||||
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer {
|
if let Some(inflation_point_calc_tracer) = inflation_point_calc_tracer.as_ref() {
|
||||||
inflation_point_calc_tracer(
|
inflation_point_calc_tracer(
|
||||||
&InflationPointCalculationEvent::EffectiveStakeAtRewardedEpoch(stake.stake(
|
&InflationPointCalculationEvent::EffectiveStakeAtRewardedEpoch(stake.stake(
|
||||||
rewarded_epoch,
|
rewarded_epoch,
|
||||||
@@ -1581,7 +1581,7 @@ pub fn calculate_points(
|
|||||||
Ok(stake.calculate_points(
|
Ok(stake.calculate_points(
|
||||||
&vote_state,
|
&vote_state,
|
||||||
stake_history,
|
stake_history,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
fix_stake_deactivate,
|
fix_stake_deactivate,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
@@ -3901,7 +3901,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -3920,7 +3920,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -3956,7 +3956,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -3971,7 +3971,7 @@ mod tests {
|
|||||||
// no overflow on points
|
// no overflow on points
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
u128::from(stake.delegation.stake) * epoch_slots,
|
u128::from(stake.delegation.stake) * epoch_slots,
|
||||||
stake.calculate_points(&vote_state, None, &mut null_tracer(), true)
|
stake.calculate_points(&vote_state, None, null_tracer(), true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3998,7 +3998,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4017,7 +4017,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4033,7 +4033,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4052,7 +4052,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4069,7 +4069,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4092,7 +4092,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4109,7 +4109,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4123,7 +4123,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4140,7 +4140,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4157,7 +4157,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
&vote_state,
|
&vote_state,
|
||||||
None,
|
None,
|
||||||
&mut null_tracer(),
|
null_tracer(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -4165,11 +4165,11 @@ mod tests {
|
|||||||
// assert the previous behavior is preserved where fix_stake_deactivate=false
|
// assert the previous behavior is preserved where fix_stake_deactivate=false
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(0, 0),
|
(0, 0),
|
||||||
stake.calculate_points_and_credits(&vote_state, None, &mut null_tracer(), false)
|
stake.calculate_points_and_credits(&vote_state, None, null_tracer(), false)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
(0, 4),
|
(0, 4),
|
||||||
stake.calculate_points_and_credits(&vote_state, None, &mut null_tracer(), true)
|
stake.calculate_points_and_credits(&vote_state, None, null_tracer(), true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -713,7 +713,7 @@ pub enum RewardCalculationEvent<'a, 'b> {
|
|||||||
Staking(&'a Pubkey, &'b InflationPointCalculationEvent),
|
Staking(&'a Pubkey, &'b InflationPointCalculationEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn null_tracer() -> Option<impl FnMut(&RewardCalculationEvent)> {
|
fn null_tracer() -> Option<impl Fn(&RewardCalculationEvent) + Send + Sync> {
|
||||||
None::<fn(&RewardCalculationEvent)>
|
None::<fn(&RewardCalculationEvent)>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,7 +1014,7 @@ impl Bank {
|
|||||||
|
|
||||||
/// Create a new bank that points to an immutable checkpoint of another bank.
|
/// Create a new bank that points to an immutable checkpoint of another bank.
|
||||||
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: Slot) -> Self {
|
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: Slot) -> Self {
|
||||||
Self::_new_from_parent(parent, collector_id, slot, &mut null_tracer(), false)
|
Self::_new_from_parent(parent, collector_id, slot, null_tracer(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_parent_with_vote_only(
|
pub fn new_from_parent_with_vote_only(
|
||||||
@@ -1023,35 +1023,23 @@ impl Bank {
|
|||||||
slot: Slot,
|
slot: Slot,
|
||||||
vote_only_bank: bool,
|
vote_only_bank: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::_new_from_parent(
|
Self::_new_from_parent(parent, collector_id, slot, null_tracer(), vote_only_bank)
|
||||||
parent,
|
|
||||||
collector_id,
|
|
||||||
slot,
|
|
||||||
&mut null_tracer(),
|
|
||||||
vote_only_bank,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_parent_with_tracer(
|
pub fn new_from_parent_with_tracer(
|
||||||
parent: &Arc<Bank>,
|
parent: &Arc<Bank>,
|
||||||
collector_id: &Pubkey,
|
collector_id: &Pubkey,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
reward_calc_tracer: impl FnMut(&RewardCalculationEvent),
|
reward_calc_tracer: impl Fn(&RewardCalculationEvent) + Send + Sync,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::_new_from_parent(
|
Self::_new_from_parent(parent, collector_id, slot, Some(reward_calc_tracer), false)
|
||||||
parent,
|
|
||||||
collector_id,
|
|
||||||
slot,
|
|
||||||
&mut Some(reward_calc_tracer),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _new_from_parent(
|
fn _new_from_parent(
|
||||||
parent: &Arc<Bank>,
|
parent: &Arc<Bank>,
|
||||||
collector_id: &Pubkey,
|
collector_id: &Pubkey,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
|
||||||
vote_only_bank: bool,
|
vote_only_bank: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
parent.freeze();
|
parent.freeze();
|
||||||
@@ -1713,7 +1701,7 @@ impl Bank {
|
|||||||
fn update_rewards(
|
fn update_rewards(
|
||||||
&mut self,
|
&mut self,
|
||||||
prev_epoch: Epoch,
|
prev_epoch: Epoch,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
|
||||||
) {
|
) {
|
||||||
if prev_epoch == self.epoch() {
|
if prev_epoch == self.epoch() {
|
||||||
return;
|
return;
|
||||||
@@ -1817,7 +1805,7 @@ impl Bank {
|
|||||||
/// Filters out invalid pairs
|
/// Filters out invalid pairs
|
||||||
fn stake_delegation_accounts(
|
fn stake_delegation_accounts(
|
||||||
&self,
|
&self,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
|
||||||
) -> HashMap<Pubkey, (Vec<(Pubkey, AccountSharedData)>, AccountSharedData)> {
|
) -> HashMap<Pubkey, (Vec<(Pubkey, AccountSharedData)>, AccountSharedData)> {
|
||||||
let mut accounts = HashMap::new();
|
let mut accounts = HashMap::new();
|
||||||
|
|
||||||
@@ -1833,7 +1821,7 @@ impl Bank {
|
|||||||
) {
|
) {
|
||||||
(Some(stake_account), Some(vote_account)) => {
|
(Some(stake_account), Some(vote_account)) => {
|
||||||
// call tracer to catch any illegal data if any
|
// call tracer to catch any illegal data if any
|
||||||
if let Some(reward_calc_tracer) = reward_calc_tracer {
|
if let Some(reward_calc_tracer) = reward_calc_tracer.as_ref() {
|
||||||
reward_calc_tracer(&RewardCalculationEvent::Staking(
|
reward_calc_tracer(&RewardCalculationEvent::Staking(
|
||||||
stake_pubkey,
|
stake_pubkey,
|
||||||
&InflationPointCalculationEvent::Delegation(
|
&InflationPointCalculationEvent::Delegation(
|
||||||
@@ -1878,12 +1866,13 @@ impl Bank {
|
|||||||
&mut self,
|
&mut self,
|
||||||
rewarded_epoch: Epoch,
|
rewarded_epoch: Epoch,
|
||||||
rewards: u64,
|
rewards: u64,
|
||||||
reward_calc_tracer: &mut Option<impl FnMut(&RewardCalculationEvent)>,
|
reward_calc_tracer: Option<impl Fn(&RewardCalculationEvent) + Send + Sync>,
|
||||||
fix_stake_deactivate: bool,
|
fix_stake_deactivate: bool,
|
||||||
) -> f64 {
|
) -> f64 {
|
||||||
let stake_history = self.stakes.read().unwrap().history().clone();
|
let stake_history = self.stakes.read().unwrap().history().clone();
|
||||||
|
|
||||||
let mut stake_delegation_accounts = self.stake_delegation_accounts(reward_calc_tracer);
|
let mut stake_delegation_accounts =
|
||||||
|
self.stake_delegation_accounts(reward_calc_tracer.as_ref());
|
||||||
|
|
||||||
let points: u128 = stake_delegation_accounts
|
let points: u128 = stake_delegation_accounts
|
||||||
.iter()
|
.iter()
|
||||||
@@ -1928,7 +1917,7 @@ impl Bank {
|
|||||||
|
|
||||||
for (stake_pubkey, stake_account) in stake_group.iter_mut() {
|
for (stake_pubkey, stake_account) in stake_group.iter_mut() {
|
||||||
// curry closure to add the contextual stake_pubkey
|
// curry closure to add the contextual stake_pubkey
|
||||||
let mut reward_calc_tracer = reward_calc_tracer.as_mut().map(|outer| {
|
let reward_calc_tracer = reward_calc_tracer.as_ref().map(|outer| {
|
||||||
let stake_pubkey = *stake_pubkey;
|
let stake_pubkey = *stake_pubkey;
|
||||||
// inner
|
// inner
|
||||||
move |inner_event: &_| {
|
move |inner_event: &_| {
|
||||||
@@ -1942,7 +1931,7 @@ impl Bank {
|
|||||||
&vote_state,
|
&vote_state,
|
||||||
&point_value,
|
&point_value,
|
||||||
Some(&stake_history),
|
Some(&stake_history),
|
||||||
&mut reward_calc_tracer.as_mut(),
|
reward_calc_tracer,
|
||||||
fix_stake_deactivate,
|
fix_stake_deactivate,
|
||||||
);
|
);
|
||||||
if let Ok((stakers_reward, _voters_reward)) = redeemed {
|
if let Ok((stakers_reward, _voters_reward)) = redeemed {
|
||||||
@@ -7140,7 +7129,7 @@ pub(crate) mod tests {
|
|||||||
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
|
bank0.store_account_and_update_capitalization(&vote_id, &vote_account);
|
||||||
|
|
||||||
let validator_points: u128 = bank0
|
let validator_points: u128 = bank0
|
||||||
.stake_delegation_accounts(&mut null_tracer())
|
.stake_delegation_accounts(null_tracer())
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|(_vote_pubkey, (stake_group, vote_account))| {
|
.flat_map(|(_vote_pubkey, (stake_group, vote_account))| {
|
||||||
stake_group
|
stake_group
|
||||||
@@ -12308,7 +12297,7 @@ pub(crate) mod tests {
|
|||||||
vec![10_000; 2],
|
vec![10_000; 2],
|
||||||
);
|
);
|
||||||
let bank = Arc::new(Bank::new(&genesis_config));
|
let bank = Arc::new(Bank::new(&genesis_config));
|
||||||
let stake_delegation_accounts = bank.stake_delegation_accounts(&mut null_tracer());
|
let stake_delegation_accounts = bank.stake_delegation_accounts(null_tracer());
|
||||||
assert_eq!(stake_delegation_accounts.len(), 2);
|
assert_eq!(stake_delegation_accounts.len(), 2);
|
||||||
|
|
||||||
let mut vote_account = bank
|
let mut vote_account = bank
|
||||||
@@ -12347,7 +12336,7 @@ pub(crate) mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Accounts must be valid stake and vote accounts
|
// Accounts must be valid stake and vote accounts
|
||||||
let stake_delegation_accounts = bank.stake_delegation_accounts(&mut null_tracer());
|
let stake_delegation_accounts = bank.stake_delegation_accounts(null_tracer());
|
||||||
assert_eq!(stake_delegation_accounts.len(), 0);
|
assert_eq!(stake_delegation_accounts.len(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user