Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck transactions - graceful handling? #1115

Open
skgbanga opened this issue Jun 16, 2021 · 1 comment
Open

Stuck transactions - graceful handling? #1115

skgbanga opened this issue Jun 16, 2021 · 1 comment

Comments

@skgbanga
Copy link

Hello,

I noticed a weird thing in which sometimes (about ~1%) brownie says that it has sent a transaction, but then is just stuck. e.g.

Transaction sent: 0xtransaction_hash
<waiting>

I looked into the code a little bit, and noticed this while True loop.

    def _await_transaction(self, required_confs: int, is_blocking: bool) -> None:
        # await tx showing in mempool
        while True:
            try:
                tx: Dict = web3.eth.get_transaction(HexBytes(self.txid))
                break
            except (TransactionNotFound, ValueError):
                if self.sender is None:
                    # if sender was not explicitly set, this transaction was
                    # not broadcasted locally and so likely doesn't exist
                    raise
                if self.nonce is not None:
                    sender_nonce = web3.eth.get_transaction_count(str(self.sender))
                    if sender_nonce > self.nonce:
                        self.status = Status(-2)
                        return
                time.sleep(1)

According to the documentation here:
https://web3py.readthedocs.io/en/stable/web3.eth.html#web3.eth.Eth.get_transaction

it will throw TransactionNotFound if it hasn't been mined yet, and it seems we are handling few cases in the except clause.

I was wondering if these are exhaustive enough. i.e. could it be that some case is missing, and we can end up in an infinite loop here? Also does it make sense to have an upper limit of waiting here and maybe send a cancel for that transaction after that.

@skgbanga
Copy link
Author

I spent more time to figure out what is going on. (since I was being affected by this problem quite badly).

When we do contract.foo(...), essentially we call web3.eth.send_transaction and then in TransactionReceipt init function, we keep calling web3.eth.get_transaction (as shown above) in a tight loop. (I added print statements in the code to verify this).

So most likely this is outside the scope of brownie, and in the realm of web3.eth

I am curious if there is anything we can do about this though. Any function we can call to figure out what is going on? (check for packet drop or something). Being stuck in a script is painful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant