13
13
"""
14
14
15
15
from dataclasses import dataclass
16
- from typing import Any , List , Optional , Tuple
16
+ from typing import List , Optional , Tuple
17
17
18
18
from ethereum_rlp import rlp
19
19
from ethereum_types .bytes import Bytes
@@ -179,9 +179,7 @@ def get_last_256_block_hashes(chain: BlockChain) -> List[Hash32]:
179
179
return recent_block_hashes
180
180
181
181
182
- def state_transition (
183
- chain : BlockChain , block : Block , oracle : Optional [Any ] = None
184
- ) -> None :
182
+ def state_transition (chain : BlockChain , block : Block ) -> None :
185
183
"""
186
184
Attempts to apply a block to an existing block chain.
187
185
@@ -212,13 +210,9 @@ def state_transition(
212
210
if block .ommers != ():
213
211
raise InvalidBlock
214
212
215
- # Oracle must be provided
216
- if oracle is None :
217
- raise ValueError ("Oracle parameter is required for state_transition" )
218
-
219
213
block_env = vm .BlockEnvironment (
220
214
chain_id = chain .chain_id ,
221
- oracle = oracle ,
215
+ state = chain . state ,
222
216
block_gas_limit = block .header .gas_limit ,
223
217
block_hashes = get_last_256_block_hashes (chain ),
224
218
coinbase = block .header .coinbase ,
@@ -235,7 +229,7 @@ def state_transition(
235
229
transactions = block .transactions ,
236
230
withdrawals = block .withdrawals ,
237
231
)
238
- block_state_root = block_env .oracle .state_root ()
232
+ block_state_root = block_env .get_oracle () .state_root ()
239
233
transactions_root = root (block_output .transactions_trie )
240
234
receipt_root = root (block_output .receipts_trie )
241
235
block_logs_bloom = logs_bloom (block_output .block_logs )
@@ -459,7 +453,7 @@ def check_transaction(
459
453
raise BlobGasLimitExceededError ("blob gas limit exceeded" )
460
454
461
455
sender_address = recover_sender (block_env .chain_id , tx )
462
- sender_account = block_env .oracle .get_account (sender_address )
456
+ sender_account = block_env .get_oracle () .get_account (sender_address )
463
457
464
458
if isinstance (
465
459
tx , (FeeMarketTransaction , BlobTransaction , SetCodeTransaction )
@@ -664,7 +658,9 @@ def process_checked_system_transaction(
664
658
system_tx_output : `MessageCallOutput`
665
659
Output of processing the system transaction.
666
660
"""
667
- system_contract_code = block_env .oracle .get_account (target_address ).code
661
+ system_contract_code = (
662
+ block_env .get_oracle ().get_account (target_address ).code
663
+ )
668
664
669
665
if len (system_contract_code ) == 0 :
670
666
raise InvalidBlock (
@@ -711,7 +707,9 @@ def process_unchecked_system_transaction(
711
707
system_tx_output : `MessageCallOutput`
712
708
Output of processing the system transaction.
713
709
"""
714
- system_contract_code = block_env .oracle .get_account (target_address ).code
710
+ system_contract_code = (
711
+ block_env .get_oracle ().get_account (target_address ).code
712
+ )
715
713
return process_system_transaction (
716
714
block_env ,
717
715
target_address ,
@@ -868,7 +866,7 @@ def process_transaction(
868
866
tx = tx ,
869
867
)
870
868
871
- sender_account = block_env .oracle .get_account (sender )
869
+ sender_account = block_env .get_oracle () .get_account (sender )
872
870
873
871
if isinstance (tx , BlobTransaction ):
874
872
blob_gas_fee = calculate_data_fee (block_env .excess_blob_gas , tx )
@@ -878,12 +876,12 @@ def process_transaction(
878
876
effective_gas_fee = tx .gas * effective_gas_price
879
877
880
878
gas = tx .gas - intrinsic_gas
881
- block_env .oracle .increment_nonce (sender )
879
+ block_env .get_oracle () .increment_nonce (sender )
882
880
883
881
sender_balance_after_gas_fee = (
884
882
Uint (sender_account .balance ) - effective_gas_fee - blob_gas_fee
885
883
)
886
- block_env .oracle .set_account_balance (
884
+ block_env .get_oracle () .set_account_balance (
887
885
sender , U256 (sender_balance_after_gas_fee )
888
886
)
889
887
@@ -947,29 +945,33 @@ def process_transaction(
947
945
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
948
946
949
947
# refund gas
950
- current_sender_balance = block_env .oracle .get_account (sender ).balance
948
+ current_sender_balance = block_env .get_oracle () .get_account (sender ).balance
951
949
sender_balance_after_refund = current_sender_balance + U256 (
952
950
gas_refund_amount
953
951
)
954
- block_env .oracle .set_account_balance (sender , sender_balance_after_refund )
952
+ block_env .get_oracle ().set_account_balance (
953
+ sender , sender_balance_after_refund
954
+ )
955
955
956
956
# transfer miner fees
957
- current_coinbase_balance = block_env . oracle . get_account (
958
- block_env .coinbase
959
- ). balance
957
+ current_coinbase_balance = (
958
+ block_env .get_oracle (). get_account ( block_env . coinbase ). balance
959
+ )
960
960
coinbase_balance_after_mining_fee = current_coinbase_balance + U256 (
961
961
transaction_fee
962
962
)
963
963
if coinbase_balance_after_mining_fee != 0 :
964
- block_env .oracle .set_account_balance (
964
+ block_env .get_oracle () .set_account_balance (
965
965
block_env .coinbase ,
966
966
coinbase_balance_after_mining_fee ,
967
967
)
968
- elif block_env .oracle .account_exists_and_is_empty (block_env .coinbase ):
969
- block_env .oracle .destroy_account (block_env .coinbase )
968
+ elif block_env .get_oracle ().account_exists_and_is_empty (
969
+ block_env .coinbase
970
+ ):
971
+ block_env .get_oracle ().destroy_account (block_env .coinbase )
970
972
971
973
for address in tx_output .accounts_to_delete :
972
- block_env .oracle .destroy_account (address )
974
+ block_env .get_oracle () .destroy_account (address )
973
975
974
976
block_output .block_gas_used += tx_gas_used_after_refund
975
977
block_output .blob_gas_used += tx_blob_gas_used
@@ -1009,10 +1011,12 @@ def increase_recipient_balance(recipient: Account) -> None:
1009
1011
rlp .encode (wd ),
1010
1012
)
1011
1013
1012
- block_env .oracle .modify_state (wd .address , increase_recipient_balance )
1014
+ block_env .get_oracle ().modify_state (
1015
+ wd .address , increase_recipient_balance
1016
+ )
1013
1017
1014
- if block_env .oracle .account_exists_and_is_empty (wd .address ):
1015
- block_env .oracle .destroy_account (wd .address )
1018
+ if block_env .get_oracle () .account_exists_and_is_empty (wd .address ):
1019
+ block_env .get_oracle () .destroy_account (wd .address )
1016
1020
1017
1021
1018
1022
def check_gas_limit (gas_limit : Uint , parent_gas_limit : Uint ) -> bool :
0 commit comments