|
|
@ -10,17 +10,16 @@ import ( |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/bls/ffi/go/bls" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/utils/contract" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
"github.com/ethereum/go-ethereum/log" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/bls/ffi/go/bls" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/drand" |
|
|
|
"github.com/harmony-one/harmony/drand" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
"github.com/harmony-one/harmony/internal/profiler" |
|
|
|
"github.com/harmony-one/harmony/internal/profiler" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/utils/contract" |
|
|
|
"github.com/harmony-one/harmony/node" |
|
|
|
"github.com/harmony-one/harmony/node" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p/p2pimpl" |
|
|
|
"github.com/harmony-one/harmony/p2p/p2pimpl" |
|
|
@ -85,7 +84,9 @@ var ( |
|
|
|
keyFile = flag.String("key", "./.hmykey", "the private key file of the harmony node") |
|
|
|
keyFile = flag.String("key", "./.hmykey", "the private key file of the harmony node") |
|
|
|
// isBeacon indicates this node is a beacon chain node
|
|
|
|
// isBeacon indicates this node is a beacon chain node
|
|
|
|
isBeacon = flag.Bool("is_beacon", false, "true means this node is a beacon chain node") |
|
|
|
isBeacon = flag.Bool("is_beacon", false, "true means this node is a beacon chain node") |
|
|
|
// isNewNode indicates this node is a new node
|
|
|
|
// isArchival indicates this node is an archival node that will save and archive current blockchain
|
|
|
|
|
|
|
|
isArchival = flag.Bool("is_archival", false, "true means this node is a archival node") |
|
|
|
|
|
|
|
//isNewNode indicates this node is a new node
|
|
|
|
isNewNode = flag.Bool("is_newnode", false, "true means this node is a new node") |
|
|
|
isNewNode = flag.Bool("is_newnode", false, "true means this node is a new node") |
|
|
|
accountIndex = flag.Int("account_index", 0, "the index of the staking account to use") |
|
|
|
accountIndex = flag.Int("account_index", 0, "the index of the staking account to use") |
|
|
|
// isLeader indicates this node is a beacon chain leader node during the bootstrap process
|
|
|
|
// isLeader indicates this node is a beacon chain leader node during the bootstrap process
|
|
|
@ -171,6 +172,8 @@ func createGlobalConfig() *nodeconfig.ConfigType { |
|
|
|
if *isLeader { |
|
|
|
if *isLeader { |
|
|
|
nodeConfig.StringRole = "leader" |
|
|
|
nodeConfig.StringRole = "leader" |
|
|
|
nodeConfig.Leader = nodeConfig.SelfPeer |
|
|
|
nodeConfig.Leader = nodeConfig.SelfPeer |
|
|
|
|
|
|
|
} else if *isArchival { |
|
|
|
|
|
|
|
nodeConfig.StringRole = "archival" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
nodeConfig.StringRole = "validator" |
|
|
|
nodeConfig.StringRole = "validator" |
|
|
|
} |
|
|
|
} |
|
|
@ -188,6 +191,13 @@ func createGlobalConfig() *nodeconfig.ConfigType { |
|
|
|
return nodeConfig |
|
|
|
return nodeConfig |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func setupArchivalNode(nodeConfig *nodeconfig.ConfigType) (*node.Node, *nodeconfig.ConfigType) { |
|
|
|
|
|
|
|
currentNode := node.New(nodeConfig.Host, &consensus.Consensus{ShardID: uint32(0)}, nil) |
|
|
|
|
|
|
|
currentNode.NodeConfig.SetRole(nodeconfig.ArchivalNode) |
|
|
|
|
|
|
|
currentNode.AddBeaconChainDatabase(nodeConfig.BeaconDB) |
|
|
|
|
|
|
|
return currentNode, nodeConfig |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consensus, *node.Node) { |
|
|
|
func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consensus, *node.Node) { |
|
|
|
// Consensus object.
|
|
|
|
// Consensus object.
|
|
|
|
// TODO: consensus object shouldn't start here
|
|
|
|
// TODO: consensus object shouldn't start here
|
|
|
@ -251,11 +261,14 @@ func main() { |
|
|
|
flag.Parse() |
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
|
|
initSetup() |
|
|
|
initSetup() |
|
|
|
|
|
|
|
var currentNode *node.Node |
|
|
|
|
|
|
|
var consensus *consensus.Consensus |
|
|
|
nodeConfig := createGlobalConfig() |
|
|
|
nodeConfig := createGlobalConfig() |
|
|
|
|
|
|
|
if *isArchival { |
|
|
|
// Init logging.
|
|
|
|
currentNode, nodeConfig = setupArchivalNode(nodeConfig) |
|
|
|
loggingInit(*logFolder, nodeConfig.StringRole, *ip, *port, *onlyLogTps) |
|
|
|
loggingInit(*logFolder, nodeConfig.StringRole, *ip, *port, *onlyLogTps) |
|
|
|
|
|
|
|
go currentNode.DoBeaconSyncing() |
|
|
|
|
|
|
|
} else { |
|
|
|
// Start Profiler for leader if profile argument is on
|
|
|
|
// Start Profiler for leader if profile argument is on
|
|
|
|
if nodeConfig.StringRole == "leader" && (*profile || *metricsReportURL != "") { |
|
|
|
if nodeConfig.StringRole == "leader" && (*profile || *metricsReportURL != "") { |
|
|
|
prof := profiler.GetProfiler() |
|
|
|
prof := profiler.GetProfiler() |
|
|
@ -264,15 +277,15 @@ func main() { |
|
|
|
prof.Start() |
|
|
|
prof.Start() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
consensus, currentNode = setUpConsensusAndNode(nodeConfig) |
|
|
|
consensus, currentNode := setUpConsensusAndNode(nodeConfig) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if consensus.IsLeader { |
|
|
|
if consensus.IsLeader { |
|
|
|
go currentNode.SendPongMessage() |
|
|
|
go currentNode.SendPongMessage() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Init logging.
|
|
|
|
log.Info("New Harmony Node ====", "Role", currentNode.NodeConfig.Role(), "multiaddress", fmt.Sprintf("/ip4/%s/tcp/%s/p2p/%s", *ip, *port, nodeConfig.Host.GetID().Pretty())) |
|
|
|
loggingInit(*logFolder, nodeConfig.StringRole, *ip, *port, *onlyLogTps) |
|
|
|
go currentNode.SupportSyncing() |
|
|
|
go currentNode.SupportSyncing() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Info("New Harmony Node ====", "Role", currentNode.NodeConfig.Role(), "multiaddress", fmt.Sprintf("/ip4/%s/tcp/%s/p2p/%s", *ip, *port, nodeConfig.Host.GetID().Pretty())) |
|
|
|
currentNode.ServiceManagerSetup() |
|
|
|
currentNode.ServiceManagerSetup() |
|
|
|
currentNode.RunServices() |
|
|
|
currentNode.RunServices() |
|
|
|
currentNode.StartServer() |
|
|
|
currentNode.StartServer() |
|
|
|