From f9249467945ce5276acd575d5bdaa2c6f1946f51 Mon Sep 17 00:00:00 2001 From: Nguyen Ba Tam Date: Mon, 29 Oct 2018 17:11:46 +0700 Subject: [PATCH] fix error deadlocked master node in case : try mine block Epoch when start node --- miner/worker.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 919fb41a3afd..258f857263b1 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -337,6 +337,24 @@ func (self *worker) wait() { if stat == core.CanonStatTy { events = append(events, core.ChainHeadEvent{Block: block}) } + if work.config.Posv != nil { + // epoch block + if (block.NumberU64() % work.config.Posv.Epoch) == 0 { + core.CheckpointCh <- 1 + } + // prepare set of masternodes for the next epoch + if (block.NumberU64() % work.config.Posv.Epoch) == (work.config.Posv.Epoch - work.config.Posv.Gap) { + err := self.chain.UpdateM1() + if err != nil { + if err == core.ErrNotPoSV { + log.Error("Stopping node", "err", err) + os.Exit(1) + } else { + log.Error("Error when update masternodes set. Keep the current masternodes set for the next epoch.", "err", err) + } + } + } + } self.chain.PostChainEvents(events, logs) // Insert the block into the set of pending ones to wait for confirmations @@ -590,24 +608,6 @@ func (self *worker) commitNewWork() { log.Info("Commit new mining work", "number", work.Block.Number(), "txs", work.tcount, "special txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart))) self.unconfirmed.Shift(work.Block.NumberU64() - 1) } - if work.config.Posv != nil { - // epoch block - if (work.Block.NumberU64() % work.config.Posv.Epoch) == 0 { - core.CheckpointCh <- 1 - } - // prepare set of masternodes for the next epoch - if (work.Block.NumberU64() % work.config.Posv.Epoch) == (work.config.Posv.Epoch - work.config.Posv.Gap) { - err := self.chain.UpdateM1() - if err != nil { - if err == core.ErrNotPoSV { - log.Error("Stopping node", "err", err) - os.Exit(1) - } else { - log.Error("Error when update masternodes set. Keep the current masternodes set for the next epoch.", "err", err) - } - } - } - } self.push(work) }