fix bug on no committing new block (#29)

This commit is contained in:
maskpp 2022-02-17 18:25:41 +08:00 committed by GitHub
parent 1ecbde748c
commit 8b16b4cefa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -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
}

View file

@ -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