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/remove validator #232

Merged
merged 3 commits into from
Sep 4, 2023
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
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.