@@ -23,51 +23,47 @@ class XRPLReliableSubmissionException(XRPLException):
2323
2424
2525async 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