Skip to content

Commit

Permalink
revert: Revert "feat: staking config (#10988)" (#11446)
Browse files Browse the repository at this point in the history
* Revert "feat: staking config (#10988)"

This reverts commit 5e9656f.

* remove docs
  • Loading branch information
tac0turtle authored Mar 24, 2022
1 parent d7ba5d2 commit 66ca3e8
Show file tree
Hide file tree
Showing 46 changed files with 139 additions and 190 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#11124](https://github.com/cosmos/cosmos-sdk/pull/11124) Add `GetAllVersions` to application store
* (x/authz) [\#10447](https://github.com/cosmos/cosmos-sdk/pull/10447) authz `NewGrant` takes a new argument: block time, to correctly validate expire time.
* [\#10961](https://github.com/cosmos/cosmos-sdk/pull/10961) Support third-party modules to add extension snapshots to state-sync.
* [\#10988](https://github.com/cosmos/cosmos-sdk/pull/10988) Removes sdk.PowerReduction as a global and pass it directly to the staking keeper on creation.
- Deletes `types/staking.go` and moves the functions to `x/staking/types/power_reduction.go`
* [\#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) `types/errors.New` now is an alias for `types/errors.Register` and should only be used in initialization code.


### Client Breaking Changes

* [\#11089](https://github.com/cosmos/cosmos-sdk/pull/11089]) interacting with the node through `grpc.Dial` requires clients to pass a codec refer to [doc](docs/run-node/interact-node.md).
Expand Down
8 changes: 1 addition & 7 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,8 @@ func NewSimApp(
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
)

stakingConfig := stakingtypes.DefaultConfig()
/*
Example of setting staking params:
stakingConfig.PowerReduction = sdk.NewIntFromUint64(10)
*/
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), stakingConfig,
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
Expand Down
6 changes: 3 additions & 3 deletions simapp/simd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func initTestnetFiles(
return err
}

accTokens := sdk.NewIntFromUint64(1000_000_000)
accStakingTokens := sdk.NewIntFromUint64(500_000_000)
accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)
accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction)
coins := sdk.Coins{
sdk.NewCoin("testtoken", accTokens),
sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens),
Expand All @@ -292,7 +292,7 @@ func initTestnetFiles(
genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))

valTokens := sdk.NewIntFromUint64(100_000_000)
valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
Expand Down
2 changes: 1 addition & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func genesisStateWithValSet(t *testing.T,
validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := stakingtypes.DefaultConfig().PowerReduction
bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
Expand Down
6 changes: 3 additions & 3 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func DefaultConfig() Config {
NumValidators: 4,
BondDenom: sdk.DefaultBondDenom,
MinGasPrices: fmt.Sprintf("0.000006%s", sdk.DefaultBondDenom),
AccountTokens: sdk.NewIntFromUint64(1000_000_000),
StakingTokens: sdk.NewIntFromUint64(500_000_000),
BondedTokens: sdk.NewIntFromUint64(100_000_000),
AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction),
StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction),
BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction),
PruningStrategy: storetypes.PruningOptionNothing,
CleanupDir: true,
SigningAlgo: string(hd.Secp256k1Type),
Expand Down
28 changes: 0 additions & 28 deletions testutil/token.go

This file was deleted.

2 changes: 1 addition & 1 deletion types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (m *Manager) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, genesisData

// a chain must initialize with a non-empty validator set
if len(validatorUpdates) == 0 {
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction, found in x/staking/types/config.go"))
panic(fmt.Sprintf("validator set is empty after InitGenesis, please ensure at least one validator is initialized with a delegation greater than or equal to the DefaultPowerReduction (%d)", sdk.DefaultPowerReduction))
}

return abci.ResponseInitChain{
Expand Down
13 changes: 13 additions & 0 deletions types/globals.go → types/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ const (
// https://tendermint.com/docs/spec/abci/apps.html#endblock
ValidatorUpdateDelay int64 = 1
)

// DefaultPowerReduction is the default amount of staking tokens required for 1 unit of consensus-engine power
var DefaultPowerReduction = NewIntFromUint64(1000000)

// TokensToConsensusPower - convert input tokens to potential consensus-engine power
func TokensToConsensusPower(tokens Int, powerReduction Int) int64 {
return (tokens.Quo(powerReduction)).Int64()
}

// TokensFromConsensusPower - convert input power to tokens
func TokensFromConsensusPower(power int64, powerReduction Int) Int {
return NewInt(power).Mul(powerReduction)
}
26 changes: 26 additions & 0 deletions types/staking_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type stakingTestSuite struct {
suite.Suite
}

func TestStakingTestSuite(t *testing.T) {
suite.Run(t, new(stakingTestSuite))
}

func (s *stakingTestSuite) SetupSuite() {
s.T().Parallel()
}

func (s *stakingTestSuite) TestTokensToConsensusPower() {
s.Require().Equal(int64(0), sdk.TokensToConsensusPower(sdk.NewInt(999_999), sdk.DefaultPowerReduction))
s.Require().Equal(int64(1), sdk.TokensToConsensusPower(sdk.NewInt(1_000_000), sdk.DefaultPowerReduction))
}
4 changes: 2 additions & 2 deletions x/auth/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ func (s *IntegrationTestSuite) TestCLISendGenerateSignAndBroadcast() {
account, err := val1.ClientCtx.Keyring.Key("newAccount")
s.Require().NoError(err)

sendTokens := sdk.NewCoin(s.cfg.BondDenom, testutil.TokensFromConsensusPower(10, testutil.DefaultpowerReduction))
sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))

addr, err := account.GetAddress()
s.Require().NoError(err)
Expand Down Expand Up @@ -849,7 +849,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignInsufficientCosigners() {
func (s *IntegrationTestSuite) TestCLIEncode() {
val1 := s.network.Validators[0]

sendTokens := sdk.NewCoin(s.cfg.BondDenom, testutil.TokensFromConsensusPower(10, testutil.DefaultpowerReduction))
sendTokens := sdk.NewCoin(s.cfg.BondDenom, sdk.TokensFromConsensusPower(10, sdk.DefaultPowerReduction))

normalGeneratedTx, err := s.createBankMsg(
val1, val1.Address,
Expand Down
4 changes: 1 addition & 3 deletions x/auth/migrations/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -658,7 +657,7 @@ func dirtyTrackingFields(ctx sdk.Context, vesting exported.VestingAccount, app *
}

func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers int64) (sdk.AccAddress, sdk.ValAddress) {
valTokens := testutil.TokensFromConsensusPower(powers, testutil.DefaultpowerReduction)
valTokens := sdk.TokensFromConsensusPower(powers, sdk.DefaultPowerReduction)
addrs := simapp.AddTestAddrsIncremental(app, ctx, 1, valTokens)
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
pks := simapp.CreateTestPubKeys(1)
Expand All @@ -670,7 +669,6 @@ func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers i
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
stakingtypes.DefaultConfig(),
)

val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
Expand Down
3 changes: 1 addition & 2 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
gocontext "context"
"fmt"

sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
Expand Down Expand Up @@ -325,7 +324,7 @@ func (suite *IntegrationTestSuite) TestGRPCDenomOwners() {

bal := sdk.NewCoins(sdk.NewCoin(
sdk.DefaultBondDenom,
sdktestutil.TokensFromConsensusPower(initialPower/10, sdktestutil.DefaultpowerReduction),
sdk.TokensFromConsensusPower(initialPower/10, sdk.DefaultPowerReduction),
))
suite.Require().NoError(keeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, acc.GetAddress(), bal))
}
Expand Down
4 changes: 2 additions & 2 deletions x/bank/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -41,7 +40,8 @@ var (
randomPermAcc = authtypes.NewEmptyModuleAccount(randomPerm, "random")

// The default power validators are initialized to have within tests
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdktestutil.TokensFromConsensusPower(initialPower, sdktestutil.DefaultpowerReduction)))
initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
)

func newFooCoin(amt int64) sdk.Coin {
Expand Down
8 changes: 5 additions & 3 deletions x/bank/types/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
)
Expand Down Expand Up @@ -142,7 +141,8 @@ func TestBalance_GetAddress(t *testing.T) {

func TestSanitizeBalances(t *testing.T) {
// 1. Generate balances
coin := sdk.NewCoin("benchcoin", testutil.TokensFromConsensusPower(81, testutil.DefaultpowerReduction))
tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction)
coin := sdk.NewCoin("benchcoin", tokens)
coins := sdk.Coins{coin}
addrs, _ := makeRandomAddressesAndPublicKeys(20)

Expand Down Expand Up @@ -193,7 +193,9 @@ func BenchmarkSanitizeBalances1000(b *testing.B) {

func benchmarkSanitizeBalances(b *testing.B, nAddresses int) {
b.ReportAllocs()
coins := sdk.NewCoins(sdk.NewCoin("benchcoin", testutil.TokensFromConsensusPower(81, testutil.DefaultpowerReduction)))
tokens := sdk.TokensFromConsensusPower(81, sdk.DefaultPowerReduction)
coin := sdk.NewCoin("benchcoin", tokens)
coins := sdk.Coins{coin}
addrs, _ := makeRandomAddressesAndPublicKeys(nAddresses)

b.ResetTimer()
Expand Down
6 changes: 3 additions & 3 deletions x/evidence/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"fmt"
"time"

minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"

"github.com/stretchr/testify/suite"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/evidence/exported"
"github.com/cosmos/cosmos-sdk/x/evidence/keeper"
"github.com/cosmos/cosmos-sdk/x/evidence/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
)

var (
Expand All @@ -35,7 +35,7 @@ var (
}

// The default power validators are initialized to have within tests
initAmt = testutil.TokensFromConsensusPower(200, testutil.DefaultpowerReduction)
initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
)

Expand Down
3 changes: 1 addition & 2 deletions x/feegrant/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/cosmos/cosmos-sdk/simapp"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
Expand Down Expand Up @@ -39,7 +38,7 @@ func (suite *SimTestSuite) SetupTest() {
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
accounts := simtypes.RandomAccounts(r, n)

initAmt := sdktestutil.TokensFromConsensusPower(200, sdktestutil.DefaultpowerReduction)
initAmt := sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))

// add coins to the accounts
Expand Down
3 changes: 1 addition & 2 deletions x/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/gov/keeper"
Expand Down Expand Up @@ -374,7 +373,7 @@ func createValidators(t *testing.T, stakingMsgSvr stakingtypes.MsgServer, ctx sd
require.True(t, len(addrs) <= len(pubkeys), "Not enough pubkeys specified at top of file.")

for i := 0; i < len(addrs); i++ {
valTokens := testutil.TokensFromConsensusPower(powerAmt[i], testutil.DefaultpowerReduction)
valTokens := sdk.TokensFromConsensusPower(powerAmt[i], sdk.DefaultPowerReduction)
valCreateMsg, err := stakingtypes.NewMsgCreateValidator(
addrs[i], pubkeys[i], sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
TestDescription, TestCommissionRates, sdk.OneInt(),
Expand Down
3 changes: 1 addition & 2 deletions x/gov/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand All @@ -19,7 +18,7 @@ import (
)

var (
valTokens = testutil.TokensFromConsensusPower(42, testutil.DefaultpowerReduction)
valTokens = sdk.TokensFromConsensusPower(42, sdk.DefaultPowerReduction)
TestProposal = v1beta1.NewTextProposal("Test", "description")
TestDescription = stakingtypes.NewDescription("T", "E", "S", "T", "Z")
TestCommissionRates = stakingtypes.NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
Expand Down
1 change: 0 additions & 1 deletion x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
stakingtypes.DefaultConfig(),
)

val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
Expand Down
3 changes: 1 addition & 2 deletions x/group/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/cosmos/cosmos-sdk/simapp"
sdktestutil "github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
Expand Down Expand Up @@ -83,7 +82,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account {
accounts := simtypes.RandomAccounts(r, n)

initAmt := sdktestutil.TokensFromConsensusPower(200, sdktestutil.DefaultpowerReduction)
initAmt := sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))

// add coins to the accounts
Expand Down
2 changes: 0 additions & 2 deletions x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ func TestBeginBlocker(t *testing.T) {
addr, pk := sdk.ValAddress(pks[0].Address()), pks[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

InitTokens := sdk.NewIntFromUint64(200_000_000)
// bond the validator
power := int64(100)
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
staking.EndBlocker(ctx, app.StakingKeeper)
require.Equal(
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),

sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.GetParams(ctx).BondDenom, InitTokens.Sub(amt))),
)
require.Equal(t, amt, app.StakingKeeper.Validator(ctx, addr).GetBondedTokens())
Expand Down
Loading

0 comments on commit 66ca3e8

Please sign in to comment.