ethereum / populus

The Ethereum development framework with the most cute animal pictures
http://populus.readthedocs.org/
321 stars 321 forks source link

Race condition exception in `wait_for_transaction_receipt` #443

Open paultiplady opened 6 years ago

paultiplady commented 6 years ago

What was wrong?

When deploying a contract to Rinkeby, and immediately starting a wait for the transaction receipt, an exception is raised:

gateway/contract/tests/e2e/e2e_test_deploy.py:9 (test_deploy)
gateway/contract/tests/e2e/e2e_test_deploy.py:36: in test_deploy
    contract_address = chain.wait.for_contract_address(deploy_tx_hash)
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/populus/wait.py:33: in for_contract_address
    txn_receipt = self.for_receipt(txn_hash, **kwargs)
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/populus/wait.py:47: in for_receipt
    return wait_for_transaction_receipt(self.web3, txn_hash, **kwargs)
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/populus/utils/wait.py:94: in wait_for_transaction_receipt
    poll_interval_fn=lambda: poll_interval if poll_interval is not None else random.random(),
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/populus/utils/wait.py:77: in poll_until
    value = poll_fn()
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/web3/eth.py:192: in getTransactionReceipt
    [transaction_hash],
../../.virtualenvs/ethereum-xPw_EAxE/lib/python3.5/site-packages/web3/manager.py:96: in request_blocking
    raise ValueError(response["error"])
E   ValueError: {'code': -32000, 'message': 'unknown transaction'}

The code in question is:

Token = chain.provider.get_contract_factory('Token')
deploy_tx_hash = Token.deploy(
    transaction={
        'from': owner,
    },
    kwargs={
        'totalSupply': 1000,
        'name': 'TestToken',
    },
)
contract_address = chain.wait.for_contract_address(deploy_tx_hash)

If I insert a sleep(60) or sit in the debugger until the txn has committed on Etherscan, the call succeeds.

The exception is being raised from here: https://github.com/ethereum/web3.py/blob/master/web3/manager.py#L102

Looks like wait_for_transaction_receipt should perhaps handle exceptions generated in web3.py?

https://github.com/ethereum/populus/blob/master/populus/utils/wait.py#L89-L95

Cute Animal Picture

put a cute animal picture here. image

paultiplady commented 6 years ago

Digging a bit more, this error is not showing up on geth version 1.7.3-stable (built from source), but it is on geth 1.8.1 (bundled with Mist). Could be some changes to the RPC format, or something else wacky going on.

I'll update as I find further info, won't have much more time to look at this today.

carver commented 6 years ago

@paultiplady Yes, please follow https://github.com/ethereum/web3.py/issues/655 for progress. It's a change in how geth 1.8 works that isn't addressed in web3.py yet.