From 2d20fed893faa894f50af709349b13b6ad9b45db Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Tue, 8 Feb 2022 01:34:13 +0800 Subject: [PATCH] miner: avoid data race in miner (#24349) --- miner/worker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/miner/worker.go b/miner/worker.go index f49feac79f..c6927a1ca1 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1134,6 +1134,9 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti if interval != nil { interval() } + // Create a local environment copy, avoid the data race with snapshot state. + // https://github.com/ethereum/go-ethereum/issues/24299 + env := env.copy() block, err := w.engine.FinalizeAndAssemble(w.chain, env.header, env.state, env.txs, env.unclelist(), env.receipts) if err != nil { return err