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

R4R: Enable/disable withdraw addresses with a parameter #3292

Merged
merged 52 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
22a9d7c
Refactor old distribution code in prep for F1
cwgoes Dec 13, 2018
ad90d2c
Update PENDING.md
cwgoes Dec 13, 2018
667f83c
Types; basic layout; BeginBlock allocation
cwgoes Dec 14, 2018
c0babcc
Periods; hooks; handler; simulation
cwgoes Dec 14, 2018
ff6ffe5
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 2, 2019
db781b8
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 3, 2019
20861f8
A few bug fixes; simulation testing; testcases
cwgoes Jan 4, 2019
459a7ab
Import/export full distribution state
cwgoes Jan 8, 2019
e9a3f6f
Actually withdraw validator commission
cwgoes Jan 8, 2019
93612a0
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 9, 2019
bfb231e
Add TODOs in response to @ValarDragon comments
cwgoes Jan 9, 2019
1d3dfc9
Allocation tests
cwgoes Jan 9, 2019
284c3e5
Calculation tests in progress
cwgoes Jan 9, 2019
78683de
Add multi-delegator calculation test
cwgoes Jan 9, 2019
2057328
Add test for calculation after a slash
cwgoes Jan 9, 2019
da50794
Iterate over all validators, since we don't force commission-withdraw
cwgoes Jan 9, 2019
c87cc3b
Fix minor one-off bug; add testcase
cwgoes Jan 9, 2019
0968752
Include error bound in simulation invariant
cwgoes Jan 9, 2019
135a007
Remove unused testcase
cwgoes Jan 9, 2019
660ead7
'make format'
cwgoes Jan 9, 2019
6d91b02
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 9, 2019
55e6d57
Clear historical rewards on export-for-zero-height
cwgoes Jan 10, 2019
800f622
Add comment about implicit key height
cwgoes Jan 10, 2019
1bb8714
Fix linter
cwgoes Jan 10, 2019
93ec057
Add multi-delegator multi-slash test
cwgoes Jan 10, 2019
c623d47
Wait 2 blocks on CLI test (?)
cwgoes Jan 10, 2019
0a758f2
Remove CanWithdrawInvariant from runtime (a bit expensive)
cwgoes Jan 10, 2019
d233f6d
Reset block height for zero-height export
cwgoes Jan 10, 2019
80c3d87
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 10, 2019
89655bc
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 14, 2019
e3a9acf
'make format'
cwgoes Jan 14, 2019
d9f7ace
Simulation debugging
cwgoes Jan 14, 2019
9341bf6
Enable/disable withdraw addresses with a parameter
cwgoes Jan 14, 2019
4ae5959
Testcase; fix genesis
cwgoes Jan 14, 2019
c9a4978
Simulation fixes; hopefully
cwgoes Jan 14, 2019
adb5a24
Merge branch 'cwgoes/mclaren-mcl33-first-pass' into cwgoes/disable-wi…
cwgoes Jan 14, 2019
d596bd3
Ensure no divide-by-zero
cwgoes Jan 14, 2019
3e61732
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 14, 2019
859163f
Merge branch 'cwgoes/mclaren-mcl33-first-pass' into cwgoes/disable-wi…
cwgoes Jan 14, 2019
702dc3b
Update x/distribution/keeper/allocation.go
alexanderbez Jan 15, 2019
de687ab
Address @alexanderbez comments
cwgoes Jan 15, 2019
199df87
Update x/distribution/keeper/calculation.go
alexanderbez Jan 15, 2019
eef4479
Multiline signature; comments
cwgoes Jan 15, 2019
1866de0
Clarify comment
cwgoes Jan 15, 2019
59ff57d
Address @rigelrozanski comments
cwgoes Jan 16, 2019
6ef7ef0
Calculate expected test outputs; lowercase comments
cwgoes Jan 16, 2019
0850de4
Add multi-delegator, multi-withdraw testcase
cwgoes Jan 16, 2019
2a19018
Merge branch 'develop' into cwgoes/mclaren-mcl33-first-pass
cwgoes Jan 16, 2019
9b35d49
Initialize distribution state first (needed for hooks)
cwgoes Jan 16, 2019
4b64f53
Merge branch 'cwgoes/mclaren-mcl33-first-pass' into cwgoes/disable-wi…
cwgoes Jan 16, 2019
51bd7c8
Merge branch 'develop' into cwgoes/disable-withdraw-addresses
cwgoes Jan 16, 2019
5e444b0
Enable withdraw-addresses by default
cwgoes Jan 16, 2019
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: 3 additions & 2 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ BREAKING CHANGES
* [\#3064](https://github.com/cosmos/cosmos-sdk/issues/3064) Sanitize `sdk.Coin` denom. Coins denoms are now case insensitive, i.e. 100fooToken equals to 100FOOTOKEN.
* [\#3195](https://github.com/cosmos/cosmos-sdk/issues/3195) Allows custom configuration for syncable strategy
* [\#3242](https://github.com/cosmos/cosmos-sdk/issues/3242) Fix infinite gas
meter utilization during aborted ante handler executions.
* [staking] \#2222 `/stake` -> `/staking` module rename
meter utilization during aborted ante handler executions.
* [\#2222] [x/staking] `/stake` -> `/staking` module rename
* \#3292 [x/distribution] Enable or disable withdraw addresses with a parameter in the param store
* [staking] \#1402 Redelegation and unbonding-delegation structs changed to include multiple an array of entries

* Tendermint
Expand Down
2 changes: 0 additions & 2 deletions cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"io"

"github.com/cosmos/cosmos-sdk/store"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store"

Expand Down
6 changes: 4 additions & 2 deletions x/distribution/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
keeper.SetCommunityTax(ctx, data.CommunityTax)
keeper.SetBaseProposerReward(ctx, data.BaseProposerReward)
keeper.SetBonusProposerReward(ctx, data.BonusProposerReward)
keeper.SetWithdrawAddrEnabled(ctx, data.WithdrawAddrEnabled)
for _, dwi := range data.DelegatorWithdrawInfos {
keeper.SetDelegatorWithdrawAddr(ctx, dwi.DelegatorAddr, dwi.WithdrawAddr)
}
Expand Down Expand Up @@ -39,6 +40,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
communityTax := keeper.GetCommunityTax(ctx)
baseProposerRewards := keeper.GetBaseProposerReward(ctx)
bonusProposerRewards := keeper.GetBonusProposerReward(ctx)
withdrawAddrEnabled := keeper.GetWithdrawAddrEnabled(ctx)
dwi := make([]types.DelegatorWithdrawInfo, 0)
keeper.IterateDelegatorWithdrawAddrs(ctx, func(del sdk.AccAddress, addr sdk.AccAddress) (stop bool) {
dwi = append(dwi, types.DelegatorWithdrawInfo{
Expand Down Expand Up @@ -102,6 +104,6 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
return false
},
)
return types.NewGenesisState(feePool, communityTax, baseProposerRewards, bonusProposerRewards, dwi, pp, outstanding,
acc, his, cur, dels, slashes)
return types.NewGenesisState(feePool, communityTax, baseProposerRewards, bonusProposerRewards, withdrawAddrEnabled,
dwi, pp, outstanding, acc, his, cur, dels, slashes)
}
5 changes: 4 additions & 1 deletion x/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func NewHandler(k keeper.Keeper) sdk.Handler {

func handleMsgModifyWithdrawAddress(ctx sdk.Context, msg types.MsgSetWithdrawAddress, k keeper.Keeper) sdk.Result {

k.SetDelegatorWithdrawAddr(ctx, msg.DelegatorAddr, msg.WithdrawAddr)
err := k.SetWithdrawAddr(ctx, msg.DelegatorAddr, msg.WithdrawAddr)
if err != nil {
return err.Result()
}

tags := sdk.NewTags(
tags.Delegator, []byte(msg.DelegatorAddr.String()),
Expand Down
11 changes: 11 additions & 0 deletions x/distribution/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey, paramSpace params.Subspace, c
return keeper
}

// set withdraw address
func (k Keeper) SetWithdrawAddr(ctx sdk.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) sdk.Error {
if !k.GetWithdrawAddrEnabled(ctx) {
return types.ErrSetWithdrawAddrDisabled(k.codespace)
}

k.SetDelegatorWithdrawAddr(ctx, delegatorAddr, withdrawAddr)

return nil
}

// withdraw rewards from a delegation
func (k Keeper) WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) sdk.Error {
val := k.stakingKeeper.Validator(ctx, valAddr)
Expand Down
14 changes: 14 additions & 0 deletions x/distribution/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import (
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

func TestSetWithdrawAddr(t *testing.T) {
ctx, _, keeper, _, _ := CreateTestInputDefault(t, false, 1000)

keeper.SetWithdrawAddrEnabled(ctx, false)

err := keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
require.NotNil(t, err)

keeper.SetWithdrawAddrEnabled(ctx, true)

err = keeper.SetWithdrawAddr(ctx, delAddr1, delAddr2)
require.Nil(t, err)
}

func TestWithdrawValidatorCommission(t *testing.T) {
ctx, ak, keeper, _, _ := CreateTestInputDefault(t, false, 1000)

Expand Down
1 change: 1 addition & 0 deletions x/distribution/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
ParamStoreKeyCommunityTax = []byte("communitytax")
ParamStoreKeyBaseProposerReward = []byte("baseproposerreward")
ParamStoreKeyBonusProposerReward = []byte("bonusproposerreward")
ParamStoreKeyWithdrawAddrEnabled = []byte("withdrawaddrenabled")
)

// gets an address from a delegator's withdraw info key
Expand Down
14 changes: 14 additions & 0 deletions x/distribution/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func ParamTypeTable() params.TypeTable {
ParamStoreKeyCommunityTax, sdk.Dec{},
ParamStoreKeyBaseProposerReward, sdk.Dec{},
ParamStoreKeyBonusProposerReward, sdk.Dec{},
ParamStoreKeyWithdrawAddrEnabled, false,
)
}

Expand Down Expand Up @@ -52,3 +53,16 @@ func (k Keeper) GetBonusProposerReward(ctx sdk.Context) sdk.Dec {
func (k Keeper) SetBonusProposerReward(ctx sdk.Context, percent sdk.Dec) {
k.paramSpace.Set(ctx, ParamStoreKeyBonusProposerReward, &percent)
}

// returns the current WithdrawAddrEnabled
// nolint: errcheck
func (k Keeper) GetWithdrawAddrEnabled(ctx sdk.Context) bool {
var enabled bool
k.paramSpace.Get(ctx, ParamStoreKeyWithdrawAddrEnabled, &enabled)
return enabled
}

// nolint: errcheck
func (k Keeper) SetWithdrawAddrEnabled(ctx sdk.Context, enabled bool) {
k.paramSpace.Set(ctx, ParamStoreKeyWithdrawAddrEnabled, &enabled)
}
12 changes: 8 additions & 4 deletions x/distribution/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
type CodeType = sdk.CodeType

const (
DefaultCodespace sdk.CodespaceType = "DISTR"
CodeInvalidInput CodeType = 103
CodeNoDistributionInfo CodeType = 104
CodeNoValidatorCommission CodeType = 105
DefaultCodespace sdk.CodespaceType = "DISTR"
CodeInvalidInput CodeType = 103
CodeNoDistributionInfo CodeType = 104
CodeNoValidatorCommission CodeType = 105
CodeSetWithdrawAddrDisabled CodeType = 106
)

func ErrNilDelegatorAddr(codespace sdk.CodespaceType) sdk.Error {
Expand All @@ -32,3 +33,6 @@ func ErrNoValidatorDistInfo(codespace sdk.CodespaceType) sdk.Error {
func ErrNoValidatorCommission(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeNoValidatorCommission, "no validator commission to withdraw")
}
func ErrSetWithdrawAddrDisabled(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeSetWithdrawAddrDisabled, "set withdraw address disabled")
}
5 changes: 4 additions & 1 deletion x/distribution/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type GenesisState struct {
CommunityTax sdk.Dec `json:"community_tax"`
BaseProposerReward sdk.Dec `json:"base_proposer_reward"`
BonusProposerReward sdk.Dec `json:"bonus_proposer_reward"`
WithdrawAddrEnabled bool `json:"withdraw_addr_enabled"`
DelegatorWithdrawInfos []DelegatorWithdrawInfo `json:"delegator_withdraw_infos"`
PreviousProposer sdk.ConsAddress `json:"previous_proposer"`
OutstandingRewards sdk.DecCoins `json:"outstanding_rewards"`
Expand All @@ -63,7 +64,7 @@ type GenesisState struct {
}

func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusProposerReward sdk.Dec,
dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r OutstandingRewards,
withdrawAddrEnabled bool, dwis []DelegatorWithdrawInfo, pp sdk.ConsAddress, r OutstandingRewards,
acc []ValidatorAccumulatedCommissionRecord, historical []ValidatorHistoricalRewardsRecord,
cur []ValidatorCurrentRewardsRecord, dels []DelegatorStartingInfoRecord,
slashes []ValidatorSlashEventRecord) GenesisState {
Expand All @@ -73,6 +74,7 @@ func NewGenesisState(feePool FeePool, communityTax, baseProposerReward, bonusPro
CommunityTax: communityTax,
BaseProposerReward: baseProposerReward,
BonusProposerReward: bonusProposerReward,
WithdrawAddrEnabled: withdrawAddrEnabled,
DelegatorWithdrawInfos: dwis,
PreviousProposer: pp,
OutstandingRewards: r,
Expand All @@ -91,6 +93,7 @@ func DefaultGenesisState() GenesisState {
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
WithdrawAddrEnabled: true,
DelegatorWithdrawInfos: []DelegatorWithdrawInfo{},
PreviousProposer: nil,
OutstandingRewards: sdk.DecCoins{},
Expand Down