@aztec/world-state 0.77.0-testnet-ignition.30 → 0.77.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/dest/native/native_world_state.d.ts +0 -1
- package/dest/native/native_world_state.d.ts.map +1 -1
- package/dest/native/native_world_state.js +8 -37
- package/package.json +10 -10
- package/src/native/native_world_state.ts +14 -28
- package/dest/native/world_state_version.d.ts +0 -24
- package/dest/native/world_state_version.d.ts.map +0 -1
- package/dest/native/world_state_version.js +0 -30
- package/src/native/world_state_version.ts +0 -33
|
@@ -10,7 +10,6 @@ import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js
|
|
|
10
10
|
import type { MerkleTreeAdminDatabase as MerkleTreeDatabase } from '../world-state-db/merkle_tree_db.js';
|
|
11
11
|
import { type WorldStateStatusFull, type WorldStateStatusSummary } from './message.js';
|
|
12
12
|
import { NativeWorldState } from './native_world_state_instance.js';
|
|
13
|
-
export declare const WORLD_STATE_VERSION_FILE = "version";
|
|
14
13
|
export declare const WORLD_STATE_DB_VERSION = 1;
|
|
15
14
|
export declare class NativeWorldStateService implements MerkleTreeDatabase {
|
|
16
15
|
protected readonly instance: NativeWorldState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native_world_state.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"native_world_state.d.ts","sourceRoot":"","sources":["../../src/native/native_world_state.ts"],"names":[],"mappings":";;AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,KAAK,EAA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O,EACpB,mBAAmB,GAAE,kBAAkB,EAAO,EAC9C,eAAe,4BAAsD,GACpE,OAAO,CAAC,uBAAuB,CAAC;cAmBnB,IAAI;IAqBb,YAAY,IAAI,wBAAwB;IAIxC,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB;IAIpD,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;IASpE,gBAAgB,IAAI,WAAW;IAIzB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC;IA0C/F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAKrB,kBAAkB;IAKhC,OAAO,CAAC,+BAA+B;IAMvC,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,mBAAmB;IAI3B;;;;OAIG;IACU,YAAY,CAAC,aAAa,EAAE,MAAM;IAkB/C;;;;OAIG;IACU,sBAAsB,CAAC,aAAa,EAAE,MAAM;IAiBzD;;;;OAIG;IACU,YAAY,CAAC,aAAa,EAAE,MAAM;IAiBlC,gBAAgB;IAW7B,UAAU,CAAC,EAAE,SAAS,aAAa,EACjC,OAAO,EAAE,EAAE,EACX,KAAK,EAAE,qBAAqB,GAAG,MAAM,EACrC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;YAIF,wBAAwB;CAYvC"}
|
|
@@ -3,24 +3,20 @@ import { padArrayEnd } from '@aztec/foundation/collection';
|
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
6
7
|
import { MerkleTreeId, NullifierLeaf, PublicDataTreeLeaf } from '@aztec/stdlib/trees';
|
|
7
8
|
import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdlib/tx';
|
|
8
9
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
9
10
|
import assert from 'assert/strict';
|
|
10
|
-
import {
|
|
11
|
+
import { mkdtemp, rm } from 'fs/promises';
|
|
11
12
|
import { tmpdir } from 'os';
|
|
12
13
|
import { join } from 'path';
|
|
13
14
|
import { WorldStateInstrumentation } from '../instrumentation/instrumentation.js';
|
|
14
15
|
import { MerkleTreesFacade, MerkleTreesForkFacade, serializeLeaf } from './merkle_trees_facade.js';
|
|
15
16
|
import { WorldStateMessageType, blockStateReference, sanitiseFullStatus, sanitiseSummary, treeStateReferenceToSnapshot, worldStateRevision } from './message.js';
|
|
16
17
|
import { NativeWorldState } from './native_world_state_instance.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// A crude way of maintaining DB versioning
|
|
20
|
-
// We don't currently have any method of performing data migrations
|
|
21
|
-
// should the world state db structure change
|
|
22
|
-
// For now we will track versions using this hardcoded value and delete
|
|
23
|
-
// the state if a change is detected
|
|
18
|
+
// The current version of the world state database schema
|
|
19
|
+
// Increment this when making incompatible changes to the database schema
|
|
24
20
|
export const WORLD_STATE_DB_VERSION = 1; // The initial version
|
|
25
21
|
export class NativeWorldStateService {
|
|
26
22
|
instance;
|
|
@@ -38,36 +34,11 @@ export class NativeWorldStateService {
|
|
|
38
34
|
}
|
|
39
35
|
static async new(rollupAddress, dataDir, dbMapSizeKb, prefilledPublicData = [], instrumentation = new WorldStateInstrumentation(getTelemetryClient()), log = createLogger('world-state:database'), cleanup = ()=>Promise.resolve()) {
|
|
40
36
|
const worldStateDirectory = join(dataDir, 'world_state');
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
log.warn('No world state version found, deleting world state directory');
|
|
45
|
-
await rm(worldStateDirectory, {
|
|
46
|
-
recursive: true,
|
|
47
|
-
force: true,
|
|
48
|
-
maxRetries: 3
|
|
49
|
-
});
|
|
50
|
-
} else if (!rollupAddress.equals(storedWorldStateVersion.rollupAddress)) {
|
|
51
|
-
log.warn('Rollup address changed, deleting world state directory');
|
|
52
|
-
await rm(worldStateDirectory, {
|
|
53
|
-
recursive: true,
|
|
54
|
-
force: true,
|
|
55
|
-
maxRetries: 3
|
|
56
|
-
});
|
|
57
|
-
} else if (storedWorldStateVersion.version != WORLD_STATE_DB_VERSION) {
|
|
58
|
-
log.warn('World state version change detected, deleting world state directory');
|
|
59
|
-
await rm(worldStateDirectory, {
|
|
60
|
-
recursive: true,
|
|
61
|
-
force: true,
|
|
62
|
-
maxRetries: 3
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const newWorldStateVersion = new WorldStateVersion(WORLD_STATE_DB_VERSION, rollupAddress);
|
|
66
|
-
await mkdir(worldStateDirectory, {
|
|
67
|
-
recursive: true
|
|
37
|
+
// Create a version manager to handle versioning
|
|
38
|
+
const versionManager = new DatabaseVersionManager(WORLD_STATE_DB_VERSION, rollupAddress, worldStateDirectory, (dir)=>{
|
|
39
|
+
return Promise.resolve(new NativeWorldState(dir, dbMapSizeKb, prefilledPublicData, instrumentation));
|
|
68
40
|
});
|
|
69
|
-
await
|
|
70
|
-
const instance = new NativeWorldState(worldStateDirectory, dbMapSizeKb, prefilledPublicData, instrumentation);
|
|
41
|
+
const [instance] = await versionManager.open();
|
|
71
42
|
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
72
43
|
try {
|
|
73
44
|
await worldState.init();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/world-state",
|
|
3
|
-
"version": "0.77.0
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
@@ -62,19 +62,19 @@
|
|
|
62
62
|
]
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@aztec/constants": "0.77.0
|
|
66
|
-
"@aztec/foundation": "0.77.0
|
|
67
|
-
"@aztec/kv-store": "0.77.0
|
|
68
|
-
"@aztec/merkle-tree": "0.77.0
|
|
69
|
-
"@aztec/native": "0.77.0
|
|
70
|
-
"@aztec/protocol-contracts": "0.77.0
|
|
71
|
-
"@aztec/stdlib": "0.77.0
|
|
72
|
-
"@aztec/telemetry-client": "0.77.0
|
|
65
|
+
"@aztec/constants": "0.77.0",
|
|
66
|
+
"@aztec/foundation": "0.77.0",
|
|
67
|
+
"@aztec/kv-store": "0.77.0",
|
|
68
|
+
"@aztec/merkle-tree": "0.77.0",
|
|
69
|
+
"@aztec/native": "0.77.0",
|
|
70
|
+
"@aztec/protocol-contracts": "0.77.0",
|
|
71
|
+
"@aztec/stdlib": "0.77.0",
|
|
72
|
+
"@aztec/telemetry-client": "0.77.0",
|
|
73
73
|
"tslib": "^2.4.0",
|
|
74
74
|
"zod": "^3.23.8"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@aztec/archiver": "0.77.0
|
|
77
|
+
"@aztec/archiver": "0.77.0",
|
|
78
78
|
"@jest/globals": "^29.5.0",
|
|
79
79
|
"@types/jest": "^29.5.0",
|
|
80
80
|
"@types/levelup": "^5.1.2",
|
|
@@ -4,6 +4,7 @@ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
5
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
6
6
|
import type { L2Block } from '@aztec/stdlib/block';
|
|
7
|
+
import { DatabaseVersionManager } from '@aztec/stdlib/database-version';
|
|
7
8
|
import type {
|
|
8
9
|
IndexedTreeId,
|
|
9
10
|
MerkleTreeReadOperations,
|
|
@@ -14,7 +15,7 @@ import { BlockHeader, PartialStateReference, StateReference } from '@aztec/stdli
|
|
|
14
15
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
15
16
|
|
|
16
17
|
import assert from 'assert/strict';
|
|
17
|
-
import {
|
|
18
|
+
import { mkdtemp, rm } from 'fs/promises';
|
|
18
19
|
import { tmpdir } from 'os';
|
|
19
20
|
import { join } from 'path';
|
|
20
21
|
|
|
@@ -32,15 +33,9 @@ import {
|
|
|
32
33
|
worldStateRevision,
|
|
33
34
|
} from './message.js';
|
|
34
35
|
import { NativeWorldState } from './native_world_state_instance.js';
|
|
35
|
-
import { WorldStateVersion } from './world_state_version.js';
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// A crude way of maintaining DB versioning
|
|
40
|
-
// We don't currently have any method of performing data migrations
|
|
41
|
-
// should the world state db structure change
|
|
42
|
-
// For now we will track versions using this hardcoded value and delete
|
|
43
|
-
// the state if a change is detected
|
|
37
|
+
// The current version of the world state database schema
|
|
38
|
+
// Increment this when making incompatible changes to the database schema
|
|
44
39
|
export const WORLD_STATE_DB_VERSION = 1; // The initial version
|
|
45
40
|
|
|
46
41
|
export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
@@ -65,26 +60,17 @@ export class NativeWorldStateService implements MerkleTreeDatabase {
|
|
|
65
60
|
cleanup = () => Promise.resolve(),
|
|
66
61
|
): Promise<NativeWorldStateService> {
|
|
67
62
|
const worldStateDirectory = join(dataDir, 'world_state');
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else if (storedWorldStateVersion.version != WORLD_STATE_DB_VERSION) {
|
|
78
|
-
log.warn('World state version change detected, deleting world state directory');
|
|
79
|
-
await rm(worldStateDirectory, { recursive: true, force: true, maxRetries: 3 });
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const newWorldStateVersion = new WorldStateVersion(WORLD_STATE_DB_VERSION, rollupAddress);
|
|
83
|
-
|
|
84
|
-
await mkdir(worldStateDirectory, { recursive: true });
|
|
85
|
-
await newWorldStateVersion.writeVersionFile(versionFile);
|
|
63
|
+
// Create a version manager to handle versioning
|
|
64
|
+
const versionManager = new DatabaseVersionManager(
|
|
65
|
+
WORLD_STATE_DB_VERSION,
|
|
66
|
+
rollupAddress,
|
|
67
|
+
worldStateDirectory,
|
|
68
|
+
(dir: string) => {
|
|
69
|
+
return Promise.resolve(new NativeWorldState(dir, dbMapSizeKb, prefilledPublicData, instrumentation));
|
|
70
|
+
},
|
|
71
|
+
);
|
|
86
72
|
|
|
87
|
-
const instance =
|
|
73
|
+
const [instance] = await versionManager.open();
|
|
88
74
|
const worldState = new this(instance, instrumentation, log, cleanup);
|
|
89
75
|
try {
|
|
90
76
|
await worldState.init();
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export declare class WorldStateVersion {
|
|
4
|
-
readonly version: number;
|
|
5
|
-
readonly rollupAddress: EthAddress;
|
|
6
|
-
constructor(version: number, rollupAddress: EthAddress);
|
|
7
|
-
static readVersion(filename: string): Promise<WorldStateVersion | undefined>;
|
|
8
|
-
writeVersionFile(filename: string): Promise<void>;
|
|
9
|
-
static get schema(): z.ZodEffects<z.ZodObject<{
|
|
10
|
-
version: z.ZodNumber;
|
|
11
|
-
rollupAddress: z.ZodType<EthAddress, any, string>;
|
|
12
|
-
}, "strip", z.ZodTypeAny, {
|
|
13
|
-
version: number;
|
|
14
|
-
rollupAddress: EthAddress;
|
|
15
|
-
}, {
|
|
16
|
-
version: number;
|
|
17
|
-
rollupAddress: string;
|
|
18
|
-
}>, WorldStateVersion, {
|
|
19
|
-
version: number;
|
|
20
|
-
rollupAddress: string;
|
|
21
|
-
}>;
|
|
22
|
-
static empty(): WorldStateVersion;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=world_state_version.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"world_state_version.d.ts","sourceRoot":"","sources":["../../src/native/world_state_version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAK3D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,qBAAa,iBAAiB;aACA,OAAO,EAAE,MAAM;aAAkB,aAAa,EAAE,UAAU;gBAA1D,OAAO,EAAE,MAAM,EAAkB,aAAa,EAAE,UAAU;WAEzE,WAAW,CAAC,QAAQ,EAAE,MAAM;IAK5B,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAK9C,MAAM,KAAK,MAAM;;;;;;;;;;;;OAOhB;IAED,MAAM,CAAC,KAAK;CAGb"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
|
-
import { schemas } from '@aztec/foundation/schemas';
|
|
4
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
5
|
-
import { z } from 'zod';
|
|
6
|
-
export class WorldStateVersion {
|
|
7
|
-
version;
|
|
8
|
-
rollupAddress;
|
|
9
|
-
constructor(version, rollupAddress){
|
|
10
|
-
this.version = version;
|
|
11
|
-
this.rollupAddress = rollupAddress;
|
|
12
|
-
}
|
|
13
|
-
static async readVersion(filename) {
|
|
14
|
-
const versionData = await readFile(filename, 'utf-8').catch(()=>undefined);
|
|
15
|
-
return versionData === undefined ? undefined : await jsonParseWithSchema(versionData, WorldStateVersion.schema);
|
|
16
|
-
}
|
|
17
|
-
async writeVersionFile(filename) {
|
|
18
|
-
const data = jsonStringify(this);
|
|
19
|
-
await writeFile(filename, data, 'utf-8');
|
|
20
|
-
}
|
|
21
|
-
static get schema() {
|
|
22
|
-
return z.object({
|
|
23
|
-
version: z.number(),
|
|
24
|
-
rollupAddress: schemas.EthAddress
|
|
25
|
-
}).transform(({ version, rollupAddress })=>new WorldStateVersion(version, rollupAddress));
|
|
26
|
-
}
|
|
27
|
-
static empty() {
|
|
28
|
-
return new WorldStateVersion(0, EthAddress.ZERO);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
3
|
-
import { schemas } from '@aztec/foundation/schemas';
|
|
4
|
-
|
|
5
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
|
|
8
|
-
export class WorldStateVersion {
|
|
9
|
-
constructor(public readonly version: number, public readonly rollupAddress: EthAddress) {}
|
|
10
|
-
|
|
11
|
-
static async readVersion(filename: string) {
|
|
12
|
-
const versionData = await readFile(filename, 'utf-8').catch(() => undefined);
|
|
13
|
-
return versionData === undefined ? undefined : await jsonParseWithSchema(versionData, WorldStateVersion.schema);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async writeVersionFile(filename: string) {
|
|
17
|
-
const data = jsonStringify(this);
|
|
18
|
-
await writeFile(filename, data, 'utf-8');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static get schema() {
|
|
22
|
-
return z
|
|
23
|
-
.object({
|
|
24
|
-
version: z.number(),
|
|
25
|
-
rollupAddress: schemas.EthAddress,
|
|
26
|
-
})
|
|
27
|
-
.transform(({ version, rollupAddress }) => new WorldStateVersion(version, rollupAddress));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static empty() {
|
|
31
|
-
return new WorldStateVersion(0, EthAddress.ZERO);
|
|
32
|
-
}
|
|
33
|
-
}
|