// This needs to be executed after consensus and drand are setup
if!*isNewNode||*shardID>-1{// initial staking new node doesn't need to initialize shard state
currentNode.InitShardState(*shardID==-1&&!*isNewNode)// TODO: Have a better why to distinguish non-genesis node
@ -395,7 +388,15 @@ func main() {
// go currentNode.SupportBeaconSyncing()
//}
utils.GetLogInstance().Info("==== New Harmony Node ====","BlsPubKey",hex.EncodeToString(nodeConfig.ConsensusPubKey.Serialize()),"ShardID",nodeConfig.ShardID,"ShardGroupID",nodeConfig.GetShardGroupID(),"BeaconGroupID",nodeConfig.GetBeaconGroupID(),"ClientGroupID",nodeConfig.GetClientGroupID(),"Role",currentNode.NodeConfig.Role(),"multiaddress",fmt.Sprintf("/ip4/%s/tcp/%s/p2p/%s",*ip,*port,nodeConfig.Host.GetID().Pretty()))
utils.GetLogInstance().Info("==== New Harmony Node ====",
getLogger().Info("Somehow I got kicked out. Exiting")
os.Exit(8)// 8 represents it's a loop and the program restart itself
}
ifmyShardID!=uint32(math.MaxUint32){
// Update public keys
ss:=myShardState
publicKeys:=[]*bls.PublicKey{}
for_,nodeID:=rangess.NodeList{
key:=&bls.PublicKey{}
err:=key.Deserialize(nodeID.BlsPublicKey[:])
iferr!=nil{
utils.GetLogInstance().Error("Failed to deserialize BLS public key in shard state","error",err)
}
publicKeys=append(publicKeys,key)
myShardState:=shardState[myShardID]
// Update public keys
varpublicKeys[]*bls.PublicKey
foridx,nodeID:=rangemyShardState.NodeList{
key:=&bls.PublicKey{}
err:=key.Deserialize(nodeID.BlsPublicKey[:])
iferr!=nil{
getLogger().Error("Failed to deserialize BLS public key in shard state",
"idx",idx,
"error",err)
}
node.Consensus.UpdatePublicKeys(publicKeys)
node.DRand.UpdatePublicKeys(publicKeys)
publicKeys=append(publicKeys,key)
}
node.Consensus.UpdatePublicKeys(publicKeys)
node.DRand.UpdatePublicKeys(publicKeys)
aboutLeader:=""
ifnodeconfig.GetDefaultConfig().IsLeader(){
aboutLeader="I am not leader anymore"
ifisNextLeader{
aboutLeader="I am still leader"
}
}else{
aboutLeader="I am still validator"
ifisNextLeader{
aboutLeader="I become the leader"
}
ifnode.Blockchain().ShardID()==myShardID{
getLogger().Info("staying in the same shard")
}else{
getLogger().Info("moving to another shard")
iferr:=node.shardChains.Close();err!=nil{
getLogger().Error("cannot close shard chains","error",err)
}
ifnode.blockchain.ShardID()==myShardID{
utils.GetLogInstance().Info(fmt.Sprintf("[Resharded][epoch:%d] I stay at shard %d, %s",epoch,myShardID,aboutLeader),"BlsPubKey",hex.EncodeToString(myBlsPubKey))
}else{
utils.GetLogInstance().Info(fmt.Sprintf("[Resharded][epoch:%d] I got resharded to shard %d from shard %d, %s",epoch,myShardID,node.blockchain.ShardID(),aboutLeader),"BlsPubKey",hex.EncodeToString(myBlsPubKey))
node.storeEpochShardState(epochShardState)
restartProcess(getRestartArguments(myShardID))
}
}
execFile,err:=getBinaryPath()
iferr!=nil{
utils.GetLogInstance().Crit("Failed to get program path when restarting program","error",err,"file",execFile)
utils.GetLogInstance().Debug("PROPOSING NEW BLOCK ------------------------------------------------","blockNum",node.blockchain.CurrentBlock().NumberU64()+1,"threshold",threshold,"pendingTransactions",len(node.pendingTransactions))
utils.GetLogInstance().Debug("PROPOSING NEW BLOCK ------------------------------------------------","blockNum",node.Blockchain().CurrentBlock().NumberU64()+1,"threshold",threshold,"pendingTransactions",len(node.pendingTransactions))
utils.GetLogInstance().Debug("PROPOSING NEW BLOCK ------------------------------------------------","blockNum",node.Blockchain().CurrentBlock().NumberU64()+1,"threshold",threshold,"selectedTxs",len(selectedTxs))
utils.GetLogInstance().Debug("PROPOSING NEW BLOCK ------------------------------------------------","blockNum",node.blockchain.CurrentBlock().NumberU64()+1,"threshold",threshold,"selectedTxs",len(selectedTxs))
node.Worker.CommitTransactions(selectedTxs)
block,err:=node.Worker.Commit()
iferr!=nil{
utils.GetLogInstance().Debug("Failed committing new block","Error",err)
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot commit new block").
WithCause(err))
continue
}
ifnode.Consensus.ShardID==0{
// add new shard state if it's epoch block
// TODO: bug fix - the stored shard state between here and PostConsensusProcessing are different.
//node.addNewShardStateHash(block)
}
newBlock:=block
utils.GetLogInstance().Debug("Successfully proposed new block","blockNum",block.NumberU64(),"numTxs",block.Transactions().Len())