Skip to content

Commit 844c6cf

Browse files
authored
state, consensus: skip requests check when receipts unavailable after exec (#14107) (#14113)
Cherry pick #14107
1 parent ab0f917 commit 844c6cf

File tree

13 files changed

+21
-22
lines changed

13 files changed

+21
-22
lines changed

cmd/rpcdaemon/cli/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ func (e *remoteConsensusEngine) Prepare(_ consensus.ChainHeaderReader, _ *types.
11401140
panic("remoteConsensusEngine.Prepare not supported")
11411141
}
11421142

1143-
func (e *remoteConsensusEngine) Finalize(_ *chain.Config, _ *types.Header, _ *state.IntraBlockState, _ types.Transactions, _ []*types.Header, _ types.Receipts, _ []*types.Withdrawal, _ consensus.ChainReader, _ consensus.SystemCall, _ log.Logger) (types.Transactions, types.Receipts, types.FlatRequests, error) {
1143+
func (e *remoteConsensusEngine) Finalize(_ *chain.Config, _ *types.Header, _ *state.IntraBlockState, _ types.Transactions, _ []*types.Header, _ types.Receipts, _ []*types.Withdrawal, _ consensus.ChainReader, _ consensus.SystemCall, skipReceiptsEval bool, _ log.Logger) (types.Transactions, types.Receipts, types.FlatRequests, error) {
11441144
panic("remoteConsensusEngine.Finalize not supported")
11451145
}
11461146

cmd/state/exec3/historical_trace_worker.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (rw *HistoricalTraceWorker) RunTxTask(txTask *state.TxTask) {
180180
return core.SysCallContract(contract, data, rw.execArgs.ChainConfig, ibs, header, rw.execArgs.Engine, false /* constCall */)
181181
}
182182

183-
_, _, _, err := rw.execArgs.Engine.Finalize(rw.execArgs.ChainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, rw.logger)
183+
_, _, _, err := rw.execArgs.Engine.Finalize(rw.execArgs.ChainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, true /* skipReceiptsEval */, rw.logger)
184184
if err != nil {
185185
txTask.Error = err
186186
}

cmd/state/exec3/state.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (rw *Worker) Run() (err error) {
153153
func (rw *Worker) RunTxTask(txTask *state.TxTask, isMining bool) {
154154
rw.lock.Lock()
155155
defer rw.lock.Unlock()
156-
rw.RunTxTaskNoLock(txTask, isMining)
156+
rw.RunTxTaskNoLock(txTask, isMining, false)
157157
}
158158

159159
// Needed to set history reader when need to offset few txs from block beginning and does not break processing,
@@ -175,7 +175,7 @@ func (rw *Worker) SetReader(reader state.ResettableStateReader) {
175175
}
176176
}
177177

178-
func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) {
178+
func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining, skipPostEvaluaion bool) {
179179
if txTask.HistoryExecution && !rw.historyMode {
180180
// in case if we cancelled execution and commitment happened in the middle of the block, we have to process block
181181
// from the beginning until committed txNum and only then disable history mode.
@@ -238,7 +238,6 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) {
238238
break
239239
}
240240

241-
//fmt.Printf("txNum=%d, blockNum=%d, finalisation of the block\n", txTask.TxNum, txTask.BlockNum)
242241
// End of block transaction in a block
243242
syscall := func(contract libcommon.Address, data []byte) ([]byte, error) {
244243
return core.SysCallContract(contract, data, rw.chainConfig, ibs, header, rw.engine, false /* constCall */)
@@ -247,7 +246,7 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) {
247246
if isMining {
248247
_, txTask.Txs, txTask.BlockReceipts, _, err = rw.engine.FinalizeAndAssemble(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, nil, rw.logger)
249248
} else {
250-
_, _, _, err = rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, rw.logger)
249+
_, _, _, err = rw.engine.Finalize(rw.chainConfig, types.CopyHeader(header), ibs, txTask.Txs, txTask.Uncles, txTask.BlockReceipts, txTask.Withdrawals, rw.chain, syscall, skipPostEvaluaion, rw.logger)
251250
}
252251
if err != nil {
253252
txTask.Error = err

consensus/aura/aura.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func (c *AuRa) applyRewards(header *types.Header, state *state.IntraBlockState,
717717
// word `signal epoch` == word `pending epoch`
718718
func (c *AuRa) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions,
719719
uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal,
720-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
720+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
721721
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
722722
if err := c.applyRewards(header, state, syscall); err != nil {
723723
return nil, nil, nil, err
@@ -856,7 +856,7 @@ func allHeadersUntil(chain consensus.ChainHeaderReader, from *types.Header, to l
856856

857857
// FinalizeAndAssemble implements consensus.Engine
858858
func (c *AuRa) FinalizeAndAssemble(config *chain.Config, header *types.Header, state *state.IntraBlockState, txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, chain consensus.ChainReader, syscall consensus.SystemCall, call consensus.Call, logger log.Logger) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
859-
outTxs, outReceipts, _, err := c.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
859+
outTxs, outReceipts, _, err := c.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, false, logger)
860860
if err != nil {
861861
return nil, nil, nil, nil, err
862862
}

consensus/clique/clique.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (c *Clique) CalculateRewards(config *chain.Config, header *types.Header, un
379379
// rewards given.
380380
func (c *Clique) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
381381
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
382-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
382+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
383383
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
384384
return txs, r, nil, nil
385385
}

consensus/consensus.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ type EngineWriter interface {
165165
// Finalize runs any post-transaction state modifications (e.g. block rewards)
166166
// but does not assemble the block.
167167
Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
168-
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, chain ChainReader, syscall SystemCall, logger log.Logger,
168+
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal, chain ChainReader, syscall SystemCall, skipReceiptsEval bool, logger log.Logger,
169169
) (types.Transactions, types.Receipts, types.FlatRequests, error)
170170

171171
// FinalizeAndAssemble runs any post-transaction state modifications (e.g. block

consensus/ethash/consensus.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func (ethash *Ethash) Initialize(config *chain.Config, chain consensus.ChainHead
568568
// setting the final state on the header
569569
func (ethash *Ethash) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
570570
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
571-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
571+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
572572
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
573573
// Accumulate any block and uncle rewards and commit the final state root
574574
accumulateRewards(config, state, header, uncles)
@@ -583,7 +583,7 @@ func (ethash *Ethash) FinalizeAndAssemble(chainConfig *chain.Config, header *typ
583583
) (*types.Block, types.Transactions, types.Receipts, types.FlatRequests, error) {
584584

585585
// Finalize block
586-
outTxs, outR, _, err := ethash.Finalize(chainConfig, header, state, txs, uncles, r, withdrawals, chain, syscall, logger)
586+
outTxs, outR, _, err := ethash.Finalize(chainConfig, header, state, txs, uncles, r, withdrawals, chain, syscall, false, logger)
587587
if err != nil {
588588
return nil, nil, nil, nil, err
589589
}

consensus/merge/merge.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ func (s *Merge) CalculateRewards(config *chain.Config, header *types.Header, unc
151151

152152
func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
153153
txs types.Transactions, uncles []*types.Header, receipts types.Receipts, withdrawals []*types.Withdrawal,
154-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
154+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
155155
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
156156
if !misc.IsPoSHeader(header) {
157-
return s.eth1Engine.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
157+
return s.eth1Engine.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, skipReceiptsEval, logger)
158158
}
159159

160160
rewards, err := s.CalculateRewards(config, header, uncles, syscall)
@@ -186,7 +186,7 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
186186
}
187187

188188
var rs types.FlatRequests
189-
if config.IsPrague(header.Time) {
189+
if config.IsPrague(header.Time) && !skipReceiptsEval {
190190
rs = make(types.FlatRequests, 0)
191191
allLogs := make(types.Logs, 0)
192192
for _, rec := range receipts {
@@ -225,7 +225,7 @@ func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header,
225225
return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, call, logger)
226226
}
227227
header.RequestsHash = nil
228-
outTxs, outReceipts, outRequests, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger)
228+
outTxs, outReceipts, outRequests, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, false, logger)
229229

230230
if err != nil {
231231
return nil, nil, nil, nil, err

core/blockchain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func FinalizeBlockExecution(
337337
if isMining {
338338
newBlock, newTxs, newReceipt, retRequests, err = engine.FinalizeAndAssemble(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, nil, logger)
339339
} else {
340-
newTxs, newReceipt, retRequests, err = engine.Finalize(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, logger)
340+
newTxs, newReceipt, retRequests, err = engine.Finalize(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, false, logger)
341341
}
342342
if err != nil {
343343
return nil, nil, nil, nil, err

eth/stagedsync/exec3_parallel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (pe *parallelExecutor) processResultQueue(ctx context.Context, inputTxNum u
398398
}
399399

400400
// resolve first conflict right here: it's faster and conflict-free
401-
pe.applyWorker.RunTxTaskNoLock(txTask.Reset(), pe.isMining)
401+
pe.applyWorker.RunTxTaskNoLock(txTask.Reset(), pe.isMining, false)
402402
if txTask.Error != nil {
403403
//fmt.Println("RETRY", txTask.TxNum, txTask.Error)
404404
return outputTxNum, conflicts, triggers, processedBlockNum, false, fmt.Errorf("%w: %v", consensus.ErrInvalidBlock, txTask.Error)

eth/stagedsync/exec3_serial.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (se *serialExecutor) execute(ctx context.Context, tasks []*state.TxTask) (c
4040
return false, nil
4141
}
4242

43-
se.applyWorker.RunTxTaskNoLock(txTask, se.isMining)
43+
se.applyWorker.RunTxTaskNoLock(txTask, se.isMining, se.skipPostEvaluation)
4444
if err := func() error {
4545
if errors.Is(txTask.Error, context.Canceled) {
4646
return txTask.Error

polygon/bor/bor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ func (c *Bor) CalculateRewards(config *chain.Config, header *types.Header, uncle
10191019
// rewards given.
10201020
func (c *Bor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
10211021
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
1022-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
1022+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
10231023
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
10241024
headerNumber := header.Number.Uint64()
10251025

polygon/bor/fake.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func NewFaker() *FakeBor {
3838

3939
func (f *FakeBor) Finalize(config *chain.Config, header *types.Header, state *state.IntraBlockState,
4040
txs types.Transactions, uncles []*types.Header, r types.Receipts, withdrawals []*types.Withdrawal,
41-
chain consensus.ChainReader, syscall consensus.SystemCall, logger log.Logger,
41+
chain consensus.ChainReader, syscall consensus.SystemCall, skipReceiptsEval bool, logger log.Logger,
4242
) (types.Transactions, types.Receipts, types.FlatRequests, error) {
43-
return f.FakeEthash.Finalize(config, header, state, txs, uncles, r, withdrawals, chain, syscall, logger)
43+
return f.FakeEthash.Finalize(config, header, state, txs, uncles, r, withdrawals, chain, syscall, skipReceiptsEval, logger)
4444
}

0 commit comments

Comments
 (0)