From dbb8f387f9515b357d4679536e40574347cebf27 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Sun, 30 Aug 2020 10:47:07 -0400 Subject: [PATCH] fix: use correct committee params (#640) --- cmd/kvd/main.go | 34 -- contrib/kava-3/cmd.go | 77 ---- contrib/kava-3/migration.md | 168 -------- contrib/kava-3/params.go | 424 -------------------- contrib/kava-3/params_test.go | 42 -- x/committee/keeper/param_permission_test.go | 4 +- x/committee/keeper/proposal_test.go | 2 +- x/committee/types/param_permissions_test.go | 32 +- x/committee/types/permissions.go | 8 +- x/issuance/module.go | 2 +- 10 files changed, 28 insertions(+), 765 deletions(-) delete mode 100644 contrib/kava-3/cmd.go delete mode 100644 contrib/kava-3/migration.md delete mode 100644 contrib/kava-3/params.go delete mode 100644 contrib/kava-3/params_test.go diff --git a/cmd/kvd/main.go b/cmd/kvd/main.go index 65c1c245..3146225d 100644 --- a/cmd/kvd/main.go +++ b/cmd/kvd/main.go @@ -17,9 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/server" - srvconfig "github.com/cosmos/cosmos-sdk/server/config" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" @@ -27,7 +25,6 @@ import ( "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" ) @@ -56,7 +53,6 @@ func main() { genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome), genutilcli.CollectGenTxsCmd(ctx, cdc, auth.GenesisAccountIterator{}, app.DefaultNodeHome), migrate.MigrateGenesisCmd(ctx, cdc), - writeParamsAndConfigCmd(cdc), genutilcli.GenTxCmd( ctx, cdc, @@ -144,33 +140,3 @@ func persistentPreRunEFn(ctx *server.Context) func(*cobra.Command, []string) err return nil } } - -// writeParamsAndConfigCmd patches the write-params cmd to additionally update the app pruning config. -func writeParamsAndConfigCmd(cdc *codec.Codec) *cobra.Command { - cmd := kava3.WriteGenesisParamsCmd(cdc) - originalFunc := cmd.RunE - - wrappedFunc := func(cmd *cobra.Command, args []string) error { - - if err := originalFunc(cmd, args); err != nil { - return err - } - - // fetch the app config from viper - cfg, err := srvconfig.ParseConfig() - if err != nil { - return nil // don't return errors since as failures aren't critical - } - // don't prune any state, ie store everything - cfg.Pruning = store.PruningStrategyNothing - // write updated config - if viper.ConfigFileUsed() == "" { - return nil - } - srvconfig.WriteConfigFile(viper.ConfigFileUsed(), cfg) - return nil - } - - cmd.RunE = wrappedFunc - return cmd -} diff --git a/contrib/kava-3/cmd.go b/contrib/kava-3/cmd.go deleted file mode 100644 index 355cb10a..00000000 --- a/contrib/kava-3/cmd.go +++ /dev/null @@ -1,77 +0,0 @@ -package kava3 - -import ( - "fmt" - "time" - - "github.com/spf13/cobra" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/version" -) - -const ( - defaultChainID = "kava-3" - defaultGenesisTime = "2020-06-01T14:00:00Z" - flagGenesisTime = "genesis-time" - flagChainID = "chain-id" -) - -// WriteGenesisParamsCmd returns a command to write suggested kava-3 params to a genesis file. -func WriteGenesisParamsCmd(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "write-params [genesis-file]", - Short: "Write suggested params to a genesis file", - Long: "Write suggested module parameters to a gensis file, sort it, and print to STDOUT.", - Example: fmt.Sprintf(`%s write-params /path/to/genesis.json`, version.ServerName), - Args: cobra.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - - // Unmarshal existing genesis.json - - importGenesis := args[0] - genDoc, err := tmtypes.GenesisDocFromFile(importGenesis) - if err != nil { - return fmt.Errorf("failed to read genesis doc from file %s: %w", importGenesis, err) - } - - // Unmarshal flags - - chainID := cmd.Flag(flagChainID).Value.String() - genesisTime := cmd.Flag(flagGenesisTime).Value.String() - var parsedGenesisTime time.Time - if err := parsedGenesisTime.UnmarshalText([]byte(genesisTime)); err != nil { - return fmt.Errorf("failed to unmarshal genesis time: %w", err) - } - - // Write new params to the genesis file - - newGenDoc, err := AddSuggestedParams(cdc, *genDoc, chainID, parsedGenesisTime) - if err != nil { - return fmt.Errorf("failed to write params: %w", err) - } - - // Marshal output a new genesis file - - bz, err := cdc.MarshalJSONIndent(newGenDoc, "", " ") - if err != nil { - return fmt.Errorf("failed to marshal genesis doc: %w", err) - } - sortedBz, err := sdk.SortJSON(bz) - if err != nil { - return fmt.Errorf("failed to sort JSON genesis doc: %w", err) - } - - fmt.Println(string(sortedBz)) - - return nil - }, - } - - cmd.Flags().String(flagGenesisTime, defaultGenesisTime, "override genesis time") - cmd.Flags().String(flagChainID, defaultChainID, "override chain-id") - - return cmd -} diff --git a/contrib/kava-3/migration.md b/contrib/kava-3/migration.md deleted file mode 100644 index a42efc17..00000000 --- a/contrib/kava-3/migration.md +++ /dev/null @@ -1,168 +0,0 @@ -# Kava-3 Upgrade Instructions - -## Background - -The version of Kava for kava-3 is __v0.8.x__. Kava-3 is scheduled to launch __June 10, 2020 at 14:00 UTC__ - -🚨 Please note that an issue with tendermint v0.33 has been found that affects the stability of nodes running with the default pruning strategy. Please see the [Pruning](#Pruning) section for full details and mitigation 🚨 - -Many changes have occurred in both the Kava software and the cosmos-sdk software since the launch of kava-2. The primary changes in Kava are the addition of modules that comprise the [CDP system](https://docs.kava.io/). To review cosmos-sdk changes, see the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md) and note that kava-3 is launching with __v0.38.4__ of the cosmos-sdk. - -If you have technical questions or concerns, ask a developer or community member in the [Kava discord](https://discord.com/invite/kQzh3Uv). - -### Risks - -As a validator, performing the upgrade procedure on your consensus nodes carries a heightened risk of double-signing and being slashed. The most important piece of this procedure is verifying your software version and genesis file hash before starting your validator and signing. - -The riskiest thing a validator can do is discover that they made a mistake and repeat the upgrade procedure again during the network startup. If you discover a mistake in the process, the best thing to do is wait for the network to start before correcting it. If the network is halted and you have started with a different genesis file than the expected one, seek advice from a Kava developer before resetting your validator. - -### Pruning - -kava-3 uses tendermint version 0.33. Recent testing in Game of Zones and Kava has shown that nodes which are running with the default or custom pruning strategy have a [memory leak](https://github.com/tendermint/iavl/issues/256) that can cause nodes to crash and lead to irrecoverable data loss. Until a patch is released, the __ONLY__ pruning strategies that are safe to run are `nothing` (an archival node, where nothing is deleted) or `everything` (only the most recent state is kept). - -The pruning config is set in $HOME/.kvd/config/app.toml. Example safe configurations are: - -```toml -pruning = "nothing" -``` - -and - -```toml -pruning = "everything" -``` - -Exchange operators, data service providers, and other vendors who require access to historical state are recommended to run archival nodes (`pruning = "nothing"`). Other node operators can choose between a fully pruning node and archival node, with the main difference being increased storage required for archival nodes. - -It is expected that a patch to tendermint will be released in a non-breaking manner and that nodes will be able to update seamlessly after the launch of kava-3. - -### Recovery - -Prior to exporting kava-2 state, validators are encouraged to take a full data snapshot at the export height before proceeding. Snapshotting depends heavily on infrastructure, but generally this can be done by backing up the .kvd and .kvcli directories. - -It is critically important to back-up the .kvd/data/priv_validator_state.json file after stopping your kvd process. This file is updated every block as your validator participates in consensus rounds. It is a critical file needed to prevent double-signing, in case the upgrade fails and the previous chain needs to be restarted. - -In the event that the upgrade does not succeed, validators and operators must downgrade back to v0.3.5 of the Kava software and restore to their latest snapshot before restarting their nodes. - -## Upgrade Procedure - -Set your node to produce the final block of kava-2 at __13:00__ UTC June 10th, 2020. To restart your node with that stop time, - -```bash -kvd start --halt-time 1591794000 -``` - -Note that the above command will not stop `kvd` from running, it merely stops proposal / validation for blocks after that time.Validators may safely exit by issuing `CTRL+C` if running as a process. - -Kava developers will update this PR with the final block number when it is reached. __Make sure the kvd process is stopped before proceeding and that you have backed up your validator__. Failure to backup your validator could make it impossible to restart your node if the upgrade fails. - -The following up steps assume the directory structure below: change filepaths, directory names as needed - -```bash -# Kvcli Folder -~/.kvcli -# Kvd Folder -~/.kvd -# Go Path -~/go -``` - -### Pre-Migration - -1. Backup existing kava-2 .kvd and .kvcli -```bash -cp -R ~/.kvcli ~/.kvcli.bak -cp -R ~/.kvd ~/.kvd.bak -``` - -2. Backup existing kava-2 kvd and kvcli binaries (in case of rollback) -```bash -cp ~/go/bin/kvcli ~/go/bin/kvcli.bak -cp ~/go/bin/kvd ~/go/bin/kvd.bak -``` - -### Migration - -We denote `(kava-2)kvd` as the previous client (0.3.5) to be used for commands e.g `(kava-2)kvd export` and `(kava-3)kvd` as the new client (0.8.1) to be used for commands. - -1. Export state - -- Ensure that all `kvd` processes have stopped running. - -```bash - (kava-2) kvd export --height 2598890 --for-zero-height > kava_2_exported.json - # Check ShaSum for later reference - $ jq -S -c -M '' kava_2_exported.json | shasum -a 256 - # Should return - > 7b5ec6f003b3aaf0544e7490f2e383a3b0339ec4db372ce84e68992f018e20e6 - -``` - -2. Update to kava-3 - -This will replace the `kvd` and `kvcli` binaries in your GOPATH. - -```bash - # in the `kava` folder - git pull - git checkout v0.8.1 - make install - - # verify versions - kvd version --long - # name: kava - # server_name: kvd - # client_name: kvcli - # version: 0.8.1 - # commit: 869189054d68d6ec3e6446156ea0a91eb45af09c - # build_tags: netgo,ledger - # go: go version go1.13.7 linux/amd64 -``` - -3. Migrate the kava-2 keys from previous key store to new key store - -This will scan for any keys in `.kvcli` and produce new files ending in `kavaxxx.address` and `key_name.info` for the new keystore to access. - -```bash - # Migrate keys - (kava-3) kvcli keys migrate -``` - -4. Migrate the exported genesis state - -```bash - # Migrate genesis state - (kava-3) kvd migrate kava_2_exported.json > kava_3_migrated.json - # Check ShaSum for later reference - $ jq -S -c -M '' kava_3_migrated.json | shasum -a 256 - # Should return - > a7dcd440604a150a55a33e8cd22d7d1884d06ed4668e8090f6824755f4099325 - -``` - -5. Write Params to genesis state and validate - -```bash - # Migrate parameters - (kava-3) kvd write-params kava_3_migrated.json --chain-id kava-3 --genesis-time 2020-06-10T14:00:00Z > genesis.json - # Check ShaSum for later reference - # Note: jq must be installed - # DO NOT WRITE THE JQ OUTPUT TO FILE. Use only for calculating the hash. - $ jq -S -c -M '' genesis.json | shasum -a 256 - # Should return - > f73628abfab82601c9af97a023d357a95507b9c630c5331564f48c4acab97b85 - - # Verify output of genesis migration - (kava-3) kvd validate-genesis genesis.json # should say it's valid -``` - -6. Restart node with new kava-3 genesis state - -```bash - cp genesis.json ~/.kvd/config/genesis.json - # Unsafe Reset All is a irreversible action that wipes on-chain data and prepares the chain for a start from genesis - # If you have not backed up your previous kava-2 state, do not proceed. - (kava-3) kvd unsafe-reset-all - (kava-3) kvd start -``` - -### Coordination - -If the `kava-3` chain does not launch by June 10, 2020 at 16:00 UTC, the launch should be considered a failure. Validators should restore the state from `kava-2` and coordinate a relaunch. In the event of launch failure, coordination will occur in the [Kava discord](https://discord.com/invite/kQzh3Uv). diff --git a/contrib/kava-3/params.go b/contrib/kava-3/params.go deleted file mode 100644 index 3472ebcf..00000000 --- a/contrib/kava-3/params.go +++ /dev/null @@ -1,424 +0,0 @@ -// kava3 contains the suggested genesis parameters for the kava-3 mainnet. -package kava3 - -import ( - "fmt" - "time" - - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/genutil" - "github.com/cosmos/cosmos-sdk/x/supply" - - "github.com/kava-labs/kava/x/auction" - v0_8bep3 "github.com/kava-labs/kava/x/bep3/legacy/v0_9" - "github.com/kava-labs/kava/x/cdp" - "github.com/kava-labs/kava/x/committee" - "github.com/kava-labs/kava/x/incentive" - "github.com/kava-labs/kava/x/kavadist" - "github.com/kava-labs/kava/x/pricefeed" -) - -const ( - kavaDenom = "ukava" - bnbDenom = "bnb" - usdxDenom = "usdx" - referenceAsset = "usd" - bnbSpotMarketID = bnbDenom + ":" + referenceAsset - bnbLiquidationMarketID = bnbDenom + ":" + referenceAsset + ":" + "30" - debtDenom = "debt" - deputyAddressBech32 = "kava1r4v2zdhdalfj2ydazallqvrus9fkphmglhn6u6" // Binance deputy address -) - -func AddSuggestedParams(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, chainID string, genesisTime time.Time) (tmtypes.GenesisDoc, error) { - - // Add tendermint params - - genDoc.ChainID = chainID - genDoc.GenesisTime = genesisTime - - // Add app params - - var appState genutil.AppMap - if err := cdc.UnmarshalJSON(genDoc.AppState, &appState); err != nil { - return tmtypes.GenesisDoc{}, err - } - - addAuctionState(cdc, appState) - addBep3DeputyAccount(cdc, appState) - addBep3State(cdc, appState) - addCDPState(cdc, appState) - addCommitteeState(cdc, appState) - addIncentiveState(cdc, appState) - addKavaDistState(cdc, appState) - addPricefeedState(cdc, appState) - - marshaledAppState, err := cdc.MarshalJSON(appState) - if err != nil { - return tmtypes.GenesisDoc{}, err - } - genDoc.AppState = marshaledAppState - - return genDoc, nil -} - -func addBep3DeputyAccount(cdc *codec.Codec, appState genutil.AppMap) { - deputyCoins := sdk.NewCoins(sdk.NewInt64Coin(bnbDenom, 350_000_000_000_000)) - - // 1) Add account - var authGenState auth.GenesisState - cdc.MustUnmarshalJSON(appState[auth.ModuleName], &authGenState) - - authGenState.Accounts = append( - authGenState.Accounts, - auth.NewBaseAccount( - mustAccAddressFromBech32(deputyAddressBech32), - deputyCoins, - nil, // pubkey is nil for new accounts, it's set when the account first sends a tx - 0, // account numbers are reset on auth.InitGenesis, so this value doesn't matter - 0, // sequence number starts at 0 - ), - ) - appState[auth.ModuleName] = cdc.MustMarshalJSON(authGenState) - - // 2) Update total supply - var supplyGenState supply.GenesisState - cdc.MustUnmarshalJSON(appState[supply.ModuleName], &supplyGenState) - - supplyGenState.Supply = supplyGenState.Supply.Add(deputyCoins...) - - appState[supply.ModuleName] = cdc.MustMarshalJSON(supplyGenState) -} - -func addAuctionState(cdc *codec.Codec, appState genutil.AppMap) { - appState[auction.ModuleName] = cdc.MustMarshalJSON(auction.NewGenesisState( - auction.DefaultNextAuctionID, - auction.NewParams( - 24*time.Hour, - 8*time.Hour, - sdk.MustNewDecFromStr("0.01"), - sdk.MustNewDecFromStr("0.01"), - sdk.MustNewDecFromStr("0.01"), - ), - auction.GenesisAuctions{}, - )) -} - -func addBep3State(cdc *codec.Codec, appState genutil.AppMap) { - appState[v0_8bep3.ModuleName] = cdc.MustMarshalJSON(v0_8bep3.NewGenesisState( - v0_8bep3.NewParams( - mustAccAddressFromBech32(deputyAddressBech32), - v0_8bep3.DefaultBnbDeputyFixedFee, - v0_8bep3.DefaultMinAmount, - v0_8bep3.DefaultMaxAmount, - v0_8bep3.DefaultMinBlockLock, - v0_8bep3.DefaultMaxBlockLock, - v0_8bep3.AssetParams{{ - Denom: bnbDenom, - CoinID: 714, - Limit: sdk.NewInt(4_000_000_000_000), - Active: true, - }}, - ), - v0_8bep3.AtomicSwaps{}, - v0_8bep3.AssetSupplies{}, - )) -} - -func addCDPState(cdc *codec.Codec, appState genutil.AppMap) { - appState[cdp.ModuleName] = cdc.MustMarshalJSON(cdp.NewGenesisState( - cdp.NewParams( - sdk.NewInt64Coin(usdxDenom, 100_000_000_000), - cdp.CollateralParams{{ - Denom: bnbDenom, - LiquidationRatio: sdk.MustNewDecFromStr("1.5"), - DebtLimit: sdk.NewInt64Coin(usdxDenom, 100_000_000_000), - StabilityFee: sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr - LiquidationPenalty: sdk.MustNewDecFromStr("0.075"), - AuctionSize: sdk.NewInt(50_000_000_000), - Prefix: 0x20, - ConversionFactor: sdk.NewInt(8), - SpotMarketID: bnbSpotMarketID, - LiquidationMarketID: bnbLiquidationMarketID, - }}, - cdp.DebtParam{ - Denom: usdxDenom, - ReferenceAsset: referenceAsset, - ConversionFactor: sdk.NewInt(6), - DebtFloor: sdk.NewInt(10_000_000), - SavingsRate: sdk.MustNewDecFromStr("0.9"), - }, - // below values are usdx coin amounts - sdk.NewInt(200_000_000_000), // surplusThreshold - sdk.NewInt(10_000_000_000), // surplusLot - sdk.NewInt(50_000_000_000), // debtThreshold - sdk.NewInt(10_000_000_000), // debtLot - 24*time.Hour, - false, - ), - cdp.CDPs{}, - cdp.Deposits{}, - cdp.DefaultCdpStartingID, - debtDenom, - kavaDenom, - cdp.DefaultPreviousDistributionTime, - )) -} - -func addCommitteeState(cdc *codec.Codec, appState genutil.AppMap) { - appState[committee.ModuleName] = cdc.MustMarshalJSON(committee.NewGenesisState( - committee.DefaultNextProposalID, - []committee.Committee{ - committee.NewCommittee( - 1, - "Kava Stability Committee", - []sdk.AccAddress{ - // addresses from governance proposal: https://ipfs.io/ipfs/QmSiQexKNixztPgLCe2cRSJ8ZLRjetRgzHPDTuBRCm9DZb/committee-nominations.pdf - mustAccAddressFromBech32("kava1gru35up50ql2wxhegr880qy6ynl63ujlv8gum2"), - mustAccAddressFromBech32("kava1sc3mh3pkas5e7xd269am4xm5mp6zweyzmhjagj"), - mustAccAddressFromBech32("kava1c9ye54e3pzwm3e0zpdlel6pnavrj9qqv6e8r4h"), - mustAccAddressFromBech32("kava1m7p6sjqrz6mylz776ct48wj6lpnpcd0z82209d"), - mustAccAddressFromBech32("kava1a9pmkzk570egv3sflu3uwdf3gejl7qfy9hghzl"), - }, - []committee.Permission{ - committee.SubParamChangePermission{ - AllowedParams: committee.AllowedParams{ - { - Subspace: auction.ModuleName, - Key: string(auction.KeyBidDuration), - }, - { - Subspace: auction.ModuleName, - Key: string(auction.KeyIncrementSurplus), - }, - { - Subspace: auction.ModuleName, - Key: string(auction.KeyIncrementDebt), - }, - { - Subspace: auction.ModuleName, - Key: string(auction.KeyIncrementCollateral), - }, - { - Subspace: v0_8bep3.ModuleName, - Key: string(v0_8bep3.KeySupportedAssets), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyGlobalDebtLimit), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeySurplusThreshold), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeySurplusLot), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyDebtThreshold), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyDebtLot), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyDistributionFrequency), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyCollateralParams), - }, - { - Subspace: cdp.ModuleName, - Key: string(cdp.KeyDebtParam), - }, - { - Subspace: incentive.ModuleName, - Key: string(incentive.KeyActive), - }, - { - Subspace: kavadist.ModuleName, - Key: string(kavadist.KeyActive), - }, - { - Subspace: pricefeed.ModuleName, - Key: string(pricefeed.KeyMarkets), - }, - }, - AllowedCollateralParams: committee.AllowedCollateralParams{{ - Denom: bnbDenom, - LiquidationRatio: false, - DebtLimit: true, - StabilityFee: true, - AuctionSize: true, - LiquidationPenalty: false, - Prefix: false, - SpotMarketID: false, - LiquidationMarketID: false, - ConversionFactor: false, - }}, - AllowedDebtParam: committee.AllowedDebtParam{ - Denom: false, - ReferenceAsset: false, - ConversionFactor: false, - DebtFloor: true, - SavingsRate: true, - }, - AllowedAssetParams: committee.AllowedAssetParams{{ - Denom: bnbDenom, - CoinID: false, - Limit: true, - Active: true, - }}, - AllowedMarkets: committee.AllowedMarkets{ - { - MarketID: bnbSpotMarketID, - BaseAsset: false, - QuoteAsset: false, - Oracles: false, - Active: true, - }, - { - MarketID: bnbLiquidationMarketID, - BaseAsset: false, - QuoteAsset: false, - Oracles: false, - Active: true, - }, - }, - }, - committee.TextPermission{}, - }, - sdk.MustNewDecFromStr("0.5"), // 3 of 5 - 7*24*time.Hour, - ), - committee.NewCommittee( - 2, - "Kava Safety Committee", - []sdk.AccAddress{ - // address from governance proposal: https://ipfs.io/ipfs/QmPqfP1Fa8EyzubmctL5uT5TAcWTB7HBQd8pvrmSTG8yS1/safety-nominations.pdf - mustAccAddressFromBech32("kava1e0agyg6eug9r62fly9sls77ycjgw8ax6xk73es"), - }, - []committee.Permission{committee.SoftwareUpgradePermission{}}, - sdk.MustNewDecFromStr("0.5"), - 7*24*time.Hour, - ), - }, - []committee.Proposal{}, - []committee.Vote{}, - )) -} - -func addIncentiveState(cdc *codec.Codec, appState genutil.AppMap) { - appState[incentive.ModuleName] = cdc.MustMarshalJSON(incentive.NewGenesisState( - incentive.NewParams( - true, - incentive.Rewards{incentive.NewReward( - false, - kavaDenom, - sdk.NewInt64Coin(kavaDenom, 74_000_000_000), - 1*7*24*time.Hour, - 1*365*24*time.Hour, - 1*7*24*time.Hour, - )}, - ), - incentive.DefaultPreviousBlockTime, - incentive.RewardPeriods{}, - incentive.ClaimPeriods{}, - incentive.Claims{}, - incentive.GenesisClaimPeriodIDs{}, - )) -} - -func addKavaDistState(cdc *codec.Codec, appState genutil.AppMap) { - appState[kavadist.ModuleName] = cdc.MustMarshalJSON(kavadist.NewGenesisState( - kavadist.NewParams( - true, - kavadist.Periods{ - { - Start: time.Date(2020, 6, 1, 14, 0, 0, 0, time.UTC), - End: time.Date(2021, 6, 1, 14, 0, 0, 0, time.UTC), - Inflation: sdk.MustNewDecFromStr("1.000000004431822130"), // 15% - }, - { - Start: time.Date(2021, 6, 1, 14, 0, 0, 0, time.UTC), - End: time.Date(2022, 6, 1, 14, 0, 0, 0, time.UTC), - Inflation: sdk.MustNewDecFromStr("1.000000002293273137"), // 7.5% - }, - { - Start: time.Date(2022, 6, 1, 14, 0, 0, 0, time.UTC), - End: time.Date(2023, 6, 1, 14, 0, 0, 0, time.UTC), - Inflation: sdk.MustNewDecFromStr("1.000000001167363430"), // 3.75% - }, - { - Start: time.Date(2023, 6, 1, 14, 0, 0, 0, time.UTC), - End: time.Date(2024, 6, 1, 14, 0, 0, 0, time.UTC), - Inflation: sdk.MustNewDecFromStr("1.000000000782997609"), // 2.5% - }, - }, - ), - kavadist.DefaultPreviousBlockTime, - )) -} - -func addPricefeedState(cdc *codec.Codec, appState genutil.AppMap) { - appState[pricefeed.ModuleName] = cdc.MustMarshalJSON(pricefeed.NewGenesisState( - pricefeed.NewParams( - pricefeed.Markets{ - { - MarketID: bnbSpotMarketID, - BaseAsset: bnbDenom, - QuoteAsset: referenceAsset, - Oracles: []sdk.AccAddress{ - // addresses from governance proposal: https://ipfs.io/ipfs/QmXgSJ4Dcji8msKpDwYHLmfPSLjRxCEGX6egXQU9DzmFMK/oracle-nominations.pdf - mustAccAddressFromBech32("kava12dyshua9nkvx9w8ywp72wdnzrc4t4mnnycz0dl"), - mustAccAddressFromBech32("kava1tuxyepdrkwraa22k99w04c0wa64tgh70mv87fs"), - mustAccAddressFromBech32("kava1ueak7nzesm3pnev6lngp6lgk0ry02djz8pjpcg"), - mustAccAddressFromBech32("kava1sl62nqm89c780yxm3m9lp3tacmpnfljq6tytvl"), - mustAccAddressFromBech32("kava1ujfrlcd0ted58mzplnyxzklsw0sqevlgxndanp"), - mustAccAddressFromBech32("kava17fatl3wzxvk4rwfu3tqsctdp5x9vute67j9ufj"), - mustAccAddressFromBech32("kava19rjk5qmmwywnzfccwzyn02jywgpwjqf60afj92"), - mustAccAddressFromBech32("kava1xd39avn2f008jmvua0eupg39zsp2xn3wf802vn"), - mustAccAddressFromBech32("kava1pt6q4kdmwawr3thm9cd82pq7hml8u84rd0f3jy"), - mustAccAddressFromBech32("kava13tpwqygswyzupqfggfgh9dmtgthgucn5wpfksh"), - }, - Active: true, - }, - { - MarketID: bnbLiquidationMarketID, - BaseAsset: bnbDenom, - QuoteAsset: referenceAsset, - Oracles: []sdk.AccAddress{ - // addresses from governance proposal: https://ipfs.io/ipfs/QmXgSJ4Dcji8msKpDwYHLmfPSLjRxCEGX6egXQU9DzmFMK/oracle-nominations.pdf - mustAccAddressFromBech32("kava12dyshua9nkvx9w8ywp72wdnzrc4t4mnnycz0dl"), - mustAccAddressFromBech32("kava1tuxyepdrkwraa22k99w04c0wa64tgh70mv87fs"), - mustAccAddressFromBech32("kava1ueak7nzesm3pnev6lngp6lgk0ry02djz8pjpcg"), - mustAccAddressFromBech32("kava1sl62nqm89c780yxm3m9lp3tacmpnfljq6tytvl"), - mustAccAddressFromBech32("kava1ujfrlcd0ted58mzplnyxzklsw0sqevlgxndanp"), - mustAccAddressFromBech32("kava17fatl3wzxvk4rwfu3tqsctdp5x9vute67j9ufj"), - mustAccAddressFromBech32("kava19rjk5qmmwywnzfccwzyn02jywgpwjqf60afj92"), - mustAccAddressFromBech32("kava1xd39avn2f008jmvua0eupg39zsp2xn3wf802vn"), - mustAccAddressFromBech32("kava1pt6q4kdmwawr3thm9cd82pq7hml8u84rd0f3jy"), - mustAccAddressFromBech32("kava13tpwqygswyzupqfggfgh9dmtgthgucn5wpfksh"), - }, - Active: true, - }, - }, - ), - pricefeed.PostedPrices{}, - )) -} - -func mustAccAddressFromBech32(addrBech32 string) sdk.AccAddress { - addr, err := sdk.AccAddressFromBech32(addrBech32) - if err != nil { - panic(fmt.Errorf("couldn't decode address: %w", err)) - } - return addr -} diff --git a/contrib/kava-3/params_test.go b/contrib/kava-3/params_test.go deleted file mode 100644 index 18d3097b..00000000 --- a/contrib/kava-3/params_test.go +++ /dev/null @@ -1,42 +0,0 @@ -package kava3 - -import ( - "path/filepath" - "testing" - "time" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/genutil" - - "github.com/kava-labs/kava/app" - "github.com/kava-labs/kava/migrate/v0_8" - v032tendermint "github.com/kava-labs/kava/migrate/v0_8/tendermint/v0_32" -) - -func TestAddSuggestedParams(t *testing.T) { - tApp := app.NewTestApp() // also sets the bech32 prefix on sdk.Config - cdc := app.MakeCodec() - - // 1) load an exported kava-2 state and migrate to kava v0.8 format (avoids storing v0.8 state that can get out of date) - oldGenDoc, err := v032tendermint.GenesisDocFromFile(filepath.Join("../../migrate/v0_8/testdata", "kava-2.json")) - require.NoError(t, err) - genDoc := v0_8.Migrate(*oldGenDoc) - - // 2) add params - newGenDoc, err := AddSuggestedParams(cdc, genDoc, "new-chain-id", time.Date(1998, 1, 0, 0, 0, 0, 0, time.UTC)) - require.NoError(t, err) - - // 3) check new genesis is valid - var newAppState genutil.AppMap - require.NoError(t, - cdc.UnmarshalJSON(newGenDoc.AppState, &newAppState), - ) - require.NoError(t, - app.ModuleBasics.ValidateGenesis(newAppState), - ) - require.NotPanics(t, func() { - // this runs both InitGenesis for all modules (which panic on errors) and runs all invariants - tApp.InitializeFromGenesisStates(app.GenesisState(newAppState)) - }) -} diff --git a/x/committee/keeper/param_permission_test.go b/x/committee/keeper/param_permission_test.go index 454ec3a2..b2c380e3 100644 --- a/x/committee/keeper/param_permission_test.go +++ b/x/committee/keeper/param_permission_test.go @@ -171,12 +171,12 @@ func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() { }, AllowedCollateralParams: types.AllowedCollateralParams{ { - Denom: "bnb", + Type: "bnb-a", DebtLimit: true, StabilityFee: true, }, { // TODO currently even if a perm doesn't allow a change in one element it must still be present in list - Denom: "btc", + Type: "btc-a", }, }, AllowedDebtParam: types.AllowedDebtParam{ diff --git a/x/committee/keeper/proposal_test.go b/x/committee/keeper/proposal_test.go index cea6bc12..fcf1d51d 100644 --- a/x/committee/keeper/proposal_test.go +++ b/x/committee/keeper/proposal_test.go @@ -77,7 +77,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal() { }, AllowedCollateralParams: types.AllowedCollateralParams{ types.AllowedCollateralParam{ - Denom: "bnb", + Type: "bnb-a", DebtLimit: true, StabilityFee: true, }, diff --git a/x/committee/types/param_permissions_test.go b/x/committee/types/param_permissions_test.go index 21a827b9..db4dc68c 100644 --- a/x/committee/types/param_permissions_test.go +++ b/x/committee/types/param_permissions_test.go @@ -19,6 +19,7 @@ func cs(coins ...sdk.Coin) sdk.Coins { return sdk.NewCoins(coins...) } func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { testCPs := cdptypes.CollateralParams{ { + Type: "bnb-a", Denom: "bnb", LiquidationRatio: d("2.0"), DebtLimit: c("usdx", 1000000000000), @@ -31,6 +32,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { LiquidationMarketID: "bnb:usd", }, { + Type: "btc-a", Denom: "btc", LiquidationRatio: d("1.5"), DebtLimit: c("usdx", 1000000000), @@ -43,6 +45,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { LiquidationMarketID: "btc:usd", }, { + Type: "atom-a", Denom: "atom", LiquidationRatio: d("2.0"), DebtLimit: c("usdx", 1000000000), @@ -76,15 +79,16 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { name: "disallowed add", allowed: AllowedCollateralParams{ { - Denom: "bnb", + Type: "bnb-a", AuctionSize: true, }, { - Denom: "btc", + Type: "btc-a", StabilityFee: true, }, { // allow all fields - Denom: "atom", + Type: "atom-a", + Denom: true, LiquidationRatio: true, DebtLimit: true, StabilityFee: true, @@ -104,12 +108,13 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { name: "disallowed remove", allowed: AllowedCollateralParams{ { - Denom: "bnb", + Type: "bnb-a", AuctionSize: true, }, { // allow all fields - Denom: "btc", + Type: "btc-a", + Denom: true, LiquidationRatio: true, DebtLimit: true, StabilityFee: true, @@ -129,15 +134,15 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { name: "allowed change with different order", allowed: AllowedCollateralParams{ { - Denom: "bnb", + Type: "bnb-a", LiquidationPenalty: true, }, { - Denom: "btc", + Type: "btc-a", DebtLimit: true, }, { - Denom: "atom", + Type: "atom-a", DebtLimit: true, LiquidationPenalty: true, }, @@ -425,6 +430,7 @@ func (suite *PermissionsTestSuite) TestAllowedMarkets_Allows() { func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { testCP := cdptypes.CollateralParam{ + Type: "bnb-a", Denom: "bnb", LiquidationRatio: d("1.5"), DebtLimit: c("usdx", 1000000000000), @@ -456,7 +462,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { { name: "allowed change", allowed: AllowedCollateralParam{ - Denom: "bnb", + Type: "bnb-a", DebtLimit: true, StabilityFee: true, AuctionSize: true, @@ -468,7 +474,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { { name: "un-allowed change", allowed: AllowedCollateralParam{ - Denom: "bnb", + Type: "bnb-a", DebtLimit: true, StabilityFee: true, AuctionSize: true, @@ -480,7 +486,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { { name: "un-allowed mismatching denom", allowed: AllowedCollateralParam{ - Denom: "btc", + Type: "btc-a", DebtLimit: true, }, current: testCP, @@ -491,7 +497,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { { name: "allowed no change", allowed: AllowedCollateralParam{ - Denom: "bnb", + Type: "bnb-a", DebtLimit: true, }, current: testCP, @@ -501,7 +507,7 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { { name: "un-allowed change with allowed change", allowed: AllowedCollateralParam{ - Denom: "btc", + Type: "btc-a", DebtLimit: true, }, current: testCP, diff --git a/x/committee/types/permissions.go b/x/committee/types/permissions.go index ca7e3d66..f6868570 100644 --- a/x/committee/types/permissions.go +++ b/x/committee/types/permissions.go @@ -338,7 +338,7 @@ func (acps AllowedCollateralParams) Allows(current, incoming cdptypes.Collateral var foundAllowedCP bool var allowedCP AllowedCollateralParam for _, p := range acps { - if p.Denom != incomingCP.Denom { + if p.Type != incomingCP.Type { continue } foundAllowedCP = true @@ -372,7 +372,8 @@ func (acps AllowedCollateralParams) Allows(current, incoming cdptypes.Collateral } type AllowedCollateralParam struct { - Denom string `json:"denom" yaml:"denom"` + Type string `json:"type" yaml:"type"` + Denom bool `json:"denom" yaml:"denom"` LiquidationRatio bool `json:"liquidation_ratio" yaml:"liquidation_ratio"` DebtLimit bool `json:"debt_limit" yaml:"debt_limit"` StabilityFee bool `json:"stability_fee" yaml:"stability_fee"` @@ -385,7 +386,8 @@ type AllowedCollateralParam struct { } func (acp AllowedCollateralParam) Allows(current, incoming cdptypes.CollateralParam) bool { - allowed := ((acp.Denom == current.Denom) && (acp.Denom == incoming.Denom)) && // require denoms to be all equal + allowed := ((acp.Type == current.Type) && (acp.Type == incoming.Type)) && // require collateral types to be all equal + (current.Denom == incoming.Denom || acp.Denom) && (current.LiquidationRatio.Equal(incoming.LiquidationRatio) || acp.LiquidationRatio) && (current.DebtLimit.IsEqual(incoming.DebtLimit) || acp.DebtLimit) && (current.StabilityFee.Equal(incoming.StabilityFee) || acp.StabilityFee) && diff --git a/x/issuance/module.go b/x/issuance/module.go index 6cfd7a89..cdccfc32 100644 --- a/x/issuance/module.go +++ b/x/issuance/module.go @@ -116,7 +116,7 @@ func (AppModule) QuerierRoute() string { // NewQuerierHandler returns no sdk.Querier. func (am AppModule) NewQuerierHandler() sdk.Querier { - return nil + return NewQuerier(am.keeper) } // InitGenesis module init-genesis