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

Added wait_for_confirmation() to AlgodClient #214

Merged
merged 12 commits into from
Oct 4, 2021

Conversation

DamianB-BitFlipper
Copy link
Contributor

When using the Python SDK, I oftentimes find myself copying the same code to wait_for_confirmation() of a pending transaction.

The wait_for_confirmation() waits for a pending transaction to be accepted and confirmed by the network. Until then, it blocks. I have implemented this function with a timeout feature as well that will raise an Exception if the timeout is achieved.

I also went through the code and found spots where a rigged "wait_for_confirmation" like code was used to wait for the pending transaction to be accepted. Instead, I replaced those instances with the proper wait_for_confirmation()

I am unsure what to do about the CHANGELOG

@CLAassistant
Copy link

CLAassistant commented Jul 16, 2021

CLA assistant check
All committers have signed the CLA.

Copy link

@cremeikas cremeikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was looking for almost exactly this functionality, and came across the PR by accident.

Seems to be working great in my test cases.

# Wait until the block for the `current_round` is confirmed
self.status_after_block(current_round)

# Incremenent the `current_round`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increment misspelled here

Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the submission. Please update the function interface as suggested.

@@ -3008,3 +3008,32 @@ def assign_group_id(txns, address=None):
tx.group = gid
result.append(tx)
return result

def wait_for_confirmation(algod_client, transaction_id, timeout=None, **kwargs):
Copy link
Contributor

@algorandskiy algorandskiy Aug 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def wait_for_confirmation(algod_client, transaction_id, timeout=None, **kwargs):
def wait_for_confirmation(algod_client, txid, wait_rounds=0 **kwargs):

Rationale:
txid is most used ident for txn ids across all the code
timeout usually assumes time, but the func accepts rounds

while True:
# Check that the `timeout` has not passed
if timeout is not None and current_round > last_round + timeout:
raise error.AlgodResponseError(f"Wait for transaction id {transaction_id} timed out")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new error type ConfirmationTimeout or similar

@@ -373,16 +373,16 @@ def genesis(self, **kwargs):
"""Returns the entire genesis file."""
req = "/genesis"
return self.algod_request("GET", req, **kwargs)

def proof(self, round_num, txid, **kwargs):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these changes are not needed


# The transaction has been confirmed
if 'confirmed-round' in tx_info:
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to return the tx_info here. Often there is a need to check the some properties of this after waiting.

Copy link
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the Algod v2 client to the docstring and fix the formatting issues, and it will be ready to merge.

algosdk/future/transaction.py Show resolved Hide resolved
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Formatting issues

$ black --check .
would reformat algosdk/v2client/algod.py
would reformat algosdk/future/transaction.py
would reformat test/steps/steps.py
Oh no! 💥 💔 💥
3 files would be reformatted, 61 files would be left unchanged.
The command "black --check ." exited with 1.

@algorandskiy
Copy link
Contributor

Please merge-in develop

@DamianB-BitFlipper
Copy link
Contributor Author

Github is telling me: "Only those with write access to this repository can merge pull requests." What should I do in this case?

@jasonpaulos
Copy link
Contributor

@algorandskiy meant to merge develop into this branch so it's up to date. However, the PR can still be merged automatically by github, so no need to do this.

@DamianB-BitFlipper can you please add algod_client to the args section of the wait_for_confirmation function? After that it looks good to merge to me

@algorandskiy
Copy link
Contributor

Ah, I see, I had "rebase and merge" option selected for some reason and it indicated conflicts. "squash and merge" is green - so please ignore my last comment.

@DamianB-BitFlipper
Copy link
Contributor Author

Should be pushed with the doc comment updated. I do not have write permissions to this repo, so I cannot be the one merging (I believe).

@jasonpaulos
Copy link
Contributor

Thank you for updating the docstring

@jasonpaulos jasonpaulos merged commit b88a471 into algorand:develop Oct 4, 2021
aldur pushed a commit that referenced this pull request Feb 8, 2022
* Incorporated wait_for_confirmation into the AlgodClient

* Replaced parts of code that manually wait for transaction to confirm with dedicated wait_for_confirmation()

* Fixed small bug

* Moved locatoin of wait_for_confirmation code to transaction.future

* Moved locatoin of wait_for_confirmation code to transaction.future

* Integrated comments from PR

* Small change in how wait_rounds branches or not

* Reformatted files

* Added doc comment for algod_client
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

Successfully merging this pull request may close these issues.

6 participants