Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixed concurrency issue that allowed multiple miners instantiation. #909

Merged
merged 2 commits into from
Jan 29, 2021

Conversation

dzajkowski
Copy link
Contributor

This PR is a refresh of #777

Description

Concurrent EthashConsensus.startMiningProcess() method invocation can lead to several miner actors.
There's no thread mutual exclusion and atomicity between AtomicReference.get() and AtomicReference.set() calls.

Proposed Solution

synchronized or ReentrantReadWrite is recommended to ensure that only one miner is created.
AtomicReference is redundant, since no CAS-related methods are used.
Solution assumes that no thread synchronization is needed when miner already exists.

@dzajkowski dzajkowski changed the title Fix ethconsensus concurrent startmining Fixed concurrency issue that allowed multiple miners instantiation. Jan 28, 2021
@AnastasiiaL AnastasiiaL self-requested a review January 28, 2021 16:07
Copy link
Contributor

@1015bit 1015bit left a comment

Choose a reason for hiding this comment

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

Any reasons to not turn EthashConsensus into an actor instead of using low level concurrency mechanisms?

@dzajkowski
Copy link
Contributor Author

Any reasons to not turn EthashConsensus into an actor instead of using low level concurrency mechanisms?

I would prefer such a solution but after some digging I found that the reorg would touch a lot of code. this solution isn't pretty but it's small.
I will add a task to do a proper refactor of how the application is instrumented to avoid such runtime oddities.

@dzajkowski dzajkowski force-pushed the fix-ethconsensus-concurrent-startmining branch from 2c28513 to a81e65f Compare January 29, 2021 10:53
@dzajkowski dzajkowski merged commit 9c34144 into develop Jan 29, 2021
@dzajkowski dzajkowski deleted the fix-ethconsensus-concurrent-startmining branch January 29, 2021 13:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants