-
Notifications
You must be signed in to change notification settings - Fork 756
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
Remove vm accesses to stateManager trie and cache #376
Remove vm accesses to stateManager trie and cache #376
Conversation
Hi Matthew, cool, I did a complex (or at least broadly scoped) API doc refactoring PR merge #377 in between and also merged the Then I think we get your stuff merged relatively quickly. Cheers, Holger (relaxing a bit at the hotel :-)) |
b08d5cb
to
26e6541
Compare
I've rebased and updated the docs to include the change to the |
Hold off reviewing this for now as it's causing extra failing blockchain tests. Will investigate |
26e6541
to
d759d35
Compare
Rebased this. |
var trie = opts.state || new Trie() | ||
if (opts.activatePrecompiles) { | ||
trie = new Trie() | ||
for (var i = 1; i <= 8; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally irritated, was this one precompile forgotten before and this is an implicit fix (you are iterating up to 8 and not to 7)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks that way...
Additionally failing tests: OOGStateCopyContainingDeletedContract, 542, 544 |
@@ -217,13 +227,11 @@ module.exports = function (opts, cb) { | |||
if (ethUtil.bufferToInt(block.header.gasUsed) !== Number(gasUsed)) { | |||
err = new Error((err || '') + 'invalid gasUsed ') | |||
} | |||
if (self.stateManager.trie.root.toString('hex') !== block.header.stateRoot.toString('hex')) { | |||
if (stateRoot.toString('hex') !== block.header.stateRoot.toString('hex')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra failures are happening here, not sure why yet, probably you'll get this faster than me.
When I run node ./tests/tester.js -b --file='suicideStorageCheck'
, looking at the first test and and add console output for the first and second state root value, I get:
211aca80b1d1084fd9a18fda2afbc5bdf3866d06c5321660e105546e79fded8d
334d8d12b70ab372703f37bf6c9fed76c7c61ba1f131517123d5d440776d825a
On the old version I get both:
334d8d12b70ab372703f37bf6c9fed76c7c61ba1f131517123d5d440776d825a
334d8d12b70ab372703f37bf6c9fed76c7c61ba1f131517123d5d440776d825a
d759d35
to
80c1c34
Compare
Right we're back to 50 failing blockchain tests. I'm not quite happy that I understand quite why what I've changed works, but I have an inkling. I'd recommend we hold off of merging until I've done a bit more digging |
Ok, no rush here. |
f3eef12
to
86d2b05
Compare
So after a bit of investigating, I found that the changes introduced in #375 were not particularly compatible with the work I've been doing on #309. Essentially the issue is that the My additional changes make it so that the This has made this PR, once again, larger than I would like. The alternative would be to split this up to first change the |
86d2b05
to
c399832
Compare
I now merged the |
c399832
to
d9cca33
Compare
Rebased as requested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looks good, thanks again Matthew!
@@ -6,13 +6,12 @@ const async = require('async') | |||
var Cache = module.exports = function (trie) { | |||
this._cache = Tree() | |||
this._checkpoints = [] | |||
this._deletes = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring seems to make very much sense, to remove this separate delete stack and put it in the values itself.
runState.stateManager.putAccount(runState.address, runState.contract, function (err) { | ||
if (err) return cb(err) | ||
runState._vm.runCall(callOptions, parseCallResults) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
// credit all block rewards | ||
if (generateStateRoot) { | ||
block.header.stateRoot = stateRoot | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
* @property {Account} account the [`Account`](https://github.com/ethereum/ethereumjs-account) which owns the code running | ||
* @property {Buffer} address the address of the `account` | ||
* @property {Number} depth the current number of calls deep the contract is | ||
* @property {Buffer} memory the memory of the VM as a `buffer` | ||
* @property {FunctionalRedBlackTree} cache the account cache. Contains all the accounts loaded from the trie. It is an instance of [functional red black tree](https://www.npmjs.com/package/functional-red-black-tree) | ||
* @property {StateManager} storageManager a state manager instance (EXPERIMENTAL - unstable API) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that this aligned documentation is already used and further evolved and corrected, really glad that I once went through this hazzle, even if there might be still some glizzles every here and there to be corrected.
self.stateManager.commit(function (err) { | ||
cb(err, results) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
self.stateManager.cache.put(block.header.coinbase, minerAccount) | ||
self.stateManager.putAccount(block.header.coinbase, minerAccount, next) | ||
} else { | ||
next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
|
||
function cleanTouched (done) { | ||
self.stateManager.cleanupTouchedAccounts(done) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
}) | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is evolving into a really clean and easy-to-grasp well-named API, nice! 👍
Have re-read your initial comments, think changes to |
This is part of the broader discussion in #268 and #309 so readers should probably start there.
This PR removes all direct accesses, from the VM functions, to the
cache
andtrie
properties ofstateManager
. This is essentially done by replacing calls to these properties to the equivalentstateManager
functions.There are potentially two more controversial change here. The first is the removal of the
loadCompiled
method on the VM. This method is unused internally and undocumented. It is problematic to keep this function as it interferes with checkpoint/commit structure used instateManager
. My assumption is that if someone desires this functionality they would interact with thestateManager
directly prior to instantiating the vm. The second is the change of thestep
event which now exposes thestateManager
instance rather than thecache
. This is essentially a breaking change as the event object structure is documented.