Skip to content

Commit 014f68f

Browse files
authored
Merge pull request #232 from terra-money/fix/remove-validator
Fix/remove validator
2 parents 1c71bbb + 69e5637 commit 014f68f

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ jobs:
2323
uses: golangci/golangci-lint-action@v3
2424
with:
2525
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
26-
version: latest
26+
version: v1.51.2
27+
args: --timeout 10m
28+
github-token: ${{ secrets.github_token }}
29+
if: env.GIT_DIFF

x/alliance/keeper/hooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ func (h Hooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) error {
1919
return nil
2020
}
2121

22-
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) error {
22+
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
23+
h.k.DeleteValidatorInfo(ctx, valAddr)
2324
h.k.QueueAssetRebalanceEvent(ctx)
2425
return nil
2526
}

x/alliance/keeper/reward.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,15 @@ func accumulateRewards(latestRewardHistories types.RewardHistories, rewardHistor
131131
// To calculate the number of rewards claimable, take reward_history * alliance_token_amount * reward_weight
132132
func (k Keeper) AddAssetsToRewardPool(ctx sdk.Context, from sdk.AccAddress, val types.AllianceValidator, coins sdk.Coins) error {
133133
rewardHistories := types.NewRewardHistories(val.GlobalRewardHistory)
134+
// We need some delegations before we can split rewards. Else rewards belong to no one and do nothing
135+
if len(val.TotalDelegatorShares) == 0 {
136+
return nil
137+
}
138+
134139
totalAssetWeight := k.totalAssetWeight(ctx, val)
135-
// We need some delegations before we can split rewards. Else rewards belong to no one
136140
if totalAssetWeight.IsZero() {
137-
return types.ErrZeroDelegations
141+
// Do nothing since there are no assets to distribute rewards to
142+
return nil
138143
}
139144

140145
for _, c := range coins {

x/alliance/keeper/tests/reward_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ func TestRewardPoolAndGlobalIndex(t *testing.T) {
6262
coin := app.BankKeeper.GetBalance(ctx, mintPoolAddr, "stake")
6363
require.Equal(t, sdk.NewCoin("stake", sdk.NewInt(4000_000)), coin)
6464

65-
// Transfer to reward pool without delegations will fail
66-
err = app.AllianceKeeper.AddAssetsToRewardPool(ctx, mintPoolAddr, val1, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000_000))))
67-
require.Error(t, err)
68-
6965
_, err = app.AllianceKeeper.Delegate(ctx, user1, val1, sdk.NewCoin(AllianceDenom, sdk.NewInt(1000_000)))
7066
require.NoError(t, err)
7167
assets := app.AllianceKeeper.GetAllAssets(ctx)

x/alliance/keeper/validator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ func (k Keeper) GetAllAllianceValidatorInfo(ctx sdk.Context) []types.AllianceVal
7272
}
7373
return infos
7474
}
75+
76+
func (k Keeper) DeleteValidatorInfo(ctx sdk.Context, valAddr sdk.ValAddress) {
77+
store := ctx.KVStore(k.storeKey)
78+
key := types.GetAllianceValidatorInfoKey(valAddr)
79+
store.Delete(key)
80+
}

x/alliance/tests/benchmark/benchmark_genesis.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)