mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
4a8b5696cb
* initial sketch * add module migrations * add migrations for all accout types * test account migration * add tendermint migration and migrate cmd * remove need for errors pkg dependency * add bech32 decoding fork * add suggested params and cmd to write them * add basic upgrade instructions * fix tests * address some migration todos * tidy contrib folder * finalize params values * align cdp init genesis with other modules * add tendermint and distribution test add custom distribution migration to patch bug * add staking migration test * add slashing, evidence tests, refactor auth tests * add full migration test * remove go-amino dependency from go.mod also tidy up unused indirect dependencies * address remaining TODOs * remove commented out code from legacy types * add spot/liquidation markets ids to kava-3 params * Apply suggestions from code review Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * address code review suggestions * add validate genesis to migrate test * refactor add params func * remove commented out code from old types * fix add params * add deputy address * add tests using exported kava-2 state * incorporate new cdp params from master * update params from review Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> * add deputy account * add committee permissions for new params Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com>
119 lines
3.6 KiB
Go
119 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
dbm "github.com/tendermint/tm-db"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/cli"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/server"
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
kava3 "github.com/kava-labs/kava/contrib/kava-3"
|
|
"github.com/kava-labs/kava/migrate"
|
|
)
|
|
|
|
// kvd custom flags
|
|
const flagInvCheckPeriod = "inv-check-period"
|
|
|
|
var invCheckPeriod uint
|
|
|
|
func main() {
|
|
cdc := app.MakeCodec()
|
|
|
|
config := sdk.GetConfig()
|
|
app.SetBech32AddressPrefixes(config)
|
|
app.SetBip44CoinType(config)
|
|
config.Seal()
|
|
|
|
ctx := server.NewDefaultContext()
|
|
cobra.EnableCommandSorting = false
|
|
rootCmd := &cobra.Command{
|
|
Use: "kvd",
|
|
Short: "Kava Daemon (server)",
|
|
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
|
|
}
|
|
|
|
rootCmd.AddCommand(
|
|
genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome),
|
|
genutilcli.CollectGenTxsCmd(ctx, cdc, auth.GenesisAccountIterator{}, app.DefaultNodeHome),
|
|
migrate.MigrateGenesisCmd(ctx, cdc),
|
|
kava3.WriteGenesisParamsCmd(cdc),
|
|
genutilcli.GenTxCmd(
|
|
ctx,
|
|
cdc,
|
|
app.ModuleBasics,
|
|
staking.AppModuleBasic{},
|
|
auth.GenesisAccountIterator{},
|
|
app.DefaultNodeHome,
|
|
app.DefaultCLIHome),
|
|
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),
|
|
AddGenesisAccountCmd(ctx, cdc, app.DefaultNodeHome, app.DefaultCLIHome),
|
|
flags.NewCompletionCmd(rootCmd, true),
|
|
)
|
|
|
|
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
|
|
|
|
// prepare and add flags
|
|
executor := cli.PrepareBaseCmd(rootCmd, "KA", app.DefaultNodeHome)
|
|
rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod,
|
|
0, "Assert registered invariants every N blocks")
|
|
err := executor.Execute()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
|
|
var cache sdk.MultiStorePersistentCache
|
|
|
|
if viper.GetBool(server.FlagInterBlockCache) {
|
|
cache = store.NewCommitKVStoreCacheManager()
|
|
}
|
|
|
|
skipUpgradeHeights := make(map[int64]bool)
|
|
for _, h := range viper.GetIntSlice(server.FlagUnsafeSkipUpgrades) {
|
|
skipUpgradeHeights[int64(h)] = true
|
|
}
|
|
|
|
return app.NewApp(
|
|
logger, db, traceStore, true, skipUpgradeHeights, invCheckPeriod,
|
|
baseapp.SetPruning(store.NewPruningOptionsFromString(viper.GetString("pruning"))),
|
|
baseapp.SetMinGasPrices(viper.GetString(server.FlagMinGasPrices)),
|
|
baseapp.SetHaltHeight(viper.GetUint64(server.FlagHaltHeight)),
|
|
baseapp.SetHaltTime(viper.GetUint64(server.FlagHaltTime)),
|
|
baseapp.SetInterBlockCache(cache),
|
|
)
|
|
}
|
|
|
|
func exportAppStateAndTMValidators(
|
|
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
|
|
) (json.RawMessage, []tmtypes.GenesisValidator, error) {
|
|
|
|
if height != -1 {
|
|
tempApp := app.NewApp(logger, db, traceStore, false, map[int64]bool{}, uint(1))
|
|
err := tempApp.LoadHeight(height)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
return tempApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
|
}
|
|
tempApp := app.NewApp(logger, db, traceStore, true, map[int64]bool{}, uint(1))
|
|
return tempApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
|
|
}
|