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

Common sub-expression elimination in inflation calculation #1444

Merged
merged 1 commit into from
Jun 5, 2023
Merged
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
7 changes: 4 additions & 3 deletions shared/src/ledger/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ impl RewardsController {
let control_val = p_gain * error - d_gain * delta_error;

let last_inflation_amount = Decimal::from(last_inflation_amount);
let inflation = if last_inflation_amount + control_val > max_inflation {
let new_inflation_amount = last_inflation_amount + control_val;
let inflation = if new_inflation_amount > max_inflation {
max_inflation
} else if last_inflation_amount + control_val > dec!(0.0) {
last_inflation_amount + control_val
} else if new_inflation_amount > dec!(0.0) {
new_inflation_amount
} else {
dec!(0.0)
};
Expand Down