|
|
@ -114,7 +114,6 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
ks *keystore.KeyStore |
|
|
|
ks *keystore.KeyStore |
|
|
|
genesisAccount *genesis.DeployAccount |
|
|
|
genesisAccount *genesis.DeployAccount |
|
|
|
accountIndex int |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// logging verbosity
|
|
|
|
// logging verbosity
|
|
|
|
verbosity = flag.Int("verbosity", 5, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 5)") |
|
|
|
verbosity = flag.Int("verbosity", 5, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 5)") |
|
|
@ -127,14 +126,7 @@ var ( |
|
|
|
"Do not propose view change (testing only)") |
|
|
|
"Do not propose view change (testing only)") |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func initSetup() { |
|
|
|
func initSetup() (bool, uint32) { |
|
|
|
flag.Var(&utils.BootNodes, "bootnodes", "a list of bootnode multiaddress (delimited by ,)") |
|
|
|
|
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// maybe request passphrase for bls key.
|
|
|
|
// maybe request passphrase for bls key.
|
|
|
|
passphraseForBls() |
|
|
|
passphraseForBls() |
|
|
@ -173,8 +165,10 @@ func initSetup() { |
|
|
|
utils.BootNodes = bootNodeAddrs |
|
|
|
utils.BootNodes = bootNodeAddrs |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var isLeader bool |
|
|
|
|
|
|
|
var sid uint32 |
|
|
|
if !*isExplorer { // Explorer node doesn't need the following setup
|
|
|
|
if !*isExplorer { // Explorer node doesn't need the following setup
|
|
|
|
setupECDSAKeys() |
|
|
|
isLeader, sid = setupECDSAKeys() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
genesisAccount = &genesis.DeployAccount{} |
|
|
|
genesisAccount = &genesis.DeployAccount{} |
|
|
|
genesisAccount.ShardID = uint32(*shardID) |
|
|
|
genesisAccount.ShardID = uint32(*shardID) |
|
|
@ -184,6 +178,7 @@ func initSetup() { |
|
|
|
if *enableGC { |
|
|
|
if *enableGC { |
|
|
|
memprofiling.MaybeCallGCPeriodically() |
|
|
|
memprofiling.MaybeCallGCPeriodically() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return isLeader, sid |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func passphraseForBls() { |
|
|
|
func passphraseForBls() { |
|
|
@ -200,19 +195,20 @@ func passphraseForBls() { |
|
|
|
blsPassphrase = passphrase |
|
|
|
blsPassphrase = passphrase |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setupECDSAKeys() { |
|
|
|
func setupECDSAKeys() (bool, uint32) { |
|
|
|
ks = hmykey.GetHmyKeyStore() |
|
|
|
ks = hmykey.GetHmyKeyStore() |
|
|
|
|
|
|
|
|
|
|
|
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch)) |
|
|
|
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch)) |
|
|
|
pubKey := setUpConsensusKeyAndReturnIndex(nodeconfig.GetDefaultConfig()) |
|
|
|
pubKey := setUpConsensusKeyAndReturnIndex(nodeconfig.GetDefaultConfig()) |
|
|
|
|
|
|
|
|
|
|
|
index, genesisAccount := genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr()) |
|
|
|
var index int |
|
|
|
|
|
|
|
index, genesisAccount = genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr()) |
|
|
|
if index < 0 { |
|
|
|
if index < 0 { |
|
|
|
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr()) |
|
|
|
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr()) |
|
|
|
os.Exit(100) |
|
|
|
os.Exit(100) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
genesisAccount.ShardID = uint32(accountIndex) % genesisShardingConfig.NumShards() |
|
|
|
genesisAccount.ShardID = uint32(index) % genesisShardingConfig.NumShards() |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("My Genesis Account: %v\n", *genesisAccount) |
|
|
|
fmt.Printf("My Genesis Account: %v\n", *genesisAccount) |
|
|
|
|
|
|
|
|
|
|
@ -220,6 +216,7 @@ func setupECDSAKeys() { |
|
|
|
if *enableGC { |
|
|
|
if *enableGC { |
|
|
|
memprofiling.MaybeCallGCPeriodically() |
|
|
|
memprofiling.MaybeCallGCPeriodically() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return index < int(genesisShardingConfig.NumShards()), genesisAccount.ShardID |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey { |
|
|
|
func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey { |
|
|
@ -239,7 +236,7 @@ func setUpConsensusKeyAndReturnIndex(nodeConfig *nodeconfig.ConfigType) *bls.Pub |
|
|
|
return pubKey |
|
|
|
return pubKey |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func createGlobalConfig() *nodeconfig.ConfigType { |
|
|
|
func createGlobalConfig(isLeader bool, sid uint32) *nodeconfig.ConfigType { |
|
|
|
var err error |
|
|
|
var err error |
|
|
|
var myShardID uint32 |
|
|
|
var myShardID uint32 |
|
|
|
|
|
|
|
|
|
|
@ -248,12 +245,12 @@ func createGlobalConfig() *nodeconfig.ConfigType { |
|
|
|
if !*isExplorer { |
|
|
|
if !*isExplorer { |
|
|
|
// Specified Shard ID override calculated Shard ID
|
|
|
|
// Specified Shard ID override calculated Shard ID
|
|
|
|
if *shardID >= 0 { |
|
|
|
if *shardID >= 0 { |
|
|
|
utils.GetLogInstance().Info("ShardID Override", "original", genesisAccount.ShardID, "override", *shardID) |
|
|
|
utils.GetLogInstance().Info("ShardID Override", "original", sid, "override", *shardID) |
|
|
|
genesisAccount.ShardID = uint32(*shardID) |
|
|
|
genesisAccount.ShardID = uint32(*shardID) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !*isNewNode { |
|
|
|
if !*isNewNode { |
|
|
|
nodeConfig = nodeconfig.GetShardConfig(uint32(genesisAccount.ShardID)) |
|
|
|
nodeConfig = nodeconfig.GetShardConfig(sid) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
myShardID = 0 // This should be default value as new node doesn't belong to any shard.
|
|
|
|
myShardID = 0 // This should be default value as new node doesn't belong to any shard.
|
|
|
|
if *shardID >= 0 { |
|
|
|
if *shardID >= 0 { |
|
|
@ -290,9 +287,7 @@ func createGlobalConfig() *nodeconfig.ConfigType { |
|
|
|
|
|
|
|
|
|
|
|
nodeConfig.SelfPeer = p2p.Peer{IP: *ip, Port: *port, ConsensusPubKey: nodeConfig.ConsensusPubKey} |
|
|
|
nodeConfig.SelfPeer = p2p.Peer{IP: *ip, Port: *port, ConsensusPubKey: nodeConfig.ConsensusPubKey} |
|
|
|
|
|
|
|
|
|
|
|
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch)) |
|
|
|
if isLeader && !*isExplorer && !*leaderOverride { // The first node in a shard is the leader at genesis
|
|
|
|
genesisShardNum := int(genesisShardingConfig.NumShards()) |
|
|
|
|
|
|
|
if accountIndex < genesisShardNum && !*isExplorer && !*leaderOverride { // The first node in a shard is the leader at genesis
|
|
|
|
|
|
|
|
nodeConfig.Leader = nodeConfig.SelfPeer |
|
|
|
nodeConfig.Leader = nodeConfig.SelfPeer |
|
|
|
nodeConfig.StringRole = "leader" |
|
|
|
nodeConfig.StringRole = "leader" |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -454,7 +449,14 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
initSetup() |
|
|
|
flag.Var(&utils.BootNodes, "bootnodes", "a list of bootnode multiaddress (delimited by ,)") |
|
|
|
|
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch *networkType { |
|
|
|
switch *networkType { |
|
|
|
case nodeconfig.Mainnet: |
|
|
|
case nodeconfig.Mainnet: |
|
|
|
core.ShardingSchedule = shardingconfig.MainnetSchedule |
|
|
|
core.ShardingSchedule = shardingconfig.MainnetSchedule |
|
|
@ -473,7 +475,8 @@ func main() { |
|
|
|
} |
|
|
|
} |
|
|
|
core.ShardingSchedule = shardingconfig.NewFixedSchedule(devnetConfig) |
|
|
|
core.ShardingSchedule = shardingconfig.NewFixedSchedule(devnetConfig) |
|
|
|
} |
|
|
|
} |
|
|
|
nodeConfig := createGlobalConfig() |
|
|
|
isLeader, sid := initSetup() |
|
|
|
|
|
|
|
nodeConfig := createGlobalConfig(isLeader, sid) |
|
|
|
|
|
|
|
|
|
|
|
// 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 != "") { |
|
|
|