@sentio/runtime 4.0.0-rc.1 → 4.0.0-rc.11
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/lib/chunk-67PFSF7W.js +15174 -0
- package/lib/chunk-67PFSF7W.js.map +1 -0
- package/lib/chunk-PM3ZD75E.js +4988 -0
- package/lib/chunk-PM3ZD75E.js.map +1 -0
- package/lib/index.d.ts +1423 -581
- package/lib/index.js +4 -10
- package/lib/index.js.map +1 -1
- package/lib/plugin-D-rx1WCp.d.ts +108 -0
- package/lib/processor-runner.js +25516 -525
- package/lib/processor-runner.js.map +1 -1
- package/package.json +1 -1
- package/src/action-server.ts +3 -2
- package/src/chain-config.ts +6 -1
- package/src/db-context.ts +58 -45
- package/src/endpoints.ts +22 -4
- package/src/full-service.ts +18 -400
- package/src/gen/google/type/money_pb.ts +41 -0
- package/src/gen/processor/protos/processor_pb.ts +3855 -0
- package/src/gen/service/common/protos/common_pb.ts +4456 -0
- package/src/global-config.ts +3 -2
- package/src/index.ts +1 -2
- package/src/plugin.ts +26 -16
- package/src/processor-runner.ts +25 -35
- package/src/service-v3.ts +57 -59
- package/src/utils.ts +29 -12
- package/lib/chunk-GUQLAUIA.js +0 -67172
- package/lib/chunk-GUQLAUIA.js.map +0 -1
- package/lib/chunk-KOMGWSWU.js +0 -25311
- package/lib/chunk-KOMGWSWU.js.map +0 -1
- package/lib/processor-StqZovMW.d.ts +0 -554
- package/src/gen/google/protobuf/empty.ts +0 -71
- package/src/gen/google/protobuf/struct.ts +0 -561
- package/src/gen/google/protobuf/timestamp.ts +0 -113
- package/src/gen/google/type/money.ts +0 -134
- package/src/gen/processor/protos/processor.ts +0 -15354
- package/src/gen/service/common/protos/common.ts +0 -16525
- package/src/multicall.ts +0 -1605
- package/src/provider.ts +0 -195
- package/src/service.ts +0 -549
package/src/provider.ts
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { JsonRpcProvider, Network } from 'ethers'
|
|
2
|
-
|
|
3
|
-
import PQueue from 'p-queue'
|
|
4
|
-
import { Endpoints } from './endpoints.js'
|
|
5
|
-
import { EthChainId } from '@sentio/chain'
|
|
6
|
-
import { LRUCache } from 'lru-cache'
|
|
7
|
-
import { providerMetrics, processMetrics, metricsStorage } from './metrics.js'
|
|
8
|
-
import { GLOBAL_CONFIG } from './global-config.js'
|
|
9
|
-
const { miss_count, hit_count, queue_size } = providerMetrics
|
|
10
|
-
|
|
11
|
-
export const DummyProvider = new JsonRpcProvider('', Network.from(1))
|
|
12
|
-
|
|
13
|
-
const providers = new Map<string, JsonRpcProvider>()
|
|
14
|
-
|
|
15
|
-
// export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
|
|
16
|
-
// if (!networkish) {
|
|
17
|
-
// networkish = EthChainId.ETHEREUM
|
|
18
|
-
// }
|
|
19
|
-
// if (networkish instanceof BaseContext) {
|
|
20
|
-
// networkish = networkish.getChainId()
|
|
21
|
-
// }
|
|
22
|
-
// return networkish
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
export function getProvider(chainId?: EthChainId): JsonRpcProvider {
|
|
26
|
-
// const network = getNetworkFromCtxOrNetworkish(networkish)
|
|
27
|
-
if (!chainId) {
|
|
28
|
-
chainId = EthChainId.ETHEREUM
|
|
29
|
-
}
|
|
30
|
-
const network = Network.from(parseInt(chainId))
|
|
31
|
-
// TODO check if other key needed
|
|
32
|
-
|
|
33
|
-
const address = Endpoints.INSTANCE.chainServer.get(chainId)
|
|
34
|
-
const key = network.chainId.toString() + '-' + address
|
|
35
|
-
|
|
36
|
-
// console.debug(`init provider for ${chainId}, address: ${address}`)
|
|
37
|
-
let provider = providers.get(key)
|
|
38
|
-
|
|
39
|
-
if (provider) {
|
|
40
|
-
return provider
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (address === undefined) {
|
|
44
|
-
throw Error(
|
|
45
|
-
'Provider not found for chain ' +
|
|
46
|
-
network.chainId +
|
|
47
|
-
', configured chains: ' +
|
|
48
|
-
[...Endpoints.INSTANCE.chainServer.keys()].join(' ')
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
// console.log(
|
|
52
|
-
// `init provider for chain ${network.chainId}, concurrency: ${Endpoints.INSTANCE.concurrency}, batchCount: ${Endpoints.INSTANCE.batchCount}`
|
|
53
|
-
// )
|
|
54
|
-
provider = new QueuedStaticJsonRpcProvider(
|
|
55
|
-
address,
|
|
56
|
-
network,
|
|
57
|
-
Endpoints.INSTANCE.concurrency,
|
|
58
|
-
Endpoints.INSTANCE.batchCount
|
|
59
|
-
)
|
|
60
|
-
providers.set(key, provider)
|
|
61
|
-
return provider
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getTag(prefix: string, value: any): string {
|
|
65
|
-
return (
|
|
66
|
-
prefix +
|
|
67
|
-
':' +
|
|
68
|
-
JSON.stringify(value, (k, v) => {
|
|
69
|
-
if (v == null) {
|
|
70
|
-
return 'null'
|
|
71
|
-
}
|
|
72
|
-
if (typeof v === 'bigint') {
|
|
73
|
-
return `bigint:${v.toString()}`
|
|
74
|
-
}
|
|
75
|
-
if (typeof v === 'string') {
|
|
76
|
-
return v.toLowerCase()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Sort object keys
|
|
80
|
-
if (typeof v === 'object' && !Array.isArray(v)) {
|
|
81
|
-
const keys = Object.keys(v)
|
|
82
|
-
keys.sort()
|
|
83
|
-
return keys.reduce(
|
|
84
|
-
(accum, key) => {
|
|
85
|
-
accum[key] = v[key]
|
|
86
|
-
return accum
|
|
87
|
-
},
|
|
88
|
-
<any>{}
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return v
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
98
|
-
executor: PQueue
|
|
99
|
-
#performCache = new LRUCache<string, Promise<any>>({
|
|
100
|
-
max: 300000, // 300k items
|
|
101
|
-
maxSize: 500 * 1024 * 1024 // 500mb key size for cache
|
|
102
|
-
// ttl: 1000 * 60 * 60, // 1 hour no ttl for better performance
|
|
103
|
-
// sizeCalculation: (value: any) => {
|
|
104
|
-
// assume each item is 1kb for simplicity
|
|
105
|
-
// return 1024
|
|
106
|
-
// }
|
|
107
|
-
})
|
|
108
|
-
#retryCache = new LRUCache<string, number>({
|
|
109
|
-
max: 300000 // 300k items
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
constructor(url: string, network: Network, concurrency: number, batchCount = 1) {
|
|
113
|
-
// TODO re-enable match when possible
|
|
114
|
-
super(url, network, { staticNetwork: network, batchMaxCount: batchCount })
|
|
115
|
-
this.executor = new PQueue({ concurrency: concurrency })
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async send(method: string, params: Array<any>): Promise<any> {
|
|
119
|
-
if (method !== 'eth_call' || params.length > 2) {
|
|
120
|
-
return await this.executor.add(() => super.send(method, params))
|
|
121
|
-
}
|
|
122
|
-
const tag = getTag(method, params)
|
|
123
|
-
const block = params[params.length - 1]
|
|
124
|
-
let perform = this.#performCache.get(tag)
|
|
125
|
-
if (!perform) {
|
|
126
|
-
miss_count.add(1)
|
|
127
|
-
const handler = metricsStorage.getStore()
|
|
128
|
-
const queued: number = Date.now()
|
|
129
|
-
perform = this.executor.add(() => {
|
|
130
|
-
const started = Date.now()
|
|
131
|
-
processMetrics.processor_rpc_queue_duration.record(started - queued, {
|
|
132
|
-
chain_id: this._network.chainId.toString(),
|
|
133
|
-
handler
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
let success = true
|
|
137
|
-
return super
|
|
138
|
-
.send(method, params)
|
|
139
|
-
.catch((e) => {
|
|
140
|
-
success = false
|
|
141
|
-
throw e
|
|
142
|
-
})
|
|
143
|
-
.finally(() => {
|
|
144
|
-
processMetrics.processor_rpc_duration.record(Date.now() - started, {
|
|
145
|
-
chain_id: this._network.chainId.toString(),
|
|
146
|
-
handler,
|
|
147
|
-
success
|
|
148
|
-
})
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
queue_size.record(this.executor.size)
|
|
153
|
-
|
|
154
|
-
this.#performCache.set(tag, perform, {
|
|
155
|
-
size: tag.length
|
|
156
|
-
})
|
|
157
|
-
// For non latest block call, we cache permanently, otherwise we cache for one minute
|
|
158
|
-
if (block === 'latest') {
|
|
159
|
-
setTimeout(() => {
|
|
160
|
-
if (this.#performCache.get(tag) === perform) {
|
|
161
|
-
this.#performCache.delete(tag)
|
|
162
|
-
}
|
|
163
|
-
}, 60 * 1000)
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
hit_count.add(1)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let result
|
|
170
|
-
try {
|
|
171
|
-
result = await perform
|
|
172
|
-
} catch (e: any) {
|
|
173
|
-
this.#performCache.delete(tag)
|
|
174
|
-
if (e.code === 'TIMEOUT') {
|
|
175
|
-
let retryCount = this.#retryCache.get(tag)
|
|
176
|
-
if (GLOBAL_CONFIG.execution.rpcRetryTimes && retryCount === undefined) {
|
|
177
|
-
retryCount = GLOBAL_CONFIG.execution.rpcRetryTimes
|
|
178
|
-
}
|
|
179
|
-
if (retryCount) {
|
|
180
|
-
this.#retryCache.set(tag, retryCount - 1)
|
|
181
|
-
return this.send(method, params)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
throw e
|
|
185
|
-
}
|
|
186
|
-
if (!result) {
|
|
187
|
-
throw Error('Unexpected null response')
|
|
188
|
-
}
|
|
189
|
-
return result
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
toString() {
|
|
193
|
-
return 'QueuedStaticJsonRpcProvider'
|
|
194
|
-
}
|
|
195
|
-
}
|