Skip to content

Commit

Permalink
Fix issues with gas_price being a string in rpc strategy
Browse files Browse the repository at this point in the history
- All gas_price_strategy implementations expect to return Wei, but some return the hex value without result formatting to int
- Catch a known case / bug where this happens and make sure to convert appropriately when building the transaction params
  • Loading branch information
fselmo committed Jul 26, 2023
1 parent 959151a commit c7df358
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 1 addition & 4 deletions web3/gas_strategies/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from web3 import (
Web3,
)
from web3._utils.rpc_abi import (
RPC,
)
from web3.types import (
TxParams,
Wei,
Expand All @@ -20,4 +17,4 @@ def rpc_gas_price_strategy(
"""
A simple gas price strategy deriving it's value from the eth_gasPrice JSON-RPC call.
"""
return w3.manager.request_blocking(RPC.eth_gasPrice, [])
return w3.eth.gas_price
7 changes: 6 additions & 1 deletion web3/middleware/gas_price_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from eth_utils.toolz import (
assoc,
)
from web3._utils.method_formatters import (
to_integer_if_hex,
)

from web3._utils.utility_methods import (
all_in_dict,
Expand Down Expand Up @@ -45,7 +48,9 @@ def validate_transaction_params(
and "gasPrice" not in transaction
and none_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction)
):
transaction = assoc(transaction, "gasPrice", hex(strategy_based_gas_price))
transaction = assoc(
transaction, "gasPrice", to_integer_if_hex(strategy_based_gas_price)
)

# legacy and dynamic fee tx variables used:
if "gasPrice" in transaction and any_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction):
Expand Down

0 comments on commit c7df358

Please sign in to comment.