Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DUPLICATE_TRANSACTION error for Queries #2190

Merged
merged 15 commits into from
Feb 4, 2025
Merged
5 changes: 4 additions & 1 deletion sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ tasks.withType<Test>().configureEach {
systemProperty("OPERATOR_KEY", providers.gradleProperty("OPERATOR_KEY").getOrElse(""))
}

tasks.testIntegration { failFast = true }
tasks.testIntegration {
maxParallelForks = (Runtime.getRuntime().availableProcessors()).coerceAtLeast(1)
failFast = true
}

tasks.withType<JavaCompile>().configureEach { options.compilerArgs.add("-Xlint:-exports,-dep-ann") }

Expand Down
25 changes: 9 additions & 16 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,22 +364,15 @@ private void initWithNodeIds(Client client) {
* @return the transaction
*/
Transaction getPaymentTransaction(int index) {
var paymentTx = Objects.requireNonNull(paymentTransactions).get(index);
if (paymentTx != null) {
return paymentTx;
} else {
if (paymentTransactionId == null) {
paymentTransactionId = TransactionId.generate(Objects.requireNonNull(paymentOperator).accountId);
}

var newPaymentTx = makePaymentTransaction(
paymentTransactionId,
nodeAccountIds.get(index),
paymentOperator,
Objects.requireNonNull(chosenQueryPayment));
paymentTransactions.set(index, newPaymentTx);
return newPaymentTx;
}
paymentTransactionId = TransactionId.generate(Objects.requireNonNull(paymentOperator).accountId);

var newPaymentTx = makePaymentTransaction(
paymentTransactionId,
nodeAccountIds.get(index),
paymentOperator,
Objects.requireNonNull(chosenQueryPayment));
paymentTransactions.set(index, newPaymentTx);
return newPaymentTx;
}

@Override
Expand Down
12 changes: 11 additions & 1 deletion sdk/src/main/java/com/hedera/hashgraph/sdk/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,9 @@ TransactionResponse mapResponse(
com.hedera.hashgraph.sdk.proto.Transaction request) {
var transactionId = Objects.requireNonNull(getTransactionIdInternal());
var hash = hash(request.getSignedTransactionBytes().toByteArray());
// advance is needed for chunked transactions
transactionIds.advance();
return new TransactionResponse(nodeId, transactionId, hash, null);
return new TransactionResponse(nodeId, transactionId, hash, null, this);
}

@Override
Expand Down Expand Up @@ -1375,6 +1376,15 @@ ExecutionState getExecutionState(Status status, com.hedera.hashgraph.sdk.proto.T
return super.getExecutionState(status, response);
}

Transaction regenerateTransactionId(Client client) {
Objects.requireNonNull(client.getOperatorAccountId());
transactionIds.setLocked(false);
var newTransactionID = TransactionId.generate(client.getOperatorAccountId());
transactionIds.set(transactionIds.getIndex(), newTransactionID);
transactionIds.setLocked(true);
return this;
}

@Override
@SuppressWarnings("LiteProtoToString")
public String toString() {
Expand Down
139 changes: 83 additions & 56 deletions sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionResponse.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ TransactionResponse mapResponse(
new AccountId(3),
TransactionId.withValidStart(new AccountId(3), now),
new byte[] {1, 2, 3},
null,
null)
.setValidateStatus(true);
}
Expand Down Expand Up @@ -299,6 +300,7 @@ TransactionResponse mapResponse(
new AccountId(4),
TransactionId.withValidStart(new AccountId(4), now),
new byte[] {1, 2, 3},
null,
null);
}
};
Expand Down Expand Up @@ -352,6 +354,7 @@ TransactionResponse mapResponse(
new AccountId(3),
TransactionId.withValidStart(new AccountId(3), now),
new byte[] {1, 2, 3},
null,
null);
}
};
Expand Down Expand Up @@ -423,6 +426,7 @@ void testChannelFailedToConnectTimeout() {
new AccountId(3),
TransactionId.withValidStart(new AccountId(3), java.time.Instant.now()),
new byte[] {1, 2, 3},
null,
null);
var tx = new DummyTransaction();

Expand Down
Loading