Skip to content

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

@ten15bit ten15bit 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
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.

5 participants