@ocap/resolver 1.32.1 → 1.32.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/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");
@@ -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
- return (0, _ocap_util_lib_client_ip.resolveClientIp)(req) || "unknown";
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
  /**
@@ -22,6 +27,22 @@ let _ocap_state = require("@ocap/state");
22
27
  * - Enforces pre-commit `expectedCommitHash` on `statedb.runAsLambda` so any state divergence rolls back
23
28
  * SQLite atomically BEFORE `COMMIT` and before appending to `ledger.sqlite`.
24
29
  */
30
+ /**
31
+ * Cross-layer chainId rule for executable replay (#2029, #2039):
32
+ * Own-chain entries (`entry.chainId === expectedChainId`) are accepted directly; a self-declared foreign-`chainId`
33
+ * wire entry (`isEntryChainIdAcceptable(entry, expectedChainId)`) can ONLY execute as a force-finalized orphan
34
+ * (`(entry.stateCommitHash ?? '').trim() === ''`), because `VerifyTx` rejects `chainId !== config.chainId` before
35
+ * `PrepareState`/`CommitState` so a foreign-`chainId` entry can never commit state.
36
+ */
37
+ function isReplayEntryChainIdAcceptable(entry, expectedChainId) {
38
+ if (entry.chainId === expectedChainId) return true;
39
+ return (0, _arcblock_ledger_core.isEntryChainIdAcceptable)(entry, expectedChainId) && (entry.stateCommitHash ?? "").trim() === "";
40
+ }
41
+ function assertReplayEntryChainIdAcceptable(entry, expectedChainId, prefix = "Ledger entry") {
42
+ if (isReplayEntryChainIdAcceptable(entry, expectedChainId)) return;
43
+ if (entry.chainId !== expectedChainId && typeof entry.txRaw === "string" && (0, _arcblock_ledger_core.isEntryChainIdAcceptable)(entry, expectedChainId) && (entry.stateCommitHash ?? "").trim() !== "") throw new _ocap_util_lib_error.CustomError("CHAIN_ID_MISMATCH", `${prefix} foreign-chainId entry at seq=${String(entry.sequence)} (chainId=${String(entry.chainId)}, local=${expectedChainId}) cannot carry a stateCommitHash`);
44
+ throw new _ocap_util_lib_error.CustomError("CHAIN_ID_MISMATCH", `${prefix} chainId mismatch at seq=${String(entry.sequence)}: expected ${expectedChainId}, got ${String(entry.chainId)}`);
45
+ }
25
46
  /** Error code of a replayed entry refused for a timestamp ahead of the local clock (retryable, never halting). */
26
47
  const FUTURE_LEDGER_ENTRY_TIMESTAMP = "FUTURE_LEDGER_ENTRY_TIMESTAMP";
27
48
  function normalizeHexLower(raw) {
@@ -182,33 +203,56 @@ var LedgerEntryReplayer = class {
182
203
  if (!entry || typeof entry !== "object" || !Number.isSafeInteger(entry.sequence) || entry.sequence < 1 || !Number.isSafeInteger(entry.nonce) || entry.nonce < 0 || !Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > 864e13 || typeof entry.hash !== "string" || typeof entry.from !== "string" || typeof entry.pk !== "string" || typeof entry.signature !== "string" || typeof entry.txRaw !== "string" || typeof entry.txType !== "string" || typeof entry.chainId !== "string" || typeof entry.entryHash !== "string" || typeof entry.finalized !== "boolean" || entry.stateCommitHash !== void 0 && typeof entry.stateCommitHash !== "string" || entry.tx === null || typeof entry.tx !== "object" || Array.isArray(entry.tx)) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${String(entry?.sequence)} has invalid wire primitive types`);
183
204
  this.verifyRawTxHashMatchesEntry(entry, "INVALID_LEDGER_ENTRY");
184
205
  this.authenticateAndDecodeEntry(entry);
206
+ if (!(entry.stateCommitHash ?? "").trim()) this.decodeOrphanEntryContext(entry);
185
207
  if (!options.skipFutureTimestampCheck) this.assertEntryTimestampNotInFuture(entry);
186
208
  }
187
209
  authenticateAndDecodeEntry(entry) {
188
210
  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}`);
211
+ 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
212
  return authRes.decodedTx;
191
213
  }
192
- async indexOrphanEntry(entry, decodedTx) {
193
- const safeTx = decodedTx && typeof decodedTx === "object" ? decodedTx : {};
194
- const rawItx = safeTx.itx && typeof safeTx.itx === "object" ? safeTx.itx : void 0;
195
- const derivedTxType = rawItx && typeof rawItx.typeUrl === "string" && rawItx.typeUrl ? rawItx.typeUrl : rawItx && typeof rawItx.type === "string" && rawItx.type ? rawItx.type : typeof safeTx.txType === "string" && safeTx.txType ? safeTx.txType : entry.txType;
196
- const txTimeIso = Number.isSafeInteger(entry.timestamp) && entry.timestamp >= 0 && entry.timestamp <= 864e13 ? new Date(entry.timestamp).toISOString() : (/* @__PURE__ */ new Date()).toISOString();
197
- await this.resolver._indexRejectedLedgerTx({
198
- ledgerSequence: entry.sequence,
199
- txHash: entry.hash,
200
- txType: derivedTxType,
201
- txTime: txTimeIso,
202
- tx: {
203
- ...safeTx,
204
- from: String(safeTx.from ?? safeTx.spenderDid ?? ""),
205
- nonce: safeTx.nonce ?? 0,
206
- pk: String(safeTx.pk ?? safeTx.spenderPublicKey ?? ""),
207
- signature: String(safeTx.signature ?? safeTx.spenderSignature ?? ""),
208
- chainId: String(safeTx.chainId ?? this.resolver.config.chainId ?? "")
209
- },
210
- ...rawItx ? { itxJson: rawItx } : {}
211
- }, { code: "ORPHAN_LEDGER_ENTRY" });
214
+ /**
215
+ * Synchronously run `pipes.DecodeTx` + `pipes.DecodeItx` on a force-finalized orphan entry (`stateCommitHash === ''`)
216
+ * so any wire byte ceiling, non-canonical `signatures[].data` JSON, undecodable nested Any, or missing `itx` is
217
+ * caught as a peer-disqualifying `INVALID_LEDGER_ENTRY` BEFORE `importSegment` / `appendVerifiedEntryToLedger`
218
+ * mutates `ledger.sqlite` (#2039).
219
+ */
220
+ decodeOrphanEntryContext(entry) {
221
+ const ctx = {
222
+ txBase64: entry.txRaw,
223
+ config: this.resolver.config,
224
+ extra: { txTime: entry.timestamp }
225
+ };
226
+ const runPipeSync = (pipe) => {
227
+ let pipeErr;
228
+ let completed = false;
229
+ pipe(ctx, (err) => {
230
+ completed = true;
231
+ pipeErr = err;
232
+ });
233
+ if (!completed) throw new Error("Orphan decode pipe did not complete synchronously");
234
+ if (pipeErr) throw pipeErr;
235
+ };
236
+ try {
237
+ runPipeSync(_ocap_tx_pipeline.pipes.DecodeTx);
238
+ runPipeSync(_ocap_tx_pipeline.pipes.DecodeItx);
239
+ } catch (err) {
240
+ 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)}`);
241
+ }
242
+ if (String(ctx.txHash ?? "").toUpperCase() !== String(entry.hash).toUpperCase()) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Orphan ledger entry seq=${entry.sequence} hash=${entry.hash}: txRaw does not hash to its entry hash`);
243
+ return ctx;
244
+ }
245
+ /**
246
+ * Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
247
+ * leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
248
+ * follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
249
+ * (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
250
+ */
251
+ async indexOrphanEntry(entry, preDecodedCtx) {
252
+ const ctx = preDecodedCtx ?? this.decodeOrphanEntryContext(entry);
253
+ const leaderCtx = (0, lodash_merge.default)((0, lodash_cloneDeep.default)(ctx), ctx);
254
+ leaderCtx.ledgerSequence = entry.sequence;
255
+ await this.resolver._indexRejectedLedgerTx(leaderCtx, { code: "ORPHAN_LEDGER_ENTRY" });
212
256
  await this.resolver.flushIndexWrites();
213
257
  }
214
258
  /**
@@ -219,8 +263,7 @@ var LedgerEntryReplayer = class {
219
263
  if (!entry || typeof entry !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", "Cannot replay null or non-object ledger entry");
220
264
  if (!entry.finalized) throw new _ocap_util_lib_error.CustomError("UNFINALIZED_LEDGER_ENTRY", `Refusing to replay unfinalized entry seq=${entry.sequence}`);
221
265
  if (!Number.isSafeInteger(entry.timestamp) || entry.timestamp < 0 || entry.timestamp > 864e13) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Refusing to replay entry seq=${entry.sequence} with out-of-range timestamp: ${String(entry.timestamp)}`);
222
- const expectedChainId = this.resolver.config.chainId || this.resolver.ledger.chainId;
223
- if (entry.chainId !== expectedChainId) throw new _ocap_util_lib_error.CustomError("CHAIN_ID_MISMATCH", `Ledger entry chainId mismatch at seq=${entry.sequence}: expected ${expectedChainId}, got ${entry.chainId}`);
266
+ assertReplayEntryChainIdAcceptable(entry, this.resolver.config.chainId || this.resolver.ledger.chainId, "Ledger entry");
224
267
  const appendToLedger = options.appendToLedger !== false;
225
268
  if (options.entryHashV2From !== void 0 && options.entryHashV2From !== "infinity" && (!Number.isSafeInteger(options.entryHashV2From) || options.entryHashV2From < 1)) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Invalid entryHashV2From replay option: ${String(options.entryHashV2From)}`);
226
269
  if (!Number.isSafeInteger(entry.sequence) || entry.sequence < 1 || !Number.isSafeInteger(entry.nonce) || entry.nonce < 0 || typeof entry.entryHash !== "string" || !entry.entryHash || entry.stateCommitHash !== void 0 && typeof entry.stateCommitHash !== "string") throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entry seq=${String(entry.sequence)} has invalid sequence, nonce, or entryHash types`);
@@ -241,7 +284,7 @@ var LedgerEntryReplayer = class {
241
284
  }
242
285
  if (appendToLedger) this.assertEntryTimestampNotInFuture(entry);
243
286
  this.verifyRawTxHashMatchesEntry(entry);
244
- const decodedTx = this.authenticateAndDecodeEntry(entry);
287
+ this.authenticateAndDecodeEntry(entry);
245
288
  const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
246
289
  if (appendToLedger) {
247
290
  const v2Cutoff = options.entryHashV2From === "infinity" ? Number.POSITIVE_INFINITY : typeof options.entryHashV2From === "number" ? options.entryHashV2From : this.resolver.ledger.getEntryHashV2From?.() ?? 1;
@@ -249,8 +292,9 @@ var LedgerEntryReplayer = class {
249
292
  if (entry.entryHash !== expectedEntryHash) throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Ledger entryHash mismatch before execution at seq=${entry.sequence}: expected ${expectedEntryHash}, got ${entry.entryHash}`);
250
293
  }
251
294
  if (!expectedStateCommit) {
295
+ const decodedOrphanCtx = this.decodeOrphanEntryContext(entry);
252
296
  if (appendToLedger) await this.appendVerifiedEntryToLedger(entry, options.entryHashV2From);
253
- await this.indexOrphanEntry(entry, decodedTx);
297
+ await this.indexOrphanEntry(entry, decodedOrphanCtx);
254
298
  return {
255
299
  status: "orphan-indexed",
256
300
  sequence: entry.sequence,
@@ -329,7 +373,7 @@ var LedgerEntryReplayer = class {
329
373
  const entry = entries[i];
330
374
  if (!entry || typeof entry !== "object") throw new _ocap_util_lib_error.CustomError("INVALID_LEDGER_ENTRY", `Proposal entry at index ${i} is not an object`);
331
375
  if (entry.finalized !== true) throw new _ocap_util_lib_error.CustomError("UNFINALIZED_LEDGER_ENTRY", `Proposal entry seq=${String(entry.sequence)} must be finalized`);
332
- if (entry.chainId !== expectedChainId) throw new _ocap_util_lib_error.CustomError("CHAIN_ID_MISMATCH", `Proposal entry chainId mismatch at seq=${String(entry.sequence)}: expected ${expectedChainId}, got ${entry.chainId}`);
376
+ assertReplayEntryChainIdAcceptable(entry, expectedChainId, "Proposal entry");
333
377
  if (entry.sequence !== baseSeq + i + 1) throw new _ocap_util_lib_error.CustomError("SEQUENCE_GAP", `Proposal entry sequence mismatch at index ${i}: expected ${baseSeq + i + 1}, got ${entry.sequence}`);
334
378
  this.validateWireEntry(entry, { skipFutureTimestampCheck: options.skipFutureTimestampCheck });
335
379
  const expectedStateCommit = (entry.stateCommitHash ?? "").trim();
@@ -404,9 +448,27 @@ var LedgerEntryReplayer = class {
404
448
  };
405
449
  });
406
450
  }
451
+ /** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
452
+ async hashesMissingFromIndex(entries) {
453
+ const missing = /* @__PURE__ */ new Set();
454
+ if (entries.length === 0) return missing;
455
+ const hashes = [...new Set(entries.map((e) => String(e.hash).toUpperCase()))];
456
+ const { indexdb, statedb } = this.resolver;
457
+ if (await indexdb.tx.count({ hash: { $in: hashes } }) === hashes.length) return missing;
458
+ for (const hash of hashes) {
459
+ if (await indexdb.tx.count({ hash }) > 0) continue;
460
+ if (await Promise.resolve(statedb?.tx?.get?.(hash))) continue;
461
+ missing.add(hash);
462
+ }
463
+ return missing;
464
+ }
407
465
  /**
408
- * Scan existing local ledger entries in `[fromSeq, toSeq]` and ensure any force-finalized
409
- * orphan entries (`stateCommitHash === ''`) are indexed into `indexdb.tx` after `rebuildIndex()`.
466
+ * After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
467
+ * have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
468
+ * from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
469
+ * holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
470
+ * `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
471
+ * is authenticated as before and fails closed.
410
472
  */
411
473
  async indexExistingOrphanEntries(fromSeq = 1, toSeq) {
412
474
  const latestSeq = toSeq ?? await this.resolver.ledger.getLatestSequence();
@@ -415,11 +477,13 @@ var LedgerEntryReplayer = class {
415
477
  const pageSize = 200;
416
478
  for (let cursor = Math.max(1, fromSeq); cursor <= latestSeq; cursor += pageSize) {
417
479
  const end = Math.min(latestSeq, cursor + pageSize - 1);
418
- const entries = await this.resolver.ledger.getRange(cursor, end);
419
- for (const entry of entries) if (!entry.stateCommitHash || !entry.stateCommitHash.trim()) {
480
+ const candidates = (await this.resolver.ledger.getRange(cursor, end)).filter((entry) => !entry.stateCommitHash || !entry.stateCommitHash.trim());
481
+ const missing = await this.hashesMissingFromIndex(candidates);
482
+ for (const entry of candidates) {
483
+ if (!missing.has(String(entry.hash).toUpperCase())) continue;
420
484
  this.verifyRawTxHashMatchesEntry(entry);
421
- const decodedTx = this.authenticateAndDecodeEntry(entry);
422
- await this.indexOrphanEntry(entry, decodedTx);
485
+ this.authenticateAndDecodeEntry(entry);
486
+ await this.indexOrphanEntry(entry);
423
487
  indexedCount++;
424
488
  }
425
489
  }
@@ -429,4 +493,6 @@ var LedgerEntryReplayer = class {
429
493
 
430
494
  //#endregion
431
495
  exports.FUTURE_LEDGER_ENTRY_TIMESTAMP = FUTURE_LEDGER_ENTRY_TIMESTAMP;
432
- exports.LedgerEntryReplayer = LedgerEntryReplayer;
496
+ exports.LedgerEntryReplayer = LedgerEntryReplayer;
497
+ exports.assertReplayEntryChainIdAcceptable = assertReplayEntryChainIdAcceptable;
498
+ exports.isReplayEntryChainIdAcceptable = isReplayEntryChainIdAcceptable;
@@ -31,6 +31,24 @@ interface IDryRunVerifyEntriesOptions {
31
31
  /** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
32
32
  skipFutureTimestampCheck?: boolean;
33
33
  }
34
+ /**
35
+ * Cross-layer chainId rule for executable replay (#2029, #2039):
36
+ * Own-chain entries (`entry.chainId === expectedChainId`) are accepted directly; a self-declared foreign-`chainId`
37
+ * wire entry (`isEntryChainIdAcceptable(entry, expectedChainId)`) can ONLY execute as a force-finalized orphan
38
+ * (`(entry.stateCommitHash ?? '').trim() === ''`), because `VerifyTx` rejects `chainId !== config.chainId` before
39
+ * `PrepareState`/`CommitState` so a foreign-`chainId` entry can never commit state.
40
+ */
41
+ declare function isReplayEntryChainIdAcceptable(entry: {
42
+ chainId?: string | null;
43
+ txRaw: string;
44
+ stateCommitHash?: string | null;
45
+ }, expectedChainId: string): boolean;
46
+ declare function assertReplayEntryChainIdAcceptable(entry: {
47
+ sequence?: unknown;
48
+ chainId?: string | null;
49
+ txRaw: string;
50
+ stateCommitHash?: string | null;
51
+ }, expectedChainId: string, prefix?: string): void;
34
52
  interface IValidateWireEntryOptions {
35
53
  /** Entries come from the local ledger (crash reconciliation), not from a peer: skip the future-timestamp guard. */
36
54
  skipFutureTimestampCheck?: boolean;
@@ -93,6 +111,19 @@ declare class LedgerEntryReplayer {
93
111
  */
94
112
  validateWireEntry(entry: ILedgerEntry, options?: IValidateWireEntryOptions): void;
95
113
  private authenticateAndDecodeEntry;
114
+ /**
115
+ * Synchronously run `pipes.DecodeTx` + `pipes.DecodeItx` on a force-finalized orphan entry (`stateCommitHash === ''`)
116
+ * so any wire byte ceiling, non-canonical `signatures[].data` JSON, undecodable nested Any, or missing `itx` is
117
+ * caught as a peer-disqualifying `INVALID_LEDGER_ENTRY` BEFORE `importSegment` / `appendVerifiedEntryToLedger`
118
+ * mutates `ledger.sqlite` (#2039).
119
+ */
120
+ private decodeOrphanEntryContext;
121
+ /**
122
+ * Index a rejected-but-ledgered entry (finalized, no stateCommitHash) with the row the leader wrote for it: the
123
+ * leader's `sendTx` passes the context of its `DecodeTx` + `DecodeItx` pipes to `_indexRejectedLedgerTx`, so the
124
+ * follower builds that context from the entry's txRaw with the same pipes and the time pinned to the entry
125
+ * (#1875). Only the rejection code differs: it is not in the ledger, so the row says `ORPHAN_LEDGER_ENTRY`.
126
+ */
96
127
  private indexOrphanEntry;
97
128
  /**
98
129
  * Replay a single finalized `ILedgerEntry` sequentially (`concurrency = 1`).
@@ -104,11 +135,17 @@ declare class LedgerEntryReplayer {
104
135
  * and post-execution `_state_commit` hash with zero mutations to `statedb`, `trusted`, `indexdb`, or `ledger`.
105
136
  */
106
137
  dryRunVerifyEntries(entries: ILedgerEntry[], options?: IDryRunVerifyEntriesOptions): Promise<IDryRunVerifyEntriesResult>;
138
+ /** Upper-cased hashes of `entries` that neither `indexdb.tx` nor `statedb.tx` holds (one `$in` count per page). */
139
+ private hashesMissingFromIndex;
107
140
  /**
108
- * Scan existing local ledger entries in `[fromSeq, toSeq]` and ensure any force-finalized
109
- * orphan entries (`stateCommitHash === ''`) are indexed into `indexdb.tx` after `rebuildIndex()`.
141
+ * After `rebuildIndex()`, index the force-finalized orphan entries of `[fromSeq, toSeq]` that the index does not
142
+ * have yet. An orphan is an entry without a `stateCommitHash` (its tx never reached the statedb, so the build
143
+ * from the statedb cannot see it) whose tx is in neither `indexdb.tx` nor `statedb.tx`. Entries the index already
144
+ * holds are skipped before any decoding: beta's ledger starts with 434k migrated entries without a
145
+ * `stateCommitHash` and in a legacy entry shape, all indexed by the build (#1875). Every entry that is processed
146
+ * is authenticated as before and fails closed.
110
147
  */
111
148
  indexExistingOrphanEntries(fromSeq?: number, toSeq?: number): Promise<number>;
112
149
  }
113
150
  //#endregion
114
- export { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer };
151
+ export { FUTURE_LEDGER_ENTRY_TIMESTAMP, IDryRunVerifyEntriesOptions, IDryRunVerifyEntriesResult, IFutureTimestampGuardOptions, IFutureTimestampRejection, ILedgerEntryReplayerOptions, IReplayEntryOptions, IReplayEntryResult, IReplayerResolverTarget, IValidateWireEntryOptions, LedgerEntryReplayer, assertReplayEntryChainIdAcceptable, isReplayEntryChainIdAcceptable };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.32.1",
6
+ "version": "1.32.3",
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.1",
58
- "@arcblock/did-ext": "1.32.1",
59
- "@arcblock/did-util": "1.32.1",
60
- "@arcblock/ledger-core": "1.32.1",
57
+ "@arcblock/did": "1.32.3",
58
+ "@arcblock/did-ext": "1.32.3",
59
+ "@arcblock/did-util": "1.32.3",
60
+ "@arcblock/ledger-core": "1.32.3",
61
61
  "@arcblock/nft-display": "^3.2.3",
62
- "@arcblock/validator": "1.32.1",
63
- "@ocap/config": "1.32.1",
64
- "@ocap/indexdb": "1.32.1",
65
- "@ocap/mcrypto": "1.32.1",
66
- "@ocap/message": "1.32.1",
67
- "@ocap/state": "1.32.1",
68
- "@ocap/tx-protocols": "1.32.1",
69
- "@ocap/types": "1.32.1",
70
- "@ocap/util": "1.32.1",
71
- "@ocap/wallet": "1.32.1",
62
+ "@arcblock/validator": "1.32.3",
63
+ "@ocap/config": "1.32.3",
64
+ "@ocap/indexdb": "1.32.3",
65
+ "@ocap/mcrypto": "1.32.3",
66
+ "@ocap/message": "1.32.3",
67
+ "@ocap/state": "1.32.3",
68
+ "@ocap/tx-pipeline": "1.32.3",
69
+ "@ocap/tx-protocols": "1.32.3",
70
+ "@ocap/types": "1.32.3",
71
+ "@ocap/util": "1.32.3",
72
+ "@ocap/wallet": "1.32.3",
72
73
  "debug": "^4.4.3",
73
74
  "express": "^4.22.1",
74
75
  "lodash": "^4.17.23",