miner: avoid data race in miner#24349
Conversation
| } | ||
| // Create a local environment copy, avoid the data race with snapshot state. | ||
| // https://github.com/ethereum/go-ethereum/issues/24299 | ||
| env := env.copy() |
There was a problem hiding this comment.
A few lines up, at line 1118, we already do w.commit(work.copy(), w.fullTaskHook, true, start). Are you sure this fixes it?
There was a problem hiding this comment.
Yup, in line 1118, we indeed create the env copy for commit function to isolate the mutation between the commit function and other logic in miner.
However, in the commit function, there are two places can read/write the passed env in the same time. One is updateSnapshot which inits the pending state snapshot from the given env. Another is resultLoop for mutating the state root of the cached env.
There was a problem hiding this comment.
I still don't see how this fixes it. Don't the two still use the same instance, only this time a copy of the one that was passed in?
There was a problem hiding this comment.
If mining is enabled, then the copy of passed env is passed to the sealer and the passed env is passed to the pending state.
This PR fixes the #24299. It's an alternative fix of #24301