From fd39a09eae0ffca8cf8d9e69d849a3b5c230ea82 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sat, 21 Nov 2020 05:28:08 +0000 Subject: [PATCH] stake: Don't pay out rewards for epochs where inflation was not enabled (#13744) (cherry picked from commit 13aa38d307875dbf4f0fa31866979e72103f0c27) Co-authored-by: Trent Nelson --- programs/stake/src/stake_state.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/programs/stake/src/stake_state.rs b/programs/stake/src/stake_state.rs index 245565deac..9f8a42f7ee 100644 --- a/programs/stake/src/stake_state.rs +++ b/programs/stake/src/stake_state.rs @@ -581,6 +581,11 @@ impl Stake { fix_stake_deactivate, ); + // Drive credits_observed forward unconditionally when rewards are disabled + if point_value.rewards == 0 && fix_stake_deactivate { + return Some((0, 0, credits_observed)); + } + if points == 0 || point_value.points == 0 { return None; } @@ -3005,6 +3010,23 @@ mod tests { true, ) ); + + // now one with inflation disabled. no one gets paid, but we still need + // to advance the stake state's observed_credits field to prevent back- + // paying rewards when inflation is turned on. + assert_eq!( + Some((0, 0, 4)), + stake.calculate_rewards( + &PointValue { + rewards: 0, + points: 4 + }, + &vote_state, + None, + &mut null_tracer(), + true, + ) + ); } #[test]