diff --git a/consensus/vbft/event_timer.go b/consensus/vbft/event_timer.go index 718906dc7..9a02d07de 100644 --- a/consensus/vbft/event_timer.go +++ b/consensus/vbft/event_timer.go @@ -19,8 +19,6 @@ package vbft import ( - "container/heap" - "fmt" "math/rand" "sync" "sync/atomic" @@ -79,17 +77,14 @@ type EventTimer struct { // peer heartbeat tickers peerTickers map[uint32]*time.Timer - // other timers - normalTimers map[uint32]*time.Timer } func NewEventTimer(server *Server) *EventTimer { timer := &EventTimer{ - server: server, - C: make(chan *TimerEvent, 64), - eventTimers: make(map[TimerEventType]perBlockTimer), - peerTickers: make(map[uint32]*time.Timer), - normalTimers: make(map[uint32]*time.Timer), + server: server, + C: make(chan *TimerEvent, 64), + eventTimers: make(map[TimerEventType]perBlockTimer), + peerTickers: make(map[uint32]*time.Timer), } for i := 0; i < int(EventMax); i++ { @@ -114,42 +109,6 @@ func (self *EventTimer) stop() { stopAllTimers(self.eventTimers[TimerEventType(i)]) self.eventTimers[TimerEventType(i)] = make(map[uint32]*time.Timer) } - - // clear normal timers - stopAllTimers(self.normalTimers) - self.normalTimers = make(map[uint32]*time.Timer) -} - -func (self *EventTimer) StartTimer(Idx uint32, timeout time.Duration) { - self.lock.Lock() - defer self.lock.Unlock() - - if t, present := self.normalTimers[Idx]; present { - t.Stop() - log.Infof("timer for %d got reset", Idx) - } - - self.normalTimers[Idx] = time.AfterFunc(timeout, func() { - // remove timer from map - self.lock.Lock() - defer self.lock.Unlock() - delete(self.normalTimers, Idx) - - self.C <- &TimerEvent{ - evtType: EventMax, - blockNum: Idx, - } - }) -} - -func (self *EventTimer) CancelTimer(idx uint32) { - self.lock.Lock() - defer self.lock.Unlock() - - if t, present := self.normalTimers[idx]; present { - t.Stop() - delete(self.normalTimers, idx) - } } func (self *EventTimer) getEventTimeout(evtType TimerEventType) time.Duration { @@ -180,15 +139,13 @@ func (self *EventTimer) getEventTimeout(evtType TimerEventType) time.Duration { return time.Duration(txPooltimeout) case EventTxBlockTimeout: return time.Duration(atomic.LoadInt64(&zeroTxBlockTimeout)) + default: + panic("unknown timer event type") } - - return 0 } -// // internal helper, should call with lock held -// -func (self *EventTimer) startEventTimer(evtType TimerEventType, blockNum uint32) error { +func (self *EventTimer) startEventTimer(evtType TimerEventType, blockNum uint32) { timers := self.eventTimers[evtType] if t, present := timers[blockNum]; present { t.Stop() @@ -198,8 +155,8 @@ func (self *EventTimer) startEventTimer(evtType TimerEventType, blockNum uint32) timeout := self.getEventTimeout(evtType) if timeout == 0 { - log.Errorf("invalid timeout for event %d, blkNum %d", evtType, blockNum) - return fmt.Errorf("invalid timeout for event %d, blkNum %d", evtType, blockNum) + // never happen when config correctly + timeout = time.Second } timers[blockNum] = time.AfterFunc(timeout, func() { self.C <- &TimerEvent{ @@ -207,12 +164,9 @@ func (self *EventTimer) startEventTimer(evtType TimerEventType, blockNum uint32) blockNum: blockNum, } }) - return nil } -// // internal helper, should call with lock held -// func (self *EventTimer) cancelEventTimer(evtType TimerEventType, blockNum uint32) { timers := self.eventTimers[evtType] @@ -222,12 +176,12 @@ func (self *EventTimer) cancelEventTimer(evtType TimerEventType, blockNum uint32 } } -func (self *EventTimer) StartProposalTimer(blockNum uint32) error { +func (self *EventTimer) StartProposalTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() log.Infof("server %d started proposal timer for blk %d", self.server.Index, blockNum) - return self.startEventTimer(EventProposeBlockTimeout, blockNum) + self.startEventTimer(EventProposeBlockTimeout, blockNum) } func (self *EventTimer) CancelProposalTimer(blockNum uint32) { @@ -237,12 +191,12 @@ func (self *EventTimer) CancelProposalTimer(blockNum uint32) { self.cancelEventTimer(EventProposeBlockTimeout, blockNum) } -func (self *EventTimer) StartEndorsingTimer(blockNum uint32) error { +func (self *EventTimer) StartEndorsingTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() log.Infof("server %d started endorsing timer for blk %d", self.server.Index, blockNum) - return self.startEventTimer(EventEndorseBlockTimeout, blockNum) + self.startEventTimer(EventEndorseBlockTimeout, blockNum) } func (self *EventTimer) CancelEndorseMsgTimer(blockNum uint32) { @@ -252,12 +206,12 @@ func (self *EventTimer) CancelEndorseMsgTimer(blockNum uint32) { self.cancelEventTimer(EventEndorseBlockTimeout, blockNum) } -func (self *EventTimer) StartEndorseEmptyBlockTimer(blockNum uint32) error { +func (self *EventTimer) StartEndorseEmptyBlockTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() log.Infof("server %d started empty endorsing timer for blk %d", self.server.Index, blockNum) - return self.startEventTimer(EventEndorseEmptyBlockTimeout, blockNum) + self.startEventTimer(EventEndorseEmptyBlockTimeout, blockNum) } func (self *EventTimer) CancelEndorseEmptyBlockTimer(blockNum uint32) { @@ -267,12 +221,12 @@ func (self *EventTimer) CancelEndorseEmptyBlockTimer(blockNum uint32) { self.cancelEventTimer(EventEndorseEmptyBlockTimeout, blockNum) } -func (self *EventTimer) StartCommitTimer(blockNum uint32) error { +func (self *EventTimer) StartCommitTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() log.Infof("server %d started commit timer for blk %d", self.server.Index, blockNum) - return self.startEventTimer(EventCommitBlockTimeout, blockNum) + self.startEventTimer(EventCommitBlockTimeout, blockNum) } func (self *EventTimer) CancelCommitMsgTimer(blockNum uint32) { @@ -282,11 +236,11 @@ func (self *EventTimer) CancelCommitMsgTimer(blockNum uint32) { self.cancelEventTimer(EventCommitBlockTimeout, blockNum) } -func (self *EventTimer) StartProposalBackoffTimer(blockNum uint32) error { +func (self *EventTimer) StartProposalBackoffTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() - return self.startEventTimer(EventProposalBackoff, blockNum) + self.startEventTimer(EventProposalBackoff, blockNum) } func (self *EventTimer) CancelProposalBackoffTimer(blockNum uint32) { @@ -296,11 +250,11 @@ func (self *EventTimer) CancelProposalBackoffTimer(blockNum uint32) { self.cancelEventTimer(EventProposalBackoff, blockNum) } -func (self *EventTimer) StartBackoffTimer(blockNum uint32) error { +func (self *EventTimer) StartBackoffTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() - return self.startEventTimer(EventRandomBackoff, blockNum) + self.startEventTimer(EventRandomBackoff, blockNum) } func (self *EventTimer) CancelBackoffTimer(blockNum uint32) { @@ -310,11 +264,11 @@ func (self *EventTimer) CancelBackoffTimer(blockNum uint32) { self.cancelEventTimer(EventRandomBackoff, blockNum) } -func (self *EventTimer) Start2ndProposalTimer(blockNum uint32) error { +func (self *EventTimer) Start2ndProposalTimer(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() - return self.startEventTimer(EventPropose2ndBlockTimeout, blockNum) + self.startEventTimer(EventPropose2ndBlockTimeout, blockNum) } func (self *EventTimer) Cancel2ndProposalTimer(blockNum uint32) { @@ -334,11 +288,11 @@ func (self *EventTimer) onBlockSealed(blockNum uint32) { } } -func (self *EventTimer) StartTxBlockTimeout(blockNum uint32) error { +func (self *EventTimer) StartTxBlockTimeout(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() - return self.startEventTimer(EventTxBlockTimeout, blockNum) + self.startEventTimer(EventTxBlockTimeout, blockNum) } func (self *EventTimer) CancelTxBlockTimeout(blockNum uint32) { @@ -348,7 +302,7 @@ func (self *EventTimer) CancelTxBlockTimeout(blockNum uint32) { self.cancelEventTimer(EventTxBlockTimeout, blockNum) } -func (self *EventTimer) startPeerTicker(peerIdx uint32) error { +func (self *EventTimer) startPeerTicker(peerIdx uint32) { self.lock.Lock() defer self.lock.Unlock() @@ -365,11 +319,9 @@ func (self *EventTimer) startPeerTicker(peerIdx uint32) error { } self.peerTickers[peerIdx].Reset(timeout) }) - - return nil } -func (self *EventTimer) stopPeerTicker(peerIdx uint32) error { +func (self *EventTimer) stopPeerTicker(peerIdx uint32) { self.lock.Lock() defer self.lock.Unlock() @@ -377,67 +329,18 @@ func (self *EventTimer) stopPeerTicker(peerIdx uint32) error { p.Stop() delete(self.peerTickers, peerIdx) } - return nil } -func (self *EventTimer) startTxTicker(blockNum uint32) error { +func (self *EventTimer) startTxPoolTicker(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() - return self.startEventTimer(EventTxPool, blockNum) + self.startEventTimer(EventTxPool, blockNum) } -func (self *EventTimer) stopTxTicker(blockNum uint32) { +func (self *EventTimer) stopTxPoolTicker(blockNum uint32) { self.lock.Lock() defer self.lock.Unlock() self.cancelEventTimer(EventTxPool, blockNum) } - -/////////////////////////////////////////////////////////// -// -// timer queue -// -/////////////////////////////////////////////////////////// - -type TimerItem struct { - due time.Time - evt *TimerEvent - index int -} - -type TimerQueue []*TimerItem - -func (tq TimerQueue) Len() int { - return len(tq) -} - -func (tq TimerQueue) Less(i, j int) bool { - return tq[j].due.After(tq[i].due) -} - -func (tq TimerQueue) Swap(i, j int) { - tq[i], tq[j] = tq[j], tq[i] - tq[i].index = i - tq[j].index = j -} - -func (tq *TimerQueue) Push(x interface{}) { - item := x.(*TimerItem) - item.index = len(*tq) - *tq = append(*tq, item) -} - -func (tq *TimerQueue) Pop() interface{} { - old := *tq - n := len(old) - item := old[n-1] - item.index = -1 - *tq = old[0 : n-1] - return item -} - -func (tq *TimerQueue) update(item *TimerItem, due time.Time) { - item.due = due - heap.Fix(tq, item.index) -} diff --git a/consensus/vbft/event_timer_test.go b/consensus/vbft/event_timer_test.go index 1b6a44e4a..4cab6704a 100644 --- a/consensus/vbft/event_timer_test.go +++ b/consensus/vbft/event_timer_test.go @@ -25,25 +25,13 @@ func constructEventTimer() *EventTimer { return NewEventTimer(server) } -func TestStartTimer(t *testing.T) { - eventtimer := constructEventTimer() - eventtimer.StartTimer(1, 10) -} - -func TestCancelTimer(t *testing.T) { - eventtimer := constructEventTimer() - eventtimer.StartTimer(1, 10) - eventtimer.CancelTimer(1) -} func TestStartEventTimer(t *testing.T) { eventtimer := constructEventTimer() - err := eventtimer.startEventTimer(EventProposeBlockTimeout, 1) - t.Logf("TestStartEventTimer: %v", err) + eventtimer.startEventTimer(EventProposeBlockTimeout, 1) } func TestCancelEventTimer(t *testing.T) { eventtimer := constructEventTimer() - err := eventtimer.startEventTimer(EventProposeBlockTimeout, 1) - t.Logf("startEventTimer: %v", err) + eventtimer.startEventTimer(EventProposeBlockTimeout, 1) eventtimer.cancelEventTimer(EventProposeBlockTimeout, 1) } diff --git a/consensus/vbft/service.go b/consensus/vbft/service.go index 37f3de052..81ff6d21f 100644 --- a/consensus/vbft/service.go +++ b/consensus/vbft/service.go @@ -339,7 +339,7 @@ func (self *Server) nonConsensusNode() bool { return self.Index == math.MaxUint32 } -//updateChainCofig +// updateChainCofig func (self *Server) updateChainConfig() error { block, _ := self.blockPool.getSealedBlock(self.GetCompletedBlockNum()) if block == nil { @@ -553,9 +553,7 @@ func (self *Server) stop() { self.peerPool.clean() } -// // go routine per net connection -// func (self *Server) run(peerPubKey keypair.PublicKey) error { peerID := vconfig.PubkeyID(peerPubKey) peerIdx, present := self.peerPool.GetPeerIndex(peerID) @@ -726,14 +724,8 @@ func (self *Server) startNewRound() error { self.processProposalMsg(proposal) return nil } - if err := self.timer.startTxTicker(blkNum); err != nil { - log.Errorf("startxticker blk:%d,err:%s", blkNum, err) - return err - } - if err := self.timer.StartTxBlockTimeout(blkNum); err != nil { - log.Errorf("starttxblocktimeout blk:%d,err:%s", blkNum, err) - return err - } + self.timer.startTxPoolTicker(blkNum) + self.timer.StartTxBlockTimeout(blkNum) return nil } @@ -749,16 +741,11 @@ func (self *Server) startNewProposal(blkNum uint32) { } } else if self.is2ndProposer(blkNum, self.Index) { log.Infof("server %d, 2nd proposer for block %d", self.Index, blkNum) - if err := self.timer.StartProposalBackoffTimer(blkNum); err != nil { - log.Errorf("server %d, startproposalbackofftimer for block %d err:%s", self.Index, blkNum, err) - } + self.timer.StartProposalBackoffTimer(blkNum) } // TODO: if new round block proposal has received, go endorsing/committing directly - - if err := self.timer.StartProposalTimer(blkNum); err != nil { - log.Errorf("server %d, startnewproposal for block %d err:%s", self.Index, blkNum, err) - } + self.timer.StartProposalTimer(blkNum) } // verify consensus messsage, then send msg to processMsgEvent @@ -1293,10 +1280,7 @@ func (self *Server) processMsgEvent() error { // if had committed for current round, skip the following steps if self.blockPool.committedForBlock(msgBlkNum) { // get more endorse msg after committed, trigger seal-block-timeout - if err := self.timer.StartCommitTimer(msgBlkNum); err != nil { - log.Errorf("server %d start commit timer for %d(%d), block %d, err: %s", - self.Index, pMsg.Endorser, pMsg.EndorsedProposer, msgBlkNum, err) - } + self.timer.StartCommitTimer(msgBlkNum) return nil } @@ -1526,9 +1510,7 @@ func (self *Server) actionLoop() { if proposal == nil { log.Infof("server %d fastforward stopped at blk %d, no proposal", self.Index, blkNum) self.fetchProposal(blkNum, proposer) - if err := self.timer.StartCommitTimer(blkNum); err != nil { - log.Errorf("server %d fastforward startcommittimer at blk %d, err:%s", self.Index, blkNum, err) - } + self.timer.StartCommitTimer(blkNum) break } @@ -1615,9 +1597,7 @@ func (self *Server) actionLoop() { if proposal == nil { self.fetchProposal(blkNum, proposer) // restart endorsing timer - if err := self.timer.StartEndorsingTimer(blkNum); err != nil { - log.Errorf("server %d endorse %d done, startendorsingtimer err:%s", self.Index, blkNum, err) - } + self.timer.StartEndorsingTimer(blkNum) log.Errorf("server %d endorse %d done, but no proposal", self.Index, blkNum) } else if err := self.makeCommitment(proposal, blkNum, forEmpty); err != nil { log.Errorf("server %d failed to commit block %d on rebroadcasting: %s", @@ -1744,16 +1724,12 @@ func (self *Server) processTimerEvent(evt *TimerEvent) error { if proposal == nil { self.fetchProposal(evt.blockNum, proposer) // restart endorsing timer - if err := self.timer.StartEndorsingTimer(evt.blockNum); err != nil { - log.Errorf("endorse %d done,fetchproposal startendorsingtimer err:%s", evt.blockNum, err) - } + self.timer.StartEndorsingTimer(evt.blockNum) return fmt.Errorf("endorse %d done, but no proposal available", evt.blockNum) } if err := self.verifyPrevBlockHash(evt.blockNum, proposal); err != nil { // restart endorsing timer - if errinfo := self.timer.StartEndorsingTimer(evt.blockNum); errinfo != nil { - log.Errorf("endorse %d done,verifyprevblockhash, startendorsingtimer err:%s", evt.blockNum, errinfo) - } + self.timer.StartEndorsingTimer(evt.blockNum) return fmt.Errorf("endorse %d done, but prev blk hash inconsistency: %s", evt.blockNum, err) } if err := self.makeCommitment(proposal, evt.blockNum, forEmpty); err != nil { @@ -1802,9 +1778,7 @@ func (self *Server) processTimerEvent(evt *TimerEvent) error { if proposal == nil { self.fetchProposal(evt.blockNum, proposer) // restart timer - if err := self.timer.StartEndorseEmptyBlockTimer(evt.blockNum); err != nil { - return fmt.Errorf("failed to startendorseemptyblocktimer block %d err:%s", evt.blockNum, err) - } + self.timer.StartEndorseEmptyBlockTimer(evt.blockNum) } else if err := self.makeCommitment(proposal, evt.blockNum, forEmpty); err != nil { return fmt.Errorf("failed to endorse for block %d on empty endorse timeout: %s", evt.blockNum, err) } @@ -1820,9 +1794,7 @@ func (self *Server) processTimerEvent(evt *TimerEvent) error { } } } else { - if err := self.timer.StartEndorseEmptyBlockTimer(evt.blockNum); err != nil { - return fmt.Errorf("failed to endorse block proposal (%d): StartEndorseEmptyBlockTimer err: %s", evt.blockNum, err) - } + self.timer.StartEndorseEmptyBlockTimer(evt.blockNum) } } return nil @@ -1863,7 +1835,7 @@ func (self *Server) processTimerEvent(evt *TimerEvent) error { self.heartbeat() case EventTxPool: - self.timer.stopTxTicker(evt.blockNum) + self.timer.stopTxPoolTicker(evt.blockNum) if self.GetCompletedBlockNum()+1 == evt.blockNum { validHeight := self.validHeight(evt.blockNum) newProposal := false @@ -1879,13 +1851,13 @@ func (self *Server) processTimerEvent(evt *TimerEvent) error { self.startNewProposal(evt.blockNum) } else { //reset timer, continue waiting txs from txnpool - self.timer.startTxTicker(evt.blockNum) + self.timer.startTxPoolTicker(evt.blockNum) } } else { - self.timer.startTxTicker(evt.blockNum) + self.timer.startTxPoolTicker(evt.blockNum) } case EventTxBlockTimeout: - self.timer.stopTxTicker(evt.blockNum) + self.timer.stopTxPoolTicker(evt.blockNum) self.timer.CancelTxBlockTimeout(evt.blockNum) self.startNewProposal(evt.blockNum) } @@ -1969,14 +1941,9 @@ func (self *Server) endorseBlock(proposal *blockProposalMsg, forEmpty bool) erro // start endorsing timer // TODO: endorsing may have reached consensus before received proposal, handle this if !forEmpty { - if err := self.timer.StartEndorsingTimer(blkNum); err != nil { - log.Errorf("endorseblock blk:%d,startendorsingtimer err:%s", blkNum, err) - return fmt.Errorf("endorseblock blk:%d,startendorsingkimer err:%s", blkNum, err) - } + self.timer.StartEndorsingTimer(blkNum) } else { - if err := self.timer.StartEndorseEmptyBlockTimer(blkNum); err != nil { - return fmt.Errorf("endorseBlock blk:%d,forEmpty:%v,StartEndorsingTimer err:%s", blkNum, forEmpty, err) - } + self.timer.StartEndorseEmptyBlockTimer(blkNum) } return nil @@ -2036,16 +2003,12 @@ func (self *Server) commitBlock(proposal *blockProposalMsg, forEmpty bool) error // start commit timer // TODO: committing may have reached consensus before received endorsement, handle this - if err := self.timer.StartCommitTimer(blkNum); err != nil { - return fmt.Errorf("commitBlock startcommittimer err: %s", err) - } + self.timer.StartCommitTimer(blkNum) return nil } -// // Note: sealProposal updates self.currentBlockNum, make sure not concurrency // (only called by sealProposal action) -// func (self *Server) sealProposal(proposal *blockProposalMsg, empty bool) error { // for each round, we can only seal one block if err := self.sealBlock(proposal.Block, empty, true); err != nil { @@ -2152,7 +2115,7 @@ func (self *Server) msgSendLoop() { } } -//creategovernaceTransaction invoke governance native contract commit_pos +// creategovernaceTransaction invoke governance native contract commit_pos func (self *Server) creategovernaceTransaction(blkNum uint32) (*types.Transaction, error) { mutable := utils.BuildNativeTransaction(nutils.GovernanceContractAddress, gover.COMMIT_DPOS, []byte{}) mutable.Nonce = blkNum @@ -2160,7 +2123,7 @@ func (self *Server) creategovernaceTransaction(blkNum uint32) (*types.Transactio return tx, err } -//checkNeedUpdateChainConfig use blockcount +// checkNeedUpdateChainConfig use blockcount func (self *Server) checkNeedUpdateChainConfig(blockNum uint32) bool { prevBlk, _ := self.blockPool.getSealedBlock(blockNum - 1) if prevBlk == nil { @@ -2174,7 +2137,7 @@ func (self *Server) checkNeedUpdateChainConfig(blockNum uint32) bool { return false } -//checkUpdateChainConfig query leveldb check is force update +// checkUpdateChainConfig query leveldb check is force update func (self *Server) checkUpdateChainConfig(blkNum uint32) bool { force, err := isUpdate(self.blockPool.getExecWriteSet(blkNum-1), self.GetChainConfig().View) if err != nil { @@ -2351,9 +2314,7 @@ func (self *Server) handleProposalTimeout(evt *TimerEvent) error { switch evt.evtType { case EventProposeBlockTimeout: - if err := self.timer.StartBackoffTimer(evt.blockNum); err != nil { - return fmt.Errorf("failed to blk:%d, startbackofftimer err: %s", evt.blockNum, err) - } + self.timer.StartBackoffTimer(evt.blockNum) log.Infof("server %d started backoff timer for blk %d", self.Index, evt.blockNum) return nil case EventRandomBackoff: @@ -2361,9 +2322,7 @@ func (self *Server) handleProposalTimeout(evt *TimerEvent) error { if err := self.makeProposal(evt.blockNum, true); err != nil { return fmt.Errorf("failed to propose empty block: %s", err) } - if err := self.timer.Start2ndProposalTimer(evt.blockNum); err != nil { - return fmt.Errorf("failed to propose start2ndproposaltimer err:%s", err) - } + self.timer.Start2ndProposalTimer(evt.blockNum) log.Infof("server %d proposed empty block for blk %d", self.Index, evt.blockNum) } return nil diff --git a/consensus/vbft/state_mgmt.go b/consensus/vbft/state_mgmt.go index 0139a0b67..2bf6b15ee 100644 --- a/consensus/vbft/state_mgmt.go +++ b/consensus/vbft/state_mgmt.go @@ -171,9 +171,7 @@ func (self *StateMgr) run() { case SyncDone: log.Infof("server %d sync done, curr blkNum: %d", self.server.Index, self.server.GetCurrentBlockNo()) - if err := self.setSyncedReady(); err != nil { - log.Warnf("server %d set syncready: %s", self.server.Index, err) - } + self.setSyncedReady() case LiveTick: log.Infof("server %d peer update, current blk: %d, state: %d. received peer states: %v", @@ -237,9 +235,7 @@ func (self *StateMgr) onPeerUpdate(peerState *PeerState) { } if self.isSyncedReady() { log.Infof("server %d synced from syncing", self.server.Index) - if err := self.setSyncedReady(); err != nil { - log.Warnf("server %d, state %d set syncready: %s", self.server.Index, self.getState(), err) - } + self.setSyncedReady() } case WaitNetworkReady: if self.isSyncedReady() { @@ -256,9 +252,7 @@ func (self *StateMgr) onPeerUpdate(peerState *PeerState) { } case SyncingCheck: if self.isSyncedReady() { - if err := self.setSyncedReady(); err != nil { - log.Warnf("server %d, state %d set syncready: %s", self.server.Index, self.getState(), err) - } + self.setSyncedReady() } else { self.checkStartSyncing(self.server.GetCommittedBlockNo()+MAX_SYNCING_CHECK_BLK_NUM, false) } @@ -361,7 +355,7 @@ func (self *StateMgr) isSyncedReady() bool { return self.canFastForward(committedBlkNum) } -func (self *StateMgr) setSyncedReady() error { +func (self *StateMgr) setSyncedReady() { prevState := self.getState() self.setState(SyncReady) if prevState <= SyncReady { @@ -375,8 +369,6 @@ func (self *StateMgr) setSyncedReady() error { }) self.server.makeFastForward() } - - return nil } func (self *StateMgr) checkStartSyncing(startBlkNum uint32, forceSync bool) {