Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testnet): add two new parameters --base-fee and --min-gas-price to the command evmosd testnet init-files #1864

Merged
merged 20 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
21f5050
feat(testnet): add two new parameters --base-fee and --min-gas-price …
luchenqun Oct 14, 2023
b083209
chore: fix the conflicts
luchenqun Oct 23, 2023
a7a1612
Merge branch 'main' into luke/min-gas-price
GAtom22 Oct 25, 2023
76a778d
feat(testnet): change the type of minGasPrice from Int to LegacyDec
luchenqun Oct 25, 2023
84e78f4
Merge branch 'main' into luke/min-gas-price
GAtom22 Oct 25, 2023
32d5109
Merge branch 'main' into luke/min-gas-price
fedekunze Oct 25, 2023
e936da2
feat(testnet): check base-fee and min-gas-price parameters for plausi…
luchenqun Oct 26, 2023
1aa0a1d
Merge branch 'main' into luke/min-gas-price
GAtom22 Oct 26, 2023
e4f014d
feat(testnet): update minGasPrice input param err illustrate
luchenqun Oct 27, 2023
574eb03
feat(testnet): update NewDynamicFeeChecker
luchenqun Oct 27, 2023
55f94be
feat(testnet): add the --gas-prices input parameter to the genesis bl…
luchenqun Oct 28, 2023
6da5361
Merge branch 'main' into luke/min-gas-price
luchenqun Oct 28, 2023
ae6038b
Merge branch 'main' into luke/min-gas-price
GAtom22 Oct 30, 2023
b2b061c
chore: fix make lint
luchenqun Oct 31, 2023
8b46747
feat(testnet): update NewDynamicFeeChecker add checkTxFeeWithValidato…
luchenqun Nov 2, 2023
88da29b
Merge branch 'main' into luke/min-gas-price
GAtom22 Nov 2, 2023
8023616
Merge branch 'main' into luke/min-gas-price
GAtom22 Nov 2, 2023
726e43c
Merge branch 'main' into luke/min-gas-price
GAtom22 Nov 2, 2023
7d3c834
Merge branch 'main' into luke/min-gas-price
GAtom22 Nov 2, 2023
81699c1
Merge branch 'main' into luke/min-gas-price
GAtom22 Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

- (testnet) [#1864](https://github.com/evmos/evmos/pull/1864) Add `--base-fee` and `--min-gas-price` flags to the command `evmosd testnet init-files`.
- (stride-outpost) [#1912](https://github.com/evmos/evmos/pull/1912) Add Stride Outpost interface and ABI.
- (stride-outpost) [#1913](https://github.com/evmos/evmos/pull/1913) Add Run function, Precompile struct and tx definitions.
- (stride-outpost) [#1914](https://github.com/evmos/evmos/pull/1914) Add types, events and common util function.
Expand Down
2 changes: 1 addition & 1 deletion app/ante/evm/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
// - Tx priority is set to `effectiveGasPrice / DefaultPriorityReduction`.
func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) anteutils.TxFeeChecker {
return func(ctx sdk.Context, feeTx sdk.FeeTx) (sdk.Coins, int64, error) {
// TODO: in the e2e test, if the fee in the genesis transaction meet the baseFee and minGasPrice in the feemarket, we can remove this code
if ctx.BlockHeight() == 0 {
// genesis transactions: fallback to min-gas-price logic
return checkTxFeeWithValidatorMinGasPrices(ctx, feeTx)
}

params := k.GetParams(ctx)
denom := params.EvmDenom
ethCfg := params.ChainConfig.EthereumConfig(k.ChainID())
Expand Down
56 changes: 50 additions & 6 deletions cmd/evmosd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@
"net"
"os"
"path/filepath"
"strconv"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"

tmconfig "github.com/cometbft/cometbft/config"
tmrand "github.com/cometbft/cometbft/libs/rand"
"github.com/cometbft/cometbft/types"
tmtime "github.com/cometbft/cometbft/types/time"
"github.com/spf13/cobra"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand All @@ -39,16 +42,15 @@
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

cmdcfg "github.com/evmos/evmos/v15/cmd/config"
"github.com/evmos/evmos/v15/crypto/hd"
evmoskr "github.com/evmos/evmos/v15/crypto/keyring"
"github.com/evmos/evmos/v15/server/config"
srvflags "github.com/evmos/evmos/v15/server/flags"

"github.com/evmos/evmos/v15/testutil/network"
evmostypes "github.com/evmos/evmos/v15/types"
evmtypes "github.com/evmos/evmos/v15/x/evm/types"

cmdcfg "github.com/evmos/evmos/v15/cmd/config"
evmoskr "github.com/evmos/evmos/v15/crypto/keyring"
"github.com/evmos/evmos/v15/testutil/network"
feemarkettypes "github.com/evmos/evmos/v15/x/feemarket/types"
)

var (
Expand All @@ -61,6 +63,8 @@
flagRPCAddress = "rpc.address"
flagAPIAddress = "api.address"
flagPrintMnemonic = "print-mnemonic"
flagBaseFee = "base-fee"
flagMinGasPrice = "min-gas-price"
)

type initArgs struct {
Expand All @@ -73,6 +77,8 @@
numValidators int
outputDir string
startingIPAddress string
baseFee sdkmath.Int
minGasPrice sdkmath.LegacyDec
}

type startArgs struct {
Expand All @@ -89,12 +95,18 @@
printMnemonic bool
}

// createValidatorMsgGasLimit is the gas limit used in the MsgCreateValidator included in genesis transactions.
// This transaction consumes approximately 220,000 gas when executed in the genesis block.
const createValidatorMsgGasLimit = 250_000

func addTestnetFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().Int(flagNumValidators, 4, "Number of validators to initialize the testnet with")
cmd.Flags().StringP(flagOutputDir, "o", "./.testnets", "Directory to store initialization data for the testnet")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(sdkserver.FlagMinGasPrices, fmt.Sprintf("0.000006%s", cmdcfg.BaseDenom), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01photino,0.001stake)")
cmd.Flags().String(flags.FlagKeyType, string(hd.EthSecp256k1Type), "Key signing algorithm to generate keys for")
cmd.Flags().String(flagBaseFee, strconv.Itoa(params.InitialBaseFee), "The params base_fee in the feemarket module in geneis")
cmd.Flags().String(flagMinGasPrice, "0", "The params min_gas_price in the feemarket module in geneis")
}

// NewTestnetCmd creates a root testnet command with subcommands to run an in-process testnet or initialize
Expand Down Expand Up @@ -148,6 +160,22 @@
args.startingIPAddress, _ = cmd.Flags().GetString(flagStartingIPAddress)
args.numValidators, _ = cmd.Flags().GetInt(flagNumValidators)
args.algo, _ = cmd.Flags().GetString(flags.FlagKeyType)
baseFee, _ := cmd.Flags().GetString(flagBaseFee)

Check warning

Code scanning / gosec

Returned error is not propagated up the stack. Warning

Returned error is not propagated up the stack.
GAtom22 marked this conversation as resolved.
Show resolved Hide resolved
minGasPrice, _ := cmd.Flags().GetString(flagMinGasPrice)
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check warning

Code scanning / gosec

Returned error is not propagated up the stack. Warning

Returned error is not propagated up the stack.

var ok bool
args.baseFee, ok = sdk.NewIntFromString(baseFee)
if !ok || args.baseFee.LT(sdk.ZeroInt()) {
return fmt.Errorf("invalid value for --base-fee. expected a int number greater than or equal to 0 but got %s", baseFee)
}

args.minGasPrice, err = sdk.NewDecFromStr(minGasPrice)
if err != nil {
return fmt.Errorf("invalid value for --min-gas-price. expected a int or decimal greater than or equal to 0 but got %s and err %s", minGasPrice, err.Error())
}
if args.minGasPrice.LT(sdk.ZeroDec()) {
return fmt.Errorf("invalid value for --min-gas-price. expected a int or decimal greater than or equal to 0 but got an negative number %s", minGasPrice)
}

return initTestnetFiles(clientCtx, cmd, serverCtx.Config, mbm, genBalIterator, args)
},
Expand Down Expand Up @@ -324,7 +352,14 @@
return err
}

minGasPrice := args.minGasPrice
if sdkmath.LegacyNewDecFromInt(args.baseFee).GT(args.minGasPrice) {
minGasPrice = sdkmath.LegacyNewDecFromInt(args.baseFee)
}

txBuilder.SetMemo(memo)
txBuilder.SetGasLimit(createValidatorMsgGasLimit)
txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(cmdcfg.BaseDenom, minGasPrice.MulInt64(createValidatorMsgGasLimit).Ceil().TruncateInt())))

txFactory := tx.Factory{}
txFactory = txFactory.
Expand Down Expand Up @@ -357,7 +392,7 @@
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), appConfig)
}

if err := initGenFiles(clientCtx, mbm, args.chainID, cmdcfg.BaseDenom, genAccounts, genBalances, genFiles, args.numValidators); err != nil {
if err := initGenFiles(clientCtx, mbm, args.chainID, cmdcfg.BaseDenom, genAccounts, genBalances, genFiles, args.numValidators, args.baseFee, args.minGasPrice); err != nil {
return err
}

Expand All @@ -382,6 +417,8 @@
genBalances []banktypes.Balance,
genFiles []string,
numValidators int,
baseFee sdkmath.Int,
minGasPrice sdkmath.LegacyDec,
) error {
appGenState := mbm.DefaultGenesis(clientCtx.Codec)
// set the accounts in the genesis state
Expand Down Expand Up @@ -421,6 +458,13 @@
evmGenState.Params.EvmDenom = coinDenom
appGenState[evmtypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&evmGenState)

var feemarketGenState feemarkettypes.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[feemarkettypes.ModuleName], &feemarketGenState)

feemarketGenState.Params.BaseFee = baseFee
feemarketGenState.Params.MinGasPrice = minGasPrice
appGenState[feemarkettypes.ModuleName] = clientCtx.Codec.MustMarshalJSON(&feemarketGenState)

appGenStateJSON, err := json.MarshalIndent(appGenState, "", " ")
if err != nil {
return err
Expand Down
8 changes: 7 additions & 1 deletion local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ HOMEDIR="$HOME/.tmp-evmosd"
#TRACE="--trace"
TRACE=""

# feemarket params basefee
BASEFEE=1000000000

# Path variables
CONFIG=$HOMEDIR/config/config.toml
APP_TOML=$HOMEDIR/config/app.toml
Expand Down Expand Up @@ -146,6 +149,9 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
# 0xA61808Fe40fEb8B3433778BBC2ecECCAA47c8c47 || evmos15cvq3ljql6utxseh0zau9m8ve2j8erz89m5wkz
jq -r --arg amount_to_claim "$amount_to_claim" '.app_state["bank"]["balances"] += [{"address":"evmos15cvq3ljql6utxseh0zau9m8ve2j8erz89m5wkz","coins":[{"denom":"aevmos", "amount":$amount_to_claim}]}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# Set base fee in genesis
jq '.app_state["feemarket"]["params"]["base_fee"]="'${BASEFEE}'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

if [[ $1 == "pending" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "30s"/g' "$CONFIG"
Expand Down Expand Up @@ -208,7 +214,7 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
jq -r --arg total_supply "$total_supply" '.app_state["bank"]["supply"][0]["amount"]=$total_supply' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# Sign genesis transaction
evmosd gentx "$VAL_KEY" 1000000000000000000000aevmos --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$HOMEDIR"
evmosd gentx "$VAL_KEY" 1000000000000000000000aevmos --gas-prices ${BASEFEE}aevmos --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$HOMEDIR"
## In case you want to create multiple validators at genesis
## 1. Back to `evmosd keys add` step, init more keys
## 2. Back to `evmosd add-genesis-account` step, add balance for those
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/init-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ TMP_GENESIS="$CHAINDIR/config/tmp_genesis.json"
APP_TOML="$CHAINDIR/config/app.toml"
CONFIG_TOML="$CHAINDIR/config/config.toml"

# feemarket params basefee
BASEFEE=1000000000

# myKey address 0x7cb61d4117ae31a12e393a1cfa3bac666481d02e
VAL_KEY="mykey"
VAL_MNEMONIC="gesture inject test cycle original hollow east ridge hen combine junk child bacon zero hope comfort vacuum milk pitch cage oppose unhappy lunar seat"
Expand Down Expand Up @@ -102,6 +105,9 @@ jq '.app_state.claims.params.duration_until_decay="100000s"' "$GENESIS" >"$TMP_G
# 0xA61808Fe40fEb8B3433778BBC2ecECCAA47c8c47 || evmos15cvq3ljql6utxseh0zau9m8ve2j8erz89m5wkz
jq -r --arg amount_to_claim "$amount_to_claim" '.app_state.bank.balances += [{"address":"evmos15cvq3ljql6utxseh0zau9m8ve2j8erz89m5wkz","coins":[{"denom":"aevmos", "amount":$amount_to_claim}]}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# Set base fee in genesis
jq '.app_state["feemarket"]["params"]["base_fee"]="'${BASEFEE}'"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# disable produce empty block
sed -i.bak 's/create_empty_blocks = true/create_empty_blocks = false/g' "$CONFIG_TOML"

Expand Down Expand Up @@ -133,7 +139,7 @@ sed -i.bak 's/127.0.0.1/0.0.0.0/g' "$APP_TOML"
sed -i.bak 's/timeout_commit = "3s"/timeout_commit = "1s"/g' "$CONFIG_TOML"

# Sign genesis transaction
evmosd gentx "$VAL_KEY" 1000000000000000000000aevmos --keyring-backend "$KEYRING" --chain-id "$CHAINID"
evmosd gentx "$VAL_KEY" 1000000000000000000000aevmos --gas-prices ${BASEFEE}aevmos --keyring-backend "$KEYRING" --chain-id "$CHAINID"
## In case you want to create multiple validators at genesis
## 1. Back to `evmosd keys add` step, init more keys
## 2. Back to `evmosd add-genesis-account` step, add balance for those
Expand Down