diff --git a/PENDING.md b/PENDING.md index 9c4db6c45c..73567c2373 100644 --- a/PENDING.md +++ b/PENDING.md @@ -13,6 +13,7 @@ BREAKING CHANGES * Gaia - [#128](https://github.com/tendermint/devops/issues/128) Updated CircleCI job to trigger website build on every push to master/develop. - [\#2994](https://github.com/cosmos/cosmos-sdk/pull/2994) Change wrong-password error message. + - \#3009 Added missing Gaia genesis verification * SDK - [auth] \#2952 Signatures are no longer serialized on chain with the account number and sequence number diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index 358c3395c7..e356d6d6da 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -7,6 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/auth" distr "github.com/cosmos/cosmos-sdk/x/distribution" + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/slashing" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/stretchr/testify/require" @@ -22,12 +24,15 @@ func setGenesis(gapp *GaiaApp, accs ...*auth.BaseAccount) error { genaccs[i] = NewGenesisAccount(acc) } - genesisState := GenesisState{ - Accounts: genaccs, - StakeData: stake.DefaultGenesisState(), - DistrData: distr.DefaultGenesisState(), - SlashingData: slashing.DefaultGenesisState(), - } + genesisState := NewGenesisState( + genaccs, + auth.DefaultGenesisState(), + stake.DefaultGenesisState(), + mint.DefaultGenesisState(), + distr.DefaultGenesisState(), + gov.DefaultGenesisState(), + slashing.DefaultGenesisState(), + ) stateBytes, err := codec.MarshalJSONIndent(gapp.cdc, genesisState) if err != nil { diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 44cb9d2eeb..ee3ecfcd65 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -155,20 +155,42 @@ func NewDefaultGenesisState() GenesisState { // TODO: No validators are both bonded and jailed (#2088) // TODO: Error if there is a duplicate validator (#1708) // TODO: Ensure all state machine parameters are in genesis (#1704) -func GaiaValidateGenesisState(genesisState GenesisState) (err error) { - err = validateGenesisStateAccounts(genesisState.Accounts) +func GaiaValidateGenesisState(genesisState GenesisState) error { + err := validateGenesisStateAccounts(genesisState.Accounts) if err != nil { - return + return err } // skip stakeData validation as genesis is created from txs if len(genesisState.GenTxs) > 0 { return nil } - return stake.ValidateGenesis(genesisState.StakeData) + + err = stake.ValidateGenesis(genesisState.StakeData) + if err != nil { + return err + } + err = mint.ValidateGenesis(genesisState.MintData) + if err != nil { + return err + } + err = distr.ValidateGenesis(genesisState.DistrData) + if err != nil { + return err + } + err = gov.ValidateGenesis(genesisState.GovData) + if err != nil { + return err + } + err = slashing.ValidateGenesis(genesisState.SlashingData) + if err != nil { + return err + } + + return nil } // Ensures that there are no duplicate accounts in the genesis state, -func validateGenesisStateAccounts(accs []GenesisAccount) (err error) { +func validateGenesisStateAccounts(accs []GenesisAccount) error { addrMap := make(map[string]bool, len(accs)) for i := 0; i < len(accs); i++ { acc := accs[i] @@ -178,7 +200,7 @@ func validateGenesisStateAccounts(accs []GenesisAccount) (err error) { } addrMap[strAddr] = true } - return + return nil } // GaiaAppGenState but with JSON diff --git a/cmd/gaia/init/gentx.go b/cmd/gaia/init/gentx.go index b68481b3b3..0a4eb80345 100644 --- a/cmd/gaia/init/gentx.go +++ b/cmd/gaia/init/gentx.go @@ -172,7 +172,7 @@ func accountInGenesis(genesisState app.GenesisState, key sdk.AccAddress, coins s // Ensure account contains enough funds of default bond denom if coins.AmountOf(bondDenom).GT(acc.Coins.AmountOf(bondDenom)) { return fmt.Errorf( - "Account %s is in genesis, but the only has %s%s available to stake, not %s%s", + "Account %v is in genesis, but the only has %v%v available to stake, not %v%v", key, acc.Coins.AmountOf(bondDenom), bondDenom, coins.AmountOf(bondDenom), bondDenom, ) } diff --git a/x/distribution/alias.go b/x/distribution/alias.go index 34813abd6d..7f4457b35a 100644 --- a/x/distribution/alias.go +++ b/x/distribution/alias.go @@ -49,6 +49,7 @@ var ( InitialFeePool = types.InitialFeePool NewGenesisState = types.NewGenesisState + ValidateGenesis = types.ValidateGenesis DefaultGenesisState = types.DefaultGenesisState DefaultGenesisWithValidators = types.DefaultGenesisWithValidators diff --git a/x/distribution/types/fee_pool.go b/x/distribution/types/fee_pool.go index c036473307..2f921220c7 100644 --- a/x/distribution/types/fee_pool.go +++ b/x/distribution/types/fee_pool.go @@ -1,6 +1,8 @@ package types import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -31,3 +33,25 @@ func InitialFeePool() FeePool { CommunityPool: DecCoins{}, } } + +// ValidateGenesis validates the fee pool for a genesis state +func (f FeePool) ValidateGenesis() error { + if f.TotalValAccum.Accum.IsNegative() { + return fmt.Errorf("negative accum in distribution fee pool, is %v", + f.TotalValAccum.Accum.String()) + } + if f.TotalValAccum.UpdateHeight < 0 { + return fmt.Errorf("negative update height in distribution fee pool, is %v", + f.TotalValAccum.UpdateHeight) + } + if f.ValPool.HasNegative() { + return fmt.Errorf("negative ValPool in distribution fee pool, is %v", + f.ValPool) + } + if f.CommunityPool.HasNegative() { + return fmt.Errorf("negative CommunityPool in distribution fee pool, is %v", + f.CommunityPool) + } + + return nil +} diff --git a/x/distribution/types/genesis.go b/x/distribution/types/genesis.go index 0577af4d33..a94eb7005f 100644 --- a/x/distribution/types/genesis.go +++ b/x/distribution/types/genesis.go @@ -1,6 +1,10 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" +) // the address for where distributions rewards are withdrawn to by default // this struct is only used at genesis to feed in default withdraw addresses @@ -67,3 +71,26 @@ func DefaultGenesisWithValidators(valAddrs []sdk.ValAddress) GenesisState { DelegationDistInfos: ddis, } } + +// ValidateGenesis validates the genesis state of distribution genesis input +func ValidateGenesis(data GenesisState) error { + if data.CommunityTax.IsNegative() || data.CommunityTax.GT(sdk.OneDec()) { + return fmt.Errorf("mint parameter CommunityTax should non-negative and "+ + "less than one, is %s", data.CommunityTax.String()) + } + if data.BaseProposerReward.IsNegative() { + return fmt.Errorf("mint parameter BaseProposerReward should be positive, is %s", + data.BaseProposerReward.String()) + } + if data.BonusProposerReward.IsNegative() { + return fmt.Errorf("mint parameter BonusProposerReward should be positive, is %s", + data.BonusProposerReward.String()) + } + if (data.BaseProposerReward.Add(data.BonusProposerReward)). + GT(sdk.OneDec()) { + return fmt.Errorf("mint parameters BaseProposerReward and "+ + "BonusProposerReward cannot add to be greater than one, "+ + "adds to %s", data.BaseProposerReward.Add(data.BonusProposerReward).String()) + } + return data.FeePool.ValidateGenesis() +} diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 2096fc2ec2..341a4253b2 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -58,6 +58,11 @@ func DefaultGenesisState() GenesisState { } } +// ValidateGenesis TODO https://github.com/cosmos/cosmos-sdk/issues/3007 +func ValidateGenesis(data GenesisState) error { + return nil +} + // InitGenesis - store genesis parameters func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { err := k.setInitialProposalID(ctx, data.StartingProposalID) diff --git a/x/slashing/genesis.go b/x/slashing/genesis.go index 2a921af49a..05ac917817 100644 --- a/x/slashing/genesis.go +++ b/x/slashing/genesis.go @@ -29,6 +29,11 @@ func DefaultGenesisState() GenesisState { } } +// ValidateGenesis TODO https://github.com/cosmos/cosmos-sdk/issues/3008 +func ValidateGenesis(data GenesisState) error { + return nil +} + // InitGenesis initialize default parameters // and the keeper's address to pubkey map func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState, sdata types.GenesisState) {