This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sync start command with cosmos-sdk 0.43 Closes #340 - add grpc web and rosetta server - add tx/tm services - add standalone mode - update cosmos-sdk to 0.43.0-rc2, which fixed a bug in service startup - add EnableUnsafeCORS option to evm rpc server * set keyring options in root cmd and use viper prefix * fix linter and pr suggestions Co-authored-by: Federico Kunze Küllmer <[email protected]>
- Loading branch information
Showing
6 changed files
with
292 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package server | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/rs/cors" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/server" | ||
"github.com/cosmos/cosmos-sdk/server/types" | ||
ethrpc "github.com/ethereum/go-ethereum/rpc" | ||
"github.com/tharsis/ethermint/cmd/ethermintd/config" | ||
"github.com/tharsis/ethermint/ethereum/rpc" | ||
) | ||
|
||
// StartEVMRPC start evm rpc server | ||
func StartEVMRPC(ctx *server.Context, clientCtx client.Context, tmRPCAddr string, tmEndpoint string, config config.Config) (*http.Server, chan struct{}, error) { | ||
tmWsClient := ConnectTmWS(tmRPCAddr, tmEndpoint) | ||
|
||
rpcServer := ethrpc.NewServer() | ||
apis := rpc.GetRPCAPIs(ctx, clientCtx, tmWsClient) | ||
|
||
for _, api := range apis { | ||
if err := rpcServer.RegisterName(api.Namespace, api.Service); err != nil { | ||
ctx.Logger.Error( | ||
"failed to register service in EVM RPC namespace", | ||
"namespace", api.Namespace, | ||
"service", api.Service, | ||
) | ||
return nil, nil, err | ||
} | ||
} | ||
|
||
r := mux.NewRouter() | ||
r.HandleFunc("/", rpcServer.ServeHTTP).Methods("POST") | ||
|
||
handlerWithCors := cors.Default() | ||
if config.EVMRPC.EnableUnsafeCORS { | ||
handlerWithCors = cors.AllowAll() | ||
} | ||
|
||
httpSrv := &http.Server{ | ||
Addr: config.EVMRPC.RPCAddress, | ||
Handler: handlerWithCors.Handler(r), | ||
} | ||
httpSrvDone := make(chan struct{}, 1) | ||
|
||
errCh := make(chan error) | ||
go func() { | ||
ctx.Logger.Info("Starting EVM RPC server", "address", config.EVMRPC.RPCAddress) | ||
if err := httpSrv.ListenAndServe(); err != nil { | ||
if err == http.ErrServerClosed { | ||
close(httpSrvDone) | ||
return | ||
} | ||
|
||
ctx.Logger.Error("failed to start EVM RPC server", "error", err.Error()) | ||
errCh <- err | ||
} | ||
}() | ||
|
||
select { | ||
case err := <-errCh: | ||
ctx.Logger.Error("failed to boot EVM RPC server", "error", err.Error()) | ||
return nil, nil, err | ||
case <-time.After(types.ServerStartTime): // assume EVM RPC server started successfully | ||
} | ||
|
||
ctx.Logger.Info("Starting EVM WebSocket server", "address", config.EVMRPC.WsAddress) | ||
_, port, _ := net.SplitHostPort(config.EVMRPC.RPCAddress) | ||
|
||
// allocate separate WS connection to Tendermint | ||
tmWsClient = ConnectTmWS(tmRPCAddr, tmEndpoint) | ||
wsSrv := rpc.NewWebsocketsServer(ctx.Logger, tmWsClient, "localhost:"+port, config.EVMRPC.WsAddress) | ||
wsSrv.Start() | ||
return httpSrv, httpSrvDone, nil | ||
} |
Oops, something went wrong.