ponder 0.8.26 → 0.8.27
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/dist/bin/ponder.js +258 -244
- package/dist/bin/ponder.js.map +1 -1
- package/package.json +1 -1
- package/src/database/index.ts +4 -0
- package/src/database/kysely.ts +32 -10
- package/src/sync/index.ts +3 -2
- package/src/sync-store/index.ts +475 -484
package/dist/bin/ponder.js
CHANGED
|
@@ -19,7 +19,7 @@ import { Command } from "@commander-js/extra-typings";
|
|
|
19
19
|
import dotenv from "dotenv";
|
|
20
20
|
|
|
21
21
|
// src/build/index.ts
|
|
22
|
-
import
|
|
22
|
+
import crypto2 from "node:crypto";
|
|
23
23
|
import fs from "node:fs";
|
|
24
24
|
import path2 from "node:path";
|
|
25
25
|
|
|
@@ -1803,7 +1803,7 @@ var createBuild = async ({
|
|
|
1803
1803
|
return executeResult;
|
|
1804
1804
|
}
|
|
1805
1805
|
const config = executeResult.exports.default;
|
|
1806
|
-
const contentHash =
|
|
1806
|
+
const contentHash = crypto2.createHash("sha256").update(serialize(config)).digest("hex");
|
|
1807
1807
|
return {
|
|
1808
1808
|
status: "success",
|
|
1809
1809
|
result: { config, contentHash }
|
|
@@ -1827,7 +1827,7 @@ var createBuild = async ({
|
|
|
1827
1827
|
status: "success",
|
|
1828
1828
|
result: {
|
|
1829
1829
|
schema,
|
|
1830
|
-
contentHash:
|
|
1830
|
+
contentHash: crypto2.createHash("sha256").update(contents).digest("hex")
|
|
1831
1831
|
}
|
|
1832
1832
|
};
|
|
1833
1833
|
};
|
|
@@ -1854,7 +1854,7 @@ var createBuild = async ({
|
|
|
1854
1854
|
return executeResult;
|
|
1855
1855
|
}
|
|
1856
1856
|
}
|
|
1857
|
-
const hash =
|
|
1857
|
+
const hash = crypto2.createHash("sha256");
|
|
1858
1858
|
for (const file of files) {
|
|
1859
1859
|
try {
|
|
1860
1860
|
const contents = fs.readFileSync(file, "utf-8");
|
|
@@ -2004,7 +2004,7 @@ var createBuild = async ({
|
|
|
2004
2004
|
for (const log of buildConfigAndIndexingFunctionsResult.logs) {
|
|
2005
2005
|
common.logger[log.level]({ service: "build", msg: log.msg });
|
|
2006
2006
|
}
|
|
2007
|
-
const buildId =
|
|
2007
|
+
const buildId = crypto2.createHash("sha256").update(BUILD_ID_VERSION).update(configResult.contentHash).update(schemaResult.contentHash).update(indexingResult.contentHash).digest("hex").slice(0, 10);
|
|
2008
2008
|
return {
|
|
2009
2009
|
status: "success",
|
|
2010
2010
|
result: {
|
|
@@ -4008,15 +4008,18 @@ var BASE_DURATION = 125;
|
|
|
4008
4008
|
var HeadlessKysely = class extends Kysely {
|
|
4009
4009
|
common;
|
|
4010
4010
|
name;
|
|
4011
|
+
includeTraceLogs;
|
|
4011
4012
|
isKilled = false;
|
|
4012
4013
|
constructor({
|
|
4013
4014
|
common,
|
|
4014
4015
|
name,
|
|
4016
|
+
includeTraceLogs = false,
|
|
4015
4017
|
...args
|
|
4016
4018
|
}) {
|
|
4017
4019
|
super(args);
|
|
4018
4020
|
this.common = common;
|
|
4019
4021
|
this.name = name;
|
|
4022
|
+
this.includeTraceLogs = includeTraceLogs;
|
|
4020
4023
|
}
|
|
4021
4024
|
async destroy() {
|
|
4022
4025
|
this.isKilled = true;
|
|
@@ -4026,6 +4029,13 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4026
4029
|
let hasError = false;
|
|
4027
4030
|
for (let i = 0; i <= RETRY_COUNT; i++) {
|
|
4028
4031
|
const endClock = startClock();
|
|
4032
|
+
const id = crypto.randomUUID().slice(0, 8);
|
|
4033
|
+
if (this.includeTraceLogs) {
|
|
4034
|
+
this.common.logger.trace({
|
|
4035
|
+
service: this.name,
|
|
4036
|
+
msg: `Started '${options.method}' database method (id=${id})`
|
|
4037
|
+
});
|
|
4038
|
+
}
|
|
4029
4039
|
try {
|
|
4030
4040
|
const result = await fn();
|
|
4031
4041
|
this.common.metrics.ponder_database_method_duration.observe(
|
|
@@ -4046,7 +4056,7 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4046
4056
|
if (this.isKilled) {
|
|
4047
4057
|
this.common.logger.trace({
|
|
4048
4058
|
service: this.name,
|
|
4049
|
-
msg: `Ignored error during '${options.method}' database method
|
|
4059
|
+
msg: `Ignored error during '${options.method}' database method, service is killed (id=${id})`
|
|
4050
4060
|
});
|
|
4051
4061
|
throw new IgnorableError();
|
|
4052
4062
|
}
|
|
@@ -4054,17 +4064,18 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4054
4064
|
hasError = true;
|
|
4055
4065
|
firstError = error;
|
|
4056
4066
|
}
|
|
4057
|
-
if (error instanceof NonRetryableError
|
|
4067
|
+
if (error instanceof NonRetryableError) {
|
|
4058
4068
|
this.common.logger.warn({
|
|
4059
4069
|
service: this.name,
|
|
4060
|
-
msg: `Failed '${options.method}' database method
|
|
4070
|
+
msg: `Failed '${options.method}' database method (id=${id})`,
|
|
4071
|
+
error
|
|
4061
4072
|
});
|
|
4062
4073
|
throw error;
|
|
4063
4074
|
}
|
|
4064
4075
|
if (i === RETRY_COUNT) {
|
|
4065
4076
|
this.common.logger.warn({
|
|
4066
4077
|
service: this.name,
|
|
4067
|
-
msg: `Failed '${options.method}' database method after '${i + 1}' attempts`,
|
|
4078
|
+
msg: `Failed '${options.method}' database method after '${i + 1}' attempts (id=${id})`,
|
|
4068
4079
|
error
|
|
4069
4080
|
});
|
|
4070
4081
|
throw firstError;
|
|
@@ -4072,10 +4083,17 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4072
4083
|
const duration = BASE_DURATION * 2 ** i;
|
|
4073
4084
|
this.common.logger.debug({
|
|
4074
4085
|
service: this.name,
|
|
4075
|
-
msg: `Failed '${options.method}' database method, retrying after ${duration} milliseconds`,
|
|
4086
|
+
msg: `Failed '${options.method}' database method, retrying after ${duration} milliseconds (id=${id})`,
|
|
4076
4087
|
error
|
|
4077
4088
|
});
|
|
4078
4089
|
await wait(duration);
|
|
4090
|
+
} finally {
|
|
4091
|
+
if (this.includeTraceLogs) {
|
|
4092
|
+
this.common.logger.trace({
|
|
4093
|
+
service: this.name,
|
|
4094
|
+
msg: `Completed '${options.method}' database method in ${Math.round(endClock())}ms (id=${id})`
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4079
4097
|
}
|
|
4080
4098
|
}
|
|
4081
4099
|
};
|
|
@@ -4100,6 +4118,7 @@ var createDatabase = ({
|
|
|
4100
4118
|
internal: new HeadlessKysely({
|
|
4101
4119
|
name: "internal",
|
|
4102
4120
|
common,
|
|
4121
|
+
includeTraceLogs: true,
|
|
4103
4122
|
dialect: kyselyDialect,
|
|
4104
4123
|
log(event) {
|
|
4105
4124
|
if (event.level === "query") {
|
|
@@ -4139,6 +4158,7 @@ var createDatabase = ({
|
|
|
4139
4158
|
sync: new HeadlessKysely({
|
|
4140
4159
|
name: "sync",
|
|
4141
4160
|
common,
|
|
4161
|
+
includeTraceLogs: true,
|
|
4142
4162
|
dialect: kyselyDialect,
|
|
4143
4163
|
log(event) {
|
|
4144
4164
|
if (event.level === "query") {
|
|
@@ -4196,6 +4216,7 @@ var createDatabase = ({
|
|
|
4196
4216
|
internal: new HeadlessKysely({
|
|
4197
4217
|
name: "internal",
|
|
4198
4218
|
common,
|
|
4219
|
+
includeTraceLogs: true,
|
|
4199
4220
|
dialect: new PostgresDialect({ pool: driver.internal }),
|
|
4200
4221
|
log(event) {
|
|
4201
4222
|
if (event.level === "query") {
|
|
@@ -4235,6 +4256,7 @@ var createDatabase = ({
|
|
|
4235
4256
|
sync: new HeadlessKysely({
|
|
4236
4257
|
name: "sync",
|
|
4237
4258
|
common,
|
|
4259
|
+
includeTraceLogs: true,
|
|
4238
4260
|
dialect: new PostgresDialect({ pool: driver.sync }),
|
|
4239
4261
|
log(event) {
|
|
4240
4262
|
if (event.level === "query") {
|
|
@@ -7157,239 +7179,98 @@ var createSyncStore = ({
|
|
|
7157
7179
|
}
|
|
7158
7180
|
});
|
|
7159
7181
|
},
|
|
7160
|
-
getEvents: async ({ filters, from, to, limit }) => {
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7166
|
-
|
|
7167
|
-
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7171
|
-
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
"
|
|
7178
|
-
"
|
|
7179
|
-
"
|
|
7180
|
-
"
|
|
7181
|
-
"
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
"
|
|
7208
|
-
"
|
|
7209
|
-
"
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
"
|
|
7226
|
-
"
|
|
7227
|
-
"
|
|
7228
|
-
"
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
]).
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
).$if(
|
|
7246
|
-
|
|
7247
|
-
|
|
7248
|
-
);
|
|
7249
|
-
const transferSQL = (filter, db2, index) => db2.selectFrom("traces").select([
|
|
7250
|
-
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7251
|
-
"checkpoint",
|
|
7252
|
-
"chainId",
|
|
7253
|
-
"blockHash",
|
|
7254
|
-
"transactionHash",
|
|
7255
|
-
ksql`null`.as("logId"),
|
|
7256
|
-
"id as traceId"
|
|
7257
|
-
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, filter.toAddress, "to")).where("value", ">", "0").$if(
|
|
7258
|
-
filter.includeReverted === false,
|
|
7259
|
-
(qb) => qb.where("isReverted", "=", 0)
|
|
7260
|
-
).$if(
|
|
7261
|
-
filter.fromBlock !== void 0,
|
|
7262
|
-
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7263
|
-
).$if(
|
|
7264
|
-
filter.toBlock !== void 0,
|
|
7265
|
-
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7266
|
-
);
|
|
7267
|
-
const traceSQL = (filter, db2, index) => db2.selectFrom("traces").select([
|
|
7268
|
-
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7269
|
-
"checkpoint",
|
|
7270
|
-
"chainId",
|
|
7271
|
-
"blockHash",
|
|
7272
|
-
"transactionHash",
|
|
7273
|
-
ksql`null`.as("logId"),
|
|
7274
|
-
"id as traceId"
|
|
7275
|
-
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, filter.toAddress, "to")).$if(
|
|
7276
|
-
filter.includeReverted === false,
|
|
7277
|
-
(qb) => qb.where("isReverted", "=", 0)
|
|
7278
|
-
).$if(
|
|
7279
|
-
filter.callType !== void 0,
|
|
7280
|
-
(qb) => qb.where("type", "=", filter.callType)
|
|
7281
|
-
).$if(filter.functionSelector !== void 0, (qb) => {
|
|
7282
|
-
if (Array.isArray(filter.functionSelector)) {
|
|
7283
|
-
return qb.where("functionSelector", "in", filter.functionSelector);
|
|
7182
|
+
getEvents: async ({ filters, from, to, limit }) => db.wrap({ method: "getEvents" }, async () => {
|
|
7183
|
+
let query2;
|
|
7184
|
+
for (let i = 0; i < filters.length; i++) {
|
|
7185
|
+
const filter = filters[i];
|
|
7186
|
+
const _query = filter.type === "log" ? logSQL(filter, db, i) : filter.type === "block" ? blockSQL(filter, db, i) : filter.type === "transaction" ? transactionSQL(filter, db, i) : filter.type === "transfer" ? transferSQL(filter, db, i) : traceSQL(filter, db, i);
|
|
7187
|
+
query2 = query2 === void 0 ? _query : query2.unionAll(_query);
|
|
7188
|
+
}
|
|
7189
|
+
const rows = await db.with("event", () => query2).selectFrom("event").select([
|
|
7190
|
+
"event.filterIndex as event_filterIndex",
|
|
7191
|
+
"event.checkpoint as event_checkpoint"
|
|
7192
|
+
]).innerJoin("blocks", "blocks.hash", "event.blockHash").select([
|
|
7193
|
+
"blocks.baseFeePerGas as block_baseFeePerGas",
|
|
7194
|
+
"blocks.difficulty as block_difficulty",
|
|
7195
|
+
"blocks.extraData as block_extraData",
|
|
7196
|
+
"blocks.gasLimit as block_gasLimit",
|
|
7197
|
+
"blocks.gasUsed as block_gasUsed",
|
|
7198
|
+
"blocks.hash as block_hash",
|
|
7199
|
+
"blocks.logsBloom as block_logsBloom",
|
|
7200
|
+
"blocks.miner as block_miner",
|
|
7201
|
+
"blocks.mixHash as block_mixHash",
|
|
7202
|
+
"blocks.nonce as block_nonce",
|
|
7203
|
+
"blocks.number as block_number",
|
|
7204
|
+
"blocks.parentHash as block_parentHash",
|
|
7205
|
+
"blocks.receiptsRoot as block_receiptsRoot",
|
|
7206
|
+
"blocks.sha3Uncles as block_sha3Uncles",
|
|
7207
|
+
"blocks.size as block_size",
|
|
7208
|
+
"blocks.stateRoot as block_stateRoot",
|
|
7209
|
+
"blocks.timestamp as block_timestamp",
|
|
7210
|
+
"blocks.totalDifficulty as block_totalDifficulty",
|
|
7211
|
+
"blocks.transactionsRoot as block_transactionsRoot"
|
|
7212
|
+
]).leftJoin("logs", "logs.id", "event.logId").select([
|
|
7213
|
+
"logs.address as log_address",
|
|
7214
|
+
"logs.chainId as log_chainId",
|
|
7215
|
+
"logs.data as log_data",
|
|
7216
|
+
"logs.id as log_id",
|
|
7217
|
+
"logs.logIndex as log_logIndex",
|
|
7218
|
+
"logs.topic0 as log_topic0",
|
|
7219
|
+
"logs.topic1 as log_topic1",
|
|
7220
|
+
"logs.topic2 as log_topic2",
|
|
7221
|
+
"logs.topic3 as log_topic3"
|
|
7222
|
+
]).leftJoin("transactions", "transactions.hash", "event.transactionHash").select([
|
|
7223
|
+
"transactions.accessList as tx_accessList",
|
|
7224
|
+
"transactions.from as tx_from",
|
|
7225
|
+
"transactions.gas as tx_gas",
|
|
7226
|
+
"transactions.gasPrice as tx_gasPrice",
|
|
7227
|
+
"transactions.hash as tx_hash",
|
|
7228
|
+
"transactions.input as tx_input",
|
|
7229
|
+
"transactions.maxFeePerGas as tx_maxFeePerGas",
|
|
7230
|
+
"transactions.maxPriorityFeePerGas as tx_maxPriorityFeePerGas",
|
|
7231
|
+
"transactions.nonce as tx_nonce",
|
|
7232
|
+
"transactions.r as tx_r",
|
|
7233
|
+
"transactions.s as tx_s",
|
|
7234
|
+
"transactions.to as tx_to",
|
|
7235
|
+
"transactions.transactionIndex as tx_transactionIndex",
|
|
7236
|
+
"transactions.type as tx_type",
|
|
7237
|
+
"transactions.value as tx_value",
|
|
7238
|
+
"transactions.v as tx_v"
|
|
7239
|
+
]).leftJoin("traces", "traces.id", "event.traceId").select([
|
|
7240
|
+
"traces.id as trace_id",
|
|
7241
|
+
"traces.type as trace_callType",
|
|
7242
|
+
"traces.from as trace_from",
|
|
7243
|
+
"traces.to as trace_to",
|
|
7244
|
+
"traces.gas as trace_gas",
|
|
7245
|
+
"traces.gasUsed as trace_gasUsed",
|
|
7246
|
+
"traces.input as trace_input",
|
|
7247
|
+
"traces.output as trace_output",
|
|
7248
|
+
"traces.error as trace_error",
|
|
7249
|
+
"traces.revertReason as trace_revertReason",
|
|
7250
|
+
"traces.value as trace_value",
|
|
7251
|
+
"traces.index as trace_index",
|
|
7252
|
+
"traces.subcalls as trace_subcalls"
|
|
7253
|
+
]).leftJoin(
|
|
7254
|
+
"transactionReceipts",
|
|
7255
|
+
"transactionReceipts.transactionHash",
|
|
7256
|
+
"event.transactionHash"
|
|
7257
|
+
).select([
|
|
7258
|
+
"transactionReceipts.contractAddress as txr_contractAddress",
|
|
7259
|
+
"transactionReceipts.cumulativeGasUsed as txr_cumulativeGasUsed",
|
|
7260
|
+
"transactionReceipts.effectiveGasPrice as txr_effectiveGasPrice",
|
|
7261
|
+
"transactionReceipts.from as txr_from",
|
|
7262
|
+
"transactionReceipts.gasUsed as txr_gasUsed",
|
|
7263
|
+
"transactionReceipts.logsBloom as txr_logsBloom",
|
|
7264
|
+
"transactionReceipts.status as txr_status",
|
|
7265
|
+
"transactionReceipts.to as txr_to",
|
|
7266
|
+
"transactionReceipts.type as txr_type"
|
|
7267
|
+
]).where("event.checkpoint", ">", from).where("event.checkpoint", "<=", to).orderBy("event.checkpoint", "asc").orderBy("event.filterIndex", "asc").$if(limit !== void 0, (qb) => qb.limit(limit)).execute().catch((error) => {
|
|
7268
|
+
if (error.message.includes("statement timeout")) {
|
|
7269
|
+
throw new NonRetryableError(error.message);
|
|
7284
7270
|
} else {
|
|
7285
|
-
|
|
7286
|
-
}
|
|
7287
|
-
}).$if(
|
|
7288
|
-
filter.fromBlock !== void 0,
|
|
7289
|
-
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7290
|
-
).$if(
|
|
7291
|
-
filter.toBlock !== void 0,
|
|
7292
|
-
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7293
|
-
);
|
|
7294
|
-
const rows = await db.wrap(
|
|
7295
|
-
{
|
|
7296
|
-
method: "getEvents",
|
|
7297
|
-
shouldRetry(error) {
|
|
7298
|
-
return error.message.includes("statement timeout") === false;
|
|
7299
|
-
}
|
|
7300
|
-
},
|
|
7301
|
-
async () => {
|
|
7302
|
-
let query2;
|
|
7303
|
-
for (let i = 0; i < filters.length; i++) {
|
|
7304
|
-
const filter = filters[i];
|
|
7305
|
-
const _query = filter.type === "log" ? logSQL(filter, db, i) : filter.type === "block" ? blockSQL(filter, db, i) : filter.type === "transaction" ? transactionSQL(filter, db, i) : filter.type === "transfer" ? transferSQL(filter, db, i) : traceSQL(filter, db, i);
|
|
7306
|
-
query2 = query2 === void 0 ? _query : query2.unionAll(_query);
|
|
7307
|
-
}
|
|
7308
|
-
return await db.with("event", () => query2).selectFrom("event").select([
|
|
7309
|
-
"event.filterIndex as event_filterIndex",
|
|
7310
|
-
"event.checkpoint as event_checkpoint"
|
|
7311
|
-
]).innerJoin("blocks", "blocks.hash", "event.blockHash").select([
|
|
7312
|
-
"blocks.baseFeePerGas as block_baseFeePerGas",
|
|
7313
|
-
"blocks.difficulty as block_difficulty",
|
|
7314
|
-
"blocks.extraData as block_extraData",
|
|
7315
|
-
"blocks.gasLimit as block_gasLimit",
|
|
7316
|
-
"blocks.gasUsed as block_gasUsed",
|
|
7317
|
-
"blocks.hash as block_hash",
|
|
7318
|
-
"blocks.logsBloom as block_logsBloom",
|
|
7319
|
-
"blocks.miner as block_miner",
|
|
7320
|
-
"blocks.mixHash as block_mixHash",
|
|
7321
|
-
"blocks.nonce as block_nonce",
|
|
7322
|
-
"blocks.number as block_number",
|
|
7323
|
-
"blocks.parentHash as block_parentHash",
|
|
7324
|
-
"blocks.receiptsRoot as block_receiptsRoot",
|
|
7325
|
-
"blocks.sha3Uncles as block_sha3Uncles",
|
|
7326
|
-
"blocks.size as block_size",
|
|
7327
|
-
"blocks.stateRoot as block_stateRoot",
|
|
7328
|
-
"blocks.timestamp as block_timestamp",
|
|
7329
|
-
"blocks.totalDifficulty as block_totalDifficulty",
|
|
7330
|
-
"blocks.transactionsRoot as block_transactionsRoot"
|
|
7331
|
-
]).leftJoin("logs", "logs.id", "event.logId").select([
|
|
7332
|
-
"logs.address as log_address",
|
|
7333
|
-
"logs.chainId as log_chainId",
|
|
7334
|
-
"logs.data as log_data",
|
|
7335
|
-
"logs.id as log_id",
|
|
7336
|
-
"logs.logIndex as log_logIndex",
|
|
7337
|
-
"logs.topic0 as log_topic0",
|
|
7338
|
-
"logs.topic1 as log_topic1",
|
|
7339
|
-
"logs.topic2 as log_topic2",
|
|
7340
|
-
"logs.topic3 as log_topic3"
|
|
7341
|
-
]).leftJoin(
|
|
7342
|
-
"transactions",
|
|
7343
|
-
"transactions.hash",
|
|
7344
|
-
"event.transactionHash"
|
|
7345
|
-
).select([
|
|
7346
|
-
"transactions.accessList as tx_accessList",
|
|
7347
|
-
"transactions.from as tx_from",
|
|
7348
|
-
"transactions.gas as tx_gas",
|
|
7349
|
-
"transactions.gasPrice as tx_gasPrice",
|
|
7350
|
-
"transactions.hash as tx_hash",
|
|
7351
|
-
"transactions.input as tx_input",
|
|
7352
|
-
"transactions.maxFeePerGas as tx_maxFeePerGas",
|
|
7353
|
-
"transactions.maxPriorityFeePerGas as tx_maxPriorityFeePerGas",
|
|
7354
|
-
"transactions.nonce as tx_nonce",
|
|
7355
|
-
"transactions.r as tx_r",
|
|
7356
|
-
"transactions.s as tx_s",
|
|
7357
|
-
"transactions.to as tx_to",
|
|
7358
|
-
"transactions.transactionIndex as tx_transactionIndex",
|
|
7359
|
-
"transactions.type as tx_type",
|
|
7360
|
-
"transactions.value as tx_value",
|
|
7361
|
-
"transactions.v as tx_v"
|
|
7362
|
-
]).leftJoin("traces", "traces.id", "event.traceId").select([
|
|
7363
|
-
"traces.id as trace_id",
|
|
7364
|
-
"traces.type as trace_callType",
|
|
7365
|
-
"traces.from as trace_from",
|
|
7366
|
-
"traces.to as trace_to",
|
|
7367
|
-
"traces.gas as trace_gas",
|
|
7368
|
-
"traces.gasUsed as trace_gasUsed",
|
|
7369
|
-
"traces.input as trace_input",
|
|
7370
|
-
"traces.output as trace_output",
|
|
7371
|
-
"traces.error as trace_error",
|
|
7372
|
-
"traces.revertReason as trace_revertReason",
|
|
7373
|
-
"traces.value as trace_value",
|
|
7374
|
-
"traces.index as trace_index",
|
|
7375
|
-
"traces.subcalls as trace_subcalls"
|
|
7376
|
-
]).leftJoin(
|
|
7377
|
-
"transactionReceipts",
|
|
7378
|
-
"transactionReceipts.transactionHash",
|
|
7379
|
-
"event.transactionHash"
|
|
7380
|
-
).select([
|
|
7381
|
-
"transactionReceipts.contractAddress as txr_contractAddress",
|
|
7382
|
-
"transactionReceipts.cumulativeGasUsed as txr_cumulativeGasUsed",
|
|
7383
|
-
"transactionReceipts.effectiveGasPrice as txr_effectiveGasPrice",
|
|
7384
|
-
"transactionReceipts.from as txr_from",
|
|
7385
|
-
"transactionReceipts.gasUsed as txr_gasUsed",
|
|
7386
|
-
"transactionReceipts.logsBloom as txr_logsBloom",
|
|
7387
|
-
"transactionReceipts.status as txr_status",
|
|
7388
|
-
"transactionReceipts.to as txr_to",
|
|
7389
|
-
"transactionReceipts.type as txr_type"
|
|
7390
|
-
]).where("event.checkpoint", ">", from).where("event.checkpoint", "<=", to).orderBy("event.checkpoint", "asc").orderBy("event.filterIndex", "asc").$if(limit !== void 0, (qb) => qb.limit(limit)).execute();
|
|
7271
|
+
throw error;
|
|
7391
7272
|
}
|
|
7392
|
-
);
|
|
7273
|
+
});
|
|
7393
7274
|
const events = rows.map((_row) => {
|
|
7394
7275
|
const row = _row;
|
|
7395
7276
|
const filter = filters[row.event_filterIndex];
|
|
@@ -7501,7 +7382,7 @@ var createSyncStore = ({
|
|
|
7501
7382
|
cursor = events[events.length - 1].checkpoint;
|
|
7502
7383
|
}
|
|
7503
7384
|
return { events, cursor };
|
|
7504
|
-
},
|
|
7385
|
+
}),
|
|
7505
7386
|
insertRpcRequestResult: async ({ request, blockNumber, chainId, result }) => db.wrap({ method: "insertRpcRequestResult" }, async () => {
|
|
7506
7387
|
await db.insertInto("rpc_request_results").values({
|
|
7507
7388
|
request,
|
|
@@ -7536,6 +7417,139 @@ var createSyncStore = ({
|
|
|
7536
7417
|
})
|
|
7537
7418
|
)
|
|
7538
7419
|
});
|
|
7420
|
+
var addressSQL = (qb, db, address, column) => {
|
|
7421
|
+
if (typeof address === "string")
|
|
7422
|
+
return qb.where(column, "=", address);
|
|
7423
|
+
if (isAddressFactory(address)) {
|
|
7424
|
+
return qb.where(
|
|
7425
|
+
column,
|
|
7426
|
+
"in",
|
|
7427
|
+
db.selectFrom("logs").$call((qb2) => logFactorySQL(qb2, address))
|
|
7428
|
+
);
|
|
7429
|
+
}
|
|
7430
|
+
if (Array.isArray(address))
|
|
7431
|
+
return qb.where(column, "in", address);
|
|
7432
|
+
return qb;
|
|
7433
|
+
};
|
|
7434
|
+
var logSQL = (filter, db, index) => db.selectFrom("logs").select([
|
|
7435
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7436
|
+
"checkpoint",
|
|
7437
|
+
"chainId",
|
|
7438
|
+
"blockHash",
|
|
7439
|
+
"transactionHash",
|
|
7440
|
+
"id as logId",
|
|
7441
|
+
ksql`null`.as("traceId")
|
|
7442
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => {
|
|
7443
|
+
for (const idx of [0, 1, 2, 3]) {
|
|
7444
|
+
const raw = filter[`topic${idx}`] ?? null;
|
|
7445
|
+
if (raw === null)
|
|
7446
|
+
continue;
|
|
7447
|
+
const topic = Array.isArray(raw) && raw.length === 1 ? raw[0] : raw;
|
|
7448
|
+
if (Array.isArray(topic)) {
|
|
7449
|
+
qb = qb.where(
|
|
7450
|
+
(eb) => eb.or(topic.map((t) => eb(`logs.topic${idx}`, "=", t)))
|
|
7451
|
+
);
|
|
7452
|
+
} else {
|
|
7453
|
+
qb = qb.where(`logs.topic${idx}`, "=", topic);
|
|
7454
|
+
}
|
|
7455
|
+
}
|
|
7456
|
+
return qb;
|
|
7457
|
+
}).$call((qb) => addressSQL(qb, db, filter.address, "address")).$if(
|
|
7458
|
+
filter.fromBlock !== void 0,
|
|
7459
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7460
|
+
).$if(
|
|
7461
|
+
filter.toBlock !== void 0,
|
|
7462
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7463
|
+
);
|
|
7464
|
+
var blockSQL = (filter, db, index) => db.selectFrom("blocks").select([
|
|
7465
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7466
|
+
"checkpoint",
|
|
7467
|
+
"chainId",
|
|
7468
|
+
"hash as blockHash",
|
|
7469
|
+
ksql`null`.as("transactionHash"),
|
|
7470
|
+
ksql`null`.as("logId"),
|
|
7471
|
+
ksql`null`.as("traceId")
|
|
7472
|
+
]).where("chainId", "=", filter.chainId).$if(
|
|
7473
|
+
filter !== void 0 && filter.interval !== void 0,
|
|
7474
|
+
(qb) => qb.where(ksql`(number - ${filter.offset}) % ${filter.interval} = 0`)
|
|
7475
|
+
).$if(
|
|
7476
|
+
filter.fromBlock !== void 0,
|
|
7477
|
+
(qb) => qb.where("number", ">=", filter.fromBlock.toString())
|
|
7478
|
+
).$if(
|
|
7479
|
+
filter.toBlock !== void 0,
|
|
7480
|
+
(qb) => qb.where("number", "<=", filter.toBlock.toString())
|
|
7481
|
+
);
|
|
7482
|
+
var transactionSQL = (filter, db, index) => db.selectFrom("transactions").select([
|
|
7483
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7484
|
+
"checkpoint",
|
|
7485
|
+
"chainId",
|
|
7486
|
+
"blockHash",
|
|
7487
|
+
"hash as transactionHash",
|
|
7488
|
+
ksql`null`.as("logId"),
|
|
7489
|
+
ksql`null`.as("traceId")
|
|
7490
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).$if(
|
|
7491
|
+
filter.includeReverted === false,
|
|
7492
|
+
(qb) => qb.where(
|
|
7493
|
+
db.selectFrom("transactionReceipts").select("status").where(
|
|
7494
|
+
"transactionReceipts.transactionHash",
|
|
7495
|
+
"=",
|
|
7496
|
+
ksql.ref("transactions.hash")
|
|
7497
|
+
),
|
|
7498
|
+
"=",
|
|
7499
|
+
"0x1"
|
|
7500
|
+
)
|
|
7501
|
+
).$if(
|
|
7502
|
+
filter.fromBlock !== void 0,
|
|
7503
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7504
|
+
).$if(
|
|
7505
|
+
filter.toBlock !== void 0,
|
|
7506
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7507
|
+
);
|
|
7508
|
+
var transferSQL = (filter, db, index) => db.selectFrom("traces").select([
|
|
7509
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7510
|
+
"checkpoint",
|
|
7511
|
+
"chainId",
|
|
7512
|
+
"blockHash",
|
|
7513
|
+
"transactionHash",
|
|
7514
|
+
ksql`null`.as("logId"),
|
|
7515
|
+
"id as traceId"
|
|
7516
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).where("value", ">", "0").$if(
|
|
7517
|
+
filter.includeReverted === false,
|
|
7518
|
+
(qb) => qb.where("isReverted", "=", 0)
|
|
7519
|
+
).$if(
|
|
7520
|
+
filter.fromBlock !== void 0,
|
|
7521
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7522
|
+
).$if(
|
|
7523
|
+
filter.toBlock !== void 0,
|
|
7524
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7525
|
+
);
|
|
7526
|
+
var traceSQL = (filter, db, index) => db.selectFrom("traces").select([
|
|
7527
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7528
|
+
"checkpoint",
|
|
7529
|
+
"chainId",
|
|
7530
|
+
"blockHash",
|
|
7531
|
+
"transactionHash",
|
|
7532
|
+
ksql`null`.as("logId"),
|
|
7533
|
+
"id as traceId"
|
|
7534
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).$if(
|
|
7535
|
+
filter.includeReverted === false,
|
|
7536
|
+
(qb) => qb.where("isReverted", "=", 0)
|
|
7537
|
+
).$if(
|
|
7538
|
+
filter.callType !== void 0,
|
|
7539
|
+
(qb) => qb.where("type", "=", filter.callType)
|
|
7540
|
+
).$if(filter.functionSelector !== void 0, (qb) => {
|
|
7541
|
+
if (Array.isArray(filter.functionSelector)) {
|
|
7542
|
+
return qb.where("functionSelector", "in", filter.functionSelector);
|
|
7543
|
+
} else {
|
|
7544
|
+
return qb.where("functionSelector", "=", filter.functionSelector);
|
|
7545
|
+
}
|
|
7546
|
+
}).$if(
|
|
7547
|
+
filter.fromBlock !== void 0,
|
|
7548
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7549
|
+
).$if(
|
|
7550
|
+
filter.toBlock !== void 0,
|
|
7551
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7552
|
+
);
|
|
7539
7553
|
|
|
7540
7554
|
// src/sync-realtime/filter.ts
|
|
7541
7555
|
import { hexToBigInt as hexToBigInt3, hexToNumber as hexToNumber2 } from "viem";
|
|
@@ -10464,13 +10478,13 @@ var createSync = async (args) => {
|
|
|
10464
10478
|
getOmnichainCheckpoint("finalized"),
|
|
10465
10479
|
getOmnichainCheckpoint("current")
|
|
10466
10480
|
);
|
|
10481
|
+
let consecutiveErrors = 0;
|
|
10467
10482
|
while (true) {
|
|
10468
10483
|
if (isKilled)
|
|
10469
10484
|
return;
|
|
10470
10485
|
if (from >= to)
|
|
10471
10486
|
break;
|
|
10472
10487
|
const getEventsMaxBatchSize = args.common.options.syncEventsQuerySize;
|
|
10473
|
-
let consecutiveErrors = 0;
|
|
10474
10488
|
const estimatedTo = encodeCheckpoint({
|
|
10475
10489
|
...zeroCheckpoint,
|
|
10476
10490
|
blockTimestamp: Math.min(
|
|
@@ -10487,7 +10501,7 @@ var createSync = async (args) => {
|
|
|
10487
10501
|
});
|
|
10488
10502
|
args.common.logger.debug({
|
|
10489
10503
|
service: "sync",
|
|
10490
|
-
msg: `Fetched ${events.length} events from the database for a ${formatEta(estimateSeconds * 1e3)} range from ${decodeCheckpoint(from).blockTimestamp}`
|
|
10504
|
+
msg: `Fetched ${events.length} events from the database for a ${formatEta(estimateSeconds * 1e3)} range from timestamp ${decodeCheckpoint(from).blockTimestamp}`
|
|
10491
10505
|
});
|
|
10492
10506
|
for (const network of args.networks) {
|
|
10493
10507
|
updateHistoricalStatus({ events, checkpoint: cursor, network });
|