@@ -442,13 +442,13 @@ public O execute(Client client, Duration timeout) throws TimeoutException, Prech
442442 lastException = grpcRequest .mapStatusException ();
443443 advanceRequest (); // Advance to next node before retrying
444444
445- // Handle INVALID_NODE_ACCOUNT after advancing (matches Go SDK's executionStateRetryWithAnotherNode)
445+ // Handle INVALID_NODE_ACCOUNT after advancing
446446 if (status == Status .INVALID_NODE_ACCOUNT ) {
447447 logger .trace (
448448 "Received INVALID_NODE_ACCOUNT; updating address book and marking node {} as unhealthy, attempt #{}" ,
449449 node .getAccountId (),
450450 attempt );
451- // Schedule async address book update (matches Go's defer client._UpdateAddressBook())
451+ // Schedule async address book update
452452 client .updateNetworkFromAddressBook ();
453453 // Mark this node as unhealthy
454454 client .network .increaseBackoff (node );
@@ -613,7 +613,19 @@ void setNodesFromNodeAccountIds(Client client) {
613613 if (nodeAccountIds .size () == 1 ) {
614614 var nodeProxies = client .network .getNodeProxies (nodeAccountIds .get (0 ));
615615 if (nodeProxies == null || nodeProxies .isEmpty ()) {
616- throw new IllegalStateException ("Account ID did not map to valid node in the client's network" );
616+ logger .warn ("Node {} not found in network, fetching latest address book" ,
617+ nodeAccountIds .get (0 ));
618+
619+ try {
620+ client .updateNetworkFromAddressBook (); // Synchronous update
621+ nodeProxies = client .network .getNodeProxies (nodeAccountIds .get (0 ));
622+ } catch (Exception e ) {
623+ logger .error ("Failed to update address book" , e );
624+ }
625+
626+ if (nodeProxies == null || nodeProxies .isEmpty ()) {
627+ throw new IllegalStateException ("nodeProxies is null or empty" );
628+ }
617629 }
618630
619631 nodes .addAll (nodeProxies ).shuffle ();
@@ -696,7 +708,7 @@ private ProtoRequestT getRequestForExecute() {
696708 var request = makeRequest ();
697709
698710 // NOTE: advanceRequest() is now called explicitly in the retry logic
699- // after we determine that a retry is needed, to match Go SDK behavior
711+ // after we determine that a retry is needed
700712 // where node advancement happens AFTER error detection, not before
701713
702714 return request ;
@@ -903,12 +915,14 @@ ExecutionState getExecutionState(Status status, ResponseT response) {
903915 return ExecutionState .SERVER_ERROR ;
904916 case BUSY :
905917 return ExecutionState .RETRY ;
906- case INVALID_NODE_ACCOUNT :
907- // Matches Go SDK's executionStateRetryWithAnotherNode behavior:
908- // immediately retry with next node without delay
909- // This occurs when a node's account ID has changed
910- return ExecutionState .SERVER_ERROR ;
911- case OK :
918+ //TODO - use ExecutionState.SUCCESS otherwise there is issue with transaction receipt - raised status INVALID_NODE_ACCOUNT
919+ // case INVALID_NODE_ACCOUNT:
920+ // // Matches Go SDK's executionStateRetryWithAnotherNode behavior:
921+ // // immediately retry with next node without delay
922+ // // This occurs when a node's account ID has changed
923+ // return ExecutionState.SERVER_ERROR;
924+ case INVALID_NODE_ACCOUNT :
925+ case OK :
912926 return ExecutionState .SUCCESS ;
913927 default :
914928 return ExecutionState .REQUEST_ERROR ; // user error
0 commit comments