forked from cerc-io/laconicd-deprecated
rpc: configure gas cap (#457)
* rpc: configure gas cap * c++ * rm old const * docs
This commit is contained in:
@@ -36,7 +36,7 @@ const (
|
||||
// GetRPCAPIs returns the list of all APIs
|
||||
func GetRPCAPIs(ctx *server.Context, clientCtx client.Context, tmWSClient *rpcclient.WSClient, selectedAPIs []string) []rpc.API {
|
||||
nonceLock := new(types.AddrLocker)
|
||||
evmBackend := backend.NewEVMBackend(ctx.Logger, clientCtx)
|
||||
evmBackend := backend.NewEVMBackend(ctx, ctx.Logger, clientCtx)
|
||||
|
||||
var apis []rpc.API
|
||||
// remove duplicates
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/tharsis/ethermint/ethereum/rpc/types"
|
||||
"github.com/tharsis/ethermint/server/config"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||
)
|
||||
@@ -48,6 +50,7 @@ type Backend interface {
|
||||
BloomStatus() (uint64, uint64)
|
||||
GetCoinbase() (sdk.AccAddress, error)
|
||||
EstimateGas(args evmtypes.CallArgs, blockNrOptional *types.BlockNumber) (hexutil.Uint64, error)
|
||||
RPCGasCap() uint64
|
||||
}
|
||||
|
||||
var _ Backend = (*EVMBackend)(nil)
|
||||
@@ -59,20 +62,28 @@ type EVMBackend struct {
|
||||
queryClient *types.QueryClient // gRPC query client
|
||||
logger log.Logger
|
||||
chainID *big.Int
|
||||
cfg config.Config
|
||||
}
|
||||
|
||||
// NewEVMBackend creates a new EVMBackend instance
|
||||
func NewEVMBackend(logger log.Logger, clientCtx client.Context) *EVMBackend {
|
||||
func NewEVMBackend(ctx *server.Context, logger log.Logger, clientCtx client.Context) *EVMBackend {
|
||||
chainID, err := ethermint.ParseChainID(clientCtx.ChainID)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
appConf, err := config.ParseConfig(ctx.Viper)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &EVMBackend{
|
||||
ctx: context.Background(),
|
||||
clientCtx: clientCtx,
|
||||
queryClient: types.NewQueryClient(clientCtx),
|
||||
logger: logger.With("module", "evm-backend"),
|
||||
chainID: chainID,
|
||||
cfg: *appConf,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -547,7 +558,8 @@ func (e *EVMBackend) EstimateGas(args evmtypes.CallArgs, blockNrOptional *types.
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
req := evmtypes.EthCallRequest{Args: bz, GasCap: ethermint.DefaultRPCGasLimit}
|
||||
|
||||
req := evmtypes.EthCallRequest{Args: bz, GasCap: e.RPCGasCap()}
|
||||
|
||||
// From ContextWithHeight: if the provided height is 0,
|
||||
// it will return an empty context and the gRPC query will use
|
||||
@@ -581,3 +593,8 @@ func (e *EVMBackend) GetTransactionCount(address common.Address, blockNum types.
|
||||
n := hexutil.Uint64(nonce)
|
||||
return &n, nil
|
||||
}
|
||||
|
||||
// RPCGasCap is the global gas cap for eth-call variants.
|
||||
func (e *EVMBackend) RPCGasCap() uint64 {
|
||||
return e.cfg.JSONRPC.GasCap
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/tharsis/ethermint/ethereum/rpc/types"
|
||||
ethermint "github.com/tharsis/ethermint/types"
|
||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||
)
|
||||
|
||||
@@ -21,10 +20,8 @@ import (
|
||||
func (e *EVMBackend) setTxDefaults(args types.SendTxArgs) (types.SendTxArgs, error) {
|
||||
|
||||
if args.GasPrice == nil {
|
||||
// TODO: Change to either:
|
||||
// - min gas price from context once available through server/daemon, or
|
||||
// - suggest a gas price based on the previous included txs
|
||||
args.GasPrice = (*hexutil.Big)(big.NewInt(ethermint.DefaultGasPrice))
|
||||
// TODO: Suggest a gas price based on the previous included txs
|
||||
args.GasPrice = (*hexutil.Big)(new(big.Int).SetUint64(e.RPCGasCap()))
|
||||
}
|
||||
|
||||
if args.Nonce == nil {
|
||||
|
||||
@@ -167,8 +167,7 @@ func (e *PublicAPI) Hashrate() hexutil.Uint64 {
|
||||
// GasPrice returns the current gas price based on Ethermint's gas price oracle.
|
||||
func (e *PublicAPI) GasPrice() *hexutil.Big {
|
||||
e.logger.Debug("eth_gasPrice")
|
||||
// TODO: use minimum value defined in config instead of default or implement oracle
|
||||
out := big.NewInt(ethermint.DefaultGasPrice)
|
||||
out := new(big.Int).SetUint64(e.backend.RPCGasCap())
|
||||
return (*hexutil.Big)(out)
|
||||
}
|
||||
|
||||
@@ -438,7 +437,7 @@ func (e *PublicAPI) doCall(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := evmtypes.EthCallRequest{Args: bz, GasCap: ethermint.DefaultRPCGasLimit}
|
||||
req := evmtypes.EthCallRequest{Args: bz, GasCap: e.backend.RPCGasCap()}
|
||||
|
||||
// From ContextWithHeight: if the provided height is 0,
|
||||
// it will return an empty context and the gRPC query will use
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
sdkconfig "github.com/cosmos/cosmos-sdk/server/config"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"github.com/tharsis/ethermint/ethereum/rpc/backend"
|
||||
rpctypes "github.com/tharsis/ethermint/ethereum/rpc/types"
|
||||
"github.com/tharsis/ethermint/server/config"
|
||||
)
|
||||
|
||||
// API is the miner prefixed set of APIs in the Miner JSON-RPC spec.
|
||||
@@ -186,7 +187,7 @@ func (api *API) SetGasPrice(gasPrice hexutil.Big) bool {
|
||||
c := sdk.NewDecCoin(unit, sdk.NewIntFromBigInt(gasPrice.ToInt()))
|
||||
|
||||
appConf.SetMinGasPrices(sdk.DecCoins{c})
|
||||
config.WriteConfigFile(api.ctx.Viper.ConfigFileUsed(), appConf)
|
||||
sdkconfig.WriteConfigFile(api.ctx.Viper.ConfigFileUsed(), appConf)
|
||||
api.logger.Info("Your configuration file was modified. Please RESTART your node.", "gas-price", c.String())
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user