@aztec/stdlib 0.82.2 → 0.82.3-nightly.20250403
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/avm/avm.d.ts +4648 -1474
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm.js +182 -109
- package/dest/avm/avm_proving_request.d.ts +1867 -498
- package/dest/avm/avm_proving_request.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts +10 -12
- package/dest/block/l2_block_downloader/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_downloader/l2_block_stream.js +45 -11
- package/dest/config/config.d.ts +2 -2
- package/dest/config/config.d.ts.map +1 -1
- package/dest/config/config.js +4 -5
- package/dest/contract/interfaces/node-info.d.ts +2 -2
- package/dest/contract/interfaces/node-info.d.ts.map +1 -1
- package/dest/contract/interfaces/node-info.js +1 -1
- package/dest/database-version/version_manager.d.ts +4 -2
- package/dest/database-version/version_manager.d.ts.map +1 -1
- package/dest/database-version/version_manager.js +13 -9
- package/dest/epoch-helpers/index.d.ts +2 -0
- package/dest/epoch-helpers/index.d.ts.map +1 -1
- package/dest/epoch-helpers/index.js +3 -0
- package/dest/file-store/factory.d.ts +7 -0
- package/dest/file-store/factory.d.ts.map +1 -0
- package/dest/file-store/factory.js +46 -0
- package/dest/file-store/gcs.d.ts +22 -0
- package/dest/file-store/gcs.d.ts.map +1 -0
- package/dest/file-store/gcs.js +115 -0
- package/dest/file-store/http.d.ts +15 -0
- package/dest/file-store/http.d.ts.map +1 -0
- package/dest/file-store/http.js +53 -0
- package/dest/file-store/index.d.ts +3 -0
- package/dest/file-store/index.d.ts.map +1 -0
- package/dest/file-store/index.js +2 -0
- package/dest/file-store/interface.d.ts +24 -0
- package/dest/file-store/interface.d.ts.map +1 -0
- package/dest/file-store/interface.js +1 -0
- package/dest/file-store/local.d.ts +16 -0
- package/dest/file-store/local.d.ts.map +1 -0
- package/dest/file-store/local.js +40 -0
- package/dest/interfaces/aztec-node-admin.d.ts +9 -1
- package/dest/interfaces/aztec-node-admin.d.ts.map +1 -1
- package/dest/interfaces/aztec-node-admin.js +2 -1
- package/dest/interfaces/aztec-node.d.ts +3 -0
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +2 -0
- package/dest/interfaces/p2p.d.ts +2 -0
- package/dest/interfaces/p2p.d.ts.map +1 -1
- package/dest/interfaces/p2p.js +2 -1
- package/dest/interfaces/prover-client.d.ts +3 -3
- package/dest/interfaces/prover-client.d.ts.map +1 -1
- package/dest/interfaces/prover-client.js +6 -4
- package/dest/interfaces/prover-node.d.ts +4 -0
- package/dest/interfaces/prover-node.d.ts.map +1 -1
- package/dest/interfaces/prover-node.js +5 -1
- package/dest/interfaces/proving-job.d.ts +1866 -497
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/pxe.d.ts +7 -6
- package/dest/interfaces/pxe.d.ts.map +1 -1
- package/dest/interfaces/pxe.js +1 -1
- package/dest/interfaces/service.d.ts +3 -0
- package/dest/interfaces/service.d.ts.map +1 -1
- package/dest/interfaces/service.js +7 -0
- package/dest/interfaces/world_state.d.ts +13 -15
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/keys/derivation.d.ts +1 -1
- package/dest/keys/derivation.d.ts.map +1 -1
- package/dest/keys/derivation.js +10 -2
- package/dest/logs/index.d.ts +2 -1
- package/dest/logs/index.d.ts.map +1 -1
- package/dest/logs/index.js +2 -1
- package/dest/logs/pending_tagged_log.d.ts +17 -0
- package/dest/logs/pending_tagged_log.d.ts.map +1 -0
- package/dest/logs/pending_tagged_log.js +45 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.d.ts → shared_secret_derivation.d.ts} +4 -3
- package/dest/logs/shared_secret_derivation.d.ts.map +1 -0
- package/dest/logs/{l1_payload/shared_secret_derivation.js → shared_secret_derivation.js} +3 -5
- package/dest/logs/tx_scoped_l2_log.d.ts +6 -1
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +12 -4
- package/dest/note/note.d.ts +45 -4
- package/dest/note/note.d.ts.map +1 -1
- package/dest/note/note.js +51 -4
- package/dest/proofs/proof.d.ts.map +1 -1
- package/dest/proofs/proof.js +33 -7
- package/dest/snapshots/download.d.ts +9 -0
- package/dest/snapshots/download.d.ts.map +1 -0
- package/dest/snapshots/download.js +37 -0
- package/dest/snapshots/index.d.ts +4 -0
- package/dest/snapshots/index.d.ts.map +1 -0
- package/dest/snapshots/index.js +3 -0
- package/dest/snapshots/types.d.ts +97 -0
- package/dest/snapshots/types.d.ts.map +1 -0
- package/dest/snapshots/types.js +27 -0
- package/dest/snapshots/upload.d.ts +5 -0
- package/dest/snapshots/upload.d.ts.map +1 -0
- package/dest/snapshots/upload.js +37 -0
- package/dest/tests/factories.d.ts +21 -7
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +78 -30
- package/dest/tests/mocks.d.ts +2 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +5 -1
- package/dest/trees/merkle_tree_id.d.ts +8 -0
- package/dest/trees/merkle_tree_id.d.ts.map +1 -1
- package/dest/trees/merkle_tree_id.js +10 -0
- package/dest/trees/nullifier_leaf.d.ts +49 -15
- package/dest/trees/nullifier_leaf.d.ts.map +1 -1
- package/dest/trees/nullifier_leaf.js +45 -22
- package/dest/trees/nullifier_membership_witness.d.ts +34 -18
- package/dest/trees/nullifier_membership_witness.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.d.ts +0 -1
- package/dest/trees/protocol_contract_leaf.d.ts.map +1 -1
- package/dest/trees/protocol_contract_leaf.js +0 -3
- package/dest/trees/public_data_leaf.d.ts +59 -25
- package/dest/trees/public_data_leaf.d.ts.map +1 -1
- package/dest/trees/public_data_leaf.js +41 -30
- package/dest/trees/public_data_witness.d.ts +42 -24
- package/dest/trees/public_data_witness.d.ts.map +1 -1
- package/dest/trees/public_data_witness.js +6 -6
- package/dest/validators/index.d.ts +3 -0
- package/dest/validators/index.d.ts.map +1 -0
- package/dest/validators/index.js +1 -0
- package/dest/validators/schemas.d.ts +342 -0
- package/dest/validators/schemas.d.ts.map +1 -0
- package/dest/validators/schemas.js +40 -0
- package/dest/validators/types.d.ts +39 -0
- package/dest/validators/types.d.ts.map +1 -0
- package/dest/validators/types.js +1 -0
- package/dest/versioning/versioning.d.ts +1 -1
- package/dest/versioning/versioning.d.ts.map +1 -1
- package/dest/versioning/versioning.js +6 -6
- package/package.json +11 -8
- package/src/avm/avm.ts +183 -104
- package/src/block/l2_block_downloader/l2_block_stream.ts +64 -29
- package/src/config/config.ts +6 -6
- package/src/contract/interfaces/node-info.ts +3 -3
- package/src/database-version/version_manager.ts +12 -8
- package/src/epoch-helpers/index.ts +8 -0
- package/src/file-store/factory.ts +61 -0
- package/src/file-store/gcs.ts +121 -0
- package/src/file-store/http.ts +58 -0
- package/src/file-store/index.ts +2 -0
- package/src/file-store/interface.ts +19 -0
- package/src/file-store/local.ts +46 -0
- package/src/interfaces/aztec-node-admin.ts +11 -1
- package/src/interfaces/aztec-node.ts +7 -0
- package/src/interfaces/p2p.ts +4 -0
- package/src/interfaces/prover-client.ts +9 -7
- package/src/interfaces/prover-node.ts +10 -0
- package/src/interfaces/pxe.ts +14 -7
- package/src/interfaces/service.ts +13 -0
- package/src/interfaces/world_state.ts +17 -15
- package/src/keys/derivation.ts +12 -6
- package/src/logs/index.ts +2 -1
- package/src/logs/pending_tagged_log.ts +43 -0
- package/src/logs/{l1_payload/shared_secret_derivation.ts → shared_secret_derivation.ts} +4 -11
- package/src/logs/tx_scoped_l2_log.ts +13 -4
- package/src/note/note.ts +61 -5
- package/src/proofs/proof.ts +39 -5
- package/src/snapshots/download.ts +60 -0
- package/src/snapshots/index.ts +3 -0
- package/src/snapshots/types.ts +58 -0
- package/src/snapshots/upload.ts +55 -0
- package/src/tests/factories.ts +137 -53
- package/src/tests/mocks.ts +7 -0
- package/src/trees/merkle_tree_id.ts +12 -0
- package/src/trees/nullifier_leaf.ts +48 -21
- package/src/trees/protocol_contract_leaf.ts +0 -4
- package/src/trees/public_data_leaf.ts +40 -29
- package/src/trees/public_data_witness.ts +6 -6
- package/src/validators/index.ts +3 -0
- package/src/validators/schemas.ts +53 -0
- package/src/validators/types.ts +37 -0
- package/src/versioning/versioning.ts +8 -14
- package/dest/event/event.d.ts +0 -24
- package/dest/event/event.d.ts.map +0 -1
- package/dest/event/event.js +0 -13
- package/dest/event/event_metadata.d.ts +0 -38
- package/dest/event/event_metadata.d.ts.map +0 -1
- package/dest/event/event_metadata.js +0 -45
- package/dest/event/index.d.ts +0 -4
- package/dest/event/index.d.ts.map +0 -1
- package/dest/event/index.js +0 -3
- package/dest/event/l1_event_payload.d.ts +0 -52
- package/dest/event/l1_event_payload.d.ts.map +0 -1
- package/dest/event/l1_event_payload.js +0 -64
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts +0 -50
- package/dest/logs/l1_payload/encrypted_log_payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/encrypted_log_payload.js +0 -140
- package/dest/logs/l1_payload/encryption_util.d.ts +0 -24
- package/dest/logs/l1_payload/encryption_util.d.ts.map +0 -1
- package/dest/logs/l1_payload/encryption_util.js +0 -46
- package/dest/logs/l1_payload/index.d.ts +0 -3
- package/dest/logs/l1_payload/index.d.ts.map +0 -1
- package/dest/logs/l1_payload/index.js +0 -2
- package/dest/logs/l1_payload/payload.d.ts +0 -60
- package/dest/logs/l1_payload/payload.d.ts.map +0 -1
- package/dest/logs/l1_payload/payload.js +0 -61
- package/dest/logs/l1_payload/shared_secret_derivation.d.ts.map +0 -1
- package/src/event/event.ts +0 -16
- package/src/event/event_metadata.ts +0 -56
- package/src/event/index.ts +0 -3
- package/src/event/l1_event_payload.ts +0 -87
- package/src/logs/l1_payload/encrypted_log_payload.ts +0 -202
- package/src/logs/l1_payload/encryption_util.ts +0 -54
- package/src/logs/l1_payload/index.ts +0 -2
- package/src/logs/l1_payload/payload.ts +0 -73
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avm_proving_request.d.ts","sourceRoot":"","sources":["../../src/avm/avm_proving_request.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,uBAAuB
|
|
1
|
+
{"version":3,"file":"avm_proving_request.d.ts","sourceRoot":"","sources":["../../src/avm/avm_proving_request.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { L2BlockSource, L2Tips } from '../l2_block_source.js';
|
|
1
|
+
import type { L2BlockId, L2BlockSource, L2Tips } from '../l2_block_source.js';
|
|
2
2
|
import type { PublishedL2Block } from '../published_l2_block.js';
|
|
3
3
|
/** Creates a stream of events for new blocks, chain tips updates, and reorgs, out of polling an archiver or a node. */
|
|
4
4
|
export declare class L2BlockStream {
|
|
@@ -9,6 +9,7 @@ export declare class L2BlockStream {
|
|
|
9
9
|
private opts;
|
|
10
10
|
private readonly runningPromise;
|
|
11
11
|
private isSyncing;
|
|
12
|
+
private hasStarted;
|
|
12
13
|
constructor(l2BlockSource: Pick<L2BlockSource, 'getPublishedBlocks' | 'getBlockHeader' | 'getL2Tips'>, localData: L2BlockStreamLocalDataProvider, handler: L2BlockStreamEventHandler, log?: import("@aztec/foundation/log").Logger, opts?: {
|
|
13
14
|
proven?: boolean;
|
|
14
15
|
pollIntervalMS?: number;
|
|
@@ -26,6 +27,7 @@ export declare class L2BlockStream {
|
|
|
26
27
|
* @param args - A cache of data already requested from source, to avoid re-requesting it.
|
|
27
28
|
*/
|
|
28
29
|
private areBlockHashesEqualAt;
|
|
30
|
+
private getBlockHashFromSource;
|
|
29
31
|
private emitEvent;
|
|
30
32
|
}
|
|
31
33
|
/** Interface to the local view of the chain. Implemented by world-state and l2-tips-store. */
|
|
@@ -37,21 +39,17 @@ export interface L2BlockStreamLocalDataProvider {
|
|
|
37
39
|
export interface L2BlockStreamEventHandler {
|
|
38
40
|
handleBlockStreamEvent(event: L2BlockStreamEvent): Promise<void>;
|
|
39
41
|
}
|
|
40
|
-
export type L2BlockStreamEvent = {
|
|
42
|
+
export type L2BlockStreamEvent = /** Emits blocks added to the chain. */ {
|
|
41
43
|
type: 'blocks-added';
|
|
42
|
-
/** New blocks added to the chain. */
|
|
43
44
|
blocks: PublishedL2Block[];
|
|
44
|
-
} | {
|
|
45
|
+
} | /** Reports last correct block (new tip of the unproven chain). */ {
|
|
45
46
|
type: 'chain-pruned';
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} | {
|
|
47
|
+
block: L2BlockId;
|
|
48
|
+
} | /** Reports new proven block. */ {
|
|
49
49
|
type: 'chain-proven';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} | {
|
|
50
|
+
block: L2BlockId;
|
|
51
|
+
} | /** Reports new finalized block (proven and finalized on L1). */ {
|
|
53
52
|
type: 'chain-finalized';
|
|
54
|
-
|
|
55
|
-
blockNumber: number;
|
|
53
|
+
block: L2BlockId;
|
|
56
54
|
};
|
|
57
55
|
//# sourceMappingURL=l2_block_stream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"l2_block_stream.d.ts","sourceRoot":"","sources":["../../../src/block/l2_block_downloader/l2_block_stream.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"l2_block_stream.d.ts","sourceRoot":"","sources":["../../../src/block/l2_block_downloader/l2_block_stream.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,u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,CAAC;CAClB,GACD,gCAAgC,CAAC;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,SAAS,CAAC;CAClB,GACD,gEAAgE,CAAC;IAC/D,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC"}
|
|
@@ -9,6 +9,7 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
9
9
|
opts;
|
|
10
10
|
runningPromise;
|
|
11
11
|
isSyncing;
|
|
12
|
+
hasStarted;
|
|
12
13
|
constructor(l2BlockSource, localData, handler, log = createLogger('types:block_stream'), opts = {}){
|
|
13
14
|
this.l2BlockSource = l2BlockSource;
|
|
14
15
|
this.localData = localData;
|
|
@@ -16,6 +17,7 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
16
17
|
this.log = log;
|
|
17
18
|
this.opts = opts;
|
|
18
19
|
this.isSyncing = false;
|
|
20
|
+
this.hasStarted = false;
|
|
19
21
|
this.runningPromise = new RunningPromise(()=>this.work(), log, this.opts.pollIntervalMS ?? 1000);
|
|
20
22
|
}
|
|
21
23
|
start() {
|
|
@@ -53,10 +55,11 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
53
55
|
});
|
|
54
56
|
// Check if there was a reorg and emit a chain-pruned event if so.
|
|
55
57
|
let latestBlockNumber = localTips.latest.number;
|
|
58
|
+
const sourceCache = new BlockHashCache([
|
|
59
|
+
sourceTips.latest
|
|
60
|
+
]);
|
|
56
61
|
while(!await this.areBlockHashesEqualAt(latestBlockNumber, {
|
|
57
|
-
sourceCache
|
|
58
|
-
sourceTips.latest
|
|
59
|
-
]
|
|
62
|
+
sourceCache
|
|
60
63
|
})){
|
|
61
64
|
latestBlockNumber--;
|
|
62
65
|
}
|
|
@@ -64,13 +67,20 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
64
67
|
this.log.verbose(`Reorg detected. Pruning blocks from ${latestBlockNumber + 1} to ${localTips.latest.number}.`);
|
|
65
68
|
await this.emitEvent({
|
|
66
69
|
type: 'chain-pruned',
|
|
67
|
-
|
|
70
|
+
block: {
|
|
71
|
+
number: latestBlockNumber,
|
|
72
|
+
hash: sourceCache.get(latestBlockNumber) ?? await this.getBlockHashFromSource(latestBlockNumber)
|
|
73
|
+
}
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
// If we are just starting, use the starting block number from the options.
|
|
71
77
|
if (latestBlockNumber === 0 && this.opts.startingBlock !== undefined) {
|
|
72
78
|
latestBlockNumber = Math.max(this.opts.startingBlock - 1, 0);
|
|
79
|
+
}
|
|
80
|
+
// Only log this entry once (for sanity)
|
|
81
|
+
if (!this.hasStarted) {
|
|
73
82
|
this.log.verbose(`Starting sync from block number ${latestBlockNumber}`);
|
|
83
|
+
this.hasStarted = true;
|
|
74
84
|
}
|
|
75
85
|
// Request new blocks from the source.
|
|
76
86
|
while(latestBlockNumber < sourceTips.latest.number){
|
|
@@ -91,13 +101,13 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
91
101
|
if (localTips.proven !== undefined && sourceTips.proven.number !== localTips.proven.number) {
|
|
92
102
|
await this.emitEvent({
|
|
93
103
|
type: 'chain-proven',
|
|
94
|
-
|
|
104
|
+
block: sourceTips.proven
|
|
95
105
|
});
|
|
96
106
|
}
|
|
97
107
|
if (localTips.finalized !== undefined && sourceTips.finalized.number !== localTips.finalized.number) {
|
|
98
108
|
await this.emitEvent({
|
|
99
109
|
type: 'chain-finalized',
|
|
100
|
-
|
|
110
|
+
block: sourceTips.finalized
|
|
101
111
|
});
|
|
102
112
|
}
|
|
103
113
|
} catch (err) {
|
|
@@ -116,20 +126,44 @@ import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
|
116
126
|
return true;
|
|
117
127
|
}
|
|
118
128
|
const localBlockHash = await this.localData.getL2BlockHash(blockNumber);
|
|
119
|
-
const
|
|
129
|
+
const sourceBlockHashFromCache = args.sourceCache.get(blockNumber);
|
|
130
|
+
const sourceBlockHash = args.sourceCache.get(blockNumber) ?? await this.getBlockHashFromSource(blockNumber);
|
|
131
|
+
if (!sourceBlockHashFromCache && sourceBlockHash) {
|
|
132
|
+
args.sourceCache.add({
|
|
133
|
+
number: blockNumber,
|
|
134
|
+
hash: sourceBlockHash
|
|
135
|
+
});
|
|
136
|
+
}
|
|
120
137
|
this.log.trace(`Comparing block hashes for block ${blockNumber}`, {
|
|
121
138
|
localBlockHash,
|
|
122
|
-
sourceBlockHash
|
|
123
|
-
sourceCacheNumber: args.sourceCache[0]?.number,
|
|
124
|
-
sourceCacheHash: args.sourceCache[0]?.hash
|
|
139
|
+
sourceBlockHash
|
|
125
140
|
});
|
|
126
141
|
return localBlockHash === sourceBlockHash;
|
|
127
142
|
}
|
|
143
|
+
getBlockHashFromSource(blockNumber) {
|
|
144
|
+
return this.l2BlockSource.getBlockHeader(blockNumber).then((h)=>h?.hash()).then((hash)=>hash?.toString());
|
|
145
|
+
}
|
|
128
146
|
async emitEvent(event) {
|
|
129
|
-
this.log.debug(`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.
|
|
147
|
+
this.log.debug(`Emitting ${event.type} (${event.type === 'blocks-added' ? event.blocks.length : event.block.number})`);
|
|
130
148
|
await this.handler.handleBlockStreamEvent(event);
|
|
131
149
|
if (!this.isRunning() && !this.isSyncing) {
|
|
132
150
|
throw new AbortError();
|
|
133
151
|
}
|
|
134
152
|
}
|
|
135
153
|
}
|
|
154
|
+
class BlockHashCache {
|
|
155
|
+
cache = new Map();
|
|
156
|
+
constructor(initial = []){
|
|
157
|
+
for (const block of initial){
|
|
158
|
+
this.add(block);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
add(block) {
|
|
162
|
+
if (block.hash) {
|
|
163
|
+
this.cache.set(block.number, block.hash);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
get(blockNumber) {
|
|
167
|
+
return this.cache.get(blockNumber);
|
|
168
|
+
}
|
|
169
|
+
}
|
package/dest/config/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
export { type AllowedElement, type SequencerConfig, SequencerConfigSchema } from '../interfaces/configs.js';
|
|
4
4
|
export declare const emptyChainConfig: ChainConfig;
|
|
@@ -8,7 +8,7 @@ export type ChainConfig = {
|
|
|
8
8
|
/** The chain id of the ethereum host. */
|
|
9
9
|
l1ChainId: number;
|
|
10
10
|
/** The version of the rollup. */
|
|
11
|
-
|
|
11
|
+
rollupVersion: number;
|
|
12
12
|
/** The address to the L1 contracts. */
|
|
13
13
|
l1Contracts: {
|
|
14
14
|
/** The address to rollup */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAE5G,eAAO,MAAM,gBAAgB,EAAE,WAI9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,kBAAkB,CAAC,WAAW,CAgB/D,CAAC;AAEF,2BAA2B;AAC3B,MAAM,MAAM,WAAW,GAAG;IACxB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,uCAAuC;IACvC,WAAW,EAAE;QACX,4BAA4B;QAC5B,aAAa,EAAE,UAAU,CAAC;KAC3B,CAAC;CACH,CAAC"}
|
package/dest/config/config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { l1ContractAddressesMapping } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import { numberConfigHelper } from '@aztec/foundation/config';
|
|
3
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
3
|
export { SequencerConfigSchema } from '../interfaces/configs.js';
|
|
5
4
|
export const emptyChainConfig = {
|
|
@@ -7,7 +6,7 @@ export const emptyChainConfig = {
|
|
|
7
6
|
l1Contracts: {
|
|
8
7
|
rollupAddress: EthAddress.ZERO
|
|
9
8
|
},
|
|
10
|
-
|
|
9
|
+
rollupVersion: 0
|
|
11
10
|
};
|
|
12
11
|
export const chainConfigMappings = {
|
|
13
12
|
l1ChainId: {
|
|
@@ -16,10 +15,10 @@ export const chainConfigMappings = {
|
|
|
16
15
|
defaultValue: 31337,
|
|
17
16
|
description: 'The chain ID of the ethereum host.'
|
|
18
17
|
},
|
|
19
|
-
|
|
20
|
-
env: '
|
|
18
|
+
rollupVersion: {
|
|
19
|
+
env: 'ROLLUP_VERSION',
|
|
21
20
|
description: 'The version of the rollup.',
|
|
22
|
-
|
|
21
|
+
parseEnv: (val)=>Number.isSafeInteger(parseInt(val, 10)) ? parseInt(val, 10) : undefined
|
|
23
22
|
},
|
|
24
23
|
l1Contracts: {
|
|
25
24
|
description: 'The deployed L1 contract addresses',
|
|
@@ -7,8 +7,8 @@ export interface NodeInfo {
|
|
|
7
7
|
nodeVersion: string;
|
|
8
8
|
/** L1 chain id. */
|
|
9
9
|
l1ChainId: number;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/** Rollup version. */
|
|
11
|
+
rollupVersion: number;
|
|
12
12
|
/** The node's ENR. */
|
|
13
13
|
enr: string | undefined;
|
|
14
14
|
/** The deployed l1 contract addresses */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-info.d.ts","sourceRoot":"","sources":["../../../src/contract/interfaces/node-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAA6B,MAAM,uCAAuC,CAAC;AAC5G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAIxD,OAAO,EAAE,KAAK,yBAAyB,EAAmC,MAAM,kCAAkC,CAAC;AAEnH,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"node-info.d.ts","sourceRoot":"","sources":["../../../src/contract/interfaces/node-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAA6B,MAAM,uCAAuC,CAAC;AAC5G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAIxD,OAAO,EAAE,KAAK,yBAAyB,EAAmC,MAAM,kCAAkC,CAAC;AAEnH,yDAAyD;AACzD,MAAM,WAAW,QAAQ;IACvB,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,sBAAsB;IACtB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,yCAAyC;IACzC,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,kCAAkC;IAClC,yBAAyB,EAAE,yBAAyB,CAAC;CACtD;AAED,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,QAAQ,CASK,CAAC"}
|
|
@@ -4,7 +4,7 @@ import { ProtocolContractAddressesSchema } from './protocol_contract_addresses.j
|
|
|
4
4
|
export const NodeInfoSchema = z.object({
|
|
5
5
|
nodeVersion: z.string(),
|
|
6
6
|
l1ChainId: z.number().int().nonnegative(),
|
|
7
|
-
|
|
7
|
+
rollupVersion: z.number().int().nonnegative(),
|
|
8
8
|
enr: z.string().optional(),
|
|
9
9
|
l1ContractAddresses: L1ContractAddressesSchema,
|
|
10
10
|
protocolContractAddresses: ProtocolContractAddressesSchema
|
|
@@ -48,6 +48,7 @@ export declare class DatabaseVersion {
|
|
|
48
48
|
static empty(): DatabaseVersion;
|
|
49
49
|
}
|
|
50
50
|
export type DatabaseVersionManagerFs = Pick<typeof fs, 'readFile' | 'writeFile' | 'rm' | 'mkdir'>;
|
|
51
|
+
export declare const DATABASE_VERSION_FILE_NAME = "db_version";
|
|
51
52
|
/**
|
|
52
53
|
* A manager for handling database versioning and migrations.
|
|
53
54
|
* This class will check the version of data in a directory and either
|
|
@@ -75,6 +76,7 @@ export declare class DatabaseVersionManager<T> {
|
|
|
75
76
|
* @param options - Configuration options
|
|
76
77
|
*/
|
|
77
78
|
constructor(schemaVersion: number, rollupAddress: EthAddress, dataDirectory: string, onOpen: (dataDir: string) => Promise<T>, onUpgrade?: ((dataDir: string, currentVersion: number, latestVersion: number) => Promise<void>) | undefined, fileSystem?: DatabaseVersionManagerFs, log?: import("@aztec/foundation/log").Logger);
|
|
79
|
+
static writeVersion(version: DatabaseVersion, dataDir: string, fileSystem?: DatabaseVersionManagerFs): Promise<void>;
|
|
78
80
|
/**
|
|
79
81
|
* Checks the stored version against the current version and handles the outcome
|
|
80
82
|
* by either resetting the data directory or calling an upgrade function
|
|
@@ -87,11 +89,11 @@ export declare class DatabaseVersionManager<T> {
|
|
|
87
89
|
/**
|
|
88
90
|
* Writes the current version to the version file
|
|
89
91
|
*/
|
|
90
|
-
|
|
92
|
+
writeVersion(dir?: string): Promise<void>;
|
|
91
93
|
/**
|
|
92
94
|
* Resets the data directory by deleting it and recreating it
|
|
93
95
|
*/
|
|
94
|
-
|
|
96
|
+
resetDataDirectory(): Promise<void>;
|
|
95
97
|
/**
|
|
96
98
|
* Get the data directory path
|
|
97
99
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version_manager.d.ts","sourceRoot":"","sources":["../../src/database-version/version_manager.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,qBAAa,eAAe;aACE,aAAa,EAAE,MAAM;aAAkB,aAAa,EAAE,UAAU;gBAAhE,aAAa,EAAE,MAAM,EAAkB,aAAa,EAAE,UAAU;IAErF,QAAQ,IAAI,MAAM;WAIX,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe;IAQtD;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAa1D;;OAEG;IACI,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO;IAI9C;;OAEG;IACH,MAAM,KAAK,MAAM;;;;;;;;;;;;OAOhB;IAED,uCAAuC;IAChC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM;IAI1B,QAAQ,IAAI,MAAM;IAIzB;;OAEG;IACH,MAAM,CAAC,KAAK;CAGb;AAED,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC;AAElG;;;;GAIG;AACH,qBAAa,sBAAsB,CAAC,CAAC;IAqBjC,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,GAAG;IAxBb,gBAAuB,YAAY,
|
|
1
|
+
{"version":3,"file":"version_manager.d.ts","sourceRoot":"","sources":["../../src/database-version/version_manager.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAI3D,OAAO,EAAE,M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,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACvC,SAAS,CAAC,aAAY,MAAM,kBAAkB,MAAM,iBAAiB,MAAM,KAAK,QAAQ,IAAI,CAAC,aAAA,EAC7F,UAAU,GAAE,wBAA6B,EACzC,GAAG,yCAA6C;WAU7C,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,wBAA6B;IAK9G;;;;;;;OAOG;IACU,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAmD1C;;OAEG;IACI,YAAY,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD;;OAEG;IACU,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAUhD;;OAEG;IACI,gBAAgB,IAAI,MAAM;IAIjC;;OAEG;IACI,gBAAgB,IAAI,MAAM;CAGlC"}
|
|
@@ -65,6 +65,7 @@ import { z } from 'zod';
|
|
|
65
65
|
return new DatabaseVersion(0, EthAddress.ZERO);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
export const DATABASE_VERSION_FILE_NAME = 'db_version';
|
|
68
69
|
/**
|
|
69
70
|
* A manager for handling database versioning and migrations.
|
|
70
71
|
* This class will check the version of data in a directory and either
|
|
@@ -75,7 +76,7 @@ import { z } from 'zod';
|
|
|
75
76
|
onUpgrade;
|
|
76
77
|
fileSystem;
|
|
77
78
|
log;
|
|
78
|
-
static VERSION_FILE =
|
|
79
|
+
static VERSION_FILE = DATABASE_VERSION_FILE_NAME;
|
|
79
80
|
versionFile;
|
|
80
81
|
currentVersion;
|
|
81
82
|
/**
|
|
@@ -101,6 +102,12 @@ import { z } from 'zod';
|
|
|
101
102
|
this.versionFile = join(this.dataDirectory, DatabaseVersionManager.VERSION_FILE);
|
|
102
103
|
this.currentVersion = new DatabaseVersion(schemaVersion, rollupAddress);
|
|
103
104
|
}
|
|
105
|
+
static async writeVersion(version, dataDir, fileSystem = fs) {
|
|
106
|
+
await fileSystem.mkdir(dataDir, {
|
|
107
|
+
recursive: true
|
|
108
|
+
});
|
|
109
|
+
return fileSystem.writeFile(join(dataDir, DatabaseVersionManager.VERSION_FILE), version.toBuffer());
|
|
110
|
+
}
|
|
104
111
|
/**
|
|
105
112
|
* Checks the stored version against the current version and handles the outcome
|
|
106
113
|
* by either resetting the data directory or calling an upgrade function
|
|
@@ -139,7 +146,9 @@ import { z } from 'zod';
|
|
|
139
146
|
needsReset = true;
|
|
140
147
|
}
|
|
141
148
|
} else {
|
|
142
|
-
this.log.warn('Rollup address changed, resetting data directory'
|
|
149
|
+
this.log.warn('Rollup address changed, resetting data directory', {
|
|
150
|
+
versionFile: this.versionFile
|
|
151
|
+
});
|
|
143
152
|
needsReset = true;
|
|
144
153
|
}
|
|
145
154
|
// Handle reset if needed
|
|
@@ -155,13 +164,8 @@ import { z } from 'zod';
|
|
|
155
164
|
}
|
|
156
165
|
/**
|
|
157
166
|
* Writes the current version to the version file
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
await this.fileSystem.mkdir(this.dataDirectory, {
|
|
161
|
-
recursive: true
|
|
162
|
-
});
|
|
163
|
-
// Write the version file
|
|
164
|
-
await this.fileSystem.writeFile(this.versionFile, this.currentVersion.toBuffer());
|
|
167
|
+
*/ writeVersion(dir) {
|
|
168
|
+
return DatabaseVersionManager.writeVersion(this.currentVersion, dir ?? this.dataDirectory, this.fileSystem);
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
171
|
* Resets the data directory by deleting it and recreating it
|
|
@@ -26,6 +26,8 @@ export declare const L1RollupConstantsSchema: z.ZodObject<{
|
|
|
26
26
|
epochDuration: number;
|
|
27
27
|
ethereumSlotDuration: number;
|
|
28
28
|
}>;
|
|
29
|
+
/** Returns the timestamp for a given L2 slot. */
|
|
30
|
+
export declare function getTimestampForSlot(slot: bigint, constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>): bigint;
|
|
29
31
|
/** Returns the slot number for a given timestamp. */
|
|
30
32
|
export declare function getSlotAtTimestamp(ts: bigint, constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>): bigint;
|
|
31
33
|
/** Returns the epoch number for a given timestamp. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/epoch-helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,iBAMpC,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;EAME,CAAC;AAEvC,qDAAqD;AACrD,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,UAElH;AAED,sDAAsD;AACtD,wBAAgB,yBAAyB,CACvC,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,GAAG,eAAe,CAAC,UAGvF;AAED,iDAAiD;AACjD,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,UAE/F;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,CAAC,YAG5G;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,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B,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,GAAG,eAAe,GAAG,sBAAsB,CAAC,YAUhH"}
|
|
@@ -14,6 +14,9 @@ export const L1RollupConstantsSchema = z.object({
|
|
|
14
14
|
epochDuration: z.number(),
|
|
15
15
|
ethereumSlotDuration: z.number()
|
|
16
16
|
});
|
|
17
|
+
/** Returns the timestamp for a given L2 slot. */ export function getTimestampForSlot(slot, constants) {
|
|
18
|
+
return constants.l1GenesisTime + slot * BigInt(constants.slotDuration);
|
|
19
|
+
}
|
|
17
20
|
/** Returns the slot number for a given timestamp. */ export function getSlotAtTimestamp(ts, constants) {
|
|
18
21
|
return ts < constants.l1GenesisTime ? 0n : (ts - constants.l1GenesisTime) / BigInt(constants.slotDuration);
|
|
19
22
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
2
|
+
import type { FileStore, ReadOnlyFileStore } from './interface.js';
|
|
3
|
+
export declare function createFileStore(config: string, logger?: Logger): Promise<FileStore>;
|
|
4
|
+
export declare function createFileStore(config: undefined, logger?: Logger): Promise<undefined>;
|
|
5
|
+
export declare function createReadOnlyFileStore(config: string, logger?: Logger): Promise<ReadOnlyFileStore>;
|
|
6
|
+
export declare function createReadOnlyFileStore(config: undefined, logger?: Logger): Promise<undefined>;
|
|
7
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/file-store/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAIlE,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AASnE,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAC3F,wBAAsB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAgC9F,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC3G,wBAAsB,uBAAuB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { GoogleCloudFileStore } from './gcs.js';
|
|
3
|
+
import { HttpFileStore } from './http.js';
|
|
4
|
+
import { LocalFileStore } from './local.js';
|
|
5
|
+
const supportedExamples = [
|
|
6
|
+
`gs://bucket-name/path/to/store`,
|
|
7
|
+
`file:///absolute/local/path/to/store`,
|
|
8
|
+
`https://host/path`
|
|
9
|
+
];
|
|
10
|
+
export async function createFileStore(config, logger = createLogger('stdlib:file-store')) {
|
|
11
|
+
if (config === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
} else if (config.startsWith('file://')) {
|
|
14
|
+
const url = new URL(config);
|
|
15
|
+
if (url.host) {
|
|
16
|
+
throw new Error(`File store URL only supports local paths (got host ${url.host} from ${config})`);
|
|
17
|
+
}
|
|
18
|
+
const path = url.pathname;
|
|
19
|
+
logger.info(`Creating local file file store at ${path}`);
|
|
20
|
+
return new LocalFileStore(path);
|
|
21
|
+
} else if (config.startsWith('gs://')) {
|
|
22
|
+
try {
|
|
23
|
+
const url = new URL(config);
|
|
24
|
+
const bucket = url.host;
|
|
25
|
+
const path = url.pathname.replace(/^\/+/, '');
|
|
26
|
+
logger.info(`Creating google cloud file store at ${bucket} ${path}`);
|
|
27
|
+
const store = new GoogleCloudFileStore(bucket, path);
|
|
28
|
+
await store.checkCredentials();
|
|
29
|
+
return store;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
throw new Error(`Invalid google cloud store definition: '${config}'.`);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error(`Unknown file store config: '${config}'. Supported values are ${supportedExamples.join(', ')}.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function createReadOnlyFileStore(config, logger = createLogger('stdlib:file-store')) {
|
|
38
|
+
if (config === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
} else if (config.startsWith('http://') || config.startsWith('https://')) {
|
|
41
|
+
logger.info(`Creating read-only HTTP file store at ${config}`);
|
|
42
|
+
return new HttpFileStore(config, logger);
|
|
43
|
+
} else {
|
|
44
|
+
return await createFileStore(config, logger);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { FileStore, FileStoreSaveOptions } from './interface.js';
|
|
5
|
+
export declare class GoogleCloudFileStore implements FileStore {
|
|
6
|
+
private readonly bucketName;
|
|
7
|
+
private readonly basePath;
|
|
8
|
+
private readonly log;
|
|
9
|
+
private readonly storage;
|
|
10
|
+
constructor(bucketName: string, basePath: string, log?: Logger);
|
|
11
|
+
checkCredentials(): Promise<void>;
|
|
12
|
+
save(path: string, data: Buffer, opts?: FileStoreSaveOptions): Promise<string>;
|
|
13
|
+
upload(destPath: string, srcPath: string, opts?: FileStoreSaveOptions): Promise<string>;
|
|
14
|
+
private handleUploadedFile;
|
|
15
|
+
read(pathOrUrlStr: string): Promise<Buffer>;
|
|
16
|
+
download(pathOrUrlStr: string, destPath: string): Promise<void>;
|
|
17
|
+
exists(pathOrUrlStr: string): Promise<boolean>;
|
|
18
|
+
private getFileObject;
|
|
19
|
+
private getBucketAndFullPath;
|
|
20
|
+
private getFullPath;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=gcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gcs.d.ts","sourceRoot":"","sources":["../../src/file-store/gcs.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAKlE,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtE,qBAAa,oBAAqB,YAAW,SAAS;IAIlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;gBAGf,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,GAAG,GAAE,MAA8C;IAKzD,gBAAgB;IAIhB,IAAI,CACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,oBAAuE,GAC5E,OAAO,CAAC,MAAM,CAAC;IAYL,MAAM,CACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,oBAAsE,GAC3E,OAAO,CAAC,MAAM,CAAC;YAiBJ,kBAAkB;IAmBnB,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM3C,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/D,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAQ7C,aAAa;IAU3B,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
+
import { Storage } from '@google-cloud/storage';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
export class GoogleCloudFileStore {
|
|
5
|
+
bucketName;
|
|
6
|
+
basePath;
|
|
7
|
+
log;
|
|
8
|
+
storage;
|
|
9
|
+
constructor(bucketName, basePath, log = createLogger('stdlib:gcs-file-store')){
|
|
10
|
+
this.bucketName = bucketName;
|
|
11
|
+
this.basePath = basePath;
|
|
12
|
+
this.log = log;
|
|
13
|
+
this.storage = new Storage();
|
|
14
|
+
}
|
|
15
|
+
async checkCredentials() {
|
|
16
|
+
await this.storage.getServiceAccount();
|
|
17
|
+
}
|
|
18
|
+
async save(path, data, opts = {
|
|
19
|
+
public: false,
|
|
20
|
+
metadata: {},
|
|
21
|
+
compress: false
|
|
22
|
+
}) {
|
|
23
|
+
const fullPath = this.getFullPath(path);
|
|
24
|
+
try {
|
|
25
|
+
const bucket = this.storage.bucket(this.bucketName);
|
|
26
|
+
const file = bucket.file(fullPath);
|
|
27
|
+
await file.save(data, {
|
|
28
|
+
metadata: opts.metadata,
|
|
29
|
+
gzip: opts.compress
|
|
30
|
+
});
|
|
31
|
+
return this.handleUploadedFile(file, opts);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
throw new Error(`Error saving file to google cloud storage at ${fullPath}: ${err.message ?? err}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async upload(destPath, srcPath, opts = {
|
|
37
|
+
compress: true,
|
|
38
|
+
public: false,
|
|
39
|
+
metadata: {}
|
|
40
|
+
}) {
|
|
41
|
+
const fullPath = this.getFullPath(destPath);
|
|
42
|
+
try {
|
|
43
|
+
const bucket = this.storage.bucket(this.bucketName);
|
|
44
|
+
const file = bucket.file(fullPath);
|
|
45
|
+
const uploadOpts = {
|
|
46
|
+
destination: file,
|
|
47
|
+
gzip: opts.compress,
|
|
48
|
+
metadata: opts.metadata
|
|
49
|
+
};
|
|
50
|
+
await bucket.upload(srcPath, uploadOpts);
|
|
51
|
+
return this.handleUploadedFile(file, opts);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
throw new Error(`Error saving file to google cloud storage at ${fullPath}: ${err.message ?? err}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async handleUploadedFile(file, opts) {
|
|
57
|
+
if (opts.public) {
|
|
58
|
+
try {
|
|
59
|
+
if (!await file.isPublic()) {
|
|
60
|
+
await file.makePublic();
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
this.log.warn(`Error making file ${file.name} public: ${err.message ?? err}. This is expected if we handle public access at the bucket level.`);
|
|
64
|
+
}
|
|
65
|
+
return file.publicUrl().replaceAll('%2F', '/');
|
|
66
|
+
} else {
|
|
67
|
+
return file.cloudStorageURI.toString();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async read(pathOrUrlStr) {
|
|
71
|
+
const file = await this.getFileObject(pathOrUrlStr);
|
|
72
|
+
const contents = await file.download();
|
|
73
|
+
return contents[0];
|
|
74
|
+
}
|
|
75
|
+
async download(pathOrUrlStr, destPath) {
|
|
76
|
+
const file = await this.getFileObject(pathOrUrlStr);
|
|
77
|
+
await file.download({
|
|
78
|
+
destination: destPath
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async exists(pathOrUrlStr) {
|
|
82
|
+
const { bucketName, fullPath } = this.getBucketAndFullPath(pathOrUrlStr);
|
|
83
|
+
const bucket = this.storage.bucket(bucketName);
|
|
84
|
+
const file = bucket.file(fullPath);
|
|
85
|
+
const [exists] = await file.exists();
|
|
86
|
+
return exists;
|
|
87
|
+
}
|
|
88
|
+
async getFileObject(pathOrUrlStr) {
|
|
89
|
+
const { bucketName, fullPath } = this.getBucketAndFullPath(pathOrUrlStr);
|
|
90
|
+
const bucket = this.storage.bucket(bucketName);
|
|
91
|
+
const file = bucket.file(fullPath);
|
|
92
|
+
if (!await file.exists()) {
|
|
93
|
+
throw new Error(`File at ${fullPath} in gcs bucket ${bucketName} does not exist`);
|
|
94
|
+
}
|
|
95
|
+
return file;
|
|
96
|
+
}
|
|
97
|
+
getBucketAndFullPath(pathOrUrlStr) {
|
|
98
|
+
if (URL.canParse(pathOrUrlStr)) {
|
|
99
|
+
const url = new URL(pathOrUrlStr);
|
|
100
|
+
// Note that we accept reading from anywhere, not just our bucket
|
|
101
|
+
return {
|
|
102
|
+
fullPath: url.pathname.replace(/^\/+/, ''),
|
|
103
|
+
bucketName: url.host
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
return {
|
|
107
|
+
fullPath: this.getFullPath(pathOrUrlStr),
|
|
108
|
+
bucketName: this.bucketName
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
getFullPath(path) {
|
|
113
|
+
return this.basePath && this.basePath.length > 0 ? join(this.basePath, path) : path;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { type Logger } from '@aztec/foundation/log';
|
|
4
|
+
import type { ReadOnlyFileStore } from './interface.js';
|
|
5
|
+
export declare class HttpFileStore implements ReadOnlyFileStore {
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
private readonly log;
|
|
8
|
+
private readonly fetch;
|
|
9
|
+
constructor(baseUrl: string, log?: Logger);
|
|
10
|
+
read(pathOrUrl: string): Promise<Buffer>;
|
|
11
|
+
download(pathOrUrl: string, destPath: string): Promise<void>;
|
|
12
|
+
exists(pathOrUrl: string): Promise<boolean>;
|
|
13
|
+
private getUrl;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/file-store/http.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AASlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,aAAc,YAAW,iBAAiB;IAGzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFlE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAER,OAAO,EAAE,MAAM,EAAmB,GAAG,GAAE,MAA+C;IAYtG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5D,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAMxD,OAAO,CAAC,MAAM;CAGf"}
|