Skip to content

Commit edfb00c

Browse files
authored
Support pagination on getLogs requests (#701)
By default mirror node returns only 25 entries on request and next link for the next entries. - Use `ILimitOrderParams` by default if none are set. Default: `limit: 100, order: ASC` - Can pass `ILimitOrderParams` on `eth_getLogs` method, which will override default ones. - Use next links if there is one and until there is one. - Add unit and acceptance tests for this functionality. Signed-off-by: georgi-l95 <[email protected]>
1 parent fbc0238 commit edfb00c

File tree

15 files changed

+209
-69
lines changed

15 files changed

+209
-69
lines changed

.DS_Store

6 KB
Binary file not shown.

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ DEV_MODE =
2121
MIRROR_NODE_RETRIES =
2222
MIRROR_NODE_RETRY_DELAY =
2323
GAS_PRICE_TINY_BAR_BUFFER =
24+
MIRROR_NODE_LIMIT_PARAM =

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ HBAR_RATE_LIMIT_TINYBAR = 6000000000
8181
HBAR_RATE_LIMIT_DURATION = 60000
8282
RATE_LIMIT_DISABLED = false
8383
DEV_MODE = false
84+
GAS_PRICE_TINY_BAR_BUFFER = 10000000000
8485
MIRROR_NODE_RETRIES = 3
8586
MIRROR_NODE_RETRY_DELAY = 500
86-
GAS_PRICE_TINY_BAR_BUFFER = 10000000000
87+
MIRROR_NODE_LIMIT_PARAM = 100
8788
```
8889

8990
Note: Read more about `DEV_MODE` [here](docs/dev-mode.md)

helm-chart/templates/configmap.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ data:
2828
ETH_GET_LOGS_BLOCK_RANGE_LIMIT: {{ .Values.config.ETH_GET_LOGS_BLOCK_RANGE_LIMIT }}
2929
RATE_LIMIT_DISABLED: {{ .Values.config.RATE_LIMIT_DISABLED }}
3030
DEV_MODE: {{ .Values.config.DEV_MODE }}
31+
MIRROR_NODE_RETRIES: {{ .Values.config.MIRROR_NODE_RETRIES }}
32+
MIRROR_NODE_RETRY_DELAY: {{ .Values.config.MIRROR_NODE_RETRY_DELAY }}
33+
MIRROR_NODE_LIMIT_PARAM: {{ .Values.config.MIRROR_NODE_LIMIT_PARAM }}

helm-chart/templates/deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ spec:
155155
configMapKeyRef:
156156
name: {{ include "json-rpc-relay.fullname" . }}
157157
key: GAS_PRICE_TINY_BAR_BUFFER
158+
- name: MIRROR_NODE_RETRIES
159+
valueFrom:
160+
configMapKeyRef:
161+
name: {{ include "json-rpc-relay.fullname" . }}
162+
key: MIRROR_NODE_RETRIES
163+
optional: true
164+
- name: MIRROR_NODE_RETRY_DELAY
165+
valueFrom:
166+
configMapKeyRef:
167+
name: {{ include "json-rpc-relay.fullname" . }}
168+
key: MIRROR_NODE_RETRY_DELAY
169+
optional: true
170+
- name: MIRROR_NODE_LIMIT_PARAM
171+
valueFrom:
172+
configMapKeyRef:
173+
name: {{ include "json-rpc-relay.fullname" . }}
174+
key: MIRROR_NODE_LIMIT_PARAM
158175
optional: true
159176
ports:
160177
- containerPort: {{ .Values.ports.containerPort }}

helm-chart/values.yaml

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ image:
66
repository: ghcr.io/hashgraph/hedera-json-rpc-relay
77
pullPolicy: Always
88
# Overrides the image tag whose default is the chart appVersion.
9-
tag: ""
9+
tag: ''
1010

1111
imagePullSecrets: []
12-
nameOverride: ""
13-
fullnameOverride: ""
12+
nameOverride: ''
13+
fullnameOverride: ''
1414

1515
serviceAccount:
1616
# Specifies whether a service account should be created
@@ -19,14 +19,16 @@ serviceAccount:
1919
annotations: {}
2020
# The name of the service account to use.
2121
# If not set and create is true, a name is generated using the fullname template
22-
name: ""
22+
name: ''
2323

2424
podAnnotations: {}
2525

26-
podSecurityContext: {}
26+
podSecurityContext:
27+
{}
2728
# fsGroup: 2000
2829

29-
securityContext: {}
30+
securityContext:
31+
{}
3032
# capabilities:
3133
# drop:
3234
# - ALL
@@ -42,8 +44,9 @@ service:
4244

4345
ingress:
4446
enabled: false
45-
className: ""
46-
annotations: {}
47+
className: ''
48+
annotations:
49+
{}
4750
# kubernetes.io/ingress.class: nginx
4851
# kubernetes.io/tls-acme: "true"
4952
hosts:
@@ -56,7 +59,8 @@ ingress:
5659
# hosts:
5760
# - chart-example.local
5861

59-
resources: {}
62+
resources:
63+
{}
6064
# It's recommended not to specify default resources and to leave this as a choice for the user.
6165
# This also increases chances charts run on environments with little resources, such as Minikube.
6266
# If you do want to specify resources, uncomment use the following
@@ -87,9 +91,9 @@ ports:
8791

8892
config:
8993
# This value should be in decimal, not hexadecimal format.
90-
CHAIN_ID: ""
91-
MIRROR_NODE_URL: ""
92-
LOG_LEVEL: ""
94+
CHAIN_ID: ''
95+
MIRROR_NODE_URL: ''
96+
LOG_LEVEL: ''
9397
# Use config.local.HEDERA_NETWORK when running against a locally hosted hedera network
9498
# local:
9599
# config.local.HEDERA_NETWORK should configured as a json set - {"$IPv4_ADDR_1:$PORT_1":"$ACCOUNT_ID_1","$IPv4_ADDR_2:$PORT_2":"$ACCOUNT_ID_2"}
@@ -98,10 +102,10 @@ config:
98102
# Use config.hosted.HEDERA_NETWORK when running against a hosted Hedera network. Valid options are `previewnet`, `testnet`, and `mainnet`
99103
# hosted:
100104
# HEDERA_NETWORK: ""
101-
OPERATOR_ID_MAIN: ""
102-
OPERATOR_KEY_MAIN: ""
103-
OPERATOR_ID_ETH_SENDRAWTRANSACTION: ""
104-
OPERATOR_KEY_ETH_SENDRAWTRANSACTION: ""
105+
OPERATOR_ID_MAIN: ''
106+
OPERATOR_KEY_MAIN: ''
107+
OPERATOR_ID_ETH_SENDRAWTRANSACTION: ''
108+
OPERATOR_KEY_ETH_SENDRAWTRANSACTION: ''
105109
DEFAULT_RATE_LIMIT: 200
106110
TIER_1_RATE_LIMIT: 100
107111
TIER_2_RATE_LIMIT: 200
@@ -113,9 +117,11 @@ config:
113117
RATE_LIMIT_DISABLED: false
114118
DEV_MODE: false
115119
GAS_PRICE_TINY_BAR_BUFFER: 10000000000
120+
MIRROR_NODE_RETRIES: 3
121+
MIRROR_NODE_RETRY_DELAY: 500
122+
MIRROR_NODE_LIMIT_PARAM: 100
116123

117124
# Enable rolling_restarts if SDK calls fail this is usually due to stale connections that get cycled on restart
118125
rolling_restart:
119126
enabled: false
120-
schedule: "@daily"
121-
127+
schedule: '@daily'

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,36 @@ export class MirrorNodeClient {
339339
requestId);
340340
}
341341

342+
public async getContractResultsLogsByNextLink(
343+
link: string,
344+
requestId?: string
345+
) {
346+
const nextLink = link.replace(constants.NEXT_LINK_PREFIX, '');
347+
return this.request(`${nextLink}`,
348+
MirrorNodeClient.GET_CONTRACT_RESULT_LOGS_ENDPOINT,
349+
[400, 404],
350+
requestId);
351+
}
352+
353+
public async pageAllResults(
354+
result: any,
355+
requestId?: string
356+
) {
357+
let unproccesedLogs = result.logs;
358+
if (result.links && result.links.next) {
359+
let nextLink = result.links.next;
360+
while (nextLink) {
361+
let nextResult = await this.getContractResultsLogsByNextLink(nextLink, requestId);
362+
if (!nextResult || !nextResult.logs) {
363+
break;
364+
}
365+
unproccesedLogs = unproccesedLogs.concat(nextResult.logs);
366+
nextLink = nextResult.links.next;
367+
}
368+
}
369+
return unproccesedLogs;
370+
}
371+
342372
public async getLatestBlock(requestId?: string) {
343373
return this.getBlocks(undefined, undefined, this.getLimitOrderQueryParam(1, MirrorNodeClient.ORDER.DESC), requestId);
344374
}
@@ -423,6 +453,9 @@ export class MirrorNodeClient {
423453
if (limitOrderParams) {
424454
this.setQueryParam(queryParamObject, 'limit', limitOrderParams.limit);
425455
this.setQueryParam(queryParamObject, 'order', limitOrderParams.order);
456+
} else {
457+
this.setQueryParam(queryParamObject, 'limit', parseInt(process.env.MIRROR_NODE_LIMIT_PARAM!) || 100);
458+
this.setQueryParam(queryParamObject, 'order', constants.ORDER.ASC);
426459
}
427460
}
428461

packages/relay/src/lib/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ export default {
5959
TX_CREATE_EXTRA: 32_000,
6060
TX_DATA_ZERO_COST: 4,
6161
REQUEST_ID_STRING: `Request ID: `,
62-
BALANCES_UPDATE_INTERVAL: 900 // 15 minutes
62+
BALANCES_UPDATE_INTERVAL: 900, // 15 minutes
63+
MIRROR_NODE_QUERY_LIMIT: 100,
64+
NEXT_LINK_PREFIX: '/api/v1/'
6365
};

packages/relay/src/lib/eth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,10 @@ export class EthImpl implements Eth {
13591359
return [];
13601360
}
13611361

1362+
let unproccesedLogs = await this.mirrorNodeClient.pageAllResults(result, requestId);
1363+
13621364
const logs: Log[] = [];
1363-
for(const log of result.logs) {
1365+
for(const log of unproccesedLogs) {
13641366
logs.push(
13651367
new Log({
13661368
address: await this.getLogEvmAddress(log.address, requestId) || log.address,

0 commit comments

Comments
 (0)