Auth Module Param Store (#2998)
This commit is contained in:
committed by
Jack Zampolin
parent
0c0bff7ea0
commit
217a2925dc
+6
-7
@@ -91,11 +91,14 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
|
||||
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
|
||||
}
|
||||
|
||||
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
|
||||
|
||||
// define the accountKeeper
|
||||
app.accountKeeper = auth.NewAccountKeeper(
|
||||
app.cdc,
|
||||
app.keyAccount, // target store
|
||||
auth.ProtoBaseAccount, // prototype
|
||||
app.keyAccount,
|
||||
app.paramsKeeper.Subspace(auth.DefaultParamspace),
|
||||
auth.ProtoBaseAccount,
|
||||
)
|
||||
|
||||
// add handlers
|
||||
@@ -104,10 +107,6 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
|
||||
app.cdc,
|
||||
app.keyFeeCollection,
|
||||
)
|
||||
app.paramsKeeper = params.NewKeeper(
|
||||
app.cdc,
|
||||
app.keyParams, app.tkeyParams,
|
||||
)
|
||||
stakeKeeper := stake.NewKeeper(
|
||||
app.cdc,
|
||||
app.keyStake, app.tkeyStake,
|
||||
@@ -246,7 +245,7 @@ func (app *GaiaApp) initFromGenesisState(ctx sdk.Context, genesisState GenesisSt
|
||||
}
|
||||
|
||||
// initialize module-specific stores
|
||||
auth.InitGenesis(ctx, app.feeCollectionKeeper, genesisState.AuthData)
|
||||
auth.InitGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper, genesisState.AuthData)
|
||||
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.SlashingData, genesisState.StakeData)
|
||||
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
|
||||
mint.InitGenesis(ctx, app.mintKeeper, genesisState.MintData)
|
||||
|
||||
@@ -39,7 +39,7 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (
|
||||
|
||||
genState := NewGenesisState(
|
||||
accounts,
|
||||
auth.ExportGenesis(ctx, app.feeCollectionKeeper),
|
||||
auth.ExportGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper),
|
||||
stake.ExportGenesis(ctx, app.stakeKeeper),
|
||||
mint.ExportGenesis(ctx, app.mintKeeper),
|
||||
distr.ExportGenesis(ctx, app.distrKeeper),
|
||||
|
||||
+9
-13
@@ -143,6 +143,7 @@ func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []js
|
||||
func NewDefaultGenesisState() GenesisState {
|
||||
return GenesisState{
|
||||
Accounts: nil,
|
||||
AuthData: auth.DefaultGenesisState(),
|
||||
StakeData: stake.DefaultGenesisState(),
|
||||
MintData: mint.DefaultGenesisState(),
|
||||
DistrData: distr.DefaultGenesisState(),
|
||||
@@ -157,37 +158,32 @@ func NewDefaultGenesisState() GenesisState {
|
||||
// TODO: Error if there is a duplicate validator (#1708)
|
||||
// TODO: Ensure all state machine parameters are in genesis (#1704)
|
||||
func GaiaValidateGenesisState(genesisState GenesisState) error {
|
||||
err := validateGenesisStateAccounts(genesisState.Accounts)
|
||||
if err != nil {
|
||||
if err := validateGenesisStateAccounts(genesisState.Accounts); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// skip stakeData validation as genesis is created from txs
|
||||
if len(genesisState.GenTxs) > 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = stake.ValidateGenesis(genesisState.StakeData)
|
||||
if err != nil {
|
||||
if err := auth.ValidateGenesis(genesisState.AuthData); err != nil {
|
||||
return err
|
||||
}
|
||||
err = mint.ValidateGenesis(genesisState.MintData)
|
||||
if err != nil {
|
||||
if err := stake.ValidateGenesis(genesisState.StakeData); err != nil {
|
||||
return err
|
||||
}
|
||||
err = distr.ValidateGenesis(genesisState.DistrData)
|
||||
if err != nil {
|
||||
if err := mint.ValidateGenesis(genesisState.MintData); err != nil {
|
||||
return err
|
||||
}
|
||||
err = gov.ValidateGenesis(genesisState.GovData)
|
||||
if err != nil {
|
||||
if err := distr.ValidateGenesis(genesisState.DistrData); err != nil {
|
||||
return err
|
||||
}
|
||||
err = slashing.ValidateGenesis(genesisState.SlashingData)
|
||||
if err != nil {
|
||||
if err := gov.ValidateGenesis(genesisState.GovData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return slashing.ValidateGenesis(genesisState.SlashingData)
|
||||
}
|
||||
|
||||
// Ensures that there are no duplicate accounts in the genesis state,
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
authsim "github.com/cosmos/cosmos-sdk/x/auth/simulation"
|
||||
banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation"
|
||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||
@@ -75,6 +76,17 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||
})
|
||||
}
|
||||
|
||||
authGenesis := auth.GenesisState{
|
||||
Params: auth.Params{
|
||||
MemoCostPerByte: uint64(r.Intn(10) + 1),
|
||||
MaxMemoCharacters: uint64(r.Intn(200-100) + 100),
|
||||
TxSigLimit: uint64(r.Intn(7) + 1),
|
||||
SigVerifyCostED25519: uint64(r.Intn(1000-500) + 500),
|
||||
SigVerifyCostSecp256k1: uint64(r.Intn(1000-500) + 500),
|
||||
},
|
||||
}
|
||||
fmt.Printf("Selected randomly generated auth parameters:\n\t%+v\n", authGenesis)
|
||||
|
||||
// Random genesis states
|
||||
vp := time.Duration(r.Intn(2*172800)) * time.Second
|
||||
govGenesis := gov.GenesisState{
|
||||
@@ -151,6 +163,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
|
||||
|
||||
genesis := GenesisState{
|
||||
Accounts: genesisAccounts,
|
||||
AuthData: authGenesis,
|
||||
StakeData: stakeGenesis,
|
||||
MintData: mintGenesis,
|
||||
DistrData: distr.DefaultGenesisWithValidators(valAddrs),
|
||||
|
||||
@@ -165,16 +165,18 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
|
||||
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
|
||||
}
|
||||
|
||||
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
|
||||
|
||||
// define the accountKeeper
|
||||
app.accountKeeper = auth.NewAccountKeeper(
|
||||
app.cdc,
|
||||
app.keyAccount, // target store
|
||||
app.keyAccount, // target store
|
||||
app.paramsKeeper.Subspace(auth.DefaultParamspace),
|
||||
auth.ProtoBaseAccount, // prototype
|
||||
)
|
||||
|
||||
// add handlers
|
||||
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
|
||||
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
|
||||
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), stake.DefaultCodespace)
|
||||
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), slashing.DefaultCodespace)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user