This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 680
fix: save evm_mine
blocks before returning
#3016
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MicaiahReid
force-pushed
the
fix/mining-race-condition
branch
from
May 5, 2022 14:25
e084843
to
e024fb5
Compare
MicaiahReid
commented
May 5, 2022
MicaiahReid
commented
May 5, 2022
MicaiahReid
changed the title
Fix/mining race condition
fix: save May 5, 2022
evm_mine
blocks before returning
MicaiahReid
force-pushed
the
fix/mining-race-condition
branch
from
May 5, 2022 16:20
a1353c1
to
79e7bda
Compare
Thoughts on adding tests for this new timing behavior? |
I mean our Yeah, I'll get some tests added. |
@davidmurdoch I've added a test! I'm instantiating a provider where I specify the db using the I've created a branch that has these tests without the actual race condition fixes as a proof that the tests do what I say they should, and that my changes actually fix the bug. |
davidmurdoch
suggested changes
May 20, 2022
davidmurdoch
approved these changes
May 26, 2022
jeffsmale90
suggested changes
May 29, 2022
jeffsmale90
approved these changes
May 31, 2022
MicaiahReid
force-pushed
the
fix/mining-race-condition
branch
from
May 31, 2022 21:16
1a48bbb
to
9884de0
Compare
davidmurdoch
pushed a commit
that referenced
this pull request
Jun 2, 2022
* await _saving_ block before returning evm_mine * delay emitting block til next event loop in eager blocktime mode * remove manual awaitBlockSaving * await `blockBeingSavedPromise` after mining * add back newline * add memdown and patch-package as dev dep * add patch to memdown to delay _batch calls by 20ms * add test for mining race condition * remove patch package; monkey patch instead * remove patch-package dependency * assert memdown patch works * add clarifying comment * remove unneeded return
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Though it was rare, sometimes calling
evm_mine
would return before the mined block was actually saved. If you polled for the block that Ganache had claimed to mine directly after callingevm_mine
, that block could not yet exist.This change ensures that the block is saved before emitting the
"newHeads"
subscription message and before returning during anevm_mine
. Fixes #3060.Potential Side Effect
This change does have one potential side effect, though we really doubt anyone should be impacted, and we consider it a bug fix. Sometimes when a block is mined, Ganache waits until the next iteration of the event loop (using
setImmediate
) to emit the mined block. This is to ensure that the user has time to listen for the new block's"message"
before Ganache emits it.Previously, Ganache would delay emitting this event if
--miner.instamine="eager"
AND--miner.blockTime=0
. These settings mean that transactions are saved before returning the transaction (as apposed to returning a hash as the transaction enters the transaction pool in"strict"
mode), and the miner immediately starts mining transactions as they enter the transaction pool (as opposed to mining a block everyblockTime
seconds).*Now, Ganache delays emitting this event when
--miner.instamine="eager"
regardless of howblockTime
is set. The instamine mode affects when the transaction is returned to the user, so it should be the driving factor behind delaying the event. If in--miner.blockTime=0
mode (the default) you somehow relied on the event being emitted at a very specific event tick, this may cause issues for you. For most of us mere mortal developers, this won't make a difference.*Note: We'll have a blog post or discussion providing a deeper dive into all of our mining modes soon that should help further clarify
--miner.instamine
,--miner.blockTime
, and--chain.vmErrorsOnRPCResponse
.