Skip to content

Commit

Permalink
eip1559: exchange baseFeePerGas and maxPriorityFeePerGas
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev committed Jan 12, 2025
1 parent 2664420 commit f796f79
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
13 changes: 6 additions & 7 deletions integration/tests/basic/erc/test_EIP1559.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ def test_too_low_fee(
value=1000000,
nonce="auto",
gas="auto",
max_priority_fee_per_gas=0,
max_fee_per_gas=int(base_fee_per_gas * 0.5),
max_priority_fee_per_gas=int(max_priority_fee_per_gas * 0.75),
max_fee_per_gas=base_fee_per_gas + max_priority_fee_per_gas,
data=None,
access_list=None,
)
Expand All @@ -454,22 +454,21 @@ def test_too_low_fee(
self.web3_client.send_transaction(account=sender, transaction=tx_params, timeout=TX_TIMEOUT)

@pytest.mark.neon_only
@pytest.mark.parametrize("max_priority_fee_per_gas, base_fee_multiplier",
[(1000000000, 1.1), (1000, 1.5)])
@pytest.mark.parametrize("base_fee_multiplier",
[1.1, 1.5])
def test_compute_unit_price(
self,
accounts: EthAccounts,
web3_client: NeonChainWeb3Client,
json_rpc_client: JsonRPCSession,
sol_client: SolanaClient,
max_priority_fee_per_gas,
base_fee_multiplier
):
sender = accounts[0]
recipient = accounts[1]

latest_block: web3.types.BlockData = web3_client._web3.eth.get_block(block_identifier="latest") # noqa
base_fee_per_gas = latest_block.baseFeePerGas # noqa
max_priority_fee_per_gas = web3_client.max_priority_fee_per_gas()
base_fee_per_gas = web3_client.base_fee_per_gas()
max_fee_per_gas = int((base_fee_multiplier * base_fee_per_gas) + max_priority_fee_per_gas)

value = 1029380121
Expand Down
9 changes: 7 additions & 2 deletions integration/tests/basic/evm/opcodes/test_base_opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ def test_base_fee_trx_type_2(
tx = web3_client.make_raw_tx(accounts[0], tx_type=TransactionType.EIP_1559)
instruction_tx = basefee_checker.functions.baseFeeTrx().build_transaction(tx)
instruction_tx["maxFeePerGas"] = 3000000000
instruction_tx["maxPriorityFeePerGas"] = 2000000
instruction_tx["maxPriorityFeePerGas"] = 2500000000
resp = web3_client.send_transaction(accounts[0], instruction_tx)
base_fee_from_log = basefee_checker.events.Log().process_receipt(resp)[0]['args']['baseFee']
assert base_fee_from_log == instruction_tx["maxFeePerGas"] - instruction_tx["maxPriorityFeePerGas"]
# Neon specific, it uses maxPriorityFee to pay an Operator
# it is just an adoption to Ethereum clients
# which use eth_maxPriorityFeePerGas() as a constant
# and increase baseFeePerGas to increase chances to include a Tx into a block
# on Solana the situation is another - increased part of the gasPrice should be used for the Prioritization
assert base_fee_from_log == instruction_tx["maxPriorityFeePerGas"]
4 changes: 2 additions & 2 deletions integration/tests/basic/rpc/test_eip_1559_neon_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_neon_get_transaction_receipt(
recipient = accounts[1]

base_fee_per_gas = web3_client.base_fee_per_gas()
max_priority_fee_per_gas = web3_client._web3.eth._max_priority_fee() # noqa
max_priority_fee_per_gas = web3_client.max_priority_fee_per_gas()
max_fee_per_gas = (5 * base_fee_per_gas) + max_priority_fee_per_gas

receipt = web3_client.send_tokens_eip_1559(
Expand All @@ -94,5 +94,5 @@ def test_neon_get_transaction_receipt(
assert "error" not in response, response["error"]

actual_effective_gas_price = int(response["result"].get("effectiveGasPrice"), 16)
assert actual_effective_gas_price >= base_fee_per_gas
assert actual_effective_gas_price >= max_priority_fee_per_gas
assert actual_effective_gas_price <= max_fee_per_gas
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_multiple_scheduled_trx(
)
trxs = []
max_fee_per_gas = 3000000000
max_priority_fee_per_gas = 15
max_priority_fee_per_gas = 2500000000
for i in range(4):
trxs.append(
ScheduledTransaction(
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_multiple_scheduled_trx_with_failed_trx(
call_data = abi.function_signature_to_4byte_selector("doAssert()")
gas_limit = 30000000
max_fee_per_gas = 3000000000
max_priority_fee_per_gas = 15
max_priority_fee_per_gas = 2500000000

tx0 = ScheduledTransaction(
neon_user.neon_address,
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_scheduled_trx_with_timestamp(

gas_limit = 30000000
max_fee_per_gas = 3000000000
max_priority_fee_per_gas = 15
max_priority_fee_per_gas = 2500000000
trxs = []
for i in range(trx_count):
trxs.append(
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_scheduled_trx_with_small_gas_limit(
)
gas_limit = 3000000
max_fee_per_gas = 3000000000
max_priority_fee_per_gas = 15
max_priority_fee_per_gas = 2500000000

tx0 = ScheduledTransaction(
neon_user.neon_address,
Expand Down
4 changes: 2 additions & 2 deletions utils/scheduled_trx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ScheduledTransaction:
"chain_id": 112,
"gas_limit": 3000000,
"max_fee_per_gas": 3000000000,
"max_priority_fee_per_gas": 15,
"max_priority_fee_per_gas": 2500000000,
}

FIELD_NAMES = [
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_serialized_node(self, child_index, success_limit):


class CreateTreeAccMultipleData:
def __init__(self, nonce, max_fee_per_gas=3000000000, max_priority_fee_per_gas=15):
def __init__(self, nonce, max_fee_per_gas=3000000000, max_priority_fee_per_gas=2500000000):
self.nonce = nonce.to_bytes(8, byteorder="big")
self.max_fee_per_gas = max_fee_per_gas.to_bytes(32, byteorder="big")
self.max_priority_fee_per_gas = max_priority_fee_per_gas.to_bytes(32, byteorder="big")
Expand Down

0 comments on commit f796f79

Please sign in to comment.