mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
tidy up naming
This commit is contained in:
parent
0f6f109f95
commit
4cbc222e4f
@ -285,7 +285,7 @@ func (app *App) initFromGenesisState(ctx sdk.Context, genesisState GenesisState)
|
|||||||
mint.InitGenesis(ctx, app.mintKeeper, genesisState.MintData)
|
mint.InitGenesis(ctx, app.mintKeeper, genesisState.MintData)
|
||||||
|
|
||||||
// validate genesis state
|
// validate genesis state
|
||||||
if err := GaiaValidateGenesisState(genesisState); err != nil {
|
if err := ValidateGenesisState(genesisState); err != nil {
|
||||||
panic(err) // TODO find a way to do this w/o panics
|
panic(err) // TODO find a way to do this w/o panics
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +308,7 @@ func (app *App) initFromGenesisState(ctx sdk.Context, genesisState GenesisState)
|
|||||||
return validators
|
return validators
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom logic for gaia initialization
|
// custom logic for app initialization
|
||||||
func (app *App) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
func (app *App) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
|
||||||
stateJSON := req.AppStateBytes
|
stateJSON := req.AppStateBytes
|
||||||
// TODO is this now the whole genesis file?
|
// TODO is this now the whole genesis file?
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setGenesis(gapp *App, accs ...*auth.BaseAccount) error {
|
func setGenesis(app *App, accs ...*auth.BaseAccount) error {
|
||||||
genaccs := make([]GenesisAccount, len(accs))
|
genaccs := make([]GenesisAccount, len(accs))
|
||||||
for i, acc := range accs {
|
for i, acc := range accs {
|
||||||
genaccs[i] = NewGenesisAccount(acc)
|
genaccs[i] = NewGenesisAccount(acc)
|
||||||
@ -40,26 +40,26 @@ func setGenesis(gapp *App, accs ...*auth.BaseAccount) error {
|
|||||||
slashing.DefaultGenesisState(),
|
slashing.DefaultGenesisState(),
|
||||||
)
|
)
|
||||||
|
|
||||||
stateBytes, err := codec.MarshalJSONIndent(gapp.cdc, genesisState)
|
stateBytes, err := codec.MarshalJSONIndent(app.cdc, genesisState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the chain
|
// Initialize the chain
|
||||||
vals := []abci.ValidatorUpdate{}
|
vals := []abci.ValidatorUpdate{}
|
||||||
gapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
|
app.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
|
||||||
gapp.Commit()
|
app.Commit()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
db := db.NewMemDB()
|
db := db.NewMemDB()
|
||||||
gapp := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
||||||
setGenesis(gapp)
|
setGenesis(app)
|
||||||
|
|
||||||
// Making a new app object with the db, so that initchain hasn't been called
|
// Making a new app object with the db, so that initchain hasn't been called
|
||||||
newGapp := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
newApp := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, 0)
|
||||||
_, _, err := newGapp.ExportAppStateAndValidators(false, []string{})
|
_, _, err := newApp.ExportAppStateAndValidators(false, []string{})
|
||||||
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
)
|
)
|
||||||
|
|
||||||
// export the state of gaia for a genesis file
|
// export the state of the app for a genesis file
|
||||||
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string) (
|
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string) (
|
||||||
appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
|
appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
|
||||||
|
|
||||||
|
@ -218,11 +218,11 @@ func NewDefaultGenesisState() GenesisState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GaiaValidateGenesisState ensures that the genesis state obeys the expected invariants
|
// ValidateGenesisState ensures that the genesis state obeys the expected invariants
|
||||||
// TODO: No validators are both bonded and jailed (#2088)
|
// TODO: No validators are both bonded and jailed (#2088)
|
||||||
// TODO: Error if there is a duplicate validator (#1708)
|
// TODO: Error if there is a duplicate validator (#1708)
|
||||||
// TODO: Ensure all state machine parameters are in genesis (#1704)
|
// TODO: Ensure all state machine parameters are in genesis (#1704)
|
||||||
func GaiaValidateGenesisState(genesisState GenesisState) error {
|
func ValidateGenesisState(genesisState GenesisState) error {
|
||||||
if err := validateGenesisStateAccounts(genesisState.Accounts); err != nil {
|
if err := validateGenesisStateAccounts(genesisState.Accounts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -109,23 +109,23 @@ func makeMsg(name string, pk crypto.PubKey) auth.StdTx {
|
|||||||
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
|
return auth.NewStdTx([]sdk.Msg{msg}, auth.StdFee{}, nil, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaiaGenesisValidation(t *testing.T) {
|
func TestGenesisValidation(t *testing.T) {
|
||||||
genTxs := []auth.StdTx{makeMsg("test-0", pk1), makeMsg("test-1", pk2)}
|
genTxs := []auth.StdTx{makeMsg("test-0", pk1), makeMsg("test-1", pk2)}
|
||||||
dupGenTxs := []auth.StdTx{makeMsg("test-0", pk1), makeMsg("test-1", pk1)}
|
dupGenTxs := []auth.StdTx{makeMsg("test-0", pk1), makeMsg("test-1", pk1)}
|
||||||
|
|
||||||
// require duplicate accounts fails validation
|
// require duplicate accounts fails validation
|
||||||
genesisState := makeGenesisState(t, dupGenTxs)
|
genesisState := makeGenesisState(t, dupGenTxs)
|
||||||
err := GaiaValidateGenesisState(genesisState)
|
err := ValidateGenesisState(genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// require invalid vesting account fails validation (invalid end time)
|
// require invalid vesting account fails validation (invalid end time)
|
||||||
genesisState = makeGenesisState(t, genTxs)
|
genesisState = makeGenesisState(t, genTxs)
|
||||||
genesisState.Accounts[0].OriginalVesting = genesisState.Accounts[0].Coins
|
genesisState.Accounts[0].OriginalVesting = genesisState.Accounts[0].Coins
|
||||||
err = GaiaValidateGenesisState(genesisState)
|
err = ValidateGenesisState(genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
genesisState.Accounts[0].StartTime = 1548888000
|
genesisState.Accounts[0].StartTime = 1548888000
|
||||||
genesisState.Accounts[0].EndTime = 1548775410
|
genesisState.Accounts[0].EndTime = 1548775410
|
||||||
err = GaiaValidateGenesisState(genesisState)
|
err = ValidateGenesisState(genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// require bonded + jailed validator fails validation
|
// require bonded + jailed validator fails validation
|
||||||
@ -134,7 +134,7 @@ func TestGaiaGenesisValidation(t *testing.T) {
|
|||||||
val1.Jailed = true
|
val1.Jailed = true
|
||||||
val1.Status = sdk.Bonded
|
val1.Status = sdk.Bonded
|
||||||
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
|
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
|
||||||
err = GaiaValidateGenesisState(genesisState)
|
err = ValidateGenesisState(genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
// require duplicate validator fails validation
|
// require duplicate validator fails validation
|
||||||
@ -143,7 +143,7 @@ func TestGaiaGenesisValidation(t *testing.T) {
|
|||||||
val2 := staking.NewValidator(addr1, pk1, staking.NewDescription("test #3", "", "", ""))
|
val2 := staking.NewValidator(addr1, pk1, staking.NewDescription("test #3", "", "", ""))
|
||||||
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
|
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val1)
|
||||||
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val2)
|
genesisState.StakingData.Validators = append(genesisState.StakingData.Validators, val2)
|
||||||
err = GaiaValidateGenesisState(genesisState)
|
err = ValidateGenesisState(genesisState)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ func TestNewDefaultGenesisAccount(t *testing.T) {
|
|||||||
|
|
||||||
func TestGenesisStateSanitize(t *testing.T) {
|
func TestGenesisStateSanitize(t *testing.T) {
|
||||||
genesisState := makeGenesisState(t, nil)
|
genesisState := makeGenesisState(t, nil)
|
||||||
require.Nil(t, GaiaValidateGenesisState(genesisState))
|
require.Nil(t, ValidateGenesisState(genesisState))
|
||||||
|
|
||||||
addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
|
||||||
authAcc1 := auth.NewBaseAccountWithAddress(addr1)
|
authAcc1 := auth.NewBaseAccountWithAddress(addr1)
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/store"
|
"github.com/cosmos/cosmos-sdk/store"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/kava-labs/kava/app"
|
||||||
gaiaInit "github.com/kava-labs/kava/init"
|
initPkg "github.com/kava-labs/kava/init"
|
||||||
)
|
)
|
||||||
|
|
||||||
// kvd custom flags
|
// kvd custom flags
|
||||||
@ -40,16 +40,16 @@ func main() {
|
|||||||
cobra.EnableCommandSorting = false
|
cobra.EnableCommandSorting = false
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: "kvd",
|
Use: "kvd",
|
||||||
Short: "Gaia Daemon (server)",
|
Short: "Kava Daemon (server)",
|
||||||
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.AddCommand(gaiaInit.InitCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.InitCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(gaiaInit.CollectGenTxsCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.CollectGenTxsCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(gaiaInit.TestnetFilesCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.TestnetFilesCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(gaiaInit.GenTxCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.GenTxCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(gaiaInit.AddGenesisAccountCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.AddGenesisAccountCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(gaiaInit.ValidateGenesisCmd(ctx, cdc))
|
rootCmd.AddCommand(initPkg.ValidateGenesisCmd(ctx, cdc))
|
||||||
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
|
rootCmd.AddCommand(client.NewCompletionCmd(rootCmd, true))
|
||||||
|
|
||||||
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
|
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
|
||||||
|
@ -89,7 +89,7 @@ following delegation and commission default parameters:
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = app.GaiaValidateGenesisState(genesisState); err != nil {
|
if err = app.ValidateGenesisState(genesisState); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func TestInitCmd(t *testing.T) {
|
|||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
cmd := InitCmd(ctx, cdc)
|
cmd := InitCmd(ctx, cdc)
|
||||||
|
|
||||||
require.NoError(t, cmd.RunE(nil, []string{"gaianode-test"}))
|
require.NoError(t, cmd.RunE(nil, []string{"kavanode-test"}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupClientHome(t *testing.T) func() {
|
func setupClientHome(t *testing.T) func() {
|
||||||
@ -59,7 +59,7 @@ func TestEmptyState(t *testing.T) {
|
|||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
|
|
||||||
cmd := InitCmd(ctx, cdc)
|
cmd := InitCmd(ctx, cdc)
|
||||||
require.NoError(t, cmd.RunE(nil, []string{"gaianode-test"}))
|
require.NoError(t, cmd.RunE(nil, []string{"kavanode-test"}))
|
||||||
|
|
||||||
old := os.Stdout
|
old := os.Stdout
|
||||||
r, w, _ := os.Pipe()
|
r, w, _ := os.Pipe()
|
||||||
@ -101,7 +101,7 @@ func TestStartStandAlone(t *testing.T) {
|
|||||||
ctx := server.NewContext(cfg, logger)
|
ctx := server.NewContext(cfg, logger)
|
||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
initCmd := InitCmd(ctx, cdc)
|
initCmd := InitCmd(ctx, cdc)
|
||||||
require.NoError(t, initCmd.RunE(nil, []string{"gaianode-test"}))
|
require.NoError(t, initCmd.RunE(nil, []string{"kavanode-test"}))
|
||||||
|
|
||||||
app, err := mock.NewApp(home, logger)
|
app, err := mock.NewApp(home, logger)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
@ -106,8 +106,8 @@ func initTestnet(config *tmconfig.Config, cdc *codec.Codec) error {
|
|||||||
nodeIDs := make([]string, numValidators)
|
nodeIDs := make([]string, numValidators)
|
||||||
valPubKeys := make([]crypto.PubKey, numValidators)
|
valPubKeys := make([]crypto.PubKey, numValidators)
|
||||||
|
|
||||||
gaiaConfig := srvconfig.DefaultConfig()
|
appConfig := srvconfig.DefaultConfig()
|
||||||
gaiaConfig.MinGasPrices = viper.GetString(server.FlagMinGasPrices)
|
appConfig.MinGasPrices = viper.GetString(server.FlagMinGasPrices)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
accs []app.GenesisAccount
|
accs []app.GenesisAccount
|
||||||
@ -236,8 +236,8 @@ func initTestnet(config *tmconfig.Config, cdc *codec.Codec) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gaiaConfigFilePath := filepath.Join(nodeDir, "config/kvd.toml")
|
appConfigFilePath := filepath.Join(nodeDir, "config/kvd.toml")
|
||||||
srvconfig.WriteConfigFile(gaiaConfigFilePath, gaiaConfig)
|
srvconfig.WriteConfigFile(appConfigFilePath, appConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := initGenFiles(cdc, chainID, accs, genFiles, numValidators); err != nil {
|
if err := initGenFiles(cdc, chainID, accs, genFiles, numValidators); err != nil {
|
||||||
|
@ -40,7 +40,7 @@ func ValidateGenesisCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
|
|||||||
return fmt.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error())
|
return fmt.Errorf("Error unmarshaling genesis doc %s: %s", genesis, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = app.GaiaValidateGenesisState(genstate); err != nil {
|
if err = app.ValidateGenesisState(genstate); err != nil {
|
||||||
return fmt.Errorf("Error validating genesis file %s: %s", genesis, err.Error())
|
return fmt.Errorf("Error validating genesis file %s: %s", genesis, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user