diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index 61666fda23..0828f257f7 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -109,6 +109,7 @@ func (w *wizard) makeGenesis() { genesis.Config.Bor = ¶ms.BorConfig{ Period: 1, ProducerInterval: 60, + ProducerDelay: 5, Epoch: 30000, } default: diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index fd2fbb0ac0..60383ab4e2 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -190,6 +190,16 @@ func CalcDifficulty(snap *Snapshot, signer common.Address, producerPeriod uint64 return new(big.Int).Set(diffNoTurn) } +// CalcProducerDelay is the producer delay algorithm based on block time. +func CalcProducerDelay(snap *Snapshot, producerInterval uint64, producerDelay uint64) uint64 { + isFirstBlock := (snap.Number + 1) % producerInterval + if isFirstBlock == 0 { + return producerDelay + } + + return 0 +} + // BorRLP returns the rlp bytes which needs to be signed for the bor // sealing. The RLP to sign consists of the entire header apart from the 65 byte signature // contained at the end of the extra data. @@ -576,7 +586,7 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error { if parent == nil { return consensus.ErrUnknownAncestor } - header.Time = parent.Time + c.config.Period + header.Time = parent.Time + c.config.Period + CalcProducerDelay(snap, c.config.ProducerInterval, c.config.ProducerDelay) if header.Time < uint64(time.Now().Unix()) { header.Time = uint64(time.Now().Unix()) } diff --git a/params/config.go b/params/config.go index afa222263d..77870cd1ee 100644 --- a/params/config.go +++ b/params/config.go @@ -230,6 +230,7 @@ func (c *CliqueConfig) String() string { type BorConfig struct { Period uint64 `json:"period"` // Number of seconds between blocks to enforce ProducerInterval uint64 `json:"producerInterval"` // Number of seconds between change in block producer interval to enforce + ProducerDelay uint64 `json:"producerDelay"` // Number of seconds delay between two producer interval Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint }