Skip to content

Commit 7df3b8b

Browse files
committed
chore(specs): refactor block reward and fee refunds
1 parent d7def91 commit 7df3b8b

24 files changed

Lines changed: 40 additions & 193 deletions

File tree

src/ethereum/forks/amsterdam/fork.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
from .state_tracker import (
7171
BlockState,
7272
TransactionState,
73-
account_exists_and_is_empty,
7473
create_ether,
7574
destroy_account,
7675
extract_block_diff,
@@ -1054,19 +1053,10 @@ def process_transaction(
10541053
transaction_fee = tx_gas_used * priority_fee_per_gas
10551054

10561055
# refund gas
1057-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
1058-
gas_refund_amount
1059-
)
1060-
set_account_balance(tx_state, sender, sender_balance_after_refund)
1056+
create_ether(tx_state, sender, U256(gas_refund_amount))
10611057

10621058
# transfer miner fees
1063-
coinbase_balance_after_mining_fee = get_account(
1064-
tx_state, block_env.coinbase
1065-
).balance + U256(transaction_fee)
1066-
1067-
set_account_balance(
1068-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
1069-
)
1059+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
10701060

10711061
# EIP-7708: Emit burn logs for balances held by accounts marked for
10721062
# deletion AFTER miner fee transfer.
@@ -1088,11 +1078,6 @@ def process_transaction(
10881078

10891079
all_logs = tx_output.logs + tuple(finalization_logs)
10901080

1091-
if coinbase_balance_after_mining_fee == 0 and account_exists_and_is_empty(
1092-
tx_state, block_env.coinbase
1093-
):
1094-
destroy_account(tx_state, block_env.coinbase)
1095-
10961081
block_output.cumulative_gas_used += tx_gas_used
10971082
block_output.block_gas_used += block_gas_used_in_tx
10981083
block_output.blob_gas_used += tx_blob_gas_used

src/ethereum/forks/arrow_glacier/fork.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,7 @@ def process_transaction(
818818
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
819819

820820
# refund gas
821-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
822-
gas_refund_amount
823-
)
824-
set_account_balance(tx_state, sender, sender_balance_after_refund)
821+
create_ether(tx_state, sender, U256(gas_refund_amount))
825822

826823
# transfer miner fees
827824
coinbase_balance_after_mining_fee = get_account(

src/ethereum/forks/berlin/fork.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,7 @@ def process_transaction(
703703
transaction_fee = tx_gas_used_after_refund * tx.gas_price
704704

705705
# refund gas
706-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
707-
gas_refund_amount
708-
)
709-
set_account_balance(tx_state, sender, sender_balance_after_refund)
706+
create_ether(tx_state, sender, U256(gas_refund_amount))
710707

711708
# transfer miner fees
712709
coinbase_balance_after_mining_fee = get_account(

src/ethereum/forks/bpo1/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,18 +954,10 @@ def process_transaction(
954954
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
955955

956956
# refund gas
957-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
958-
gas_refund_amount
959-
)
960-
set_account_balance(tx_state, sender, sender_balance_after_refund)
957+
create_ether(tx_state, sender, U256(gas_refund_amount))
961958

962959
# transfer miner fees
963-
coinbase_balance_after_mining_fee = get_account(
964-
tx_state, block_env.coinbase
965-
).balance + U256(transaction_fee)
966-
set_account_balance(
967-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
968-
)
960+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
969961

970962
for address in tx_output.accounts_to_delete:
971963
destroy_account(tx_state, address)

src/ethereum/forks/bpo2/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,18 +954,10 @@ def process_transaction(
954954
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
955955

956956
# refund gas
957-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
958-
gas_refund_amount
959-
)
960-
set_account_balance(tx_state, sender, sender_balance_after_refund)
957+
create_ether(tx_state, sender, U256(gas_refund_amount))
961958

962959
# transfer miner fees
963-
coinbase_balance_after_mining_fee = get_account(
964-
tx_state, block_env.coinbase
965-
).balance + U256(transaction_fee)
966-
set_account_balance(
967-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
968-
)
960+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
969961

970962
for address in tx_output.accounts_to_delete:
971963
destroy_account(tx_state, address)

src/ethereum/forks/bpo3/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,18 +954,10 @@ def process_transaction(
954954
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
955955

956956
# refund gas
957-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
958-
gas_refund_amount
959-
)
960-
set_account_balance(tx_state, sender, sender_balance_after_refund)
957+
create_ether(tx_state, sender, U256(gas_refund_amount))
961958

962959
# transfer miner fees
963-
coinbase_balance_after_mining_fee = get_account(
964-
tx_state, block_env.coinbase
965-
).balance + U256(transaction_fee)
966-
set_account_balance(
967-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
968-
)
960+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
969961

970962
for address in tx_output.accounts_to_delete:
971963
destroy_account(tx_state, address)

src/ethereum/forks/bpo4/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,18 +954,10 @@ def process_transaction(
954954
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
955955

956956
# refund gas
957-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
958-
gas_refund_amount
959-
)
960-
set_account_balance(tx_state, sender, sender_balance_after_refund)
957+
create_ether(tx_state, sender, U256(gas_refund_amount))
961958

962959
# transfer miner fees
963-
coinbase_balance_after_mining_fee = get_account(
964-
tx_state, block_env.coinbase
965-
).balance + U256(transaction_fee)
966-
set_account_balance(
967-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
968-
)
960+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
969961

970962
for address in tx_output.accounts_to_delete:
971963
destroy_account(tx_state, address)

src/ethereum/forks/bpo5/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -954,18 +954,10 @@ def process_transaction(
954954
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
955955

956956
# refund gas
957-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
958-
gas_refund_amount
959-
)
960-
set_account_balance(tx_state, sender, sender_balance_after_refund)
957+
create_ether(tx_state, sender, U256(gas_refund_amount))
961958

962959
# transfer miner fees
963-
coinbase_balance_after_mining_fee = get_account(
964-
tx_state, block_env.coinbase
965-
).balance + U256(transaction_fee)
966-
set_account_balance(
967-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
968-
)
960+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
969961

970962
for address in tx_output.accounts_to_delete:
971963
destroy_account(tx_state, address)

src/ethereum/forks/byzantium/fork.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,7 @@ def process_transaction(
680680
transaction_fee = tx_gas_used_after_refund * tx.gas_price
681681

682682
# refund gas
683-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
684-
gas_refund_amount
685-
)
686-
set_account_balance(tx_state, sender, sender_balance_after_refund)
683+
create_ether(tx_state, sender, U256(gas_refund_amount))
687684

688685
# transfer miner fees
689686
coinbase_balance_after_mining_fee = get_account(

src/ethereum/forks/cancun/fork.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,10 @@ def process_transaction(
769769
transaction_fee = tx_gas_used_after_refund * priority_fee_per_gas
770770

771771
# refund gas
772-
sender_balance_after_refund = get_account(tx_state, sender).balance + U256(
773-
gas_refund_amount
774-
)
775-
set_account_balance(tx_state, sender, sender_balance_after_refund)
772+
create_ether(tx_state, sender, U256(gas_refund_amount))
776773

777774
# transfer miner fees
778-
coinbase_balance_after_mining_fee = get_account(
779-
tx_state, block_env.coinbase
780-
).balance + U256(transaction_fee)
781-
set_account_balance(
782-
tx_state, block_env.coinbase, coinbase_balance_after_mining_fee
783-
)
775+
create_ether(tx_state, block_env.coinbase, U256(transaction_fee))
784776

785777
for address in tx_output.accounts_to_delete:
786778
destroy_account(tx_state, address)

0 commit comments

Comments
 (0)