Skip to content

Commit 5e29f4b

Browse files
bas-vkfjl
authored andcommitted
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.
1 parent 4367106 commit 5e29f4b

File tree

15 files changed

+38
-67
lines changed

15 files changed

+38
-67
lines changed

cmd/geth/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func init() {
140140
utils.MetricsEnabledFlag,
141141
utils.FakePoWFlag,
142142
utils.NoCompactionFlag,
143-
utils.SolcPathFlag,
144143
utils.GpoBlocksFlag,
145144
utils.GpoPercentileFlag,
146145
utils.ExtraDataFlag,

cmd/geth/usage.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ var AppHelpFlagGroups = []flagGroup{
174174
utils.WhisperEnabledFlag,
175175
},
176176
},
177-
{
178-
Name: "MISCELLANEOUS",
179-
Flags: []cli.Flag{
180-
utils.SolcPathFlag,
181-
},
182-
},
183177
}
184178

185179
func init() {

cmd/utils/flags.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,6 @@ var (
392392
Usage: "JavaScript root path for `loadScript`",
393393
Value: ".",
394394
}
395-
SolcPathFlag = cli.StringFlag{
396-
Name: "solc",
397-
Usage: "Solidity compiler command to be used",
398-
Value: "solc",
399-
}
400395

401396
// Gas price oracle settings
402397
GpoBlocksFlag = cli.IntFlag{
@@ -528,9 +523,9 @@ func setNAT(ctx *cli.Context, cfg *p2p.Config) {
528523
}
529524
}
530525

531-
// makeRPCModules splits input separated by a comma and trims excessive white
532-
// space from the substrings.
533-
func makeRPCModules(input string) []string {
526+
// splitAndTrim splits input separated by a comma
527+
// and trims excessive white space from the substrings.
528+
func splitAndTrim(input string) []string {
534529
result := strings.Split(input, ",")
535530
for i, r := range result {
536531
result[i] = strings.TrimSpace(r)
@@ -552,10 +547,10 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
552547
cfg.HTTPPort = ctx.GlobalInt(RPCPortFlag.Name)
553548
}
554549
if ctx.GlobalIsSet(RPCCORSDomainFlag.Name) {
555-
cfg.HTTPCors = ctx.GlobalString(RPCCORSDomainFlag.Name)
550+
cfg.HTTPCors = splitAndTrim(ctx.GlobalString(RPCCORSDomainFlag.Name))
556551
}
557552
if ctx.GlobalIsSet(RPCApiFlag.Name) {
558-
cfg.HTTPModules = makeRPCModules(ctx.GlobalString(RPCApiFlag.Name))
553+
cfg.HTTPModules = splitAndTrim(ctx.GlobalString(RPCApiFlag.Name))
559554
}
560555
}
561556

@@ -573,10 +568,10 @@ func setWS(ctx *cli.Context, cfg *node.Config) {
573568
cfg.WSPort = ctx.GlobalInt(WSPortFlag.Name)
574569
}
575570
if ctx.GlobalIsSet(WSAllowedOriginsFlag.Name) {
576-
cfg.WSOrigins = ctx.GlobalString(WSAllowedOriginsFlag.Name)
571+
cfg.WSOrigins = splitAndTrim(ctx.GlobalString(WSAllowedOriginsFlag.Name))
577572
}
578573
if ctx.GlobalIsSet(WSApiFlag.Name) {
579-
cfg.WSModules = makeRPCModules(ctx.GlobalString(WSApiFlag.Name))
574+
cfg.WSModules = splitAndTrim(ctx.GlobalString(WSApiFlag.Name))
580575
}
581576
}
582577

@@ -828,10 +823,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
828823
if ctx.GlobalIsSet(GasPriceFlag.Name) {
829824
cfg.GasPrice = GlobalBig(ctx, GasPriceFlag.Name)
830825
}
831-
832-
if ctx.GlobalIsSet(SolcPathFlag.Name) {
833-
cfg.SolcPath = ctx.GlobalString(SolcPathFlag.Name)
834-
}
835826
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
836827
// TODO(fjl): force-enable this in --dev mode
837828
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)

eth/backend.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ type Ethereum struct {
7979
Mining bool
8080
MinerThreads int
8181
etherbase common.Address
82-
solcPath string
8382

8483
netVersionId int
8584
netRPCService *ethapi.PublicNetAPI
@@ -122,7 +121,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
122121
netVersionId: config.NetworkId,
123122
etherbase: config.Etherbase,
124123
MinerThreads: config.MinerThreads,
125-
solcPath: config.SolcPath,
126124
}
127125

128126
if err := addMipmapBloomBins(chainDb); err != nil {
@@ -236,7 +234,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig
236234
// APIs returns the collection of RPC services the ethereum package offers.
237235
// NOTE, some of these services probably need to be moved to somewhere else.
238236
func (s *Ethereum) APIs() []rpc.API {
239-
apis := ethapi.GetAPIs(s.ApiBackend, s.solcPath)
237+
apis := ethapi.GetAPIs(s.ApiBackend)
240238

241239
// Append any APIs exposed explicitly by the consensus engine
242240
apis = append(apis, s.engine.APIs(s.BlockChain())...)

eth/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ type Config struct {
105105
EnablePreimageRecording bool
106106

107107
// Miscellaneous options
108-
SolcPath string
109108
DocRoot string `toml:"-"`
110109
PowFake bool `toml:"-"`
111110
PowTest bool `toml:"-"`

eth/gen_config.go

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/ethapi/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type State interface {
7272
GetNonce(ctx context.Context, addr common.Address) (uint64, error)
7373
}
7474

75-
func GetAPIs(apiBackend Backend, solcPath string) []rpc.API {
75+
func GetAPIs(apiBackend Backend) []rpc.API {
7676
return []rpc.API{
7777
{
7878
Namespace: "eth",

internal/web3ext/web3ext.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ web3._extend({
143143
call: 'admin_sleepBlocks',
144144
params: 2
145145
}),
146-
new web3._extend.Method({
147-
name: 'setSolc',
148-
call: 'admin_setSolc',
149-
params: 1
150-
}),
151146
new web3._extend.Method({
152147
name: 'startRPC',
153148
call: 'admin_startRPC',

les/backend.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/accounts"
2525
"github.com/ethereum/go-ethereum/common"
26-
"github.com/ethereum/go-ethereum/common/compiler"
2726
"github.com/ethereum/go-ethereum/common/hexutil"
2827
"github.com/ethereum/go-ethereum/consensus"
2928
"github.com/ethereum/go-ethereum/core"
@@ -61,8 +60,6 @@ type LightEthereum struct {
6160
eventMux *event.TypeMux
6261
engine consensus.Engine
6362
accountManager *accounts.Manager
64-
solcPath string
65-
solc *compiler.Solidity
6663

6764
netVersionId int
6865
netRPCService *ethapi.PublicNetAPI
@@ -91,7 +88,6 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
9188
engine: eth.CreateConsensusEngine(ctx, config, chainConfig, chainDb),
9289
shutdownChan: make(chan bool),
9390
netVersionId: config.NetworkId,
94-
solcPath: config.SolcPath,
9591
}
9692
if eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.engine, eth.eventMux); err != nil {
9793
return nil, err
@@ -145,7 +141,7 @@ func (s *LightDummyAPI) Mining() bool {
145141
// APIs returns the collection of RPC services the ethereum package offers.
146142
// NOTE, some of these services probably need to be moved to somewhere else.
147143
func (s *LightEthereum) APIs() []rpc.API {
148-
return append(ethapi.GetAPIs(s.ApiBackend, s.solcPath), []rpc.API{
144+
return append(ethapi.GetAPIs(s.ApiBackend), []rpc.API{
149145
{
150146
Namespace: "eth",
151147
Version: "1.0",

node/api.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
9292
if port == nil {
9393
port = &api.node.config.HTTPPort
9494
}
95-
if cors == nil {
96-
cors = &api.node.config.HTTPCors
95+
96+
allowedOrigins := api.node.config.HTTPCors
97+
if cors != nil {
98+
allowedOrigins = nil
99+
for _, origin := range strings.Split(*cors, ",") {
100+
allowedOrigins = append(allowedOrigins, strings.TrimSpace(origin))
101+
}
97102
}
98103

99104
modules := api.node.httpWhitelist
@@ -104,7 +109,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
104109
}
105110
}
106111

107-
if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, *cors); err != nil {
112+
if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, allowedOrigins); err != nil {
108113
return false, err
109114
}
110115
return true, nil
@@ -141,8 +146,13 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str
141146
if port == nil {
142147
port = &api.node.config.WSPort
143148
}
144-
if allowedOrigins == nil {
145-
allowedOrigins = &api.node.config.WSOrigins
149+
150+
origins := api.node.config.WSOrigins
151+
if allowedOrigins != nil {
152+
origins = nil
153+
for _, origin := range strings.Split(*allowedOrigins, ",") {
154+
origins = append(origins, strings.TrimSpace(origin))
155+
}
146156
}
147157

148158
modules := api.node.config.WSModules
@@ -153,7 +163,7 @@ func (api *PrivateAdminAPI) StartWS(host *string, port *int, allowedOrigins *str
153163
}
154164
}
155165

156-
if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, *allowedOrigins); err != nil {
166+
if err := api.node.startWS(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, origins); err != nil {
157167
return false, err
158168
}
159169
return true, nil

0 commit comments

Comments
 (0)