Skip to content

Commit

Permalink
Merge 3544e44 into 4c5ac64
Browse files Browse the repository at this point in the history
  • Loading branch information
elvis88 committed Jul 12, 2019
2 parents 4c5ac64 + 3544e44 commit 250a713
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions consensus/miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ func (worker *Worker) setExtra(extra []byte) {

func (worker *Worker) commitNewWork(timestamp int64, parent *types.Header, quit chan struct{}) (*types.Block, error) {
dpos := worker.Engine().(*dpos.Dpos)
if time.Now().UnixNano() >= timestamp+int64(dpos.BlockInterval()) {
return nil, errors.New("mint the ingore block")
if t := time.Now().UnixNano(); t >= timestamp+int64(dpos.BlockInterval()) {
return nil, fmt.Errorf("mint the ingore block, need %v, now %v", timestamp, t)
}
if parent.Time.Int64() >= timestamp {
return nil, errors.New("mint the future block")
return nil, errors.New("mint the old block")
}
// if dpos.IsFirst(uint64(timestamp)) && parent.Time.Int64() != timestamp-int64(dpos.BlockInterval()) && timestamp-time.Now().UnixNano() >= int64(dpos.BlockInterval())/10 {
if parent.Number.Uint64() > 0 &&
Expand Down Expand Up @@ -470,18 +470,18 @@ type Work struct {
quit chan struct{}
}

func (worker *Worker) usleep(duration time.Duration) {
func (worker *Worker) usleep(duration time.Duration) time.Time {
end := time.Now().Add(duration)
for {
time.Sleep(time.Microsecond)
time.Sleep(time.Millisecond)
if time.Now().Sub(end) >= 0 {
break
}
}
return end
}
func (worker *Worker) utimer(duration time.Duration, c chan time.Time) {
go func(c chan time.Time) {
worker.usleep(duration)
c <- time.Now()
c <- worker.usleep(duration)
}(c)
}

0 comments on commit 250a713

Please sign in to comment.