From 1be0ba8cf2c58dd2b713cf0586b2a987dcf7df4e 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 f49feac79f06..c6927a1ca1e8 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