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

refactor(distribution)!: make FeePool state use collections #16302

Merged
merged 7 commits into from
May 26, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* `SigVerifiableTx.GetSigners()` now returns `([][]byte, error)` instead of `[]sdk.AccAddress`.
* (x/authx) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`.
* (x/gov) [#15284](https://github.com/cosmos/cosmos-sdk/pull/15284) `NewKeeper` now requires `codec.Codec`.
* (x/distribution) [](https://github.com/cosmos/cosmos-sdk/pull/16302) Use collections for FeePool state management.
* removed: keeper `GetFeePool`, `SetFeePool`, `GetFeePoolCommunityCoins`

### Client Breaking Changes

Expand Down
4 changes: 2 additions & 2 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
if err != nil {
panic(err)
}
feePool, err := app.DistrKeeper.GetFeePool(ctx)
feePool, err := app.DistrKeeper.FeePool.Get(ctx)
if err != nil {
panic(err)
}
feePool.CommunityPool = feePool.CommunityPool.Add(scraps...)
if err := app.DistrKeeper.SetFeePool(ctx, feePool); err != nil {
if err := app.DistrKeeper.FeePool.Set(ctx, feePool); err != nil {
panic(err)
}

Expand Down
46 changes: 23 additions & 23 deletions tests/integration/distribution/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGRPCParams(t *testing.T) {
t.Parallel()
f := initFixture(t)

f.distrKeeper.Params.Set(f.sdkCtx, types.DefaultParams())
assert.NilError(t, f.distrKeeper.Params.Set(f.sdkCtx, types.DefaultParams()))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
Expand Down Expand Up @@ -77,10 +77,10 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {

// set module account coins
initTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)))
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))

// Set default staking params
f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams())
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
Expand All @@ -92,7 +92,7 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {

// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds)))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
Expand Down Expand Up @@ -120,7 +120,7 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {
},
{
name: "invalid address",
msg: &types.QueryValidatorOutstandingRewardsRequest{ValidatorAddress: sdk.ValAddress([]byte("addr1_______________")).String()},
msg: &types.QueryValidatorOutstandingRewardsRequest{ValidatorAddress: sdk.ValAddress("addr1_______________").String()},
expPass: false,
expErrMsg: "validator does not exist",
},
Expand Down Expand Up @@ -154,25 +154,25 @@ func TestGRPCValidatorCommission(t *testing.T) {

// set module account coins
initTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)))
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))

// Set default staking params
f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams())
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)

// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds)))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), math.LegacyNewDec(0))
tstaking.CreateValidator(f.valAddr, valConsPk0, sdk.NewInt(initialStake), true)

commission := sdk.DecCoins{sdk.DecCoin{Denom: "token1", Amount: math.LegacyNewDec(4)}, {Denom: "token2", Amount: math.LegacyNewDec(2)}}
f.distrKeeper.SetValidatorAccumulatedCommission(f.sdkCtx, f.valAddr, types.ValidatorAccumulatedCommission{Commission: commission})
assert.NilError(t, f.distrKeeper.SetValidatorAccumulatedCommission(f.sdkCtx, f.valAddr, types.ValidatorAccumulatedCommission{Commission: commission}))

testCases := []struct {
name string
Expand All @@ -188,7 +188,7 @@ func TestGRPCValidatorCommission(t *testing.T) {
},
{
name: "invalid validator",
msg: &types.QueryValidatorCommissionRequest{ValidatorAddress: sdk.ValAddress([]byte("addr1_______________")).String()},
msg: &types.QueryValidatorCommissionRequest{ValidatorAddress: sdk.ValAddress("addr1_______________").String()},
expPass: false,
expErrMsg: "validator does not exist",
},
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestGRPCValidatorSlashes(t *testing.T) {
}

for i, slash := range slashes {
f.distrKeeper.SetValidatorSlashEvent(f.sdkCtx, f.valAddr, uint64(i+2), 0, slash)
assert.NilError(t, f.distrKeeper.SetValidatorSlashEvent(f.sdkCtx, f.valAddr, uint64(i+2), 0, slash))
}

var (
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestGRPCDelegatorWithdrawAddress(t *testing.T) {
t.Parallel()
f := initFixture(t)

f.distrKeeper.Params.Set(f.sdkCtx, types.DefaultParams())
assert.NilError(t, f.distrKeeper.Params.Set(f.sdkCtx, types.DefaultParams()))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
Expand Down Expand Up @@ -418,9 +418,9 @@ func TestGRPCCommunityPool(t *testing.T) {
t.Parallel()
f := initFixture(t)

f.distrKeeper.SetFeePool(f.sdkCtx, types.FeePool{
assert.NilError(t, f.distrKeeper.FeePool.Set(f.sdkCtx, types.FeePool{
CommunityPool: sdk.NewDecCoins(sdk.DecCoin{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(0)}),
})
}))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
Expand Down Expand Up @@ -474,16 +474,16 @@ func TestGRPCDelegationRewards(t *testing.T) {
t.Parallel()
f := initFixture(t)

f.distrKeeper.SetFeePool(f.sdkCtx, types.FeePool{
assert.NilError(t, f.distrKeeper.FeePool.Set(f.sdkCtx, types.FeePool{
CommunityPool: sdk.NewDecCoins(sdk.DecCoin{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(1000)}),
})
}))

// set module account coins
initTokens := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens)))
assert.NilError(t, f.bankKeeper.MintCoins(f.sdkCtx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))))

// Set default staking params
f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams())
assert.NilError(t, f.stakingKeeper.SetParams(f.sdkCtx, stakingtypes.DefaultParams()))

qr := f.app.QueryHelper()
queryClient := types.NewQueryClient(qr)
Expand All @@ -494,7 +494,7 @@ func TestGRPCDelegationRewards(t *testing.T) {

// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds)))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
Expand All @@ -509,16 +509,16 @@ func TestGRPCDelegationRewards(t *testing.T) {
validator, issuedShares := val.AddTokensFromDel(delTokens)
delegation := stakingtypes.NewDelegation(delAddr, f.valAddr, issuedShares)
f.stakingKeeper.SetDelegation(f.sdkCtx, delegation)
f.distrKeeper.SetDelegatorStartingInfo(f.sdkCtx, validator.GetOperator(), delAddr, types.NewDelegatorStartingInfo(2, math.LegacyNewDec(initialStake), 20))
assert.NilError(t, f.distrKeeper.SetDelegatorStartingInfo(f.sdkCtx, validator.GetOperator(), delAddr, types.NewDelegatorStartingInfo(2, math.LegacyNewDec(initialStake), 20)))

// setup validator rewards
decCoins := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, math.LegacyOneDec())}
historicalRewards := types.NewValidatorHistoricalRewards(decCoins, 2)
f.distrKeeper.SetValidatorHistoricalRewards(f.sdkCtx, validator.GetOperator(), 2, historicalRewards)
assert.NilError(t, f.distrKeeper.SetValidatorHistoricalRewards(f.sdkCtx, validator.GetOperator(), 2, historicalRewards))
// setup current rewards and outstanding rewards
currentRewards := types.NewValidatorCurrentRewards(decCoins, 3)
f.distrKeeper.SetValidatorCurrentRewards(f.sdkCtx, f.valAddr, currentRewards)
f.distrKeeper.SetValidatorOutstandingRewards(f.sdkCtx, f.valAddr, types.ValidatorOutstandingRewards{Rewards: decCoins})
assert.NilError(t, f.distrKeeper.SetValidatorCurrentRewards(f.sdkCtx, f.valAddr, currentRewards))
assert.NilError(t, f.distrKeeper.SetValidatorOutstandingRewards(f.sdkCtx, f.valAddr, types.ValidatorOutstandingRewards{Rewards: decCoins}))

expRes := &types.QueryDelegationRewardsResponse{
Rewards: sdk.DecCoins{sdk.DecCoin{Denom: sdk.DefaultBondDenom, Amount: math.LegacyNewDec(initialStake / 10)}},
Expand Down
Loading