-
-func (n *Node) SyncManager() *netsync.SyncManager {
- return n.syncManager
-}
-
-/**bytomdRPCCheck Check if bytomd connection via RPC is correctly working*/
-func bytomdRPCCheck() bool {
- type Req struct {
- BlockHeight uint64 `json:"block_height"`
- }
- if util.ValidatePegin {
- for {
- resp, err := util.CallRPC("/get-merkle-proof", &Req{BlockHeight: 0})
- if err != nil {
- log.Error("Call mainchain interface get-block-header failed")
- time.Sleep(time.Millisecond * 1000)
- continue
- }
- tmp, _ := json.Marshal(resp)
- var blockHeader api.GetBlockHeaderResp
- json.Unmarshal(tmp, &blockHeader)
- hash := blockHeader.BlockHeader.Hash()
- if strings.Compare(consensus.ActiveNetParams.ParentGenesisBlockHash, hash.String()) != 0 {
- log.Error("Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?", consensus.ActiveNetParams.ParentGenesisBlockHash, ":", hash.String())
- return false
- }
- break
- }
- }
-
- return true
-}
-
-func initConsensusConfig(config *cfg.Config) {
- if config.ConsensusConfigFile == "" {
- // poa
- } else {
- //
- file, err := os.Open(config.ConsensusConfigFile)
- if err != nil {
- cmn.Exit(cmn.Fmt("Failed to read consensus file: %v", err))
- }
- defer file.Close()
-
- if err := json.NewDecoder(file).Decode(config); err != nil {
- cmn.Exit(cmn.Fmt("invalid consensus file: %v", err))
- }
-
- for _, v := range config.Consensus.SelfVoteSigners {
- address, err := common.DecodeAddress(v, &consensus.ActiveNetParams)
- if err != nil {
- cmn.Exit(cmn.Fmt("Address resolution failed: %v", err))
- }
- config.Consensus.Signers = append(config.Consensus.Signers, address)
- }
- }
-}
-
-func initDpos(chain *protocol.Chain, config *cfg.Config) {
- header := chain.BestBlockHeader()
- height := header.Height
- hash := header.Hash()
- maxSignerCount := config.Consensus.MaxSignerCount
- period := config.Consensus.Period
- if err := dpos.GDpos.Init(chain, maxSignerCount, period, height, hash); err != nil {
- cmn.Exit(cmn.Fmt("initVote: Dpos new: %v", err))
- }
-
- if height > 0 {
- oldBlockHeight := dpos.GDpos.GetOldBlockHeight()
- oldBlockHash := dpos.GDpos.GetOldBlockHash()
- if err := chain.RepairDPoSData(oldBlockHeight, oldBlockHash); err != nil {
- cmn.Exit(cmn.Fmt("initVote failed: %v", err))
- }
- }
-}