diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 8315ec2d48..7152cf450a 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -123,6 +123,10 @@ var ( // turn of the signer. errWrongDifficulty = errors.New("wrong difficulty") + // errInvalidTimestamp is returned if the timestamp of a block is lower than + // the previous block's timestamp + the minimum block period. + errInvalidTimestamp = errors.New("invalid timestamp") + // errInvalidVotingChain is returned if an authorization list is attempted to // be modified via out-of-range or non-contiguous headers. errInvalidVotingChain = errors.New("invalid voting chain") @@ -323,9 +327,9 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash { return consensus.ErrUnknownAncestor } - /*if parent.Time+c.config.Period > header.Time { + if parent.Time+c.config.Period > header.Time { return errInvalidTimestamp - }*/ + } // Verify that the gasUsed is <= gasLimit if header.GasUsed > header.GasLimit { return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit) @@ -549,10 +553,10 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header if parent == nil { return consensus.ErrUnknownAncestor } - //header.Time = parent.Time + c.config.Period - //if header.Time < uint64(time.Now().Unix()) { - header.Time = uint64(time.Now().Unix()) - //} + header.Time = parent.Time + c.config.Period + if header.Time < uint64(time.Now().Unix()) { + header.Time = uint64(time.Now().Unix()) + } return nil } diff --git a/miner/worker.go b/miner/worker.go index e0e56f8f3f..855a8ba898 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -400,7 +400,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) { case head := <-w.chainHeadCh: clearPending(head.Block.NumberU64()) timestamp = time.Now().Unix() - // commit(false, commitInterruptNewHead) + commit(true, commitInterruptNewHead) case <-timer.C: // If mining is running resubmit a new work cycle periodically to pull in