77ed4aa754
* Store eth tx index separately Closes: #1075 Solution: - run a optional indexer service - adapt the json-rpc to the more efficient query changelog changelog fix lint fix backward compatibility fix lint timeout better strconv fix linter fix package name add cli command to index old tx fix for loop indexer cmd don't have access to local rpc workaround exceed block gas limit situation add unit tests for indexer refactor polish the indexer module Update server/config/toml.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> improve comments share code between GetTxByEthHash and GetTxByIndex fix unit test Update server/indexer.go Co-authored-by: Freddy Caceres <facs95@gmail.com> * Apply suggestions from code review * test enable-indexer in integration test * fix go lint * address review suggestions * fix linter * address review suggestions - test indexer in backend unit test - add comments * fix build * fix test * service name Co-authored-by: Freddy Caceres <facs95@gmail.com> Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
122 lines
3.1 KiB
Go
122 lines
3.1 KiB
Go
package server
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/evmos/ethermint/server/config"
|
|
"github.com/gorilla/mux"
|
|
"github.com/improbable-eng/grpc-web/go/grpcweb"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/net/netutil"
|
|
|
|
sdkserver "github.com/cosmos/cosmos-sdk/server"
|
|
"github.com/cosmos/cosmos-sdk/server/types"
|
|
"github.com/cosmos/cosmos-sdk/version"
|
|
|
|
tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
|
tmlog "github.com/tendermint/tendermint/libs/log"
|
|
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
|
)
|
|
|
|
// AddCommands adds server commands
|
|
func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
|
|
tendermintCmd := &cobra.Command{
|
|
Use: "tendermint",
|
|
Short: "Tendermint subcommands",
|
|
}
|
|
|
|
tendermintCmd.AddCommand(
|
|
sdkserver.ShowNodeIDCmd(),
|
|
sdkserver.ShowValidatorCmd(),
|
|
sdkserver.ShowAddressCmd(),
|
|
sdkserver.VersionCmd(),
|
|
tmcmd.ResetAllCmd,
|
|
tmcmd.ResetStateCmd,
|
|
)
|
|
|
|
startCmd := StartCmd(appCreator, defaultNodeHome)
|
|
addStartFlags(startCmd)
|
|
|
|
rootCmd.AddCommand(
|
|
startCmd,
|
|
tendermintCmd,
|
|
sdkserver.ExportCmd(appExport, defaultNodeHome),
|
|
version.NewVersionCommand(),
|
|
sdkserver.NewRollbackCmd(defaultNodeHome),
|
|
|
|
// custom tx indexer command
|
|
NewIndexTxCmd(),
|
|
)
|
|
}
|
|
|
|
func ConnectTmWS(tmRPCAddr, tmEndpoint string, logger tmlog.Logger) *rpcclient.WSClient {
|
|
tmWsClient, err := rpcclient.NewWS(tmRPCAddr, tmEndpoint,
|
|
rpcclient.MaxReconnectAttempts(256),
|
|
rpcclient.ReadWait(120*time.Second),
|
|
rpcclient.WriteWait(120*time.Second),
|
|
rpcclient.PingPeriod(50*time.Second),
|
|
rpcclient.OnReconnect(func() {
|
|
logger.Debug("EVM RPC reconnects to Tendermint WS", "address", tmRPCAddr+tmEndpoint)
|
|
}),
|
|
)
|
|
|
|
if err != nil {
|
|
logger.Error(
|
|
"Tendermint WS client could not be created",
|
|
"address", tmRPCAddr+tmEndpoint,
|
|
"error", err,
|
|
)
|
|
} else if err := tmWsClient.OnStart(); err != nil {
|
|
logger.Error(
|
|
"Tendermint WS client could not start",
|
|
"address", tmRPCAddr+tmEndpoint,
|
|
"error", err,
|
|
)
|
|
}
|
|
|
|
return tmWsClient
|
|
}
|
|
|
|
func MountGRPCWebServices(
|
|
router *mux.Router,
|
|
grpcWeb *grpcweb.WrappedGrpcServer,
|
|
grpcResources []string,
|
|
logger tmlog.Logger,
|
|
) {
|
|
for _, res := range grpcResources {
|
|
|
|
logger.Info("[GRPC Web] HTTP POST mounted", "resource", res)
|
|
|
|
s := router.Methods("POST").Subrouter()
|
|
s.HandleFunc(res, func(resp http.ResponseWriter, req *http.Request) {
|
|
if grpcWeb.IsGrpcWebSocketRequest(req) {
|
|
grpcWeb.HandleGrpcWebsocketRequest(resp, req)
|
|
return
|
|
}
|
|
|
|
if grpcWeb.IsGrpcWebRequest(req) {
|
|
grpcWeb.HandleGrpcWebRequest(resp, req)
|
|
return
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// 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
|
|
}
|