From 9fe7a51efafddd82f8dd55af687f163045153453 Mon Sep 17 00:00:00 2001 From: Peter Chung Date: Sun, 6 Jun 2021 01:29:08 +0800 Subject: [PATCH] [rpc] add hmyv2_getConfig rpc --- cmd/harmony/main.go | 20 ++++++++------------ hmy/hmy.go | 1 + node/api.go | 8 ++++++++ node/node.go | 2 ++ rpc/common/types.go | 1 + rpc/debug.go | 8 ++++++++ 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 9918b1fcc..40055a081 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -1,7 +1,6 @@ package main import ( - "encoding/json" "fmt" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" rpc_common "github.com/harmony-one/harmony/rpc/common" @@ -297,17 +296,6 @@ func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) { os.Exit(1) } - if hc.Log.VerbosePrints["config"] { - if cfgJson, err := json.MarshalIndent(rpc_common.Config{ - HarmonyConfig: hc, - NodeConfig: *nodeConfig, - }, "", " "); err != nil { - panic(err) - } else { - println(string(cfgJson)) - } - } - // Update ethereum compatible chain ids params.UpdateEthChainIDByShard(nodeConfig.ShardID) @@ -393,6 +381,14 @@ func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) { nodeconfig.SetPeerID(myHost.GetID()) + if hc.Log.VerbosePrints["config"] { + utils.Logger().Info().Interface("config", rpc_common.Config{ + HarmonyConfig: hc, + NodeConfig: *nodeConfig, + ChainConfig: *currentNode.Blockchain().Config(), + }).Msg("verbose prints config") + } + // Setup services if hc.Sync.Enabled { setupSyncService(currentNode, myHost, hc) diff --git a/hmy/hmy.go b/hmy/hmy.go index d62955520..a88cfe608 100644 --- a/hmy/hmy.go +++ b/hmy/hmy.go @@ -106,6 +106,7 @@ type NodeAPI interface { GetConsensusPhase() string GetConsensusViewChangingID() uint64 GetConsensusCurViewID() uint64 + GetConfig() commonRPC.Config ShutDown() } diff --git a/node/api.go b/node/api.go index 5c677bfa1..47311ac24 100644 --- a/node/api.go +++ b/node/api.go @@ -142,3 +142,11 @@ func (node *Node) GetConsensusInternal() rpc_common.ConsensusInternal { ConsensusTime: node.Consensus.GetFinality(), } } + +func (node *Node) GetConfig() rpc_common.Config { + return rpc_common.Config{ + HarmonyConfig: node.HarmonyConfig, + NodeConfig: *node.NodeConfig, + ChainConfig: node.chainConfig, + } +} \ No newline at end of file diff --git a/node/node.go b/node/node.go index 5f1ff452c..a36a79cd3 100644 --- a/node/node.go +++ b/node/node.go @@ -3,6 +3,7 @@ package node import ( "context" "fmt" + "github.com/harmony-one/harmony/internal/configs/harmony" "math/big" "os" "strings" @@ -105,6 +106,7 @@ type Node struct { ContractAddresses []common.Address // Channel to notify consensus service to really start consensus startConsensus chan struct{} + HarmonyConfig harmony.HarmonyConfig // node configuration, including group ID, shard ID, etc NodeConfig *nodeconfig.ConfigType // Chain configuration. diff --git a/rpc/common/types.go b/rpc/common/types.go index 78f08c9c0..bd39873d0 100644 --- a/rpc/common/types.go +++ b/rpc/common/types.go @@ -86,4 +86,5 @@ type NodePeerInfo struct { type Config struct { HarmonyConfig harmonyconfig.HarmonyConfig NodeConfig nodeconfig.ConfigType + ChainConfig params.ChainConfig } \ No newline at end of file diff --git a/rpc/debug.go b/rpc/debug.go index 9d05a113e..5c199de1c 100644 --- a/rpc/debug.go +++ b/rpc/debug.go @@ -2,6 +2,7 @@ package rpc import ( "context" + commonRPC "github.com/harmony-one/harmony/rpc/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" @@ -64,3 +65,10 @@ func (s *PrivateDebugService) GetConsensusPhase( ) string { return s.hmy.NodeAPI.GetConsensusPhase() } + +// GetConfig get harmony config +func (s *PrivateDebugService) GetConfig( + ctx context.Context, +) commonRPC.Config { + return s.hmy.NodeAPI.GetConfig() +}