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
  • Loading branch information
mossid committed Jun 25, 2018
1 parent f2a83a0 commit 6c9bc69
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 20 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 @@ -57,9 +57,11 @@ func getEndBlocker(keeper Keeper) sdk.EndBlocker {
func getInitChainer(mapp *mock.App, keeper Keeper, stakeKeeper stake.Keeper) sdk.InitChainer {
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
mapp.InitChainer(ctx, req)
stake.InitGenesis(ctx, stakeKeeper, stake.DefaultGenesisState())
validators := stake.InitGenesis(ctx, stakeKeeper, stake.DefaultGenesisState())
InitGenesis(ctx, keeper, DefaultGenesisState())
return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions x/slashing/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ func getEndBlocker(keeper stake.Keeper) sdk.EndBlocker {
func getInitChainer(mapp *mock.App, keeper stake.Keeper) sdk.InitChainer {
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
mapp.InitChainer(ctx, req)
stake.InitGenesis(ctx, keeper, stake.DefaultGenesisState())
return abci.ResponseInitChain{}
validators := stake.InitGenesis(ctx, keeper, stake.DefaultGenesisState())
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 @@ -60,9 +60,11 @@ func getEndBlocker(keeper Keeper) sdk.EndBlocker {
func getInitChainer(mapp *mock.App, keeper Keeper) sdk.InitChainer {
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
mapp.InitChainer(ctx, req)
InitGenesis(ctx, keeper, DefaultGenesisState())
validators := InitGenesis(ctx, keeper, DefaultGenesisState())

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

Expand Down
5 changes: 4 additions & 1 deletion x/stake/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stake

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

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -32,7 +33,7 @@ func DefaultGenesisState() GenesisState {
}

// InitGenesis - store genesis parameters
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) {
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) (vals []abci.Validator) {
store := ctx.KVStore(k.storeKey)
k.setPool(ctx, data.Pool)
k.setNewParams(ctx, data.Params)
Expand All @@ -52,6 +53,8 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) {
k.setDelegation(ctx, bond)
}
k.updateBondedValidatorsFull(ctx, store)

return k.getTendermintUpdates(ctx)
}

// WriteGenesis - output genesis parameters
Expand Down
6 changes: 3 additions & 3 deletions x/stake/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (k Keeper) updateValidator(ctx sdk.Context, validator Validator) Validator
store.Set(GetValidatorKey(ownerAddr), bz)
}()

// retreive the old validator record
// retrieve the old validator record
oldValidator, oldFound := k.GetValidator(ctx, ownerAddr)

if validator.Revoked && oldValidator.Status() == sdk.Bonded {
Expand Down Expand Up @@ -288,7 +288,7 @@ func (k Keeper) updateValidator(ctx sdk.Context, validator Validator) Validator

// update the validator set for this validator
updatedVal := k.updateBondedValidators(ctx, store, validator)
if updatedVal.Owner != nil { // updates to validator occured to be updated
if updatedVal.Owner != nil { // updates to validator occurred to be updated
validator = updatedVal
}
return validator
Expand Down Expand Up @@ -498,7 +498,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, store sdk.KVStore, validator Vali

func (k Keeper) removeValidator(ctx sdk.Context, address sdk.Address) {

// first retreive the old validator record
// first retrieve the old validator record
validator, found := k.GetValidator(ctx, address)
if !found {
return
Expand Down
2 changes: 1 addition & 1 deletion x/stake/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func GetValidatorSortingMixed(t *testing.T) {
assert.Equal(t, validators[0].Owner, resValidators[4].Owner, "%v", resValidators)
}

// TODO seperate out into multiple tests
// TODO separate out into multiple tests
func TestGetValidatorsEdgeCases(t *testing.T) {
ctx, _, keeper := createTestInput(t, false, sdk.NewInt(0))
var found bool
Expand Down
2 changes: 1 addition & 1 deletion x/stake/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Pool struct {
DateLastCommissionReset int64 `json:"date_last_commission_reset"` // unix timestamp for last commission accounting reset (daily)

// Fee Related
PrevBondedShares sdk.Rat `json:"prev_bonded_shares"` // last recorded bonded shares - for fee calcualtions
PrevBondedShares sdk.Rat `json:"prev_bonded_shares"` // last recorded bonded shares - for fee calculations
}

func (p Pool) equal(p2 Pool) bool {
Expand Down
2 changes: 1 addition & 1 deletion x/stake/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func (v Validator) HumanReadableString() (string, error) {
resp += fmt.Sprintf("Proposer Reward Pool: %s\n", v.ProposerRewardPool.String())
resp += fmt.Sprintf("Commission: %s\n", v.Commission.String())
resp += fmt.Sprintf("Max Commission Rate: %s\n", v.CommissionMax.String())
resp += fmt.Sprintf("Comission Change Rate: %s\n", v.CommissionChangeRate.String())
resp += fmt.Sprintf("Commission Change Rate: %s\n", v.CommissionChangeRate.String())
resp += fmt.Sprintf("Commission Change Today: %s\n", v.CommissionChangeToday.String())
resp += fmt.Sprintf("Previously Bonded Stares: %s\n", v.PrevBondedShares.String())

Expand Down

0 comments on commit 6c9bc69

Please sign in to comment.