@aztec/sequencer-client 0.0.1-commit.d3ec352c → 0.0.1-commit.e61ad554

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 (96) hide show
  1. package/dest/client/sequencer-client.d.ts +12 -12
  2. package/dest/client/sequencer-client.d.ts.map +1 -1
  3. package/dest/client/sequencer-client.js +32 -25
  4. package/dest/config.d.ts +12 -5
  5. package/dest/config.d.ts.map +1 -1
  6. package/dest/config.js +73 -30
  7. package/dest/global_variable_builder/global_builder.d.ts +21 -12
  8. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  9. package/dest/global_variable_builder/global_builder.js +51 -41
  10. package/dest/index.d.ts +2 -3
  11. package/dest/index.d.ts.map +1 -1
  12. package/dest/index.js +1 -2
  13. package/dest/publisher/config.d.ts +7 -4
  14. package/dest/publisher/config.d.ts.map +1 -1
  15. package/dest/publisher/config.js +9 -3
  16. package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
  17. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  18. package/dest/publisher/sequencer-publisher-factory.js +1 -1
  19. package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
  20. package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
  21. package/dest/publisher/sequencer-publisher-metrics.js +15 -86
  22. package/dest/publisher/sequencer-publisher.d.ts +48 -40
  23. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  24. package/dest/publisher/sequencer-publisher.js +564 -114
  25. package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
  26. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
  27. package/dest/sequencer/checkpoint_proposal_job.js +1165 -0
  28. package/dest/sequencer/checkpoint_voter.d.ts +35 -0
  29. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
  30. package/dest/sequencer/checkpoint_voter.js +109 -0
  31. package/dest/sequencer/config.d.ts +3 -2
  32. package/dest/sequencer/config.d.ts.map +1 -1
  33. package/dest/sequencer/events.d.ts +46 -0
  34. package/dest/sequencer/events.d.ts.map +1 -0
  35. package/dest/sequencer/events.js +1 -0
  36. package/dest/sequencer/index.d.ts +4 -2
  37. package/dest/sequencer/index.d.ts.map +1 -1
  38. package/dest/sequencer/index.js +3 -1
  39. package/dest/sequencer/metrics.d.ts +22 -2
  40. package/dest/sequencer/metrics.d.ts.map +1 -1
  41. package/dest/sequencer/metrics.js +125 -62
  42. package/dest/sequencer/sequencer.d.ts +107 -131
  43. package/dest/sequencer/sequencer.d.ts.map +1 -1
  44. package/dest/sequencer/sequencer.js +690 -602
  45. package/dest/sequencer/timetable.d.ts +54 -14
  46. package/dest/sequencer/timetable.d.ts.map +1 -1
  47. package/dest/sequencer/timetable.js +148 -59
  48. package/dest/sequencer/types.d.ts +3 -0
  49. package/dest/sequencer/types.d.ts.map +1 -0
  50. package/dest/sequencer/types.js +1 -0
  51. package/dest/sequencer/utils.d.ts +14 -8
  52. package/dest/sequencer/utils.d.ts.map +1 -1
  53. package/dest/sequencer/utils.js +7 -4
  54. package/dest/test/index.d.ts +4 -3
  55. package/dest/test/index.d.ts.map +1 -1
  56. package/dest/test/mock_checkpoint_builder.d.ts +95 -0
  57. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
  58. package/dest/test/mock_checkpoint_builder.js +222 -0
  59. package/dest/test/utils.d.ts +53 -0
  60. package/dest/test/utils.d.ts.map +1 -0
  61. package/dest/test/utils.js +103 -0
  62. package/package.json +30 -28
  63. package/src/client/sequencer-client.ts +30 -41
  64. package/src/config.ts +78 -34
  65. package/src/global_variable_builder/global_builder.ts +63 -59
  66. package/src/index.ts +1 -7
  67. package/src/publisher/config.ts +12 -9
  68. package/src/publisher/sequencer-publisher-factory.ts +5 -4
  69. package/src/publisher/sequencer-publisher-metrics.ts +16 -72
  70. package/src/publisher/sequencer-publisher.ts +262 -155
  71. package/src/sequencer/README.md +531 -0
  72. package/src/sequencer/checkpoint_proposal_job.ts +845 -0
  73. package/src/sequencer/checkpoint_voter.ts +130 -0
  74. package/src/sequencer/config.ts +2 -1
  75. package/src/sequencer/events.ts +27 -0
  76. package/src/sequencer/index.ts +3 -1
  77. package/src/sequencer/metrics.ts +164 -70
  78. package/src/sequencer/sequencer.ts +430 -804
  79. package/src/sequencer/timetable.ts +173 -79
  80. package/src/sequencer/types.ts +6 -0
  81. package/src/sequencer/utils.ts +18 -9
  82. package/src/test/index.ts +3 -2
  83. package/src/test/mock_checkpoint_builder.ts +311 -0
  84. package/src/test/utils.ts +164 -0
  85. package/dest/sequencer/block_builder.d.ts +0 -28
  86. package/dest/sequencer/block_builder.d.ts.map +0 -1
  87. package/dest/sequencer/block_builder.js +0 -134
  88. package/dest/tx_validator/nullifier_cache.d.ts +0 -14
  89. package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
  90. package/dest/tx_validator/nullifier_cache.js +0 -24
  91. package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
  92. package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
  93. package/dest/tx_validator/tx_validator_factory.js +0 -53
  94. package/src/sequencer/block_builder.ts +0 -222
  95. package/src/tx_validator/nullifier_cache.ts +0 -30
  96. package/src/tx_validator/tx_validator_factory.ts +0 -133
@@ -1,24 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/stdlib/trees';
2
- /**
3
- * Implements a nullifier source by checking a DB and an in-memory collection.
4
- * Intended for validating transactions as they are added to a block.
5
- */ export class NullifierCache {
6
- db;
7
- nullifiers;
8
- constructor(db){
9
- this.db = db;
10
- this.nullifiers = new Set();
11
- }
12
- async nullifiersExist(nullifiers) {
13
- const cacheResults = nullifiers.map((n)=>this.nullifiers.has(n.toString()));
14
- const toCheckDb = nullifiers.filter((_n, index)=>!cacheResults[index]);
15
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
16
- let dbIndex = 0;
17
- return nullifiers.map((_n, index)=>cacheResults[index] || dbHits[dbIndex++] !== undefined);
18
- }
19
- addNullifiers(nullifiers) {
20
- for (const nullifier of nullifiers){
21
- this.nullifiers.add(nullifier.toString());
22
- }
23
- }
24
- }
@@ -1,18 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import type { ContractDataSource } from '@aztec/stdlib/contract';
3
- import type { GasFees } from '@aztec/stdlib/gas';
4
- import type { AllowedElement, ClientProtocolCircuitVerifier, MerkleTreeReadOperations, PublicProcessorValidator } from '@aztec/stdlib/interfaces/server';
5
- import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
6
- import type { UInt64 } from '@aztec/stdlib/types';
7
- export declare function createValidatorForAcceptingTxs(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, verifier: ClientProtocolCircuitVerifier | undefined, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }: {
8
- l1ChainId: number;
9
- rollupVersion: number;
10
- setupAllowList: AllowedElement[];
11
- gasFees: GasFees;
12
- skipFeeEnforcement?: boolean;
13
- timestamp: UInt64;
14
- blockNumber: BlockNumber;
15
- txsPermitted: boolean;
16
- }): TxValidator<Tx>;
17
- export declare function createValidatorForBlockBuilding(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): PublicProcessorValidator;
18
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfdmFsaWRhdG9yX2ZhY3RvcnkuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90eF92YWxpZGF0b3IvdHhfdmFsaWRhdG9yX2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBaUI5RCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHdCQUF3Q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EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,eAAe,EAAE,eAAe,EAChC,cAAc,EAAE,cAAc,EAAE,GAC/B,wBAAwB,CAgB1B"}
@@ -1,53 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
3
- import { AggregateTxValidator, ArchiveCache, BlockHeaderTxValidator, DataTxValidator, DoubleSpendTxValidator, GasTxValidator, MetadataTxValidator, PhasesTxValidator, TimestampTxValidator, TxPermittedValidator, TxProofValidator } from '@aztec/p2p';
4
- import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
5
- import { DatabasePublicStateSource } from '@aztec/stdlib/trees';
6
- import { NullifierCache } from './nullifier_cache.js';
7
- export function createValidatorForAcceptingTxs(db, contractDataSource, verifier, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted }) {
8
- const validators = [
9
- new TxPermittedValidator(txsPermitted),
10
- new DataTxValidator(),
11
- new MetadataTxValidator({
12
- l1ChainId: new Fr(l1ChainId),
13
- rollupVersion: new Fr(rollupVersion),
14
- protocolContractsHash,
15
- vkTreeRoot: getVKTreeRoot()
16
- }),
17
- new TimestampTxValidator({
18
- timestamp,
19
- blockNumber
20
- }),
21
- new DoubleSpendTxValidator(new NullifierCache(db)),
22
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
23
- new BlockHeaderTxValidator(new ArchiveCache(db))
24
- ];
25
- if (!skipFeeEnforcement) {
26
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
27
- }
28
- if (verifier) {
29
- validators.push(new TxProofValidator(verifier));
30
- }
31
- return new AggregateTxValidator(...validators);
32
- }
33
- export function createValidatorForBlockBuilding(db, contractDataSource, globalVariables, setupAllowList) {
34
- const nullifierCache = new NullifierCache(db);
35
- const archiveCache = new ArchiveCache(db);
36
- const publicStateSource = new DatabasePublicStateSource(db);
37
- return {
38
- preprocessValidator: preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList),
39
- nullifierCache
40
- };
41
- }
42
- function preprocessValidator(nullifierCache, archiveCache, publicStateSource, contractDataSource, globalVariables, setupAllowList) {
43
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
44
- return new AggregateTxValidator(new MetadataTxValidator({
45
- l1ChainId: globalVariables.chainId,
46
- rollupVersion: globalVariables.version,
47
- protocolContractsHash,
48
- vkTreeRoot: getVKTreeRoot()
49
- }), new TimestampTxValidator({
50
- timestamp: globalVariables.timestamp,
51
- blockNumber: globalVariables.blockNumber
52
- }), new DoubleSpendTxValidator(nullifierCache), new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp), new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees), new BlockHeaderTxValidator(archiveCache));
53
- }
@@ -1,222 +0,0 @@
1
- import { MerkleTreeId } from '@aztec/aztec.js/trees';
2
- import { BlockNumber } from '@aztec/foundation/branded-types';
3
- import { merge, pick } from '@aztec/foundation/collection';
4
- import type { Fr } from '@aztec/foundation/fields';
5
- import { createLogger } from '@aztec/foundation/log';
6
- import { retryUntil } from '@aztec/foundation/retry';
7
- import { bufferToHex } from '@aztec/foundation/string';
8
- import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
9
- import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
10
- import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
11
- import {
12
- GuardedMerkleTreeOperations,
13
- PublicContractsDB,
14
- PublicProcessor,
15
- TelemetryCppPublicTxSimulator,
16
- } from '@aztec/simulator/server';
17
- import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
18
- import type { ContractDataSource } from '@aztec/stdlib/contract';
19
- import { type L1RollupConstants, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
20
- import { Gas } from '@aztec/stdlib/gas';
21
- import type {
22
- BuildBlockResult,
23
- FullNodeBlockBuilderConfig,
24
- IFullNodeBlockBuilder,
25
- MerkleTreeWriteOperations,
26
- PublicProcessorLimits,
27
- PublicProcessorValidator,
28
- WorldStateSynchronizer,
29
- } from '@aztec/stdlib/interfaces/server';
30
- import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
31
- import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
32
-
33
- import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
34
-
35
- const log = createLogger('block-builder');
36
-
37
- export async function buildBlock(
38
- pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
39
- l1ToL2Messages: Fr[],
40
- newGlobalVariables: GlobalVariables,
41
- opts: PublicProcessorLimits = {},
42
- worldStateFork: MerkleTreeWriteOperations,
43
- processor: PublicProcessor,
44
- validator: PublicProcessorValidator,
45
- l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>,
46
- dateProvider: DateProvider,
47
- telemetryClient: TelemetryClient = getTelemetryClient(),
48
- ): Promise<BuildBlockResult> {
49
- const blockBuildingTimer = new Timer();
50
- const blockNumber = newGlobalVariables.blockNumber;
51
- const slot = newGlobalVariables.slotNumber;
52
- const msgCount = l1ToL2Messages.length;
53
- const stateReference = await worldStateFork.getStateReference();
54
- const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
55
-
56
- log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
57
- slot,
58
- slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
59
- now: new Date(dateProvider.now()),
60
- blockNumber,
61
- msgCount,
62
- initialStateReference: stateReference.toInspect(),
63
- initialArchiveRoot: bufferToHex(archiveTree.root),
64
- opts,
65
- });
66
- const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
67
- await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
68
-
69
- const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
70
- processor.process(pendingTxs, opts, validator),
71
- );
72
-
73
- // All real transactions have been added, set the block as full and pad if needed
74
- await blockFactory.addTxs(processedTxs);
75
- const block = await blockFactory.setBlockCompleted();
76
-
77
- // How much public gas was processed
78
- const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
79
-
80
- const res = {
81
- block,
82
- publicGas,
83
- publicProcessorDuration,
84
- numMsgs: l1ToL2Messages.length,
85
- numTxs: processedTxs.length,
86
- failedTxs: failedTxs,
87
- blockBuildingTimer,
88
- usedTxs,
89
- };
90
- log.trace('Built block', res.block.header);
91
- return res;
92
- }
93
-
94
- const FullNodeBlockBuilderConfigKeys = [
95
- 'l1GenesisTime',
96
- 'slotDuration',
97
- 'l1ChainId',
98
- 'rollupVersion',
99
- 'txPublicSetupAllowList',
100
- 'fakeProcessingDelayPerTxMs',
101
- ] as const;
102
-
103
- export class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
104
- constructor(
105
- private config: FullNodeBlockBuilderConfig,
106
- private worldState: WorldStateSynchronizer,
107
- private contractDataSource: ContractDataSource,
108
- private dateProvider: DateProvider,
109
- private telemetryClient: TelemetryClient = getTelemetryClient(),
110
- ) {}
111
-
112
- public getConfig(): FullNodeBlockBuilderConfig {
113
- return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
114
- }
115
-
116
- public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
117
- this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
118
- }
119
-
120
- public async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
121
- const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
122
- const contractsDB = new PublicContractsDB(this.contractDataSource);
123
- const guardedFork = new GuardedMerkleTreeOperations(fork);
124
-
125
- const publicTxSimulator = new TelemetryCppPublicTxSimulator(
126
- guardedFork,
127
- contractsDB,
128
- globalVariables,
129
- this.telemetryClient,
130
- PublicSimulatorConfig.from({
131
- skipFeeEnforcement: false,
132
- collectDebugLogs: false,
133
- collectHints: false,
134
- collectStatistics: false,
135
- collectCallMetadata: false,
136
- }),
137
- );
138
-
139
- const processor = new PublicProcessor(
140
- globalVariables,
141
- guardedFork,
142
- contractsDB,
143
- publicTxSimulator,
144
- this.dateProvider,
145
- this.telemetryClient,
146
- undefined,
147
- this.config,
148
- );
149
-
150
- const validator = createValidatorForBlockBuilding(
151
- fork,
152
- this.contractDataSource,
153
- globalVariables,
154
- txPublicSetupAllowList,
155
- );
156
-
157
- return {
158
- processor,
159
- validator,
160
- };
161
- }
162
-
163
- private async syncToPreviousBlock(parentBlockNumber: BlockNumber, timeout: number | undefined) {
164
- await retryUntil(
165
- () => this.worldState.syncImmediate(parentBlockNumber, true).then(syncedTo => syncedTo >= parentBlockNumber),
166
- 'sync to previous block',
167
- timeout,
168
- 0.1,
169
- );
170
- log.debug(`Synced to previous block ${parentBlockNumber}`);
171
- }
172
-
173
- async buildBlock(
174
- pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
175
- l1ToL2Messages: Fr[],
176
- globalVariables: GlobalVariables,
177
- opts: PublicProcessorLimits,
178
- suppliedFork?: MerkleTreeWriteOperations,
179
- ): Promise<BuildBlockResult> {
180
- const parentBlockNumber = BlockNumber(globalVariables.blockNumber - 1);
181
- const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
182
- await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
183
- const fork = suppliedFork ?? (await this.worldState.fork(parentBlockNumber));
184
-
185
- try {
186
- const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
187
- const res = await buildBlock(
188
- pendingTxs,
189
- l1ToL2Messages,
190
- globalVariables,
191
- opts,
192
- fork,
193
- processor,
194
- validator,
195
- this.config,
196
- this.dateProvider,
197
- this.telemetryClient,
198
- );
199
- return res;
200
- } finally {
201
- // If the fork was supplied, we don't close it.
202
- // Otherwise, we wait a bit to close the fork we just created,
203
- // since the processor may still be working on a dangling tx
204
- // which was interrupted due to the processingDeadline being hit.
205
- if (!suppliedFork) {
206
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
207
- setTimeout(async () => {
208
- try {
209
- await fork.close();
210
- } catch (err) {
211
- // This can happen if the sequencer is stopped before we hit this timeout.
212
- log.warn(`Error closing forks for block processing`, err);
213
- }
214
- }, 5000);
215
- }
216
- }
217
- }
218
-
219
- getFork(blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
220
- return this.worldState.fork(blockNumber);
221
- }
222
- }
@@ -1,30 +0,0 @@
1
- import type { NullifierSource } from '@aztec/p2p';
2
- import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
3
- import { MerkleTreeId } from '@aztec/stdlib/trees';
4
-
5
- /**
6
- * Implements a nullifier source by checking a DB and an in-memory collection.
7
- * Intended for validating transactions as they are added to a block.
8
- */
9
- export class NullifierCache implements NullifierSource {
10
- nullifiers: Set<string>;
11
-
12
- constructor(private db: MerkleTreeReadOperations) {
13
- this.nullifiers = new Set();
14
- }
15
-
16
- public async nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]> {
17
- const cacheResults = nullifiers.map(n => this.nullifiers.has(n.toString()));
18
- const toCheckDb = nullifiers.filter((_n, index) => !cacheResults[index]);
19
- const dbHits = await this.db.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, toCheckDb);
20
-
21
- let dbIndex = 0;
22
- return nullifiers.map((_n, index) => cacheResults[index] || dbHits[dbIndex++] !== undefined);
23
- }
24
-
25
- public addNullifiers(nullifiers: Buffer[]) {
26
- for (const nullifier of nullifiers) {
27
- this.nullifiers.add(nullifier.toString());
28
- }
29
- }
30
- }
@@ -1,133 +0,0 @@
1
- import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
4
- import {
5
- AggregateTxValidator,
6
- ArchiveCache,
7
- BlockHeaderTxValidator,
8
- DataTxValidator,
9
- DoubleSpendTxValidator,
10
- GasTxValidator,
11
- MetadataTxValidator,
12
- PhasesTxValidator,
13
- TimestampTxValidator,
14
- TxPermittedValidator,
15
- TxProofValidator,
16
- } from '@aztec/p2p';
17
- import { ProtocolContractAddress, protocolContractsHash } from '@aztec/protocol-contracts';
18
- import type { ContractDataSource } from '@aztec/stdlib/contract';
19
- import type { GasFees } from '@aztec/stdlib/gas';
20
- import type {
21
- AllowedElement,
22
- ClientProtocolCircuitVerifier,
23
- MerkleTreeReadOperations,
24
- PublicProcessorValidator,
25
- } from '@aztec/stdlib/interfaces/server';
26
- import { DatabasePublicStateSource, type PublicStateSource } from '@aztec/stdlib/trees';
27
- import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
28
- import type { UInt64 } from '@aztec/stdlib/types';
29
-
30
- import { NullifierCache } from './nullifier_cache.js';
31
-
32
- export function createValidatorForAcceptingTxs(
33
- db: MerkleTreeReadOperations,
34
- contractDataSource: ContractDataSource,
35
- verifier: ClientProtocolCircuitVerifier | undefined,
36
- {
37
- l1ChainId,
38
- rollupVersion,
39
- setupAllowList,
40
- gasFees,
41
- skipFeeEnforcement,
42
- timestamp,
43
- blockNumber,
44
- txsPermitted,
45
- }: {
46
- l1ChainId: number;
47
- rollupVersion: number;
48
- setupAllowList: AllowedElement[];
49
- gasFees: GasFees;
50
- skipFeeEnforcement?: boolean;
51
- timestamp: UInt64;
52
- blockNumber: BlockNumber;
53
- txsPermitted: boolean;
54
- },
55
- ): TxValidator<Tx> {
56
- const validators: TxValidator<Tx>[] = [
57
- new TxPermittedValidator(txsPermitted),
58
- new DataTxValidator(),
59
- new MetadataTxValidator({
60
- l1ChainId: new Fr(l1ChainId),
61
- rollupVersion: new Fr(rollupVersion),
62
- protocolContractsHash,
63
- vkTreeRoot: getVKTreeRoot(),
64
- }),
65
- new TimestampTxValidator({
66
- timestamp,
67
- blockNumber,
68
- }),
69
- new DoubleSpendTxValidator(new NullifierCache(db)),
70
- new PhasesTxValidator(contractDataSource, setupAllowList, timestamp),
71
- new BlockHeaderTxValidator(new ArchiveCache(db)),
72
- ];
73
-
74
- if (!skipFeeEnforcement) {
75
- validators.push(new GasTxValidator(new DatabasePublicStateSource(db), ProtocolContractAddress.FeeJuice, gasFees));
76
- }
77
-
78
- if (verifier) {
79
- validators.push(new TxProofValidator(verifier));
80
- }
81
-
82
- return new AggregateTxValidator(...validators);
83
- }
84
-
85
- export function createValidatorForBlockBuilding(
86
- db: MerkleTreeReadOperations,
87
- contractDataSource: ContractDataSource,
88
- globalVariables: GlobalVariables,
89
- setupAllowList: AllowedElement[],
90
- ): PublicProcessorValidator {
91
- const nullifierCache = new NullifierCache(db);
92
- const archiveCache = new ArchiveCache(db);
93
- const publicStateSource = new DatabasePublicStateSource(db);
94
-
95
- return {
96
- preprocessValidator: preprocessValidator(
97
- nullifierCache,
98
- archiveCache,
99
- publicStateSource,
100
- contractDataSource,
101
- globalVariables,
102
- setupAllowList,
103
- ),
104
- nullifierCache,
105
- };
106
- }
107
-
108
- function preprocessValidator(
109
- nullifierCache: NullifierCache,
110
- archiveCache: ArchiveCache,
111
- publicStateSource: PublicStateSource,
112
- contractDataSource: ContractDataSource,
113
- globalVariables: GlobalVariables,
114
- setupAllowList: AllowedElement[],
115
- ): TxValidator<Tx> {
116
- // We don't include the TxProofValidator nor the DataTxValidator here because they are already checked by the time we get to block building.
117
- return new AggregateTxValidator(
118
- new MetadataTxValidator({
119
- l1ChainId: globalVariables.chainId,
120
- rollupVersion: globalVariables.version,
121
- protocolContractsHash,
122
- vkTreeRoot: getVKTreeRoot(),
123
- }),
124
- new TimestampTxValidator({
125
- timestamp: globalVariables.timestamp,
126
- blockNumber: globalVariables.blockNumber,
127
- }),
128
- new DoubleSpendTxValidator(nullifierCache),
129
- new PhasesTxValidator(contractDataSource, setupAllowList, globalVariables.timestamp),
130
- new GasTxValidator(publicStateSource, ProtocolContractAddress.FeeJuice, globalVariables.gasFees),
131
- new BlockHeaderTxValidator(archiveCache),
132
- );
133
- }