From 4c1b57856f0f5ebccb6edb83ab755ab114500078 Mon Sep 17 00:00:00 2001 From: buddho Date: Tue, 19 Mar 2024 22:23:55 +0800 Subject: [PATCH] miner: modify header before checking time-based fields (#29242) The Prepare-method of consensus engine might modify the time-field in a header, so it should be called prior to checks that rely on it --- miner/worker.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 7e038b0f30..a72af3a3a4 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -167,6 +167,12 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) header.GasLimit = core.CalcGasLimit(parentGasLimit, miner.config.GasCeil) } } + // Run the consensus preparation with the default or customized consensus engine. + // Note that the `header.Time` may be changed. + if err := miner.engine.Prepare(miner.chain, header); err != nil { + log.Error("Failed to prepare header for sealing", "err", err) + return nil, err + } // Apply EIP-4844, EIP-4788. if miner.chainConfig.IsCancun(header.Number, header.Time) { var excessBlobGas uint64 @@ -180,11 +186,6 @@ func (miner *Miner) prepareWork(genParams *generateParams) (*environment, error) header.ExcessBlobGas = &excessBlobGas header.ParentBeaconRoot = genParams.beaconRoot } - // Run the consensus preparation with the default or customized consensus engine. - if err := miner.engine.Prepare(miner.chain, header); err != nil { - log.Error("Failed to prepare header for sealing", "err", err) - return nil, err - } // Could potentially happen if starting to mine in an odd state. // Note genParams.coinbase can be different with header.Coinbase // since clique algorithm can modify the coinbase field in header.