From 5d3945d094688e571b8b09886ea0e4261ba0688a Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 11 Aug 2021 11:50:14 -0600 Subject: [PATCH 1/5] Revert fee history commit (d722f3) --- newsfragments/2038.feature.rst | 1 - tests/integration/test_ethereum_tester.py | 12 ----- web3/_utils/method_formatters.py | 12 ----- web3/_utils/module_testing/eth_module.py | 57 ----------------------- web3/_utils/rpc_abi.py | 1 - web3/eth.py | 24 ---------- web3/providers/eth_tester/defaults.py | 1 - web3/types.py | 7 --- 8 files changed, 115 deletions(-) delete mode 100644 newsfragments/2038.feature.rst diff --git a/newsfragments/2038.feature.rst b/newsfragments/2038.feature.rst deleted file mode 100644 index a6685e2b5e..0000000000 --- a/newsfragments/2038.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Add support for eth_feeHistory RPC method diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index 8698f41f1c..172f7d1e10 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -284,18 +284,6 @@ def test_eth_getBlockByHash_pending( block = web3.eth.get_block('pending') assert block['hash'] is not None - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') - def test_eth_fee_history(self, web3: "Web3"): - super().test_eth_fee_history(web3) - - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') - def test_eth_fee_history_with_integer(self, web3: "Web3"): - super().test_eth_fee_history_with_integer(web3) - - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') - def test_eth_fee_history_no_reward_percentiles(self, web3: "Web3"): - super().test_eth_fee_history_no_reward_percentiles(web3) - @pytest.mark.xfail(reason='EIP 1559 is not implemented on eth-tester') def test_eth_get_transaction_receipt_unmined(self, eth_tester, web3, unlocked_account): super().test_eth_get_transaction_receipt_unmined(web3, unlocked_account) diff --git a/web3/_utils/method_formatters.py b/web3/_utils/method_formatters.py index cc4b87ea69..807595c061 100644 --- a/web3/_utils/method_formatters.py +++ b/web3/_utils/method_formatters.py @@ -278,16 +278,6 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]: TRANSACTION_POOL_INSPECT_FORMATTERS ) -FEE_HISTORY_FORMATTERS = { - 'baseFeePerGas': apply_formatter_to_array(to_integer_if_hex), - 'gasUsedRatio': apply_formatter_if(is_not_null, apply_formatter_to_array(float)), - 'oldestBlock': to_integer_if_hex, - 'reward': apply_formatter_if(is_not_null, apply_formatter_to_array( - apply_formatter_to_array(to_integer_if_hex))), -} - -fee_history_formatter = apply_formatters_to_dict(FEE_HISTORY_FORMATTERS) - STORAGE_PROOF_FORMATTERS = { 'key': HexBytes, 'value': HexBytes, @@ -392,7 +382,6 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]: PYTHONIC_REQUEST_FORMATTERS: Dict[RPCEndpoint, Callable[..., Any]] = { # Eth - RPC.eth_feeHistory: apply_formatter_at_index(to_hex_if_integer, 1), RPC.eth_getBalance: apply_formatter_at_index(to_hex_if_integer, 1), RPC.eth_getBlockByNumber: apply_formatter_at_index(to_hex_if_integer, 0), RPC.eth_getBlockTransactionCountByNumber: apply_formatter_at_index( @@ -452,7 +441,6 @@ def apply_list_to_array_formatter(formatter: Any) -> Callable[..., Any]: RPC.eth_coinbase: to_checksum_address, RPC.eth_call: HexBytes, RPC.eth_estimateGas: to_integer_if_hex, - RPC.eth_feeHistory: fee_history_formatter, RPC.eth_maxPriorityFeePerGas: to_integer_if_hex, RPC.eth_gasPrice: to_integer_if_hex, RPC.eth_getBalance: to_integer_if_hex, diff --git a/web3/_utils/module_testing/eth_module.py b/web3/_utils/module_testing/eth_module.py index 7da391ff2d..4f2ae0ad8f 100644 --- a/web3/_utils/module_testing/eth_module.py +++ b/web3/_utils/module_testing/eth_module.py @@ -353,36 +353,6 @@ async def test_eth_estimate_gas( assert is_integer(gas_estimate) assert gas_estimate > 0 - @pytest.mark.asyncio - async def test_eth_fee_history(self, async_w3: "Web3") -> None: - fee_history = await async_w3.eth.fee_history(1, 'latest', [50]) # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) - - @pytest.mark.asyncio - async def test_eth_fee_history_with_integer( - self, async_w3: "Web3", empty_block: BlockData - ) -> None: - fee_history = await async_w3.eth.fee_history(1, empty_block['number'], [50]) # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) - - @pytest.mark.asyncio - async def test_eth_fee_history_no_reward_percentiles(self, async_w3: "Web3") -> None: - fee_history = await async_w3.eth.fee_history(1, 'latest') # type: ignore - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - @pytest.mark.asyncio async def test_eth_max_priority_fee(self, async_w3: "Web3") -> None: max_priority_fee = await async_w3.eth.max_priority_fee # type: ignore @@ -662,33 +632,6 @@ def test_eth_chainId(self, web3: "Web3") -> None: # chain id value from geth fixture genesis file assert chain_id == 131277322940537 - def test_eth_fee_history(self, web3: "Web3") -> None: - fee_history = web3.eth.fee_history(1, 'latest', [50]) - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) - - def test_eth_fee_history_with_integer(self, - web3: "Web3", - empty_block: BlockData) -> None: - fee_history = web3.eth.fee_history(1, empty_block['number'], [50]) - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - assert is_list_like(fee_history['reward']) - assert is_list_like(fee_history['reward'][0]) - - def test_eth_fee_history_no_reward_percentiles(self, web3: "Web3") -> None: - fee_history = web3.eth.fee_history(1, 'latest') - assert is_list_like(fee_history['baseFeePerGas']) - assert is_list_like(fee_history['gasUsedRatio']) - assert is_integer(fee_history['oldestBlock']) - assert fee_history['oldestBlock'] >= 0 - def test_eth_gas_price(self, web3: "Web3") -> None: gas_price = web3.eth.gas_price assert is_integer(gas_price) diff --git a/web3/_utils/rpc_abi.py b/web3/_utils/rpc_abi.py index e904c5a0bc..6a73ee4e17 100644 --- a/web3/_utils/rpc_abi.py +++ b/web3/_utils/rpc_abi.py @@ -46,7 +46,6 @@ class RPC: eth_chainId = RPCEndpoint("eth_chainId") eth_coinbase = RPCEndpoint("eth_coinbase") eth_estimateGas = RPCEndpoint("eth_estimateGas") - eth_feeHistory = RPCEndpoint("eth_feeHistory") eth_maxPriorityFeePerGas = RPCEndpoint("eth_maxPriorityFeePerGas") eth_gasPrice = RPCEndpoint("eth_gasPrice") eth_getBalance = RPCEndpoint("eth_getBalance") diff --git a/web3/eth.py b/web3/eth.py index 0de738635c..9fec1ee9dd 100644 --- a/web3/eth.py +++ b/web3/eth.py @@ -87,9 +87,7 @@ ENS, BlockData, BlockIdentifier, - BlockParams, CallOverrideParams, - FeeHistory, FilterParams, GasPriceStrategy, LogReceipt, @@ -178,11 +176,6 @@ def estimate_gas_munger( mungers=[estimate_gas_munger] ) - _fee_history: Method[Callable[..., FeeHistory]] = Method( - RPC.eth_feeHistory, - mungers=[default_root_munger] - ) - _max_priority_fee: Method[Callable[..., Wei]] = Method( RPC.eth_maxPriorityFeePerGas, mungers=None, @@ -257,15 +250,6 @@ async def gas_price(self) -> Wei: async def max_priority_fee(self) -> Wei: return await self._max_priority_fee() # type: ignore - async def fee_history( - self, - block_count: int, - newest_block: Union[BlockParams, BlockNumber], - reward_percentiles: Optional[List[float]] = None - ) -> FeeHistory: - return await self._fee_history( # type: ignore - block_count, newest_block, reward_percentiles) - async def send_transaction(self, transaction: TxParams) -> HexBytes: # types ignored b/c mypy conflict with BlockingEth properties return await self._send_transaction(transaction) # type: ignore @@ -727,14 +711,6 @@ def estimate_gas( ) -> Wei: return self._estimate_gas(transaction, block_identifier) - def fee_history( - self, - block_count: int, - newest_block: Union[BlockParams, BlockNumber], - reward_percentiles: Optional[List[float]] = None - ) -> FeeHistory: - return self._fee_history(block_count, newest_block, reward_percentiles) - def filter_munger( self, filter_params: Optional[Union[str, FilterParams]] = None, diff --git a/web3/providers/eth_tester/defaults.py b/web3/providers/eth_tester/defaults.py index 982d41caba..2cbbafcf6d 100644 --- a/web3/providers/eth_tester/defaults.py +++ b/web3/providers/eth_tester/defaults.py @@ -213,7 +213,6 @@ def personal_send_transaction(eth_tester: "EthereumTester", params: Any) -> HexS 'mining': static_return(False), 'hashrate': static_return(0), 'chainId': static_return('0x3d'), - 'feeHistory': not_implemented, 'maxPriorityFeePerGas': not_implemented, 'gasPrice': static_return(1), 'accounts': call_eth_tester('get_accounts'), diff --git a/web3/types.py b/web3/types.py index 042fdd4ab9..7236443c54 100644 --- a/web3/types.py +++ b/web3/types.py @@ -144,13 +144,6 @@ class FilterParams(TypedDict, total=False): topics: Sequence[Optional[Union[_Hash32, Sequence[_Hash32]]]] -class FeeHistory(TypedDict): - baseFeePerGas: List[Wei] - gasUsedRatio: List[float] - oldestBlock: BlockNumber - reward: List[List[Wei]] - - class LogReceipt(TypedDict): address: ChecksumAddress blockHash: HexBytes From 5b0b291d4dc843217c0a5c74f8d103fa7e9801e8 Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 11 Aug 2021 13:00:53 -0600 Subject: [PATCH 2/5] Revert "Clarify feeHistory docs and add param types" This reverts commit 34875cc836734c5c89855d11b23208cee66b0e2a. --- docs/web3.eth.rst | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 9ce98ffa8c..75145f3e05 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -1051,27 +1051,25 @@ The following methods are available on the ``web3.eth`` namespace. * Delegates to ``eth_feeHistory`` RPC Method - Returns transaction fee data for up to 1,024 blocks. - - :param block_count: The number of blocks in the requested range. This value should be an :py:class:`int` between 1 - and 1024. Less than requested may be returned if not all blocks are available. - :type block_count: int - :param newest_block: The newest, highest-numbered, block in the requested range. This value may be an - :py:class:`int` or one of the predefined block parameters ``'latest'``, ``'earliest'``, or ``'pending'``. - :type newest_block: int or BlockParams - :param reward_percentiles: *(optional)* A monotonically increasing list of percentile :py:class:`float` values to - sample from each block's effective priority fees per gas in ascending order, weighted by gas used. - :type reward_percentiles: List[float] or None - :return: An ``AttributeDict`` containing the following keys: - - * **oldestBlock** *(int)* -- The oldest, lowest-numbered, block in the range requested as a ``BlockNumber`` type - with :py:class:`int` value. - * **baseFeePerGas** *(List[Wei])* -- An array of block base fees per gas. This includes the next block after the - newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for - pre-EIP-1559 blocks. - * **gasUsedRatio** *(List[float])* -- An array of ``gasUsed``/``gasLimit`` float values for the requested blocks. - * **reward** *(List[List[Wei]])* -- *(optional)* A two-dimensional array of effective priority fees per gas at the - requested block percentiles. + Returns transaction fee data for up to 1024 blocks. + + Parameters: + + * ``block_count``: The number of blocks in the requested range. This value is a number between 1 and 1024. + Less than requested may be returned if not all blocks are available. + * ``newest_block``: The newest, highest-numbered, block in the requested range. + * ``reward_percentiles`` (optional): A monotonically increasing list of percentile values to sample from each + block's effective priority fees per gas in ascending order, weighted by gas used. + + Return data: + + * ``oldestBlock``: The oldest, lowest-numbered, block in the range requested. + * ``baseFeePerGas``: An array of block base fees per gas. This includes the next block after the newest of the + returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 + blocks. + * ``gasUsedRatio``: An array of ``gasUsed``/``gasLimit`` values for the requested blocks. + * ``reward`` (optional): An array of effective priority fee per gas data points from a single block. + All zeroes are returned if the block is empty. .. code-block:: python From ab8d191e25fb6d1582dc07aea55b5ab9c85342d1 Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 11 Aug 2021 13:01:27 -0600 Subject: [PATCH 3/5] Revert "Cleanup fee_history documentation" This reverts commit 96ff6505f65d82daf62cd61a913bcf963865fcc1. --- docs/web3.eth.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 75145f3e05..6119c3d099 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -116,6 +116,40 @@ The following properties are available on the ``web3.eth`` namespace. >>> web3.eth.hashrate 906 +.. py:attribute:: Eth.fee_history + + * Delegates to ``eth_feeHistory`` RPC Method + + Returns transaction fee data for up to 1024 blocks. + + Parameters: + + * ``block_count``: The number of blocks in the requested range. This value is a number between 1 and 1024. + Less than requested may be returned if not all blocks are available. + * ``newest_block``: The newest, highest-numbered, block in the requested range. + * ``reward_percentiles`` (optional): A monotonically increasing list of percentile values to sample from each + block's effective priority fees per gas in ascending order, weighted by gas used. + + Return data: + + * ``oldestBlock``: The oldest, lowest-numbered, block in the range requested. + * ``baseFeePerGas``: An array of block base fees per gas. This includes the next block after the newest of the + returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 + blocks. + * ``gasUsedRatio``: An array of ``gasUsed``/``gasLimit`` values for the requested blocks. + * ``reward`` (optional): An array of effective priority fee per gas data points from a single block. + All zeroes are returned if the block is empty. + + .. code-block:: python + + >>> w3.eth.fee_history(4, 'latest', [10, 90]) + AttributeDict({ + 'oldestBlock': 3, + 'reward': [[220, 7145389], [1000000, 6000213], [550, 550], [125, 12345678]], + 'baseFeePerGas': [202583058, 177634473, 155594425, 136217133, 119442408], + 'gasUsedRatio': [0.007390479689642084, 0.0036988514889990873, 0.0018512333048507866, 0.00741217041320997] + }) + .. py:attribute:: Eth.max_priority_fee From 639ad45eaec47e1c3e4a1c4ec1602f4d025f154f Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 11 Aug 2021 13:01:44 -0600 Subject: [PATCH 4/5] Revert "Move feeHistory docs to appropriate "method" documentation" This reverts commit e75d9f2ce89d831910d207bb6acdc629f06f54ca. --- docs/web3.eth.rst | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 6119c3d099..28ed957fe9 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -1081,41 +1081,6 @@ The following methods are available on the ``web3.eth`` namespace. for a list of possible parameters. -.. py:method:: Eth.fee_history(block_count, newest_block, reward_percentiles=None) - - * Delegates to ``eth_feeHistory`` RPC Method - - Returns transaction fee data for up to 1024 blocks. - - Parameters: - - * ``block_count``: The number of blocks in the requested range. This value is a number between 1 and 1024. - Less than requested may be returned if not all blocks are available. - * ``newest_block``: The newest, highest-numbered, block in the requested range. - * ``reward_percentiles`` (optional): A monotonically increasing list of percentile values to sample from each - block's effective priority fees per gas in ascending order, weighted by gas used. - - Return data: - - * ``oldestBlock``: The oldest, lowest-numbered, block in the range requested. - * ``baseFeePerGas``: An array of block base fees per gas. This includes the next block after the newest of the - returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 - blocks. - * ``gasUsedRatio``: An array of ``gasUsed``/``gasLimit`` values for the requested blocks. - * ``reward`` (optional): An array of effective priority fee per gas data points from a single block. - All zeroes are returned if the block is empty. - - .. code-block:: python - - >>> w3.eth.fee_history(4, 'latest', [10, 90]) - AttributeDict({ - 'oldestBlock': 3, - 'reward': [[220, 7145389], [1000000, 6000213], [550, 550], [125, 12345678]], - 'baseFeePerGas': [202583058, 177634473, 155594425, 136217133, 119442408], - 'gasUsedRatio': [0.007390479689642084, 0.0036988514889990873, 0.0018512333048507866, 0.00741217041320997] - }) - - .. py:method:: Eth.estimate_gas(transaction, block_identifier=None) * Delegates to ``eth_estimateGas`` RPC Method From 9a2c9a762d6850079638b56f933d14fa36c34b53 Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 11 Aug 2021 13:02:35 -0600 Subject: [PATCH 5/5] Revert "Add docs for eth.fee_history usage" This reverts commit 0259afd884046092ce7a4efe8b0abed2989d9a9f. --- docs/web3.eth.rst | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/docs/web3.eth.rst b/docs/web3.eth.rst index 28ed957fe9..f68c0791e9 100644 --- a/docs/web3.eth.rst +++ b/docs/web3.eth.rst @@ -116,40 +116,6 @@ The following properties are available on the ``web3.eth`` namespace. >>> web3.eth.hashrate 906 -.. py:attribute:: Eth.fee_history - - * Delegates to ``eth_feeHistory`` RPC Method - - Returns transaction fee data for up to 1024 blocks. - - Parameters: - - * ``block_count``: The number of blocks in the requested range. This value is a number between 1 and 1024. - Less than requested may be returned if not all blocks are available. - * ``newest_block``: The newest, highest-numbered, block in the requested range. - * ``reward_percentiles`` (optional): A monotonically increasing list of percentile values to sample from each - block's effective priority fees per gas in ascending order, weighted by gas used. - - Return data: - - * ``oldestBlock``: The oldest, lowest-numbered, block in the range requested. - * ``baseFeePerGas``: An array of block base fees per gas. This includes the next block after the newest of the - returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 - blocks. - * ``gasUsedRatio``: An array of ``gasUsed``/``gasLimit`` values for the requested blocks. - * ``reward`` (optional): An array of effective priority fee per gas data points from a single block. - All zeroes are returned if the block is empty. - - .. code-block:: python - - >>> w3.eth.fee_history(4, 'latest', [10, 90]) - AttributeDict({ - 'oldestBlock': 3, - 'reward': [[220, 7145389], [1000000, 6000213], [550, 550], [125, 12345678]], - 'baseFeePerGas': [202583058, 177634473, 155594425, 136217133, 119442408], - 'gasUsedRatio': [0.007390479689642084, 0.0036988514889990873, 0.0018512333048507866, 0.00741217041320997] - }) - .. py:attribute:: Eth.max_priority_fee