webevm 0.7.0 → 0.9.0
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/README.md +115 -63
- package/dist/derived-trie.d.ts +38 -0
- package/dist/derived-trie.d.ts.map +1 -0
- package/dist/derived-trie.js +187 -0
- package/dist/derived-trie.js.map +1 -0
- package/dist/engine.d.ts +1 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +2 -3
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +45 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1108 -140
- package/dist/node.js.map +1 -1
- package/dist/revm-state-store.d.ts +5 -0
- package/dist/revm-state-store.d.ts.map +1 -1
- package/dist/revm-state-store.js +42 -13
- package/dist/revm-state-store.js.map +1 -1
- package/dist/revm.d.ts.map +1 -1
- package/dist/revm.js +5 -19
- package/dist/revm.js.map +1 -1
- package/dist/state-manager.d.ts +256 -18
- package/dist/state-manager.d.ts.map +1 -1
- package/dist/state-manager.js +429 -20
- package/dist/state-manager.js.map +1 -1
- package/dist/storage-keys.d.ts +8 -0
- package/dist/storage-keys.d.ts.map +1 -1
- package/dist/storage-keys.js +18 -2
- package/dist/storage-keys.js.map +1 -1
- package/dist/types.d.ts +150 -33
- package/dist/types.d.ts.map +1 -1
- package/dist/worker-client.d.ts.map +1 -1
- package/dist/worker-client.js +20 -12
- package/dist/worker-client.js.map +1 -1
- package/dist/worker-host.d.ts.map +1 -1
- package/dist/worker-host.js +17 -9
- package/dist/worker-host.js.map +1 -1
- package/dist/worker-rpc-error.d.ts +21 -0
- package/dist/worker-rpc-error.d.ts.map +1 -0
- package/dist/worker-rpc-error.js +121 -0
- package/dist/worker-rpc-error.js.map +1 -0
- package/package.json +3 -1
- package/src/derived-trie.ts +214 -0
- package/src/engine.ts +2 -3
- package/src/index.ts +2 -1
- package/src/node.ts +1318 -136
- package/src/revm-state-store.ts +47 -13
- package/src/revm.ts +11 -25
- package/src/state-manager.ts +515 -21
- package/src/storage-keys.ts +21 -2
- package/src/types.ts +152 -34
- package/src/worker-client.ts +22 -12
- package/src/worker-host.ts +17 -9
- package/src/worker-rpc-error.ts +139 -0
package/dist/storage-keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-keys.js","sourceRoot":"","sources":["../src/storage-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,iFAAiF;AACjF,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,GAAG,EAAE;IACtC,MAAM,CAAC,GAAa,EAAE,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE;QAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,CAAC;AACV,CAAC,CAAC,EAAE,CAAC;AASL;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,OAAmB;IACjD,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,cAAc,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC,YAAY,CACzB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC9B,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAC9B,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC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AAC,CAAC;AACpB,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,GAAkB;IAC/C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC7B,GAAqC;IAErC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5B,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACH,SAAS,MAAM,CAAC,GAAW;IAC1B,IAAI,CAAC,GAAG,IAAI,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC5B,CAAC,IAAI,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,CAAC,CAAC;AACV,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -55,19 +55,6 @@ export interface PersistenceAdapter {
|
|
|
55
55
|
*/
|
|
56
56
|
save(state: SerializedState): Promise<void>;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* State backing mode.
|
|
60
|
-
* - `'none'` (DEFAULT): `SimpleStateManager` — plain Maps, NO trie, NO state root.
|
|
61
|
-
* The fast path; block `stateRoot`/`receiptsRoot`/`transactionsRoot` are zero
|
|
62
|
-
* placeholders (you are a local chain; canonical roots aren't needed). This is
|
|
63
|
-
* the recommended mode and what makes the node ~4× faster than the trie path.
|
|
64
|
-
* - `'trie'`: `MerkleStateManager` — real Merkle-Patricia trie. SLOWER (recomputes
|
|
65
|
-
* the state root each tx) but produces a REAL `stateRoot`, which (a) lets the
|
|
66
|
-
* node be conformance-tested against `ethereum/tests` GeneralStateTests (they
|
|
67
|
-
* verify the post-state root), and (b) gives honest canonical block roots for
|
|
68
|
-
* consumers that need them. Opt-in: pay for the trie only when you want it.
|
|
69
|
-
*/
|
|
70
|
-
export type StateMode = 'none' | 'trie';
|
|
71
58
|
/**
|
|
72
59
|
* Sender-derivation mode.
|
|
73
60
|
* - `'recover'` (DEFAULT): derive the sender from the signature with ecrecover,
|
|
@@ -338,12 +325,6 @@ export interface EngineContext {
|
|
|
338
325
|
* rather than an engine-side option to remember to pass.
|
|
339
326
|
*/
|
|
340
327
|
getBlockHash(blockNumber: bigint): Uint8Array | undefined;
|
|
341
|
-
/**
|
|
342
|
-
* The node's state mode. An engine that cannot serve it must THROW here —
|
|
343
|
-
* `connect` is called during `createNode()`, so the refusal lands at
|
|
344
|
-
* construction rather than at the first opcode.
|
|
345
|
-
*/
|
|
346
|
-
readonly stateMode: StateMode;
|
|
347
328
|
}
|
|
348
329
|
/**
|
|
349
330
|
* THE EVM BEHIND THE NODE, in ONE interface with TWO REQUIRED operations: execute
|
|
@@ -458,9 +439,28 @@ export interface EngineInfo {
|
|
|
458
439
|
export interface NodeOptions {
|
|
459
440
|
/** EIP-155 chain id. Default 31337 (anvil/hardhat-style local). */
|
|
460
441
|
chainId?: number;
|
|
461
|
-
/**
|
|
462
|
-
*
|
|
463
|
-
|
|
442
|
+
/**
|
|
443
|
+
* Whether the node computes a STATE ROOT. Default `false`. EVERY node runs on
|
|
444
|
+
* the same state (our `SimpleStateManager` subclass: plain Maps, no trie);
|
|
445
|
+
* this only decides whether a trie is DERIVED from it.
|
|
446
|
+
* - `false` (DEFAULT): no trie, no state root, no trie work. Block
|
|
447
|
+
* `stateRoot`/`receiptsRoot`/`transactionsRoot` are zero placeholders (you
|
|
448
|
+
* are a local chain; canonical roots aren't needed) and `getStateRoot()`
|
|
449
|
+
* throws.
|
|
450
|
+
* - `true`: additionally keep a Merkle-Patricia trie derived from the state,
|
|
451
|
+
* updated at the end of each block from the keys the block changed, and
|
|
452
|
+
* report its REAL root in each block header and from `getStateRoot()`. That
|
|
453
|
+
* (a) lets the node be conformance-tested against `ethereum/tests`
|
|
454
|
+
* GeneralStateTests (they verify the post-state root), and (b) gives honest
|
|
455
|
+
* canonical block roots for consumers that need them. Execution never reads
|
|
456
|
+
* the trie, so it works on every engine (revm included) and behaves exactly
|
|
457
|
+
* as a node without it in every other respect. See
|
|
458
|
+
* `docs/adr/0014-the-trie-is-derived-from-the-flat-state-not-a-state-manager.md`.
|
|
459
|
+
*
|
|
460
|
+
* Only `true` turns it on; any other value (absent, `false`, or a non-boolean
|
|
461
|
+
* passed from untyped code) leaves it off.
|
|
462
|
+
*/
|
|
463
|
+
computeStateRoot?: boolean;
|
|
464
464
|
/**
|
|
465
465
|
* Sender derivation: `'recover'` (ecrecover, authenticated — DEFAULT) or
|
|
466
466
|
* `'trusted'` (skip ecrecover, trust a caller-supplied `from`). See
|
|
@@ -492,11 +492,44 @@ export interface NodeOptions {
|
|
|
492
492
|
/**
|
|
493
493
|
* Full genesis pre-state (address -> {balance, nonce, code, storage}). Richer
|
|
494
494
|
* than `initialBalances` (which only sets balance). Used to load an arbitrary
|
|
495
|
-
* starting state
|
|
496
|
-
* `
|
|
495
|
+
* starting state (e.g. a GeneralStateTest `pre` section) so that, with
|
|
496
|
+
* `computeStateRoot: true`, `getStateRoot()` after a tx can be compared to the
|
|
497
497
|
* fixture's expected post-state root. Applied at genesis, before block 0.
|
|
498
498
|
*/
|
|
499
499
|
initialState?: Record<string, GenesisAccount>;
|
|
500
|
+
/**
|
|
501
|
+
* The TIMESTAMP OF THE GENESIS BLOCK (block 0), in seconds since the epoch: the
|
|
502
|
+
* same unit and type as {@link BlockEnv.timestamp} and the header field.
|
|
503
|
+
* ABSENT MEANS THE WALL CLOCK, in whole seconds at construction, which is what
|
|
504
|
+
* block 0 has always carried.
|
|
505
|
+
*
|
|
506
|
+
* Why it exists: genesis is otherwise the one block a consumer cannot pin, so
|
|
507
|
+
* two nodes running the same chain, created in different seconds, report
|
|
508
|
+
* different hashes for every block. With this set (and `blockEnv.timestamp`
|
|
509
|
+
* pinning the mined blocks), the same chain produces the same hashes and a
|
|
510
|
+
* byte-identical `dumpState`.
|
|
511
|
+
*
|
|
512
|
+
* INDEPENDENT OF `blockEnv`, which still does not touch genesis's timestamp:
|
|
513
|
+
* `blockEnv` pins every MINED block's environment to one fixed value, and
|
|
514
|
+
* stretching it to genesis would stamp block 0 and every block after it alike.
|
|
515
|
+
* The converse holds too: this option moves ONLY block 0. A `genesisTimestamp`
|
|
516
|
+
* in the future does not move mined blocks, which keep the wall clock (or
|
|
517
|
+
* `blockEnv.timestamp`), so a mined block can then carry an EARLIER timestamp
|
|
518
|
+
* than genesis.
|
|
519
|
+
*
|
|
520
|
+
* A NEW GENESIS ONLY: a state loaded with `loadState` (or restored by
|
|
521
|
+
* `persistence` at construction) brings its own block 0, timestamp included,
|
|
522
|
+
* and that one wins. A `dumpState` carries the timestamp like every other
|
|
523
|
+
* header field.
|
|
524
|
+
*
|
|
525
|
+
* Must be a non-negative bigint; anything else (a number, a string, a negative
|
|
526
|
+
* bigint) throws at construction naming this option. It is not bounded above,
|
|
527
|
+
* the same as `blockEnv.timestamp`, but a dump records every block's timestamp
|
|
528
|
+
* as a JS number, so only a value up to `Number.MAX_SAFE_INTEGER` survives a
|
|
529
|
+
* `dumpState` / `loadState` round trip exactly (any real date does). It crosses `createWorkerNode` like every
|
|
530
|
+
* other option (a bigint structured-clones).
|
|
531
|
+
*/
|
|
532
|
+
genesisTimestamp?: bigint;
|
|
500
533
|
/**
|
|
501
534
|
* Override the header fields of MINED blocks. Lets a consumer run a tx under a
|
|
502
535
|
* specific block environment (coinbase, base fee, number, timestamp,
|
|
@@ -532,6 +565,38 @@ export interface NodeOptions {
|
|
|
532
565
|
* `docs/adr/0006-the-engine-is-an-injected-object-not-a-named-string.md`.
|
|
533
566
|
*/
|
|
534
567
|
engine?: Engine;
|
|
568
|
+
/**
|
|
569
|
+
* OPT-IN, BOUNDED STATE HISTORY. With `{blocks: N}` the node answers
|
|
570
|
+
* `eth_getBalance`, `eth_getCode`, `eth_getStorageAt` and
|
|
571
|
+
* `eth_getTransactionCount` pinned to any of the last N blocks below the head
|
|
572
|
+
* (and the head) exactly as they answered when that block was the head. A
|
|
573
|
+
* block older than `head - N` is refused with `-32000 historical state not
|
|
574
|
+
* available`, naming the oldest block it can serve. `eth_call` and
|
|
575
|
+
* `eth_estimateGas` pinned to a block in the window EXECUTE at it: against
|
|
576
|
+
* its state and its block environment, with state overrides on top. The
|
|
577
|
+
* history is carried by `dumpState` / `loadState` (so IndexedDB persistence
|
|
578
|
+
* keeps the window across a reload).
|
|
579
|
+
*
|
|
580
|
+
* ABSENT MEANS OFF, and there is no default window: a node without it behaves
|
|
581
|
+
* exactly as before (the head is served, anything below it refused) and pays
|
|
582
|
+
* nothing. `N` must be a positive safe integer; anything else throws at
|
|
583
|
+
* construction. It composes with `computeStateRoot: true`.
|
|
584
|
+
*
|
|
585
|
+
* THE COST is memory per changed key per retained block: the node keeps, for
|
|
586
|
+
* each of the last N blocks, the value every account, code entry and storage
|
|
587
|
+
* slot the block changed had before it (an undo log over the one flat state).
|
|
588
|
+
* Measured: about 300 bytes per changed key per retained block, and a
|
|
589
|
+
* historical `eth_call` costs about 0.8 microseconds per distinct key changed
|
|
590
|
+
* since the block it is pinned to; the README's "What it costs" section has a
|
|
591
|
+
* sizing example, from `docs/spikes/bounded-state-history-cost/results.md`.
|
|
592
|
+
* See `docs/adr/0013-bounded-state-history-is-an-undo-log-over-the-flat-state.md`.
|
|
593
|
+
*/
|
|
594
|
+
stateHistory?: StateHistoryOptions;
|
|
595
|
+
}
|
|
596
|
+
/** See {@link NodeOptions.stateHistory}. */
|
|
597
|
+
export interface StateHistoryOptions {
|
|
598
|
+
/** How many blocks below the head stay readable: a positive safe integer. */
|
|
599
|
+
blocks: number;
|
|
535
600
|
}
|
|
536
601
|
/** A full genesis account (all fields optional except an implicit zero default). */
|
|
537
602
|
export interface GenesisAccount {
|
|
@@ -569,13 +634,14 @@ export interface SlimNode {
|
|
|
569
634
|
hash: string;
|
|
570
635
|
}) => void): () => void;
|
|
571
636
|
/**
|
|
572
|
-
* Current canonical state root.
|
|
573
|
-
* Merkle-Patricia root
|
|
574
|
-
*
|
|
637
|
+
* Current canonical state root. With `computeStateRoot: true` this is the REAL
|
|
638
|
+
* Merkle-Patricia root of the current state, `evm_set*` cheats since the last
|
|
639
|
+
* block included (usable for GeneralStateTests conformance); without it there
|
|
640
|
+
* is no trie so this throws (honest: there is no root to give).
|
|
575
641
|
*/
|
|
576
642
|
getStateRoot(): Promise<string>;
|
|
577
|
-
/**
|
|
578
|
-
readonly
|
|
643
|
+
/** Whether this node computes a state root (its `computeStateRoot` option). */
|
|
644
|
+
readonly computeStateRoot: boolean;
|
|
579
645
|
/** The sender mode this node was created with. */
|
|
580
646
|
readonly senderMode: SenderMode;
|
|
581
647
|
/**
|
|
@@ -628,13 +694,23 @@ export interface ServedPort {
|
|
|
628
694
|
* every IndexedDB record in the wild for a format they can still be read as. Bump
|
|
629
695
|
* it when a dump stops being loadable by the code that wrote it, which is the only
|
|
630
696
|
* question `version` can usefully answer.
|
|
697
|
+
*
|
|
698
|
+
* The same holds for `history` (2026-09-28, `state-history-persistence`): an
|
|
699
|
+
* OPTIONAL field, absent from every dump written before it and from every dump
|
|
700
|
+
* of a node without `stateHistory`, so it is still `version: 1`.
|
|
701
|
+
*
|
|
702
|
+
* And for a field REMOVED (2026-09-28, `rename-statemode-to-computestateroot`):
|
|
703
|
+
* dumps written before the node's `computeStateRoot` option replaced the old
|
|
704
|
+
* `'none' | 'trie'` mode option carry that mode as an informational string
|
|
705
|
+
* field. It is no longer written and it was never read, so such a dump loads
|
|
706
|
+
* unchanged with the field ignored (proved by `test/dumpstate-layout.spec.ts`'s
|
|
707
|
+
* fixture, which still carries it), and the format is still `version: 1`.
|
|
631
708
|
*/
|
|
632
709
|
export interface SerializedState {
|
|
633
710
|
version: 1;
|
|
634
711
|
chainId: number;
|
|
635
|
-
/**
|
|
636
|
-
|
|
637
|
-
/** SimpleStateManager Maps: address -> hex-encoded account/code/storage. */
|
|
712
|
+
/** The node's state, on every node: address -> hex-encoded account/code/storage.
|
|
713
|
+
* A `computeStateRoot` node's trie is not serialised; `loadState` rebuilds it. */
|
|
638
714
|
accounts: Record<string, string>;
|
|
639
715
|
code: Record<string, string>;
|
|
640
716
|
storage: Record<string, Record<string, string>>;
|
|
@@ -644,6 +720,47 @@ export interface SerializedState {
|
|
|
644
720
|
receipts: Record<string, SerializedReceipt>;
|
|
645
721
|
/** Raw tx + meta keyed by tx hash (for eth_getTransactionByHash). */
|
|
646
722
|
transactions: Record<string, SerializedTx>;
|
|
723
|
+
/**
|
|
724
|
+
* The `stateHistory` UNDO LOG, oldest first: one record per retained block,
|
|
725
|
+
* holding the value every key that block changed had at the END of the block
|
|
726
|
+
* before it (ADR 0013). Written only by a node created with `stateHistory`
|
|
727
|
+
* (possibly empty), and read only by one: a node without the option ignores it.
|
|
728
|
+
*
|
|
729
|
+
* OPTIONAL, and absent means "no history": a dump written before this field
|
|
730
|
+
* existed loads with history starting at its head, as it always did. A dump
|
|
731
|
+
* carrying more blocks than the loading node's window is truncated to that
|
|
732
|
+
* window; one carrying fewer serves what it has. `loadState` restores the
|
|
733
|
+
* CONTIGUOUS run of records ending at the dump's head block and drops anything
|
|
734
|
+
* older than a gap, since a read below a gap would be answered from a later
|
|
735
|
+
* state than the one asked for.
|
|
736
|
+
*/
|
|
737
|
+
history?: SerializedHistoryBlock[];
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* One block's undo record in {@link SerializedState.history}, hex-encoded like
|
|
741
|
+
* the rest of the dump. Every map is keyed by `0x` lowercase hex (addresses of
|
|
742
|
+
* 20 bytes, slots of 32), and `null` means the key was ABSENT at the end of the
|
|
743
|
+
* block before (`number - 1`): no account, no code, an unset slot. That is not
|
|
744
|
+
* the same as an empty value, and a loader must not conflate them: an absent
|
|
745
|
+
* account reads as absent (EXTCODEHASH zero), an existing empty one does not.
|
|
746
|
+
*/
|
|
747
|
+
export interface SerializedHistoryBlock {
|
|
748
|
+
/** The block this record undoes: its keys' values are the ones before it. */
|
|
749
|
+
number: number;
|
|
750
|
+
/** Account RLP (as in {@link SerializedState.accounts}), or `null` if absent. */
|
|
751
|
+
accounts: Record<string, string | null>;
|
|
752
|
+
/** Code hex, or `null` if the address had none. */
|
|
753
|
+
code: Record<string, string | null>;
|
|
754
|
+
/** Address -> (slot -> value hex, or `null` if the slot was unset). */
|
|
755
|
+
storage: Record<string, Record<string, string | null>>;
|
|
756
|
+
/**
|
|
757
|
+
* Addresses whose storage the block CLEARED (creation over storage,
|
|
758
|
+
* `SELFDESTRUCT`, EIP-161 removal). The clear also recorded every slot the
|
|
759
|
+
* account held in `storage`, so this marker restores no value on its own: it
|
|
760
|
+
* tells a historical `eth_call` to clear the account's live storage before
|
|
761
|
+
* applying those slots, dropping the ones written since.
|
|
762
|
+
*/
|
|
763
|
+
storageCleared: string[];
|
|
647
764
|
}
|
|
648
765
|
export interface SerializedBlock {
|
|
649
766
|
number: number;
|
|
@@ -653,7 +770,7 @@ export interface SerializedBlock {
|
|
|
653
770
|
gasUsed: string;
|
|
654
771
|
gasLimit: string;
|
|
655
772
|
baseFeePerGas: string;
|
|
656
|
-
/** Real Merkle-Patricia state root
|
|
773
|
+
/** Real Merkle-Patricia state root with `computeStateRoot: true`; zero placeholder without. */
|
|
657
774
|
stateRoot: string;
|
|
658
775
|
/**
|
|
659
776
|
* The block's coinbase, under the name `eth_getBlockByNumber` reports it. Named
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,kBAAkB,CAAC;AAC9C,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAE/C,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC;CAC9C;AAED,qEAAqE;AACrE,qBAAa,QAAS,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBACZ,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAMzD;AAED,MAAM,MAAM,YAAY,GACrB;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GACd;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAC,GAChB;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,CAAC;AAE1C,MAAM,WAAW,kBAAkB;IAClC,sEAAsE;IACtE,IAAI,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IACxC;;;;;;;;;;;;;;;;OAgBG;IACH,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CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-client.d.ts","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-client.d.ts","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACX,WAAW,EACX,QAAQ,EAIR,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACrD;;;;;;;OAOG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CACf;AAED,wBAAsB,gBAAgB,CACrC,IAAI,EAAE,iBAAiB,GACrB,OAAO,CAAC,QAAQ,CAAC,CAiGnB"}
|
package/dist/worker-client.js
CHANGED
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* the consumer never hand-rolls the comlink plumbing.
|
|
7
7
|
*/
|
|
8
8
|
import { wrap, proxy, transfer, releaseProxy } from 'comlink';
|
|
9
|
+
// ...and the ONE runtime import besides comlink: rebuilding an `RpcError` the
|
|
10
|
+
// worker sent, which comlink alone would deliver without its `code` and `data`.
|
|
11
|
+
import { receivingRpcErrors } from './worker-rpc-error.js';
|
|
9
12
|
export async function createWorkerNode(opts) {
|
|
10
13
|
const { worker, ...nodeOptions } = opts;
|
|
11
14
|
// AN ENGINE CANNOT CROSS THIS BOUNDARY, and says so. `WorkerNodeOptions`
|
|
@@ -39,25 +42,30 @@ export async function createWorkerNode(opts) {
|
|
|
39
42
|
}
|
|
40
43
|
const api = wrap(worker);
|
|
41
44
|
const remote = await api.createNode(nodeOptions);
|
|
42
|
-
//
|
|
45
|
+
// computeStateRoot/senderMode/engine are plain values on the node; over comlink
|
|
43
46
|
// they read as promises.
|
|
44
47
|
//
|
|
45
48
|
// NO `as any` HERE, and that is load-bearing. The remote is a `SlimNode` (the
|
|
46
49
|
// one proxy in ./worker-host.ts is typed as one), so these three reads are
|
|
47
50
|
// CHECKED: `senderMode` was silently absent from that proxy for a month, and
|
|
48
51
|
// what hid it from the compiler was the cast that used to be on this line.
|
|
49
|
-
const
|
|
52
|
+
const computeStateRoot = await remote.computeStateRoot;
|
|
50
53
|
const senderMode = await remote.senderMode;
|
|
51
54
|
const engineInfo = await remote.engine;
|
|
55
|
+
// EVERY ASYNC METHOD IS WRAPPED IN `receivingRpcErrors`, the other half of the
|
|
56
|
+
// host proxy's `sendingRpcErrors`: an `RpcError` the node raises reaches the
|
|
57
|
+
// caller as a real `RpcError` with its `code` and `data`, the same error a
|
|
58
|
+
// main-thread node rejects with (./worker-rpc-error.ts). Any other error is
|
|
59
|
+
// comlink's, unchanged.
|
|
52
60
|
return {
|
|
53
|
-
request: (args) => remote.request(args),
|
|
54
|
-
mine: () => remote.mine(),
|
|
55
|
-
dumpState: () => remote.dumpState(),
|
|
56
|
-
loadState: (s) => remote.loadState(s),
|
|
57
|
-
|
|
61
|
+
request: receivingRpcErrors((args) => remote.request(args)),
|
|
62
|
+
mine: receivingRpcErrors(() => remote.mine()),
|
|
63
|
+
dumpState: receivingRpcErrors(() => remote.dumpState()),
|
|
64
|
+
loadState: receivingRpcErrors((s) => remote.loadState(s)),
|
|
65
|
+
computeStateRoot,
|
|
58
66
|
senderMode,
|
|
59
67
|
engine: engineInfo,
|
|
60
|
-
getStateRoot: () => remote.getStateRoot(),
|
|
68
|
+
getStateRoot: receivingRpcErrors(() => remote.getStateRoot()),
|
|
61
69
|
onNewHead(cb) {
|
|
62
70
|
// The callback must cross the thread boundary as a comlink proxy.
|
|
63
71
|
let unsub;
|
|
@@ -68,7 +76,7 @@ export async function createWorkerNode(opts) {
|
|
|
68
76
|
void unsub?.();
|
|
69
77
|
};
|
|
70
78
|
},
|
|
71
|
-
async
|
|
79
|
+
serveOn: receivingRpcErrors(async (port) => {
|
|
72
80
|
// TRANSFERRED, never cloned: a MessagePort cannot be cloned at all, and the
|
|
73
81
|
// point is that the port now belongs to the node's worker, so a consumer
|
|
74
82
|
// holding the other end reaches that worker without this thread in between.
|
|
@@ -83,13 +91,13 @@ export async function createWorkerNode(opts) {
|
|
|
83
91
|
served[releaseProxy]();
|
|
84
92
|
},
|
|
85
93
|
};
|
|
86
|
-
},
|
|
94
|
+
}),
|
|
87
95
|
// Terminating the worker also ends every port it was serving: a consumer's
|
|
88
96
|
// requests then get no answer, as they would from a stopped port.
|
|
89
|
-
async
|
|
97
|
+
dispose: receivingRpcErrors(async () => {
|
|
90
98
|
await remote.dispose();
|
|
91
99
|
worker.terminate();
|
|
92
|
-
},
|
|
100
|
+
}),
|
|
93
101
|
};
|
|
94
102
|
}
|
|
95
103
|
//# sourceMappingURL=worker-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-client.js","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-client.js","sourceRoot":"","sources":["../src/worker-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAMzE,8EAA8E;AAC9E,gFAAgF;AAChF,OAAO,EAAC,kBAAkB,EAAC,MAAM,uBAAuB,CAAC;AA4BzD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,IAAuB;IAEvB,MAAM,EAAC,MAAM,EAAE,GAAG,WAAW,EAAC,GAAG,IAAI,CAAC;IACtC,yEAAyE;IACzE,8EAA8E;IAC9E,qEAAqE;IACrE,+EAA+E;IAC/E,0EAA0E;IAC1E,2EAA2E;IAC3E,0EAA0E;IAC1E,8EAA8E;IAC9E,iBAAiB;IACjB,EAAE;IACF,4EAA4E;IAC5E,iDAAiD;IACjD,EAAE;IACF,oBAAoB;IACpB,mDAAmD;IACnD,kDAAkD;IAClD,4CAA4C;IAC5C,gEAAgE;IAChE,EAAE;IACF,8EAA8E;IAC9E,+EAA+E;IAC/E,qFAAqF;IACrF,6EAA6E;IAC7E,SAAS;IACT,IAAK,WAA2B,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CACd,8QAA8Q;YAC7Q,mPAAmP;YACnP,yDAAyD,CAC1D,CAAC;IACH,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAgB,MAAM,CAAC,CAAC;IACxC,MAAM,MAA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AC;QACD,OAAO,EAAE,kBAAkB,CAAC,KAAK,EAAE,IAAiB,EAAE,EAAE;YACvD,4EAA4E;YAC5E,yEAAyE;YACzE,4EAA4E;YAC5E,EAAE;YACF,2EAA2E;YAC3E,yEAAyE;YACzE,iDAAiD;YACjD,MAAM,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,OAAO,CACnC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,CACtB,CAAkC,CAAC;YACpC,OAAO;gBACN,KAAK,CAAC,KAAK;oBACV,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;oBACrB,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;gBACxB,CAAC;aACD,CAAC;QACH,CAAC,CAAC;QACF,2EAA2E;QAC3E,kEAAkE;QAClE,OAAO,EAAE,kBAAkB,CAAC,KAAK,IAAI,EAAE;YACtC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,CAAC,CAAC;KACF,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-host.d.ts","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-host.d.ts","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAgDA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAG9D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE5D,4EAA4E;AAC5E,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;;;;;;OAcG;IACH,YAAY,CAAC,EAAE,cAAc,CAAC;CAC9B;AA8CD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,GAAE,iBAAsB;wBAiB3C,WAAW;EAatC;AA2CD,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,WAAW,GAAE,iBAAsB,GAAG,aAAa,CAI7E"}
|
package/dist/worker-host.js
CHANGED
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
*/
|
|
47
47
|
import { expose, proxy } from 'comlink';
|
|
48
48
|
import { createNode } from './node.js';
|
|
49
|
+
import { sendingRpcErrors } from './worker-rpc-error.js';
|
|
49
50
|
/**
|
|
50
51
|
* THE ONE `SlimNode` PROXY. Comlink cannot pass the node itself (its methods are
|
|
51
52
|
* functions and its subscription hands back another one), so this is the node's
|
|
@@ -57,17 +58,24 @@ import { createNode } from './node.js';
|
|
|
57
58
|
* (which a bare `SlimNode` annotation would let through, since it demands only
|
|
58
59
|
* the required members). `SlimNode` has no optional members today, so this costs
|
|
59
60
|
* nothing now and stops the one thing the guarantee otherwise missed. The plain
|
|
60
|
-
* values (`
|
|
61
|
+
* values (`computeStateRoot`, `senderMode`, `engine`) clone across as-is; the client
|
|
61
62
|
* reads them off the remote as promises.
|
|
63
|
+
*
|
|
64
|
+
* EVERY ASYNC METHOD IS WRAPPED IN {@link sendingRpcErrors}, so an `RpcError` it
|
|
65
|
+
* throws crosses with its `code` and `data` (comlink alone keeps only the
|
|
66
|
+
* message; `./worker-rpc-error.ts` has why, and why this is not a comlink
|
|
67
|
+
* transfer handler). All of them, not only `request`: `getStateRoot` raises
|
|
68
|
+
* `-32004`, and a method that raises none today costs nothing to cover.
|
|
69
|
+
* `onNewHead` is the exception because it is synchronous and throws nothing.
|
|
62
70
|
*/
|
|
63
71
|
function nodeProxy(node) {
|
|
64
72
|
const forwarded = {
|
|
65
|
-
request: (args) => node.request(args),
|
|
66
|
-
mine: () => node.mine(),
|
|
67
|
-
dumpState: () => node.dumpState(),
|
|
68
|
-
loadState: (state) => node.loadState(state),
|
|
69
|
-
getStateRoot: () => node.getStateRoot(),
|
|
70
|
-
|
|
73
|
+
request: sendingRpcErrors((args) => node.request(args)),
|
|
74
|
+
mine: sendingRpcErrors(() => node.mine()),
|
|
75
|
+
dumpState: sendingRpcErrors(() => node.dumpState()),
|
|
76
|
+
loadState: sendingRpcErrors((state) => node.loadState(state)),
|
|
77
|
+
getStateRoot: sendingRpcErrors(() => node.getStateRoot()),
|
|
78
|
+
computeStateRoot: node.computeStateRoot,
|
|
71
79
|
senderMode: node.senderMode,
|
|
72
80
|
engine: node.engine,
|
|
73
81
|
// newHeads over comlink: the callback arrives as a comlink proxy, and the
|
|
@@ -77,8 +85,8 @@ function nodeProxy(node) {
|
|
|
77
85
|
// thread's: the node serves it right here, and a consumer holding the other
|
|
78
86
|
// end talks to this worker directly. The handle going back carries a
|
|
79
87
|
// function, so it crosses as a proxy, like the unsubscribe above.
|
|
80
|
-
serveOn: async (port) => proxy(await node.serveOn(port)),
|
|
81
|
-
dispose: () => node.dispose(),
|
|
88
|
+
serveOn: sendingRpcErrors(async (port) => proxy(await node.serveOn(port))),
|
|
89
|
+
dispose: sendingRpcErrors(() => node.dispose()),
|
|
82
90
|
};
|
|
83
91
|
return forwarded;
|
|
84
92
|
}
|
package/dist/worker-host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-host.js","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,SAAS,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-host.js","sourceRoot":"","sources":["../src/worker-host.ts"],"names":[],"mappings":"AAAA;;;;;;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UAAU,EAAE,CAAC;QAC3E,OAAO,CACN,sLAAsL;YACtL,0GAA0G;YAC1G,4NAA4N;YAC5N,GAAG,CACH,CAAC;IACH,CAAC;IACD,OAAO,CACN,yHAAyH,QAAQ,CAAC,YAAY,CAAC,KAAK;QACpJ,2IAA2I;QAC3I,GAAG,CACH,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,SAAS,QAAQ,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;IAC1B,OAAO,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;AACpD,CAAC;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,UAAU,CAAC,cAAiC,EAAE;IAC7D,MAAM,GAAG,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** An `RpcError` rendered as a plain, structured-cloneable value. */
|
|
2
|
+
export interface WireRpcError {
|
|
3
|
+
/** The marker the client recognises it by (with a numeric `code`). */
|
|
4
|
+
webevmRpcError: true;
|
|
5
|
+
name: 'RpcError';
|
|
6
|
+
code: number;
|
|
7
|
+
message: string;
|
|
8
|
+
data: unknown;
|
|
9
|
+
stack?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* HOST SIDE: `fn`, rejecting with a {@link WireRpcError} wherever it would have
|
|
13
|
+
* rejected with an `RpcError`. Every other rejection passes through untouched.
|
|
14
|
+
*/
|
|
15
|
+
export declare function sendingRpcErrors<A extends unknown[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
16
|
+
/**
|
|
17
|
+
* CLIENT SIDE: `fn`, rejecting with a real `RpcError` wherever the worker sent a
|
|
18
|
+
* {@link WireRpcError}. Every other rejection passes through untouched.
|
|
19
|
+
*/
|
|
20
|
+
export declare function receivingRpcErrors<A extends unknown[], R>(fn: (...args: A) => Promise<R>): (...args: A) => Promise<R>;
|
|
21
|
+
//# sourceMappingURL=worker-rpc-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-rpc-error.d.ts","sourceRoot":"","sources":["../src/worker-rpc-error.ts"],"names":[],"mappings":"AAgDA,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC5B,sEAAsE;IACtE,cAAc,EAAE,IAAI,CAAC;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAmDD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EACtD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC5B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAQ5B;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC5B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAQ5B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* worker-rpc-error.ts: HOW AN `RpcError` CROSSES THE WORKER BOUNDARY WHOLE.
|
|
3
|
+
* Shared by the two ends of it: `./worker-host.ts` (the node's thread) turns a
|
|
4
|
+
* thrown `RpcError` into a plain {@link WireRpcError}, and `./worker-client.ts`
|
|
5
|
+
* (the caller's thread) turns that back into a real `RpcError`.
|
|
6
|
+
*
|
|
7
|
+
* WHY IT IS NEEDED. comlink carries a thrown `Error` across as
|
|
8
|
+
* `{message, name, stack}` and nothing else (its built-in `throw` transfer
|
|
9
|
+
* handler), so every `RpcError` a worker-hosted node raised used to reach the
|
|
10
|
+
* caller with `code === undefined` and no `data`: a `-32000` refusal, a `-32601`
|
|
11
|
+
* method not found, and above all a `3 execution reverted` whose `data` is the
|
|
12
|
+
* revert payload a viem client decodes into a custom error. A node served over a
|
|
13
|
+
* port (`node.serveOn`, through `@eip-1193/over-port`) never had the gap, so the
|
|
14
|
+
* two worker transports disagreed, and a worker node was not interchangeable
|
|
15
|
+
* with a main-thread one for anything that branches on `code`.
|
|
16
|
+
*
|
|
17
|
+
* THE CHOICE: THROW A PLAIN OBJECT, NOT AN `Error`, AND TOUCH NO COMLINK STATE.
|
|
18
|
+
* comlink's `throw` handler passes a thrown NON-Error value through structured
|
|
19
|
+
* clone unchanged and rethrows it as-is on the other side. So the host throws
|
|
20
|
+
* `{name: 'RpcError', code, message, data, stack}` in place of the `RpcError`,
|
|
21
|
+
* which crosses with every field, and the client rebuilds the `RpcError` from it.
|
|
22
|
+
* Rejected alternatives, and why:
|
|
23
|
+
*
|
|
24
|
+
* - A custom comlink transfer handler (or replacing the built-in `throw` one).
|
|
25
|
+
* comlink's `transferHandlers` is a MODULE-GLOBAL map, so registering one
|
|
26
|
+
* changes error handling for every other comlink use in the consumer's app,
|
|
27
|
+
* which this package does not own (and a consumer's own `throw` handler, set
|
|
28
|
+
* before or after ours, would silently win or lose).
|
|
29
|
+
* - An envelope (`{ok: value}` / `{error: {...}}`) returned by every proxied
|
|
30
|
+
* method. Also global-state-free, but it rewraps EVERY SUCCESSFUL answer and
|
|
31
|
+
* changes every method's return type on the wire, which breaks the
|
|
32
|
+
* `Required<SlimNode>` typing of the host proxy the client relies on. The
|
|
33
|
+
* thrown object only changes the failure path, and only for `RpcError`.
|
|
34
|
+
*
|
|
35
|
+
* WHAT A DIRECT COMLINK CONSUMER SEES. Someone who `wrap()`s the worker-host api
|
|
36
|
+
* themselves instead of using `createWorkerNode` now gets the plain object as the
|
|
37
|
+
* rejection rather than an `Error` with only a message: it carries `code`,
|
|
38
|
+
* `message` and `data` at the top level, so code reading `e.code` / `e.message`
|
|
39
|
+
* works, and `e instanceof Error` does not. Every other error (a plain `Error`, a
|
|
40
|
+
* `RangeError` from malformed input, the misused-`createEngine` refusal) is
|
|
41
|
+
* left to comlink's own handling, exactly as before.
|
|
42
|
+
*
|
|
43
|
+
* `data` MUST BE STRUCTURED-CLONEABLE, as any value crossing a thread is. Every
|
|
44
|
+
* `data` this package raises is (a hex string, or absent); a non-cloneable one
|
|
45
|
+
* makes comlink report its own "Unserializable return value" instead.
|
|
46
|
+
*/
|
|
47
|
+
import { RpcError } from './types.js';
|
|
48
|
+
/**
|
|
49
|
+
* An `RpcError`, by class or by shape: a consumer's engine may throw one built
|
|
50
|
+
* from ANOTHER copy of this package, which fails `instanceof` but is the same
|
|
51
|
+
* error. The name AND a numeric code are required, since a numeric `code` alone
|
|
52
|
+
* is also what a `DOMException` has.
|
|
53
|
+
*/
|
|
54
|
+
function isRpcError(e) {
|
|
55
|
+
return (e instanceof RpcError ||
|
|
56
|
+
(e instanceof Error &&
|
|
57
|
+
e.name === 'RpcError' &&
|
|
58
|
+
typeof e.code === 'number'));
|
|
59
|
+
}
|
|
60
|
+
function isWireRpcError(e) {
|
|
61
|
+
return (typeof e === 'object' &&
|
|
62
|
+
e !== null &&
|
|
63
|
+
e.webevmRpcError === true &&
|
|
64
|
+
typeof e.code === 'number' &&
|
|
65
|
+
typeof e.message === 'string');
|
|
66
|
+
}
|
|
67
|
+
/** HOST SIDE: an `RpcError` becomes a {@link WireRpcError}; anything else is unchanged. */
|
|
68
|
+
function toWire(e) {
|
|
69
|
+
if (!isRpcError(e))
|
|
70
|
+
return e;
|
|
71
|
+
const wire = {
|
|
72
|
+
webevmRpcError: true,
|
|
73
|
+
name: 'RpcError',
|
|
74
|
+
code: e.code,
|
|
75
|
+
message: e.message,
|
|
76
|
+
data: e.data,
|
|
77
|
+
};
|
|
78
|
+
if (typeof e.stack === 'string')
|
|
79
|
+
wire.stack = e.stack;
|
|
80
|
+
return wire;
|
|
81
|
+
}
|
|
82
|
+
/** CLIENT SIDE: a {@link WireRpcError} becomes a real `RpcError`; anything else is unchanged. */
|
|
83
|
+
function fromWire(e) {
|
|
84
|
+
if (!isWireRpcError(e))
|
|
85
|
+
return e;
|
|
86
|
+
const error = new RpcError(e.code, e.message, e.data);
|
|
87
|
+
// The worker's stack, as comlink keeps it for a plain Error: it is where the
|
|
88
|
+
// error was raised, which is what a reader of the stack wants.
|
|
89
|
+
if (typeof e.stack === 'string')
|
|
90
|
+
error.stack = e.stack;
|
|
91
|
+
return error;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* HOST SIDE: `fn`, rejecting with a {@link WireRpcError} wherever it would have
|
|
95
|
+
* rejected with an `RpcError`. Every other rejection passes through untouched.
|
|
96
|
+
*/
|
|
97
|
+
export function sendingRpcErrors(fn) {
|
|
98
|
+
return async (...args) => {
|
|
99
|
+
try {
|
|
100
|
+
return await fn(...args);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
throw toWire(e);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* CLIENT SIDE: `fn`, rejecting with a real `RpcError` wherever the worker sent a
|
|
109
|
+
* {@link WireRpcError}. Every other rejection passes through untouched.
|
|
110
|
+
*/
|
|
111
|
+
export function receivingRpcErrors(fn) {
|
|
112
|
+
return async (...args) => {
|
|
113
|
+
try {
|
|
114
|
+
return await fn(...args);
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
throw fromWire(e);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=worker-rpc-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-rpc-error.js","sourceRoot":"","sources":["../src/worker-rpc-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAapC;;;;;GAKG;AACH,SAAS,UAAU,CAAC,CAAU;IAC7B,OAAO,CACN,CAAC,YAAY,QAAQ;QACrB,CAAC,CAAC,YAAY,KAAK;YAClB,CAAC,CAAC,IAAI,KAAK,UAAU;YACrB,OAAQ,CAAsB,CAAC,IAAI,KAAK,QAAQ,CAAC,CAClD,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,CAAU;IACjC,OAAO,CACN,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACT,CAAgC,CAAC,cAAc,KAAK,IAAI;QACzD,OAAQ,CAAsB,CAAC,IAAI,KAAK,QAAQ;QAChD,OAAQ,CAAyB,CAAC,OAAO,KAAK,QAAQ,CACtD,CAAC;AACH,CAAC;AAED,2FAA2F;AAC3F,SAAS,MAAM,CAAC,CAAU;IACzB,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAiB;QAC1B,cAAc,EAAE,IAAI;QACpB,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,IAAI,EAAE,CAAC,CAAC,IAAI;KACZ,CAAC;IACF,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;QAAE,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IACtD,OAAO,IAAI,CAAC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