Skip to content

Commit

Permalink
Merge pull request #1373: Initialization of POS chain
Browse files Browse the repository at this point in the history
pass lint

apply requests

fix test
  • Loading branch information
mossid committed Jun 27, 2018
1 parent 6f140d7 commit a9e86ee
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 15 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC

// Initialize the deliver state and run initChain
app.setDeliverState(abci.Header{})
app.initChainer(app.deliverState.ctx, req) // no error
res = app.initChainer(app.deliverState.ctx, req) // no error

// NOTE: we don't commit, but BeginBlock for block 1
// starts from this deliverState
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,13 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
validators := stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)

gov.InitGenesis(ctx, app.govKeeper, gov.DefaultGenesisState())

return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}

// export the state of gaia for a genesis file
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
return abci.ResponseInitChain{}
validators := stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
return abci.ResponseInitChain{
Validators: validators,
}

}
6 changes: 4 additions & 2 deletions examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ func (app *BasecoinApp) initChainer(ctx sdk.Context, req abci.RequestInitChain)
}

// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
validators := stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)

return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}

// Custom logic for state export
Expand Down
6 changes: 4 additions & 2 deletions x/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ func getInitChainer(mapp *mock.App, keeper Keeper, stakeKeeper stake.Keeper) sdk
stakeGenesis := stake.DefaultGenesisState()
stakeGenesis.Pool.LooseTokens = 100000

stake.InitGenesis(ctx, stakeKeeper, stakeGenesis)
validators := stake.InitGenesis(ctx, stakeKeeper, stakeGenesis)
InitGenesis(ctx, keeper, DefaultGenesisState())
return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ func getInitChainer(mapp *mock.App, keeper stake.Keeper) sdk.InitChainer {
mapp.InitChainer(ctx, req)
stakeGenesis := stake.DefaultGenesisState()
stakeGenesis.Pool.LooseTokens = 100000
stake.InitGenesis(ctx, keeper, stakeGenesis)
return abci.ResponseInitChain{}
validators := stake.InitGenesis(ctx, keeper, stakeGenesis)

return abci.ResponseInitChain{
Validators: validators,
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions x/stake/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ func getInitChainer(mapp *mock.App, keeper Keeper) sdk.InitChainer {
mapp.InitChainer(ctx, req)
stakeGenesis := DefaultGenesisState()
stakeGenesis.Pool.LooseTokens = 100000
InitGenesis(ctx, keeper, stakeGenesis)
validators := InitGenesis(ctx, keeper, stakeGenesis)

return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}
}

Expand Down
13 changes: 11 additions & 2 deletions x/stake/genesis.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package stake

import (
abci "github.com/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"

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

// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
// InitGenesis - store genesis parametersi
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res []abci.Validator) {
keeper.SetPool(ctx, data.Pool)
keeper.SetNewParams(ctx, data.Params)
keeper.InitIntraTxCounter(ctx)
Expand All @@ -27,7 +28,15 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) {
for _, bond := range data.Bonds {
keeper.SetDelegation(ctx, bond)
}

keeper.UpdateBondedValidatorsFull(ctx)

vals := keeper.GetAllValidators(ctx)
res = make([]abci.Validator, len(vals))
for i, val := range vals {
res[i] = sdk.ABCIValidator(val)
}
return
}

// WriteGenesis - output genesis parameters
Expand Down
42 changes: 42 additions & 0 deletions x/stake/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package stake

import (
"testing"

"github.com/stretchr/testify/assert"

abci "github.com/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/stake/keeper"
)

func TestInitGenesis(t *testing.T) {
vals := make([]Validator, 10)
for i, _ := range vals {
vals[i] = NewValidator(
keeper.Addrs[i],
keeper.PKs[i],
Description{},
)
vals[i].PoolShares = PoolShares{
Status: sdk.Bonded,
Amount: sdk.NewRat(int64(i)),
}
}

state := GenesisState{
Validators: vals,
}

abcivals := make([]abci.Validator, len(vals))
for i, val := range vals {
abcivals[i] = sdk.ABCIValidator(val)
}

ctx, _, k := keeper.CreateTestInput(t, false, 100000)

res := InitGenesis(ctx, k, state)

assert.Equal(t, abcivals, res)
}

0 comments on commit a9e86ee

Please sign in to comment.