|
1 |
| -from eth.vm.forks.frontier.constants import REFUND_SELFDESTRUCT |
2 | 1 | from typing import Type
|
3 | 2 |
|
4 | 3 | from eth_hash.auto import keccak
|
5 |
| -from eth_utils.exceptions import ValidationError |
6 | 4 | from eth_utils import (
|
7 | 5 | encode_hex,
|
8 | 6 | )
|
9 | 7 |
|
10 | 8 | from eth.abc import (
|
11 | 9 | AccountDatabaseAPI,
|
12 |
| - ComputationAPI, |
13 | 10 | MessageAPI,
|
14 | 11 | SignedTransactionAPI,
|
15 | 12 | StateAPI,
|
|
18 | 15 | )
|
19 | 16 | from eth.constants import (
|
20 | 17 | CREATE_CONTRACT_ADDRESS,
|
21 |
| - SECPK1_N, |
22 | 18 | )
|
23 | 19 | from eth.db.account import (
|
24 | 20 | AccountDB
|
@@ -90,82 +86,31 @@ def build_evm_message(self, transaction: SignedTransactionAPI) -> MessageAPI:
|
90 | 86 | )
|
91 | 87 | return message
|
92 | 88 |
|
93 |
| - def finalize_computation( |
94 |
| - self, |
95 |
| - transaction: SignedTransactionAPI, |
96 |
| - computation: ComputationAPI |
97 |
| - ) -> ComputationAPI: |
98 |
| - transaction_context = self.vm_state.get_transaction_context(transaction) |
99 |
| - |
100 |
| - # Self Destruct Refunds |
101 |
| - num_deletions = len(computation.get_accounts_for_deletion()) |
102 |
| - if num_deletions: |
103 |
| - computation.refund_gas(REFUND_SELFDESTRUCT * num_deletions) |
104 |
| - |
105 |
| - # Gas Refunds |
106 |
| - gas_remaining = computation.get_gas_remaining() |
107 |
| - gas_refunded = computation.get_gas_refund() |
108 |
| - gas_used = transaction.gas - gas_remaining |
109 |
| - gas_refund = min(gas_refunded, gas_used // 2) |
110 |
| - gas_refund_amount = (gas_refund + gas_remaining) * transaction_context.gas_price |
111 |
| - |
112 |
| - if gas_refund_amount: |
113 |
| - self.vm_state.logger.debug2( |
114 |
| - 'TRANSACTION REFUND: %s -> %s', |
115 |
| - gas_refund_amount, |
116 |
| - encode_hex(computation.msg.sender), |
117 |
| - ) |
118 |
| - |
119 |
| - self.vm_state.delta_balance(computation.msg.sender, gas_refund_amount) |
120 |
| - |
121 |
| - # Miner Fees |
122 |
| - transaction_fee = \ |
123 |
| - (transaction.gas - gas_remaining - gas_refund) * transaction.max_priority_fee_per_gas |
124 |
| - self.vm_state.logger.debug2( |
125 |
| - 'TRANSACTION FEE: %s -> %s', |
126 |
| - transaction_fee, |
127 |
| - encode_hex(self.vm_state.coinbase), |
128 |
| - ) |
129 |
| - self.vm_state.delta_balance(self.vm_state.coinbase, transaction_fee) |
130 |
| - |
131 |
| - # Process Self Destructs |
132 |
| - for account, _ in computation.get_accounts_for_deletion(): |
133 |
| - # TODO: need to figure out how we prevent multiple selfdestructs from |
134 |
| - # the same account and if this is the right place to put this. |
135 |
| - self.vm_state.logger.debug2('DELETING ACCOUNT: %s', encode_hex(account)) |
136 |
| - |
137 |
| - # TODO: this balance setting is likely superflous and can be |
138 |
| - # removed since `delete_account` does this. |
139 |
| - self.vm_state.set_balance(account, 0) |
140 |
| - self.vm_state.delete_account(account) |
141 |
| - |
142 |
| - return computation |
143 |
| - |
144 | 89 |
|
145 | 90 | class LondonState(BerlinState):
|
146 | 91 | account_db_class: Type[AccountDatabaseAPI] = AccountDB
|
147 | 92 | computation_class = LondonComputation
|
148 | 93 | transaction_executor_class: Type[TransactionExecutorAPI] = LondonTransactionExecutor
|
149 | 94 |
|
| 95 | + def get_tip(self, transaction: SignedTransactionAPI) -> int: |
| 96 | + return min( |
| 97 | + transaction.max_fee_per_gas - self.execution_context.base_fee_per_gas, |
| 98 | + transaction.max_priority_fee_per_gas, |
| 99 | + ) |
| 100 | + |
| 101 | + def get_gas_price(self, transaction: SignedTransactionAPI) -> int: |
| 102 | + return min( |
| 103 | + transaction.max_fee_per_gas, |
| 104 | + transaction.max_priority_fee_per_gas + self.execution_context.base_fee_per_gas, |
| 105 | + ) |
| 106 | + |
150 | 107 | def validate_transaction(
|
151 | 108 | self,
|
152 | 109 | transaction: SignedTransactionAPI
|
153 | 110 | ) -> None:
|
154 |
| - # frontier validation (without the gas price checks) |
155 |
| - sender_nonce = self.get_nonce(transaction.sender) |
156 |
| - if sender_nonce != transaction.nonce: |
157 |
| - raise ValidationError( |
158 |
| - f"Invalid transaction nonce: Expected {sender_nonce}, but got {transaction.nonce}" |
159 |
| - ) |
160 |
| - |
161 |
| - # homestead validation |
162 |
| - if transaction.s > SECPK1_N // 2 or transaction.s == 0: |
163 |
| - raise ValidationError("Invalid signature S value") |
164 |
| - |
165 | 111 | validate_london_normalized_transaction(
|
166 | 112 | state=self,
|
167 | 113 | transaction=transaction,
|
168 |
| - base_fee_per_gas=self.execution_context.base_fee_per_gas |
169 | 114 | )
|
170 | 115 |
|
171 | 116 | def get_transaction_context(self: StateAPI,
|
|
0 commit comments