-
Notifications
You must be signed in to change notification settings - Fork 89
Deprecate wait_for_accept parameter
#1102
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
Merged
drknzz
merged 24 commits into
drknzz/starknet-0.12.0
from
tomek/wait-for-transaction-removal
Jul 12, 2023
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5bd9e1d
deprecated wait_for_transaction parameter
tomek0123456789 72ba1d6
added poe precommit task
tomek0123456789 b161180
added note in migration guide
tomek0123456789 cdaea27
migration guide fix
tomek0123456789 808eb0b
logic change
tomek0123456789 06b47e8
logic change
tomek0123456789 5a650fc
formatting
tomek0123456789 ae77ac8
added retries below 0 check
tomek0123456789 fe16829
typos
tomek0123456789 215d232
fixed logic
tomek0123456789 394d67c
docstring fix
tomek0123456789 f360b5e
deprecated wait_for_transaction parameter
tomek0123456789 e38e1e0
added poe precommit task
tomek0123456789 cdbb67c
added note in migration guide
tomek0123456789 77839bc
migration guide fix
tomek0123456789 f51af7a
logic change
tomek0123456789 b9fbcbb
logic change
tomek0123456789 19601c8
formatting
tomek0123456789 a022f8f
added retries below 0 check
tomek0123456789 461f769
typos
tomek0123456789 9225942
fixed logic
tomek0123456789 78787f0
docstring fix
tomek0123456789 5362448
Merge remote-tracking branch 'origin/tomek/wait-for-transaction-remov…
drknzz 65648af
Handle no status in RPC
drknzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
| import warnings | ||
| from abc import ABC, abstractmethod | ||
| from typing import List, Optional, Tuple, Union | ||
|
|
||
|
|
@@ -135,27 +136,39 @@ async def get_transaction_receipt( | |
| async def wait_for_tx( | ||
| self, | ||
| tx_hash: Hash, | ||
| wait_for_accept: Optional[bool] = False, # pylint: disable=unused-argument | ||
| check_interval=5, | ||
| wait_for_accept: Optional[bool] = None, # pylint: disable=unused-argument | ||
| check_interval: float = 5, | ||
| retries: int = 200, | ||
drknzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) -> Tuple[int, TransactionStatus]: | ||
| # pylint: disable=too-many-branches | ||
| """ | ||
| Awaits for transaction to get accepted or at least pending by polling its status. | ||
|
|
||
| :param tx_hash: Transaction's hash. | ||
| :param wait_for_accept: If true waits for at least ACCEPTED_ON_L2 status, otherwise waits for at least PENDING. | ||
| Defaults to false | ||
| :param wait_for_accept: | ||
| .. deprecated:: 0.17.0 | ||
| Parameter `wait_for_accept` has been deprecated - since Starknet 0.12.0, transactions in a PENDING | ||
| block have status ACCEPTED_ON_L2. | ||
| :param check_interval: Defines interval between checks. | ||
| :param retries: Defines how many times the transaction is checked until an error is thrown. | ||
| :return: Tuple containing block number and transaction status. | ||
| """ | ||
| if check_interval <= 0: | ||
| raise ValueError("Argument check_interval has to be greater than 0.") | ||
|
|
||
| first_run = True | ||
| try: | ||
| while True: | ||
| if retries <= 0: | ||
| raise ValueError("Argument retries has to be greater than 0.") | ||
| if wait_for_accept is not None: | ||
| warnings.warn( | ||
| "Parameter `wait_for_accept` has been deprecated - since Starknet 0.12.0, transactions in a PENDING" | ||
| " block have status ACCEPTED_ON_L2." | ||
| ) | ||
|
|
||
| while True: | ||
| try: | ||
| result = await self.get_transaction_receipt(tx_hash=tx_hash) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would probably need to catch failed receipt fetch, and retry |
||
| status = result.status | ||
| if status is None: | ||
| raise ClientError(f"Unknown status in transaction {tx_hash}.") | ||
|
|
||
| if status in ( | ||
| TransactionStatus.ACCEPTED_ON_L1, | ||
|
|
@@ -168,24 +181,27 @@ async def wait_for_tx( | |
| message=result.rejection_reason, | ||
| ) | ||
| if status == TransactionStatus.NOT_RECEIVED: | ||
| if not first_run: | ||
| if retries == 0: | ||
| raise TransactionNotReceivedError() | ||
| elif status != TransactionStatus.RECEIVED: | ||
| # This will never get executed with current possible transactions statuses | ||
| raise TransactionFailedError( | ||
| message=result.rejection_reason, | ||
| ) | ||
|
|
||
| first_run = False | ||
| retries -= 1 | ||
| await asyncio.sleep(check_interval) | ||
| except asyncio.CancelledError as exc: | ||
| raise TransactionNotReceivedError from exc | ||
| except ClientError as exc: | ||
| if "Transaction hash not found" in exc.message: | ||
| raise ClientError( | ||
| "Nodes can't access pending transactions, try using parameter 'wait_for_accept=True'." | ||
| ) from exc | ||
| raise exc | ||
| except asyncio.CancelledError as exc: | ||
| raise TransactionNotReceivedError from exc | ||
| except ClientError as exc: | ||
| if ( | ||
| "Transaction hash not found" not in exc.message | ||
| and "Unknown status" not in exc.message | ||
| ): | ||
| raise exc | ||
| retries -= 1 | ||
| if retries == 0: | ||
| raise TransactionNotReceivedError from exc | ||
|
|
||
| @abstractmethod | ||
| async def estimate_fee( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.