Skip to content

Commit

Permalink
Add unstable warning for async providers
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jun 4, 2021
1 parent d4b2815 commit 46953d1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
4 changes: 1 addition & 3 deletions tests/integration/go_ethereum/test_goethereum_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ async def async_w3(geth_process, endpoint_uri):
async_gas_price_strategy_middleware,
async_buffered_gas_estimate_middleware
],
modules={
'eth': (AsyncEth,),
})
modules={'eth': (AsyncEth,)})
return _web3


Expand Down
8 changes: 4 additions & 4 deletions web3/_utils/async_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

if TYPE_CHECKING:
from web3 import Web3 # noqa: F401
from web3.eth import AsyncEth, Eth # noqa: F401
from web3.eth import AsyncEth # noqa: F401


async def get_block_gas_limit(
Expand All @@ -25,13 +25,13 @@ async def get_block_gas_limit(


async def get_buffered_gas_estimate(
web3_eth: "Eth", transaction: TxParams, gas_buffer: Wei = Wei(100000)
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
) -> Wei:
gas_estimate_transaction = cast(TxParams, dict(**transaction))

gas_estimate = await web3_eth.estimate_gas(gas_estimate_transaction) # type: ignore
gas_estimate = await web3.eth.estimate_gas(gas_estimate_transaction) # type: ignore

gas_limit = await get_block_gas_limit(web3_eth) # type: ignore
gas_limit = await get_block_gas_limit(web3.eth) # type: ignore

if gas_estimate > gas_limit:
raise ValueError(
Expand Down
13 changes: 6 additions & 7 deletions web3/_utils/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

if TYPE_CHECKING:
from web3 import Web3 # noqa: F401
from web3.eth import Eth # noqa: F401


@curry
Expand Down Expand Up @@ -113,21 +112,21 @@ def wait_for_transaction_receipt(
return txn_receipt


def get_block_gas_limit(web3_eth: "Eth", block_identifier: Optional[BlockIdentifier] = None) -> Wei:
def get_block_gas_limit(web3: "Web3", block_identifier: Optional[BlockIdentifier] = None) -> Wei:
if block_identifier is None:
block_identifier = web3_eth.block_number
block = web3_eth.get_block(block_identifier)
block_identifier = web3.eth.block_number
block = web3.eth.get_block(block_identifier)
return block['gasLimit']


def get_buffered_gas_estimate(
web3_eth: "Eth", transaction: TxParams, gas_buffer: Wei = Wei(100000)
web3: "Web3", transaction: TxParams, gas_buffer: Wei = Wei(100000)
) -> Wei:
gas_estimate_transaction = cast(TxParams, dict(**transaction))

gas_estimate = web3_eth.estimate_gas(gas_estimate_transaction)
gas_estimate = web3.eth.estimate_gas(gas_estimate_transaction)

gas_limit = get_block_gas_limit(web3_eth)
gas_limit = get_block_gas_limit(web3)

if gas_estimate > gas_limit:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions web3/middleware/buffered_gas_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
transaction = assoc(
transaction,
'gas',
hex(get_buffered_gas_estimate(web3.eth, transaction)),
hex(get_buffered_gas_estimate(web3, transaction)),
)
return make_request(method, [transaction])
return make_request(method, params)
Expand All @@ -48,7 +48,7 @@ async def middleware(method: RPCEndpoint, params: Any) -> RPCResponse:
if method == 'eth_sendTransaction':
transaction = params[0]
if 'gas' not in transaction:
gas_estimate = await async_get_buffered_gas_estimate(web3.eth, transaction)
gas_estimate = await async_get_buffered_gas_estimate(web3, transaction)
transaction = assoc(
transaction,
'gas',
Expand Down
6 changes: 6 additions & 0 deletions web3/providers/async_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Tuple,
cast,
)
import warnings

from eth_utils import (
to_bytes,
Expand Down Expand Up @@ -35,6 +36,11 @@ class AsyncBaseProvider:
# a tuple of (all_middlewares, request_func)
_request_func_cache: Tuple[Tuple[Middleware, ...], Callable[..., RPCResponse]] = (None, None)

def __init__(self) -> None:
warnings.warn(
"Async providers are still being developed and refined. "
"Expect breaking changes in minor releases.")

@property
def middlewares(self) -> Tuple[Middleware, ...]:
return self._middlewares
Expand Down
1 change: 1 addition & 0 deletions web3/providers/eth_tester/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from .main import ( # noqa: F401
EthereumTesterProvider,
AsyncEthereumTesterProvider,
)
5 changes: 0 additions & 5 deletions web3/providers/eth_tester/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@


class AsyncEthereumTesterProvider(AsyncBaseProvider):
"""This is a placeholder.
For now its purpose is to provide an awaitable request function
for testing the async api execution.
"""
def __init__(self) -> None:
self.eth_tester = EthereumTesterProvider()

Expand Down
1 change: 1 addition & 0 deletions web3/tools/benchmark/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def unlocked_account(w3: "Web3") -> ChecksumAddress:


async def async_unlocked_account(w3: Web3, w3_eth: Eth) -> ChecksumAddress:
# change w3_eth type to w3_eth: AsyncEth once AsyncEth reflects Eth
coinbase = await w3_eth.coinbase # type: ignore
w3.geth.personal.unlock_account(coinbase, KEYFILE_PW)
return coinbase
Expand Down

0 comments on commit 46953d1

Please sign in to comment.