This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
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.
Fixes conditions described in trufflesuite/ganache#453 and trufflesuite/ganache#417
get
onundefined
is caused by races aroundgetDBs
When doing a checkpoint we end up with two dbs and all reads (getRaw->db.get) happen on both asynchronously. When things are committed or reverted the second db goes away and the in-flight get will try the second instance (think
db[0] / db[1]
) that's not there anymore and fail with undefined .One case (in
getRaw
) was trickier and is partially a break of encapsulation problem:getRaw
should probably be private but is called directly from Account.This means that access needs to be synchronized around anything that would race for db instances.
Many of the operations were already using semaphores for this however some didn't (e.g.
checkpoint
,get
). The problem with the last race was due to direct access togetRaw
fromAccount.prototype.getCode
. Again IMO this is mostly an encapsulation problem as get should probably be used instead (and perhaps that's the right fix, although I'd say it would also require makinggetRaw
"private".The alternative (which is what is include in the patch) for a local fix is to mark the under-lock state with a flag (param), based on which's absence (if flag is off) the semaphore can be acquired to avoid the race.
The pop issue, is a logical one and happened due to propagation (or lack thereof) of
not found
errors fromdb.get
operations.Lastly, the merkle-patricia-tree code is more complex than it perhaps should given the functionality (deep callback stack, mutual recursion, heavy async, etc.). In addition the stuff around it, there may be other issues lying around,
As a caveat - now with the get / pop issues out of the way I can sometimes see
Initially I was concerned that they were somehow introduced by these fixes and tried to see how but that wasn't the case (not sure how they occur though) however I've confirmed them without the fixes as well.