Skip to content

Commit 70099c7

Browse files
authored
Fix SDK reinitialization (#1252)
* fix sdk instance reinit Signed-off-by: georgi-l95 <[email protected]> * add invalid transaction body error logging Signed-off-by: georgi-l95 <[email protected]> * add log switch Signed-off-by: georgi-l95 <[email protected]> --------- Signed-off-by: georgi-l95 <[email protected]>
1 parent 51b3ea6 commit 70099c7

File tree

7 files changed

+15
-2
lines changed

7 files changed

+15
-2
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ WS_MULTIPLE_ADDRESSES_ENABLED=
4242
ETH_BLOCK_NUMBER_CACHE_TTL_MS=
4343
ETH_GET_BALANCE_CACHE_TTL_MS=
4444
ETH_FEE_HISTORY_FIXED=
45+
TRACE_LOG_INVALID_TRANSACTION_BODY=

helm-chart/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ data:
3737
SUBSCRIPTIONS_ENABLED: {{ .Values.config.SUBSCRIPTIONS_ENABLED | quote }}
3838
ETH_CALL_DEFAULT_TO_CONSENSUS_NODE: {{ .Values.config.ETH_CALL_DEFAULT_TO_CONSENSUS_NODE | quote }}
3939
CONTRACT_QUERY_TIMEOUT_RETRIES: {{ .Values.config.CONTRACT_QUERY_TIMEOUT_RETRIES | quote }}
40+
TRACE_LOG_INVALID_TRANSACTION_BODY: {{ .Values.config.TRACE_LOG_INVALID_TRANSACTION_BODY | quote }}

helm-chart/value-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ config:
126126
CONTRACT_QUERY_TIMEOUT_RETRIES: 3
127127
SUBSCRIPTIONS_ENABLED: false
128128
ETH_CALL_DEFAULT_TO_CONSENSUS_NODE: false
129+
TRACE_LOG_INVALID_TRANSACTION_BODY: true
129130

130131
# Enable rolling_restarts if SDK calls fail this is usually due to stale connections that get cycled on restart
131132
rolling_restart:

helm-chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ config:
127127
CONTRACT_QUERY_TIMEOUT_RETRIES: 3
128128
SUBSCRIPTIONS_ENABLED: false
129129
ETH_CALL_DEFAULT_TO_CONSENSUS_NODE: true
130+
TRACE_LOG_INVALID_TRANSACTION_BODY: true
130131

131132
# Enable rolling_restarts if SDK calls fail this is usually due to stale connections that get cycled on restart
132133
rolling_restart:

packages/relay/src/lib/clients/sdkClient.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ export class SDKClient {
455455
if (sdkClientError.isGrpcTimeout()) {
456456
throw predefined.REQUEST_TIMEOUT;
457457
}
458+
459+
if (sdkClientError.isInvalidTransactionBody() && process.env.TRACE_LOG_INVALID_TRANSACTION_BODY) {
460+
this.logger.error(`${requestIdPrefix} Query object on InvalidTransactionBody error: ${JSON.stringify(query)}`);
461+
this.logger.error(`${requestIdPrefix} Client object on InvalidTransactionBody error: ${JSON.stringify({...client, _timer: undefined})}`);
462+
}
458463
throw sdkClientError;
459464
}
460465
};

packages/relay/src/lib/errors/SDKClientError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,9 @@ export class SDKClientError extends Error {
6868
// The SDK uses the same code for Grpc Timeout as INVALID_TRANSACTION_ID
6969
return this.statusCode === Status.InvalidTransactionId._code;
7070
}
71+
72+
public isInvalidTransactionBody(): boolean {
73+
return this.statusCode === Status.InvalidTransactionBody._code;
74+
}
7175
}
7276

packages/relay/src/lib/eth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class EthImpl implements Eth {
168168
/* Temporary code duplication for a temporary HotFix workaround while the definitive fix is implemented
169169
* Please remove initClient workaround, or better yet, do not let this be merged on MAIN, short-lived fix intended only for 0.23.1 version */
170170
private requestsPerSdkClient = 0;
171-
private maxRequestsPerSdkClient = process.env.ETH_CALL_MAX_REQUEST_PER_SDK_INSTANCE || 50;
171+
private maxRequestsPerSdkClient = parseInt(process.env.ETH_CALL_MAX_REQUEST_PER_SDK_INSTANCE!) || 50;
172172
private hederaNetwork: string = (process.env.HEDERA_NETWORK || '{}').toLowerCase();
173173
private ethSdkClient: SDKClient | undefined;
174174
private isInTest = typeof global.it === 'function';
@@ -184,7 +184,7 @@ export class EthImpl implements Eth {
184184

185185
// if we have reached the max number of requests per sdk client instance, or if the sdk client instance is undefined, create a new one
186186
if (this.requestsPerSdkClient >= this.maxRequestsPerSdkClient || this.ethSdkClient == undefined) {
187-
this.ethSdkClient = new SDKClient(this.hederaClient, this.logger, this.registry);
187+
this.ethSdkClient = new SDKClient(SDKClient.initClient(this.logger, this.hederaNetwork), this.logger, this.registry);
188188
this.requestsPerSdkClient = 0;
189189
this.logger.debug(`Limit of requests per instance ${this.maxRequestsPerSdkClient} was reached. Created new SDK client instance`);
190190
}

0 commit comments

Comments
 (0)