@ocap/resolver 1.32.1 → 1.32.2
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/esm/explorer.mjs +12 -3
- package/esm/follower.mjs +9 -3
- package/esm/hooks.mjs +1 -1
- package/esm/index.mjs +1 -1
- package/esm/node-preferences.mjs +7 -6
- package/esm/replayer.d.mts +14 -2
- package/esm/replayer.mjs +61 -29
- package/lib/explorer.cjs +13 -3
- package/lib/follower.cjs +9 -3
- package/lib/hooks.cjs +2 -2
- package/lib/index.cjs +2 -2
- package/lib/node-preferences.cjs +6 -5
- package/lib/replayer.cjs +63 -29
- package/lib/replayer.d.cts +14 -2
- package/package.json +16 -15
package/esm/explorer.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __require } from "./_virtual/rolldown_runtime.mjs";
|
|
2
2
|
import { UNIFIED_CONSOLE_APP_JS, buildUnifiedConsoleHtml } from "./dashboard.mjs";
|
|
3
|
+
import { isLoopbackAddress } from "@ocap/util/lib/client-ip";
|
|
3
4
|
|
|
4
5
|
//#region src/explorer.ts
|
|
5
6
|
function loadNodeBuiltin(id) {
|
|
@@ -120,8 +121,15 @@ function createExplorerMiddleware(options) {
|
|
|
120
121
|
if (verifiedDistRealPath && reqPath === "/static/js/networks.js") {
|
|
121
122
|
const cfg = options.getConfig() ?? {};
|
|
122
123
|
const chainId = String(cfg.chainId || "local-chain");
|
|
123
|
-
const
|
|
124
|
-
const
|
|
124
|
+
const rawHost = String(req.get?.("host") || req.headers?.host || "").trim();
|
|
125
|
+
const safeHost = rawHost.length > 0 && rawHost.length <= 255 && (/^[A-Za-z0-9.-]+(?::\d{1,5})?$/.test(rawHost) || /^\[[0-9a-fA-F:]+\](?::\d{1,5})?$/.test(rawHost)) ? rawHost : "127.0.0.1";
|
|
126
|
+
let scheme = req.protocol === "https" ? "https" : "http";
|
|
127
|
+
if (scheme === "http" && isLoopbackAddress(req.socket?.remoteAddress)) {
|
|
128
|
+
const xfProto = String(req.headers?.["x-forwarded-proto"] || "").split(",")[0].trim().toLowerCase();
|
|
129
|
+
const cfVisitor = String(req.headers?.["cf-visitor"] || "");
|
|
130
|
+
if (xfProto === "https" || /"scheme"\s*:\s*"https"/i.test(cfVisitor)) scheme = "https";
|
|
131
|
+
}
|
|
132
|
+
const endpoint = /^https?:\/\//.test(chainEndpoint) ? chainEndpoint : `${scheme}://${safeHost}${chainEndpoint.startsWith("/") ? "" : "/"}${chainEndpoint.replace(/\/+$/, "")}/`;
|
|
125
133
|
const networks = [{
|
|
126
134
|
name: chainId,
|
|
127
135
|
abbr: cfg.token?.symbol || "ARC",
|
|
@@ -131,7 +139,8 @@ function createExplorerMiddleware(options) {
|
|
|
131
139
|
}];
|
|
132
140
|
applyExplorerSecurityHeaders(res, false);
|
|
133
141
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
134
|
-
res.setHeader("Cache-Control", "no-
|
|
142
|
+
res.setHeader("Cache-Control", "no-store");
|
|
143
|
+
res.setHeader("Vary", "Host, X-Forwarded-Proto, CF-Visitor");
|
|
135
144
|
return res.status(200).send(`window.ARCBLOCK_NETWORKS = ${safeJsonForJsLiteral(networks)};\n`);
|
|
136
145
|
}
|
|
137
146
|
if (reqPath === "/static/js/networks.js") {
|
package/esm/follower.mjs
CHANGED
|
@@ -1535,7 +1535,7 @@ var FollowerSyncService = class {
|
|
|
1535
1535
|
if (entry.finalized !== true) throw new CustomError("UNFINALIZED_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} is not finalized`);
|
|
1536
1536
|
if (!Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > MAX_SAFE_EPOCH_MS) throw new CustomError("INVALID_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} has invalid timestamp: ${String(entry.timestamp)}`);
|
|
1537
1537
|
if (typeof entry.txRaw !== "string" || !entry.txRaw || entry.txRaw !== entry.txRaw.trim()) throw new CustomError("INVALID_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} has missing or non-canonical txRaw`);
|
|
1538
|
-
this.replayer.validateWireEntry(entry);
|
|
1538
|
+
this.replayer.validateWireEntry(entry, { skipFutureTimestampCheck: true });
|
|
1539
1539
|
const expectedHash = computeEntryHash(entry.sequence, entry.txRaw, entry.stateCommitHash ?? "", entry.sequence >= v2Cutoff ? 2 : 1);
|
|
1540
1540
|
if (entry.entryHash !== expectedHash) throw new CustomError("LEDGER_DIVERGENCE", `Hot-tail entryHash mismatch at seq=${entry.sequence}: expected ${expectedHash}, got ${entry.entryHash}`);
|
|
1541
1541
|
entryHashes.push(entry.entryHash);
|
|
@@ -1563,6 +1563,7 @@ var FollowerSyncService = class {
|
|
|
1563
1563
|
signatureRatchetLocked: true
|
|
1564
1564
|
});
|
|
1565
1565
|
}
|
|
1566
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1566
1567
|
return batchParsedV2From;
|
|
1567
1568
|
}
|
|
1568
1569
|
const cp = upstreamStatus.latestCheckpoint;
|
|
@@ -1586,11 +1587,15 @@ var FollowerSyncService = class {
|
|
|
1586
1587
|
signatureRatchetLocked: true
|
|
1587
1588
|
});
|
|
1588
1589
|
}
|
|
1590
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1589
1591
|
return;
|
|
1590
1592
|
}
|
|
1591
1593
|
}
|
|
1592
1594
|
}
|
|
1593
|
-
if (importOpts.allowUnauthenticated && !entriesBody.batchSignature && !this.hotstuffClusterConfig)
|
|
1595
|
+
if (importOpts.allowUnauthenticated && !entriesBody.batchSignature && !this.hotstuffClusterConfig) {
|
|
1596
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1597
|
+
return batchParsedV2From ?? parsedV2From;
|
|
1598
|
+
}
|
|
1594
1599
|
throw new CustomError("HOT_TAIL_SIGNATURE_MISSING", "Hot-tail /api/ledger/entries response is missing a valid proposer batchSignature");
|
|
1595
1600
|
}
|
|
1596
1601
|
/**
|
|
@@ -1795,7 +1800,7 @@ var FollowerSyncService = class {
|
|
|
1795
1800
|
for (const item of batch) {
|
|
1796
1801
|
if (item.sequence > targetCp.sequence) break;
|
|
1797
1802
|
if (item.sequence !== cursor) throw new CustomError("INVALID_LEDGER_ENTRY", `Non-contiguous entry sequence at height ${nextHeight}: expected ${cursor}, got ${item.sequence}`);
|
|
1798
|
-
this.replayer.validateWireEntry(item);
|
|
1803
|
+
this.replayer.validateWireEntry(item, { skipFutureTimestampCheck: true });
|
|
1799
1804
|
segmentEntries.push(item);
|
|
1800
1805
|
cursor++;
|
|
1801
1806
|
}
|
|
@@ -1818,6 +1823,7 @@ var FollowerSyncService = class {
|
|
|
1818
1823
|
requireSignature: !importOpts.allowUnauthenticated,
|
|
1819
1824
|
allowUnauthenticated: importOpts.allowUnauthenticated
|
|
1820
1825
|
});
|
|
1826
|
+
for (const item of segmentEntries) this.replayer.assertEntryTimestampNotInFuture(item);
|
|
1821
1827
|
let mutatedLocalDb = false;
|
|
1822
1828
|
try {
|
|
1823
1829
|
if (segmentEntries.length > 0 && typeof this.resolver.statedb.runWithinDryRunSession === "function") {
|
package/esm/hooks.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { name } from "./package.mjs";
|
|
2
2
|
import { BN } from "@ocap/util";
|
|
3
|
+
import merge from "lodash/merge.js";
|
|
3
4
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
4
5
|
import createDebug from "debug";
|
|
5
|
-
import merge from "lodash/merge.js";
|
|
6
6
|
import pick from "lodash/pick.js";
|
|
7
7
|
|
|
8
8
|
//#region src/hooks.ts
|
package/esm/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { fromPublicKey, isValid, toTypeInfo } from "@arcblock/did";
|
|
|
18
18
|
import { BN, fromTokenToUnit, toAddress, toBN } from "@ocap/util";
|
|
19
19
|
import { CustomError } from "@ocap/util/lib/error";
|
|
20
20
|
import * as states from "@ocap/state";
|
|
21
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
21
22
|
import { toStakeAddress } from "@arcblock/did-util";
|
|
22
23
|
import createDebug from "debug";
|
|
23
24
|
import pick from "lodash/pick.js";
|
|
@@ -29,7 +30,6 @@ import { decodeAnySafe } from "@ocap/tx-protocols/lib/util";
|
|
|
29
30
|
import { DEFAULT_TOKEN_DECIMAL } from "@ocap/util/lib/constant";
|
|
30
31
|
import { stripDefaultDepositV2BridgeFields } from "@ocap/util/lib/deposit-v2-bridge-fields";
|
|
31
32
|
import { md5 } from "@ocap/util/lib/md5";
|
|
32
|
-
import cloneDeep from "lodash/cloneDeep.js";
|
|
33
33
|
import get from "lodash/get.js";
|
|
34
34
|
import isEmpty from "lodash/isEmpty.js";
|
|
35
35
|
import isEqual from "lodash/isEqual.js";
|
package/esm/node-preferences.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import * as crypto from "node:crypto";
|
|
|
4
4
|
import * as dns from "node:dns";
|
|
5
5
|
import * as net from "node:net";
|
|
6
6
|
import { isValid } from "@arcblock/did";
|
|
7
|
-
import { resolveClientIp } from "@ocap/util/lib/client-ip";
|
|
7
|
+
import { getTrustedClientIpHeaders, resolveClientIp } from "@ocap/util/lib/client-ip";
|
|
8
8
|
|
|
9
9
|
//#region src/node-preferences.ts
|
|
10
10
|
/**
|
|
@@ -826,8 +826,9 @@ var NodePreferencesManager = class {
|
|
|
826
826
|
* socket address alone would put all clients in one bucket; `resolveClientIp` reads the trusted proxy header
|
|
827
827
|
* (`CHAIN_CLIENT_IP_HEADERS`, default `x-real-ip`) only from a loopback peer and ignores them from a remote one (#1922, trust rule in `@ocap/util/lib/client-ip`).
|
|
828
828
|
*/
|
|
829
|
-
function extractClientIp(req) {
|
|
830
|
-
|
|
829
|
+
function extractClientIp(req, env) {
|
|
830
|
+
const headers = env !== void 0 ? getTrustedClientIpHeaders(env.CHAIN_CLIENT_IP_HEADERS) : void 0;
|
|
831
|
+
return resolveClientIp(req, headers !== void 0 ? { headers } : void 0) || "unknown";
|
|
831
832
|
}
|
|
832
833
|
function extractProvidedAdminToken(req) {
|
|
833
834
|
const headers = req.headers || {};
|
|
@@ -919,7 +920,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
919
920
|
const isGatewayNonAdminBearerOnly = Boolean(req.user) && !hasAdminSpecificHeader;
|
|
920
921
|
if (hasExplicitAuthHeader && !isGatewayNonAdminBearerOnly) {
|
|
921
922
|
const now = Date.now();
|
|
922
|
-
const ip = extractClientIp(req);
|
|
923
|
+
const ip = extractClientIp(req, env);
|
|
923
924
|
if (!isRateLimited(ip, now).limited) recordFailure(ip, now);
|
|
924
925
|
}
|
|
925
926
|
return false;
|
|
@@ -933,7 +934,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
933
934
|
if (timingSafeTokenEqual(expected, token)) return "admin";
|
|
934
935
|
if (Boolean(req.user) && !hasAdminSpecificHeader) return "anonymous";
|
|
935
936
|
const now = Date.now();
|
|
936
|
-
const ip = extractClientIp(req);
|
|
937
|
+
const ip = extractClientIp(req, env);
|
|
937
938
|
const rate = isRateLimited(ip, now);
|
|
938
939
|
if (rate.limited) {
|
|
939
940
|
res.setHeader("Retry-After", String(rate.retryAfterSec));
|
|
@@ -993,7 +994,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
993
994
|
return;
|
|
994
995
|
}
|
|
995
996
|
const now = Date.now();
|
|
996
|
-
const ip = extractClientIp(req);
|
|
997
|
+
const ip = extractClientIp(req, env);
|
|
997
998
|
const rate = isRateLimited(ip, now);
|
|
998
999
|
if (rate.limited) {
|
|
999
1000
|
res.setHeader("Retry-After", String(rate.retryAfterSec));
|
package/esm/replayer.d.mts
CHANGED
|
@@ -93,6 +93,12 @@ declare class LedgerEntryReplayer {
|
|
|
93
93
|
*/
|
|
94
94
|
validateWireEntry(entry: ILedgerEntry, options?: IValidateWireEntryOptions): void;
|
|
95
95
|
private authenticateAndDecodeEntry;
|
|
96
|
+
/**
|
|
97
|
+
* Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
|
|
98
|
+
* leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
|
|
99
|
+
* follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
|
|
100
|
+
* (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
|
|
101
|
+
*/
|
|
96
102
|
private indexOrphanEntry;
|
|
97
103
|
/**
|
|
98
104
|
* Replay a single finalized `ILedgerEntry` sequentially (`concurrency = 1`).
|
|
@@ -104,9 +110,15 @@ declare class LedgerEntryReplayer {
|
|
|
104
110
|
* and post-execution `_state_commit` hash with zero mutations to `statedb`, `trusted`, `indexdb`, or `ledger`.
|
|
105
111
|
*/
|
|
106
112
|
dryRunVerifyEntries(entries: ILedgerEntry[], options?: IDryRunVerifyEntriesOptions): Promise<IDryRunVerifyEntriesResult>;
|
|
113
|
+
/** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
|
|
114
|
+
private hashesMissingFromIndex;
|
|
107
115
|
/**
|
|
108
|
-
*
|
|
109
|
-
* orphan
|
|
116
|
+
* After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
|
|
117
|
+
* have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
|
|
118
|
+
* from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
|
|
119
|
+
* holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
|
|
120
|
+
* `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
|
|
121
|
+
* is authenticated as before and fails closed.
|
|
110
122
|
*/
|
|
111
123
|
indexExistingOrphanEntries(fromSeq?: number, toSeq?: number): Promise<number>;
|
|
112
124
|
}
|
package/esm/replayer.mjs
CHANGED
|
@@ -4,6 +4,9 @@ import { createExecutor } from "@ocap/tx-protocols";
|
|
|
4
4
|
import { fromBase64 } from "@ocap/util";
|
|
5
5
|
import { CustomError } from "@ocap/util/lib/error";
|
|
6
6
|
import { Blacklist } from "@ocap/state";
|
|
7
|
+
import { pipes } from "@ocap/tx-pipeline";
|
|
8
|
+
import cloneDeep from "lodash/cloneDeep.js";
|
|
9
|
+
import merge from "lodash/merge.js";
|
|
7
10
|
|
|
8
11
|
//#region src/replayer.ts
|
|
9
12
|
/**
|
|
@@ -185,29 +188,38 @@ var LedgerEntryReplayer = class {
|
|
|
185
188
|
}
|
|
186
189
|
authenticateAndDecodeEntry(entry) {
|
|
187
190
|
const authRes = authenticateEntryDecodedFields(entry, true, { requireFullWireEntry: true });
|
|
188
|
-
if (!authRes.ok) throw new CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${entry.sequence} failed field authentication: ${authRes.reason}`);
|
|
191
|
+
if (!authRes.ok) throw new CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${entry.sequence} hash=${String(entry.hash)} failed field authentication: ${authRes.reason}`);
|
|
189
192
|
return authRes.decodedTx;
|
|
190
193
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
|
|
196
|
+
* leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
|
|
197
|
+
* follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
|
|
198
|
+
* (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
|
|
199
|
+
*/
|
|
200
|
+
async indexOrphanEntry(entry) {
|
|
201
|
+
const ctx = {
|
|
202
|
+
txBase64: entry.txRaw,
|
|
203
|
+
config: this.resolver.config,
|
|
204
|
+
extra: { txTime: entry.timestamp }
|
|
205
|
+
};
|
|
206
|
+
const runPipe = (pipe) => new Promise((resolve, reject) => {
|
|
207
|
+
try {
|
|
208
|
+
pipe(ctx, (err) => err ? reject(err) : resolve());
|
|
209
|
+
} catch (err) {
|
|
210
|
+
reject(err);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
await runPipe(pipes.DecodeTx);
|
|
215
|
+
await runPipe(pipes.DecodeItx);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
throw new CustomError("INVALID_LEDGER_ENTRY", `Orphan ledger entry seq=${entry.sequence} hash=${entry.hash} does not decode as the leader decodes it: ${err instanceof Error ? err.message : String(err)}`);
|
|
218
|
+
}
|
|
219
|
+
if (String(ctx.txHash ?? "").toUpperCase() !== String(entry.hash).toUpperCase()) throw new CustomError("TX_HASH_MISMATCH", `Orphan ledger entry seq=${entry.sequence} hash=${entry.hash}: txRaw does not hash to its entry hash`);
|
|
220
|
+
const leaderCtx = merge(cloneDeep(ctx), ctx);
|
|
221
|
+
leaderCtx.ledgerSequence = entry.sequence;
|
|
222
|
+
await this.resolver._indexRejectedLedgerTx(leaderCtx, { code: "ORPHAN_LEDGER_ENTRY" });
|
|
211
223
|
await this.resolver.flushIndexWrites();
|
|
212
224
|
}
|
|
213
225
|
/**
|
|
@@ -240,7 +252,7 @@ var LedgerEntryReplayer = class {
|
|
|
240
252
|
}
|
|
241
253
|
if (appendToLedger) this.assertEntryTimestampNotInFuture(entry);
|
|
242
254
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
243
|
-
|
|
255
|
+
this.authenticateAndDecodeEntry(entry);
|
|
244
256
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
245
257
|
if (appendToLedger) {
|
|
246
258
|
const v2Cutoff = options.entryHashV2From === "infinity" ? Number.POSITIVE_INFINITY : typeof options.entryHashV2From === "number" ? options.entryHashV2From : this.resolver.ledger.getEntryHashV2From?.() ?? 1;
|
|
@@ -249,7 +261,7 @@ var LedgerEntryReplayer = class {
|
|
|
249
261
|
}
|
|
250
262
|
if (!expectedStateCommit) {
|
|
251
263
|
if (appendToLedger) await this.appendVerifiedEntryToLedger(entry, options.entryHashV2From);
|
|
252
|
-
await this.indexOrphanEntry(entry
|
|
264
|
+
await this.indexOrphanEntry(entry);
|
|
253
265
|
return {
|
|
254
266
|
status: "orphan-indexed",
|
|
255
267
|
sequence: entry.sequence,
|
|
@@ -403,9 +415,27 @@ var LedgerEntryReplayer = class {
|
|
|
403
415
|
};
|
|
404
416
|
});
|
|
405
417
|
}
|
|
418
|
+
/** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
|
|
419
|
+
async hashesMissingFromIndex(entries) {
|
|
420
|
+
const missing = /* @__PURE__ */ new Set();
|
|
421
|
+
if (entries.length === 0) return missing;
|
|
422
|
+
const hashes = [...new Set(entries.map((e) => String(e.hash).toUpperCase()))];
|
|
423
|
+
const { indexdb, statedb } = this.resolver;
|
|
424
|
+
if (await indexdb.tx.count({ hash: { $in: hashes } }) === hashes.length) return missing;
|
|
425
|
+
for (const hash of hashes) {
|
|
426
|
+
if (await indexdb.tx.count({ hash }) > 0) continue;
|
|
427
|
+
if (await Promise.resolve(statedb?.tx?.get?.(hash))) continue;
|
|
428
|
+
missing.add(hash);
|
|
429
|
+
}
|
|
430
|
+
return missing;
|
|
431
|
+
}
|
|
406
432
|
/**
|
|
407
|
-
*
|
|
408
|
-
* orphan
|
|
433
|
+
* After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
|
|
434
|
+
* have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
|
|
435
|
+
* from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
|
|
436
|
+
* holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
|
|
437
|
+
* `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
|
|
438
|
+
* is authenticated as before and fails closed.
|
|
409
439
|
*/
|
|
410
440
|
async indexExistingOrphanEntries(fromSeq = 1, toSeq) {
|
|
411
441
|
const latestSeq = toSeq ?? await this.resolver.ledger.getLatestSequence();
|
|
@@ -414,11 +444,13 @@ var LedgerEntryReplayer = class {
|
|
|
414
444
|
const pageSize = 200;
|
|
415
445
|
for (let cursor = Math.max(1, fromSeq); cursor <= latestSeq; cursor += pageSize) {
|
|
416
446
|
const end = Math.min(latestSeq, cursor + pageSize - 1);
|
|
417
|
-
const
|
|
418
|
-
|
|
447
|
+
const candidates = (await this.resolver.ledger.getRange(cursor, end)).filter((entry) => !entry.stateCommitHash || !entry.stateCommitHash.trim());
|
|
448
|
+
const missing = await this.hashesMissingFromIndex(candidates);
|
|
449
|
+
for (const entry of candidates) {
|
|
450
|
+
if (!missing.has(String(entry.hash).toUpperCase())) continue;
|
|
419
451
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
420
|
-
|
|
421
|
-
await this.indexOrphanEntry(entry
|
|
452
|
+
this.authenticateAndDecodeEntry(entry);
|
|
453
|
+
await this.indexOrphanEntry(entry);
|
|
422
454
|
indexedCount++;
|
|
423
455
|
}
|
|
424
456
|
}
|
package/lib/explorer.cjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
1
2
|
const require_dashboard = require('./dashboard.cjs');
|
|
3
|
+
let _ocap_util_lib_client_ip = require("@ocap/util/lib/client-ip");
|
|
2
4
|
|
|
3
5
|
//#region src/explorer.ts
|
|
4
6
|
function loadNodeBuiltin(id) {
|
|
@@ -119,8 +121,15 @@ function createExplorerMiddleware(options) {
|
|
|
119
121
|
if (verifiedDistRealPath && reqPath === "/static/js/networks.js") {
|
|
120
122
|
const cfg = options.getConfig() ?? {};
|
|
121
123
|
const chainId = String(cfg.chainId || "local-chain");
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
+
const rawHost = String(req.get?.("host") || req.headers?.host || "").trim();
|
|
125
|
+
const safeHost = rawHost.length > 0 && rawHost.length <= 255 && (/^[A-Za-z0-9.-]+(?::\d{1,5})?$/.test(rawHost) || /^\[[0-9a-fA-F:]+\](?::\d{1,5})?$/.test(rawHost)) ? rawHost : "127.0.0.1";
|
|
126
|
+
let scheme = req.protocol === "https" ? "https" : "http";
|
|
127
|
+
if (scheme === "http" && (0, _ocap_util_lib_client_ip.isLoopbackAddress)(req.socket?.remoteAddress)) {
|
|
128
|
+
const xfProto = String(req.headers?.["x-forwarded-proto"] || "").split(",")[0].trim().toLowerCase();
|
|
129
|
+
const cfVisitor = String(req.headers?.["cf-visitor"] || "");
|
|
130
|
+
if (xfProto === "https" || /"scheme"\s*:\s*"https"/i.test(cfVisitor)) scheme = "https";
|
|
131
|
+
}
|
|
132
|
+
const endpoint = /^https?:\/\//.test(chainEndpoint) ? chainEndpoint : `${scheme}://${safeHost}${chainEndpoint.startsWith("/") ? "" : "/"}${chainEndpoint.replace(/\/+$/, "")}/`;
|
|
124
133
|
const networks = [{
|
|
125
134
|
name: chainId,
|
|
126
135
|
abbr: cfg.token?.symbol || "ARC",
|
|
@@ -130,7 +139,8 @@ function createExplorerMiddleware(options) {
|
|
|
130
139
|
}];
|
|
131
140
|
applyExplorerSecurityHeaders(res, false);
|
|
132
141
|
res.setHeader("Content-Type", "application/javascript; charset=utf-8");
|
|
133
|
-
res.setHeader("Cache-Control", "no-
|
|
142
|
+
res.setHeader("Cache-Control", "no-store");
|
|
143
|
+
res.setHeader("Vary", "Host, X-Forwarded-Proto, CF-Visitor");
|
|
134
144
|
return res.status(200).send(`window.ARCBLOCK_NETWORKS = ${safeJsonForJsLiteral(networks)};\n`);
|
|
135
145
|
}
|
|
136
146
|
if (reqPath === "/static/js/networks.js") {
|
package/lib/follower.cjs
CHANGED
|
@@ -1536,7 +1536,7 @@ var FollowerSyncService = class {
|
|
|
1536
1536
|
if (entry.finalized !== true) throw new _ocap_util_lib_error.CustomError("UNFINALIZED_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} is not finalized`);
|
|
1537
1537
|
if (!Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > MAX_SAFE_EPOCH_MS) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} has invalid timestamp: ${String(entry.timestamp)}`);
|
|
1538
1538
|
if (typeof entry.txRaw !== "string" || !entry.txRaw || entry.txRaw !== entry.txRaw.trim()) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Hot-tail entry seq=${entry.sequence} has missing or non-canonical txRaw`);
|
|
1539
|
-
this.replayer.validateWireEntry(entry);
|
|
1539
|
+
this.replayer.validateWireEntry(entry, { skipFutureTimestampCheck: true });
|
|
1540
1540
|
const expectedHash = (0, _arcblock_ledger_core.computeEntryHash)(entry.sequence, entry.txRaw, entry.stateCommitHash ?? "", entry.sequence >= v2Cutoff ? 2 : 1);
|
|
1541
1541
|
if (entry.entryHash !== expectedHash) throw new _ocap_util_lib_error.CustomError("LEDGER_DIVERGENCE", `Hot-tail entryHash mismatch at seq=${entry.sequence}: expected ${expectedHash}, got ${entry.entryHash}`);
|
|
1542
1542
|
entryHashes.push(entry.entryHash);
|
|
@@ -1564,6 +1564,7 @@ var FollowerSyncService = class {
|
|
|
1564
1564
|
signatureRatchetLocked: true
|
|
1565
1565
|
});
|
|
1566
1566
|
}
|
|
1567
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1567
1568
|
return batchParsedV2From;
|
|
1568
1569
|
}
|
|
1569
1570
|
const cp = upstreamStatus.latestCheckpoint;
|
|
@@ -1587,11 +1588,15 @@ var FollowerSyncService = class {
|
|
|
1587
1588
|
signatureRatchetLocked: true
|
|
1588
1589
|
});
|
|
1589
1590
|
}
|
|
1591
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1590
1592
|
return;
|
|
1591
1593
|
}
|
|
1592
1594
|
}
|
|
1593
1595
|
}
|
|
1594
|
-
if (importOpts.allowUnauthenticated && !entriesBody.batchSignature && !this.hotstuffClusterConfig)
|
|
1596
|
+
if (importOpts.allowUnauthenticated && !entriesBody.batchSignature && !this.hotstuffClusterConfig) {
|
|
1597
|
+
for (const entry of entries) this.replayer.assertEntryTimestampNotInFuture(entry);
|
|
1598
|
+
return batchParsedV2From ?? parsedV2From;
|
|
1599
|
+
}
|
|
1595
1600
|
throw new _ocap_util_lib_error.CustomError("HOT_TAIL_SIGNATURE_MISSING", "Hot-tail /api/ledger/entries response is missing a valid proposer batchSignature");
|
|
1596
1601
|
}
|
|
1597
1602
|
/**
|
|
@@ -1796,7 +1801,7 @@ var FollowerSyncService = class {
|
|
|
1796
1801
|
for (const item of batch) {
|
|
1797
1802
|
if (item.sequence > targetCp.sequence) break;
|
|
1798
1803
|
if (item.sequence !== cursor) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Non-contiguous entry sequence at height ${nextHeight}: expected ${cursor}, got ${item.sequence}`);
|
|
1799
|
-
this.replayer.validateWireEntry(item);
|
|
1804
|
+
this.replayer.validateWireEntry(item, { skipFutureTimestampCheck: true });
|
|
1800
1805
|
segmentEntries.push(item);
|
|
1801
1806
|
cursor++;
|
|
1802
1807
|
}
|
|
@@ -1819,6 +1824,7 @@ var FollowerSyncService = class {
|
|
|
1819
1824
|
requireSignature: !importOpts.allowUnauthenticated,
|
|
1820
1825
|
allowUnauthenticated: importOpts.allowUnauthenticated
|
|
1821
1826
|
});
|
|
1827
|
+
for (const item of segmentEntries) this.replayer.assertEntryTimestampNotInFuture(item);
|
|
1822
1828
|
let mutatedLocalDb = false;
|
|
1823
1829
|
try {
|
|
1824
1830
|
if (segmentEntries.length > 0 && typeof this.resolver.statedb.runWithinDryRunSession === "function") {
|
package/lib/hooks.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_package = require('./package.cjs');
|
|
3
3
|
let _ocap_util = require("@ocap/util");
|
|
4
|
+
let lodash_merge = require("lodash/merge");
|
|
5
|
+
lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
|
|
4
6
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
5
7
|
let debug = require("debug");
|
|
6
8
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
7
|
-
let lodash_merge = require("lodash/merge");
|
|
8
|
-
lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
|
|
9
9
|
let lodash_pick = require("lodash/pick");
|
|
10
10
|
lodash_pick = require_rolldown_runtime.__toESM(lodash_pick);
|
|
11
11
|
|
package/lib/index.cjs
CHANGED
|
@@ -21,6 +21,8 @@ let _ocap_util = require("@ocap/util");
|
|
|
21
21
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
22
22
|
let _ocap_state = require("@ocap/state");
|
|
23
23
|
_ocap_state = require_rolldown_runtime.__toESM(_ocap_state);
|
|
24
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
25
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
24
26
|
let _arcblock_did_util = require("@arcblock/did-util");
|
|
25
27
|
let debug = require("debug");
|
|
26
28
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
@@ -35,8 +37,6 @@ let _ocap_tx_protocols_lib_util = require("@ocap/tx-protocols/lib/util");
|
|
|
35
37
|
let _ocap_util_lib_constant = require("@ocap/util/lib/constant");
|
|
36
38
|
let _ocap_util_lib_deposit_v2_bridge_fields = require("@ocap/util/lib/deposit-v2-bridge-fields");
|
|
37
39
|
let _ocap_util_lib_md5 = require("@ocap/util/lib/md5");
|
|
38
|
-
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
39
|
-
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
40
40
|
let lodash_get = require("lodash/get");
|
|
41
41
|
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
42
42
|
let lodash_isEmpty = require("lodash/isEmpty");
|
package/lib/node-preferences.cjs
CHANGED
|
@@ -832,8 +832,9 @@ var NodePreferencesManager = class {
|
|
|
832
832
|
* socket address alone would put all clients in one bucket; `resolveClientIp` reads the trusted proxy header
|
|
833
833
|
* (`CHAIN_CLIENT_IP_HEADERS`, default `x-real-ip`) only from a loopback peer and ignores them from a remote one (#1922, trust rule in `@ocap/util/lib/client-ip`).
|
|
834
834
|
*/
|
|
835
|
-
function extractClientIp(req) {
|
|
836
|
-
|
|
835
|
+
function extractClientIp(req, env) {
|
|
836
|
+
const headers = env !== void 0 ? (0, _ocap_util_lib_client_ip.getTrustedClientIpHeaders)(env.CHAIN_CLIENT_IP_HEADERS) : void 0;
|
|
837
|
+
return (0, _ocap_util_lib_client_ip.resolveClientIp)(req, headers !== void 0 ? { headers } : void 0) || "unknown";
|
|
837
838
|
}
|
|
838
839
|
function extractProvidedAdminToken(req) {
|
|
839
840
|
const headers = req.headers || {};
|
|
@@ -925,7 +926,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
925
926
|
const isGatewayNonAdminBearerOnly = Boolean(req.user) && !hasAdminSpecificHeader;
|
|
926
927
|
if (hasExplicitAuthHeader && !isGatewayNonAdminBearerOnly) {
|
|
927
928
|
const now = Date.now();
|
|
928
|
-
const ip = extractClientIp(req);
|
|
929
|
+
const ip = extractClientIp(req, env);
|
|
929
930
|
if (!isRateLimited(ip, now).limited) recordFailure(ip, now);
|
|
930
931
|
}
|
|
931
932
|
return false;
|
|
@@ -939,7 +940,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
939
940
|
if (timingSafeTokenEqual(expected, token)) return "admin";
|
|
940
941
|
if (Boolean(req.user) && !hasAdminSpecificHeader) return "anonymous";
|
|
941
942
|
const now = Date.now();
|
|
942
|
-
const ip = extractClientIp(req);
|
|
943
|
+
const ip = extractClientIp(req, env);
|
|
943
944
|
const rate = isRateLimited(ip, now);
|
|
944
945
|
if (rate.limited) {
|
|
945
946
|
res.setHeader("Retry-After", String(rate.retryAfterSec));
|
|
@@ -999,7 +1000,7 @@ function createAdminAuthGuard(options = {}) {
|
|
|
999
1000
|
return;
|
|
1000
1001
|
}
|
|
1001
1002
|
const now = Date.now();
|
|
1002
|
-
const ip = extractClientIp(req);
|
|
1003
|
+
const ip = extractClientIp(req, env);
|
|
1003
1004
|
const rate = isRateLimited(ip, now);
|
|
1004
1005
|
if (rate.limited) {
|
|
1005
1006
|
res.setHeader("Retry-After", String(rate.retryAfterSec));
|
package/lib/replayer.cjs
CHANGED
|
@@ -5,6 +5,11 @@ let _ocap_tx_protocols = require("@ocap/tx-protocols");
|
|
|
5
5
|
let _ocap_util = require("@ocap/util");
|
|
6
6
|
let _ocap_util_lib_error = require("@ocap/util/lib/error");
|
|
7
7
|
let _ocap_state = require("@ocap/state");
|
|
8
|
+
let _ocap_tx_pipeline = require("@ocap/tx-pipeline");
|
|
9
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
10
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
11
|
+
let lodash_merge = require("lodash/merge");
|
|
12
|
+
lodash_merge = require_rolldown_runtime.__toESM(lodash_merge);
|
|
8
13
|
|
|
9
14
|
//#region src/replayer.ts
|
|
10
15
|
/**
|
|
@@ -186,29 +191,38 @@ var LedgerEntryReplayer = class {
|
|
|
186
191
|
}
|
|
187
192
|
authenticateAndDecodeEntry(entry) {
|
|
188
193
|
const authRes = (0, _arcblock_ledger_core.authenticateEntryDecodedFields)(entry, true, { requireFullWireEntry: true });
|
|
189
|
-
if (!authRes.ok) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${entry.sequence} failed field authentication: ${authRes.reason}`);
|
|
194
|
+
if (!authRes.ok) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${entry.sequence} hash=${String(entry.hash)} failed field authentication: ${authRes.reason}`);
|
|
190
195
|
return authRes.decodedTx;
|
|
191
196
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
|
|
199
|
+
* leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
|
|
200
|
+
* follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
|
|
201
|
+
* (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
|
|
202
|
+
*/
|
|
203
|
+
async indexOrphanEntry(entry) {
|
|
204
|
+
const ctx = {
|
|
205
|
+
txBase64: entry.txRaw,
|
|
206
|
+
config: this.resolver.config,
|
|
207
|
+
extra: { txTime: entry.timestamp }
|
|
208
|
+
};
|
|
209
|
+
const runPipe = (pipe) => new Promise((resolve, reject) => {
|
|
210
|
+
try {
|
|
211
|
+
pipe(ctx, (err) => err ? reject(err) : resolve());
|
|
212
|
+
} catch (err) {
|
|
213
|
+
reject(err);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
try {
|
|
217
|
+
await runPipe(_ocap_tx_pipeline.pipes.DecodeTx);
|
|
218
|
+
await runPipe(_ocap_tx_pipeline.pipes.DecodeItx);
|
|
219
|
+
} catch (err) {
|
|
220
|
+
throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Orphan ledger entry seq=${entry.sequence} hash=${entry.hash} does not decode as the leader decodes it: ${err instanceof Error ? err.message : String(err)}`);
|
|
221
|
+
}
|
|
222
|
+
if (String(ctx.txHash ?? "").toUpperCase() !== String(entry.hash).toUpperCase()) throw new _ocap_util_lib_error.CustomError("TX_HASH_MISMATCH", `Orphan ledger entry seq=${entry.sequence} hash=${entry.hash}: txRaw does not hash to its entry hash`);
|
|
223
|
+
const leaderCtx = (0, lodash_merge.default)((0, lodash_cloneDeep.default)(ctx), ctx);
|
|
224
|
+
leaderCtx.ledgerSequence = entry.sequence;
|
|
225
|
+
await this.resolver._indexRejectedLedgerTx(leaderCtx, { code: "ORPHAN_LEDGER_ENTRY" });
|
|
212
226
|
await this.resolver.flushIndexWrites();
|
|
213
227
|
}
|
|
214
228
|
/**
|
|
@@ -241,7 +255,7 @@ var LedgerEntryReplayer = class {
|
|
|
241
255
|
}
|
|
242
256
|
if (appendToLedger) this.assertEntryTimestampNotInFuture(entry);
|
|
243
257
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
244
|
-
|
|
258
|
+
this.authenticateAndDecodeEntry(entry);
|
|
245
259
|
const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
|
|
246
260
|
if (appendToLedger) {
|
|
247
261
|
const v2Cutoff = options.entryHashV2From === "infinity" ? Number.POSITIVE_INFINITY : typeof options.entryHashV2From === "number" ? options.entryHashV2From : this.resolver.ledger.getEntryHashV2From?.() ?? 1;
|
|
@@ -250,7 +264,7 @@ var LedgerEntryReplayer = class {
|
|
|
250
264
|
}
|
|
251
265
|
if (!expectedStateCommit) {
|
|
252
266
|
if (appendToLedger) await this.appendVerifiedEntryToLedger(entry, options.entryHashV2From);
|
|
253
|
-
await this.indexOrphanEntry(entry
|
|
267
|
+
await this.indexOrphanEntry(entry);
|
|
254
268
|
return {
|
|
255
269
|
status: "orphan-indexed",
|
|
256
270
|
sequence: entry.sequence,
|
|
@@ -404,9 +418,27 @@ var LedgerEntryReplayer = class {
|
|
|
404
418
|
};
|
|
405
419
|
});
|
|
406
420
|
}
|
|
421
|
+
/** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
|
|
422
|
+
async hashesMissingFromIndex(entries) {
|
|
423
|
+
const missing = /* @__PURE__ */ new Set();
|
|
424
|
+
if (entries.length === 0) return missing;
|
|
425
|
+
const hashes = [...new Set(entries.map((e) => String(e.hash).toUpperCase()))];
|
|
426
|
+
const { indexdb, statedb } = this.resolver;
|
|
427
|
+
if (await indexdb.tx.count({ hash: { $in: hashes } }) === hashes.length) return missing;
|
|
428
|
+
for (const hash of hashes) {
|
|
429
|
+
if (await indexdb.tx.count({ hash }) > 0) continue;
|
|
430
|
+
if (await Promise.resolve(statedb?.tx?.get?.(hash))) continue;
|
|
431
|
+
missing.add(hash);
|
|
432
|
+
}
|
|
433
|
+
return missing;
|
|
434
|
+
}
|
|
407
435
|
/**
|
|
408
|
-
*
|
|
409
|
-
* orphan
|
|
436
|
+
* After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
|
|
437
|
+
* have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
|
|
438
|
+
* from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
|
|
439
|
+
* holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
|
|
440
|
+
* `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
|
|
441
|
+
* is authenticated as before and fails closed.
|
|
410
442
|
*/
|
|
411
443
|
async indexExistingOrphanEntries(fromSeq = 1, toSeq) {
|
|
412
444
|
const latestSeq = toSeq ?? await this.resolver.ledger.getLatestSequence();
|
|
@@ -415,11 +447,13 @@ var LedgerEntryReplayer = class {
|
|
|
415
447
|
const pageSize = 200;
|
|
416
448
|
for (let cursor = Math.max(1, fromSeq); cursor <= latestSeq; cursor += pageSize) {
|
|
417
449
|
const end = Math.min(latestSeq, cursor + pageSize - 1);
|
|
418
|
-
const
|
|
419
|
-
|
|
450
|
+
const candidates = (await this.resolver.ledger.getRange(cursor, end)).filter((entry) => !entry.stateCommitHash || !entry.stateCommitHash.trim());
|
|
451
|
+
const missing = await this.hashesMissingFromIndex(candidates);
|
|
452
|
+
for (const entry of candidates) {
|
|
453
|
+
if (!missing.has(String(entry.hash).toUpperCase())) continue;
|
|
420
454
|
this.verifyRawTxHashMatchesEntry(entry);
|
|
421
|
-
|
|
422
|
-
await this.indexOrphanEntry(entry
|
|
455
|
+
this.authenticateAndDecodeEntry(entry);
|
|
456
|
+
await this.indexOrphanEntry(entry);
|
|
423
457
|
indexedCount++;
|
|
424
458
|
}
|
|
425
459
|
}
|
package/lib/replayer.d.cts
CHANGED
|
@@ -93,6 +93,12 @@ declare class LedgerEntryReplayer {
|
|
|
93
93
|
*/
|
|
94
94
|
validateWireEntry(entry: ILedgerEntry, options?: IValidateWireEntryOptions): void;
|
|
95
95
|
private authenticateAndDecodeEntry;
|
|
96
|
+
/**
|
|
97
|
+
* Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
|
|
98
|
+
* leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
|
|
99
|
+
* follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
|
|
100
|
+
* (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
|
|
101
|
+
*/
|
|
96
102
|
private indexOrphanEntry;
|
|
97
103
|
/**
|
|
98
104
|
* Replay a single finalized `ILedgerEntry` sequentially (`concurrency = 1`).
|
|
@@ -104,9 +110,15 @@ declare class LedgerEntryReplayer {
|
|
|
104
110
|
* and post-execution `_state_commit` hash with zero mutations to `statedb`, `trusted`, `indexdb`, or `ledger`.
|
|
105
111
|
*/
|
|
106
112
|
dryRunVerifyEntries(entries: ILedgerEntry[], options?: IDryRunVerifyEntriesOptions): Promise<IDryRunVerifyEntriesResult>;
|
|
113
|
+
/** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
|
|
114
|
+
private hashesMissingFromIndex;
|
|
107
115
|
/**
|
|
108
|
-
*
|
|
109
|
-
* orphan
|
|
116
|
+
* After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
|
|
117
|
+
* have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
|
|
118
|
+
* from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
|
|
119
|
+
* holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
|
|
120
|
+
* `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
|
|
121
|
+
* is authenticated as before and fails closed.
|
|
110
122
|
*/
|
|
111
123
|
indexExistingOrphanEntries(fromSeq?: number, toSeq?: number): Promise<number>;
|
|
112
124
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.32.
|
|
6
|
+
"version": "1.32.2",
|
|
7
7
|
"description": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -54,21 +54,22 @@
|
|
|
54
54
|
"tsdown": "^0.18.4"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@arcblock/did": "1.32.
|
|
58
|
-
"@arcblock/did-ext": "1.32.
|
|
59
|
-
"@arcblock/did-util": "1.32.
|
|
60
|
-
"@arcblock/ledger-core": "1.32.
|
|
57
|
+
"@arcblock/did": "1.32.2",
|
|
58
|
+
"@arcblock/did-ext": "1.32.2",
|
|
59
|
+
"@arcblock/did-util": "1.32.2",
|
|
60
|
+
"@arcblock/ledger-core": "1.32.2",
|
|
61
61
|
"@arcblock/nft-display": "^3.2.3",
|
|
62
|
-
"@arcblock/validator": "1.32.
|
|
63
|
-
"@ocap/config": "1.32.
|
|
64
|
-
"@ocap/indexdb": "1.32.
|
|
65
|
-
"@ocap/mcrypto": "1.32.
|
|
66
|
-
"@ocap/message": "1.32.
|
|
67
|
-
"@ocap/state": "1.32.
|
|
68
|
-
"@ocap/tx-
|
|
69
|
-
"@ocap/
|
|
70
|
-
"@ocap/
|
|
71
|
-
"@ocap/
|
|
62
|
+
"@arcblock/validator": "1.32.2",
|
|
63
|
+
"@ocap/config": "1.32.2",
|
|
64
|
+
"@ocap/indexdb": "1.32.2",
|
|
65
|
+
"@ocap/mcrypto": "1.32.2",
|
|
66
|
+
"@ocap/message": "1.32.2",
|
|
67
|
+
"@ocap/state": "1.32.2",
|
|
68
|
+
"@ocap/tx-pipeline": "1.32.2",
|
|
69
|
+
"@ocap/tx-protocols": "1.32.2",
|
|
70
|
+
"@ocap/types": "1.32.2",
|
|
71
|
+
"@ocap/util": "1.32.2",
|
|
72
|
+
"@ocap/wallet": "1.32.2",
|
|
72
73
|
"debug": "^4.4.3",
|
|
73
74
|
"express": "^4.22.1",
|
|
74
75
|
"lodash": "^4.17.23",
|