mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
bor producer change delay
This commit is contained in:
parent
f37d07db3d
commit
17ed765ce0
3 changed files with 13 additions and 1 deletions
|
|
@ -109,6 +109,7 @@ func (w *wizard) makeGenesis() {
|
||||||
genesis.Config.Bor = ¶ms.BorConfig{
|
genesis.Config.Bor = ¶ms.BorConfig{
|
||||||
Period: 1,
|
Period: 1,
|
||||||
ProducerInterval: 60,
|
ProducerInterval: 60,
|
||||||
|
ProducerDelay: 5,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,16 @@ func CalcDifficulty(snap *Snapshot, signer common.Address, producerPeriod uint64
|
||||||
return new(big.Int).Set(diffNoTurn)
|
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
|
// 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
|
// sealing. The RLP to sign consists of the entire header apart from the 65 byte signature
|
||||||
// contained at the end of the extra data.
|
// 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 {
|
if parent == nil {
|
||||||
return consensus.ErrUnknownAncestor
|
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()) {
|
if header.Time < uint64(time.Now().Unix()) {
|
||||||
header.Time = uint64(time.Now().Unix())
|
header.Time = uint64(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,7 @@ func (c *CliqueConfig) String() string {
|
||||||
type BorConfig struct {
|
type BorConfig struct {
|
||||||
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
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
|
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
|
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue