Skip to content

Add regenerate_transaction_id to the Transaction class #2643

Description

@iron-prog

Description

Add regenerate_transaction_id support to the Transaction class, bringing the Python SDK closer with the transaction ID regeneration behavior supported by the other SDKs.

Specifically, add:

  • set_regenerate_transaction_id()
  • regenerate_transaction_id

This support is also required by the TCK CommonTransactionParams, which receive regenerateTransactionId parameter through JSON-RPC request parameters.

Proposed Solution

  • Add the regenerate_transaction_id property to Transaction
def __init__(self) -> None:
  ...
  self._regenerate_transaction_id: bool | None = None
  ...

@proprty
def regenerate_transaction_id(self) -> bool | None:
   return self._regenerate_transaction_id
  • Add the setter for the regenerate transaction id
def set_regenerate_transaction_id(self, value: bool):
  self._regenerate_transaction_id = value
  return self
  • Update the transaction retry/expiration handling so that TRANSACTION_EXPIRED triggers a retry when transaction ID regeneration is enabled.
def _should_retry(self, response):
  ...
  if status == ResponseCode.TRANSACTION_EXPIRED:
     # Regenerate the transaction ID and retry if enabled.
      if self.regenerate_transaction_id:
        self._handle_transaction_id_regeneration()
        return _ExecutionState.RETRY

    # Transaction ID regeneration is disabled.
    return _ExecutionState.EXPIRED
  ...
  • Create _handle_transaction_id_regeneration method to generate new transactionId.
def _handle_transaction_id_regeneration(self):
   # unlock the transaction_ids list
   new_trasnaction_id = TransactionId.generate(client.operator_account_id)
   # transaction_ids.set(transaction_ids.index, new_transaction_id);
   # lock the transaction_ids list
  return self
  • Add the default_regenerate_transaction_id: bool = True to Client, default value True.
  • Add setter in the Client to set_default_regenerate_transaction_id().
  • Update the freeze_with() method to to resolve the regenerate_transaction_id
self._regenerate_transaction_id = ( self._regenerate_transaction_id if self._regenerate_transaction_id is not None else client.default_regenerate_transaction_id )
  • Add unit/integration test to validate the changes

Acceptance Criteria

  • Transaction exposes a regenerate_transaction_id property.
  • Transaction provides a fluent set_regenerate_transaction_id(bool) method.
  • The transaction-level setting takes precedence over the client-level default.
  • Client provides default_regenerate_transaction_id, with a default value of True.
  • When no transaction-level value is configured, freeze_with() uses Client.default_regenerate_transaction_id.
  • When TRANSACTION_EXPIRED is received and transaction ID regeneration is enabled, a new transaction ID is generated and the transaction is retried.
  • The newly generated transaction ID uses the client's operator account ID.
  • Existing transaction IDs are correctly replaced with the newly generated transaction ID(s).
  • Transaction ID locking is preserved correctly during regeneration.
  • When transaction ID regeneration is disabled, TRANSACTION_EXPIRED results in _ExecutionState.EXPIRED and the transaction is not retried.

Note
Once this issue is resolved, create a separate follow-up issue to update apply_common_params() to handle the regenerateTransactionId parameter from CommonTransactionParams and apply it to the transaction using set_regenerate_transaction_id().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions