Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. # Core refactor
  2.  
  3. The following document will describe the necessary items that will be refactored
  4. during the **core refactoring** phase. This eleminary document will describe the
  5. steps required for a clean API for the core components of ethereum which
  6. includes the following packages: core, core/vm, core/state.
  7.  
  8. ## Topics
  9.  
  10. The following topics will see refactoring:
  11.  
  12. * `core`
  13. * `core/vm`
  14.  
  15. Many of the `core` objects are used to modify **state** and many of them stack
  16. to complete modifications. The `core/vm` lacks in documentation and suffers from
  17. code duplication due to the new JIT-VM.
  18.  
  19. ## Tasks
  20.  
  21. - [x] Filter
  22. - [x] Execution object
  23. - [ ] VM Database model
  24. - [x] Cleanup byte code vm
  25. - [x] Context => Contract
  26. - [x] State transition changes
  27. - [x] Remove checkpointing
  28. - [x] ChainManager => BlockChain
  29. - [ ] VM documentation
  30. - [ ] Code setting from VM returned execution
  31. - [ ] VM var cleanup
  32.  
  33. ## Changes
  34.  
  35. The `core.Filter` object and methods no longer use unexported core functionality
  36. and can therefor be moved to the `event/filter` package. Remove the
  37. `core.Backend` dependency from the `core.Filter` objects by adding the following
  38. `core` methods:
  39.  
  40. * `core.GetCurrentBlock(db common.Database)`
  41.  
  42. and remove the dependency on the block manager by directly using
  43. `core.GetBlockReceipts`. These changes require the `core.NewFilter` to take a
  44. `common.Database` argument instead of `core.Backend`.
  45.  
  46. Inside `core/vm` `vm.Transact` needs to be moved to the `core` package. From a
  47. VM point of view "transacting" shouldn't exist. The VM shouldn't handle core
  48. tasks.
  49.  
  50. The `core/vm` depends on the `core/state` packages for handling state changes.
  51. An interface needs to be created that can handle this instead (`vm.Database`)
  52. consisting of the following methods:
  53.  
  54. * AddBalance
  55. * AddRefund
  56. * Delete
  57. * GetBalance
  58. * Get/SetState
  59. * GetCode
  60.  
  61. This will the dependency on the `core/state` packages.
  62.  
  63. Some parts of the core depends on the `vm.Environment` for retrieving the
  64. statedb. Now that `State` has been removed from the environment we can no longer
  65. depend on it (and shouldn't).
  66.  
  67. When a new object (e.g. account) is create - therefor creating a new instance of
  68. the VM - upon returning the VM shouldn't be responsible for any state
  69. modefication. Currently the VM is responsible for checking the error code and
  70. setting the code if it's successful. This should be handled in the core instead
  71. (i.e. `core.Execution`).
  72.  
  73. Cleanup up the VM to use the same type code as the JIT-VM this in order to
  74. further reduce code duplication and reduce maintainability of the code and bugs
  75. that would otherwise be required to be fixed in 2 places. By moving to the JIT
  76. specific instructions it should optimise VM byte code execution by a small
  77. factor.
  78.  
  79. Extend the documentation of `core/vm`
  80.  
  81. * Context method and objects
  82. * Common functions, variables and constants
  83. * Precompiled contracts functions
  84. * Memory methods and object
  85. * Stack method and object
  86.  
  87. Cleanup `core/vm/common.go` and remove unused variables/old variables.
  88.  
  89. The `vm.Context` object, while previous handling more than just contract
  90. related tasks should be renamed to `vm.Contract`. This is much more in line with
  91. with it actual tasks and its purpose.
  92.  
  93. `core` should reduce the amount of objects required to modify **state**. This
  94. should make it much easier to be re-used and will remove some of the requirement
  95. to use the full **ethereum stack**:
  96.  
  97. * `core.Execution` => `core.Create`
  98. * `core.Execution` => `core.Call`
  99. * `core.ApplyMessage` => `core.ApplyTransaction`
  100.  
  101. The `core.ApplyMessage` should be the initialiser of the `core.StateTransition`
  102. object and the `core.NewStateTranstion` method should be removed. No pointer are
  103. required and no dynamic memory allocation is required this way. No pointer will
  104. be escaped.
  105.  
  106. With the merging of the databases we can safely remove the checkpointing from
  107. the chain manager.
  108.  
  109. The `core.ChainManager` object should be renamed to `core.BlockChain` to better
  110. reflect the meaning of the object itself.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement