mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
feat: implement relaxed period in clique (#763)
* feat: implement relaxed period in clique and enable it on Sepolia * simplify if check * chore: auto version bump [bot] * Update clique.go --------- Co-authored-by: omerfirmak <omerfirmak@users.noreply.github.com>
This commit is contained in:
parent
c7990a3eb1
commit
dd96ceced8
4 changed files with 16 additions and 6 deletions
|
|
@ -328,7 +328,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
|
||||||
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
if parent.Time+c.config.Period > header.Time {
|
if header.Time < parent.Time {
|
||||||
return errInvalidTimestamp
|
return errInvalidTimestamp
|
||||||
}
|
}
|
||||||
// Verify that the gasUsed is <= gasLimit
|
// Verify that the gasUsed is <= gasLimit
|
||||||
|
|
@ -555,7 +555,9 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
header.Time = parent.Time + c.config.Period
|
header.Time = parent.Time + c.config.Period
|
||||||
if header.Time < uint64(time.Now().Unix()) {
|
// If RelaxedPeriod is enabled, always set the header timestamp to now (ie the time we start building it) as
|
||||||
|
// we don't know when it will be sealed
|
||||||
|
if c.config.RelaxedPeriod || header.Time < uint64(time.Now().Unix()) {
|
||||||
header.Time = uint64(time.Now().Unix())
|
header.Time = uint64(time.Now().Unix())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -708,7 +708,14 @@ func (w *worker) startNewPipeline(timestamp int64) {
|
||||||
|
|
||||||
w.currentPipelineStart = time.Now()
|
w.currentPipelineStart = time.Now()
|
||||||
w.currentPipeline = pipeline.NewPipeline(w.chain, w.chain.GetVMConfig(), parentState, header, nextL1MsgIndex, w.getCCC()).WithBeforeTxHook(w.beforeTxHook)
|
w.currentPipeline = pipeline.NewPipeline(w.chain, w.chain.GetVMConfig(), parentState, header, nextL1MsgIndex, w.getCCC()).WithBeforeTxHook(w.beforeTxHook)
|
||||||
if err := w.currentPipeline.Start(time.Unix(int64(header.Time), 0)); err != nil {
|
|
||||||
|
deadline := time.Unix(int64(header.Time), 0)
|
||||||
|
if w.chainConfig.Clique != nil && w.chainConfig.Clique.RelaxedPeriod {
|
||||||
|
// clique with relaxed period uses time.Now() as the header.Time, calculate the deadline
|
||||||
|
deadline = time.Unix(int64(header.Time+w.chainConfig.Clique.Period), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.currentPipeline.Start(deadline); err != nil {
|
||||||
log.Error("failed to start pipeline", "err", err)
|
log.Error("failed to start pipeline", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -602,8 +602,9 @@ func (c *EthashConfig) String() string {
|
||||||
|
|
||||||
// CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
|
// CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
|
||||||
type CliqueConfig struct {
|
type CliqueConfig struct {
|
||||||
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
||||||
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
||||||
|
RelaxedPeriod bool `json:"relaxed_period"` // Relaxes the period to be just an upper bound
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface, returning the consensus engine details.
|
// String implements the stringer interface, returning the consensus engine details.
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 3 // Minor version component of the current release
|
VersionMinor = 3 // Minor version component of the current release
|
||||||
VersionPatch = 18 // Patch version component of the current release
|
VersionPatch = 19 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue