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

Implementing VMState and Refactoring Computation #244

Merged
merged 13 commits into from
Dec 29, 2017

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Dec 29, 2017

What was wrong?

  1. This PR is for Implement State object #236 - Implement VMState object.
  2. After discussion with @gsalgado and @pipermerriam in State Object #240, I open a new PR includes refactoring Computation class.

How was it fixed?

  1. New VMState class - class represents the VM state while the VM is at rest
    1. Move codes of accessing AccountStateDB from BaseVM to VMState class.
      • Snapshot and Revert
      • VMState.get_ancestor_hash()
      • Access to the current block header information (coinbase/timestamp/block_number/difficulty/gas_limit)
  2. Computation refactoring - represents the VM state while the VM is running
    1. Make Computation configurable and specified for each VM.
    2. Move all of the state transition codes from VM to Computation. I found that message and vm_state could be just assigned in initialization function:Computation.__init__(vm_state, message, opcodes, precompiles)
      • @classmethod Computation.apply_computation(vm_state, message, opcodes, precompiles): Modify it to be a classmethod. Hope @pipermerriam can take a look if it's a weird anti pattern…?
      • Computation.apply_message()
      • Computation.apply_create_message()
      • Computation.opcodes
      • Computation.precompiles
      • Computation.get_opcode_fn()
    3. Modify apply_child_computation(child_msg).
      • It calls a classmethod Computation.generate_child_computation(vm_state, child_msg, opcodes, precompiles) to generate the child_compuation and then call Computation.add_child_computation(child_computation).
  3. Rename StateDB to AccountStateDB.

TODO

  • Next PR will refactor block object (Make them dumb data containers). It may include:
    1. Move VM.apply_transaction(transaction) function to VMState.apply_transactionn(transaction)
    2. Move VM.execute_transaction(transaction) function to VMState.execute_transaction(transaction)
    3. Move Block.add_transaction(transaction, computation) to VMState.execute_transaction(transaction, computation)
    4. Move Block.make_receipt(transaction, computation) to VMState.make_receipt(transaction, computation)

Cute Animal Picture

cute

@pipermerriam
Copy link
Member

:shipit: whenever you're ready.

@gsalgado
Copy link
Collaborator

gsalgado commented Jan 2, 2018

Looks great, thanks for considering my suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants