Merge pull request #3396 from janet-harmony/private_debug_service

[config] Add flag to enable debug APIs
pull/3406/head
Leo Chen 4 years ago committed by GitHub
commit 933ced343e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/harmony/config.go
  2. 3
      cmd/harmony/default.go
  3. 21
      cmd/harmony/flags.go
  4. 25
      cmd/harmony/flags_test.go
  5. 14
      cmd/harmony/main.go
  6. 2
      internal/configs/node/config.go
  7. 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 {
DebugEnabled bool // Enables PrivateDebugService APIs, including the EVM tracer
}
type devnetConfig struct {
NumShards int
ShardSize int

@ -36,6 +36,9 @@ var defaultConfig = harmonyConfig{
IP: "127.0.0.1",
Port: nodeconfig.DefaultWSPort,
},
RPCOpt: rpcOptConfig{
DebugEnabled: 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.DebugEnabled,
Hidden: true,
}
)
func applyRPCOptFlags(cmd *cobra.Command, config *harmonyConfig) {
if cli.IsFlagChanged(cmd, rpcDebugEnabledFlag) {
config.RPCOpt.DebugEnabled = cli.GetBoolFlagValue(cmd, rpcDebugEnabledFlag)
}
}
// bls flags
var (
blsDirFlag = cli.StringFlag{

@ -483,6 +483,31 @@ func TestWSFlags(t *testing.T) {
}
}
func TestRPCOptFlags(t *testing.T) {
tests := []struct {
args []string
expConfig rpcOptConfig
}{
{
args: []string{"--rpc.debug"},
expConfig: rpcOptConfig{
DebugEnabled: true,
},
},
}
for i, test := range tests {
ts := newFlagTestSuite(t, rpcOptFlags, applyRPCOptFlags)
hc, _ := ts.run(test.args)
if !reflect.DeepEqual(hc.RPCOpt, test.expConfig) {
t.Errorf("Test %v: \n\t%+v\n\t%+v", i, hc.RPCOpt, test.expConfig)
}
ts.tearDown()
}
}
func TestBLSFlags(t *testing.T) {
tests := []struct {
args []string

@ -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.DebugEnabled,
}
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