Skip to content

Commit 083cc4a

Browse files
committed
Move tip v burn logic to Frontier to dedup code
1 parent c4b9075 commit 083cc4a

File tree

2 files changed

+5
-56
lines changed

2 files changed

+5
-56
lines changed

eth/vm/forks/frontier/state.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def build_computation(self,
145145
def finalize_computation(self,
146146
transaction: SignedTransactionAPI,
147147
computation: ComputationAPI) -> ComputationAPI:
148+
transaction_context = self.vm_state.get_transaction_context(transaction)
149+
148150
# Self Destruct Refunds
149151
num_deletions = len(computation.get_accounts_for_deletion())
150152
if num_deletions:
@@ -155,7 +157,7 @@ def finalize_computation(self,
155157
gas_refunded = computation.get_gas_refund()
156158
gas_used = transaction.gas - gas_remaining
157159
gas_refund = min(gas_refunded, gas_used // 2)
158-
gas_refund_amount = (gas_refund + gas_remaining) * transaction.gas_price
160+
gas_refund_amount = (gas_refund + gas_remaining) * transaction_context.gas_price
159161

160162
if gas_refund_amount:
161163
self.vm_state.logger.debug2(
@@ -167,8 +169,8 @@ def finalize_computation(self,
167169
self.vm_state.delta_balance(computation.msg.sender, gas_refund_amount)
168170

169171
# Miner Fees
170-
transaction_fee = \
171-
(transaction.gas - gas_remaining - gas_refund) * transaction.gas_price
172+
gas_used = transaction.gas - gas_remaining - gas_refund
173+
transaction_fee = gas_used * self.vm_state.get_tip(transaction)
172174
self.vm_state.logger.debug2(
173175
'TRANSACTION FEE: %s -> %s',
174176
transaction_fee,

eth/vm/forks/london/state.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from eth.vm.forks.frontier.constants import REFUND_SELFDESTRUCT
21
from typing import Type
32

43
from eth_hash.auto import keccak
@@ -9,7 +8,6 @@
98

109
from eth.abc import (
1110
AccountDatabaseAPI,
12-
ComputationAPI,
1311
MessageAPI,
1412
SignedTransactionAPI,
1513
StateAPI,
@@ -90,57 +88,6 @@ def build_evm_message(self, transaction: SignedTransactionAPI) -> MessageAPI:
9088
)
9189
return message
9290

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-
gas_used = transaction.gas - gas_remaining - gas_refund
123-
transaction_fee = gas_used * self.vm_state.get_tip(transaction)
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-
14491

14592
class LondonState(BerlinState):
14693
account_db_class: Type[AccountDatabaseAPI] = AccountDB

0 commit comments

Comments
 (0)