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

fix(emissions): add nil checks for reward distributions #2999

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ var (
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
emissionstypes.UndistributedTSSRewardsPool: nil,
}

// module accounts that are NOT allowed to receive tokens
Expand Down
2 changes: 1 addition & 1 deletion testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var moduleAccountPerms = map[string][]string{
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: {authtypes.Minter},
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
emissionstypes.UndistributedTSSRewardsPool: nil,
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ibccrosschaintypes.ModuleName: nil,
}
Expand Down
29 changes: 23 additions & 6 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,33 @@
func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
emissionPoolBalance := keeper.GetReservesFactor(ctx)

// reduce frequency of log messages
logEach10Blocks := func(message string) {
if ctx.BlockHeight()%10 == 0 {
ctx.Logger().Info(message)
} else {
ctx.Logger().Debug(message)
}
}

// Get the block rewards from the params
params, found := keeper.GetParams(ctx)
if !found {
ctx.Logger().Error("Params not found")
return
}
blockRewards := params.BlockRewardAmount

// skip if block rewards are nil or not positive
if blockRewards.IsNil() || !blockRewards.IsPositive() {
logEach10Blocks("Block rewards are nil or not positive")
return

Check warning on line 38 in x/emissions/abci.go

View check run for this annotation

Codecov / codecov/patch

x/emissions/abci.go#L37-L38

Added lines #L37 - L38 were not covered by tests
}

if blockRewards.GT(emissionPoolBalance) {
ctx.Logger().
Info(fmt.Sprintf("Block rewards %s are greater than emission pool balance %s", blockRewards.String(), emissionPoolBalance.String()))
logEach10Blocks(fmt.Sprintf("Block rewards %s are greater than emission pool balance %s",
blockRewards.String(), emissionPoolBalance.String()),
)
return
}

Expand All @@ -44,7 +61,7 @@
ctx.Logger().Error(fmt.Sprintf("Error while distributing observer rewards %s", err))
return
}
err = DistributeTssRewards(tmpCtx, tssSignerRewards, keeper.GetBankKeeper())
err = DistributeTSSRewards(tmpCtx, tssSignerRewards, keeper.GetBankKeeper())
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Error while distributing tss signer rewards %s", err))
return
Expand Down Expand Up @@ -166,9 +183,9 @@
return nil
}

// DistributeTssRewards trasferes the allocated rewards to the Undistributed Tss Rewards Pool.
// DistributeTSSRewards trasferes the allocated rewards to the Undistributed Tss Rewards Pool.
// This is done so that the reserves factor is properly calculated in the next block
func DistributeTssRewards(ctx sdk.Context, amount sdk.Int, bankKeeper types.BankKeeper) error {
func DistributeTSSRewards(ctx sdk.Context, amount sdk.Int, bankKeeper types.BankKeeper) error {
coin := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, amount))
return bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, types.UndistributedTssRewardsPool, coin)
return bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, types.UndistributedTSSRewardsPool, coin)
}
Loading
Loading