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

StateManager interface #763

Merged
merged 7 commits into from
Jun 5, 2020
Merged

StateManager interface #763

merged 7 commits into from
Jun 5, 2020

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jun 4, 2020

So I've added an interface for the StateManager. Had to make a few other changes:

  • The precompile activation logic was using stateManager._trie directly, replaced that with putAccount.
  • Also the blake2f precompile wasn't activated because the addresses were hardcoded. Fixed now.
  • _clearOriginalStorageCache was private, made it public. The issue is that StateManager is persistent state, but the originalStorageCache should only persist for the duration of one tx.

Should I move the docs to the interface or leave them in the implementation? Also please feel free to suggest better names for DefaultStateManager :D

@codecov
Copy link

codecov bot commented Jun 4, 2020

Codecov Report

Merging #763 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #763      +/-   ##
==========================================
+ Coverage   92.01%   92.06%   +0.05%     
==========================================
  Files          47       46       -1     
  Lines        3018     3025       +7     
  Branches      472      471       -1     
==========================================
+ Hits         2777     2785       +8     
  Misses        145      145              
+ Partials       96       95       -1     
Flag Coverage Δ
#account 94.11% <ø> (ø)
#block 88.36% <ø> (+0.27%) ⬆️
#blockchain 89.15% <ø> (+0.41%) ⬆️
#common 93.78% <ø> (ø)
#tx 94.02% <ø> (-0.14%) ⬇️
#vm 93.10% <100.00%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
packages/vm/lib/runTx.ts 91.02% <ø> (-0.12%) ⬇️
packages/vm/lib/index.ts 97.10% <100.00%> (+0.04%) ⬆️
packages/vm/lib/state/index.ts 100.00% <100.00%> (ø)
packages/vm/lib/state/stateManager.ts 91.45% <100.00%> (+0.08%) ⬆️
packages/tx/src/index.ts
packages/blockchain/src/cache.ts 100.00% <0.00%> (+20.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28b8fa4...5ff3354. Read the comment docs.

@s1na s1na force-pushed the statemanager-iface branch from 8cc790c to 255c51f Compare June 4, 2020 10:59
@s1na
Copy link
Contributor Author

s1na commented Jun 4, 2020

Rebased master, that should hopefully fix the codecov issue? also should I rebuild the docs in the PR or is that done at release?

@s1na s1na requested review from ryanio and holgerd77 and removed request for ryanio June 4, 2020 11:30
@lgtm-com
Copy link

lgtm-com bot commented Jun 4, 2020

This pull request introduces 1 alert when merging 255c51f into 61c3dca - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@evertonfraga
Copy link
Contributor

@s1na I got started late today, but it seems Codecov issue is gone.

image

And LGTM finally finished its report.

Comment on lines -148 to +155
const trie = this.stateManager._trie
const put = promisify(trie.put.bind(trie))
for (let i = 1; i <= 8; i++) {
await put(new BN(i).toArrayLike(Buffer, 'be', 20), new Account().serialize())
}
this.stateManager.checkpoint()
Object.keys(precompiles)
.map((k: string): Buffer => Buffer.from(k, 'hex'))
.forEach(async (k: Buffer) => await this.stateManager.putAccount(k, new Account()))
await this.stateManager.commit()
Copy link
Contributor

Choose a reason for hiding this comment

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

nice improvement

[key: string]: string
}

export interface StateManager {
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

ryanio
ryanio previously approved these changes Jun 4, 2020
Copy link
Contributor

@ryanio ryanio left a comment

Choose a reason for hiding this comment

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

looks great!

@ryanio
Copy link
Contributor

ryanio commented Jun 4, 2020

also should I rebuild the docs in the PR or is that done at release?

@s1na you can rebuild, I usually do it as a last commit.

it would be a nice improvement to ensure docs automatically rebuild prior to release, @evertonfraga and I have already discussed this so it's on our (long) wishlist :)

Should I move the docs to the interface or leave them in the implementation?

I have a feeling it would be better in the interface, but I guess it depends how TypeDoc organizes and outputs them. Feel free to try both ways and pick which one you think results in better docs.

Also please feel free to suggest better names for DefaultStateManager :D

Seems good to me! I'll keep thinking about it. How do you anticipate future StateManagers might be named? that might give some insight.

@evertonfraga
Copy link
Contributor

yeah, IMO having the docs generated for each PR change ensures the docs reflect exactly what’s on master branch.

Thinking of people that land on the project to experiment, having tidy docs can only help them =)

@s1na
Copy link
Contributor Author

s1na commented Jun 5, 2020

Note to self: stateManager._touched is also cleared at the end of the tx, but by checking on commit() whether the lists of checkpoints is emtpy. Same trick can probably be used for the storage original cache.

@evertonfraga
Copy link
Contributor

Also the blake2f precompile wasn't activated because the addresses were hardcoded. Fixed now.

Hi @s1na, before I move on with rebase & merge, I wanted to understand the aforementioned change. Pardon my ignorance (😄), but where exactly is this issue fixed, and what's the impact of the current state (eg: blake2f not operational)?

@s1na
Copy link
Contributor Author

s1na commented Jun 5, 2020

Hey @evertonfraga, no it only fixes a small edge case. Contracts that call blake2f will work. For context on what activatePrecompiles does see #575. In this case the new precompile wasn't being "activated" (confusing terminology) as you can see here https://github.com/ethereumjs/ethereumjs-vm/pull/763/files#diff-1c815e0b4a51825344018a6a6c522733L150 (note the range i = 0; i < 8; i++ which doesn't cover i = 9 which is the blake2f address).

Sorry I haven't the PR yet, my working tree for this branch is dirty because I just started working on the flat db without creating a new branch... will update now with re-built docs and dropping the clearOriginalStorageCache method.

@evertonfraga
Copy link
Contributor

@s1na thanks for the explanation! Yes, the activated precompiles terminology have caught me. I have seen that activation behavior before, just didn't know its name or where it was represented in the code. Thanks for pointing it out.

I will now rebase and merge this PR. Sounds good?

@lgtm-com
Copy link

lgtm-com bot commented Jun 5, 2020

This pull request introduces 1 alert when merging 56a8731 into 6ac21f6 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@s1na
Copy link
Contributor Author

s1na commented Jun 5, 2020

Update: I made clearOriginalStorageCache private again (so its not part of the interface), and removed it from runTx. It's now run implicitly when the highest-level checkpoint terminates. This happens when a tx has finished processing (but could happen in other cases too, hope its not confusing).

Oh and I'm not sure if this PR should be considered a breaking change due to StateManager being renamed to DefaultStateManager?

Also tried rebuilding docs but couldn't get it to work, was constantly getting an error.

If everything looks good the PR can be merged.

@evertonfraga
Copy link
Contributor

evertonfraga commented Jun 5, 2020

Update: I made clearOriginalStorageCache private again (so its not part of the interface), and removed it from runTx.

Alright!

Oh and I'm not sure if this PR should be considered a breaking change due to StateManager being renamed to DefaultStateManager?

The VM will be bumped to v5.0.0 anyway, so we shouldn't worry much about it. I will, of course, make a note about this change in the release notes.

Also tried rebuilding docs but couldn't get it to work, was constantly getting an error.

I'll handle it!

@evertonfraga evertonfraga self-requested a review June 5, 2020 18:24
evertonfraga
evertonfraga previously approved these changes Jun 5, 2020
@lgtm-com
Copy link

lgtm-com bot commented Jun 5, 2020

This pull request introduces 1 alert when merging 282fdfb into 28b8fa4 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@holgerd77
Copy link
Member

Short note: did a branch update here, hope that was ok, so that it might be merge-ready once CI pass.

@lgtm-com
Copy link

lgtm-com bot commented Jun 5, 2020

This pull request introduces 1 alert when merging 5ff3354 into 28b8fa4 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

LGTM

@holgerd77 holgerd77 merged commit 2b8b314 into master Jun 5, 2020
@holgerd77 holgerd77 deleted the statemanager-iface branch June 5, 2020 20:03
@evertonfraga
Copy link
Contributor

Thanks @holgerd77!

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.

4 participants