• Martin Holst Swende's avatar
    miner: don't interrupt mining after successful sync (#21701) · 1e104891
    Martin Holst Swende authored
    * miner: exit loop when downloader Done or Failed
    
    Following the logic of the comment at the method,
    this fixes a regression introduced at 7cf56d6f
    , which would allow external parties to DoS with
    blocks, preventing mining progress.
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: remove ineff assign (lint)
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: update test re downloader events
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * Revert "miner: remove ineff assign (lint)"
    
    This reverts commit eaefcd34ab4862ebc936fb8a07578aa2744bc058.
    
    * Revert "miner: exit loop when downloader Done or Failed"
    
    This reverts commit 23abd34265aa246c38fc390bb72572ad6ae9fe3b.
    
    * miner: add test showing imprecise TestMiner
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: fix waitForMiningState precision
    
    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: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: remove TestMiner_2 demonstrating broken test
    
    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: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: fix test regarding downloader event/mining expectations
    
    See comment for logic.
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: add test describing expectations for downloader/mining events
    
    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: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: use 'canStop' state to fix downloader event handling
    
    - 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: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: improve comment wording
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: start mining on downloader events iff not already mining
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: refactor miner update logic w/r/t downloader events
    
    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: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: fix handling downloader events on subcription closed
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: (lint:gosimple) use range over chan instead of for/select
    Signed-off-by: 's avatarmeows <b5c6@protonmail.com>
    
    * miner: refactor update loop to remove race condition
    
    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).
    
    * miner: alternate fix for miner-flaw
    Co-authored-by: 's avatarmeows <b5c6@protonmail.com>
    1e104891
Name
Last commit
Last update
.github Loading commit data...
accounts Loading commit data...
build Loading commit data...
cmd Loading commit data...
common Loading commit data...
consensus Loading commit data...
console Loading commit data...
contracts/checkpointoracle Loading commit data...
core Loading commit data...
crypto Loading commit data...
docs/audits Loading commit data...
eth Loading commit data...
ethclient Loading commit data...
ethdb Loading commit data...
ethstats Loading commit data...
event Loading commit data...
graphql Loading commit data...
internal Loading commit data...
les Loading commit data...
light Loading commit data...
log Loading commit data...
metrics Loading commit data...
miner Loading commit data...
mobile Loading commit data...
node Loading commit data...
p2p Loading commit data...
params Loading commit data...
rlp Loading commit data...
rpc Loading commit data...
signer Loading commit data...
swarm Loading commit data...
tests Loading commit data...
trie Loading commit data...
.dockerignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.golangci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
COPYING Loading commit data...
COPYING.LESSER Loading commit data...
Dockerfile Loading commit data...
Dockerfile.alltools Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
appveyor.yml Loading commit data...
circle.yml Loading commit data...
fuzzbuzz.yaml Loading commit data...
go.mod Loading commit data...
go.sum Loading commit data...
interfaces.go Loading commit data...