Skip to content

Commit

Permalink
fix: avoir returning errors from mint begin blocker
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 17, 2025
1 parent e1920fc commit 32c935d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions x/mint/module/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mint
import (
"context"

"cosmossdk.io/errors"
errorsmod "cosmossdk.io/errors"
"github.com/allora-network/allora-chain/x/mint/keeper"
"github.com/allora-network/allora-chain/x/mint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -17,7 +17,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {

moduleParams, err := k.Params.Get(ctx)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get module params")
}
// if emissions are not enabled, do nothing
if !moduleParams.EmissionEnabled {
Expand All @@ -26,30 +26,30 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {
// Get the balance of the "ecosystem" module account
ecosystemBalance, err := k.GetEcosystemBalance(ctx, moduleParams.MintDenom)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get ecosystem balance")
}

blockHeight := uint64(sdkCtx.BlockHeight())

blockEmission, err := k.PreviousBlockEmission.Get(ctx)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get previous block emission")
}
ecosystemMintSupplyRemaining, err := k.GetEcosystemMintSupplyRemaining(sdkCtx, moduleParams)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get ecosystem mint supply remaining")
}
blocksPerMonth, err := k.GetParamsBlocksPerMonth(ctx)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get blocks per month")
}
vPercentADec, err := k.GetValidatorsVsAlloraPercentReward(ctx)
if err != nil {
return err
return errorsmod.Wrap(err, "could not get validators vs allora percent reward")
}
vPercent, err := vPercentADec.SdkLegacyDec()
if err != nil {
return err
return errorsmod.Wrap(err, "could not convert validators vs allora percent reward to legacy dec")
}
// every month on the first block of the month, update the emissions rate
if blockHeight%blocksPerMonth == 1 { // easier to test when genesis starts at 1
Expand All @@ -69,7 +69,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {
vPercent,
)
if err != nil {
return errors.Wrap(err, "error recalculating target emission")
return errorsmod.Wrap(err, "could not recalculate target emission")
}
}
// if the expected amount of emissions is greater than the balance of the ecosystem module account
Expand All @@ -82,16 +82,16 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {
coins := sdk.NewCoins(sdk.NewCoin(moduleParams.MintDenom, tokensToMint))
err = k.MintCoins(sdkCtx, coins)
if err != nil {
return err
return errorsmod.Wrap(err, "could not mint coins")
}
err = k.MoveCoinsFromMintToEcosystem(sdkCtx, coins)
if err != nil {
return err
return errorsmod.Wrap(err, "could not move coins from mint to ecosystem")
}
// then increment the recorded history of the amount of tokens minted
err = k.AddEcosystemTokensMinted(ctx, tokensToMint)
if err != nil {
return err
return errorsmod.Wrap(err, "could not add ecosystem tokens minted")
}
types.EmitNewEcosystemTokenMintSetEvent(sdkCtx, blockHeight, tokensToMint)
}
Expand All @@ -105,11 +105,11 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {
coinsAlloraRewards := sdk.NewCoins(sdk.NewCoin(moduleParams.MintDenom, alloraRewardsCut))
err = k.PayValidatorsFromEcosystem(sdkCtx, coinsValidator)
if err != nil {
return err
return errorsmod.Wrap(err, "could not pay validators from ecosystem")
}
err = k.PayAlloraRewardsFromEcosystem(sdkCtx, coinsAlloraRewards)
if err != nil {
return err
return errorsmod.Wrap(err, "could not pay allora rewards from ecosystem")
}
types.EmitNewRewardCurrentBlockEmissionEvent(sdkCtx, blockHeight, alloraRewardsCut)
return nil
Expand Down
2 changes: 1 addition & 1 deletion x/mint/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (am AppModule) BeginBlock(ctx context.Context) error {
if err != nil {
am.keeper.Logger(ctx).Error("BeginBlocker error! ", err)
}
return err
return nil
}

//
Expand Down

0 comments on commit 32c935d

Please sign in to comment.