@ -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,28 +261,31 @@ 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 ( )
// Start Profiler for leader if profile argument is on
} else {
if nodeConfig . StringRole == "leader" && ( * profile || * metricsReportURL != "" ) {
// Start Profiler for leader if profile argument is on
prof := profiler . GetProfiler ( )
if nodeConfig . StringRole == "leader" && ( * profile || * metricsReportURL != "" ) {
prof . Config ( nodeConfig . ShardIDString , * metricsReportURL )
prof := profiler . GetProfiler ( )
if * profile {
prof . Config ( nodeConfig . ShardIDString , * metricsReportURL )
prof . Start ( )
if * profile {
prof . Start ( )
}
}
}
consensus , currentNode = setUpConsensusAndNode ( nodeConfig )
if consensus . IsLeader {
go currentNode . SendPongMessage ( )
}
// Init logging.
loggingInit ( * logFolder , nodeConfig . StringRole , * ip , * port , * onlyLogTps )
go currentNode . SupportSyncing ( )
}
}
consensus , currentNode := setUpConsensusAndNode ( nodeConfig )
if consensus . IsLeader {
go currentNode . SendPongMessage ( )
}
log . Info ( "New Harmony Node ====" , "Role" , currentNode . NodeConfig . Role ( ) , "multiaddress" , fmt . Sprintf ( "/ip4/%s/tcp/%s/p2p/%s" , * ip , * port , nodeConfig . Host . GetID ( ) . Pretty ( ) ) )
log . Info ( "New Harmony Node ====" , "Role" , currentNode . NodeConfig . Role ( ) , "multiaddress" , fmt . Sprintf ( "/ip4/%s/tcp/%s/p2p/%s" , * ip , * port , nodeConfig . Host . GetID ( ) . Pretty ( ) ) )
go currentNode . SupportSyncing ( )
currentNode . ServiceManagerSetup ( )
currentNode . ServiceManagerSetup ( )
currentNode . RunServices ( )
currentNode . RunServices ( )
currentNode . StartServer ( )
currentNode . StartServer ( )