Skip to content

Commit

Permalink
fix: properly handle PLATFORM_NOT_ACTIVE status code (#1871)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Lebedev <[email protected]>
  • Loading branch information
thenswan authored Jul 4, 2024
1 parent 7692c83 commit d7fbbc2
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ ExecutionState getExecutionState(Status status, Response response) {
case UNKNOWN:
case RECEIPT_NOT_FOUND:
case RECORD_NOT_FOUND:
case PLATFORM_NOT_ACTIVE:
return ExecutionState.RETRY;

case OK:
Expand All @@ -216,6 +217,7 @@ ExecutionState getExecutionState(Status status, Response response) {
case OK:
case RECEIPT_NOT_FOUND:
case RECORD_NOT_FOUND:
case PLATFORM_NOT_ACTIVE:
return ExecutionState.RETRY;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ ExecutionState getExecutionState(Status status, Response response) {
case OK:
case RECEIPT_NOT_FOUND:
case RECORD_NOT_FOUND:
case PLATFORM_NOT_ACTIVE:
return ExecutionState.RETRY;

default:
Expand Down
99 changes: 99 additions & 0 deletions sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import com.hedera.hashgraph.sdk.proto.Transaction;
import com.hedera.hashgraph.sdk.proto.TransactionBody;
import com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse;
import com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse;
import com.hedera.hashgraph.sdk.proto.TransactionReceipt;
import com.hedera.hashgraph.sdk.proto.TransactionRecord;
import com.hedera.hashgraph.sdk.proto.TransactionResponse;
import io.grpc.Status;
import io.grpc.stub.StreamObserver;
Expand Down Expand Up @@ -88,6 +90,98 @@ String makeBigString(int size) {
return new String(chars);
}

@ParameterizedTest(name = "[{0}] Executable retries on gRPC error with PLATFORM_NOT_ACTIVE when getting receipt")
@CsvSource({"sync", "async"})
void shouldRetryExceptionallyFunctionsCorrectlyForPlatformNotActiveGetReceipt(String sync) throws Exception {
var service = new TestCryptoService();
var server = new TestServer("getReceiptRetry" + sync, service);
server.client.setMaxAttempts(3);

service.buffer.enqueueResponse(TestResponse.transaction(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE));
service.buffer.enqueueResponse(TestResponse.transactionOk());

com.hedera.hashgraph.sdk.TransactionResponse transactionResponse;
if (sync.equals("sync")) {
transactionResponse = new AccountCreateTransaction().execute(server.client);
} else {
transactionResponse = new AccountCreateTransaction().executeAsync(server.client).get();
}

service.buffer
.enqueueResponse(TestResponse.query(
Response.newBuilder().setTransactionGetReceipt(
TransactionGetReceiptResponse.newBuilder()
.setHeader(ResponseHeader.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.PLATFORM_NOT_ACTIVE))
.setReceipt(TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build())
.build()
).build()
))
.enqueueResponse(TestResponse.receipt(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE))
.enqueueResponse(TestResponse.successfulReceipt());

if (sync.equals("sync")) {
transactionResponse.getReceipt(server.client);
} else {
transactionResponse.getReceiptAsync(server.client).get();
}
}

@ParameterizedTest(name = "[{0}] Executable retries on gRPC error with PLATFORM_NOT_ACTIVE when getting record")
@CsvSource({"sync", "async"})
void shouldRetryExceptionallyFunctionsCorrectlyForPlatformNotActiveGetRecord(String sync) throws Exception {
var service = new TestCryptoService();
var server = new TestServer("getRecordRetry" + sync, service);
server.client.setMaxAttempts(3);

service.buffer.enqueueResponse(TestResponse.transaction(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE));
service.buffer.enqueueResponse(TestResponse.transactionOk());

com.hedera.hashgraph.sdk.TransactionResponse transactionResponse;
if (sync.equals("sync")) {
transactionResponse = new AccountCreateTransaction().execute(server.client);
} else {
transactionResponse = new AccountCreateTransaction().executeAsync(server.client).get();
}

service.buffer
.enqueueResponse(TestResponse.successfulReceipt()) // for inner getReceipt
.enqueueResponse(TestResponse.successfulReceipt()) // for inner getCost
.enqueueResponse(TestResponse.query(
Response.newBuilder().setTransactionGetRecord(
TransactionGetRecordResponse.newBuilder()
.setHeader(ResponseHeader.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.PLATFORM_NOT_ACTIVE).build())
.setTransactionRecord(TransactionRecord.newBuilder().setReceipt(
TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build()
).build()
).build()
).build()
))
.enqueueResponse(TestResponse.query(
Response.newBuilder().setTransactionGetRecord(
TransactionGetRecordResponse.newBuilder()
.setTransactionRecord(TransactionRecord.newBuilder().setReceipt(
TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.PLATFORM_NOT_ACTIVE).build()
).build()
).build()
).build()
))
.enqueueResponse(TestResponse.query(
Response.newBuilder().setTransactionGetRecord(
TransactionGetRecordResponse.newBuilder()
.setTransactionRecord(TransactionRecord.newBuilder().setReceipt(
TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build()
).build()
).build()
).build()
));

if (sync.equals("sync")) {
transactionResponse.getRecord(server.client);
} else {
transactionResponse.getRecordAsync(server.client).get();
}
}

@ParameterizedTest(name = "[{0}, {1}] ContractCreateFlow functions")
@CsvSource({
"sync, stakedNode",
Expand Down Expand Up @@ -653,6 +747,11 @@ public void getTransactionReceipts(Query request, StreamObserver<Response> respo
respondToQueryFromQueue(request, responseObserver);
}

@Override
public void getTxRecordByTxID(Query request, StreamObserver<Response> responseObserver) {
respondToQueryFromQueue(request, responseObserver);
}

@Override
public void getAccountInfo(Query request, StreamObserver<Response> responseObserver) {
respondToQueryFromQueue(request, responseObserver);
Expand Down

0 comments on commit d7fbbc2

Please sign in to comment.