fix deplay check

This commit is contained in:
fudongbai 2020-08-09 12:37:39 +08:00
parent baae91db37
commit c4f4377cfd
No known key found for this signature in database
GPG Key ID: CB81CB49204A5AB9

View File

@ -14,12 +14,16 @@ const (
) )
func (p *Parlia) delayForRamanujanFork(snap *Snapshot, header *types.Header) time.Duration { func (p *Parlia) delayForRamanujanFork(snap *Snapshot, header *types.Header) time.Duration {
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple delay := time.Until(time.Unix(int64(header.Time), 0)) // nolint: gosimple
if p.chainConfig.IsRamanujan(header.Number) { if p.chainConfig.IsRamanujan(header.Number) {
return delay return delay
} }
wiggle := time.Duration(len(snap.Validators)/2+1) * wiggleTimeBeforeFork if header.Difficulty.Cmp(diffNoTurn) == 0 {
return delay + time.Duration(fixedBackOffTimeBeforeFork) + time.Duration(rand.Int63n(int64(wiggle))) // It's not our turn explicitly to sign, delay it a bit
wiggle := time.Duration(len(snap.Validators)/2+1) * wiggleTimeBeforeFork
delay += time.Duration(fixedBackOffTimeBeforeFork) + time.Duration(rand.Int63n(int64(wiggle)))
}
return delay
} }
func (p *Parlia) blockTimeForRamanujanFork(snap *Snapshot, header, parent *types.Header) uint64 { func (p *Parlia) blockTimeForRamanujanFork(snap *Snapshot, header, parent *types.Header) uint64 {