@aztec/world-state 0.0.1-commit.24de95ac → 0.0.1-commit.2606882

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.
Files changed (61) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/instrumentation/instrumentation.d.ts +1 -1
  3. package/dest/instrumentation/instrumentation.d.ts.map +1 -1
  4. package/dest/instrumentation/instrumentation.js +17 -41
  5. package/dest/native/bench_metrics.d.ts +1 -1
  6. package/dest/native/bench_metrics.d.ts.map +1 -1
  7. package/dest/native/fork_checkpoint.d.ts +7 -1
  8. package/dest/native/fork_checkpoint.d.ts.map +1 -1
  9. package/dest/native/fork_checkpoint.js +15 -3
  10. package/dest/native/index.d.ts +1 -1
  11. package/dest/native/merkle_trees_facade.d.ts +19 -10
  12. package/dest/native/merkle_trees_facade.d.ts.map +1 -1
  13. package/dest/native/merkle_trees_facade.js +68 -17
  14. package/dest/native/message.d.ts +24 -15
  15. package/dest/native/message.d.ts.map +1 -1
  16. package/dest/native/message.js +14 -13
  17. package/dest/native/native_world_state.d.ts +42 -13
  18. package/dest/native/native_world_state.d.ts.map +1 -1
  19. package/dest/native/native_world_state.js +93 -35
  20. package/dest/native/native_world_state_instance.d.ts +15 -5
  21. package/dest/native/native_world_state_instance.d.ts.map +1 -1
  22. package/dest/native/native_world_state_instance.js +54 -26
  23. package/dest/native/world_state_ops_queue.d.ts +1 -1
  24. package/dest/native/world_state_ops_queue.d.ts.map +1 -1
  25. package/dest/native/world_state_ops_queue.js +5 -5
  26. package/dest/synchronizer/config.d.ts +3 -5
  27. package/dest/synchronizer/config.d.ts.map +1 -1
  28. package/dest/synchronizer/config.js +15 -18
  29. package/dest/synchronizer/errors.d.ts +1 -1
  30. package/dest/synchronizer/errors.d.ts.map +1 -1
  31. package/dest/synchronizer/factory.d.ts +6 -5
  32. package/dest/synchronizer/factory.d.ts.map +1 -1
  33. package/dest/synchronizer/factory.js +7 -6
  34. package/dest/synchronizer/index.d.ts +1 -1
  35. package/dest/synchronizer/server_world_state_synchronizer.d.ts +11 -28
  36. package/dest/synchronizer/server_world_state_synchronizer.d.ts.map +1 -1
  37. package/dest/synchronizer/server_world_state_synchronizer.js +165 -81
  38. package/dest/test/index.d.ts +1 -1
  39. package/dest/test/utils.d.ts +12 -5
  40. package/dest/test/utils.d.ts.map +1 -1
  41. package/dest/test/utils.js +54 -50
  42. package/dest/testing.d.ts +5 -4
  43. package/dest/testing.d.ts.map +1 -1
  44. package/dest/testing.js +11 -7
  45. package/dest/world-state-db/index.d.ts +1 -1
  46. package/dest/world-state-db/merkle_tree_db.d.ts +9 -19
  47. package/dest/world-state-db/merkle_tree_db.d.ts.map +1 -1
  48. package/package.json +15 -13
  49. package/src/instrumentation/instrumentation.ts +17 -41
  50. package/src/native/fork_checkpoint.ts +19 -3
  51. package/src/native/merkle_trees_facade.ts +79 -20
  52. package/src/native/message.ts +37 -26
  53. package/src/native/native_world_state.ts +136 -48
  54. package/src/native/native_world_state_instance.ts +72 -32
  55. package/src/native/world_state_ops_queue.ts +5 -5
  56. package/src/synchronizer/config.ts +16 -23
  57. package/src/synchronizer/factory.ts +19 -11
  58. package/src/synchronizer/server_world_state_synchronizer.ts +181 -106
  59. package/src/test/utils.ts +87 -92
  60. package/src/testing.ts +9 -10
  61. package/src/world-state-db/merkle_tree_db.ts +12 -19
@@ -1,4 +1,5 @@
1
- import { Fr } from '@aztec/foundation/fields';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
2
3
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
3
4
  export var WorldStateMessageType = /*#__PURE__*/ function(WorldStateMessageType) {
4
5
  WorldStateMessageType[WorldStateMessageType["GET_TREE_INFO"] = 100] = "GET_TREE_INFO";
@@ -58,9 +59,9 @@ export function buildEmptyTreeMeta() {
58
59
  depth: 0,
59
60
  size: 0n,
60
61
  committedSize: 0n,
61
- unfinalizedBlockHeight: 0n,
62
- finalizedBlockHeight: 0n,
63
- oldestHistoricBlock: 0n,
62
+ unfinalizedBlockHeight: BlockNumber.ZERO,
63
+ finalizedBlockHeight: BlockNumber.ZERO,
64
+ oldestHistoricBlock: BlockNumber.ZERO,
64
65
  root: Fr.ZERO,
65
66
  initialRoot: Fr.ZERO,
66
67
  initialSize: 0n
@@ -86,9 +87,9 @@ export function buildEmptyWorldStateDBStats() {
86
87
  }
87
88
  export function buildEmptyWorldStateSummary() {
88
89
  return {
89
- unfinalizedBlockNumber: 0n,
90
- finalizedBlockNumber: 0n,
91
- oldestHistoricalBlock: 0n,
90
+ unfinalizedBlockNumber: BlockNumber.ZERO,
91
+ finalizedBlockNumber: BlockNumber.ZERO,
92
+ oldestHistoricalBlock: BlockNumber.ZERO,
92
93
  treesAreSynched: true
93
94
  };
94
95
  }
@@ -100,9 +101,9 @@ export function buildEmptyWorldStateStatusFull() {
100
101
  };
101
102
  }
102
103
  export function sanitizeSummary(summary) {
103
- summary.finalizedBlockNumber = BigInt(summary.finalizedBlockNumber);
104
- summary.unfinalizedBlockNumber = BigInt(summary.unfinalizedBlockNumber);
105
- summary.oldestHistoricalBlock = BigInt(summary.oldestHistoricalBlock);
104
+ summary.finalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.finalizedBlockNumber));
105
+ summary.unfinalizedBlockNumber = BlockNumber.fromBigInt(BigInt(summary.unfinalizedBlockNumber));
106
+ summary.oldestHistoricalBlock = BlockNumber.fromBigInt(BigInt(summary.oldestHistoricalBlock));
106
107
  return summary;
107
108
  }
108
109
  export function sanitizeDBStats(stats) {
@@ -112,11 +113,11 @@ export function sanitizeDBStats(stats) {
112
113
  }
113
114
  export function sanitizeMeta(meta) {
114
115
  meta.committedSize = BigInt(meta.committedSize);
115
- meta.finalizedBlockHeight = BigInt(meta.finalizedBlockHeight);
116
+ meta.finalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.finalizedBlockHeight));
116
117
  meta.initialSize = BigInt(meta.initialSize);
117
- meta.oldestHistoricBlock = BigInt(meta.oldestHistoricBlock);
118
+ meta.oldestHistoricBlock = BlockNumber.fromBigInt(BigInt(meta.oldestHistoricBlock));
118
119
  meta.size = BigInt(meta.size);
119
- meta.unfinalizedBlockHeight = BigInt(meta.unfinalizedBlockHeight);
120
+ meta.unfinalizedBlockHeight = BlockNumber.fromBigInt(BigInt(meta.unfinalizedBlockHeight));
120
121
  return meta;
121
122
  }
122
123
  export function sanitizeTreeDBStats(stats) {
@@ -1,11 +1,13 @@
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { Fr } from '@aztec/foundation/curves/bn254';
1
3
  import { EthAddress } from '@aztec/foundation/eth-address';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { type Logger } from '@aztec/foundation/log';
4
+ import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
4
5
  import type { L2Block } from '@aztec/stdlib/block';
5
6
  import type { IndexedTreeId, MerkleTreeReadOperations, MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
6
7
  import type { SnapshotDataKeys } from '@aztec/stdlib/snapshots';
7
- import { type NullifierLeafPreimage, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
8
+ import { type NullifierLeafPreimage } from '@aztec/stdlib/trees';
8
9
  import { BlockHeader } from '@aztec/stdlib/tx';
10
+ import { type GenesisData } from '@aztec/stdlib/world-state';
9
11
  import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
10
12
  import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
11
13
  import type { MerkleTreeAdminDatabase as MerkleTreeDatabase } from '../world-state-db/merkle_tree_db.js';
@@ -17,19 +19,46 @@ export declare class NativeWorldStateService implements MerkleTreeDatabase {
17
19
  protected instance: NativeWorldState;
18
20
  protected readonly worldStateInstrumentation: WorldStateInstrumentation;
19
21
  protected readonly log: Logger;
22
+ private readonly genesis;
20
23
  private readonly cleanup;
21
24
  protected initialHeader: BlockHeader | undefined;
22
25
  private cachedStatusSummary;
23
- protected constructor(instance: NativeWorldState, worldStateInstrumentation: WorldStateInstrumentation, log?: Logger, cleanup?: () => Promise<void>);
24
- static new(rollupAddress: EthAddress, dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation, log?: Logger, cleanup?: () => Promise<void>): Promise<NativeWorldStateService>;
25
- static tmp(rollupAddress?: EthAddress, cleanupTmpDir?: boolean, prefilledPublicData?: PublicDataTreeLeaf[], instrumentation?: WorldStateInstrumentation): Promise<NativeWorldStateService>;
26
+ protected constructor(instance: NativeWorldState, worldStateInstrumentation: WorldStateInstrumentation, log: Logger, genesis?: GenesisData, cleanup?: () => Promise<void>);
27
+ /**
28
+ * Opens a persistent world state at `dataDir`. Goes through `DatabaseVersionManager` so the
29
+ * caller's rollup address is bound to the on-disk schema and incompatible versions surface
30
+ * loudly. The LMDB envs commit with full fsync.
31
+ */
32
+ static new(rollupAddress: EthAddress, dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings, cleanup?: () => Promise<void>): Promise<NativeWorldStateService>;
33
+ /**
34
+ * Opens a world state in a fresh tmpdir with full fsync semantics. Use when you need the
35
+ * on-disk file to remain crash-recoverable (e.g. for snapshot/backup tests) but don't
36
+ * want a persistent dataDir. Pass `cleanupTmpDir=false` to keep the directory after
37
+ * close for inspection.
38
+ *
39
+ * If you don't care about crash-recoverability — i.e. you just want a fast scratch
40
+ * database for tests — use {@link ephemeral} instead.
41
+ */
42
+ static tmp(rollupAddress?: EthAddress, cleanupTmpDir?: boolean, genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
43
+ /**
44
+ * Opens a fully-ephemeral world state. The directory is created in `os.tmpdir()`, the LMDB
45
+ * envs open with `MDB_NOSYNC | MDB_NOMETASYNC` so commits never block on fsync, and the
46
+ * directory is removed on dispose. A crash mid-write leaves the env unrecoverable.
47
+ *
48
+ * For unit tests and other isolated runs. Use {@link tmp} when you need fsync semantics in a
49
+ * tmp dir, and {@link new} for a persistent store. Skips {@link DatabaseVersionManager} —
50
+ * there is no on-disk schema to bind to and no rollup address is taken.
51
+ */
52
+ static ephemeral(genesis?: GenesisData, instrumentation?: WorldStateInstrumentation, bindings?: LoggerBindings): Promise<NativeWorldStateService>;
26
53
  protected init(): Promise<void>;
27
54
  clear(): Promise<void>;
28
55
  getCommitted(): MerkleTreeReadOperations;
29
- getSnapshot(blockNumber: number): MerkleTreeReadOperations;
30
- fork(blockNumber?: number): Promise<MerkleTreeWriteOperations>;
56
+ getSnapshot(blockNumber: BlockNumber): MerkleTreeReadOperations;
57
+ fork(blockNumber?: BlockNumber, opts?: {
58
+ closeDelayMs?: number;
59
+ }): Promise<MerkleTreeWriteOperations>;
31
60
  getInitialHeader(): BlockHeader;
32
- handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[], isFirstBlock?: boolean): Promise<WorldStateStatusFull>;
61
+ handleL2BlockAndMessages(l2Block: L2Block, l1ToL2Messages: Fr[]): Promise<WorldStateStatusFull>;
33
62
  close(): Promise<void>;
34
63
  private buildInitialHeader;
35
64
  private sanitizeAndCacheSummaryFromFull;
@@ -40,23 +69,23 @@ export declare class NativeWorldStateService implements MerkleTreeDatabase {
40
69
  * @param toBlockNumber The block number that is now the tip of the finalized chain
41
70
  * @returns The new WorldStateStatus
42
71
  */
43
- setFinalized(toBlockNumber: bigint): Promise<WorldStateStatusSummary>;
72
+ setFinalized(toBlockNumber: BlockNumber): Promise<WorldStateStatusSummary>;
44
73
  /**
45
74
  * Removes all historical snapshots up to but not including the given block number
46
75
  * @param toBlockNumber The block number of the new oldest historical block
47
76
  * @returns The new WorldStateStatus
48
77
  */
49
- removeHistoricalBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
78
+ removeHistoricalBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
50
79
  /**
51
80
  * Removes all pending blocks down to but not including the given block number
52
81
  * @param toBlockNumber The block number of the new tip of the pending chain,
53
82
  * @returns The new WorldStateStatus
54
83
  */
55
- unwindBlocks(toBlockNumber: bigint): Promise<WorldStateStatusFull>;
84
+ unwindBlocks(toBlockNumber: BlockNumber): Promise<WorldStateStatusFull>;
56
85
  getStatusSummary(): Promise<WorldStateStatusSummary>;
57
86
  updateLeaf<ID extends IndexedTreeId>(_treeId: ID, _leaf: NullifierLeafPreimage | Buffer, _index: bigint): Promise<void>;
58
87
  private getInitialStateReference;
59
88
  backupTo(dstPath: string, compact?: boolean): Promise<Record<Exclude<SnapshotDataKeys, 'archiver'>, string>>;
60
89
  }
61
90
  export declare const NATIVE_WORLD_STATE_DBS: readonly [readonly ["l1-to-l2-message-tree", "L1ToL2MessageTree"], readonly ["archive-tree", "ArchiveTree"], readonly ["public-data-tree", "PublicDataTree"], readonly ["note-hash-tree", "NoteHashTree"], readonly ["nullifier-tree", "NullifierTree"]];
62
- //# sourceMappingURL=native_world_state.d.ts.map
91
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUUzRCxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFDdkYsT0FBTyxLQUFL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M,GACb,OAAO,CAAC,IAAI,CAAC,CAEf;YAEa,wBAAwB;IAazB,QAAQ,CACnB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,OAAc,GACtB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,CAOhE;CACF;AAGD,eAAO,MAAM,sBAAsB,0PAMzB,CAAC"}
@@ -1,13 +1,14 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
3
  import { fromEntries, padArrayEnd } from '@aztec/foundation/collection';
4
+ import { Fr } from '@aztec/foundation/curves/bn254';
3
5
  import { EthAddress } from '@aztec/foundation/eth-address';
4
- import { Fr } from '@aztec/foundation/fields';
5
6
  import { tryRmDir } from '@aztec/foundation/fs';
6
7
  import { createLogger } from '@aztec/foundation/log';
7
- import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
8
+ import { DatabaseVersionManager } from '@aztec/stdlib/database-version/manager';
8
9
  import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
9
- import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
10
- import { WorldStateRevision } from '@aztec/stdlib/world-state';
10
+ import { BlockHeader, GlobalVariables, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
11
+ import { EMPTY_GENESIS_DATA, WorldStateRevision } from '@aztec/stdlib/world-state';
11
12
  import { getTelemetryClient } from '@aztec/telemetry-client';
12
13
  import assert from 'assert/strict';
13
14
  import { mkdtemp, rm } from 'fs/promises';
@@ -21,33 +22,59 @@ import { NativeWorldState } from './native_world_state_instance.js';
21
22
  // Increment this when making incompatible changes to the database schema
22
23
  export const WORLD_STATE_DB_VERSION = 2; // The initial version
23
24
  export const WORLD_STATE_DIR = 'world_state';
25
+ const DEFAULT_TMP_TREE_MAP_SIZE_KB = 10 * 1024 * 1024;
26
+ /**
27
+ * Sets up a fresh `mkdtemp` directory + default `WorldStateTreeMapSizes` shared by both
28
+ * the `.tmp` (fsync-on) and `.ephemeral` (fsync-off) factories. Returns the raw tmpdir,
29
+ * the tree map sizes, and the package logger.
30
+ */ async function createTmpWorldStateDir(bindings) {
31
+ const log = createLogger('world-state:database', bindings);
32
+ const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
33
+ const wsTreeMapSizes = {
34
+ archiveTreeMapSizeKb: DEFAULT_TMP_TREE_MAP_SIZE_KB,
35
+ nullifierTreeMapSizeKb: DEFAULT_TMP_TREE_MAP_SIZE_KB,
36
+ noteHashTreeMapSizeKb: DEFAULT_TMP_TREE_MAP_SIZE_KB,
37
+ messageTreeMapSizeKb: DEFAULT_TMP_TREE_MAP_SIZE_KB,
38
+ publicDataTreeMapSizeKb: DEFAULT_TMP_TREE_MAP_SIZE_KB
39
+ };
40
+ log.debug(`Created temporary world state database at: ${dataDir} (map size ${DEFAULT_TMP_TREE_MAP_SIZE_KB} KB)`);
41
+ return {
42
+ dataDir,
43
+ wsTreeMapSizes,
44
+ log
45
+ };
46
+ }
24
47
  export class NativeWorldStateService {
25
48
  instance;
26
49
  worldStateInstrumentation;
27
50
  log;
51
+ genesis;
28
52
  cleanup;
29
53
  initialHeader;
30
54
  // This is read heavily and only changes when data is persisted, so we cache it
31
55
  cachedStatusSummary;
32
- constructor(instance, worldStateInstrumentation, log = createLogger('world-state:database'), cleanup = ()=>Promise.resolve()){
56
+ constructor(instance, worldStateInstrumentation, log, genesis = EMPTY_GENESIS_DATA, cleanup = ()=>Promise.resolve()){
33
57
  this.instance = instance;
34
58
  this.worldStateInstrumentation = worldStateInstrumentation;
35
59
  this.log = log;
60
+ this.genesis = genesis;
36
61
  this.cleanup = cleanup;
37
62
  }
38
- static async new(rollupAddress, dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world-state:database'), cleanup = ()=>Promise.resolve()) {
63
+ /**
64
+ * Opens a persistent world state at `dataDir`. Goes through `DatabaseVersionManager` so the
65
+ * caller's rollup address is bound to the on-disk schema and incompatible versions surface
66
+ * loudly. The LMDB envs commit with full fsync.
67
+ */ static async new(rollupAddress, dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings, cleanup = ()=>Promise.resolve()) {
68
+ const log = createLogger('world-state:database', bindings);
39
69
  const worldStateDirectory = join(dataDir, WORLD_STATE_DIR);
40
- // Create a version manager to handle versioning
41
70
  const versionManager = new DatabaseVersionManager({
42
71
  schemaVersion: WORLD_STATE_DB_VERSION,
43
72
  rollupAddress,
44
73
  dataDirectory: worldStateDirectory,
45
- onOpen: (dir)=>{
46
- return Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, prefilledPublicData, instrumentation));
47
- }
74
+ onOpen: (dir)=>Promise.resolve(new NativeWorldState(dir, wsTreeMapSizes, genesis, instrumentation, bindings, undefined, /*ephemeral=*/ false))
48
75
  });
49
76
  const [instance] = await versionManager.open();
50
- const worldState = new this(instance, instrumentation, log, cleanup);
77
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup);
51
78
  try {
52
79
  await worldState.init();
53
80
  } catch (e) {
@@ -56,19 +83,16 @@ export class NativeWorldStateService {
56
83
  }
57
84
  return worldState;
58
85
  }
59
- static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient())) {
60
- const log = createLogger('world-state:database');
61
- const dataDir = await mkdtemp(join(tmpdir(), 'aztec-world-state-'));
62
- const dbMapSizeKb = 10 * 1024 * 1024;
63
- const worldStateTreeMapSizes = {
64
- archiveTreeMapSizeKb: dbMapSizeKb,
65
- nullifierTreeMapSizeKb: dbMapSizeKb,
66
- noteHashTreeMapSizeKb: dbMapSizeKb,
67
- messageTreeMapSizeKb: dbMapSizeKb,
68
- publicDataTreeMapSizeKb: dbMapSizeKb
69
- };
70
- log.debug(`Created temporary world state database at: ${dataDir} with tree map size: ${dbMapSizeKb}`);
71
- // pass a cleanup callback because process.on('beforeExit', cleanup) does not work under Jest
86
+ /**
87
+ * Opens a world state in a fresh tmpdir with full fsync semantics. Use when you need the
88
+ * on-disk file to remain crash-recoverable (e.g. for snapshot/backup tests) but don't
89
+ * want a persistent dataDir. Pass `cleanupTmpDir=false` to keep the directory after
90
+ * close for inspection.
91
+ *
92
+ * If you don't care about crash-recoverability — i.e. you just want a fast scratch
93
+ * database for tests — use {@link ephemeral} instead.
94
+ */ static async tmp(rollupAddress = EthAddress.ZERO, cleanupTmpDir = true, genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
95
+ const { dataDir, wsTreeMapSizes, log } = await createTmpWorldStateDir(bindings);
72
96
  const cleanup = async ()=>{
73
97
  if (cleanupTmpDir) {
74
98
  await rm(dataDir, {
@@ -81,7 +105,35 @@ export class NativeWorldStateService {
81
105
  log.debug(`Leaving temporary world state database: ${dataDir}`);
82
106
  }
83
107
  };
84
- return this.new(rollupAddress, dataDir, worldStateTreeMapSizes, prefilledPublicData, instrumentation, log, cleanup);
108
+ return this.new(rollupAddress, dataDir, wsTreeMapSizes, genesis, instrumentation, bindings, cleanup);
109
+ }
110
+ /**
111
+ * Opens a fully-ephemeral world state. The directory is created in `os.tmpdir()`, the LMDB
112
+ * envs open with `MDB_NOSYNC | MDB_NOMETASYNC` so commits never block on fsync, and the
113
+ * directory is removed on dispose. A crash mid-write leaves the env unrecoverable.
114
+ *
115
+ * For unit tests and other isolated runs. Use {@link tmp} when you need fsync semantics in a
116
+ * tmp dir, and {@link new} for a persistent store. Skips {@link DatabaseVersionManager} —
117
+ * there is no on-disk schema to bind to and no rollup address is taken.
118
+ */ static async ephemeral(genesis = EMPTY_GENESIS_DATA, instrumentation = new WorldStateInstrumentation(getTelemetryClient()), bindings) {
119
+ const { dataDir, wsTreeMapSizes, log } = await createTmpWorldStateDir(bindings);
120
+ const cleanup = async ()=>{
121
+ await rm(dataDir, {
122
+ recursive: true,
123
+ force: true,
124
+ maxRetries: 3
125
+ });
126
+ log.debug(`Deleted ephemeral world state database: ${dataDir}`);
127
+ };
128
+ const instance = new NativeWorldState(join(dataDir, WORLD_STATE_DIR), wsTreeMapSizes, genesis, instrumentation, bindings, undefined, /*ephemeral=*/ true);
129
+ const worldState = new this(instance, instrumentation, log, genesis, cleanup);
130
+ try {
131
+ await worldState.init();
132
+ } catch (e) {
133
+ log.error(`Error initializing ephemeral world state: ${e}`);
134
+ throw e;
135
+ }
136
+ return worldState;
85
137
  }
86
138
  async init() {
87
139
  const status = await this.getStatusSummary();
@@ -115,23 +167,26 @@ export class NativeWorldStateService {
115
167
  getSnapshot(blockNumber) {
116
168
  return new MerkleTreesFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ 0, /* blockNumber=*/ blockNumber, /* includeUncommitted=*/ false));
117
169
  }
118
- async fork(blockNumber) {
170
+ async fork(blockNumber, opts = {}) {
119
171
  const resp = await this.instance.call(WorldStateMessageType.CREATE_FORK, {
120
172
  latest: blockNumber === undefined,
121
- blockNumber: blockNumber ?? 0,
173
+ blockNumber: blockNumber ?? BlockNumber.ZERO,
122
174
  canonical: true
123
175
  });
124
- return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ resp.forkId, /* blockNumber=*/ 0, /* includeUncommitted=*/ true));
176
+ return new MerkleTreesForkFacade(this.instance, this.initialHeader, new WorldStateRevision(/*forkId=*/ resp.forkId, /* blockNumber=*/ WorldStateRevision.LATEST, /* includeUncommitted=*/ true), opts);
125
177
  }
126
178
  getInitialHeader() {
127
179
  return this.initialHeader;
128
180
  }
129
- async handleL2BlockAndMessages(l2Block, l1ToL2Messages, // TODO(#17027)
130
- // Temporary hack to only insert l1 to l2 messages for the first block in a checkpoint.
131
- isFirstBlock = true) {
132
- // We have to pad both the values within tx effects because that's how the trees are built by circuits.
133
- const paddedNoteHashes = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
181
+ async handleL2BlockAndMessages(l2Block, l1ToL2Messages) {
182
+ const isFirstBlock = l2Block.indexWithinCheckpoint === 0;
183
+ if (!isFirstBlock && l1ToL2Messages.length > 0) {
184
+ throw new Error(`L1 to L2 messages must be empty for non-first blocks, but got ${l1ToL2Messages.length} messages for block ${l2Block.number}.`);
185
+ }
186
+ // We have to pad the given l1 to l2 messages, and the note hashes and nullifiers within tx effects, because that's
187
+ // how the trees are built by circuits.
134
188
  const paddedL1ToL2Messages = isFirstBlock ? padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) : [];
189
+ const paddedNoteHashes = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
135
190
  const paddedNullifiers = l2Block.body.txEffects.flatMap((txEffect)=>padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX)).map((nullifier)=>new NullifierLeaf(nullifier));
136
191
  const publicDataWrites = l2Block.body.txEffects.flatMap((txEffect)=>{
137
192
  return txEffect.publicDataWrites.map((write)=>{
@@ -144,7 +199,7 @@ export class NativeWorldStateService {
144
199
  try {
145
200
  return await this.instance.call(WorldStateMessageType.SYNC_BLOCK, {
146
201
  blockNumber: l2Block.number,
147
- blockHeaderHash: await l2Block.getBlockHeader().hash(),
202
+ blockHeaderHash: (await l2Block.hash()).toBuffer(),
148
203
  paddedL1ToL2Messages: paddedL1ToL2Messages.map(serializeLeaf),
149
204
  paddedNoteHashes: paddedNoteHashes.map(serializeLeaf),
150
205
  paddedNullifiers: paddedNullifiers.map(serializeLeaf),
@@ -164,7 +219,10 @@ export class NativeWorldStateService {
164
219
  async buildInitialHeader() {
165
220
  const state = await this.getInitialStateReference();
166
221
  return BlockHeader.empty({
167
- state
222
+ state,
223
+ globalVariables: GlobalVariables.empty({
224
+ timestamp: this.genesis.genesisTimestamp
225
+ })
168
226
  });
169
227
  }
170
228
  sanitizeAndCacheSummaryFromFull(response) {
@@ -1,10 +1,11 @@
1
- import { type Logger } from '@aztec/foundation/log';
2
- import type { PublicDataTreeLeaf } from '@aztec/stdlib/trees';
1
+ import { type Logger, type LoggerBindings } from '@aztec/foundation/log';
2
+ import { type GenesisData } from '@aztec/stdlib/world-state';
3
3
  import type { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
4
4
  import type { WorldStateTreeMapSizes } from '../synchronizer/factory.js';
5
5
  import { WorldStateMessageType, type WorldStateRequest, type WorldStateRequestCategories, type WorldStateResponse } from './message.js';
6
6
  export interface NativeWorldStateInstance {
7
7
  call<T extends WorldStateMessageType>(messageType: T, body: WorldStateRequest[T] & WorldStateRequestCategories): Promise<WorldStateResponse[T]>;
8
+ getHandle(): any;
8
9
  }
9
10
  /**
10
11
  * Strongly-typed interface to access the WorldState class in the native world_state_napi module.
@@ -12,16 +13,25 @@ export interface NativeWorldStateInstance {
12
13
  export declare class NativeWorldState implements NativeWorldStateInstance {
13
14
  private readonly dataDir;
14
15
  private readonly wsTreeMapSizes;
15
- private readonly prefilledPublicData;
16
+ private readonly genesis;
16
17
  private readonly instrumentation;
17
18
  private readonly log;
19
+ private readonly ephemeral;
18
20
  private open;
19
21
  private queues;
20
22
  private instance;
21
23
  /** Creates a new native WorldState instance */
22
- constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, prefilledPublicData: PublicDataTreeLeaf[] | undefined, instrumentation: WorldStateInstrumentation, log?: Logger);
24
+ constructor(dataDir: string, wsTreeMapSizes: WorldStateTreeMapSizes, genesis: GenesisData | undefined, instrumentation: WorldStateInstrumentation, bindings?: LoggerBindings, log?: Logger, ephemeral?: boolean);
23
25
  getDataDir(): string;
24
26
  clone(): NativeWorldState;
27
+ /**
28
+ * Gets the native WorldState handle from the underlying native instance.
29
+ * We call the getHandle() method on the native WorldState to get a NAPI External
30
+ * that wraps the underlying C++ WorldState pointer.
31
+ * @returns The NAPI External handle to the native WorldState instance,since
32
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
33
+ */
34
+ getHandle(): any;
25
35
  /**
26
36
  * Sends a message to the native instance and returns the response.
27
37
  * @param messageType - The type of message to send
@@ -37,4 +47,4 @@ export declare class NativeWorldState implements NativeWorldStateInstance {
37
47
  close(): Promise<void>;
38
48
  private _sendMessage;
39
49
  }
40
- //# sourceMappingURL=native_world_state_instance.d.ts.map
50
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlX3dvcmxkX3N0YXRlX2luc3RhbmNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL25hdGl2ZV93b3JsZF9zdGF0ZV9pbnN0YW5jZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFVQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWdCLE1BQU0sdUJBQXVCLENBQUM7QUFHdkYsT0FBTyxFQUFzQixLQUFLLFdBQVcsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBS2pGLE9BQU8sS0FBSyxFQUFFLHlCQUF5QixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDdkYsT0FBTyxLQUFLLEVBQUUsc0JBQXNCLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUN6RSxPQUFPLEVBQ0wscUJBQXFCLEVBQ3JCLEtBQUssaUJBQWlCLEVBQ3RCLEtBQUssMkJBQTJCLEVBQ2hDLEtBQUssa0JBQWtCLEVBSXhCLE1BQU0sY0FBYyxDQUFDO0FBS3RCLE1BQU0sV0FBVyx3QkFBd0I7SUFDdkMsSUFBSSxDQUFDLENBQU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BQVcsRUFBRSxDQUFDLEVBQ2QsSUFBSSxFQUFFLGlCQUFpQixDQUFDLENBQUMsQ0FBQyxHQUFHLDJCQUEyQixFQUV4RCxlQUFlLDZEQUF1RSxFQUN0RixZQUFZLHNCQUFvQixHQUMvQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0F3RGhDO0lBRUQ7O09BRUc7SUFDVSxLQUFLLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQWVsQztZQUVhLFlBQVk7Q0E4RDNCIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"native_world_state_instance.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state_instance.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAGlE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAK9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EACL,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EAChC,KAAK,kBAAkB,EAIxB,MAAM,cAAc,CAAC;AAKtB,MAAM,WAAW,wBAAwB;IACvC,IAAI,CAAC,CAAC,SAAS,qBAAqB,EAClC,WAAW,EAAE,CAAC,EACd,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,2BAA2B,GACvD,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,wBAAwB;IAU7D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAA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FIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
1
+ import { ARCHIVE_HEIGHT, DomainSeparator, L1_TO_L2_MSG_TREE_HEIGHT, MAX_NULLIFIERS_PER_TX, MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, NOTE_HASH_TREE_HEIGHT, NULLIFIER_TREE_HEIGHT, PUBLIC_DATA_TREE_HEIGHT } from '@aztec/constants';
2
2
  import { createLogger } from '@aztec/foundation/log';
3
3
  import { NativeWorldState as BaseNativeWorldState, MsgpackChannel } from '@aztec/native';
4
4
  import { MerkleTreeId } from '@aztec/stdlib/trees';
5
+ import { EMPTY_GENESIS_DATA } from '@aztec/stdlib/world-state';
5
6
  import assert from 'assert';
6
7
  import { cpus } from 'os';
7
8
  import { WorldStateMessageType, isWithCanonical, isWithForkId, isWithRevision } from './message.js';
@@ -12,24 +13,26 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
12
13
  */ export class NativeWorldState {
13
14
  dataDir;
14
15
  wsTreeMapSizes;
15
- prefilledPublicData;
16
+ genesis;
16
17
  instrumentation;
17
18
  log;
19
+ ephemeral;
18
20
  open;
19
21
  // We maintain a map of queue to fork
20
22
  queues;
21
23
  instance;
22
- /** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, prefilledPublicData = [], instrumentation, log = createLogger('world-state:database')){
24
+ /** Creates a new native WorldState instance */ constructor(dataDir, wsTreeMapSizes, genesis = EMPTY_GENESIS_DATA, instrumentation, bindings, log = createLogger('world-state:database', bindings), ephemeral = false){
23
25
  this.dataDir = dataDir;
24
26
  this.wsTreeMapSizes = wsTreeMapSizes;
25
- this.prefilledPublicData = prefilledPublicData;
27
+ this.genesis = genesis;
26
28
  this.instrumentation = instrumentation;
27
29
  this.log = log;
30
+ this.ephemeral = ephemeral;
28
31
  this.open = true;
29
32
  this.queues = new Map();
30
33
  const threads = Math.min(cpus().length, MAX_WORLD_STATE_THREADS);
31
- log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads.`);
32
- const prefilledPublicDataBufferArray = prefilledPublicData.map((d)=>[
34
+ log.info(`Creating world state data store at directory ${dataDir} with map sizes ${JSON.stringify(wsTreeMapSizes)} and ${threads} threads (ephemeral=${ephemeral}).`);
35
+ const prefilledPublicDataBufferArray = genesis.prefilledPublicData.map((d)=>[
33
36
  d.slot.toBuffer(),
34
37
  d.value.toBuffer()
35
38
  ]);
@@ -42,13 +45,13 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
42
45
  }, {
43
46
  [MerkleTreeId.NULLIFIER_TREE]: 2 * MAX_NULLIFIERS_PER_TX,
44
47
  [MerkleTreeId.PUBLIC_DATA_TREE]: 2 * MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
45
- }, prefilledPublicDataBufferArray, GeneratorIndex.BLOCK_HASH, {
48
+ }, prefilledPublicDataBufferArray, DomainSeparator.BLOCK_HEADER_HASH, Number(genesis.genesisTimestamp), {
46
49
  [MerkleTreeId.NULLIFIER_TREE]: wsTreeMapSizes.nullifierTreeMapSizeKb,
47
50
  [MerkleTreeId.NOTE_HASH_TREE]: wsTreeMapSizes.noteHashTreeMapSizeKb,
48
51
  [MerkleTreeId.PUBLIC_DATA_TREE]: wsTreeMapSizes.publicDataTreeMapSizeKb,
49
52
  [MerkleTreeId.L1_TO_L2_MESSAGE_TREE]: wsTreeMapSizes.messageTreeMapSizeKb,
50
53
  [MerkleTreeId.ARCHIVE]: wsTreeMapSizes.archiveTreeMapSizeKb
51
- }, threads);
54
+ }, threads, ephemeral);
52
55
  this.instance = new MsgpackChannel(ws);
53
56
  // Manually create the queue for the canonical fork
54
57
  this.queues.set(0, new WorldStateOpsQueue());
@@ -57,7 +60,28 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
57
60
  return this.dataDir;
58
61
  }
59
62
  clone() {
60
- return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.prefilledPublicData, this.instrumentation, this.log);
63
+ return new NativeWorldState(this.dataDir, this.wsTreeMapSizes, this.genesis, this.instrumentation, this.log.getBindings(), this.log, this.ephemeral);
64
+ }
65
+ /**
66
+ * Gets the native WorldState handle from the underlying native instance.
67
+ * We call the getHandle() method on the native WorldState to get a NAPI External
68
+ * that wraps the underlying C++ WorldState pointer.
69
+ * @returns The NAPI External handle to the native WorldState instance,since
70
+ * the NAPI external type is opaque, we return any (we could also use an opaque symbol type)
71
+ */ getHandle() {
72
+ const worldStateWrapper = this.instance.dest;
73
+ if (!worldStateWrapper) {
74
+ throw new Error('No WorldStateWrapper found');
75
+ }
76
+ if (typeof worldStateWrapper.getHandle !== 'function') {
77
+ throw new Error('WorldStateWrapper does not have getHandle method');
78
+ }
79
+ // Call getHandle() to get the NAPI External
80
+ try {
81
+ return worldStateWrapper.getHandle();
82
+ } catch (error) {
83
+ this.log.error('Failed to get native WorldState handle', error);
84
+ }
61
85
  }
62
86
  /**
63
87
  * Sends a message to the native instance and returns the response.
@@ -93,25 +117,29 @@ const MAX_WORLD_STATE_THREADS = +(process.env.HARDWARE_CONCURRENCY || '16');
93
117
  requestQueue = new WorldStateOpsQueue();
94
118
  this.queues.set(forkId, requestQueue);
95
119
  }
96
- // Enqueue the request and wait for the response
97
- const response = await requestQueue.execute(async ()=>{
98
- assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
99
- assert.equal(this.open, true, 'Native instance is closed');
100
- let response;
101
- try {
102
- response = await this._sendMessage(messageType, body);
103
- } catch (error) {
104
- errorHandler(error.message);
105
- throw error;
120
+ // Enqueue the request and wait for the response. The per-fork queue is cleaned up in `finally` even on
121
+ // error, so the JS-side queues map cannot outlive the native fork (e.g. when the native fork was already
122
+ // destroyed by an unwind/historical-prune and DELETE_FORK rejects with "Fork not found").
123
+ try {
124
+ const response = await requestQueue.execute(async ()=>{
125
+ assert.notEqual(messageType, WorldStateMessageType.CLOSE, 'Use close() to close the native instance');
126
+ assert.equal(this.open, true, 'Native instance is closed');
127
+ let response;
128
+ try {
129
+ response = await this._sendMessage(messageType, body);
130
+ } catch (error) {
131
+ errorHandler(error.message);
132
+ throw error;
133
+ }
134
+ return responseHandler(response);
135
+ }, messageType, committedOnly);
136
+ return response;
137
+ } finally{
138
+ if (messageType === WorldStateMessageType.DELETE_FORK) {
139
+ await requestQueue.stop();
140
+ this.queues.delete(forkId);
106
141
  }
107
- return responseHandler(response);
108
- }, messageType, committedOnly);
109
- // If the request was to delete the fork then we clean it up here
110
- if (messageType === WorldStateMessageType.DELETE_FORK) {
111
- await requestQueue.stop();
112
- this.queues.delete(forkId);
113
142
  }
114
- return response;
115
143
  }
116
144
  /**
117
145
  * Stops the native instance.
@@ -16,4 +16,4 @@ export declare class WorldStateOpsQueue {
16
16
  private sendEnqueuedRequest;
17
17
  stop(): Promise<void>;
18
18
  }
19
- //# sourceMappingURL=world_state_ops_queue.d.ts.map
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid29ybGRfc3RhdGVfb3BzX3F1ZXVlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbmF0aXZlL3dvcmxkX3N0YXRlX29wc19xdWV1ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUscUJBQXFCLEVBQUUsTUFBTSxjQUFjLENBQUM7QUF5QnJELGVBQU8sTUFBTSxrQkFBa0IsNEJBZ0I3QixDQUFDO0FBR0gscUJBQWEsa0JBQWtCO0lBQzdCLE9BQU8sQ0FBQyxRQUFRLENBQXNCO0lBQ3RDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBSztJQUNsQyxPQUF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