ponder 0.8.26 → 0.8.27-next.1
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 +261 -246
- package/dist/bin/ponder.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/build/pre.ts +3 -2
- package/src/config/config.ts +3 -0
- 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
|
|
|
@@ -1448,8 +1448,9 @@ function buildPre({
|
|
|
1448
1448
|
msg: `Using Postgres database '${getDatabaseName(connectionString)}' (${source})`
|
|
1449
1449
|
});
|
|
1450
1450
|
const poolConfig = {
|
|
1451
|
+
connectionString,
|
|
1451
1452
|
max: config.database.poolConfig?.max ?? 30,
|
|
1452
|
-
|
|
1453
|
+
ssl: config.database.poolConfig?.ssl ?? false
|
|
1453
1454
|
};
|
|
1454
1455
|
databaseConfig = { kind: "postgres", poolConfig };
|
|
1455
1456
|
} else {
|
|
@@ -1474,7 +1475,7 @@ function buildPre({
|
|
|
1474
1475
|
level: "info",
|
|
1475
1476
|
msg: `Using Postgres database ${getDatabaseName(connectionString)} (${source})`
|
|
1476
1477
|
});
|
|
1477
|
-
const poolConfig = { max: 30
|
|
1478
|
+
const poolConfig = { connectionString, max: 30 };
|
|
1478
1479
|
databaseConfig = { kind: "postgres", poolConfig };
|
|
1479
1480
|
} else {
|
|
1480
1481
|
logs.push({
|
|
@@ -1803,7 +1804,7 @@ var createBuild = async ({
|
|
|
1803
1804
|
return executeResult;
|
|
1804
1805
|
}
|
|
1805
1806
|
const config = executeResult.exports.default;
|
|
1806
|
-
const contentHash =
|
|
1807
|
+
const contentHash = crypto2.createHash("sha256").update(serialize(config)).digest("hex");
|
|
1807
1808
|
return {
|
|
1808
1809
|
status: "success",
|
|
1809
1810
|
result: { config, contentHash }
|
|
@@ -1827,7 +1828,7 @@ var createBuild = async ({
|
|
|
1827
1828
|
status: "success",
|
|
1828
1829
|
result: {
|
|
1829
1830
|
schema,
|
|
1830
|
-
contentHash:
|
|
1831
|
+
contentHash: crypto2.createHash("sha256").update(contents).digest("hex")
|
|
1831
1832
|
}
|
|
1832
1833
|
};
|
|
1833
1834
|
};
|
|
@@ -1854,7 +1855,7 @@ var createBuild = async ({
|
|
|
1854
1855
|
return executeResult;
|
|
1855
1856
|
}
|
|
1856
1857
|
}
|
|
1857
|
-
const hash =
|
|
1858
|
+
const hash = crypto2.createHash("sha256");
|
|
1858
1859
|
for (const file of files) {
|
|
1859
1860
|
try {
|
|
1860
1861
|
const contents = fs.readFileSync(file, "utf-8");
|
|
@@ -2004,7 +2005,7 @@ var createBuild = async ({
|
|
|
2004
2005
|
for (const log of buildConfigAndIndexingFunctionsResult.logs) {
|
|
2005
2006
|
common.logger[log.level]({ service: "build", msg: log.msg });
|
|
2006
2007
|
}
|
|
2007
|
-
const buildId =
|
|
2008
|
+
const buildId = crypto2.createHash("sha256").update(BUILD_ID_VERSION).update(configResult.contentHash).update(schemaResult.contentHash).update(indexingResult.contentHash).digest("hex").slice(0, 10);
|
|
2008
2009
|
return {
|
|
2009
2010
|
status: "success",
|
|
2010
2011
|
result: {
|
|
@@ -4008,15 +4009,18 @@ var BASE_DURATION = 125;
|
|
|
4008
4009
|
var HeadlessKysely = class extends Kysely {
|
|
4009
4010
|
common;
|
|
4010
4011
|
name;
|
|
4012
|
+
includeTraceLogs;
|
|
4011
4013
|
isKilled = false;
|
|
4012
4014
|
constructor({
|
|
4013
4015
|
common,
|
|
4014
4016
|
name,
|
|
4017
|
+
includeTraceLogs = false,
|
|
4015
4018
|
...args
|
|
4016
4019
|
}) {
|
|
4017
4020
|
super(args);
|
|
4018
4021
|
this.common = common;
|
|
4019
4022
|
this.name = name;
|
|
4023
|
+
this.includeTraceLogs = includeTraceLogs;
|
|
4020
4024
|
}
|
|
4021
4025
|
async destroy() {
|
|
4022
4026
|
this.isKilled = true;
|
|
@@ -4026,6 +4030,13 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4026
4030
|
let hasError = false;
|
|
4027
4031
|
for (let i = 0; i <= RETRY_COUNT; i++) {
|
|
4028
4032
|
const endClock = startClock();
|
|
4033
|
+
const id = crypto.randomUUID().slice(0, 8);
|
|
4034
|
+
if (this.includeTraceLogs) {
|
|
4035
|
+
this.common.logger.trace({
|
|
4036
|
+
service: this.name,
|
|
4037
|
+
msg: `Started '${options.method}' database method (id=${id})`
|
|
4038
|
+
});
|
|
4039
|
+
}
|
|
4029
4040
|
try {
|
|
4030
4041
|
const result = await fn();
|
|
4031
4042
|
this.common.metrics.ponder_database_method_duration.observe(
|
|
@@ -4046,7 +4057,7 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4046
4057
|
if (this.isKilled) {
|
|
4047
4058
|
this.common.logger.trace({
|
|
4048
4059
|
service: this.name,
|
|
4049
|
-
msg: `Ignored error during '${options.method}' database method
|
|
4060
|
+
msg: `Ignored error during '${options.method}' database method, service is killed (id=${id})`
|
|
4050
4061
|
});
|
|
4051
4062
|
throw new IgnorableError();
|
|
4052
4063
|
}
|
|
@@ -4054,17 +4065,18 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4054
4065
|
hasError = true;
|
|
4055
4066
|
firstError = error;
|
|
4056
4067
|
}
|
|
4057
|
-
if (error instanceof NonRetryableError
|
|
4068
|
+
if (error instanceof NonRetryableError) {
|
|
4058
4069
|
this.common.logger.warn({
|
|
4059
4070
|
service: this.name,
|
|
4060
|
-
msg: `Failed '${options.method}' database method
|
|
4071
|
+
msg: `Failed '${options.method}' database method (id=${id})`,
|
|
4072
|
+
error
|
|
4061
4073
|
});
|
|
4062
4074
|
throw error;
|
|
4063
4075
|
}
|
|
4064
4076
|
if (i === RETRY_COUNT) {
|
|
4065
4077
|
this.common.logger.warn({
|
|
4066
4078
|
service: this.name,
|
|
4067
|
-
msg: `Failed '${options.method}' database method after '${i + 1}' attempts`,
|
|
4079
|
+
msg: `Failed '${options.method}' database method after '${i + 1}' attempts (id=${id})`,
|
|
4068
4080
|
error
|
|
4069
4081
|
});
|
|
4070
4082
|
throw firstError;
|
|
@@ -4072,10 +4084,17 @@ var HeadlessKysely = class extends Kysely {
|
|
|
4072
4084
|
const duration = BASE_DURATION * 2 ** i;
|
|
4073
4085
|
this.common.logger.debug({
|
|
4074
4086
|
service: this.name,
|
|
4075
|
-
msg: `Failed '${options.method}' database method, retrying after ${duration} milliseconds`,
|
|
4087
|
+
msg: `Failed '${options.method}' database method, retrying after ${duration} milliseconds (id=${id})`,
|
|
4076
4088
|
error
|
|
4077
4089
|
});
|
|
4078
4090
|
await wait(duration);
|
|
4091
|
+
} finally {
|
|
4092
|
+
if (this.includeTraceLogs) {
|
|
4093
|
+
this.common.logger.trace({
|
|
4094
|
+
service: this.name,
|
|
4095
|
+
msg: `Completed '${options.method}' database method in ${Math.round(endClock())}ms (id=${id})`
|
|
4096
|
+
});
|
|
4097
|
+
}
|
|
4079
4098
|
}
|
|
4080
4099
|
}
|
|
4081
4100
|
};
|
|
@@ -4100,6 +4119,7 @@ var createDatabase = ({
|
|
|
4100
4119
|
internal: new HeadlessKysely({
|
|
4101
4120
|
name: "internal",
|
|
4102
4121
|
common,
|
|
4122
|
+
includeTraceLogs: true,
|
|
4103
4123
|
dialect: kyselyDialect,
|
|
4104
4124
|
log(event) {
|
|
4105
4125
|
if (event.level === "query") {
|
|
@@ -4139,6 +4159,7 @@ var createDatabase = ({
|
|
|
4139
4159
|
sync: new HeadlessKysely({
|
|
4140
4160
|
name: "sync",
|
|
4141
4161
|
common,
|
|
4162
|
+
includeTraceLogs: true,
|
|
4142
4163
|
dialect: kyselyDialect,
|
|
4143
4164
|
log(event) {
|
|
4144
4165
|
if (event.level === "query") {
|
|
@@ -4196,6 +4217,7 @@ var createDatabase = ({
|
|
|
4196
4217
|
internal: new HeadlessKysely({
|
|
4197
4218
|
name: "internal",
|
|
4198
4219
|
common,
|
|
4220
|
+
includeTraceLogs: true,
|
|
4199
4221
|
dialect: new PostgresDialect({ pool: driver.internal }),
|
|
4200
4222
|
log(event) {
|
|
4201
4223
|
if (event.level === "query") {
|
|
@@ -4235,6 +4257,7 @@ var createDatabase = ({
|
|
|
4235
4257
|
sync: new HeadlessKysely({
|
|
4236
4258
|
name: "sync",
|
|
4237
4259
|
common,
|
|
4260
|
+
includeTraceLogs: true,
|
|
4238
4261
|
dialect: new PostgresDialect({ pool: driver.sync }),
|
|
4239
4262
|
log(event) {
|
|
4240
4263
|
if (event.level === "query") {
|
|
@@ -7157,239 +7180,98 @@ var createSyncStore = ({
|
|
|
7157
7180
|
}
|
|
7158
7181
|
});
|
|
7159
7182
|
},
|
|
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);
|
|
7183
|
+
getEvents: async ({ filters, from, to, limit }) => db.wrap({ method: "getEvents" }, async () => {
|
|
7184
|
+
let query2;
|
|
7185
|
+
for (let i = 0; i < filters.length; i++) {
|
|
7186
|
+
const filter = filters[i];
|
|
7187
|
+
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);
|
|
7188
|
+
query2 = query2 === void 0 ? _query : query2.unionAll(_query);
|
|
7189
|
+
}
|
|
7190
|
+
const rows = await db.with("event", () => query2).selectFrom("event").select([
|
|
7191
|
+
"event.filterIndex as event_filterIndex",
|
|
7192
|
+
"event.checkpoint as event_checkpoint"
|
|
7193
|
+
]).innerJoin("blocks", "blocks.hash", "event.blockHash").select([
|
|
7194
|
+
"blocks.baseFeePerGas as block_baseFeePerGas",
|
|
7195
|
+
"blocks.difficulty as block_difficulty",
|
|
7196
|
+
"blocks.extraData as block_extraData",
|
|
7197
|
+
"blocks.gasLimit as block_gasLimit",
|
|
7198
|
+
"blocks.gasUsed as block_gasUsed",
|
|
7199
|
+
"blocks.hash as block_hash",
|
|
7200
|
+
"blocks.logsBloom as block_logsBloom",
|
|
7201
|
+
"blocks.miner as block_miner",
|
|
7202
|
+
"blocks.mixHash as block_mixHash",
|
|
7203
|
+
"blocks.nonce as block_nonce",
|
|
7204
|
+
"blocks.number as block_number",
|
|
7205
|
+
"blocks.parentHash as block_parentHash",
|
|
7206
|
+
"blocks.receiptsRoot as block_receiptsRoot",
|
|
7207
|
+
"blocks.sha3Uncles as block_sha3Uncles",
|
|
7208
|
+
"blocks.size as block_size",
|
|
7209
|
+
"blocks.stateRoot as block_stateRoot",
|
|
7210
|
+
"blocks.timestamp as block_timestamp",
|
|
7211
|
+
"blocks.totalDifficulty as block_totalDifficulty",
|
|
7212
|
+
"blocks.transactionsRoot as block_transactionsRoot"
|
|
7213
|
+
]).leftJoin("logs", "logs.id", "event.logId").select([
|
|
7214
|
+
"logs.address as log_address",
|
|
7215
|
+
"logs.chainId as log_chainId",
|
|
7216
|
+
"logs.data as log_data",
|
|
7217
|
+
"logs.id as log_id",
|
|
7218
|
+
"logs.logIndex as log_logIndex",
|
|
7219
|
+
"logs.topic0 as log_topic0",
|
|
7220
|
+
"logs.topic1 as log_topic1",
|
|
7221
|
+
"logs.topic2 as log_topic2",
|
|
7222
|
+
"logs.topic3 as log_topic3"
|
|
7223
|
+
]).leftJoin("transactions", "transactions.hash", "event.transactionHash").select([
|
|
7224
|
+
"transactions.accessList as tx_accessList",
|
|
7225
|
+
"transactions.from as tx_from",
|
|
7226
|
+
"transactions.gas as tx_gas",
|
|
7227
|
+
"transactions.gasPrice as tx_gasPrice",
|
|
7228
|
+
"transactions.hash as tx_hash",
|
|
7229
|
+
"transactions.input as tx_input",
|
|
7230
|
+
"transactions.maxFeePerGas as tx_maxFeePerGas",
|
|
7231
|
+
"transactions.maxPriorityFeePerGas as tx_maxPriorityFeePerGas",
|
|
7232
|
+
"transactions.nonce as tx_nonce",
|
|
7233
|
+
"transactions.r as tx_r",
|
|
7234
|
+
"transactions.s as tx_s",
|
|
7235
|
+
"transactions.to as tx_to",
|
|
7236
|
+
"transactions.transactionIndex as tx_transactionIndex",
|
|
7237
|
+
"transactions.type as tx_type",
|
|
7238
|
+
"transactions.value as tx_value",
|
|
7239
|
+
"transactions.v as tx_v"
|
|
7240
|
+
]).leftJoin("traces", "traces.id", "event.traceId").select([
|
|
7241
|
+
"traces.id as trace_id",
|
|
7242
|
+
"traces.type as trace_callType",
|
|
7243
|
+
"traces.from as trace_from",
|
|
7244
|
+
"traces.to as trace_to",
|
|
7245
|
+
"traces.gas as trace_gas",
|
|
7246
|
+
"traces.gasUsed as trace_gasUsed",
|
|
7247
|
+
"traces.input as trace_input",
|
|
7248
|
+
"traces.output as trace_output",
|
|
7249
|
+
"traces.error as trace_error",
|
|
7250
|
+
"traces.revertReason as trace_revertReason",
|
|
7251
|
+
"traces.value as trace_value",
|
|
7252
|
+
"traces.index as trace_index",
|
|
7253
|
+
"traces.subcalls as trace_subcalls"
|
|
7254
|
+
]).leftJoin(
|
|
7255
|
+
"transactionReceipts",
|
|
7256
|
+
"transactionReceipts.transactionHash",
|
|
7257
|
+
"event.transactionHash"
|
|
7258
|
+
).select([
|
|
7259
|
+
"transactionReceipts.contractAddress as txr_contractAddress",
|
|
7260
|
+
"transactionReceipts.cumulativeGasUsed as txr_cumulativeGasUsed",
|
|
7261
|
+
"transactionReceipts.effectiveGasPrice as txr_effectiveGasPrice",
|
|
7262
|
+
"transactionReceipts.from as txr_from",
|
|
7263
|
+
"transactionReceipts.gasUsed as txr_gasUsed",
|
|
7264
|
+
"transactionReceipts.logsBloom as txr_logsBloom",
|
|
7265
|
+
"transactionReceipts.status as txr_status",
|
|
7266
|
+
"transactionReceipts.to as txr_to",
|
|
7267
|
+
"transactionReceipts.type as txr_type"
|
|
7268
|
+
]).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) => {
|
|
7269
|
+
if (error.message.includes("statement timeout")) {
|
|
7270
|
+
throw new NonRetryableError(error.message);
|
|
7284
7271
|
} 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();
|
|
7272
|
+
throw error;
|
|
7391
7273
|
}
|
|
7392
|
-
);
|
|
7274
|
+
});
|
|
7393
7275
|
const events = rows.map((_row) => {
|
|
7394
7276
|
const row = _row;
|
|
7395
7277
|
const filter = filters[row.event_filterIndex];
|
|
@@ -7501,7 +7383,7 @@ var createSyncStore = ({
|
|
|
7501
7383
|
cursor = events[events.length - 1].checkpoint;
|
|
7502
7384
|
}
|
|
7503
7385
|
return { events, cursor };
|
|
7504
|
-
},
|
|
7386
|
+
}),
|
|
7505
7387
|
insertRpcRequestResult: async ({ request, blockNumber, chainId, result }) => db.wrap({ method: "insertRpcRequestResult" }, async () => {
|
|
7506
7388
|
await db.insertInto("rpc_request_results").values({
|
|
7507
7389
|
request,
|
|
@@ -7536,6 +7418,139 @@ var createSyncStore = ({
|
|
|
7536
7418
|
})
|
|
7537
7419
|
)
|
|
7538
7420
|
});
|
|
7421
|
+
var addressSQL = (qb, db, address, column) => {
|
|
7422
|
+
if (typeof address === "string")
|
|
7423
|
+
return qb.where(column, "=", address);
|
|
7424
|
+
if (isAddressFactory(address)) {
|
|
7425
|
+
return qb.where(
|
|
7426
|
+
column,
|
|
7427
|
+
"in",
|
|
7428
|
+
db.selectFrom("logs").$call((qb2) => logFactorySQL(qb2, address))
|
|
7429
|
+
);
|
|
7430
|
+
}
|
|
7431
|
+
if (Array.isArray(address))
|
|
7432
|
+
return qb.where(column, "in", address);
|
|
7433
|
+
return qb;
|
|
7434
|
+
};
|
|
7435
|
+
var logSQL = (filter, db, index) => db.selectFrom("logs").select([
|
|
7436
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7437
|
+
"checkpoint",
|
|
7438
|
+
"chainId",
|
|
7439
|
+
"blockHash",
|
|
7440
|
+
"transactionHash",
|
|
7441
|
+
"id as logId",
|
|
7442
|
+
ksql`null`.as("traceId")
|
|
7443
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => {
|
|
7444
|
+
for (const idx of [0, 1, 2, 3]) {
|
|
7445
|
+
const raw = filter[`topic${idx}`] ?? null;
|
|
7446
|
+
if (raw === null)
|
|
7447
|
+
continue;
|
|
7448
|
+
const topic = Array.isArray(raw) && raw.length === 1 ? raw[0] : raw;
|
|
7449
|
+
if (Array.isArray(topic)) {
|
|
7450
|
+
qb = qb.where(
|
|
7451
|
+
(eb) => eb.or(topic.map((t) => eb(`logs.topic${idx}`, "=", t)))
|
|
7452
|
+
);
|
|
7453
|
+
} else {
|
|
7454
|
+
qb = qb.where(`logs.topic${idx}`, "=", topic);
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
return qb;
|
|
7458
|
+
}).$call((qb) => addressSQL(qb, db, filter.address, "address")).$if(
|
|
7459
|
+
filter.fromBlock !== void 0,
|
|
7460
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7461
|
+
).$if(
|
|
7462
|
+
filter.toBlock !== void 0,
|
|
7463
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7464
|
+
);
|
|
7465
|
+
var blockSQL = (filter, db, index) => db.selectFrom("blocks").select([
|
|
7466
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7467
|
+
"checkpoint",
|
|
7468
|
+
"chainId",
|
|
7469
|
+
"hash as blockHash",
|
|
7470
|
+
ksql`null`.as("transactionHash"),
|
|
7471
|
+
ksql`null`.as("logId"),
|
|
7472
|
+
ksql`null`.as("traceId")
|
|
7473
|
+
]).where("chainId", "=", filter.chainId).$if(
|
|
7474
|
+
filter !== void 0 && filter.interval !== void 0,
|
|
7475
|
+
(qb) => qb.where(ksql`(number - ${filter.offset}) % ${filter.interval} = 0`)
|
|
7476
|
+
).$if(
|
|
7477
|
+
filter.fromBlock !== void 0,
|
|
7478
|
+
(qb) => qb.where("number", ">=", filter.fromBlock.toString())
|
|
7479
|
+
).$if(
|
|
7480
|
+
filter.toBlock !== void 0,
|
|
7481
|
+
(qb) => qb.where("number", "<=", filter.toBlock.toString())
|
|
7482
|
+
);
|
|
7483
|
+
var transactionSQL = (filter, db, index) => db.selectFrom("transactions").select([
|
|
7484
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7485
|
+
"checkpoint",
|
|
7486
|
+
"chainId",
|
|
7487
|
+
"blockHash",
|
|
7488
|
+
"hash as transactionHash",
|
|
7489
|
+
ksql`null`.as("logId"),
|
|
7490
|
+
ksql`null`.as("traceId")
|
|
7491
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).$if(
|
|
7492
|
+
filter.includeReverted === false,
|
|
7493
|
+
(qb) => qb.where(
|
|
7494
|
+
db.selectFrom("transactionReceipts").select("status").where(
|
|
7495
|
+
"transactionReceipts.transactionHash",
|
|
7496
|
+
"=",
|
|
7497
|
+
ksql.ref("transactions.hash")
|
|
7498
|
+
),
|
|
7499
|
+
"=",
|
|
7500
|
+
"0x1"
|
|
7501
|
+
)
|
|
7502
|
+
).$if(
|
|
7503
|
+
filter.fromBlock !== void 0,
|
|
7504
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7505
|
+
).$if(
|
|
7506
|
+
filter.toBlock !== void 0,
|
|
7507
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7508
|
+
);
|
|
7509
|
+
var transferSQL = (filter, db, index) => db.selectFrom("traces").select([
|
|
7510
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7511
|
+
"checkpoint",
|
|
7512
|
+
"chainId",
|
|
7513
|
+
"blockHash",
|
|
7514
|
+
"transactionHash",
|
|
7515
|
+
ksql`null`.as("logId"),
|
|
7516
|
+
"id as traceId"
|
|
7517
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).where("value", ">", "0").$if(
|
|
7518
|
+
filter.includeReverted === false,
|
|
7519
|
+
(qb) => qb.where("isReverted", "=", 0)
|
|
7520
|
+
).$if(
|
|
7521
|
+
filter.fromBlock !== void 0,
|
|
7522
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7523
|
+
).$if(
|
|
7524
|
+
filter.toBlock !== void 0,
|
|
7525
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7526
|
+
);
|
|
7527
|
+
var traceSQL = (filter, db, index) => db.selectFrom("traces").select([
|
|
7528
|
+
ksql.raw(`'${index}'`).as("filterIndex"),
|
|
7529
|
+
"checkpoint",
|
|
7530
|
+
"chainId",
|
|
7531
|
+
"blockHash",
|
|
7532
|
+
"transactionHash",
|
|
7533
|
+
ksql`null`.as("logId"),
|
|
7534
|
+
"id as traceId"
|
|
7535
|
+
]).where("chainId", "=", filter.chainId).$call((qb) => addressSQL(qb, db, filter.fromAddress, "from")).$call((qb) => addressSQL(qb, db, filter.toAddress, "to")).$if(
|
|
7536
|
+
filter.includeReverted === false,
|
|
7537
|
+
(qb) => qb.where("isReverted", "=", 0)
|
|
7538
|
+
).$if(
|
|
7539
|
+
filter.callType !== void 0,
|
|
7540
|
+
(qb) => qb.where("type", "=", filter.callType)
|
|
7541
|
+
).$if(filter.functionSelector !== void 0, (qb) => {
|
|
7542
|
+
if (Array.isArray(filter.functionSelector)) {
|
|
7543
|
+
return qb.where("functionSelector", "in", filter.functionSelector);
|
|
7544
|
+
} else {
|
|
7545
|
+
return qb.where("functionSelector", "=", filter.functionSelector);
|
|
7546
|
+
}
|
|
7547
|
+
}).$if(
|
|
7548
|
+
filter.fromBlock !== void 0,
|
|
7549
|
+
(qb) => qb.where("blockNumber", ">=", filter.fromBlock.toString())
|
|
7550
|
+
).$if(
|
|
7551
|
+
filter.toBlock !== void 0,
|
|
7552
|
+
(qb) => qb.where("blockNumber", "<=", filter.toBlock.toString())
|
|
7553
|
+
);
|
|
7539
7554
|
|
|
7540
7555
|
// src/sync-realtime/filter.ts
|
|
7541
7556
|
import { hexToBigInt as hexToBigInt3, hexToNumber as hexToNumber2 } from "viem";
|
|
@@ -10464,13 +10479,13 @@ var createSync = async (args) => {
|
|
|
10464
10479
|
getOmnichainCheckpoint("finalized"),
|
|
10465
10480
|
getOmnichainCheckpoint("current")
|
|
10466
10481
|
);
|
|
10482
|
+
let consecutiveErrors = 0;
|
|
10467
10483
|
while (true) {
|
|
10468
10484
|
if (isKilled)
|
|
10469
10485
|
return;
|
|
10470
10486
|
if (from >= to)
|
|
10471
10487
|
break;
|
|
10472
10488
|
const getEventsMaxBatchSize = args.common.options.syncEventsQuerySize;
|
|
10473
|
-
let consecutiveErrors = 0;
|
|
10474
10489
|
const estimatedTo = encodeCheckpoint({
|
|
10475
10490
|
...zeroCheckpoint,
|
|
10476
10491
|
blockTimestamp: Math.min(
|
|
@@ -10487,7 +10502,7 @@ var createSync = async (args) => {
|
|
|
10487
10502
|
});
|
|
10488
10503
|
args.common.logger.debug({
|
|
10489
10504
|
service: "sync",
|
|
10490
|
-
msg: `Fetched ${events.length} events from the database for a ${formatEta(estimateSeconds * 1e3)} range from ${decodeCheckpoint(from).blockTimestamp}`
|
|
10505
|
+
msg: `Fetched ${events.length} events from the database for a ${formatEta(estimateSeconds * 1e3)} range from timestamp ${decodeCheckpoint(from).blockTimestamp}`
|
|
10491
10506
|
});
|
|
10492
10507
|
for (const network of args.networks) {
|
|
10493
10508
|
updateHistoricalStatus({ events, checkpoint: cursor, network });
|