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

MASP rewards controller using token amounts instead of ratios #2460

Merged
merged 7 commits into from
Jan 30, 2024

Conversation

brentstone
Copy link
Collaborator

Describe your changes

Two slightly different rewards PD controllers are used for PoS and MASP now. The PoS one remains the same as before, while the MASP one no longer uses target ratios of locked tokens and instead relies on an absolute number of locked tokens.

Indicate on which release or other PRs this topic is based on

v0.30.2

Checklist before merging to draft

  • I have added a changelog
  • Git history is in acceptable state

@brentstone brentstone force-pushed the brent/refactor-shielded-inflation branch from c650800 to d315396 Compare January 26, 2024 22:20
@brentstone brentstone force-pushed the brent/refactor-shielded-inflation branch from 508fe9c to ad8b1cd Compare January 27, 2024 00:46
@brentstone brentstone force-pushed the brent/refactor-shielded-inflation branch from f67c267 to 0cdca59 Compare January 27, 2024 22:01
@brentstone brentstone mentioned this pull request Jan 27, 2024
@brentstone brentstone marked this pull request as ready for review January 27, 2024 22:04
brentstone added a commit that referenced this pull request Jan 27, 2024
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we abstract out the common logic in the rewards controller, since most of it is shared. We can live with this for now though.

/// Locked ratio for the given token
pub locked_ratio_target: Dec,
/// Target amount for the given token that is locked in the shielded pool
/// TODO: should this be a Uint or DenominatedAmount???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a uint, I think. Whatever the max supply of a token is (probably u256?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but we have the weird MASP denom splitting thing, better think carefully about this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uint (or Amount in the worst case) should be fine here. The inflation computations are done at a high level, and the low-level MASP denom splitting is taken care of by the MASP conversion logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think Uint is best, as it is clearly readable and digestible by humans, whereas Amount will not be in this scenario.

Comment on lines +165 to +173
// Max inflation amount for this epoch
let max_inflation = total_native * max_reward_rate / epochs_py;

// Intermediate values
let p_gain = p_gain_nom * max_reward_rate / epochs_py;
let d_gain = d_gain_nom * max_reward_rate / epochs_py;
let error = locked_amount_target - locked;
let delta_error = locked_amount_last - locked;
let control_val = p_gain * error - d_gain * delta_error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review these computations, to make sure they don't have values of 0

Fraccaman pushed a commit that referenced this pull request Jan 29, 2024
* origin/brent/refactor-shielded-inflation:
  fixup! rebuild masp proofs
  changelog: add #2460
  fix masp tests
  rebuild masp proofs
  need denom to write correct target inflation amount
  fix `Amount` param parsing in toml for PoS
  masp locked amount param: use u64 in config tomls and `Amount` in storage and usage
  separate masp and pos rewards controllers
Copy link
Contributor

@murisi murisi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Everything looks good to me. Just change locked_amount_target to be a Uint or an Amount.

/// Locked ratio for the given token
pub locked_ratio_target: Dec,
/// Target amount for the given token that is locked in the shielded pool
/// TODO: should this be a Uint or DenominatedAmount???
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uint (or Amount in the worst case) should be fine here. The inflation computations are done at a high level, and the low-level MASP denom splitting is taken care of by the MASP conversion logic.

storage.write(&masp_kp_gain_key(address), kp_gain_nom)?;
storage.write(&masp_kd_gain_key(address), kd_gain_nom)?;

let raw_target = Uint::from(*locked_amount_target)
Copy link
Contributor

@murisi murisi Jan 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

locked_amount_target should probably be a Uint or Amount. If that is the case, then this multiplication (or any other scaling operation) should not be needed. Such a change would probably imply that the denom parameter to this function is unnecessary.

@brentstone brentstone force-pushed the brent/refactor-shielded-inflation branch from 6632297 to a7be303 Compare January 29, 2024 21:18
brentstone added a commit that referenced this pull request Jan 29, 2024
* origin/brent/refactor-shielded-inflation:
  changelog: add #2460
  fix masp tests
  rebuild masp proofs
  need denom to write correct target inflation amount
  fix `Amount` param parsing in toml for PoS
  masp locked amount param: use u64 in config tomls and `Amount` in storage and usage
  separate masp and pos rewards controllers
brentstone added a commit that referenced this pull request Jan 29, 2024
* origin/brent/refactor-shielded-inflation:
  changelog: add #2460
  fix masp tests
  rebuild masp proofs
  need denom to write correct target inflation amount
  fix `Amount` param parsing in toml for PoS
  masp locked amount param: use u64 in config tomls and `Amount` in storage and usage
  separate masp and pos rewards controllers
@brentstone brentstone merged commit bd444a3 into main Jan 30, 2024
13 of 15 checks passed
@brentstone brentstone deleted the brent/refactor-shielded-inflation branch January 30, 2024 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants