[config] Add flag to enable/disable private debug apis

pull/3396/head
Janet Liang 4 years ago
parent 87a443a910
commit ec3f266cda
  1. 5
      cmd/harmony/config.go
  2. 3
      cmd/harmony/default.go
  3. 21
      cmd/harmony/flags.go
  4. 14
      cmd/harmony/main.go
  5. 2
      internal/configs/node/config.go
  6. 19
      rpc/rpc.go

@ -23,6 +23,7 @@ type harmonyConfig struct {
P2P p2pConfig
HTTP httpConfig
WS wsConfig
RPCOpt rpcOptConfig
BLSKeys blsConfig
TxPool txPoolConfig
Pprof pprofConfig
@ -117,6 +118,10 @@ type wsConfig struct {
Port int
}
type rpcOptConfig struct {
Enabled bool
}
type devnetConfig struct {
NumShards int
ShardSize int

@ -36,6 +36,9 @@ var defaultConfig = harmonyConfig{
IP: "127.0.0.1",
Port: nodeconfig.DefaultWSPort,
},
RPCOpt: rpcOptConfig{
Enabled: false,
},
BLSKeys: blsConfig{
KeyDir: "./.hmy/blskeys",
KeyFiles: []string{},

@ -59,6 +59,10 @@ var (
wsPortFlag,
}
rpcOptFlags = []cli.Flag{
rpcDebugEnabledFlag,
}
blsFlags = append(newBLSFlags, legacyBLSFlags...)
newBLSFlags = []cli.Flag{
@ -236,6 +240,7 @@ func getRootFlags() []cli.Flag {
flags = append(flags, p2pFlags...)
flags = append(flags, httpFlags...)
flags = append(flags, wsFlags...)
flags = append(flags, rpcOptFlags...)
flags = append(flags, blsFlags...)
flags = append(flags, consensusFlags...)
flags = append(flags, txPoolFlags...)
@ -503,6 +508,22 @@ func applyWSFlags(cmd *cobra.Command, config *harmonyConfig) {
}
}
// rpc opt flags
var (
rpcDebugEnabledFlag = cli.BoolFlag{
Name: "rpc.debug",
Usage: "enable private debug apis",
DefValue: defaultConfig.RPCOpt.Enabled,
Hidden: true,
}
)
func applyRPCOptFlags(cmd *cobra.Command, config *harmonyConfig) {
if cli.IsFlagChanged(cmd, rpcDebugEnabledFlag) {
config.RPCOpt.Enabled = cli.GetBoolFlagValue(cmd, rpcDebugEnabledFlag)
}
}
// bls flags
var (
blsDirFlag = cli.StringFlag{

@ -191,6 +191,7 @@ func applyRootFlags(cmd *cobra.Command, config *harmonyConfig) {
applyP2PFlags(cmd, config)
applyHTTPFlags(cmd, config)
applyWSFlags(cmd, config)
applyRPCOptFlags(cmd, config)
applyBLSFlags(cmd, config)
applyConsensusFlags(cmd, config)
applyTxPoolFlags(cmd, config)
@ -306,12 +307,13 @@ func setupNodeAndRun(hc harmonyConfig) {
// Parse RPC config
nodeConfig.RPCServer = nodeconfig.RPCServerConfig{
HTTPEnabled: hc.HTTP.Enabled,
HTTPIp: hc.HTTP.IP,
HTTPPort: hc.HTTP.Port,
WSEnabled: hc.WS.Enabled,
WSIp: hc.WS.IP,
WSPort: hc.WS.Port,
HTTPEnabled: hc.HTTP.Enabled,
HTTPIp: hc.HTTP.IP,
HTTPPort: hc.HTTP.Port,
WSEnabled: hc.WS.Enabled,
WSIp: hc.WS.IP,
WSPort: hc.WS.Port,
DebugEnabled: hc.RPCOpt.Enabled,
}
if nodeConfig.ShardID != shard.BeaconChainShardID {
utils.Logger().Info().

@ -103,6 +103,8 @@ type RPCServerConfig struct {
WSEnabled bool
WSIp string
WSPort int
DebugEnabled bool
}
// RosettaServerConfig is the config for the rosetta server

@ -64,7 +64,7 @@ func (n Version) Namespace() string {
// StartServers starts the http & ws servers
func StartServers(hmy *hmy.Harmony, apis []rpc.API, config nodeconfig.RPCServerConfig) error {
apis = append(apis, getAPIs(hmy)...)
apis = append(apis, getAPIs(hmy, config.DebugEnabled)...)
if config.HTTPEnabled {
httpEndpoint = fmt.Sprintf("%v:%v", config.HTTPIp, config.HTTPPort)
@ -115,8 +115,8 @@ func StopServers() error {
}
// getAPIs returns all the API methods for the RPC interface
func getAPIs(hmy *hmy.Harmony) []rpc.API {
return []rpc.API{
func getAPIs(hmy *hmy.Harmony, debugEnable bool) []rpc.API {
publicAPIs := []rpc.API{
// Public methods
NewPublicHarmonyAPI(hmy, V1),
NewPublicHarmonyAPI(hmy, V2),
@ -130,13 +130,20 @@ func getAPIs(hmy *hmy.Harmony) []rpc.API {
NewPublicPoolAPI(hmy, V2),
NewPublicStakingAPI(hmy, V1),
NewPublicStakingAPI(hmy, V2),
// Private methods
NewPrivateDebugAPI(hmy, V1),
NewPrivateDebugAPI(hmy, V2),
// Legacy methods (subject to removal)
v1.NewPublicLegacyAPI(hmy),
v2.NewPublicLegacyAPI(hmy),
}
privateAPIs := []rpc.API{
NewPrivateDebugAPI(hmy, V1),
NewPrivateDebugAPI(hmy, V2),
}
if debugEnable {
return append(publicAPIs, privateAPIs...)
}
return publicAPIs
}
func startHTTP(apis []rpc.API) (err error) {

Loading…
Cancel
Save