[consensus] enable the consensus module can spin up doSync (#3340)

* [consensus] enable the consensus module can spin up doSync

* [consensus] remove the blockNumLowChan buffer in onCommitted. Move tryCatchup logic before informing blockNumLow

* [sync] Remove an unnecessary time ticker in sync to reduce one sync loop time from 3.5s to 1s (based on testnet)

* [consensus] also spin up state sync at onPrepared

* [consensus] removed onCommitted block number check since redundent
pull/3350/head
Jacky Wang 4 years ago committed by GitHub
parent eaf51b814b
commit f9c26e663b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      api/service/syncing/syncing.go
  2. 31
      consensus/validator.go

@ -914,10 +914,7 @@ func (ss *StateSync) SyncLoop(bc *core.BlockChain, worker *worker.Worker, isBeac
if !isBeacon {
ss.RegisterNodeInfo()
}
// remove SyncLoopFrequency
ticker := time.NewTicker(SyncLoopFrequency * time.Second)
defer ticker.Stop()
for range ticker.C {
for {
otherHeight := ss.getMaxPeerHeight(isBeacon)
currentHeight := bc.CurrentBlock().NumberU64()
if currentHeight >= otherHeight {

@ -188,6 +188,10 @@ func (consensus *Consensus) onPrepared(msg *msg_pb.Message) {
// tryCatchup is also run in onCommitted(), so need to lock with commitMutex.
consensus.tryCatchup()
if recvMsg.BlockNum > consensus.blockNum {
consensus.getLogger().Info().Uint64("MsgBlockNum", recvMsg.BlockNum).Msg("[OnPrepared] OUT OF SYNC")
go consensus.spinUpStateSync()
}
if consensus.current.Mode() != Normal {
// don't sign the block that is not verified
@ -341,22 +345,14 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
consensus.aggregatedCommitSig = aggSig
consensus.commitBitmap = mask
if recvMsg.BlockNum > consensus.blockNum && recvMsg.BlockNum-consensus.blockNum > consensusBlockNumBuffer {
consensus.tryCatchup()
if recvMsg.BlockNum > consensus.blockNum {
consensus.getLogger().Info().Uint64("MsgBlockNum", recvMsg.BlockNum).Msg("[OnCommitted] OUT OF SYNC")
go func() {
select {
case consensus.BlockNumLowChan <- struct{}{}:
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
case <-time.After(1 * time.Second):
}
}()
go consensus.spinUpStateSync()
return
}
consensus.tryCatchup()
if consensus.IsViewChangingMode() {
consensus.getLogger().Info().Msg("[OnCommitted] Still in ViewChanging mode, Exiting!!")
return
@ -370,3 +366,14 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
}
consensus.consensusTimeout[timeoutConsensus].Start()
}
func (consensus *Consensus) spinUpStateSync() {
select {
case consensus.BlockNumLowChan <- struct{}{}:
consensus.current.SetMode(Syncing)
for _, v := range consensus.consensusTimeout {
v.Stop()
}
case <-time.After(1 * time.Second):
}
}

Loading…
Cancel
Save