Skip to content

Commit d349aec

Browse files
authored
fix(Transaction): prevent regeneration of manually set TransactionId (#1017)
Signed-off-by: Atharva <[email protected]>
1 parent 63988b3 commit d349aec

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/sdk/main/src/Transaction.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ struct Transaction<SdkRequestType>::TransactionImpl
150150
* The public key of the trusted batch assembler.
151151
*/
152152
std::shared_ptr<Key> mBatchKey = nullptr;
153+
154+
/**
155+
* This flag is used to determine whether a Transaction's TransactionId
156+
* should be regenerated if the Transaction expires.
157+
*
158+
* Rules:
159+
* 1. If `mTransactionIdManualSet` is `true`, the TransactionId was set manually by the user,
160+
* and it **must not be regenerated**, regardless of client-wide or transaction-specific
161+
* regeneration policies.
162+
* 2. If `mTransactionIdManualSet` is `false` (default), the TransactionId **may be regenerated**
163+
* based on the transaction's own `mTransactionIdRegenerationPolicy` or the client's policy.
164+
*/
165+
166+
bool mTransactionIdManualSet = false;
153167
};
154168

155169
//-----
@@ -654,6 +668,7 @@ SdkRequestType& Transaction<SdkRequestType>::setTransactionId(const TransactionI
654668
{
655669
requireNotFrozen();
656670
mImpl->mTransactionId = id;
671+
mImpl->mTransactionIdManualSet = true;
657672
return static_cast<SdkRequestType&>(*this);
658673
}
659674

@@ -1245,9 +1260,13 @@ typename Executable<SdkRequestType, proto::Transaction, proto::TransactionRespon
12451260
}
12461261

12471262
bool shouldRegenerate = DEFAULT_REGENERATE_TRANSACTION_ID;
1263+
if (mImpl->mTransactionIdManualSet)
1264+
{
1265+
shouldRegenerate = false;
1266+
}
12481267

12491268
// Follow this Transaction's policy if it has been explicitly set.
1250-
if (mImpl->mTransactionIdRegenerationPolicy.has_value())
1269+
else if (mImpl->mTransactionIdRegenerationPolicy.has_value())
12511270
{
12521271
shouldRegenerate = mImpl->mTransactionIdRegenerationPolicy.value();
12531272
}

0 commit comments

Comments
 (0)