Skip to content
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

Merged
merged 19 commits into from
Jul 31, 2018

Conversation

AlexeyAkhunov
Copy link
Contributor

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

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 latest changes from go-ethereum
pull latest changes from go-ethereum
Pull latest changes from go-ethereum
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@karalabe
Copy link
Member

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.

@karalabe karalabe added this to the 1.8.13 milestone Jul 31, 2018
@karalabe karalabe merged commit 2fbc454 into ethereum:master Jul 31, 2018
Copy link

@prolands prolands left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants