Sync from fork #74
@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
|
||||||
|
* (rpc) [#1229](https://github.com/evmos/ethermint/pull/1229) Add support for configuring RPC `MaxOpenConnections`
|
||||||
|
|
||||||
### State Machine Breaking
|
### State Machine Breaking
|
||||||
|
|
||||||
* (deps) [\#1159](https://github.com/evmos/ethermint/pull/1159) Bump Geth version to `v1.10.19`.
|
* (deps) [\#1159](https://github.com/evmos/ethermint/pull/1159) Bump Geth version to `v1.10.19`.
|
||||||
|
@ -74,7 +74,7 @@ type websocketsServer struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, tmWSClient *rpcclient.WSClient, cfg config.Config) WebsocketsServer {
|
func NewWebsocketsServer(clientCtx client.Context, logger log.Logger, tmWSClient *rpcclient.WSClient, cfg *config.Config) WebsocketsServer {
|
||||||
logger = logger.With("api", "websocket-server")
|
logger = logger.With("api", "websocket-server")
|
||||||
_, port, _ := net.SplitHostPort(cfg.JSONRPC.Address)
|
_, port, _ := net.SplitHostPort(cfg.JSONRPC.Address)
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ const (
|
|||||||
DefaultHTTPIdleTimeout = 120 * time.Second
|
DefaultHTTPIdleTimeout = 120 * time.Second
|
||||||
// DefaultAllowUnprotectedTxs value is false
|
// DefaultAllowUnprotectedTxs value is false
|
||||||
DefaultAllowUnprotectedTxs = false
|
DefaultAllowUnprotectedTxs = false
|
||||||
|
// DefaultMaxOpenConnections represents the amount of open connections (unlimited = 0)
|
||||||
|
DefaultMaxOpenConnections = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
var evmTracers = []string{"json", "markdown", "struct", "access_list"}
|
var evmTracers = []string{"json", "markdown", "struct", "access_list"}
|
||||||
@ -103,6 +105,9 @@ type JSONRPCConfig struct {
|
|||||||
// AllowUnprotectedTxs restricts unprotected (non EIP155 signed) transactions to be submitted via
|
// AllowUnprotectedTxs restricts unprotected (non EIP155 signed) transactions to be submitted via
|
||||||
// the node's RPC when global parameter is disabled.
|
// the node's RPC when global parameter is disabled.
|
||||||
AllowUnprotectedTxs bool `mapstructure:"allow-unprotected-txs"`
|
AllowUnprotectedTxs bool `mapstructure:"allow-unprotected-txs"`
|
||||||
|
// MaxOpenConnections sets the maximum number of simultaneous connections
|
||||||
|
// for the server listener.
|
||||||
|
MaxOpenConnections int `mapstructure:"max-open-connections"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSConfig defines the certificate and matching private key for the server.
|
// TLSConfig defines the certificate and matching private key for the server.
|
||||||
@ -202,6 +207,7 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
|
|||||||
HTTPTimeout: DefaultHTTPTimeout,
|
HTTPTimeout: DefaultHTTPTimeout,
|
||||||
HTTPIdleTimeout: DefaultHTTPIdleTimeout,
|
HTTPIdleTimeout: DefaultHTTPIdleTimeout,
|
||||||
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
|
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
|
||||||
|
MaxOpenConnections: DefaultMaxOpenConnections,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +311,7 @@ func GetConfig(v *viper.Viper) Config {
|
|||||||
BlockRangeCap: v.GetInt32("json-rpc.block-range-cap"),
|
BlockRangeCap: v.GetInt32("json-rpc.block-range-cap"),
|
||||||
HTTPTimeout: v.GetDuration("json-rpc.http-timeout"),
|
HTTPTimeout: v.GetDuration("json-rpc.http-timeout"),
|
||||||
HTTPIdleTimeout: v.GetDuration("json-rpc.http-idle-timeout"),
|
HTTPIdleTimeout: v.GetDuration("json-rpc.http-idle-timeout"),
|
||||||
|
MaxOpenConnections: v.GetInt("json-rpc.max-open-connections"),
|
||||||
},
|
},
|
||||||
TLS: TLSConfig{
|
TLS: TLSConfig{
|
||||||
CertificatePath: v.GetString("tls.certificate-path"),
|
CertificatePath: v.GetString("tls.certificate-path"),
|
||||||
|
@ -66,6 +66,10 @@ http-idle-timeout = "{{ .JSONRPC.HTTPIdleTimeout }}"
|
|||||||
# the node's RPC when the global parameter is disabled.
|
# the node's RPC when the global parameter is disabled.
|
||||||
allow-unprotected-txs = {{ .JSONRPC.AllowUnprotectedTxs }}
|
allow-unprotected-txs = {{ .JSONRPC.AllowUnprotectedTxs }}
|
||||||
|
|
||||||
|
# MaxOpenConnections sets the maximum number of simultaneous connections
|
||||||
|
# for the server listener.
|
||||||
|
max-open-connections = {{ .JSONRPC.MaxOpenConnections }}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
### TLS Configuration ###
|
### TLS Configuration ###
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -47,6 +47,7 @@ const (
|
|||||||
JSONRPCHTTPTimeout = "json-rpc.http-timeout"
|
JSONRPCHTTPTimeout = "json-rpc.http-timeout"
|
||||||
JSONRPCHTTPIdleTimeout = "json-rpc.http-idle-timeout"
|
JSONRPCHTTPIdleTimeout = "json-rpc.http-idle-timeout"
|
||||||
JSONRPCAllowUnprotectedTxs = "json-rpc.allow-unprotected-txs"
|
JSONRPCAllowUnprotectedTxs = "json-rpc.allow-unprotected-txs"
|
||||||
|
JSONRPCMaxOpenConnections = "json-rpc.max-open-connections"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EVM flags
|
// EVM flags
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// StartJSONRPC starts the JSON-RPC server
|
// StartJSONRPC starts the JSON-RPC server
|
||||||
func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEndpoint string, config config.Config) (*http.Server, chan struct{}, error) {
|
func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEndpoint string, config *config.Config) (*http.Server, chan struct{}, error) {
|
||||||
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)
|
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint, ctx.Logger)
|
||||||
|
|
||||||
logger := ctx.Logger.With("module", "geth")
|
logger := ctx.Logger.With("module", "geth")
|
||||||
@ -70,10 +70,15 @@ func StartJSONRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr, tmEn
|
|||||||
}
|
}
|
||||||
httpSrvDone := make(chan struct{}, 1)
|
httpSrvDone := make(chan struct{}, 1)
|
||||||
|
|
||||||
|
ln, err := Listen(httpSrv.Addr, config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
ctx.Logger.Info("Starting JSON-RPC server", "address", config.JSONRPC.Address)
|
ctx.Logger.Info("Starting JSON-RPC server", "address", config.JSONRPC.Address)
|
||||||
if err := httpSrv.ListenAndServe(); err != nil {
|
if err := httpSrv.Serve(ln); err != nil {
|
||||||
if err == http.ErrServerClosed {
|
if err == http.ErrServerClosed {
|
||||||
close(httpSrvDone)
|
close(httpSrvDone)
|
||||||
return
|
return
|
||||||
|
@ -164,6 +164,7 @@ which accepts a path for the resulting pprof file.
|
|||||||
cmd.Flags().Bool(srvflags.JSONRPCAllowUnprotectedTxs, config.DefaultAllowUnprotectedTxs, "Allow for unprotected (non EIP155 signed) transactions to be submitted via the node's RPC when the global parameter is disabled")
|
cmd.Flags().Bool(srvflags.JSONRPCAllowUnprotectedTxs, config.DefaultAllowUnprotectedTxs, "Allow for unprotected (non EIP155 signed) transactions to be submitted via the node's RPC when the global parameter is disabled")
|
||||||
cmd.Flags().Int32(srvflags.JSONRPCLogsCap, config.DefaultLogsCap, "Sets the max number of results can be returned from single `eth_getLogs` query")
|
cmd.Flags().Int32(srvflags.JSONRPCLogsCap, config.DefaultLogsCap, "Sets the max number of results can be returned from single `eth_getLogs` query")
|
||||||
cmd.Flags().Int32(srvflags.JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
|
cmd.Flags().Int32(srvflags.JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
|
||||||
|
cmd.Flags().Int(srvflags.JSONRPCMaxOpenConnections, config.DefaultMaxOpenConnections, "Sets the maximum number of simultaneous connections for the server listener")
|
||||||
|
|
||||||
cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)")
|
cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)")
|
||||||
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode")
|
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode")
|
||||||
@ -426,7 +427,7 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
|
|||||||
|
|
||||||
tmEndpoint := "/websocket"
|
tmEndpoint := "/websocket"
|
||||||
tmRPCAddr := cfg.RPC.ListenAddress
|
tmRPCAddr := cfg.RPC.ListenAddress
|
||||||
httpSrv, httpSrvDone, err = StartJSONRPC(ctx, clientCtx, tmRPCAddr, tmEndpoint, config)
|
httpSrv, httpSrvDone, err = StartJSONRPC(ctx, clientCtx, tmRPCAddr, tmEndpoint, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/evmos/ethermint/server/config"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/net/netutil"
|
||||||
|
|
||||||
sdkserver "github.com/cosmos/cosmos-sdk/server"
|
sdkserver "github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/server/types"
|
"github.com/cosmos/cosmos-sdk/server/types"
|
||||||
@ -17,7 +20,7 @@ import (
|
|||||||
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
// add server commands
|
// AddCommands adds server commands
|
||||||
func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
|
func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
|
||||||
tendermintCmd := &cobra.Command{
|
tendermintCmd := &cobra.Command{
|
||||||
Use: "tendermint",
|
Use: "tendermint",
|
||||||
@ -97,3 +100,19 @@ func MountGRPCWebServices(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Listen starts a net.Listener on the tcp network on the given address.
|
||||||
|
// If there is a specified MaxOpenConnections in the config, it will also set the limitListener.
|
||||||
|
func Listen(addr string, config *config.Config) (net.Listener, error) {
|
||||||
|
if addr == "" {
|
||||||
|
addr = ":http"
|
||||||
|
}
|
||||||
|
ln, err := net.Listen("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if config.JSONRPC.MaxOpenConnections > 0 {
|
||||||
|
ln = netutil.LimitListener(ln, config.JSONRPC.MaxOpenConnections)
|
||||||
|
}
|
||||||
|
return ln, err
|
||||||
|
}
|
||||||
|
@ -131,7 +131,7 @@ func startInProcess(cfg Config, val *Validator) error {
|
|||||||
tmEndpoint := "/websocket"
|
tmEndpoint := "/websocket"
|
||||||
tmRPCAddr := val.RPCAddress
|
tmRPCAddr := val.RPCAddress
|
||||||
|
|
||||||
val.jsonrpc, val.jsonrpcDone, err = server.StartJSONRPC(val.Ctx, val.ClientCtx, tmRPCAddr, tmEndpoint, *val.AppConfig)
|
val.jsonrpc, val.jsonrpcDone, err = server.StartJSONRPC(val.Ctx, val.ClientCtx, tmRPCAddr, tmEndpoint, val.AppConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user