You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The APIs on Chain, VM and State have all evolved organically. Now that
we have a better picture of how they are used, we should be able to make some
improvements to make things more intuitive, less stateful, and with reduced
mutation.
How can it be fixed
Terminology
Blocks
Finalized:
A block which has been sealed.
In proof of work this means setting the mix_hash and nonce
HEAD:
The highest finalized block in the chain
TIP:
The unsealed block who's parent is the HEAD block
Chain
The Chain is now the only stateful object with non-pure APIs
rename Chain.header to Chain.tip.
add Chain.head for access to the canonical chain head.
TODO: figure out how to remove the configure_header call and rather start with no header and initialize a new header with the correct params from the block being imported.
VM.finalize_block(block, receipts) -> block
pure
computes receipt and transaction tries.
TODO: define how mixhash and nonce get set on the header.
returns:
the finalized block.
State
The State object is now immutable, only exposing pure functions.
Architecture Refactor for Py-EVM
What is wrong?
The APIs on
Chain
,VM
andState
have all evolved organically. Now thatwe have a better picture of how they are used, we should be able to make some
improvements to make things more intuitive, less stateful, and with reduced
mutation.
How can it be fixed
Terminology
Blocks
mix_hash
andnonce
Chain
The
Chain
is now the only stateful object with non-pure APIsChain.header
toChain.tip
.Chain.head
for access to the canonical chain head.Chain.apply_transaction(transaction) -> computation
Adds the transaction to the current TIP block.
chain.tip
is empty.transaction
on top of the TIP block.chain.header
with the post execution state.transaction
and resultingreceipt
.Chain.import_block(*args, **kwargs) -> block
chain.tip
is empty.VM
to do block import.chain.header
with new tip block header.chain.tip
empty.Chain.finalize_block(*args, **kwargs) -> block
chain.tip
is empty.VM.mine_block
chain.header
with new tip block header.chain.tip
empty.`Chain.initialize_tip(parent=None, **context)
chain.tip
is not empty.chain.tip
with a new fresh header on top ofchain.head
VM
The
VM
object is now immutable, only exposing pure functions.configure_header
in favor of:initialize_block
which initializes the vm with a new empty header with some configured params likecoinbase
,difficulty
, etc.VM.execute_transaction(transaction, block) -> state_root, receipt, computation
block
VM.import_block(block) -> block
configure_header
call and rather start with no header and initialize a new header with the correct params from the block being imported.VM.finalize_block(block, receipts) -> block
mixhash
andnonce
get set on the header.State
The
State
object is now immutable, only exposing pure functions.State.execute_transaction(transaction) -> computation, state_root
The text was updated successfully, but these errors were encountered: