@sentio/runtime 2.42.0-rc.1 → 2.42.0-rc.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/provider.ts CHANGED
@@ -5,6 +5,7 @@ import { Endpoints } from './endpoints.js'
5
5
  import { EthChainId } from '@sentio/chain'
6
6
  import { LRUCache } from 'lru-cache'
7
7
  import { providerMetrics } from './metrics.js'
8
+ import { GLOBAL_CONFIG } from 'global-config.js'
8
9
  const { miss_count, hit_count, total_duration, total_queued, queue_size } = providerMetrics
9
10
 
10
11
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
@@ -104,6 +105,9 @@ export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
104
105
  // return 1024
105
106
  // }
106
107
  })
108
+ #retryCache = new LRUCache<string, number>({
109
+ max: 300000 // 300k items
110
+ })
107
111
 
108
112
  constructor(url: string, network: Network, concurrency: number, batchCount = 1) {
109
113
  // TODO re-enable match when possible
@@ -120,6 +124,9 @@ export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
120
124
  let perform = this.#performCache.get(tag)
121
125
  if (!perform) {
122
126
  miss_count.add(1)
127
+ if (GLOBAL_CONFIG.execution.rpcRetryTimes && this.#retryCache.get(tag) === undefined) {
128
+ this.#retryCache.set(tag, GLOBAL_CONFIG.execution.rpcRetryTimes)
129
+ }
123
130
  const queued: number = Date.now()
124
131
  perform = this.executor.add(() => {
125
132
  const started = Date.now()
@@ -129,14 +136,6 @@ export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
129
136
  total_duration.add(Date.now() - started)
130
137
  })
131
138
  })
132
- perform.catch((e) => {
133
- // if (e.code !== 'CALL_EXCEPTION' && e.code !== 'BAD_DATA') {
134
- setTimeout(() => {
135
- if (this.#performCache.get(tag) === perform) {
136
- this.#performCache.delete(tag)
137
- }
138
- }, 1000)
139
- })
140
139
 
141
140
  queue_size.record(this.executor.size)
142
141
 
@@ -153,7 +152,20 @@ export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
153
152
  hit_count.add(1)
154
153
  }
155
154
 
156
- const result = await perform
155
+ let result
156
+ try {
157
+ result = await perform
158
+ } catch (e) {
159
+ // if (e.code !== 'CALL_EXCEPTION' && e.code !== 'BAD_DATA') {
160
+ if (this.#performCache.get(tag) === perform) {
161
+ this.#performCache.delete(tag)
162
+ }
163
+ const retryCount = this.#retryCache.get(tag)
164
+ if (e.code === 'TIMEOUT' && retryCount) {
165
+ this.#retryCache.set(tag, retryCount - 1)
166
+ return this.send(method, params)
167
+ }
168
+ }
157
169
  if (!result) {
158
170
  throw Error('Unexpected null response')
159
171
  }