Skip to content

Commit 7315c57

Browse files
committed
Update the effective gas price calculation + validation + transaction param cleanup
1 parent d90ef79 commit 7315c57

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

eth_tester/backends/mock/serializers.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ def serialize_full_transaction(transaction, block, transaction_index, is_pending
4242
if 'gas_price' in transaction:
4343
return serialized_transaction
4444
else:
45-
return assoc(
46-
serialized_transaction,
47-
'gas_price',
48-
calculate_effective_gas_price(transaction, block)
45+
# TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
46+
# transactions and we can get rid of this behavior.
47+
# https://github.com/ethereum/execution-specs/pull/251
48+
gas_price = (
49+
transaction['max_fee_per_gas'] if is_pending
50+
else calculate_effective_gas_price(transaction, block)
4951
)
52+
return assoc(serialized_transaction, 'gas_price', gas_price)
5053

5154

5255
def serialize_receipt(receipt, transaction, block, transaction_index, is_pending):

eth_tester/backends/pyevm/main.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,24 @@ def get_base_fee(self, block_number='latest'):
498498
#
499499
@to_dict
500500
def _normalize_transaction(self, transaction, block_number='latest'):
501+
# legacy and dynamic fee params
502+
all_fee_params = DYNAMIC_FEE_TRANSACTION_PARAMS + ('gas_price',)
503+
501504
is_dynamic_fee_transaction = (
502-
any(_ in transaction for _ in DYNAMIC_FEE_TRANSACTION_PARAMS)
503-
or not any(_ in transaction for _ in DYNAMIC_FEE_TRANSACTION_PARAMS + ('gas_price',))
505+
any(_ in transaction for _ in DYNAMIC_FEE_TRANSACTION_PARAMS) or
506+
# if no fee params exist, default to dynamic fee transaction:
507+
not any(_ in transaction for _ in all_fee_params)
504508
)
505509

506510
for key in transaction:
507511
if key in ('from', 'type'):
508512
continue
513+
if key == 'gas_price' and is_dynamic_fee_transaction:
514+
# TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
515+
# transactions and we can get rid of this behavior.
516+
# https://github.com/ethereum/execution-specs/pull/251
517+
# take out gas_price from transaction if this is a dynamic fee transaction
518+
continue
509519
yield key, transaction[key]
510520

511521
if 'nonce' not in transaction:

eth_tester/backends/pyevm/serializers.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,13 @@ def serialize_transaction(block, transaction, transaction_index, is_pending):
114114
'access_list': transaction.access_list or (),
115115
'y_parity': transaction.y_parity,
116116

117-
# TODO: Sometime in early 2022 (the merge?), the inclusion of gas_price will be removed
118-
# from dynamic fee transactions and we can get rid of this behavior.
117+
# TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
118+
# transactions and we can get rid of this behavior.
119119
# https://github.com/ethereum/execution-specs/pull/251
120-
'gas_price': _calculate_effective_gas_price(transaction, block, txn_type),
120+
'gas_price': (
121+
transaction.max_fee_per_gas if is_pending
122+
else _calculate_effective_gas_price(transaction, block, txn_type)
123+
),
121124
}
122125
else:
123126
raise ValidationError('Invariant: code path should be unreachable')

eth_tester/main.py

-13
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,13 @@ def func_wrapper(self, *args, **kwargs):
7171
try:
7272
transaction_hash = func(self, *args, **kwargs)
7373
pending_transaction = self.get_transaction_by_hash(transaction_hash)
74-
pending_transaction = _clean_pending_transaction_for_sending(pending_transaction)
7574
# Remove any pending transactions with the same nonce
7675
self._pending_transactions = remove_matching_transaction_from_list(
7776
self._pending_transactions, pending_transaction)
7877
self._pending_transactions.append(pending_transaction)
7978
finally:
8079
self.revert_to_snapshot(snapshot)
8180
return transaction_hash
82-
83-
def _clean_pending_transaction_for_sending(pending_transaction):
84-
cleaned_transaction = dissoc(pending_transaction, 'type')
85-
86-
# TODO: Sometime in early 2022 (the merge?), the inclusion of gas_price will be removed
87-
# from dynamic fee transactions and we can get rid of this behavior.
88-
# https://github.com/ethereum/execution-specs/pull/251
89-
if 'gas_price' and 'max_fee_per_gas' in pending_transaction:
90-
cleaned_transaction = dissoc(cleaned_transaction, 'gas_price')
91-
92-
return cleaned_transaction
93-
9481
return func_wrapper
9582

9683

eth_tester/validation/inbound.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,17 @@ def validate_transaction(value, txn_internal_type):
246246

247247
if 'max_fee_per_gas' in value:
248248
validate_uint256(value['max_fee_per_gas'])
249-
if 'gas_price' in value:
249+
# TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
250+
# transactions and we can get rid of this behavior.
251+
# https://github.com/ethereum/execution-specs/pull/251
252+
# If inbound dynamic fee transaction with gas_price, gas_price value must be equal to the
253+
# max_fee_per_gas.
254+
if 'gas_price' in value and value['gas_price'] != value['max_fee_per_gas']:
250255
raise ValidationError('Mixed legacy and dynamic fee transaction values')
251256

252257
if 'max_priority_fee_per_gas' in value:
253258
validate_uint256(value['max_priority_fee_per_gas'])
254-
if 'gas_price' in value:
259+
if 'gas_price' in value and 'max_fee_per_gas' not in value:
255260
raise ValidationError('Mixed legacy and dynamic fee transaction values')
256261

257262
if 'value' in value:

tests/core/validation/test_outbound_validation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def _make_access_list_txn(chain_id=131277322940537, access_list=[], y_parity=0,
100100

101101
# This is an outbound transaction so we still keep the gas_price for now since the gas_price is
102102
# the min(max_fee_per_gas, base_fee_per_gas + max_priority_fee_per_gas).
103-
# TODO: Sometime in early 2022 (the merge?), the inclusion of gas_price will be removed
104-
# from dynamic fee transactions and we can get rid of this behavior.
103+
# TODO: Sometime in 2022 the inclusion of gas_price may be removed from dynamic fee
104+
# transactions and we can get rid of this behavior.
105105
# https://github.com/ethereum/execution-specs/pull/251
106106
def _make_dynamic_fee_txn(
107107
chain_id=131277322940537,

0 commit comments

Comments
 (0)