Skip to content

Commit

Permalink
Remove capped attempts from reliable_submission (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
JST5000 authored Apr 10, 2023
1 parent 65f20a1 commit 880c73c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed:
- `check_fee` now has a higher limit that is less likely to be hit
- When connected to nft devnet or hooks v2 testnet generate_faucet_wallet now defaults to using the faucet instead of requiring specification
- When connected hooks v2 testnet generate_faucet_wallet now defaults to using the faucet instead of requiring specification
- Deprecated `get_account_info`, `get_transaction_from_hash`, `get_account_payment_transactions` for direct requests
- Private function `request_impl` has been renamed to `_request_impl`. Users should always use `request` over `request_impl`.
- Removed nft-devnet faucet support as it has been decommissioned ([Blog Post](https://xrpl.org/blog/2023/nft-devnet-decommission.html))
Expand All @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add additional check to `txnNotFound` error from `reliable_submission` due to race condition
- Add `nft_offer` type in `AccountObjects`
- Handle errors better in `send_reliable_submission`
- Made `send_reliable_submission` wait the full duration until `LastLedgerSequence` passes by

## [1.7.0] - 2022-10-12
### Added:
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/sugar/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ async def test_reliable_submission_last_ledger_expiration(self, client):
signed_payment_transaction = await autofill_and_sign(
payment_transaction, WALLET, client
)

await accept_ledger_async()

with self.assertRaises(XRPLReliableSubmissionException):
await send_reliable_submission(signed_payment_transaction, client)

Expand Down
42 changes: 18 additions & 24 deletions xrpl/asyncio/transaction/reliable_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,51 +23,47 @@ class XRPLReliableSubmissionException(XRPLException):


async def _wait_for_final_transaction_outcome(
transaction_hash: str, client: Client, prelim_result: str, attempts: int = 0
transaction_hash: str, client: Client, prelim_result: str, last_ledger_sequence: int
) -> Response:
"""
The core logic of reliable submission. Polls the ledger until the result of the
transaction can be considered final, meaning it has either been included in a
validated ledger, or the transaction's lastLedgerSequence has been surpassed by the
validated ledger, or the transaction's LastLedgerSequence has been surpassed by the
latest ledger sequence (meaning it will never be included in a validated ledger).
"""
await asyncio.sleep(_LEDGER_CLOSE_TIME)
# new persisted transaction

current_ledger_sequence = await get_latest_validated_ledger_sequence(client)

if current_ledger_sequence >= last_ledger_sequence:
raise XRPLReliableSubmissionException(
f"The latest validated ledger sequence {current_ledger_sequence} is "
f"greater than LastLedgerSequence {last_ledger_sequence} in "
f"the transaction. Prelim result: {prelim_result}"
)

# query transaction by hash
transaction_response = await client._request_impl(Tx(transaction=transaction_hash))
if not transaction_response.is_successful():
if transaction_response.result["error"] == "txnNotFound" and attempts < 4:
if transaction_response.result["error"] == "txnNotFound":
"""
For the case if a submitted transaction is still
in queue and not processed on the ledger yet.
Retry 4 times before raising an exception.
"""
return await _wait_for_final_transaction_outcome(
transaction_hash, client, prelim_result, attempts + 1
transaction_hash, client, prelim_result, last_ledger_sequence
)
else:
raise XRPLRequestFailureException(transaction_response.result)

result = transaction_response.result
if "validated" in result and result["validated"]:
# result is in a validated ledger, outcome is final
return transaction_response

last_ledger_sequence = result["LastLedgerSequence"]
latest_ledger_sequence = await get_latest_validated_ledger_sequence(client)

if last_ledger_sequence > latest_ledger_sequence:
# outcome is not yet final
return await _wait_for_final_transaction_outcome(
transaction_hash,
client,
prelim_result,
)

raise XRPLReliableSubmissionException(
f"The latest ledger sequence {latest_ledger_sequence} is greater than the "
f"last ledger sequence {last_ledger_sequence} in the transaction. Prelim "
f"result: {prelim_result}"
# outcome is not yet final
return await _wait_for_final_transaction_outcome(
transaction_hash, client, prelim_result, last_ledger_sequence
)


Expand Down Expand Up @@ -109,7 +105,5 @@ async def send_reliable_submission(
)

return await _wait_for_final_transaction_outcome(
transaction_hash,
client,
prelim_result,
transaction_hash, client, prelim_result, transaction.last_ledger_sequence
)

0 comments on commit 880c73c

Please sign in to comment.