diff --git a/app/app.go b/app/app.go index 81a3f0b6f..f88b25217 100644 --- a/app/app.go +++ b/app/app.go @@ -842,8 +842,8 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) { // RegisterUpgradeHandlers returns upgrade handlers func (app *App) RegisterUpgradeHandlers(cfg module.Configurator) { - app.UpgradeKeeper.SetUpgradeHandler("v11", upgrades.CreateV11UpgradeHandler(app.mm, cfg, &app.ICAHostKeeper)) - app.UpgradeKeeper.SetUpgradeHandler("v12", upgrades.CreateV12UpgradeHandler(app.mm, cfg)) + // app.UpgradeKeeper.SetUpgradeHandler("v11", upgrades.CreateV11UpgradeHandler(app.mm, cfg, &app.ICAHostKeeper)) + app.UpgradeKeeper.SetUpgradeHandler("v12", upgrades.CreateV12UpgradeHandler(app.mm, cfg, app.MintKeeper, app.BankKeeper, app.CrisisKeeper)) } // GetMaccPerms returns a copy of the module account permissions diff --git a/app/upgrades/upgrade_handlers.go b/app/upgrades/upgrade_handlers.go index 709687d86..8a0bcf442 100644 --- a/app/upgrades/upgrade_handlers.go +++ b/app/upgrades/upgrade_handlers.go @@ -1,6 +1,8 @@ package upgrades import ( + "strings" + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -13,9 +15,19 @@ import ( icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" + mintkeeper "github.com/CosmosContracts/juno/v12/x/mint/keeper" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" ) +func GetChainsDenomToken(chainID string) string { + if strings.HasPrefix(chainID, "uni-") || strings.HasPrefix(chainID, "ares-") { + return "ujunox" + } + return "ujuno" +} + // CreateV10UpgradeHandler makes an upgrade handler for v11 of Juno func CreateV10UpgradeHandler(mm *module.Manager, cfg module.Configurator, icahostkeeper *icahostkeeper.Keeper) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { @@ -99,8 +111,25 @@ func CreateV11UpgradeHandler(mm *module.Manager, cfg module.Configurator, icahos } } -func CreateV12UpgradeHandler(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { +func CreateV12UpgradeHandler(mm *module.Manager, cfg module.Configurator, mk mintkeeper.Keeper, bk bankkeeper.Keeper, ck crisiskeeper.Keeper) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + nativeDenom := GetChainsDenomToken(ctx.ChainID()) + + // Mint 100JUNO (100mil ujuno) to the distribution module + // fixes invariance issue in wasm from governance + amt := sdk.NewCoins(sdk.NewCoin(nativeDenom, sdk.NewInt(100_000_000))) + if err := mk.MintCoins(ctx, amt); err != nil { + panic(err) + } + + if err := bk.SendCoinsFromModuleToModule(ctx, "mint", "distribution", amt); err != nil { + panic(err) + } + + // Increases crisis fee to 15000 JUNO (15000 000 000ujuno) to prevent DDoS attacks + crisisAmt := sdk.NewCoin(nativeDenom, sdk.NewInt(15000_000_000)) + ck.SetConstantFee(ctx, crisisAmt) + return mm.RunMigrations(ctx, cfg, vm) } } diff --git a/go.mod b/go.mod index 7bbe69d2b..6b4fa487f 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,10 @@ require ( gopkg.in/yaml.v2 v2.4.0 ) +// Patches invariance exploit with wasmd governance +// https://github.com/CosmosContracts/wasmd/tree/bv0.29.2-patch +replace github.com/CosmWasm/wasmd => github.com/CosmosContracts/wasmd v0.29.2-patch.1 + require ( filippo.io/edwards25519 v1.0.0-beta.2 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/go.sum b/go.sum index a8b344c42..45c32dec5 100644 --- a/go.sum +++ b/go.sum @@ -59,10 +59,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/CosmWasm/wasmd v0.29.2 h1:xYZpQjoCixaebMeZs2WGAbBQ8N9PUHVZieuNWy+avI8= -github.com/CosmWasm/wasmd v0.29.2/go.mod h1:agYHzj3R0O+UExLHlXLuEfLqhIrCC+pF5ouAmbe9/68= github.com/CosmWasm/wasmvm v1.1.1 h1:0xtdrmmsP9fibe+x42WcMkp5aQ738BICgcH3FNVLzm4= github.com/CosmWasm/wasmvm v1.1.1/go.mod h1:ei0xpvomwSdONsxDuONzV7bL1jSET1M8brEx0FCXc+A= +github.com/CosmosContracts/wasmd v0.29.2-patch.1 h1:YNZuaRfzXlZ3c0S7OskIJxdaNuqM1ozSakYVPx8VEog= +github.com/CosmosContracts/wasmd v0.29.2-patch.1/go.mod h1:agYHzj3R0O+UExLHlXLuEfLqhIrCC+pF5ouAmbe9/68= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= diff --git a/scripts/test_node.sh b/scripts/test_node.sh new file mode 100644 index 000000000..6b97ff4e5 --- /dev/null +++ b/scripts/test_node.sh @@ -0,0 +1,121 @@ +#!/bin/bash +# Run this script to quickly install, setup, and run the current version of juno without docker. +# Pulled in from my v13 main PR +# +# Example: +# CHAIN_ID="local-1" HOME_DIR="~/.juno1/" TIMEOUT_COMMIT="500ms" CLEAN=true sh scripts/test_node.sh +# CHAIN_ID="local-2" HOME_DIR="~/.juno2/" CLEAN=true RPC=36657 REST=2317 PROFF=6061 P2P=36656 GRPC=8090 GRPC_WEB=8091 ROSETTA=8081 TIMEOUT_COMMIT="500ms" sh scripts/test_node.sh + +export KEY="juno1" +export CHAIN_ID=${CHAIN_ID:-"local-1"} +export MONIKER="localjuno" +export KEYALGO="secp256k1" +export KEYRING=${KEYRING:-"test"} +export HOME_DIR=$(eval echo "${HOME_DIR:-"~/.juno/"}") + +export BINARY=${BINARY:-junod} +export CLEAN=${CLEAN:-"false"} + +export RPC=${RPC:-"26657"} +export REST=${REST:-"1317"} +export PROFF=${PROFF:-"6060"} +export P2P=${P2P:-"26656"} +export GRPC=${GRPC:-"9090"} +export GRPC_WEB=${GRPC_WEB:-"9091"} +export ROSETTA=${ROSETTA:-"8080"} +export TIMEOUT_COMMIT=${TIMEOUT_COMMIT:-"5s"} + +junod config keyring-backend $KEYRING +junod config chain-id $CHAIN_ID + +alias BINARY="$BINARY --home=$HOME_DIR" + +# Debugging +echo "CHAIN_ID=$CHAIN_ID, HOME_DIR=$HOME_DIR, CLEAN=$CLEAN, RPC=$RPC, REST=$REST, PROFF=$PROFF, P2P=$P2P, GRPC=$GRPC, GRPC_WEB=$GRPC_WEB, ROSETTA=$ROSETTA, TIMEOUT_COMMIT=$TIMEOUT_COMMIT" + +command -v junod > /dev/null 2>&1 || { echo >&2 "junod command not found. Ensure this is setup / properly installed in your GOPATH."; exit 1; } +command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } + +from_scratch () { + # Fresh install on current branch + make install + + # remove existing daemon. + rm -rf $HOME_DIR && echo "Removed $HOME_DIR" + + # juno1efd63aw40lxf3n4mhf7dzhjkr453axurv2zdzk + echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | BINARY keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover + # juno1hj5fveer5cjtn4wd6wstzugjfdxzl0xps73ftl + echo "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise" | BINARY keys add feeacc --keyring-backend $KEYRING --algo $KEYALGO --recover + + BINARY init $MONIKER --chain-id $CHAIN_ID + + # Function updates the config based on a jq argument as a string + update_test_genesis () { + # update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' + cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && mv $HOME_DIR/config/tmp_genesis.json $HOME_DIR/config/genesis.json + } + + # Set gas limit in genesis + update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"' + update_test_genesis '.app_state["gov"]["voting_params"]["voting_period"]="15s"' + + update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="ujuno"' + update_test_genesis '.app_state["bank"]["params"]["send_enabled"]=[{"denom": "ujuno","enabled": true}]' + # update_test_genesis '.app_state["staking"]["params"]["min_commission_rate"]="0.100000000000000000"' # sdk 46 only + + update_test_genesis '.app_state["mint"]["params"]["mint_denom"]="ujuno"' + update_test_genesis '.app_state["gov"]["deposit_params"]["min_deposit"]=[{"denom": "ujuno","amount": "1000000"}]' + update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom": "ujuno","amount": "1000"}' + + update_test_genesis '.app_state["tokenfactory"]["params"]["denom_creation_fee"]=[{"denom":"ujuno","amount":"100"}]' + + update_test_genesis '.app_state["feeshare"]["params"]["allowed_denoms"]=["ujuno"]' + + # Allocate genesis accounts + BINARY add-genesis-account $KEY 10000000ujuno,1000utest --keyring-backend $KEYRING + BINARY add-genesis-account feeacc 1000000ujuno,1000utest --keyring-backend $KEYRING + + BINARY gentx $KEY 1000000ujuno --keyring-backend $KEYRING --chain-id $CHAIN_ID + + # Collect genesis tx + BINARY collect-gentxs + + # Run this to ensure junorything worked and that the genesis file is setup correctly + BINARY validate-genesis +} + +# check if CLEAN is not set to false +if [ "$CLEAN" != "false" ]; then + echo "Starting from a clean state" + from_scratch +fi + +echo "Starting node..." + +# Opens the RPC endpoint to outside connections +sed -i 's/laddr = "tcp:\/\/127.0.0.1:26657"/c\laddr = "tcp:\/\/0.0.0.0:'$RPC'"/g' $HOME_DIR/config/config.toml +sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' $HOME_DIR/config/config.toml + +# REST endpoint +sed -i 's/address = "tcp:\/\/0.0.0.0:1317"/address = "tcp:\/\/0.0.0.0:'$REST'"/g' $HOME_DIR/config/app.toml +sed -i 's/enable = false/enable = true/g' $HOME_DIR/config/app.toml + +# replace pprof_laddr = "localhost:6060" binding +sed -i 's/pprof_laddr = "localhost:6060"/pprof_laddr = "localhost:'$PROFF_LADDER'"/g' $HOME_DIR/config/config.toml + +# change p2p addr laddr = "tcp://0.0.0.0:26656" +sed -i 's/laddr = "tcp:\/\/0.0.0.0:26656"/laddr = "tcp:\/\/0.0.0.0:'$P2P'"/g' $HOME_DIR/config/config.toml + +# GRPC +sed -i 's/address = "0.0.0.0:9090"/address = "0.0.0.0:'$GRPC'"/g' $HOME_DIR/config/app.toml +sed -i 's/address = "0.0.0.0:9091"/address = "0.0.0.0:'$GRPC_WEB'"/g' $HOME_DIR/config/app.toml + +# Rosetta Api +sed -i 's/address = ":8080"/address = "0.0.0.0:'$ROSETTA'"/g' $HOME_DIR/config/app.toml + +# faster blocks +sed -i 's/timeout_commit = "5s"/timeout_commit = "'$TIMEOUT_COMMIT'"/g' $HOME_DIR/config/config.toml + +# Start the node with 0 gas fees +BINARY start --pruning=nothing --minimum-gas-prices=0ujuno --rpc.laddr="tcp://0.0.0.0:$RPC" \ No newline at end of file