@aztec/sequencer-client 0.0.1-commit.b655e406 → 0.0.1-commit.d1f2d6c
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/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +12 -12
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +32 -24
- package/dest/config.d.ts +12 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +80 -28
- package/dest/global_variable_builder/global_builder.d.ts +22 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +52 -39
- package/dest/global_variable_builder/index.d.ts +1 -1
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +9 -4
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +14 -3
- package/dest/publisher/index.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-factory.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +15 -86
- package/dest/publisher/sequencer-publisher.d.ts +75 -61
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +661 -158
- package/dest/sequencer/checkpoint_proposal_job.d.ts +79 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1164 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +32 -3
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +147 -46
- package/dest/sequencer/sequencer.d.ts +110 -142
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +716 -504
- package/dest/sequencer/timetable.d.ts +54 -14
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +148 -59
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +4 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +92 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +208 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +103 -0
- package/package.json +33 -30
- package/src/client/sequencer-client.ts +30 -41
- package/src/config.ts +86 -32
- package/src/global_variable_builder/global_builder.ts +67 -59
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +20 -9
- package/src/publisher/sequencer-publisher-factory.ts +7 -5
- package/src/publisher/sequencer-publisher-metrics.ts +16 -72
- package/src/publisher/sequencer-publisher.ts +381 -203
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +843 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +198 -55
- package/src/sequencer/sequencer.ts +465 -696
- package/src/sequencer/timetable.ts +173 -79
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +3 -2
- package/src/test/mock_checkpoint_builder.ts +295 -0
- package/src/test/utils.ts +164 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -130
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -218
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
5
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
6
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
7
|
+
import type {
|
|
8
|
+
BuildBlockInCheckpointResult,
|
|
9
|
+
FullNodeBlockBuilderConfig,
|
|
10
|
+
ICheckpointBlockBuilder,
|
|
11
|
+
ICheckpointsBuilder,
|
|
12
|
+
MerkleTreeWriteOperations,
|
|
13
|
+
PublicProcessorLimits,
|
|
14
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
15
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
16
|
+
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
17
|
+
import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A fake CheckpointBuilder for testing that implements the same interface as the real one.
|
|
21
|
+
* Can be seeded with blocks to return sequentially on each `buildBlock` call.
|
|
22
|
+
*/
|
|
23
|
+
export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
24
|
+
private blocks: L2Block[] = [];
|
|
25
|
+
private builtBlocks: L2Block[] = [];
|
|
26
|
+
private usedTxsPerBlock: Tx[][] = [];
|
|
27
|
+
private blockIndex = 0;
|
|
28
|
+
|
|
29
|
+
/** Optional function to dynamically provide the block (alternative to seedBlocks) */
|
|
30
|
+
private blockProvider: (() => L2Block) | undefined = undefined;
|
|
31
|
+
|
|
32
|
+
/** Track calls for assertions */
|
|
33
|
+
public buildBlockCalls: Array<{
|
|
34
|
+
blockNumber: BlockNumber;
|
|
35
|
+
timestamp: bigint;
|
|
36
|
+
opts: PublicProcessorLimits;
|
|
37
|
+
}> = [];
|
|
38
|
+
public completeCheckpointCalled = false;
|
|
39
|
+
public getCheckpointCalled = false;
|
|
40
|
+
|
|
41
|
+
/** Set to an error to make buildBlock throw on next call */
|
|
42
|
+
public errorOnBuild: Error | undefined = undefined;
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
private readonly constants: CheckpointGlobalVariables,
|
|
46
|
+
private readonly checkpointNumber: CheckpointNumber,
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
/** Seed the builder with blocks to return on successive buildBlock calls */
|
|
50
|
+
seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
|
|
51
|
+
this.blocks = blocks;
|
|
52
|
+
this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
|
|
53
|
+
this.blockIndex = 0;
|
|
54
|
+
this.blockProvider = undefined;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set a function that provides blocks dynamically.
|
|
60
|
+
* Useful for tests where the block is determined at call time (e.g., sequencer tests).
|
|
61
|
+
*/
|
|
62
|
+
setBlockProvider(provider: () => L2Block): this {
|
|
63
|
+
this.blockProvider = provider;
|
|
64
|
+
this.blocks = [];
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getConstantData(): CheckpointGlobalVariables {
|
|
69
|
+
return this.constants;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
buildBlock(
|
|
73
|
+
_pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
74
|
+
blockNumber: BlockNumber,
|
|
75
|
+
timestamp: bigint,
|
|
76
|
+
opts: PublicProcessorLimits,
|
|
77
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
78
|
+
this.buildBlockCalls.push({ blockNumber, timestamp, opts });
|
|
79
|
+
|
|
80
|
+
if (this.errorOnBuild) {
|
|
81
|
+
return Promise.reject(this.errorOnBuild);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let block: L2Block;
|
|
85
|
+
let usedTxs: Tx[];
|
|
86
|
+
|
|
87
|
+
if (this.blockProvider) {
|
|
88
|
+
// Dynamic mode: get block from provider
|
|
89
|
+
block = this.blockProvider();
|
|
90
|
+
usedTxs = [];
|
|
91
|
+
this.builtBlocks.push(block);
|
|
92
|
+
} else {
|
|
93
|
+
// Seeded mode: get block from pre-seeded list
|
|
94
|
+
block = this.blocks[this.blockIndex];
|
|
95
|
+
usedTxs = this.usedTxsPerBlock[this.blockIndex] ?? [];
|
|
96
|
+
this.blockIndex++;
|
|
97
|
+
this.builtBlocks.push(block);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return Promise.resolve({
|
|
101
|
+
block,
|
|
102
|
+
publicGas: Gas.empty(),
|
|
103
|
+
publicProcessorDuration: 0,
|
|
104
|
+
numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
|
|
105
|
+
blockBuildingTimer: new Timer(),
|
|
106
|
+
usedTxs,
|
|
107
|
+
failedTxs: [],
|
|
108
|
+
usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
completeCheckpoint(): Promise<Checkpoint> {
|
|
113
|
+
this.completeCheckpointCalled = true;
|
|
114
|
+
const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
|
|
115
|
+
const lastBlock = allBlocks[allBlocks.length - 1];
|
|
116
|
+
// Create a CheckpointHeader from the last block's header for testing
|
|
117
|
+
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
118
|
+
return Promise.resolve(
|
|
119
|
+
new Checkpoint(
|
|
120
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
121
|
+
checkpointHeader,
|
|
122
|
+
allBlocks,
|
|
123
|
+
this.checkpointNumber,
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getCheckpoint(): Promise<Checkpoint> {
|
|
129
|
+
this.getCheckpointCalled = true;
|
|
130
|
+
const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
|
|
131
|
+
const lastBlock = builtBlocks[builtBlocks.length - 1];
|
|
132
|
+
if (!lastBlock) {
|
|
133
|
+
throw new Error('No blocks built yet');
|
|
134
|
+
}
|
|
135
|
+
// Create a CheckpointHeader from the last block's header for testing
|
|
136
|
+
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
137
|
+
return Promise.resolve(
|
|
138
|
+
new Checkpoint(
|
|
139
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
140
|
+
checkpointHeader,
|
|
141
|
+
builtBlocks,
|
|
142
|
+
this.checkpointNumber,
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Creates a CheckpointHeader from a block's header for testing.
|
|
149
|
+
* This is a simplified version that creates a minimal CheckpointHeader.
|
|
150
|
+
*/
|
|
151
|
+
private createCheckpointHeader(block: L2Block): CheckpointHeader {
|
|
152
|
+
const header = block.header;
|
|
153
|
+
const gv = header.globalVariables;
|
|
154
|
+
return CheckpointHeader.empty({
|
|
155
|
+
lastArchiveRoot: header.lastArchive.root,
|
|
156
|
+
blockHeadersHash: Fr.random(), // Use random for testing
|
|
157
|
+
slotNumber: gv.slotNumber,
|
|
158
|
+
timestamp: gv.timestamp,
|
|
159
|
+
coinbase: gv.coinbase,
|
|
160
|
+
feeRecipient: gv.feeRecipient,
|
|
161
|
+
gasFees: gv.gasFees,
|
|
162
|
+
totalManaUsed: header.totalManaUsed,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Reset for reuse in another test */
|
|
167
|
+
reset(): void {
|
|
168
|
+
this.blocks = [];
|
|
169
|
+
this.builtBlocks = [];
|
|
170
|
+
this.usedTxsPerBlock = [];
|
|
171
|
+
this.blockIndex = 0;
|
|
172
|
+
this.buildBlockCalls = [];
|
|
173
|
+
this.completeCheckpointCalled = false;
|
|
174
|
+
this.getCheckpointCalled = false;
|
|
175
|
+
this.errorOnBuild = undefined;
|
|
176
|
+
this.blockProvider = undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A fake CheckpointsBuilder (factory) for testing that implements the same interface
|
|
182
|
+
* as FullNodeCheckpointsBuilder. Returns MockCheckpointBuilder instances.
|
|
183
|
+
* Does NOT use jest mocks - this is a proper test double.
|
|
184
|
+
*/
|
|
185
|
+
export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
186
|
+
private checkpointBuilder: MockCheckpointBuilder | undefined;
|
|
187
|
+
|
|
188
|
+
/** Track calls for assertions */
|
|
189
|
+
public startCheckpointCalls: Array<{
|
|
190
|
+
checkpointNumber: CheckpointNumber;
|
|
191
|
+
constants: CheckpointGlobalVariables;
|
|
192
|
+
l1ToL2Messages: Fr[];
|
|
193
|
+
previousCheckpointOutHashes: Fr[];
|
|
194
|
+
}> = [];
|
|
195
|
+
public openCheckpointCalls: Array<{
|
|
196
|
+
checkpointNumber: CheckpointNumber;
|
|
197
|
+
constants: CheckpointGlobalVariables;
|
|
198
|
+
l1ToL2Messages: Fr[];
|
|
199
|
+
previousCheckpointOutHashes: Fr[];
|
|
200
|
+
existingBlocks: L2Block[];
|
|
201
|
+
}> = [];
|
|
202
|
+
public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Set the MockCheckpointBuilder to return from startCheckpoint.
|
|
206
|
+
* Must be called before startCheckpoint is invoked.
|
|
207
|
+
*/
|
|
208
|
+
setCheckpointBuilder(builder: MockCheckpointBuilder): this {
|
|
209
|
+
this.checkpointBuilder = builder;
|
|
210
|
+
return this;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Creates a new MockCheckpointBuilder with the given constants.
|
|
215
|
+
* Convenience method that creates and sets the builder in one call.
|
|
216
|
+
*/
|
|
217
|
+
createCheckpointBuilder(
|
|
218
|
+
constants: CheckpointGlobalVariables,
|
|
219
|
+
checkpointNumber: CheckpointNumber,
|
|
220
|
+
): MockCheckpointBuilder {
|
|
221
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
222
|
+
return this.checkpointBuilder;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Get the current checkpoint builder (for assertions) */
|
|
226
|
+
getCheckpointBuilder(): MockCheckpointBuilder | undefined {
|
|
227
|
+
return this.checkpointBuilder;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
getConfig(): FullNodeBlockBuilderConfig {
|
|
231
|
+
return {
|
|
232
|
+
l1GenesisTime: 0n,
|
|
233
|
+
slotDuration: 24,
|
|
234
|
+
l1ChainId: 1,
|
|
235
|
+
rollupVersion: 1,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void {
|
|
240
|
+
this.updateConfigCalls.push(config);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
startCheckpoint(
|
|
244
|
+
checkpointNumber: CheckpointNumber,
|
|
245
|
+
constants: CheckpointGlobalVariables,
|
|
246
|
+
l1ToL2Messages: Fr[],
|
|
247
|
+
previousCheckpointOutHashes: Fr[],
|
|
248
|
+
_fork: MerkleTreeWriteOperations,
|
|
249
|
+
): Promise<ICheckpointBlockBuilder> {
|
|
250
|
+
this.startCheckpointCalls.push({ checkpointNumber, constants, l1ToL2Messages, previousCheckpointOutHashes });
|
|
251
|
+
|
|
252
|
+
if (!this.checkpointBuilder) {
|
|
253
|
+
// Auto-create a builder if none was set
|
|
254
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return Promise.resolve(this.checkpointBuilder);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
openCheckpoint(
|
|
261
|
+
checkpointNumber: CheckpointNumber,
|
|
262
|
+
constants: CheckpointGlobalVariables,
|
|
263
|
+
l1ToL2Messages: Fr[],
|
|
264
|
+
previousCheckpointOutHashes: Fr[],
|
|
265
|
+
_fork: MerkleTreeWriteOperations,
|
|
266
|
+
existingBlocks: L2Block[] = [],
|
|
267
|
+
): Promise<ICheckpointBlockBuilder> {
|
|
268
|
+
this.openCheckpointCalls.push({
|
|
269
|
+
checkpointNumber,
|
|
270
|
+
constants,
|
|
271
|
+
l1ToL2Messages,
|
|
272
|
+
previousCheckpointOutHashes,
|
|
273
|
+
existingBlocks,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (!this.checkpointBuilder) {
|
|
277
|
+
// Auto-create a builder if none was set
|
|
278
|
+
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return Promise.resolve(this.checkpointBuilder);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
getFork(_blockNumber: BlockNumber): Promise<MerkleTreeWriteOperations> {
|
|
285
|
+
throw new Error('MockCheckpointsBuilder.getFork not implemented');
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Reset for reuse in another test */
|
|
289
|
+
reset(): void {
|
|
290
|
+
this.checkpointBuilder = undefined;
|
|
291
|
+
this.startCheckpointCalls = [];
|
|
292
|
+
this.openCheckpointCalls = [];
|
|
293
|
+
this.updateConfigCalls = [];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Body } from '@aztec/aztec.js/block';
|
|
2
|
+
import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { times } from '@aztec/foundation/collection';
|
|
4
|
+
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import type { P2P } from '@aztec/p2p';
|
|
9
|
+
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
|
+
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
|
+
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
+
import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
|
|
14
|
+
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
15
|
+
|
|
16
|
+
import type { MockProxy } from 'jest-mock-extended';
|
|
17
|
+
|
|
18
|
+
// Re-export mock classes from their dedicated file
|
|
19
|
+
export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates a mock transaction with a specific seed for deterministic testing
|
|
23
|
+
*/
|
|
24
|
+
export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
|
|
25
|
+
const tx = await mockTxForRollup(seed);
|
|
26
|
+
if (chainId) {
|
|
27
|
+
tx.data.constants.txContext.chainId = chainId;
|
|
28
|
+
}
|
|
29
|
+
return tx;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates an L2Block from transactions and global variables
|
|
34
|
+
*/
|
|
35
|
+
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
|
|
36
|
+
const processedTxs = await Promise.all(
|
|
37
|
+
txs.map(tx =>
|
|
38
|
+
makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
const body = new Body(processedTxs.map(tx => tx.txEffect));
|
|
42
|
+
const header = BlockHeader.empty({ globalVariables });
|
|
43
|
+
const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
|
|
44
|
+
return new L2Block(
|
|
45
|
+
archive,
|
|
46
|
+
header,
|
|
47
|
+
body,
|
|
48
|
+
CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
|
|
49
|
+
IndexWithinCheckpoint(0),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Mocks the P2P client to return specific pending transactions
|
|
55
|
+
*/
|
|
56
|
+
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
57
|
+
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
58
|
+
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Creates an async iterator for transactions
|
|
63
|
+
*/
|
|
64
|
+
export async function* mockTxIterator(txs: Promise<Tx[]>): AsyncIterableIterator<Tx> {
|
|
65
|
+
for (const tx of await txs) {
|
|
66
|
+
yield tx;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Creates mock committee attestations from a signer
|
|
72
|
+
*/
|
|
73
|
+
export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestation[] {
|
|
74
|
+
const mockedSig = Signature.random();
|
|
75
|
+
return [new CommitteeAttestation(signer.address, mockedSig)];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Creates a CheckpointHeader from an L2Block for testing purposes.
|
|
80
|
+
* Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
|
|
81
|
+
*/
|
|
82
|
+
function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
|
|
83
|
+
const gv = block.header.globalVariables;
|
|
84
|
+
return new CheckpointHeader(
|
|
85
|
+
block.header.lastArchive.root,
|
|
86
|
+
Fr.random(), // blockHeadersHash - mock value for testing
|
|
87
|
+
Fr.random(), // blobsHash - mock value for testing
|
|
88
|
+
Fr.random(), // inHash - mock value for testing
|
|
89
|
+
Fr.random(), // outHash - mock value for testing
|
|
90
|
+
gv.slotNumber,
|
|
91
|
+
gv.timestamp,
|
|
92
|
+
gv.coinbase,
|
|
93
|
+
gv.feeRecipient,
|
|
94
|
+
gv.gasFees,
|
|
95
|
+
block.header.totalManaUsed,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Creates a block proposal from a block and signature
|
|
101
|
+
*/
|
|
102
|
+
export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
|
|
103
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
104
|
+
return new BlockProposal(
|
|
105
|
+
block.header,
|
|
106
|
+
block.indexWithinCheckpoint,
|
|
107
|
+
Fr.ZERO, // inHash - using zero for testing
|
|
108
|
+
block.archive.root,
|
|
109
|
+
txHashes,
|
|
110
|
+
signature,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates a checkpoint proposal from a block and signature
|
|
116
|
+
*/
|
|
117
|
+
export function createCheckpointProposal(
|
|
118
|
+
block: L2Block,
|
|
119
|
+
checkpointSignature: Signature,
|
|
120
|
+
blockSignature?: Signature,
|
|
121
|
+
): CheckpointProposal {
|
|
122
|
+
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
123
|
+
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
124
|
+
return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
|
|
125
|
+
blockHeader: block.header,
|
|
126
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
127
|
+
txHashes,
|
|
128
|
+
signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates a checkpoint attestation from a block and signature.
|
|
134
|
+
* Note: We manually set the sender since we use random signatures in tests.
|
|
135
|
+
* In production, the sender is recovered from the signature.
|
|
136
|
+
*/
|
|
137
|
+
export function createCheckpointAttestation(
|
|
138
|
+
block: L2Block,
|
|
139
|
+
signature: Signature,
|
|
140
|
+
sender: EthAddress,
|
|
141
|
+
): CheckpointAttestation {
|
|
142
|
+
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
143
|
+
const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
|
|
144
|
+
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
145
|
+
// Set sender directly for testing (bypasses signature recovery)
|
|
146
|
+
(attestation as any).sender = sender;
|
|
147
|
+
return attestation;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Creates transactions and a block, and mocks P2P to return them.
|
|
152
|
+
* Helper for tests that need to set up a block with transactions.
|
|
153
|
+
*/
|
|
154
|
+
export async function setupTxsAndBlock(
|
|
155
|
+
p2p: MockProxy<P2P>,
|
|
156
|
+
globalVariables: GlobalVariables,
|
|
157
|
+
txCount: number,
|
|
158
|
+
chainId: Fr,
|
|
159
|
+
): Promise<{ txs: Tx[]; block: L2Block }> {
|
|
160
|
+
const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
|
|
161
|
+
const block = await makeBlock(txs, globalVariables);
|
|
162
|
+
mockPendingTxs(p2p, txs);
|
|
163
|
+
return { txs, block };
|
|
164
|
+
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
3
|
-
import { PublicProcessor } from '@aztec/simulator/server';
|
|
4
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
5
|
-
import { type L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
6
|
-
import type { BuildBlockResult, FullNodeBlockBuilderConfig, IFullNodeBlockBuilder, MerkleTreeWriteOperations, PublicProcessorLimits, PublicProcessorValidator, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
7
|
-
import { GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
8
|
-
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
9
|
-
export declare function buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], newGlobalVariables: GlobalVariables, opts: PublicProcessorLimits | undefined, worldStateFork: MerkleTreeWriteOperations, processor: PublicProcessor, validator: PublicProcessorValidator, l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration'>, dateProvider: DateProvider, telemetryClient?: TelemetryClient): Promise<BuildBlockResult>;
|
|
10
|
-
export declare class FullNodeBlockBuilder implements IFullNodeBlockBuilder {
|
|
11
|
-
private config;
|
|
12
|
-
private worldState;
|
|
13
|
-
private contractDataSource;
|
|
14
|
-
private dateProvider;
|
|
15
|
-
private telemetryClient;
|
|
16
|
-
constructor(config: FullNodeBlockBuilderConfig, worldState: WorldStateSynchronizer, contractDataSource: ContractDataSource, dateProvider: DateProvider, telemetryClient?: TelemetryClient);
|
|
17
|
-
getConfig(): FullNodeBlockBuilderConfig;
|
|
18
|
-
updateConfig(config: Partial<FullNodeBlockBuilderConfig>): void;
|
|
19
|
-
makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations): Promise<{
|
|
20
|
-
processor: PublicProcessor;
|
|
21
|
-
validator: PublicProcessorValidator;
|
|
22
|
-
}>;
|
|
23
|
-
private syncToPreviousBlock;
|
|
24
|
-
buildBlock(pendingTxs: Iterable<Tx> | AsyncIterable<Tx>, l1ToL2Messages: Fr[], globalVariables: GlobalVariables, opts: PublicProcessorLimits, suppliedFork?: MerkleTreeWriteOperations): Promise<BuildBlockResult>;
|
|
25
|
-
getFork(blockNumber: number): Promise<MerkleTreeWriteOperations>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=block_builder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"block_builder.d.ts","sourceRoot":"","sources":["../../src/sequencer/block_builder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAInD,OAAO,EAAE,YAAY,EAAkB,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAGL,eAAe,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,KAAK,iBAAiB,EAAuB,MAAM,6BAA6B,CAAC;AAE1F,OAAO,KAAK,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,KAAK,eAAe,EAAsB,MAAM,yBAAyB,CAAC;AAMnF,wBAAsB,UAAU,CAC9B,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,kBAAkB,EAAE,eAAe,EACnC,IAAI,EAAE,qBAAqB,YAAK,EAChC,cAAc,EAAE,yBAAyB,EACzC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,wBAAwB,EACnC,WAAW,EAAE,IAAI,CAAC,iBAAiB,EAAE,eAAe,GAAG,cAAc,CAAC,EACtE,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC,GACtD,OAAO,CAAC,gBAAgB,CAAC,CA4C3B;AAWD,qBAAa,oBAAqB,YAAW,qBAAqB;IAE9D,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,kBAAkB;IAC1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBAJf,MAAM,EAAE,0BAA0B,EAClC,UAAU,EAAE,sBAAsB,EAClC,kBAAkB,EAAE,kBAAkB,EACtC,YAAY,EAAE,YAAY,EAC1B,eAAe,GAAE,eAAsC;IAG1D,SAAS,IAAI,0BAA0B;IAIvC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,0BAA0B,CAAC;IAIlD,oBAAoB,CAAC,eAAe,EAAE,eAAe,EAAE,IAAI,EAAE,yBAAyB;;;;YAyCrF,mBAAmB;IAU3B,UAAU,CACd,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,EAC5C,cAAc,EAAE,EAAE,EAAE,EACpB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,qBAAqB,EAC3B,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,gBAAgB,CAAC;IAwC5B,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAGjE"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
-
import { merge, pick } from '@aztec/foundation/collection';
|
|
3
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { retryUntil } from '@aztec/foundation/retry';
|
|
5
|
-
import { bufferToHex } from '@aztec/foundation/string';
|
|
6
|
-
import { Timer, elapsed } from '@aztec/foundation/timer';
|
|
7
|
-
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
8
|
-
import { LightweightBlockFactory } from '@aztec/prover-client/block-factory';
|
|
9
|
-
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor, TelemetryPublicTxSimulator } from '@aztec/simulator/server';
|
|
10
|
-
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
11
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
12
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
13
|
-
import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
|
|
14
|
-
const log = createLogger('block-builder');
|
|
15
|
-
export async function buildBlock(pendingTxs, l1ToL2Messages, newGlobalVariables, opts = {}, worldStateFork, processor, validator, l1Constants, dateProvider, telemetryClient = getTelemetryClient()) {
|
|
16
|
-
const blockBuildingTimer = new Timer();
|
|
17
|
-
const blockNumber = newGlobalVariables.blockNumber;
|
|
18
|
-
const slot = newGlobalVariables.slotNumber.toBigInt();
|
|
19
|
-
const msgCount = l1ToL2Messages.length;
|
|
20
|
-
const stateReference = await worldStateFork.getStateReference();
|
|
21
|
-
const archiveTree = await worldStateFork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
22
|
-
log.verbose(`Building block ${blockNumber} for slot ${slot}`, {
|
|
23
|
-
slot,
|
|
24
|
-
slotStart: new Date(Number(getTimestampForSlot(slot, l1Constants)) * 1000),
|
|
25
|
-
now: new Date(dateProvider.now()),
|
|
26
|
-
blockNumber,
|
|
27
|
-
msgCount,
|
|
28
|
-
initialStateReference: stateReference.toInspect(),
|
|
29
|
-
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
30
|
-
opts
|
|
31
|
-
});
|
|
32
|
-
const blockFactory = new LightweightBlockFactory(worldStateFork, telemetryClient);
|
|
33
|
-
await blockFactory.startNewBlock(newGlobalVariables, l1ToL2Messages);
|
|
34
|
-
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(()=>processor.process(pendingTxs, opts, validator));
|
|
35
|
-
// All real transactions have been added, set the block as full and pad if needed
|
|
36
|
-
await blockFactory.addTxs(processedTxs);
|
|
37
|
-
const block = await blockFactory.setBlockCompleted();
|
|
38
|
-
// How much public gas was processed
|
|
39
|
-
const publicGas = processedTxs.reduce((acc, tx)=>acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
40
|
-
const res = {
|
|
41
|
-
block,
|
|
42
|
-
publicGas,
|
|
43
|
-
publicProcessorDuration,
|
|
44
|
-
numMsgs: l1ToL2Messages.length,
|
|
45
|
-
numTxs: processedTxs.length,
|
|
46
|
-
failedTxs: failedTxs,
|
|
47
|
-
blockBuildingTimer,
|
|
48
|
-
usedTxs
|
|
49
|
-
};
|
|
50
|
-
log.trace('Built block', res.block.header);
|
|
51
|
-
return res;
|
|
52
|
-
}
|
|
53
|
-
const FullNodeBlockBuilderConfigKeys = [
|
|
54
|
-
'l1GenesisTime',
|
|
55
|
-
'slotDuration',
|
|
56
|
-
'l1ChainId',
|
|
57
|
-
'rollupVersion',
|
|
58
|
-
'txPublicSetupAllowList',
|
|
59
|
-
'fakeProcessingDelayPerTxMs'
|
|
60
|
-
];
|
|
61
|
-
export class FullNodeBlockBuilder {
|
|
62
|
-
config;
|
|
63
|
-
worldState;
|
|
64
|
-
contractDataSource;
|
|
65
|
-
dateProvider;
|
|
66
|
-
telemetryClient;
|
|
67
|
-
constructor(config, worldState, contractDataSource, dateProvider, telemetryClient = getTelemetryClient()){
|
|
68
|
-
this.config = config;
|
|
69
|
-
this.worldState = worldState;
|
|
70
|
-
this.contractDataSource = contractDataSource;
|
|
71
|
-
this.dateProvider = dateProvider;
|
|
72
|
-
this.telemetryClient = telemetryClient;
|
|
73
|
-
}
|
|
74
|
-
getConfig() {
|
|
75
|
-
return pick(this.config, ...FullNodeBlockBuilderConfigKeys);
|
|
76
|
-
}
|
|
77
|
-
updateConfig(config) {
|
|
78
|
-
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
79
|
-
}
|
|
80
|
-
async makeBlockBuilderDeps(globalVariables, fork) {
|
|
81
|
-
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
82
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
83
|
-
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
84
|
-
const publicTxSimulator = new TelemetryPublicTxSimulator(guardedFork, contractsDB, globalVariables, this.telemetryClient, {
|
|
85
|
-
doMerkleOperations: true,
|
|
86
|
-
skipFeeEnforcement: true,
|
|
87
|
-
clientInitiatedSimulation: false
|
|
88
|
-
});
|
|
89
|
-
const processor = new PublicProcessor(globalVariables, guardedFork, contractsDB, publicTxSimulator, this.dateProvider, this.telemetryClient, undefined, this.config);
|
|
90
|
-
const validator = createValidatorForBlockBuilding(fork, this.contractDataSource, globalVariables, txPublicSetupAllowList);
|
|
91
|
-
return {
|
|
92
|
-
processor,
|
|
93
|
-
validator
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
async syncToPreviousBlock(parentBlockNumber, timeout) {
|
|
97
|
-
await retryUntil(()=>this.worldState.syncImmediate(parentBlockNumber, true).then((syncedTo)=>syncedTo >= parentBlockNumber), 'sync to previous block', timeout, 0.1);
|
|
98
|
-
log.debug(`Synced to previous block ${parentBlockNumber}`);
|
|
99
|
-
}
|
|
100
|
-
async buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, suppliedFork) {
|
|
101
|
-
const parentBlockNumber = globalVariables.blockNumber - 1;
|
|
102
|
-
const syncTimeout = opts.deadline ? (opts.deadline.getTime() - this.dateProvider.now()) / 1000 : undefined;
|
|
103
|
-
await this.syncToPreviousBlock(parentBlockNumber, syncTimeout);
|
|
104
|
-
const fork = suppliedFork ?? await this.worldState.fork(parentBlockNumber);
|
|
105
|
-
try {
|
|
106
|
-
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, fork);
|
|
107
|
-
const res = await buildBlock(pendingTxs, l1ToL2Messages, globalVariables, opts, fork, processor, validator, this.config, this.dateProvider, this.telemetryClient);
|
|
108
|
-
return res;
|
|
109
|
-
} finally{
|
|
110
|
-
// If the fork was supplied, we don't close it.
|
|
111
|
-
// Otherwise, we wait a bit to close the fork we just created,
|
|
112
|
-
// since the processor may still be working on a dangling tx
|
|
113
|
-
// which was interrupted due to the processingDeadline being hit.
|
|
114
|
-
if (!suppliedFork) {
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
116
|
-
setTimeout(async ()=>{
|
|
117
|
-
try {
|
|
118
|
-
await fork.close();
|
|
119
|
-
} catch (err) {
|
|
120
|
-
// This can happen if the sequencer is stopped before we hit this timeout.
|
|
121
|
-
log.warn(`Error closing forks for block processing`, err);
|
|
122
|
-
}
|
|
123
|
-
}, 5000);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
getFork(blockNumber) {
|
|
128
|
-
return this.worldState.fork(blockNumber);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { NullifierSource } from '@aztec/p2p';
|
|
2
|
-
import type { MerkleTreeReadOperations } from '@aztec/stdlib/interfaces/server';
|
|
3
|
-
/**
|
|
4
|
-
* Implements a nullifier source by checking a DB and an in-memory collection.
|
|
5
|
-
* Intended for validating transactions as they are added to a block.
|
|
6
|
-
*/
|
|
7
|
-
export declare class NullifierCache implements NullifierSource {
|
|
8
|
-
private db;
|
|
9
|
-
nullifiers: Set<string>;
|
|
10
|
-
constructor(db: MerkleTreeReadOperations);
|
|
11
|
-
nullifiersExist(nullifiers: Buffer[]): Promise<boolean[]>;
|
|
12
|
-
addNullifiers(nullifiers: Buffer[]): void;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=nullifier_cache.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nullifier_cache.d.ts","sourceRoot":"","sources":["../../src/tx_validator/nullifier_cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;GAGG;AACH,qBAAa,cAAe,YAAW,eAAe;IAGxC,OAAO,CAAC,EAAE;IAFtB,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAEJ,EAAE,EAAE,wBAAwB;IAInC,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAS/D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE;CAK1C"}
|
|
@@ -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,17 +0,0 @@
|
|
|
1
|
-
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
2
|
-
import type { GasFees } from '@aztec/stdlib/gas';
|
|
3
|
-
import type { AllowedElement, ClientProtocolCircuitVerifier, MerkleTreeReadOperations, PublicProcessorValidator } from '@aztec/stdlib/interfaces/server';
|
|
4
|
-
import { GlobalVariables, type Tx, type TxValidator } from '@aztec/stdlib/tx';
|
|
5
|
-
import type { UInt64 } from '@aztec/stdlib/types';
|
|
6
|
-
export declare function createValidatorForAcceptingTxs(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, verifier: ClientProtocolCircuitVerifier | undefined, { l1ChainId, rollupVersion, setupAllowList, gasFees, skipFeeEnforcement, timestamp, blockNumber, txsPermitted, }: {
|
|
7
|
-
l1ChainId: number;
|
|
8
|
-
rollupVersion: number;
|
|
9
|
-
setupAllowList: AllowedElement[];
|
|
10
|
-
gasFees: GasFees;
|
|
11
|
-
skipFeeEnforcement?: boolean;
|
|
12
|
-
timestamp: UInt64;
|
|
13
|
-
blockNumber: number;
|
|
14
|
-
txsPermitted: boolean;
|
|
15
|
-
}): TxValidator<Tx>;
|
|
16
|
-
export declare function createValidatorForBlockBuilding(db: MerkleTreeReadOperations, contractDataSource: ContractDataSource, globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): PublicProcessorValidator;
|
|
17
|
-
//# sourceMappingURL=tx_validator_factory.d.ts.map
|