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 Should be public #33

Closed
wanderer opened this issue Jan 17, 2016 · 4 comments · Fixed by #264
Closed

StateManager Should be public #33

wanderer opened this issue Jan 17, 2016 · 4 comments · Fixed by #264

Comments

@wanderer
Copy link
Member

It would be nice to expose the StateManager publically. And split it into its own module. What should the API be?

@wanderer
Copy link
Member Author

currently the API is

  • getAccount
  • exists // checks if an account exists
  • _putAccount
  • getAccountBalance
  • putAccountBalance
  • putContractCode
  • getContractCode
  • _lookupStorageTrie
  • _getStorageTrie
  • getContractStorage
  • putContractStorage
  • commitContracts
  • revertContracts
  • getBlockHash
  • checkpoint
  • commit
  • revert
  • getStateRoot
  • warmCache
  • dumpStorage
  • hasGenesisState
  • generateCanonicalGenesis
  • generateGenesis

Also It would be nice to inculde the following from https://github.com/ethereumjs/ethereumjs-account

  • account.getCode(trie, cb)
  • account.setCode(trie, code, cb)
  • account.getStorage(trie, key, cb)
  • account.setStorage(trie, key, val, cb)

@kumavis
Copy link
Member

kumavis commented Jan 17, 2016

the stateManager is the semantic layer over the merkle-patricia-tree.

two things to consider in terms of api design:

  • how to get data from the blockchain (e.g. balance for account x)
  • how to provide data from the blockchain (e.g. lazily from a remote node)

on the data-providing side:

for the provider engine I wanted to be able to override contract code set/gets and storage set/gets
It was possible but it would be nice if this was a little easier
https://github.com/MetaMask/provider-engine/blob/bcc101b75212fc19175d827112f369d225573230/subproviders/vm.js#L94-L98
I used:

  • _lookupStorageTrie
  • cache._lookupAccount
  • getContractCode
  • setContractCode

EDIT: update link to point to correct lines and be locked to commit

@kumavis
Copy link
Member

kumavis commented Oct 24, 2016

Here is an example of how providing a custom StateManager could be very useful:

Creating a vm backed by an arbitrary data source (here as eth rpc data lookups)
https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/hooked.js#L79-L84

@kumavis
Copy link
Member

kumavis commented Dec 1, 2016

here is an example of a module consumer overwriting StateManager https://github.com/ethereum/browser-solidity/pull/345/files

@axic axic self-assigned this Feb 2, 2018
@axic axic closed this as completed in #264 Feb 3, 2018
@axic axic removed the in progress label Feb 3, 2018
holgerd77 added a commit to holgerd77/ethereumjs-vm that referenced this issue Nov 30, 2020
holgerd77 added a commit that referenced this issue Dec 1, 2020
holgerd77 pushed a commit that referenced this issue Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants