mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 15:46:43 +00:00
fix: accept header at most 100ms earlier than timestamp (#1129)
* fix: address timing issue in system config worker * make code easier to understand * add 100ms header verification grace period to Clique
This commit is contained in:
parent
40ebbd6491
commit
748fb82899
4 changed files with 14 additions and 5 deletions
|
|
@ -254,8 +254,10 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
|
|||
}
|
||||
number := header.Number.Uint64()
|
||||
|
||||
// Don't waste time checking blocks from the future
|
||||
if header.Time > uint64(time.Now().Unix()) {
|
||||
// Don't waste time checking blocks from the future.
|
||||
// We add 100ms leeway since the scroll_worker internal timers might trigger early.
|
||||
now := time.Now()
|
||||
if header.Time > uint64(now.Unix()) && time.Unix(int64(header.Time), 0).Sub(now) > 100*time.Millisecond {
|
||||
return consensus.ErrFutureBlock
|
||||
}
|
||||
// Checkpoint blocks need to enforce zero beneficiary
|
||||
|
|
|
|||
|
|
@ -115,8 +115,10 @@ func (s *SystemContract) verifyHeader(chain consensus.ChainHeaderReader, header
|
|||
return errUnknownBlock
|
||||
}
|
||||
|
||||
// Don't waste time checking blocks from the future
|
||||
if header.Time > uint64(time.Now().Unix()) {
|
||||
// Don't waste time checking blocks from the future.
|
||||
// We add 100ms leeway since the scroll_worker internal timers might trigger early.
|
||||
now := time.Now()
|
||||
if header.Time > uint64(now.Unix()) && time.Unix(int64(header.Time), 0).Sub(now) > 100*time.Millisecond {
|
||||
return consensus.ErrFutureBlock
|
||||
}
|
||||
// Ensure that the coinbase is zero
|
||||
|
|
|
|||
|
|
@ -464,6 +464,7 @@ func (w *worker) collectPendingL1Messages(startIndex uint64) []types.L1MessageTx
|
|||
if len(l1MessagesV1) > 0 {
|
||||
// backdate the block to the parent block's timestamp -> not yet EuclidV2
|
||||
// TODO: might need to re-run Prepare here
|
||||
log.Warn("Back-labeling header timestamp to ensure it precedes the EuclidV2 transition", "blockNumber", w.current.header.Number, "oldTime", w.current.header.Time, "newTime", parent.Time)
|
||||
w.current.header.Time = parent.Time
|
||||
return l1MessagesV1
|
||||
}
|
||||
|
|
@ -541,6 +542,10 @@ func (w *worker) newWork(now time.Time, parentHash common.Hash, reorging bool, r
|
|||
// 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 w.chainConfig.SystemContract != nil && w.chainConfig.SystemContract.RelaxedPeriod {
|
||||
// system contract with relaxed period uses time.Now() as the header.Time, calculate the deadline
|
||||
deadline = time.Unix(int64(header.Time+w.chainConfig.SystemContract.Period), 0)
|
||||
}
|
||||
|
||||
w.current = &work{
|
||||
deadlineTimer: time.NewTimer(time.Until(deadline)),
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
const (
|
||||
VersionMajor = 5 // Major version component of the current release
|
||||
VersionMinor = 8 // 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
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue