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: exit loop when downloader Done or Failed #200

Merged
merged 17 commits into from
Oct 8, 2020

Conversation

meowsbits
Copy link
Contributor

Following the logic of the comment at the method,
this fixes a regression introduced at 7cf56d6
, which would allow external parties to DoS with
blocks, preventing mining progress.

Rel #199

Corresponding upstream PR at ethereum/go-ethereum#21653

Following the logic of the comment at the method,
this fixes a regression introduced at 7cf56d6
, which would allow external parties to DoS with
blocks, preventing mining progress.

Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
@meowsbits meowsbits linked an issue Oct 2, 2020 that may be closed by this pull request
@meowsbits meowsbits requested a review from ziogaschr October 2, 2020 21:47
Signed-off-by: meows <b5c6@protonmail.com>
@iquidus
Copy link
Contributor

iquidus commented Oct 5, 2020

after implementing these changes force interupt, (e.g ctrl+c) is not exiting cleanly, as it did prior to these changes. I am forced to interupt until panic, otherwise looping on looking for peers.

INFO [10-05|14:42:51.369] Ethereum protocol stopped 
INFO [10-05|14:42:51.369] Transaction pool stopped 
INFO [10-05|14:42:59.009] Looking for peers                        peercount=0 tried=17 static=0
INFO [10-05|14:43:09.039] Looking for peers                        peercount=0 tried=51 static=0
INFO [10-05|14:43:19.544] Looking for peers                        peercount=0 tried=65 static=0
INFO [10-05|14:43:29.627] Looking for peers                        peercount=0 tried=69 static=0
INFO [10-05|14:43:39.882] Looking for peers                        peercount=0 tried=38 static=0
INFO [10-05|14:43:50.282] Looking for peers                        peercount=1 tried=98 static=0
INFO [10-05|14:44:00.283] Looking for peers                        peercount=0 tried=98 static=0
INFO [10-05|14:44:10.343] Looking for peers                        peercount=1 tried=59 static=0
INFO [10-05|14:44:20.387] Looking for peers                        peercount=1 tried=75 static=0
INFO [10-05|14:44:30.544] Looking for peers                        peercount=1 tried=92 static=0
INFO [10-05|14:44:40.570] Looking for peers                        peercount=1 tried=62 static=0
INFO [10-05|14:44:50.700] Looking for peers                        peercount=0 tried=60 static=0

@meowsbits
Copy link
Contributor Author

@iquidus Yes, it needs more work. The channels are not getting closed. See upstream PR for comments as well.

This helper function would return an affirmation
on the first positive match on a desired bool.

This was imprecise; it return false positives
by not waiting initially for an 'updated' value.

This fix causes TestMiner_2 to fail, which is
expected.

Signed-off-by: meows <b5c6@protonmail.com>
This test demonstrated the imprecision of the test
helper function waitForMiningState. This function
has been fixed with 6d365c2851, and this test test
may now be removed.

Signed-off-by: meows <b5c6@protonmail.com>
See comment for logic.

Signed-off-by: meows <b5c6@protonmail.com>
We expect that once the downloader emits a DoneEvent,
signaling a successful sync, that subsequent StartEvents
are not longer permitted to stop the miner.

This prevents a security vulnerability where forced syncs via
fake high blocks would stall mining operation.

Signed-off-by: meows <b5c6@protonmail.com>
- Break downloader event handling into event
separating Done and Failed events. We need to
treat these cases differently since a DoneEvent
should prevent the miner from being stopped on
subsequent downloader Start events.

- Use canStop state to handle the one-off
case when a downloader first succeeds.

Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
This makes mining pause/start logic regarding downloader
events more explicit. Instead of eternally handling downloader
events after the first done event, the subscription is closed
when downloader events are no longer actionable.

Signed-off-by: meows <b5c6@protonmail.com>
@meowsbits
Copy link
Contributor Author

@iquidus @ziogaschr PTAL

Signed-off-by: meows <b5c6@protonmail.com>
Signed-off-by: meows <b5c6@protonmail.com>
The go routine handling the downloader events handling
vars in parallel with the parent routine, causing a
race condition.

This change, though ugly, remove the condition while
still allowing the downloader event subscription to be
closed when the miner has no further use for it (ie DoneEvent).
@ziogaschr ziogaschr self-requested a review October 5, 2020 20:54
Copy link
Contributor

@iquidus iquidus left a comment

Choose a reason for hiding this comment

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

lgtm

@meowsbits meowsbits merged commit a3b5c76 into master Oct 8, 2020
@meowsbits meowsbits deleted the fix/miner-dl-stop-break branch October 8, 2020 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mining aborted due to sync
3 participants