-
Notifications
You must be signed in to change notification settings - Fork 350
feat: pass StateOracle as a parameter to state_transition
#1371
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
Draft
kevaundray
wants to merge
11
commits into
ethereum:forks/osaka
Choose a base branch
from
kevaundray:kw/state-oracle
base: forks/osaka
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
974cbcf
add code
kevaundray c214f9f
revert format
kevaundray 4db099e
remove write
kevaundray 3112a1c
format
kevaundray a340007
formatting
kevaundray ed85d8f
python format
kevaundray ad9dd18
python lint
kevaundray d12c5d4
python lint
kevaundray 72df534
temp: hack
kevaundray c07b175
evm_tracer like approach
kevaundray 4a46cb5
tox
kevaundray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,13 +54,6 @@ | |
from .state import ( | ||
State, | ||
TransientStorage, | ||
account_exists_and_is_empty, | ||
destroy_account, | ||
get_account, | ||
increment_nonce, | ||
modify_state, | ||
set_account_balance, | ||
state_root, | ||
) | ||
from .transactions import ( | ||
AccessListTransaction, | ||
|
@@ -189,7 +182,7 @@ def get_last_256_block_hashes(chain: BlockChain) -> List[Hash32]: | |
return recent_block_hashes | ||
|
||
|
||
def state_transition(chain: BlockChain, block: Block) -> None: | ||
def state_transition(chain: BlockChain, block: Block, oracle=None) -> None: | ||
""" | ||
Attempts to apply a block to an existing block chain. | ||
|
||
|
@@ -210,6 +203,8 @@ def state_transition(chain: BlockChain, block: Block) -> None: | |
History and current state. | ||
block : | ||
Block to apply to `chain`. | ||
oracle : MerkleOracle | ||
State oracle for accessing blockchain state. Must be provided. | ||
""" | ||
if len(rlp.encode(block)) > MAX_RLP_BLOCK_SIZE: | ||
raise InvalidBlock("Block rlp size exceeds MAX_RLP_BLOCK_SIZE") | ||
|
@@ -218,9 +213,13 @@ def state_transition(chain: BlockChain, block: Block) -> None: | |
if block.ommers != (): | ||
raise InvalidBlock | ||
|
||
# Oracle must be provided | ||
if oracle is None: | ||
raise ValueError("Oracle parameter is required for state_transition") | ||
|
||
block_env = vm.BlockEnvironment( | ||
chain_id=chain.chain_id, | ||
state=chain.state, | ||
oracle=oracle, | ||
block_gas_limit=block.header.gas_limit, | ||
block_hashes=get_last_256_block_hashes(chain), | ||
coinbase=block.header.coinbase, | ||
|
@@ -237,7 +236,7 @@ def state_transition(chain: BlockChain, block: Block) -> None: | |
transactions=block.transactions, | ||
withdrawals=block.withdrawals, | ||
) | ||
block_state_root = state_root(block_env.state) | ||
block_state_root = block_env.oracle.state_root() | ||
transactions_root = root(block_output.transactions_trie) | ||
receipt_root = root(block_output.receipts_trie) | ||
block_logs_bloom = logs_bloom(block_output.block_logs) | ||
|
@@ -461,7 +460,7 @@ def check_transaction( | |
raise BlobGasLimitExceededError("blob gas limit exceeded") | ||
|
||
sender_address = recover_sender(block_env.chain_id, tx) | ||
sender_account = get_account(block_env.state, sender_address) | ||
sender_account = block_env.oracle.get_account(sender_address) | ||
|
||
if isinstance( | ||
tx, (FeeMarketTransaction, BlobTransaction, SetCodeTransaction) | ||
|
@@ -666,7 +665,7 @@ def process_checked_system_transaction( | |
system_tx_output : `MessageCallOutput` | ||
Output of processing the system transaction. | ||
""" | ||
system_contract_code = get_account(block_env.state, target_address).code | ||
system_contract_code = block_env.oracle.get_account(target_address).code | ||
|
||
if len(system_contract_code) == 0: | ||
raise InvalidBlock( | ||
|
@@ -713,7 +712,7 @@ def process_unchecked_system_transaction( | |
system_tx_output : `MessageCallOutput` | ||
Output of processing the system transaction. | ||
""" | ||
system_contract_code = get_account(block_env.state, target_address).code | ||
system_contract_code = block_env.oracle.get_account(target_address).code | ||
return process_system_transaction( | ||
block_env, | ||
target_address, | ||
|
@@ -870,7 +869,7 @@ def process_transaction( | |
tx=tx, | ||
) | ||
|
||
sender_account = get_account(block_env.state, sender) | ||
sender_account = block_env.oracle.get_account(sender) | ||
|
||
|
||
if isinstance(tx, BlobTransaction): | ||
blob_gas_fee = calculate_data_fee(block_env.excess_blob_gas, tx) | ||
|
@@ -880,13 +879,13 @@ def process_transaction( | |
effective_gas_fee = tx.gas * effective_gas_price | ||
|
||
gas = tx.gas - intrinsic_gas | ||
increment_nonce(block_env.state, sender) | ||
block_env.oracle.increment_nonce(sender) | ||
|
||
sender_balance_after_gas_fee = ( | ||
Uint(sender_account.balance) - effective_gas_fee - blob_gas_fee | ||
) | ||
set_account_balance( | ||
block_env.state, sender, U256(sender_balance_after_gas_fee) | ||
block_env.oracle.set_account_balance( | ||
sender, U256(sender_balance_after_gas_fee) | ||
) | ||
|
||
access_list_addresses = set() | ||
|
@@ -949,26 +948,29 @@ def process_transaction( | |
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas | ||
|
||
# refund gas | ||
sender_balance_after_refund = get_account( | ||
block_env.state, sender | ||
).balance + U256(gas_refund_amount) | ||
set_account_balance(block_env.state, sender, sender_balance_after_refund) | ||
current_sender_balance = block_env.oracle.get_account(sender).balance | ||
sender_balance_after_refund = current_sender_balance + U256( | ||
gas_refund_amount | ||
) | ||
block_env.oracle.set_account_balance(sender, sender_balance_after_refund) | ||
|
||
# transfer miner fees | ||
coinbase_balance_after_mining_fee = get_account( | ||
block_env.state, block_env.coinbase | ||
).balance + U256(transaction_fee) | ||
current_coinbase_balance = block_env.oracle.get_account( | ||
block_env.coinbase | ||
).balance | ||
coinbase_balance_after_mining_fee = current_coinbase_balance + U256( | ||
transaction_fee | ||
) | ||
if coinbase_balance_after_mining_fee != 0: | ||
set_account_balance( | ||
block_env.state, | ||
block_env.oracle.set_account_balance( | ||
block_env.coinbase, | ||
coinbase_balance_after_mining_fee, | ||
) | ||
elif account_exists_and_is_empty(block_env.state, block_env.coinbase): | ||
destroy_account(block_env.state, block_env.coinbase) | ||
elif block_env.oracle.account_exists_and_is_empty(block_env.coinbase): | ||
block_env.oracle.destroy_account(block_env.coinbase) | ||
|
||
for address in tx_output.accounts_to_delete: | ||
destroy_account(block_env.state, address) | ||
block_env.oracle.destroy_account(address) | ||
|
||
block_output.block_gas_used += tx_gas_used_after_refund | ||
block_output.blob_gas_used += tx_blob_gas_used | ||
|
@@ -1008,10 +1010,10 @@ def increase_recipient_balance(recipient: Account) -> None: | |
rlp.encode(wd), | ||
) | ||
|
||
modify_state(block_env.state, wd.address, increase_recipient_balance) | ||
block_env.oracle.modify_state(wd.address, increase_recipient_balance) | ||
|
||
if account_exists_and_is_empty(block_env.state, wd.address): | ||
destroy_account(block_env.state, wd.address) | ||
if block_env.oracle.account_exists_and_is_empty(wd.address): | ||
block_env.oracle.destroy_account(wd.address) | ||
|
||
|
||
def check_gas_limit(gas_limit: Uint, parent_gas_limit: Uint) -> bool: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main TLDR; the object that is used to fetch state is now an explicit parameter to the state transition function instead of it being implicit