-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miner: avoid data race in miner #24349
Conversation
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR fixes the #24299. It's an alternative fix of #24301