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.
pull/3606/merge
bas-vk 8 years ago committed by Felix Lange
parent 43671067fb
commit 5e29f4be93
  1. 1
      cmd/geth/main.go
  2. 6
      cmd/geth/usage.go
  3. 23
      cmd/utils/flags.go
  4. 4
      eth/backend.go
  5. 1
      eth/config.go
  6. 6
      eth/gen_config.go
  7. 2
      internal/ethapi/backend.go
  8. 5
      internal/web3ext/web3ext.go
  9. 6
      les/backend.go
  10. 22
      node/api.go
  11. 4
      node/config.go
  12. 4
      node/node.go
  13. 4
      rpc/client_test.go
  14. 11
      rpc/http.go
  15. 6
      rpc/websocket.go

@ -140,7 +140,6 @@ func init() {
utils.MetricsEnabledFlag, utils.MetricsEnabledFlag,
utils.FakePoWFlag, utils.FakePoWFlag,
utils.NoCompactionFlag, utils.NoCompactionFlag,
utils.SolcPathFlag,
utils.GpoBlocksFlag, utils.GpoBlocksFlag,
utils.GpoPercentileFlag, utils.GpoPercentileFlag,
utils.ExtraDataFlag, utils.ExtraDataFlag,

@ -174,12 +174,6 @@ var AppHelpFlagGroups = []flagGroup{
utils.WhisperEnabledFlag, utils.WhisperEnabledFlag,
}, },
}, },
{
Name: "MISCELLANEOUS",
Flags: []cli.Flag{
utils.SolcPathFlag,
},
},
} }
func init() { func init() {

@ -392,11 +392,6 @@ var (
Usage: "JavaScript root path for `loadScript`", Usage: "JavaScript root path for `loadScript`",
Value: ".", Value: ".",
} }
SolcPathFlag = cli.StringFlag{
Name: "solc",
Usage: "Solidity compiler command to be used",
Value: "solc",
}
// Gas price oracle settings // Gas price oracle settings
GpoBlocksFlag = cli.IntFlag{ 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 // splitAndTrim splits input separated by a comma
// space from the substrings. // and trims excessive white space from the substrings.
func makeRPCModules(input string) []string { func splitAndTrim(input string) []string {
result := strings.Split(input, ",") result := strings.Split(input, ",")
for i, r := range result { for i, r := range result {
result[i] = strings.TrimSpace(r) result[i] = strings.TrimSpace(r)
@ -552,10 +547,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name) cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
} }
if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) { if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) {
cfg.HTTPCors = ctx.GlobalString(RPCCORSDomainFlag.Name) cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name))
} }
if ctx.GlobalIsSet(RPCApiFlag.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) cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
} }
if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) { if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
cfg.WSOrigins = ctx.GlobalString(WSAllowedOriginsFlag.Name) cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
} }
if ctx.GlobalIsSet(WSApiFlag.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) { if ctx.GlobalIsSet(GasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name) cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name)
} }
if ctx.GlobalIsSet(SolcPathFlag.Name) {
cfg.SolcPath = ctx.GlobalString(SolcPathFlag.Name)
}
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) { if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
// TODO(fjl): force-enable this in --dev mode // TODO(fjl): force-enable this in --dev mode
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name) cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)

@ -79,7 +79,6 @@ type Ethereum struct {
Mining bool Mining bool
MinerThreads int MinerThreads int
etherbase common.Address etherbase common.Address
solcPath string
netVersionId int netVersionId int
netRPCService *ethapi.PublicNetAPI netRPCService *ethapi.PublicNetAPI
@ -122,7 +121,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
netVersionId: config.NetworkId, netVersionId: config.NetworkId,
etherbase: config.Etherbase, etherbase: config.Etherbase,
MinerThreads: config.MinerThreads, MinerThreads: config.MinerThreads,
solcPath: config.SolcPath,
} }
if err := addMipmapBloomBins(chainDb); err != nil { 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. // APIs returns the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else. // NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API { 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 // Append any APIs exposed explicitly by the consensus engine
apis = append(apis, s.engine.APIs(s.BlockChain())...) apis = append(apis, s.engine.APIs(s.BlockChain())...)

@ -105,7 +105,6 @@ type Config struct {
EnablePreimageRecording bool EnablePreimageRecording bool
// Miscellaneous options // Miscellaneous options
SolcPath string
DocRoot string `toml:"-"` DocRoot string `toml:"-"`
PowFake bool `toml:"-"` PowFake bool `toml:"-"`
PowTest bool `toml:"-"` PowTest bool `toml:"-"`

@ -35,7 +35,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
EthashDatasetsOnDisk int EthashDatasetsOnDisk int
GPO gasprice.Config GPO gasprice.Config
EnablePreimageRecording bool EnablePreimageRecording bool
SolcPath string
DocRoot string `toml:"-"` DocRoot string `toml:"-"`
PowFake bool `toml:"-"` PowFake bool `toml:"-"`
PowTest bool `toml:"-"` PowTest bool `toml:"-"`
@ -63,7 +62,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk
enc.GPO = c.GPO enc.GPO = c.GPO
enc.EnablePreimageRecording = c.EnablePreimageRecording enc.EnablePreimageRecording = c.EnablePreimageRecording
enc.SolcPath = c.SolcPath
enc.DocRoot = c.DocRoot enc.DocRoot = c.DocRoot
enc.PowFake = c.PowFake enc.PowFake = c.PowFake
enc.PowTest = c.PowTest enc.PowTest = c.PowTest
@ -94,7 +92,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
EthashDatasetsOnDisk *int EthashDatasetsOnDisk *int
GPO *gasprice.Config GPO *gasprice.Config
EnablePreimageRecording *bool EnablePreimageRecording *bool
SolcPath *string
DocRoot *string `toml:"-"` DocRoot *string `toml:"-"`
PowFake *bool `toml:"-"` PowFake *bool `toml:"-"`
PowTest *bool `toml:"-"` PowTest *bool `toml:"-"`
@ -167,9 +164,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.EnablePreimageRecording != nil { if dec.EnablePreimageRecording != nil {
c.EnablePreimageRecording = *dec.EnablePreimageRecording c.EnablePreimageRecording = *dec.EnablePreimageRecording
} }
if dec.SolcPath != nil {
c.SolcPath = *dec.SolcPath
}
if dec.DocRoot != nil { if dec.DocRoot != nil {
c.DocRoot = *dec.DocRoot c.DocRoot = *dec.DocRoot
} }

@ -72,7 +72,7 @@ type State interface {
GetNonce(ctx context.Context, addr common.Address) (uint64, error) 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{ return []rpc.API{
{ {
Namespace: "eth", Namespace: "eth",

@ -143,11 +143,6 @@ web3._extend({
call: 'admin_sleepBlocks', call: 'admin_sleepBlocks',
params: 2 params: 2
}), }),
new web3._extend.Method({
name: 'setSolc',
call: 'admin_setSolc',
params: 1
}),
new web3._extend.Method({ new web3._extend.Method({
name: 'startRPC', name: 'startRPC',
call: 'admin_startRPC', call: 'admin_startRPC',

@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "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/common/hexutil"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -61,8 +60,6 @@ type LightEthereum struct {
eventMux *event.TypeMux eventMux *event.TypeMux
engine consensus.Engine engine consensus.Engine
accountManager *accounts.Manager accountManager *accounts.Manager
solcPath string
solc *compiler.Solidity
netVersionId int netVersionId int
netRPCService *ethapi.PublicNetAPI netRPCService *ethapi.PublicNetAPI
@ -91,7 +88,6 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
engine: eth.CreateConsensusEngine(ctx, config, chainConfig, chainDb), engine: eth.CreateConsensusEngine(ctx, config, chainConfig, chainDb),
shutdownChan: make(chan bool), shutdownChan: make(chan bool),
netVersionId: config.NetworkId, netVersionId: config.NetworkId,
solcPath: config.SolcPath,
} }
if eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.engine, eth.eventMux); err != nil { if eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.engine, eth.eventMux); err != nil {
return nil, err return nil, err
@ -145,7 +141,7 @@ func (s *LightDummyAPI) Mining() bool {
// APIs returns the collection of RPC services the ethereum package offers. // APIs returns the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else. // NOTE, some of these services probably need to be moved to somewhere else.
func (s *LightEthereum) APIs() []rpc.API { 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", Namespace: "eth",
Version: "1.0", Version: "1.0",

@ -92,8 +92,13 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
if port == nil { if port == nil {
port = &api.node.config.HTTPPort 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 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 false, err
} }
return true, nil return true, nil
@ -141,8 +146,13 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str
if port == nil { if port == nil {
port = &api.node.config.WSPort 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 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 false, err
} }
return true, nil return true, nil

@ -100,7 +100,7 @@ type Config struct {
// HTTPCors is the Cross-Origin Resource Sharing header to send to requesting // 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 // clients. Please be aware that CORS is a browser enforced security, it's fully
// useless for custom HTTP clients. // 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. // 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 // 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 // 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 // aware that the server can only act upon the HTTP request the client sends and
// cannot verify the validity of the request header. // 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. // 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 // If the module list is empty, all RPC API endpoints designated public will be

@ -372,7 +372,7 @@ func (n *Node) stopIPC() {
} }
// startHTTP initializes and starts the HTTP RPC endpoint. // 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 // Short circuit if the HTTP endpoint isn't being exposed
if endpoint == "" { if endpoint == "" {
return nil return nil
@ -426,7 +426,7 @@ func (n *Node) stopHTTP() {
} }
// startWS initializes and starts the websocket RPC endpoint. // 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 // Short circuit if the WS endpoint isn't being exposed
if endpoint == "" { if endpoint == "" {
return nil return nil

@ -394,7 +394,7 @@ func TestClientReconnect(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
go http.Serve(l, srv.WebsocketHandler("*")) go http.Serve(l, srv.WebsocketHandler([]string{"*"}))
return srv, l return srv, l
} }
@ -466,7 +466,7 @@ func httpTestClient(srv *Server, transport string, fl *flakeyListener) (*Client,
var hs *httptest.Server var hs *httptest.Server
switch transport { switch transport {
case "ws": case "ws":
hs = httptest.NewUnstartedServer(srv.WebsocketHandler("*")) hs = httptest.NewUnstartedServer(srv.WebsocketHandler([]string{"*"}))
case "http": case "http":
hs = httptest.NewUnstartedServer(srv) hs = httptest.NewUnstartedServer(srv)
default: default:

@ -25,7 +25,6 @@ import (
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
"strings"
"sync" "sync"
"time" "time"
@ -140,8 +139,8 @@ func (t *httpReadWriteNopCloser) Close() error {
// NewHTTPServer creates a new HTTP RPC server around an API provider. // NewHTTPServer creates a new HTTP RPC server around an API provider.
// //
// Deprecated: Server implements http.Handler // Deprecated: Server implements http.Handler
func NewHTTPServer(corsString string, srv *Server) *http.Server { func NewHTTPServer(cors []string, srv *Server) *http.Server {
return &http.Server{Handler: newCorsHandler(srv, corsString)} return &http.Server{Handler: newCorsHandler(srv, cors)}
} }
// ServeHTTP serves JSON-RPC requests over HTTP. // 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) srv.ServeSingleRequest(codec, OptionMethodInvocation)
} }
func newCorsHandler(srv *Server, corsString string) http.Handler { func newCorsHandler(srv *Server, allowedOrigins []string) http.Handler {
var allowedOrigins []string
for _, domain := range strings.Split(corsString, ",") {
allowedOrigins = append(allowedOrigins, strings.TrimSpace(domain))
}
c := cors.New(cors.Options{ c := cors.New(cors.Options{
AllowedOrigins: allowedOrigins, AllowedOrigins: allowedOrigins,
AllowedMethods: []string{"POST", "GET"}, AllowedMethods: []string{"POST", "GET"},

@ -36,9 +36,9 @@ import (
// //
// allowedOrigins should be a comma-separated list of allowed origin URLs. // allowedOrigins should be a comma-separated list of allowed origin URLs.
// To allow connections with any origin, pass "*". // 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{ return websocket.Server{
Handshake: wsHandshakeValidator(strings.Split(allowedOrigins, ",")), Handshake: wsHandshakeValidator(allowedOrigins),
Handler: func(conn *websocket.Conn) { Handler: func(conn *websocket.Conn) {
srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions) 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. // NewWSServer creates a new websocket RPC server around an API provider.
// //
// Deprecated: use Server.WebsocketHandler // 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)} return &http.Server{Handler: srv.WebsocketHandler(allowedOrigins)}
} }

Loading…
Cancel
Save