/** * Assembles `RailgunTransactionV2` records - the engine's own shape - out of the Action * log stream, the calldata layer, and per-block metadata. * * The output has to be indistinguishable from what `quickSyncRailgunTransactionsV2` would * have returned for the same records, because the two are used interchangeably: the engine * pages the txid sync on `graphID`, and `queueRailgunTransactions` is a pure append with no * positional key. Anything that makes an RPC-derived record differ from its subgraph twin * shows up later as a shifted merkletree, not as an error. * * That is also why this stops rather than skips. `previousVerificationHash` is a single * running chain over every record in order, so omitting one record does not lose one leaf - * it invalidates every leaf after it. When a record cannot be completed (its calldata is * not decodable, most often), assembly returns everything before it and reports where it * stopped; the caller leaves the cursor there and lets the subgraph own the remainder. * * The unshield commitment is the one field no event carries. It is read from calldata where * that decodes and derived from the Unshield event where it does not - see * `resolveUnshieldCommitments`. */ import { RailgunTransactionV2 } from '../../../models/formatted-types'; import { RawRailgunLog } from './action-log-decode'; /** * A gap wider than this is handed to the subgraph rather than walked. * * The RPC scan is bounded per call, so closing a large gap costs one iteration per window - * a post-reset arbitrum tree is ~40 of them, each a couple of hundred sequential getLogs. * The subgraph closes the same gap in a handful of paged queries. This is the one place * where it is genuinely the faster transport rather than the only one. */ export declare const ACTION_RPC_MAX_GAP_BLOCKS = 100000; export type RailgunTransactionSourceInput = { /** First block emitting Action, or undefined when the chain has no Action event. */ activationBlock: Optional; /** graphID of the newest record in the tree, or undefined for an empty tree. */ cursorGraphID: Optional; /** chainTip - cursorBlock. Undefined when the chain tip is not known yet. */ gapBlocks?: number; /** * Set once the subgraph has returned an empty batch this sync while the gap was still * wide, which stops this sync preferring it. Named for the observation, not a diagnosis: * a dead indexer answering 200 with `[]` and a caught-up one are indistinguishable from * here, and on a sparse chain the second is routine. Both want the same response - read * the remainder from logs - so the gate does not need to know which it is. Without the * escape, an empty answer pins the wallet on the subgraph while the sync reports itself * complete. */ subgraphReturnedEmpty?: boolean; }; /** * Where the next batch of railgun transactions must come from. * * This is the gap gate in its natural form. The subgraph does not become a mere * accelerator, because it cannot: `fullResetTXIDMerkletreesV2` and a * `CURRENT_TXID_V2_MERKLETREE_HISTORY_VERSION` bump both rebuild from txid index 0, which * is below every chain's Action activation block - the event did not exist yet, so no * amount of RPC can serve that prefix. It stays a hard requirement for * `[deploymentBlock, activationBlock)` and an optional accelerator only past it. * * Not every reset goes that far: `clearLeavesAfterTxidIndex` retains the record AT the * index (`txid-merkletree.ts`, `startIndex = index + 1`), so * `resetRailgunTxidsAfterTxidIndex` and the 10-leaf reorg rewind normally leave the tip * above activation and never touch the subgraph at all. */ export declare const selectRailgunTransactionSourceV2: ({ activationBlock, cursorGraphID, gapBlocks, subgraphReturnedEmpty, }: RailgunTransactionSourceInput) => 'rpc' | 'subgraph'; /** One EVM transaction's worth of input. */ export type ActionTransactionSource = { transactionHash: string; blockNumber: number; /** Index of this EVM transaction within its block - the middle graphID segment. */ transactionIndex: number; /** Block timestamp, seconds. */ timestamp: number; /** This transaction's RAILGUN proxy logs, any order; the reducer sorts by logIndex. */ logs: readonly RawRailgunLog[]; /** * `tx.input`. Required only when a frame unshields - that is the sole reason to spend an * eth_getTransactionByHash - and may be omitted otherwise. */ calldata: Optional; }; export type AssembledActionTransactions = { transactions: RailgunTransactionV2[]; /** * Records where the calldata value and the log derivation disagreed. Calldata won - * it is what the contract bound - but a non-zero count means a REDIRECT unshield or a * non-address npk has appeared, and is worth surfacing rather than swallowing. */ logDerivationDivergences: number; /** * Where assembly stopped, if it did. Everything in `transactions` is complete and * canonically ordered; nothing after this point was produced. */ stoppedAt: Optional<{ transactionHash: string; blockNumber: number; reason: string; }>; }; /** * @param sources - one entry per EVM transaction, already in canonical * (blockNumber, transactionIndex) order * @param previousVerificationHash - the chain tip, re-read from the DB rather than carried * in memory; undefined only for a genuinely empty tree * @param afterGraphID - the tip record's graphID. Records at or below it are skipped * ENTIRELY: not emitted, and - the part that matters - not chained over. * * A resuming scan has to start at the tip record's own block, because a block can hold * further records after it, so the window legitimately re-delivers the tip. Dropping the * duplicate afterwards is not enough: `previousVerificationHash` already accounts for * the tip's nullifier, so chaining over it again makes every later record carry * H(H(tip, n_tip), n) where the engine recomputes H(tip, n). That mismatch trips * clearLeavesForInvalidVerificationHash and deletes correct leaves - the leaf hash * itself contains no verificationHash, so the data was never actually wrong. * * Resuming at `block + 1` instead would skip any record sharing the tip's block, which * is the same gap moved somewhere harder to see. */ export declare const assembleRailgunTransactionsV2: (sources: readonly ActionTransactionSource[], previousVerificationHash: Optional, afterGraphID?: string) => AssembledActionTransactions;