gitlab.com/yannislg/go-pulse@v0.0.0-20210722055913-a3e24e95638d/consensus/parlia/ramanujan_fork.go (about)

     1  package parlia
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/ethereum/go-ethereum/consensus"
     7  	"github.com/ethereum/go-ethereum/core/types"
     8  )
     9  
    10  const (
    11  	wiggleTimeBeforeFork       = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
    12  	fixedBackOffTimeBeforeFork = 200 * time.Millisecond
    13  )
    14  
    15  func (p *Parlia) delayForRamanujanFork(snap *Snapshot, header *types.Header) time.Duration {
    16  	return time.Until(time.Unix(int64(header.Time), 0))
    17  }
    18  
    19  func (p *Parlia) blockTimeForRamanujanFork(snap *Snapshot, header, parent *types.Header) uint64 {
    20  	return parent.Time + p.config.Period + backOffTime(snap, p.val)
    21  }
    22  
    23  func (p *Parlia) blockTimeVerifyForRamanujanFork(snap *Snapshot, header, parent *types.Header) error {
    24  	if header.Time < parent.Time+p.config.Period+backOffTime(snap, header.Coinbase) {
    25  		return consensus.ErrFutureBlock
    26  	}
    27  
    28  	return nil
    29  }