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

refactor(x/mint): avoid over-allocation and then burning dev rewards from mint module account #2025

Closed
Tracked by #4622 ...
p0mvn opened this issue Jul 12, 2022 · 2 comments

Comments

@p0mvn
Copy link
Member

p0mvn commented Jul 12, 2022

Background

Currently, we mint the number of tokens equal to epoch provisions:

// mint coins, update supply
mintedCoin := minter.EpochProvision(params)
mintedCoins := sdk.NewCoins(mintedCoin)
// We over-allocate by the developer vesting portion, and burn this later
err := k.MintCoins(ctx, mintedCoins)

Epoch provisions include the developer rewards proportion. However, the developer rewards must be allocated from the developer vesting module account. As a result, we over-allocate from mint module account.

To mitigate, we instead burn tokens here while distributing them to dev reward receivers:

// This is supposed to come from the developer vesting module address, not the mint module address
// we over-allocated to the mint module address earlier though, so we burn it right here.
if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, devRewardCoins); err != nil {

This is called temporal decomposition where execution order is reflected in the code structure:

Suggested Design

Instead, we should be minting the correct amount in the first place where we exclude the developer rewards from being minted by the mint module account. By doing so, we would avoid having to later burn the amount.

The suggested design should reduce coupling and remove the temporal decomposition code smell.

Acceptance Criteria

  • mint module account does not mint developer rewards
  • developer rewards are only minted by the developer vesting module account
  • unit test added to cover all new logic
@p0mvn
Copy link
Member Author

p0mvn commented Jul 12, 2022

This is currently blocked by #1916 and #1917 . Making this issue to keep track of.

There are other constraints that should be considered after the blocking issues are addressed.

For example, one constraint is that DistributedMintedCoin:

func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error {

assumes that mintedCoin includes the dev rewards amount. It might have to be refactored further to change the assumption.

@stackman27
Copy link
Contributor

I can take a shot at this, i'll follow up with the progress in #1916 and #1917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants