Skip to content

Commit 60c3650

Browse files
authored
feat: Add Pipeline Set (#2222)
* feat: add pipeline set Signed-off-by: georgi-l95 <[email protected]> * test: add unit tests Signed-off-by: georgi-l95 <[email protected]> * feat: add changes to readme and helm charts Signed-off-by: georgi-l95 <[email protected]> * feat: fix chart lint Signed-off-by: georgi-l95 <[email protected]> --------- Signed-off-by: georgi-l95 <[email protected]>
1 parent ee7ebde commit 60c3650

File tree

12 files changed

+133
-11
lines changed

12 files changed

+133
-11
lines changed

charts/hedera-json-rpc-relay-websocket/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ data:
2525
REDIS_ENABLED: {{ .Values.config.REDIS_ENABLED | quote }}
2626
REDIS_URL: {{ .Values.config.REDIS_URL | quote }}
2727
REDIS_RECONNECT_DELAY_MS: {{ .Values.config.REDIS_RECONNECT_DELAY_MS | quote }}
28+
MULTI_SET: {{ .Values.config.MULTI_SET | quote }}

charts/hedera-json-rpc-relay-websocket/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ config:
3232
REDIS_ENABLED: false
3333
REDIS_URL: ''
3434
REDIS_RECONNECT_DELAY_MS: 1000
35-
35+
MULTI_SET: true
3636
# -- Extra environment variables from existing secrets or configmaps
3737
extraEnvFrom: []
3838
# - secretRef:

charts/hedera-json-rpc-relay/templates/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ data:
3838
REDIS_RECONNECT_DELAY_MS: {{ .Values.config.REDIS_RECONNECT_DELAY_MS | quote }}
3939
DEBUG_API_ENABLED: {{ .Values.config.DEBUG_API_ENABLED | quote }}
4040
FILTER_API_ENABLED: {{ .Values.config.FILTER_API_ENABLED | quote }}
41+
MULTI_SET: {{ .Values.config.MULTI_SET | quote }}

charts/hedera-json-rpc-relay/value-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ config:
134134
REDIS_RECONNECT_DELAY_MS: 1000
135135
DEBUG_API_ENABLED: false
136136
FILTER_API_ENABLED: true
137+
MULTI_SET: true
137138

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

charts/hedera-json-rpc-relay/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ config:
5252
REDIS_RECONNECT_DELAY_MS: 1000
5353
DEBUG_API_ENABLED: false
5454
FILTER_API_ENABLED: true
55+
MULTI_SET: true
5556

5657
# -- Extra environment variables from existing secrets or configmaps
5758
extraEnvFrom: []

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Unless you need to set a non-default value, it is recommended to only populate o
9494
| `DEBUG_API_ENABLED` | "false" | Enables all debug related methods: `debug_traceTransaction`
9595
| `REDIS_ENABLED` | "true" | Enable usage of Redis as shared cache |
9696
| `REDIS_URL` | "redis://127.0.0.1:6379" | Sets the url for the Redis shared cache |
97+
| `MULTI_SET` | "true" | Switch between different implementation of setting multiple K/V pairs in the shared cache. True is mSet, false is pipeline |
9798
| `REDIS_RECONNECT_DELAY_MS` | "1000" | Sets the delay between reconnect retries from the Redis client in ms |
9899
| `SEND_RAW_TRANSACTION_SIZE_LIMIT` | "131072" | Sets the limit of the transaction size the relay accepts on eth_sendRawTransaction
99100
## WS-Server

packages/relay/src/lib/clients/cache/ICacheClient.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ export interface ICacheClient {
2424
delete(key: string, callingMethod: string, requestIdPrefix?: string): void;
2525
clear(): void;
2626
multiSet(keyValuePairs: Record<string, any>, callingMethod: string, requestIdPrefix?: string): void;
27+
pipelineSet(
28+
keyValuePairs: Record<string, any>,
29+
callingMethod: string,
30+
ttl?: number | undefined,
31+
requestIdPrefix?: string,
32+
): void;
2733
}

packages/relay/src/lib/clients/cache/localLRUCache.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ export class LocalLRUCache implements ICacheClient {
144144
}
145145
}
146146

147+
/**
148+
* Stores multiple key-value pairs in the cache.
149+
*
150+
* @param keyValuePairs - An object where each property is a key and its value is the value to be cached.
151+
* @param callingMethod - The name of the calling method.
152+
* @param ttl - Time to live on the set values
153+
* @param requestIdPrefix - Optional request ID prefix for logging.
154+
* @returns {void} A Promise that resolves when the values are cached.
155+
*/
156+
public pipelineSet(
157+
keyValuePairs: Record<string, any>,
158+
callingMethod: string,
159+
ttl?: number,
160+
requestIdPrefix?: string,
161+
): void {
162+
// Iterate over each entry in the keyValuePairs object
163+
for (const [key, value] of Object.entries(keyValuePairs)) {
164+
this.set(key, value, callingMethod, ttl, requestIdPrefix);
165+
}
166+
}
167+
147168
/**
148169
* Deletes a cached value associated with the given key.
149170
* Logs the deletion of the cache entry.

packages/relay/src/lib/clients/cache/redisCache.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,38 @@ export class RedisCache implements ICacheClient {
160160
this.logger.trace(`${requestIdPrefix} caching multiple keys via ${callingMethod}, total keys: ${entriesLength}`);
161161
}
162162

163+
/**
164+
* Stores multiple key-value pairs in the cache using pipelining.
165+
*
166+
* @param keyValuePairs - An object where each property is a key and its value is the value to be cached.
167+
* @param callingMethod - The name of the calling method.
168+
* @param {number} [ttl] - The time-to-live (expiration) of the cache item in milliseconds.
169+
* @param requestIdPrefix - Optional request ID prefix for logging.
170+
* @returns {Promise<void>} A Promise that resolves when the values are cached.
171+
*/
172+
async pipelineSet(
173+
keyValuePairs: Record<string, any>,
174+
callingMethod: string,
175+
ttl?: number | undefined,
176+
requestIdPrefix?: string,
177+
): Promise<void> {
178+
const resolvedTtl = (ttl ?? this.options.ttl) / 1000; // convert to seconds
179+
180+
const pipeline = this.client.multi();
181+
182+
for (const [key, value] of Object.entries(keyValuePairs)) {
183+
const serializedValue = JSON.stringify(value);
184+
pipeline.setEx(key, resolvedTtl, serializedValue);
185+
}
186+
187+
// Execute pipeline operation
188+
await pipeline.execAsPipeline();
189+
190+
// Log the operation
191+
const entriesLength = Object.keys(keyValuePairs).length;
192+
this.logger.trace(`${requestIdPrefix} caching multiple keys via ${callingMethod}, total keys: ${entriesLength}`);
193+
}
194+
163195
/**
164196
* Deletes a value from the cache.
165197
*

packages/relay/src/lib/eth.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,13 @@ export class EthImpl implements Eth {
21372137
}
21382138
// cache the whole array using mSet
21392139
if (Object.keys(keyValuePairs).length > 0) {
2140-
this.cacheService.multiSet(keyValuePairs, EthImpl.ethGetBlockByHash, requestIdPrefix, true);
2140+
this.cacheService.multiSet(
2141+
keyValuePairs,
2142+
EthImpl.ethGetBlockByHash,
2143+
this.syntheticLogCacheTtl,
2144+
requestIdPrefix,
2145+
true,
2146+
);
21412147
}
21422148
}
21432149

0 commit comments

Comments
 (0)