Skip to content

Commit 880c73c

Browse files
authored
Remove capped attempts from reliable_submission (#547)
1 parent 65f20a1 commit 880c73c

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818

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

3233
## [1.7.0] - 2022-10-12
3334
### Added:

tests/integration/sugar/test_transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ async def test_reliable_submission_last_ledger_expiration(self, client):
407407
signed_payment_transaction = await autofill_and_sign(
408408
payment_transaction, WALLET, client
409409
)
410+
411+
await accept_ledger_async()
412+
410413
with self.assertRaises(XRPLReliableSubmissionException):
411414
await send_reliable_submission(signed_payment_transaction, client)
412415

xrpl/asyncio/transaction/reliable_submission.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,47 @@ class XRPLReliableSubmissionException(XRPLException):
2323

2424

2525
async def _wait_for_final_transaction_outcome(
26-
transaction_hash: str, client: Client, prelim_result: str, attempts: int = 0
26+
transaction_hash: str, client: Client, prelim_result: str, last_ledger_sequence: int
2727
) -> Response:
2828
"""
2929
The core logic of reliable submission. Polls the ledger until the result of the
3030
transaction can be considered final, meaning it has either been included in a
31-
validated ledger, or the transaction's lastLedgerSequence has been surpassed by the
31+
validated ledger, or the transaction's LastLedgerSequence has been surpassed by the
3232
latest ledger sequence (meaning it will never be included in a validated ledger).
3333
"""
3434
await asyncio.sleep(_LEDGER_CLOSE_TIME)
35-
# new persisted transaction
35+
36+
current_ledger_sequence = await get_latest_validated_ledger_sequence(client)
37+
38+
if current_ledger_sequence >= last_ledger_sequence:
39+
raise XRPLReliableSubmissionException(
40+
f"The latest validated ledger sequence {current_ledger_sequence} is "
41+
f"greater than LastLedgerSequence {last_ledger_sequence} in "
42+
f"the transaction. Prelim result: {prelim_result}"
43+
)
3644

3745
# query transaction by hash
3846
transaction_response = await client._request_impl(Tx(transaction=transaction_hash))
3947
if not transaction_response.is_successful():
40-
if transaction_response.result["error"] == "txnNotFound" and attempts < 4:
48+
if transaction_response.result["error"] == "txnNotFound":
4149
"""
4250
For the case if a submitted transaction is still
4351
in queue and not processed on the ledger yet.
44-
Retry 4 times before raising an exception.
4552
"""
4653
return await _wait_for_final_transaction_outcome(
47-
transaction_hash, client, prelim_result, attempts + 1
54+
transaction_hash, client, prelim_result, last_ledger_sequence
4855
)
4956
else:
5057
raise XRPLRequestFailureException(transaction_response.result)
58+
5159
result = transaction_response.result
5260
if "validated" in result and result["validated"]:
5361
# result is in a validated ledger, outcome is final
5462
return transaction_response
5563

56-
last_ledger_sequence = result["LastLedgerSequence"]
57-
latest_ledger_sequence = await get_latest_validated_ledger_sequence(client)
58-
59-
if last_ledger_sequence > latest_ledger_sequence:
60-
# outcome is not yet final
61-
return await _wait_for_final_transaction_outcome(
62-
transaction_hash,
63-
client,
64-
prelim_result,
65-
)
66-
67-
raise XRPLReliableSubmissionException(
68-
f"The latest ledger sequence {latest_ledger_sequence} is greater than the "
69-
f"last ledger sequence {last_ledger_sequence} in the transaction. Prelim "
70-
f"result: {prelim_result}"
64+
# outcome is not yet final
65+
return await _wait_for_final_transaction_outcome(
66+
transaction_hash, client, prelim_result, last_ledger_sequence
7167
)
7268

7369

@@ -109,7 +105,5 @@ async def send_reliable_submission(
109105
)
110106

111107
return await _wait_for_final_transaction_outcome(
112-
transaction_hash,
113-
client,
114-
prelim_result,
108+
transaction_hash, client, prelim_result, transaction.last_ledger_sequence
115109
)

0 commit comments

Comments
 (0)