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: power reduction for Tendermint #3400

Merged
merged 38 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4ea3477
add uncompiled power functionality
rigelrozanski Jan 25, 2019
3b0f7c6
fix some compile errors
rigelrozanski Jan 25, 2019
1bd2fbf
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Jan 29, 2019
874f065
Power -> TendermintPower
rigelrozanski Jan 29, 2019
af5a1e3
tests rename GetTendermintPower
rigelrozanski Jan 29, 2019
5ec0826
test fix
rigelrozanski Jan 30, 2019
b792be6
working
rigelrozanski Jan 30, 2019
bce1ff0
fix delegation tests
rigelrozanski Jan 30, 2019
5fb7d78
fix slash tests
rigelrozanski Jan 30, 2019
31c2b8e
staking/keeper tests passing
rigelrozanski Jan 30, 2019
753e71b
docs reversion
rigelrozanski Jan 30, 2019
0a71ae3
debuggin workin
rigelrozanski Jan 30, 2019
500ae2d
x/staking test pass
rigelrozanski Jan 31, 2019
93a9d66
fix gov tests
rigelrozanski Jan 31, 2019
2f5ae44
fix x/slashing tests
rigelrozanski Jan 31, 2019
328b7bf
working distribution test fixes
rigelrozanski Jan 31, 2019
7958a14
fix distribution tests
rigelrozanski Jan 31, 2019
f7c7a1d
lint
rigelrozanski Jan 31, 2019
836e963
fix lcd tests
rigelrozanski Feb 1, 2019
bba4591
fix gov test
rigelrozanski Feb 1, 2019
079b4ad
lint
rigelrozanski Feb 1, 2019
ffff826
CLI fixes, rm stakingTypes
rigelrozanski Feb 1, 2019
1ab4597
typos
rigelrozanski Feb 1, 2019
6ac2afd
working cli fixes
rigelrozanski Feb 1, 2019
9f42196
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Feb 1, 2019
239f145
cli test fix
rigelrozanski Feb 1, 2019
8dcf0d7
cli tests fixed
rigelrozanski Feb 1, 2019
49c1a3c
testnet creation modification
rigelrozanski Feb 1, 2019
b1db0f4
typo
rigelrozanski Feb 1, 2019
d2cc658
pending
rigelrozanski Feb 1, 2019
b2241ef
Sanitize Dec.Roundint64 (#3475)
rigelrozanski Feb 2, 2019
7df1018
Merge remote-tracking branch 'origin/develop' into rigel/tmint-power-…
rigelrozanski Feb 6, 2019
cefba46
merge fixes
rigelrozanski Feb 6, 2019
5e95340
@cwgoes comments
rigelrozanski Feb 6, 2019
a952a41
fix tests
rigelrozanski Feb 6, 2019
a984da1
change power reduction to 10^-6
rigelrozanski Feb 6, 2019
450cad0
option to turn off minting for LCD tests
rigelrozanski Feb 6, 2019
f8c1ffc
Merge branch 'develop' into rigel/tmint-power-reduce
cwgoes Feb 6, 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
2 changes: 1 addition & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
},
nav: [
{ text: "Back to Cosmos", link: "https://cosmos.network" },
{ text: "RPC", link: "https://cosmos.network/rpc/" }
{ text: "RPC", link: "../rpc/" }
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
],
sidebar: [
{
Expand Down
23 changes: 7 additions & 16 deletions docs/clients/service-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,10 @@ The recommended way to listen for incoming transaction is to periodically query

## Rest API

The Rest API documents all the available endpoints that you can use to interact
with your full node. It can be found [here](https://cosmos.network/rpc/).

The API is divided into ICS standards for each category of endpoints. For
example, the [ICS20](https://cosmos.network/rpc/#/ICS20/) describes the API to
interact with tokens.

To give more flexibility to implementers, we have included the ability to
generate unsigned transactions, [sign](https://cosmos.network/rpc/#/ICS20/post_tx_sign)
and [broadcast](https://cosmos.network/rpc/#/ICS20/post_tx_broadcast) them with
different API endpoints. This allows service providers to use their own signing
mechanism for instance.

In order to generate an unsigned transaction (example with
[coin transfer](https://cosmos.network/rpc/#/ICS20/post_bank_accounts__address__transfers)),
you need to use the field `generate_only` in the body of `base_req`.
The Rest API documents all the available endpoints that you can use to interract with your full node. It can be found [here](https://cosmos.network/rpc/).

The API is divided into ICS standards for each category of endpoints. For example, the [ICS20](https://cosmos.network/rpc/#/ICS20/) describes the API to interact with tokens.

To give more flexibility to implementers, we have included the ability to generate unsigned transactions, [sign](https://cosmos.network/rpc/#/ICS20/post_tx_sign) and [broadcast](https://cosmos.network/rpc/#/ICS20/post_tx_broadcast) them with different API endpoints. This allows service providers to use their own signing mechanism for instance.

In order to generate an unsigned transaction (example with [coin transfer](https://cosmos.network/rpc/#/ICS20/post_bank_accounts__address__transfers)), you need to use the flag `?generate_only`.
15 changes: 3 additions & 12 deletions docs/gaia/gaiacli.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ You can also check your balance at a given block by using the `--block` flag:
gaiacli query account <account_cosmos> --block=<block_height>
```

You can simulate a transaction without actually broadcasting it by appending the
`--dry-run` flag to the command line:
You can simulate a transaction without actually broadcasting it by appending the `--dry-run` flag to the command line:

```bash
gaiacli tx send \
Expand All @@ -221,8 +220,7 @@ gaiacli tx send \
--dry-run
```

Furthermore, you can build a transaction and print its JSON format to STDOUT by
appending `--generate-only` to the list of the command line arguments:
Furthermore, you can build a transaction and print its JSON format to STDOUT by appending `--generate-only` to the list of the command line arguments:

```bash
gaiacli tx send \
Expand All @@ -233,14 +231,7 @@ gaiacli tx send \
--generate-only > unsignedSendTx.json
```

::: tip Note
Simulation cannot be used in conjunction with tx generation only functionality
due to the fact that simulation requires a public key and generation only does
not utilize a Keybase.

You can now sign the transaction file generated through the `--generate-only`
flag by providing your key to the following command:
:::
You can now sign the transaction file generated through the `--generate-only` flag by providing your key to the following command:

```bash
gaiacli tx sign \
Expand Down
2 changes: 1 addition & 1 deletion docs/gaia/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mkdir -p $GOPATH/src/github.com/cosmos
cd $GOPATH/src/github.com/cosmos
git clone https://github.com/cosmos/cosmos-sdk
cd cosmos-sdk && git checkout master
make tools install
make tools && make get_vendor_deps && make install
```

> *NOTE*: If you have issues at this step, please check that you have the latest stable version of GO installed.
Expand Down
2 changes: 1 addition & 1 deletion docs/gaia/join-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Now it is time to upgrade the software:
```bash
cd $GOPATH/src/github.com/cosmos/cosmos-sdk
git fetch --all && git checkout master
make update_tools install
make update_tools && make get_vendor_deps && make install
```

::: tip
Expand Down
5 changes: 3 additions & 2 deletions types/stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ type Validator interface {
GetOperator() ValAddress // operator address to receive/return validators coins
GetConsPubKey() crypto.PubKey // validation consensus pubkey
GetConsAddr() ConsAddress // validation consensus address
GetPower() Int // validation power
GetTokens() Int // validation tokens
GetBondedTokens() Int // validator bonded tokens
GetTendermintPower() int64 // validation power in tendermint
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
GetCommission() Dec // validator commission rate
GetDelegatorShares() Dec // total outstanding delegator shares
GetBondHeight() int64 // height in which the validator became active
Expand All @@ -54,7 +55,7 @@ type Validator interface {
func ABCIValidator(v Validator) abci.Validator {
return abci.Validator{
Address: v.GetConsPubKey().Address(),
Power: v.GetPower().Int64(),
Power: v.GetTendermintPower(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/gov/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func tally(ctx sdk.Context, keeper Keeper, proposal Proposal) (passes bool, tall
keeper.vs.IterateBondedValidatorsByPower(ctx, func(index int64, validator sdk.Validator) (stop bool) {
currValidators[validator.GetOperator().String()] = validatorGovInfo{
Address: validator.GetOperator(),
Power: sdk.NewDecFromInt(validator.GetPower()),
Power: sdk.NewDec(validator.GetTendermintPower()),
rigelrozanski marked this conversation as resolved.
Show resolved Hide resolved
DelegatorShares: validator.GetDelegatorShares(),
Minus: sdk.ZeroDec(),
Vote: OptionEmpty,
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestCannotUnjailUnlessJailed(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.Sub(amt))},
)
require.True(sdk.IntEq(t, amt, sk.Validator(ctx, addr).GetPower()))
require.Equal(t, amt.Int64(), sk.Validator(ctx, addr).GetTendermintPower())

// assert non-jailed validator can't be unjailed
got = slh(ctx, NewMsgUnjail(addr))
Expand Down
12 changes: 6 additions & 6 deletions x/slashing/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestHandleDoubleSign(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(operatorAddr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.Sub(amt))},
)
require.True(sdk.IntEq(t, amt, sk.Validator(ctx, operatorAddr).GetPower()))
require.Equal(t, amt.Int64(), sk.Validator(ctx, operatorAddr).GetTendermintPower())

// handle a signature to set signing info
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, true)
Expand Down Expand Up @@ -96,14 +96,14 @@ func TestPastMaxEvidenceAge(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(operatorAddr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.Sub(amt))},
)
require.True(sdk.IntEq(t, amt, sk.Validator(ctx, operatorAddr).GetPower()))
require.Equal(t, amt.Int64(), sk.Validator(ctx, operatorAddr).GetTendermintPower())

// handle a signature to set signing info
keeper.handleValidatorSignature(ctx, val.Address(), amtInt, true)

ctx = ctx.WithBlockHeader(abci.Header{Time: time.Unix(1, 0).Add(keeper.MaxEvidenceAge(ctx))})

oldPower := sk.Validator(ctx, operatorAddr).GetPower()
oldPower := sk.Validator(ctx, operatorAddr).GetTendermintPower()

// double sign past max age
keeper.handleDoubleSign(ctx, val.Address(), 0, time.Unix(0, 0), amtInt)
Expand All @@ -112,7 +112,7 @@ func TestPastMaxEvidenceAge(t *testing.T) {
require.True(t, sk.Validator(ctx, operatorAddr).GetStatus() == sdk.Bonded)

// should still have same power
require.True(t, sk.Validator(ctx, operatorAddr).GetPower().Equal(oldPower))
require.Equal(t, oldPower, sk.Validator(ctx, operatorAddr).GetTendermintPower())
}

// Test a validator through uptime, downtime, revocation,
Expand All @@ -133,7 +133,7 @@ func TestHandleAbsentValidator(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.Sub(amt))},
)
require.True(sdk.IntEq(t, amt, sk.Validator(ctx, addr).GetPower()))
require.Equal(t, amt.Int64(), sk.Validator(ctx, addr).GetTendermintPower())

// will exist since the validator has been bonded
info, found := keeper.getValidatorSigningInfo(ctx, sdk.ConsAddress(val.Address()))
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestHandleNewValidator(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.SubRaw(amt))},
)
require.Equal(t, amt, sk.Validator(ctx, addr).GetPower().Int64())
require.Equal(t, amt, sk.Validator(ctx, addr).GetTendermintPower())

// Now a validator, for two blocks
keeper.handleValidatorSignature(ctx, val.Address(), 100, true)
Expand Down
2 changes: 1 addition & 1 deletion x/slashing/tick_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestBeginBlocker(t *testing.T) {
t, ck.GetCoins(ctx, sdk.AccAddress(addr)),
sdk.Coins{sdk.NewCoin(sk.GetParams(ctx).BondDenom, initCoins.Sub(amt))},
)
require.True(sdk.IntEq(t, amt, sk.Validator(ctx, addr).GetPower()))
require.Equal(t, amt.Int64(), sk.Validator(ctx, addr).GetTendermintPower())

val := abci.Validator{
Address: pk.Address(),
Expand Down
6 changes: 3 additions & 3 deletions x/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
panic("expected validator, not found")
}
update := validator.ABCIValidatorUpdate()
update.Power = lv.Power.Int64() // keep the next-val-set offset, use the last power for the first block
update.Power = lv.Power // keep the next-val-set offset, use the last power for the first block
res = append(res, update)
}
} else {
Expand Down Expand Up @@ -107,7 +107,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
return false
})
var lastValidatorPowers []types.LastValidatorPower
keeper.IterateLastValidatorPowers(ctx, func(addr sdk.ValAddress, power sdk.Int) (stop bool) {
keeper.IterateLastValidatorPowers(ctx, func(addr sdk.ValAddress, power int64) (stop bool) {
lastValidatorPowers = append(lastValidatorPowers, types.LastValidatorPower{addr, power})
return false
})
Expand All @@ -130,7 +130,7 @@ func WriteValidators(ctx sdk.Context, keeper Keeper) (vals []tmtypes.GenesisVali
keeper.IterateLastValidators(ctx, func(_ int64, validator sdk.Validator) (stop bool) {
vals = append(vals, tmtypes.GenesisValidator{
PubKey: validator.GetConsPubKey(),
Power: validator.GetPower().Int64(),
Power: validator.GetTendermintPower(),
Name: validator.GetMoniker(),
})

Expand Down
2 changes: 1 addition & 1 deletion x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
// validator power should have been reduced by half
validator, found := keeper.GetValidator(ctx, valA)
require.True(t, found)
require.Equal(t, int64(5), validator.GetPower().Int64())
require.Equal(t, int64(5), validator.GetTendermintPower())

// slash the validator for an infraction committed after the unbonding and redelegation begin
ctx = ctx.WithBlockHeight(3)
Expand Down
8 changes: 5 additions & 3 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,22 @@ func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress)
}

// Set the last validator power.
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power sdk.Int) {
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power int64) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshalBinaryLengthPrefixed(power)
store.Set(GetLastValidatorPowerKey(operator), bz)
}

// Iterate over last validator powers.
func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context, handler func(operator sdk.ValAddress, power sdk.Int) (stop bool)) {
func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context,
handler func(operator sdk.ValAddress, power int64) (stop bool)) {

store := ctx.KVStore(k.storeKey)
iter := sdk.KVStorePrefixIterator(store, LastValidatorPowerKey)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[len(LastValidatorPowerKey):])
var power sdk.Int
var power int64
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &power)
if handler(addr, power) {
break
Expand Down
16 changes: 8 additions & 8 deletions x/staking/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestSlashAtNegativeHeight(t *testing.T) {

validator = keeper.mustGetValidator(ctx, validator.OperatorAddr)
// power decreased
require.True(sdk.IntEq(t, sdk.NewInt(5), validator.GetPower()))
require.Equal(t, int64(5), validator.GetTendermintPower())
// pool bonded shares decreased
require.Equal(t, int64(5), oldPool.BondedTokens.Sub(newPool.BondedTokens).Int64())
}
Expand All @@ -231,7 +231,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {

validator = keeper.mustGetValidator(ctx, validator.OperatorAddr)
// power decreased
require.True(sdk.IntEq(t, sdk.NewInt(5), validator.GetPower()))
require.Equal(t, int64(5), validator.GetTendermintPower())
// pool bonded shares decreased
require.Equal(t, int64(5), oldPool.BondedTokens.Sub(newPool.BondedTokens).Int64())
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
// was still bonded at the time of discovery and was slashed by half, 4 stake
// bonded at the time of discovery hadn't been bonded at the time of infraction
// and wasn't slashed
require.True(sdk.IntEq(t, sdk.NewInt(7), validator.GetPower()))
require.Equal(t, int64(7), validator.GetTendermintPower())

// slash validator again
ctx = ctx.WithBlockHeight(13)
Expand All @@ -294,7 +294,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
// power decreased by 3 again
require.True(sdk.IntEq(t, sdk.NewInt(4), validator.GetPower()))
require.Equal(t, int64(4), validator.GetTendermintPower())

// slash validator again
// all originally bonded stake has been slashed, so this will have no effect
Expand All @@ -315,7 +315,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
// power decreased by 3 again
require.True(sdk.IntEq(t, sdk.NewInt(1), validator.GetPower()))
require.Equal(t, int64(1), validator.GetTendermintPower())

// slash validator again
// all originally bonded stake has been slashed, so this will have no effect
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestSlashWithRedelegation(t *testing.T) {
// was still bonded at the time of discovery and was slashed by half, 4 stake
// bonded at the time of discovery hadn't been bonded at the time of infraction
// and wasn't slashed
require.True(sdk.IntEq(t, sdk.NewInt(8), validator.GetPower()))
require.Equal(t, int64(8), validator.GetTendermintPower())

// slash the validator again
ctx = ctx.WithBlockHeight(12)
Expand All @@ -412,7 +412,7 @@ func TestSlashWithRedelegation(t *testing.T) {
validator, found = keeper.GetValidatorByConsAddr(ctx, consAddr)
require.True(t, found)
// power decreased by 4
require.True(sdk.IntEq(t, sdk.NewInt(4), validator.GetPower()))
require.Equal(t, int64(4), validator.GetTendermintPower())

// slash the validator again, by 100%
ctx = ctx.WithBlockHeight(12)
Expand Down Expand Up @@ -511,5 +511,5 @@ func TestSlashBoth(t *testing.T) {
validator, found = keeper.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(PKs[0]))
require.True(t, found)
// power not decreased, all stake was bonded since
require.True(sdk.IntEq(t, sdk.NewInt(10), validator.GetPower()))
require.Equal(t, int64(10), validator.GetTendermintPower())
}
8 changes: 4 additions & 4 deletions x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab

// if we get to a zero-power validator (which we don't bond),
// there are no more possible bonded validators
if validator.Tokens.IsZero() {
if validator.PotentialTendermintPower() == 0 {
break
}

Expand All @@ -72,8 +72,8 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
oldPowerBytes, found := last[valAddrBytes]

// calculate the new power bytes
newPower := validator.BondedTokens().Int64()
newPowerBytes := k.cdc.MustMarshalBinaryLengthPrefixed(sdk.NewInt(newPower))
newPower := validator.TendermintPower()
newPowerBytes := k.cdc.MustMarshalBinaryLengthPrefixed(newPower)
// update the validator set if power has changed
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
updates = append(updates, validator.ABCIValidatorUpdate())
Expand All @@ -85,7 +85,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
}

// set validator power on lookup index.
k.SetLastValidatorPower(ctx, valAddr, sdk.NewInt(newPower))
k.SetLastValidatorPower(ctx, valAddr, newPower)
}

// validator still in the validator set, so delete from the copy
Expand Down
8 changes: 4 additions & 4 deletions x/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,8 +810,8 @@ func TestApplyAndReturnValidatorSetUpdatesPowerDecrease(t *testing.T) {
require.Equal(t, 2, len(keeper.ApplyAndReturnValidatorSetUpdates(ctx)))

// check initial power
require.Equal(t, int64(100), validators[0].GetPower().Int64())
require.Equal(t, int64(100), validators[1].GetPower().Int64())
require.Equal(t, int64(100), validators[0].GetTendermintPower())
require.Equal(t, int64(100), validators[1].GetTendermintPower())

// test multiple value change
// tendermintUpdate set: {c1, c3} -> {c1', c3'}
Expand All @@ -823,8 +823,8 @@ func TestApplyAndReturnValidatorSetUpdatesPowerDecrease(t *testing.T) {
validators[1] = TestingUpdateValidator(keeper, ctx, validators[1], false)

// power has changed
require.Equal(t, int64(80), validators[0].GetPower().Int64())
require.Equal(t, int64(70), validators[1].GetPower().Int64())
require.Equal(t, int64(80), validators[0].GetTendermintPower())
require.Equal(t, int64(70), validators[1].GetTendermintPower())

// Tendermint updates should reflect power change
updates := keeper.ApplyAndReturnValidatorSetUpdates(ctx)
Expand Down
5 changes: 3 additions & 2 deletions x/staking/simulation/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func SupplyInvariants(ck bank.Keeper, k staking.Keeper,
k.IterateValidators(ctx, func(_ int64, validator sdk.Validator) bool {
switch validator.GetStatus() {
case sdk.Bonded:
bonded = bonded.Add(sdk.NewDecFromInt(validator.GetPower()))
bonded = bonded.Add(sdk.NewDecFromInt(validator.GetBondedTokens()))
case sdk.Unbonding, sdk.Unbonded:
loose = loose.Add(sdk.NewDecFromInt(validator.GetTokens()))
}
Expand Down Expand Up @@ -119,7 +119,8 @@ func NonNegativePowerInvariant(k staking.Keeper) simulation.Invariant {

if !bytes.Equal(iterator.Key(), powerKey) {
return fmt.Errorf("power store invariance:\n\tvalidator.Power: %v"+
"\n\tkey should be: %v\n\tkey in store: %v", validator.GetPower(), powerKey, iterator.Key())
"\n\tkey should be: %v\n\tkey in store: %v",
validator.GetTendermintPower(), powerKey, iterator.Key())
}

if validator.Tokens.IsNegative() {
Expand Down
Loading