-
Notifications
You must be signed in to change notification settings - Fork 20.3k
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: Concurrent read/write during contract deployment (issue #16933) #17173
Conversation
Merge latest geth changes
Latest changes from go-ethereum
Pull latest changes from go-ethereum
Take latest changes from go-ethereum
Bring latest changes from original geth
Pull in the latest changes from go-ethereum
Pull latest changes from go-ethereum
Bring in latest changes from go-ethereum
Pull latest changes from geth
Pull latest changes from go-ethereum
Pull latest changes from go-ethereum
pull latest changes from go-ethereum
pull 1.8.4
Pull latest changes from go-ethereum
pull latest changes from go-ethereum
Pull go-ethereum 1.8.11
Pull 1.8.12
Pull latest changes from go-ethereum
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!
Not my favorite solution btw since we seem to hold the wrong lock, but since we're rewriting the miner soon-ish anyway, this fast solution will be fine. |
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.
its good after initial testing it looks like this fixed the problem
Fix for this #16933
Copy of my analysis from the issue:
Ok, I think I figured out where this race is coming from. Here: https://github.com/ethereum/go-ethereum/blob/v1.8.10/miner/worker.go#L499 the "work", containing pointer to the "current.state" gets pushed to the channel for the agents to process.
Agent processes it (finds nonce), wraps it into a "Result" and puts it into the "recv" channel. Here we read it from "recv" channel: https://github.com/ethereum/go-ethereum/blob/v1.8.10/miner/worker.go#L301.
Next, we call "WriteBlockWithState" here, passing the same state: https://github.com/ethereum/go-ethereum/blob/v1.8.10/miner/worker.go#L320.
Inside WriteBlockWithState, we call state.Commit here: https://github.com/ethereum/go-ethereum/blob/v1.8.10/core/blockchain.go#L902, which mutates the state. When it happens, we are not holding the "currentMu" lock, which means the call to "pending" can proceed concurrently
Fix is empirically verified by the OP of the issue