Merge PR #3010: Add Missing genesis checks in Gaia
This commit is contained in:
committed by
Christopher Goes
parent
f11a65dee7
commit
49da96bc09
@@ -49,6 +49,7 @@ var (
|
||||
InitialFeePool = types.InitialFeePool
|
||||
|
||||
NewGenesisState = types.NewGenesisState
|
||||
ValidateGenesis = types.ValidateGenesis
|
||||
DefaultGenesisState = types.DefaultGenesisState
|
||||
DefaultGenesisWithValidators = types.DefaultGenesisWithValidators
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user