Skip to content

Commit

Permalink
Merge pull request #232 from terra-money/fix/remove-validator
Browse files Browse the repository at this point in the history
Fix/remove validator
  • Loading branch information
emidev98 authored Sep 4, 2023
2 parents 1c71bbb + 69e5637 commit 014f68f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest
version: v1.51.2
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: env.GIT_DIFF
3 changes: 2 additions & 1 deletion x/alliance/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) error {
return nil
}

func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error {
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
h.k.DeleteValidatorInfo(ctx, valAddr)
h.k.QueueAssetRebalanceEvent(ctx)
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions x/alliance/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@ func accumulateRewards(latestRewardHistories types.RewardHistories, rewardHistor
// To calculate the number of rewards claimable, take reward_history * alliance_token_amount * reward_weight
func (k Keeper) AddAssetsToRewardPool(ctx sdk.Context, from sdk.AccAddress, val types.AllianceValidator, coins sdk.Coins) error {
rewardHistories := types.NewRewardHistories(val.GlobalRewardHistory)
// We need some delegations before we can split rewards. Else rewards belong to no one and do nothing
if len(val.TotalDelegatorShares) == 0 {
return nil
}

totalAssetWeight := k.totalAssetWeight(ctx, val)
// We need some delegations before we can split rewards. Else rewards belong to no one
if totalAssetWeight.IsZero() {
return types.ErrZeroDelegations
// Do nothing since there are no assets to distribute rewards to
return nil
}

for _, c := range coins {
Expand Down
4 changes: 0 additions & 4 deletions x/alliance/keeper/tests/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) {
coin := app.BankKeeper.GetBalance(ctx, mintPoolAddr, "stake")
require.Equal(t, sdk.NewCoin("stake", sdk.NewInt(4000_000)), coin)

// Transfer to reward pool without delegations will fail
err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000_000))))
require.Error(t, err)

_, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, sdk.NewInt(1000_000)))
require.NoError(t, err)
assets := app.AllianceKeeper.GetAllAssets(ctx)
Expand Down
6 changes: 6 additions & 0 deletions x/alliance/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ func (k Keeper) GetAllAllianceValidatorInfo(ctx sdk.Context) []types.AllianceVal
}
return infos
}

func (k Keeper) DeleteValidatorInfo(ctx sdk.Context, valAddr sdk.ValAddress) {
store := ctx.KVStore(k.storeKey)
key := types.GetAllianceValidatorInfoKey(valAddr)
store.Delete(key)
}
1 change: 0 additions & 1 deletion x/alliance/tests/benchmark/benchmark_genesis.json

This file was deleted.

0 comments on commit 014f68f

Please sign in to comment.