[nodetype] add nodetype to replace is_explorer

Signed-off-by: Leo Chen <leo@harmony.one>
pull/1582/head
Leo Chen 5 years ago
parent 3f428ce40d
commit f08fd3219a
  1. 35
      cmd/harmony/main.go
  2. 13
      node/node_syncing.go
  3. 4
      test/configs/local-resharding.txt
  4. 18
      test/deploy.sh

@ -10,6 +10,7 @@ import (
"path"
"runtime"
"strconv"
"strings"
"time"
ethCommon "github.com/ethereum/go-ethereum/common"
@ -84,8 +85,8 @@ var (
isArchival = flag.Bool("is_archival", true, "false makes node faster by turning caching off")
// delayCommit is the commit-delay timer, used by Harmony nodes
delayCommit = flag.String("delay_commit", "0ms", "how long to delay sending commit messages in consensus, ex: 500ms, 1s")
// isExplorer indicates this node is a node to serve explorer
isExplorer = flag.Bool("is_explorer", false, "true means this node is a node to serve explorer")
// nodeType indicates the type of the node: validator, explorer
nodeType = flag.String("node_type", "validator", "node type: validator, explorer")
// networkType indicates the type of the network
networkType = flag.String("network_type", "mainnet", "type of the network: mainnet, testnet, devnet, localnet")
// blockPeriod indicates the how long the leader waits to propose a new block.
@ -168,9 +169,11 @@ func initSetup() {
func passphraseForBls() {
// If FN node running, they should either specify blsPrivateKey or the file with passphrase
if *isExplorer {
// However, explorer or non-validator nodes need no blskey
if *nodeType != "validator" {
return
}
if *blsKeyFile == "" || *blsPass == "" {
fmt.Println("Internal nodes need to have pass to decrypt blskey")
os.Exit(101)
@ -231,7 +234,7 @@ func createGlobalConfig() *nodeconfig.ConfigType {
var err error
nodeConfig := nodeconfig.GetShardConfig(initialAccount.ShardID)
if !*isExplorer {
if *nodeType == "validator" {
// Set up consensus keys.
setupConsensusKey(nodeConfig)
} else {
@ -334,17 +337,17 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
currentNode.NodeConfig.SetBeaconGroupID(p2p.NewGroupIDByShardID(0))
if *isExplorer {
switch *nodeType {
case "explorer":
currentNode.NodeConfig.SetRole(nodeconfig.ExplorerNode)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(*shardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(*shardID)))
} else {
if nodeConfig.ShardID == 0 {
case "validator":
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
if nodeConfig.ShardID == 0 {
currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
currentNode.NodeConfig.SetClientGroupID(p2p.GroupIDBeaconClient)
} else {
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
}
@ -395,6 +398,15 @@ func main() {
flag.Var(&utils.BootNodes, "bootnodes", "a list of bootnode multiaddress (delimited by ,)")
flag.Parse()
switch *nodeType {
case "validator":
case "explorer":
break
default:
fmt.Fprintf(os.Stderr, "Unknown node type: %s\n", *nodeType)
os.Exit(1)
}
nodeconfig.SetVersion(fmt.Sprintf("Harmony (C) 2019. %v, version %v-%v (%v %v)", path.Base(os.Args[0]), version, commit, builtBy, builtAt))
if *versionFlag {
printVersion()
@ -431,7 +443,7 @@ func main() {
memprofiling.MaybeCallGCPeriodically()
}
if !*isExplorer {
if *nodeType == "validator" {
setupInitialAccount()
}
@ -451,10 +463,7 @@ func main() {
go currentNode.SupportBeaconSyncing()
}
startMsg := "==== New Harmony Node ===="
if *isExplorer {
startMsg = "==== New Explorer Node ===="
}
startMsg := fmt.Sprintf("==== New %s Node ====", strings.Title(*nodeType))
utils.Logger().Info().
Str("BlsPubKey", hex.EncodeToString(nodeConfig.ConsensusPubKey.Serialize())).

@ -251,15 +251,20 @@ func (node *Node) SupportSyncing() {
node.InitSyncingServer()
node.StartSyncingServer()
joinConsensus := false
// Check if the current node is explorer node.
isExplorerNode := node.NodeConfig.Role() == nodeconfig.ExplorerNode
switch node.NodeConfig.Role() {
case nodeconfig.Validator:
joinConsensus = true
}
// Send new block to unsync node if the current node is not explorer node.
if !isExplorerNode {
// TODO: leo this pushing logic has to be removed
if joinConsensus {
go node.SendNewBlockToUnsync()
}
go node.DoSyncing(node.Blockchain(), node.Worker, !isExplorerNode)
go node.DoSyncing(node.Blockchain(), node.Worker, joinConsensus)
}
// InitSyncingServer starts downloader server.
@ -402,7 +407,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, in
return response, nil
} else if len(node.peerRegistrationRecord) >= maxBroadcastNodes {
response.Type = downloader_pb.DownloaderResponse_FAIL
utils.GetLogInstance().Warn("[SYNC] maximum registration limit exceeds", "ip", ip, "port", port)
utils.GetLogInstance().Debug("[SYNC] maximum registration limit exceeds", "ip", ip, "port", port)
return response, nil
} else {
response.Type = downloader_pb.DownloaderResponse_FAIL

@ -20,7 +20,7 @@
127.0.0.1 9103 validator one1p7ht2d4kl8ve7a8jxw746yfnx4wnfxtp8jqxwe ca86e551ee42adaaa6477322d7db869d3e203c00d7b86c82ebee629ad79cb6d57b8f3db28336778ec2180e56a8e07296
127.0.0.1 9104 validator one1z05g55zamqzfw9qs432n33gycdmyvs38xjemyl 95117937cd8c09acd2dfae847d74041a67834ea88662a7cbed1e170350bc329e53db151e5a0ef3e712e35287ae954818
127.0.0.1 9105 validator one1ljznytjyn269azvszjlcqvpcj6hjm822yrcp2e 68ae289d73332872ec8d04ac256ca0f5453c88ad392730c5741b6055bc3ec3d086ab03637713a29f459177aaa8340615
127.0.0.1 9107 validator one1uyshu2jgv8w465yc8kkny36thlt2wvel89tcmg 1c1fb28d2de96e82c3d9b4917eb54412517e2763112a3164862a6ed627ac62e87ce274bb4ea36e6a61fb66a15c263a06
127.0.0.1 9108 validator one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 b179c4fdc0bee7bd0b6698b792837dd13404d3f985b59d4a9b1cd0641a76651e271518b61abbb6fbebd4acf963358604
127.0.0.1 9107 validator one1uyshu2jgv8w465yc8kkny36thlt2wvel89tcmg a547a9bf6fdde4f4934cde21473748861a3cc0fe8bbb5e57225a29f483b05b72531f002f8187675743d819c955a86100
127.0.0.1 9108 validator one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 678ec9670899bf6af85b877058bea4fc1301a5a3a376987e826e3ca150b80e3eaadffedad0fedfa111576fa76ded980c
127.0.0.1 9109 validator one1658znfwf40epvy7e46cqrmzyy54h4n0qa73nep 576d3c48294e00d6be4a22b07b66a870ddee03052fe48a5abbd180222e5d5a1f8946a78d55b025de21635fd743bbad90
127.0.0.1 9110 validator one1d2rngmem4x2c6zxsjjz29dlah0jzkr0k2n88wc 16513c487a6bb76f37219f3c2927a4f281f9dd3fd6ed2e3a64e500de6545cf391dd973cc228d24f9bd01efe94912e714

@ -149,25 +149,21 @@ sleep 2
i=0
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode account blspub <<< $line
if [ "${mode}" == "explorer" ]
then
args=("${base_args[@]}" -ip "${ip}" -port "${port}" -key "/tmp/${ip}-${port}.key" -db_dir "db-${ip}-${port}")
else
if [ ! -e .hmy/${blspub}.key ]; then
echo "missing blskey .hmy/${blspub}.key"
echo "skipping this node"
if [[ -z "$ip" || -z "$port" ]]; then
echo "skip empty node"
continue
fi
args=("${base_args[@]}" -ip "${ip}" -port "${port}" -key "/tmp/${ip}-${port}.key" -db_dir "db-${ip}-${port}" -blskey_file ".hmy/${blspub}.key")
if [ ! -e .hmy/${blspub}.key ]; then
args=("${args[@]}" -blskey_file "BLSKEY")
else
args=("${args[@]}" -blskey_file ".hmy/${blspub}.key")
fi
case "${mode}" in
leader*|validator*) args=("${args[@]}");;
esac
case "${mode}" in leader*) args=("${args[@]}" -is_leader);; esac
case "${mode}" in *archival|archival) args=("${args[@]}" -is_archival);; esac
case "${mode}" in explorer*) args=("${args[@]}" -is_explorer=true -shard_id=0);; esac
case "${mode}" in explorer*) args=("${args[@]}" -node_type=explorer -shard_id=0);; esac
case "${mode}" in
client) ;;
*) $DRYRUN "${ROOT}/bin/harmony" "${args[@]}" "${extra_args[@]}" 2>&1 | tee -a "${LOG_FILE}" &;;

Loading…
Cancel
Save