@aztec/sequencer-client 0.0.1-commit.3469e52 → 0.0.1-commit.3895657bc
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/sequencer-client.d.ts +23 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +99 -16
- package/dest/config.d.ts +24 -6
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +40 -30
- package/dest/global_variable_builder/global_builder.d.ts +2 -4
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -2
- package/dest/publisher/config.d.ts +35 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +106 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +26 -8
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +338 -48
- package/dest/sequencer/checkpoint_proposal_job.d.ts +31 -10
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +180 -95
- package/dest/sequencer/metrics.d.ts +17 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +111 -30
- package/dest/sequencer/sequencer.d.ts +25 -12
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +31 -28
- package/dest/sequencer/timetable.d.ts +4 -6
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +7 -11
- package/dest/sequencer/types.d.ts +5 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +17 -14
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +63 -40
- package/dest/test/utils.d.ts +8 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -9
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +135 -18
- package/src/config.ts +55 -41
- package/src/global_variable_builder/global_builder.ts +3 -3
- package/src/publisher/config.ts +121 -43
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -6
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +333 -60
- package/src/sequencer/checkpoint_proposal_job.ts +246 -127
- package/src/sequencer/metrics.ts +124 -32
- package/src/sequencer/sequencer.ts +41 -33
- package/src/sequencer/timetable.ts +13 -12
- package/src/sequencer/types.ts +4 -1
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +90 -62
- package/src/test/utils.ts +22 -13
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { unfreeze } from '@aztec/foundation/types';
|
|
4
|
+
import { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
6
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
7
6
|
import type {
|
|
8
|
-
BuildBlockInCheckpointResult,
|
|
9
7
|
FullNodeBlockBuilderConfig,
|
|
10
8
|
ICheckpointBlockBuilder,
|
|
11
9
|
ICheckpointsBuilder,
|
|
@@ -15,19 +13,20 @@ import type {
|
|
|
15
13
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
16
14
|
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
17
15
|
import type { CheckpointGlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
16
|
+
import type { BuildBlockInCheckpointResult } from '@aztec/validator-client';
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* A fake CheckpointBuilder for testing that implements the same interface as the real one.
|
|
21
20
|
* Can be seeded with blocks to return sequentially on each `buildBlock` call.
|
|
22
21
|
*/
|
|
23
22
|
export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
24
|
-
private blocks:
|
|
25
|
-
private builtBlocks:
|
|
23
|
+
private blocks: L2Block[] = [];
|
|
24
|
+
private builtBlocks: L2Block[] = [];
|
|
26
25
|
private usedTxsPerBlock: Tx[][] = [];
|
|
27
26
|
private blockIndex = 0;
|
|
28
27
|
|
|
29
28
|
/** Optional function to dynamically provide the block (alternative to seedBlocks) */
|
|
30
|
-
private blockProvider: (() =>
|
|
29
|
+
private blockProvider: (() => L2Block) | undefined = undefined;
|
|
31
30
|
|
|
32
31
|
/** Track calls for assertions */
|
|
33
32
|
public buildBlockCalls: Array<{
|
|
@@ -35,6 +34,8 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
35
34
|
timestamp: bigint;
|
|
36
35
|
opts: PublicProcessorLimits;
|
|
37
36
|
}> = [];
|
|
37
|
+
/** Track all consumed transaction hashes across buildBlock calls */
|
|
38
|
+
public consumedTxHashes: Set<string> = new Set();
|
|
38
39
|
public completeCheckpointCalled = false;
|
|
39
40
|
public getCheckpointCalled = false;
|
|
40
41
|
|
|
@@ -47,7 +48,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
47
48
|
) {}
|
|
48
49
|
|
|
49
50
|
/** Seed the builder with blocks to return on successive buildBlock calls */
|
|
50
|
-
seedBlocks(blocks:
|
|
51
|
+
seedBlocks(blocks: L2Block[], usedTxsPerBlock?: Tx[][]): this {
|
|
51
52
|
this.blocks = blocks;
|
|
52
53
|
this.usedTxsPerBlock = usedTxsPerBlock ?? blocks.map(() => []);
|
|
53
54
|
this.blockIndex = 0;
|
|
@@ -59,7 +60,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
59
60
|
* Set a function that provides blocks dynamically.
|
|
60
61
|
* Useful for tests where the block is determined at call time (e.g., sequencer tests).
|
|
61
62
|
*/
|
|
62
|
-
setBlockProvider(provider: () =>
|
|
63
|
+
setBlockProvider(provider: () => L2Block): this {
|
|
63
64
|
this.blockProvider = provider;
|
|
64
65
|
this.blocks = [];
|
|
65
66
|
return this;
|
|
@@ -69,8 +70,8 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
69
70
|
return this.constants;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
buildBlock(
|
|
73
|
-
|
|
73
|
+
async buildBlock(
|
|
74
|
+
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
74
75
|
blockNumber: BlockNumber,
|
|
75
76
|
timestamp: bigint,
|
|
76
77
|
opts: PublicProcessorLimits,
|
|
@@ -78,15 +79,17 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
78
79
|
this.buildBlockCalls.push({ blockNumber, timestamp, opts });
|
|
79
80
|
|
|
80
81
|
if (this.errorOnBuild) {
|
|
81
|
-
|
|
82
|
+
throw this.errorOnBuild;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
let block:
|
|
85
|
+
let block: L2Block;
|
|
85
86
|
let usedTxs: Tx[];
|
|
86
87
|
|
|
87
88
|
if (this.blockProvider) {
|
|
88
|
-
// Dynamic mode: get block from provider
|
|
89
|
-
block = this.blockProvider();
|
|
89
|
+
// Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
|
|
90
|
+
block = L2Block.fromBuffer(this.blockProvider().toBuffer());
|
|
91
|
+
block.header.globalVariables.blockNumber = blockNumber;
|
|
92
|
+
await block.header.recomputeHash();
|
|
90
93
|
usedTxs = [];
|
|
91
94
|
this.builtBlocks.push(block);
|
|
92
95
|
} else {
|
|
@@ -97,83 +100,94 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
97
100
|
this.builtBlocks.push(block);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
|
-
|
|
103
|
+
// Check that no pending tx has already been consumed
|
|
104
|
+
for await (const tx of pendingTxs) {
|
|
105
|
+
const hash = tx.getTxHash().toString();
|
|
106
|
+
if (this.consumedTxHashes.has(hash)) {
|
|
107
|
+
throw new Error(`Transaction ${hash} was already consumed in a previous block`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Add used txs to consumed set
|
|
112
|
+
for (const tx of usedTxs) {
|
|
113
|
+
this.consumedTxHashes.add(tx.getTxHash().toString());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
101
117
|
block,
|
|
102
|
-
publicGas: Gas.empty(),
|
|
103
118
|
publicProcessorDuration: 0,
|
|
104
119
|
numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
|
|
105
|
-
blockBuildingTimer: new Timer(),
|
|
106
120
|
usedTxs,
|
|
107
121
|
failedTxs: [],
|
|
108
|
-
|
|
109
|
-
});
|
|
122
|
+
};
|
|
110
123
|
}
|
|
111
124
|
|
|
112
125
|
completeCheckpoint(): Promise<Checkpoint> {
|
|
113
126
|
this.completeCheckpointCalled = true;
|
|
114
127
|
const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
|
|
115
|
-
|
|
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
|
-
);
|
|
128
|
+
return this.buildCheckpoint(allBlocks);
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
getCheckpoint(): Promise<Checkpoint> {
|
|
129
132
|
this.getCheckpointCalled = true;
|
|
130
133
|
const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
|
|
131
|
-
|
|
132
|
-
if (!lastBlock) {
|
|
134
|
+
if (builtBlocks.length === 0) {
|
|
133
135
|
throw new Error('No blocks built yet');
|
|
134
136
|
}
|
|
135
|
-
|
|
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
|
-
);
|
|
137
|
+
return this.buildCheckpoint(builtBlocks);
|
|
145
138
|
}
|
|
146
139
|
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
/** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
|
|
141
|
+
private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
|
|
142
|
+
// Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
|
|
143
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
144
|
+
blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
|
|
145
|
+
if (i > 0) {
|
|
146
|
+
unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
|
|
147
|
+
await blocks[i].header.recomputeHash();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const firstBlock = blocks[0];
|
|
152
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
153
|
+
const gv = firstBlock.header.globalVariables;
|
|
154
|
+
|
|
155
|
+
const checkpointHeader = CheckpointHeader.empty({
|
|
156
|
+
lastArchiveRoot: firstBlock.header.lastArchive.root,
|
|
157
|
+
blockHeadersHash: Fr.random(),
|
|
157
158
|
slotNumber: gv.slotNumber,
|
|
158
159
|
timestamp: gv.timestamp,
|
|
159
160
|
coinbase: gv.coinbase,
|
|
160
161
|
feeRecipient: gv.feeRecipient,
|
|
161
162
|
gasFees: gv.gasFees,
|
|
162
|
-
totalManaUsed: header.totalManaUsed,
|
|
163
|
+
totalManaUsed: lastBlock.header.totalManaUsed,
|
|
163
164
|
});
|
|
165
|
+
|
|
166
|
+
return new Checkpoint(
|
|
167
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
168
|
+
checkpointHeader,
|
|
169
|
+
blocks,
|
|
170
|
+
this.checkpointNumber,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
|
|
175
|
+
resetCheckpointState(): void {
|
|
176
|
+
this.builtBlocks = [];
|
|
177
|
+
this.blockIndex = 0;
|
|
178
|
+
this.consumedTxHashes.clear();
|
|
179
|
+
this.completeCheckpointCalled = false;
|
|
180
|
+
this.getCheckpointCalled = false;
|
|
164
181
|
}
|
|
165
182
|
|
|
166
183
|
/** Reset for reuse in another test */
|
|
167
184
|
reset(): void {
|
|
168
185
|
this.blocks = [];
|
|
169
|
-
this.builtBlocks = [];
|
|
170
186
|
this.usedTxsPerBlock = [];
|
|
171
|
-
this.blockIndex = 0;
|
|
172
187
|
this.buildBlockCalls = [];
|
|
173
|
-
this.completeCheckpointCalled = false;
|
|
174
|
-
this.getCheckpointCalled = false;
|
|
175
188
|
this.errorOnBuild = undefined;
|
|
176
189
|
this.blockProvider = undefined;
|
|
190
|
+
this.resetCheckpointState();
|
|
177
191
|
}
|
|
178
192
|
}
|
|
179
193
|
|
|
@@ -191,13 +205,15 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
191
205
|
constants: CheckpointGlobalVariables;
|
|
192
206
|
l1ToL2Messages: Fr[];
|
|
193
207
|
previousCheckpointOutHashes: Fr[];
|
|
208
|
+
feeAssetPriceModifier: bigint;
|
|
194
209
|
}> = [];
|
|
195
210
|
public openCheckpointCalls: Array<{
|
|
196
211
|
checkpointNumber: CheckpointNumber;
|
|
197
212
|
constants: CheckpointGlobalVariables;
|
|
198
213
|
l1ToL2Messages: Fr[];
|
|
199
214
|
previousCheckpointOutHashes: Fr[];
|
|
200
|
-
existingBlocks:
|
|
215
|
+
existingBlocks: L2Block[];
|
|
216
|
+
feeAssetPriceModifier: bigint;
|
|
201
217
|
}> = [];
|
|
202
218
|
public updateConfigCalls: Array<Partial<FullNodeBlockBuilderConfig>> = [];
|
|
203
219
|
|
|
@@ -233,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
233
249
|
slotDuration: 24,
|
|
234
250
|
l1ChainId: 1,
|
|
235
251
|
rollupVersion: 1,
|
|
252
|
+
rollupManaLimit: 200_000_000,
|
|
236
253
|
};
|
|
237
254
|
}
|
|
238
255
|
|
|
@@ -243,15 +260,24 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
243
260
|
startCheckpoint(
|
|
244
261
|
checkpointNumber: CheckpointNumber,
|
|
245
262
|
constants: CheckpointGlobalVariables,
|
|
263
|
+
feeAssetPriceModifier: bigint,
|
|
246
264
|
l1ToL2Messages: Fr[],
|
|
247
265
|
previousCheckpointOutHashes: Fr[],
|
|
248
266
|
_fork: MerkleTreeWriteOperations,
|
|
249
267
|
): Promise<ICheckpointBlockBuilder> {
|
|
250
|
-
this.startCheckpointCalls.push({
|
|
268
|
+
this.startCheckpointCalls.push({
|
|
269
|
+
checkpointNumber,
|
|
270
|
+
constants,
|
|
271
|
+
l1ToL2Messages,
|
|
272
|
+
previousCheckpointOutHashes,
|
|
273
|
+
feeAssetPriceModifier,
|
|
274
|
+
});
|
|
251
275
|
|
|
252
276
|
if (!this.checkpointBuilder) {
|
|
253
277
|
// Auto-create a builder if none was set
|
|
254
278
|
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
279
|
+
} else {
|
|
280
|
+
this.checkpointBuilder.resetCheckpointState();
|
|
255
281
|
}
|
|
256
282
|
|
|
257
283
|
return Promise.resolve(this.checkpointBuilder);
|
|
@@ -260,10 +286,11 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
260
286
|
openCheckpoint(
|
|
261
287
|
checkpointNumber: CheckpointNumber,
|
|
262
288
|
constants: CheckpointGlobalVariables,
|
|
289
|
+
feeAssetPriceModifier: bigint,
|
|
263
290
|
l1ToL2Messages: Fr[],
|
|
264
291
|
previousCheckpointOutHashes: Fr[],
|
|
265
292
|
_fork: MerkleTreeWriteOperations,
|
|
266
|
-
existingBlocks:
|
|
293
|
+
existingBlocks: L2Block[] = [],
|
|
267
294
|
): Promise<ICheckpointBlockBuilder> {
|
|
268
295
|
this.openCheckpointCalls.push({
|
|
269
296
|
checkpointNumber,
|
|
@@ -271,6 +298,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
271
298
|
l1ToL2Messages,
|
|
272
299
|
previousCheckpointOutHashes,
|
|
273
300
|
existingBlocks,
|
|
301
|
+
feeAssetPriceModifier,
|
|
274
302
|
});
|
|
275
303
|
|
|
276
304
|
if (!this.checkpointBuilder) {
|
package/src/test/utils.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
7
7
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
8
|
import type { P2P } from '@aztec/p2p';
|
|
9
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
|
-
import { CommitteeAttestation,
|
|
10
|
+
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
13
|
import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
|
|
@@ -30,9 +30,9 @@ export async function makeTx(seed?: number, chainId?: Fr): Promise<Tx> {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Creates an
|
|
33
|
+
* Creates an L2Block from transactions and global variables
|
|
34
34
|
*/
|
|
35
|
-
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<
|
|
35
|
+
export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Promise<L2Block> {
|
|
36
36
|
const processedTxs = await Promise.all(
|
|
37
37
|
txs.map(tx =>
|
|
38
38
|
makeProcessedTxFromPrivateOnlyTx(tx, Fr.ZERO, new PublicDataWrite(Fr.random(), Fr.random()), globalVariables),
|
|
@@ -41,7 +41,13 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
41
41
|
const body = new Body(processedTxs.map(tx => tx.txEffect));
|
|
42
42
|
const header = BlockHeader.empty({ globalVariables });
|
|
43
43
|
const archive = makeAppendOnlyTreeSnapshot(globalVariables.blockNumber + 1);
|
|
44
|
-
return new
|
|
44
|
+
return new L2Block(
|
|
45
|
+
archive,
|
|
46
|
+
header,
|
|
47
|
+
body,
|
|
48
|
+
CheckpointNumber.fromBlockNumber(globalVariables.blockNumber),
|
|
49
|
+
IndexWithinCheckpoint(0),
|
|
50
|
+
);
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -50,6 +56,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
50
56
|
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
51
57
|
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
52
58
|
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
59
|
+
p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
/**
|
|
@@ -70,10 +77,10 @@ export function createMockSignatures(signer: Secp256k1Signer): CommitteeAttestat
|
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
/**
|
|
73
|
-
* Creates a CheckpointHeader from an
|
|
74
|
-
* Uses mock values for blockHeadersHash, blobsHash and inHash since
|
|
80
|
+
* Creates a CheckpointHeader from an L2Block for testing purposes.
|
|
81
|
+
* Uses mock values for blockHeadersHash, blobsHash and inHash since L2Block doesn't have these fields.
|
|
75
82
|
*/
|
|
76
|
-
function createCheckpointHeaderFromBlock(block:
|
|
83
|
+
function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
|
|
77
84
|
const gv = block.header.globalVariables;
|
|
78
85
|
return new CheckpointHeader(
|
|
79
86
|
block.header.lastArchive.root,
|
|
@@ -93,7 +100,7 @@ function createCheckpointHeaderFromBlock(block: L2BlockNew): CheckpointHeader {
|
|
|
93
100
|
/**
|
|
94
101
|
* Creates a block proposal from a block and signature
|
|
95
102
|
*/
|
|
96
|
-
export function createBlockProposal(block:
|
|
103
|
+
export function createBlockProposal(block: L2Block, signature: Signature): BlockProposal {
|
|
97
104
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
98
105
|
return new BlockProposal(
|
|
99
106
|
block.header,
|
|
@@ -109,13 +116,14 @@ export function createBlockProposal(block: L2BlockNew, signature: Signature): Bl
|
|
|
109
116
|
* Creates a checkpoint proposal from a block and signature
|
|
110
117
|
*/
|
|
111
118
|
export function createCheckpointProposal(
|
|
112
|
-
block:
|
|
119
|
+
block: L2Block,
|
|
113
120
|
checkpointSignature: Signature,
|
|
114
121
|
blockSignature?: Signature,
|
|
122
|
+
feeAssetPriceModifier: bigint = 0n,
|
|
115
123
|
): CheckpointProposal {
|
|
116
124
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
117
125
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
118
|
-
return new CheckpointProposal(checkpointHeader, block.archive.root, checkpointSignature, {
|
|
126
|
+
return new CheckpointProposal(checkpointHeader, block.archive.root, feeAssetPriceModifier, checkpointSignature, {
|
|
119
127
|
blockHeader: block.header,
|
|
120
128
|
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
121
129
|
txHashes,
|
|
@@ -129,12 +137,13 @@ export function createCheckpointProposal(
|
|
|
129
137
|
* In production, the sender is recovered from the signature.
|
|
130
138
|
*/
|
|
131
139
|
export function createCheckpointAttestation(
|
|
132
|
-
block:
|
|
140
|
+
block: L2Block,
|
|
133
141
|
signature: Signature,
|
|
134
142
|
sender: EthAddress,
|
|
143
|
+
feeAssetPriceModifier: bigint = 0n,
|
|
135
144
|
): CheckpointAttestation {
|
|
136
145
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
137
|
-
const payload = new ConsensusPayload(checkpointHeader, block.archive.root);
|
|
146
|
+
const payload = new ConsensusPayload(checkpointHeader, block.archive.root, feeAssetPriceModifier);
|
|
138
147
|
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
139
148
|
// Set sender directly for testing (bypasses signature recovery)
|
|
140
149
|
(attestation as any).sender = sender;
|
|
@@ -150,7 +159,7 @@ export async function setupTxsAndBlock(
|
|
|
150
159
|
globalVariables: GlobalVariables,
|
|
151
160
|
txCount: number,
|
|
152
161
|
chainId: Fr,
|
|
153
|
-
): Promise<{ txs: Tx[]; block:
|
|
162
|
+
): Promise<{ txs: Tx[]; block: L2Block }> {
|
|
154
163
|
const txs = await Promise.all(times(txCount, i => makeTx(i + 1, chainId)));
|
|
155
164
|
const block = await makeBlock(txs, globalVariables);
|
|
156
165
|
mockPendingTxs(p2p, txs);
|