diff options
author | bas-vk <bas-vk@users.noreply.github.com> | 2017-04-13 05:04:14 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-04-13 05:04:14 +0800 |
commit | 5e29f4be935ff227bbf07a0c6e80e8809f5e0202 (patch) | |
tree | 18e1ef8db3c66c3bf777dc90326aa971f1343d34 | |
parent | 43671067fb453a1ed798bcc3d8016710460f2bdf (diff) | |
download | go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.gz go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.bz2 go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.lz go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.xz go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.tar.zst go-tangerine-5e29f4be935ff227bbf07a0c6e80e8809f5e0202.zip |
cmd/utils, node: remove unused solc references and improve RPC config (#14324)
Currently http cors and websocket origins are a comma separated string in the
config object. These are replaced with string arrays that are more expressive in
case of a config file.
-rw-r--r-- | cmd/geth/main.go | 1 | ||||
-rw-r--r-- | cmd/geth/usage.go | 6 | ||||
-rw-r--r-- | cmd/utils/flags.go | 23 | ||||
-rw-r--r-- | eth/backend.go | 4 | ||||
-rw-r--r-- | eth/config.go | 1 | ||||
-rw-r--r-- | eth/gen_config.go | 6 | ||||
-rw-r--r-- | internal/ethapi/backend.go | 2 | ||||
-rw-r--r-- | internal/web3ext/web3ext.go | 5 | ||||
-rw-r--r-- | les/backend.go | 6 | ||||
-rw-r--r-- | node/api.go | 22 | ||||
-rw-r--r-- | node/config.go | 4 | ||||
-rw-r--r-- | node/node.go | 4 | ||||
-rw-r--r-- | rpc/client_test.go | 4 | ||||
-rw-r--r-- | rpc/http.go | 11 | ||||
-rw-r--r-- | rpc/websocket.go | 6 |
15 files changed, 38 insertions, 67 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 8e434948e..5fb50c4ad 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -140,7 +140,6 @@ func init() { utils.MetricsEnabledFlag, utils.FakePoWFlag, utils.NoCompactionFlag, - utils.SolcPathFlag, utils.GpoBlocksFlag, utils.GpoPercentileFlag, utils.ExtraDataFlag, diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 334d017d9..a172b4775 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -174,12 +174,6 @@ var AppHelpFlagGroups = []flagGroup{ utils.WhisperEnabledFlag, }, }, - { - Name: "MISCELLANEOUS", - Flags: []cli.Flag{ - utils.SolcPathFlag, - }, - }, } func init() { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 1bd77139c..b35574c86 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -392,11 +392,6 @@ var ( Usage: "JavaScript root path for `loadScript`", Value: ".", } - SolcPathFlag = cli.StringFlag{ - Name: "solc", - Usage: "Solidity compiler command to be used", - Value: "solc", - } // Gas price oracle settings GpoBlocksFlag = cli.IntFlag{ @@ -528,9 +523,9 @@ func setNAT(ctx *cli.Context, cfg *p2p.Config) { } } -// makeRPCModules splits input separated by a comma and trims excessive white -// space from the substrings. -func makeRPCModules(input string) []string { +// splitAndTrim splits input separated by a comma +// and trims excessive white space from the substrings. +func splitAndTrim(input string) []string { result := strings.Split(input, ",") for i, r := range result { result[i] = strings.TrimSpace(r) @@ -552,10 +547,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) { cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name) } if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) { - cfg.HTTPCors = ctx.GlobalString(RPCCORSDomainFlag.Name) + cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name)) } if ctx.GlobalIsSet(RPCApiFlag.Name) { - cfg.HTTPModules = makeRPCModules(ctx.GlobalString(RPCApiFlag.Name)) + cfg.HTTPModules = splitAndTrim(ctx.GlobalString(RPCApiFlag.Name)) } } @@ -573,10 +568,10 @@ func setWS(ctx *cli.Context, cfg *node.Config) { cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name) } if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) { - cfg.WSOrigins = ctx.GlobalString(WSAllowedOriginsFlag.Name) + cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name)) } if ctx.GlobalIsSet(WSApiFlag.Name) { - cfg.WSModules = makeRPCModules(ctx.GlobalString(WSApiFlag.Name)) + cfg.WSModules = splitAndTrim(ctx.GlobalString(WSApiFlag.Name)) } } @@ -828,10 +823,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { if ctx.GlobalIsSet(GasPriceFlag.Name) { cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name) } - - if ctx.GlobalIsSet(SolcPathFlag.Name) { - cfg.SolcPath = ctx.GlobalString(SolcPathFlag.Name) - } if ctx.GlobalIsSet(VMEnableDebugFlag.Name) { // TODO(fjl): force-enable this in --dev mode cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name) diff --git a/eth/backend.go b/eth/backend.go index 7ee591f9e..03c2e38e5 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -79,7 +79,6 @@ type Ethereum struct { Mining bool MinerThreads int etherbase common.Address - solcPath string netVersionId int netRPCService *ethapi.PublicNetAPI @@ -122,7 +121,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { netVersionId: config.NetworkId, etherbase: config.Etherbase, MinerThreads: config.MinerThreads, - solcPath: config.SolcPath, } if err := addMipmapBloomBins(chainDb); err != nil { @@ -236,7 +234,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. func (s *Ethereum) APIs() []rpc.API { - apis := ethapi.GetAPIs(s.ApiBackend, s.solcPath) + apis := ethapi.GetAPIs(s.ApiBackend) // Append any APIs exposed explicitly by the consensus engine apis = append(apis, s.engine.APIs(s.BlockChain())...) diff --git a/eth/config.go b/eth/config.go index 9c3f8b0fb..daa402ca5 100644 --- a/eth/config.go +++ b/eth/config.go @@ -105,7 +105,6 @@ type Config struct { EnablePreimageRecording bool // Miscellaneous options - SolcPath string DocRoot string `toml:"-"` PowFake bool `toml:"-"` PowTest bool `toml:"-"` diff --git a/eth/gen_config.go b/eth/gen_config.go index d34273e1c..56fba1d89 100644 --- a/eth/gen_config.go +++ b/eth/gen_config.go @@ -35,7 +35,6 @@ func (c Config) MarshalTOML() (interface{}, error) { EthashDatasetsOnDisk int GPO gasprice.Config EnablePreimageRecording bool - SolcPath string DocRoot string `toml:"-"` PowFake bool `toml:"-"` PowTest bool `toml:"-"` @@ -63,7 +62,6 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk enc.GPO = c.GPO enc.EnablePreimageRecording = c.EnablePreimageRecording - enc.SolcPath = c.SolcPath enc.DocRoot = c.DocRoot enc.PowFake = c.PowFake enc.PowTest = c.PowTest @@ -94,7 +92,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { EthashDatasetsOnDisk *int GPO *gasprice.Config EnablePreimageRecording *bool - SolcPath *string DocRoot *string `toml:"-"` PowFake *bool `toml:"-"` PowTest *bool `toml:"-"` @@ -167,9 +164,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.EnablePreimageRecording != nil { c.EnablePreimageRecording = *dec.EnablePreimageRecording } - if dec.SolcPath != nil { - c.SolcPath = *dec.SolcPath - } if dec.DocRoot != nil { c.DocRoot = *dec.DocRoot } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 50cd3801b..42bf26613 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -72,7 +72,7 @@ type State interface { GetNonce(ctx context.Context, addr common.Address) (uint64, error) } -func GetAPIs(apiBackend Backend, solcPath string) []rpc.API { +func GetAPIs(apiBackend Backend) []rpc.API { return []rpc.API{ { Namespace: "eth", diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index ac79398b9..72c2bd996 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -144,11 +144,6 @@ web3._extend({ params: 2 }), new web3._extend.Method({ - name: 'setSolc', - call: 'admin_setSolc', - params: 1 - }), - new web3._extend.Method({ name: 'startRPC', call: 'admin_startRPC', params: 4, diff --git a/les/backend.go b/les/backend.go index 184464f20..783e6e94e 100644 --- a/les/backend.go +++ b/les/backend.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/compiler" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core" @@ -61,8 +60,6 @@ type LightEthereum struct { eventMux *event.TypeMux engine consensus.Engine accountManager *accounts.Manager - solcPath string - solc *compiler.Solidity netVersionId int netRPCService *ethapi.PublicNetAPI @@ -91,7 +88,6 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { engine: eth.CreateConsensusEngine(ctx, config, chainConfig, chainDb), shutdownChan: make(chan bool), netVersionId: config.NetworkId, - solcPath: config.SolcPath, } if eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.engine, eth.eventMux); err != nil { return nil, err @@ -145,7 +141,7 @@ func (s *LightDummyAPI) Mining() bool { // APIs returns the collection of RPC services the ethereum package offers. // NOTE, some of these services probably need to be moved to somewhere else. func (s *LightEthereum) APIs() []rpc.API { - return append(ethapi.GetAPIs(s.ApiBackend, s.solcPath), []rpc.API{ + return append(ethapi.GetAPIs(s.ApiBackend), []rpc.API{ { Namespace: "eth", Version: "1.0", diff --git a/node/api.go b/node/api.go index 3c451fc8a..570cb9d98 100644 --- a/node/api.go +++ b/node/api.go @@ -92,8 +92,13 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis if port == nil { port = &api.node.config.HTTPPort } - if cors == nil { - cors = &api.node.config.HTTPCors + + allowedOrigins := api.node.config.HTTPCors + if cors != nil { + allowedOrigins = nil + for _, origin := range strings.Split(*cors, ",") { + allowedOrigins = append(allowedOrigins, strings.TrimSpace(origin)) + } } modules := api.node.httpWhitelist @@ -104,7 +109,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis } } - if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, *cors); err != nil { + if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, allowedOrigins); err != nil { return false, err } return true, nil @@ -141,8 +146,13 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str if port == nil { port = &api.node.config.WSPort } - if allowedOrigins == nil { - allowedOrigins = &api.node.config.WSOrigins + + origins := api.node.config.WSOrigins + if allowedOrigins != nil { + origins = nil + for _, origin := range strings.Split(*allowedOrigins, ",") { + origins = append(origins, strings.TrimSpace(origin)) + } } modules := api.node.config.WSModules @@ -153,7 +163,7 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str } } - if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, *allowedOrigins); err != nil { + if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, origins); err != nil { return false, err } return true, nil diff --git a/node/config.go b/node/config.go index 7c17e707d..1bab4c574 100644 --- a/node/config.go +++ b/node/config.go @@ -100,7 +100,7 @@ type Config struct { // HTTPCors is the Cross-Origin Resource Sharing header to send to requesting // clients. Please be aware that CORS is a browser enforced security, it's fully // useless for custom HTTP clients. - HTTPCors string `toml:",omitempty"` + HTTPCors []string `toml:",omitempty"` // HTTPModules is a list of API modules to expose via the HTTP RPC interface. // If the module list is empty, all RPC API endpoints designated public will be @@ -119,7 +119,7 @@ type Config struct { // WSOrigins is the list of domain to accept websocket requests from. Please be // aware that the server can only act upon the HTTP request the client sends and // cannot verify the validity of the request header. - WSOrigins string `toml:",omitempty"` + WSOrigins []string `toml:",omitempty"` // WSModules is a list of API modules to expose via the websocket RPC interface. // If the module list is empty, all RPC API endpoints designated public will be diff --git a/node/node.go b/node/node.go index 2ecff2308..dc2ff0701 100644 --- a/node/node.go +++ b/node/node.go @@ -372,7 +372,7 @@ func (n *Node) stopIPC() { } // startHTTP initializes and starts the HTTP RPC endpoint. -func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors string) error { +func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string) error { // Short circuit if the HTTP endpoint isn't being exposed if endpoint == "" { return nil @@ -426,7 +426,7 @@ func (n *Node) stopHTTP() { } // startWS initializes and starts the websocket RPC endpoint. -func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsOrigins string) error { +func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsOrigins []string) error { // Short circuit if the WS endpoint isn't being exposed if endpoint == "" { return nil diff --git a/rpc/client_test.go b/rpc/client_test.go index 41471dcea..10d74670b 100644 --- a/rpc/client_test.go +++ b/rpc/client_test.go @@ -394,7 +394,7 @@ func TestClientReconnect(t *testing.T) { if err != nil { t.Fatal(err) } - go http.Serve(l, srv.WebsocketHandler("*")) + go http.Serve(l, srv.WebsocketHandler([]string{"*"})) return srv, l } @@ -466,7 +466,7 @@ func httpTestClient(srv *Server, transport string, fl *flakeyListener) (*Client, var hs *httptest.Server switch transport { case "ws": - hs = httptest.NewUnstartedServer(srv.WebsocketHandler("*")) + hs = httptest.NewUnstartedServer(srv.WebsocketHandler([]string{"*"})) case "http": hs = httptest.NewUnstartedServer(srv) default: diff --git a/rpc/http.go b/rpc/http.go index 89175b149..022f9ce8f 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -25,7 +25,6 @@ import ( "io/ioutil" "net" "net/http" - "strings" "sync" "time" @@ -140,8 +139,8 @@ func (t *httpReadWriteNopCloser) Close() error { // NewHTTPServer creates a new HTTP RPC server around an API provider. // // Deprecated: Server implements http.Handler -func NewHTTPServer(corsString string, srv *Server) *http.Server { - return &http.Server{Handler: newCorsHandler(srv, corsString)} +func NewHTTPServer(cors []string, srv *Server) *http.Server { + return &http.Server{Handler: newCorsHandler(srv, cors)} } // ServeHTTP serves JSON-RPC requests over HTTP. @@ -162,11 +161,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { srv.ServeSingleRequest(codec, OptionMethodInvocation) } -func newCorsHandler(srv *Server, corsString string) http.Handler { - var allowedOrigins []string - for _, domain := range strings.Split(corsString, ",") { - allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain)) - } +func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler { c := cors.New(cors.Options{ AllowedOrigins: allowedOrigins, AllowedMethods: []string{"POST", "GET"}, diff --git a/rpc/websocket.go b/rpc/websocket.go index 587010820..5f9593a43 100644 --- a/rpc/websocket.go +++ b/rpc/websocket.go @@ -36,9 +36,9 @@ import ( // // allowedOrigins should be a comma-separated list of allowed origin URLs. // To allow connections with any origin, pass "*". -func (srv *Server) WebsocketHandler(allowedOrigins string) http.Handler { +func (srv *Server) WebsocketHandler(allowedOrigins []string) http.Handler { return websocket.Server{ - Handshake: wsHandshakeValidator(strings.Split(allowedOrigins, ",")), + Handshake: wsHandshakeValidator(allowedOrigins), Handler: func(conn *websocket.Conn) { srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) }, @@ -48,7 +48,7 @@ func (srv *Server) WebsocketHandler(allowedOrigins string) http.Handler { // NewWSServer creates a new websocket RPC server around an API provider. // // Deprecated: use Server.WebsocketHandler -func NewWSServer(allowedOrigins string, srv *Server) *http.Server { +func NewWSServer(allowedOrigins []string, srv *Server) *http.Server { return &http.Server{Handler: srv.WebsocketHandler(allowedOrigins)} } |