Skip to content

Commit

Permalink
Merge pull request #1853 from cosmos/cwgoes/staking-bugfix
Browse files Browse the repository at this point in the history
Fix genesis bond intra-tx counter bug
  • Loading branch information
rigelrozanski authored Jul 27, 2018
2 parents 55ef898 + 79aeb2b commit 9812c88
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ BUG FIXES
* \#1804 Fixes gen-tx genesis generation logic temporarily until upstream updates
* \#1799 Fix `gaiad export`
* \#1828 Force user to specify amount on create-validator command by removing default
* \#1839 Fixed bug where intra-tx counter wasn't set correctly for genesis validators
2 changes: 1 addition & 1 deletion x/stake/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
keeper.InitIntraTxCounter(ctx)

for i, validator := range data.Validators {
validator.BondIntraTxCounter = int16(i) // set the intra-tx counter to the order the validators are presented
keeper.SetValidator(ctx, validator)

if validator.Tokens.IsZero() {
Expand All @@ -33,7 +34,6 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
// Manually set indexes for the first time
keeper.SetValidatorByPubKeyIndex(ctx, validator)

validator.BondIntraTxCounter = int16(i) // set the intra-tx counter to the order the validators are presented
keeper.SetValidatorByPowerIndex(ctx, validator, data.Pool)

if validator.Status == sdk.Bonded {
Expand Down
4 changes: 3 additions & 1 deletion x/stake/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ func TestInitGenesis(t *testing.T) {
vals, err := InitGenesis(ctx, keeper, genesisState)
require.NoError(t, err)

// now make sure the validators are bonded
// now make sure the validators are bonded and intra-tx counters are correct
resVal, found := keeper.GetValidator(ctx, keep.Addrs[0])
require.True(t, found)
require.Equal(t, sdk.Bonded, resVal.Status)
require.Equal(t, int16(0), resVal.BondIntraTxCounter)

resVal, found = keeper.GetValidator(ctx, keep.Addrs[1])
require.True(t, found)
require.Equal(t, sdk.Bonded, resVal.Status)
require.Equal(t, int16(1), resVal.BondIntraTxCounter)

abcivals := make([]abci.Validator, len(vals))
for i, val := range validators {
Expand Down

0 comments on commit 9812c88

Please sign in to comment.