@aztec/validator-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f81dbcf
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/README.md +54 -10
- package/dest/block_proposal_handler.d.ts +5 -4
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +124 -62
- package/dest/checkpoint_builder.d.ts +16 -5
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +112 -44
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +24 -0
- package/dest/duties/validation_service.d.ts +2 -2
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +6 -12
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -1
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/key_store/ha_key_store.js +1 -1
- package/dest/metrics.d.ts +9 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/validator.d.ts +30 -8
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +169 -31
- package/package.json +19 -19
- package/src/block_proposal_handler.ts +151 -80
- package/src/checkpoint_builder.ts +129 -39
- package/src/config.ts +24 -0
- package/src/duties/validation_service.ts +12 -11
- package/src/factory.ts +1 -0
- package/src/index.ts +0 -1
- package/src/key_store/ha_key_store.ts +1 -1
- package/src/metrics.ts +18 -0
- package/src/validator.ts +221 -37
- package/dest/tx_validator/index.d.ts +0 -3
- package/dest/tx_validator/index.d.ts.map +0 -1
- package/dest/tx_validator/index.js +0 -2
- 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 -19
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -54
- package/src/tx_validator/index.ts +0 -2
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -154
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
2
2
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
3
|
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
|
-
import {
|
|
4
|
+
import { pick } from '@aztec/foundation/collection';
|
|
5
5
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
6
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
7
7
|
import { createLogger } from '@aztec/foundation/log';
|
|
@@ -9,18 +9,17 @@ import { retryUntil } from '@aztec/foundation/retry';
|
|
|
9
9
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
10
10
|
import type { P2P, PeerId } from '@aztec/p2p';
|
|
11
11
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
12
|
-
import type { L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
|
+
import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
13
13
|
import { getEpochAtSlot, getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
14
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
14
15
|
import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
15
|
-
import {
|
|
16
|
-
type L1ToL2MessageSource,
|
|
17
|
-
computeCheckpointOutHash,
|
|
18
|
-
computeInHashFromL1ToL2Messages,
|
|
19
|
-
} from '@aztec/stdlib/messaging';
|
|
16
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
20
17
|
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
21
|
-
import {
|
|
18
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
19
|
+
import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
22
20
|
import {
|
|
23
21
|
ReExFailedTxsError,
|
|
22
|
+
ReExInitialStateMismatchError,
|
|
24
23
|
ReExStateMismatchError,
|
|
25
24
|
ReExTimeoutError,
|
|
26
25
|
TransactionsNotAvailableError,
|
|
@@ -33,6 +32,7 @@ import type { ValidatorMetrics } from './metrics.js';
|
|
|
33
32
|
export type BlockProposalValidationFailureReason =
|
|
34
33
|
| 'invalid_proposal'
|
|
35
34
|
| 'parent_block_not_found'
|
|
35
|
+
| 'block_source_not_synced'
|
|
36
36
|
| 'parent_block_wrong_slot'
|
|
37
37
|
| 'in_hash_mismatch'
|
|
38
38
|
| 'global_variables_mismatch'
|
|
@@ -40,6 +40,7 @@ export type BlockProposalValidationFailureReason =
|
|
|
40
40
|
| 'txs_not_available'
|
|
41
41
|
| 'state_mismatch'
|
|
42
42
|
| 'failed_txs'
|
|
43
|
+
| 'initial_state_mismatch'
|
|
43
44
|
| 'timeout'
|
|
44
45
|
| 'unknown_error';
|
|
45
46
|
|
|
@@ -92,25 +93,28 @@ export class BlockProposalHandler {
|
|
|
92
93
|
this.tracer = telemetry.getTracer('BlockProposalHandler');
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
// Non-validator handler that re-executes for monitoring but does not attest.
|
|
96
|
+
register(p2pClient: P2P, shouldReexecute: boolean): BlockProposalHandler {
|
|
97
|
+
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
97
98
|
// Returns boolean indicating whether the proposal was valid.
|
|
98
99
|
const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
|
|
99
100
|
try {
|
|
100
|
-
const
|
|
101
|
+
const { slotNumber, blockNumber } = proposal;
|
|
102
|
+
const result = await this.handleBlockProposal(proposal, proposalSender, shouldReexecute);
|
|
101
103
|
if (result.isValid) {
|
|
102
|
-
this.log.info(`Non-validator
|
|
104
|
+
this.log.info(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} handled`, {
|
|
103
105
|
blockNumber: result.blockNumber,
|
|
106
|
+
slotNumber,
|
|
104
107
|
reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
|
|
105
108
|
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
106
109
|
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
110
|
+
reexecuted: shouldReexecute,
|
|
107
111
|
});
|
|
108
112
|
return true;
|
|
109
113
|
} else {
|
|
110
|
-
this.log.warn(
|
|
111
|
-
blockNumber
|
|
112
|
-
reason: result.reason,
|
|
113
|
-
|
|
114
|
+
this.log.warn(
|
|
115
|
+
`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`,
|
|
116
|
+
{ blockNumber: result.blockNumber, slotNumber, reason: result.reason },
|
|
117
|
+
);
|
|
114
118
|
return false;
|
|
115
119
|
}
|
|
116
120
|
} catch (error) {
|
|
@@ -138,7 +142,13 @@ export class BlockProposalHandler {
|
|
|
138
142
|
return { isValid: false, reason: 'invalid_proposal' };
|
|
139
143
|
}
|
|
140
144
|
|
|
141
|
-
const proposalInfo = {
|
|
145
|
+
const proposalInfo = {
|
|
146
|
+
...proposal.toBlockInfo(),
|
|
147
|
+
proposer: proposer.toString(),
|
|
148
|
+
blockNumber: undefined as BlockNumber | undefined,
|
|
149
|
+
checkpointNumber: undefined as CheckpointNumber | undefined,
|
|
150
|
+
};
|
|
151
|
+
|
|
142
152
|
this.log.info(`Processing proposal for slot ${slotNumber}`, {
|
|
143
153
|
...proposalInfo,
|
|
144
154
|
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
@@ -152,17 +162,30 @@ export class BlockProposalHandler {
|
|
|
152
162
|
return { isValid: false, reason: 'invalid_proposal' };
|
|
153
163
|
}
|
|
154
164
|
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
165
|
+
// Ensure the block source is synced before checking for existing blocks,
|
|
166
|
+
// since a pending checkpoint prune may remove blocks we'd otherwise find.
|
|
167
|
+
// This affects mostly the block_number_already_exists check, since a pending
|
|
168
|
+
// checkpoint prune could remove a block that would conflict with this proposal.
|
|
169
|
+
// TODO(@Maddiaa0): This may break staggered slots.
|
|
170
|
+
const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
|
|
171
|
+
if (!blockSourceSync) {
|
|
172
|
+
this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
|
|
173
|
+
return { isValid: false, reason: 'block_source_not_synced' };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
177
|
+
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
178
|
+
// need to process other block proposals to get to it.
|
|
179
|
+
const parentBlock = await this.getParentBlock(proposal);
|
|
180
|
+
if (parentBlock === undefined) {
|
|
158
181
|
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
159
182
|
return { isValid: false, reason: 'parent_block_not_found' };
|
|
160
183
|
}
|
|
161
184
|
|
|
162
185
|
// Check that the parent block's slot is not greater than the proposal's slot.
|
|
163
|
-
if (
|
|
186
|
+
if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
|
|
164
187
|
this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
|
|
165
|
-
parentBlockSlot:
|
|
188
|
+
parentBlockSlot: parentBlock.header.getSlot().toString(),
|
|
166
189
|
proposalSlot: slotNumber.toString(),
|
|
167
190
|
...proposalInfo,
|
|
168
191
|
});
|
|
@@ -171,9 +194,10 @@ export class BlockProposalHandler {
|
|
|
171
194
|
|
|
172
195
|
// Compute the block number based on the parent block
|
|
173
196
|
const blockNumber =
|
|
174
|
-
|
|
197
|
+
parentBlock === 'genesis'
|
|
175
198
|
? BlockNumber(INITIAL_L2_BLOCK_NUM)
|
|
176
|
-
: BlockNumber(
|
|
199
|
+
: BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
200
|
+
proposalInfo.blockNumber = blockNumber;
|
|
177
201
|
|
|
178
202
|
// Check that this block number does not exist already
|
|
179
203
|
const existingBlock = await this.blockSource.getBlockHeader(blockNumber);
|
|
@@ -189,12 +213,22 @@ export class BlockProposalHandler {
|
|
|
189
213
|
deadline: this.getReexecutionDeadline(slotNumber, config),
|
|
190
214
|
});
|
|
191
215
|
|
|
216
|
+
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
217
|
+
if (!shouldReexecute) {
|
|
218
|
+
this.log.info(
|
|
219
|
+
`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
220
|
+
proposalInfo,
|
|
221
|
+
);
|
|
222
|
+
return { isValid: true, blockNumber };
|
|
223
|
+
}
|
|
224
|
+
|
|
192
225
|
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
193
|
-
const checkpointResult =
|
|
226
|
+
const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
|
|
194
227
|
if (checkpointResult.reason) {
|
|
195
228
|
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
196
229
|
}
|
|
197
230
|
const checkpointNumber = checkpointResult.checkpointNumber;
|
|
231
|
+
proposalInfo.checkpointNumber = checkpointNumber;
|
|
198
232
|
|
|
199
233
|
// Check that I have the same set of l1ToL2Messages as the proposal
|
|
200
234
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
@@ -215,36 +249,28 @@ export class BlockProposalHandler {
|
|
|
215
249
|
return { isValid: false, blockNumber, reason: 'txs_not_available' };
|
|
216
250
|
}
|
|
217
251
|
|
|
252
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
253
|
+
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
254
|
+
const previousCheckpointOutHashes = (await this.blockSource.getCheckpointsDataForEpoch(epoch))
|
|
255
|
+
.filter(c => c.checkpointNumber < checkpointNumber)
|
|
256
|
+
.map(c => c.checkpointOutHash);
|
|
257
|
+
|
|
218
258
|
// Try re-executing the transactions in the proposal if needed
|
|
219
259
|
let reexecutionResult;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const previousCheckpointOutHashes = blocksByCheckpoint.map(checkpointBlocks =>
|
|
230
|
-
computeCheckpointOutHash(checkpointBlocks.map(b => b.block.body.txEffects.map(tx => tx.l2ToL1Msgs))),
|
|
260
|
+
try {
|
|
261
|
+
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
262
|
+
reexecutionResult = await this.reexecuteTransactions(
|
|
263
|
+
proposal,
|
|
264
|
+
blockNumber,
|
|
265
|
+
checkpointNumber,
|
|
266
|
+
txs,
|
|
267
|
+
l1ToL2Messages,
|
|
268
|
+
previousCheckpointOutHashes,
|
|
231
269
|
);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
proposal,
|
|
237
|
-
blockNumber,
|
|
238
|
-
checkpointNumber,
|
|
239
|
-
txs,
|
|
240
|
-
l1ToL2Messages,
|
|
241
|
-
previousCheckpointOutHashes,
|
|
242
|
-
);
|
|
243
|
-
} catch (error) {
|
|
244
|
-
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
245
|
-
const reason = this.getReexecuteFailureReason(error);
|
|
246
|
-
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
247
|
-
}
|
|
270
|
+
} catch (error) {
|
|
271
|
+
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
272
|
+
const reason = this.getReexecuteFailureReason(error);
|
|
273
|
+
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
248
274
|
}
|
|
249
275
|
|
|
250
276
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
@@ -253,14 +279,14 @@ export class BlockProposalHandler {
|
|
|
253
279
|
}
|
|
254
280
|
|
|
255
281
|
this.log.info(
|
|
256
|
-
`Successfully
|
|
257
|
-
proposalInfo,
|
|
282
|
+
`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
283
|
+
{ ...proposalInfo, ...pick(reexecutionResult, 'reexecutionTimeMs', 'totalManaUsed') },
|
|
258
284
|
);
|
|
259
285
|
|
|
260
286
|
return { isValid: true, blockNumber, reexecutionResult };
|
|
261
287
|
}
|
|
262
288
|
|
|
263
|
-
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' |
|
|
289
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
|
|
264
290
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
265
291
|
const slot = proposal.slotNumber;
|
|
266
292
|
const config = this.checkpointsBuilder.getConfig();
|
|
@@ -276,12 +302,11 @@ export class BlockProposalHandler {
|
|
|
276
302
|
|
|
277
303
|
try {
|
|
278
304
|
return (
|
|
279
|
-
(await this.blockSource.
|
|
305
|
+
(await this.blockSource.getBlockDataByArchive(parentArchive)) ??
|
|
280
306
|
(timeoutDurationMs <= 0
|
|
281
307
|
? undefined
|
|
282
308
|
: await retryUntil(
|
|
283
|
-
() =>
|
|
284
|
-
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockHeaderByArchive(parentArchive)),
|
|
309
|
+
() => this.blockSource.syncImmediate().then(() => this.blockSource.getBlockDataByArchive(parentArchive)),
|
|
285
310
|
'force archiver sync',
|
|
286
311
|
timeoutDurationMs / 1000,
|
|
287
312
|
0.5,
|
|
@@ -297,12 +322,12 @@ export class BlockProposalHandler {
|
|
|
297
322
|
}
|
|
298
323
|
}
|
|
299
324
|
|
|
300
|
-
private
|
|
325
|
+
private computeCheckpointNumber(
|
|
301
326
|
proposal: BlockProposal,
|
|
302
|
-
|
|
327
|
+
parentBlock: 'genesis' | BlockData,
|
|
303
328
|
proposalInfo: object,
|
|
304
|
-
):
|
|
305
|
-
if (
|
|
329
|
+
): CheckpointComputationResult {
|
|
330
|
+
if (parentBlock === 'genesis') {
|
|
306
331
|
// First block is in checkpoint 1
|
|
307
332
|
if (proposal.indexWithinCheckpoint !== 0) {
|
|
308
333
|
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
@@ -311,19 +336,9 @@ export class BlockProposalHandler {
|
|
|
311
336
|
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
312
337
|
}
|
|
313
338
|
|
|
314
|
-
// Get the parent block to find its checkpoint number
|
|
315
|
-
// TODO(palla/mbps): The block header should include the checkpoint number to avoid this lookup,
|
|
316
|
-
// or at least the L2BlockSource should return a different struct that includes it.
|
|
317
|
-
const parentBlockNumber = parentBlockHeader.getBlockNumber();
|
|
318
|
-
const parentBlock = await this.blockSource.getL2Block(parentBlockNumber);
|
|
319
|
-
if (!parentBlock) {
|
|
320
|
-
this.log.warn(`Parent block ${parentBlockNumber} not found in archiver`, proposalInfo);
|
|
321
|
-
return { reason: 'invalid_proposal' };
|
|
322
|
-
}
|
|
323
|
-
|
|
324
339
|
if (proposal.indexWithinCheckpoint === 0) {
|
|
325
340
|
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
326
|
-
if (!(proposal.blockHeader.getSlot() >
|
|
341
|
+
if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
|
|
327
342
|
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
328
343
|
return { reason: 'invalid_proposal' };
|
|
329
344
|
}
|
|
@@ -335,7 +350,7 @@ export class BlockProposalHandler {
|
|
|
335
350
|
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
336
351
|
return { reason: 'invalid_proposal' };
|
|
337
352
|
}
|
|
338
|
-
if (proposal.blockHeader.getSlot() !==
|
|
353
|
+
if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
|
|
339
354
|
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
340
355
|
return { reason: 'invalid_proposal' };
|
|
341
356
|
}
|
|
@@ -356,7 +371,7 @@ export class BlockProposalHandler {
|
|
|
356
371
|
*/
|
|
357
372
|
private validateNonFirstBlockInCheckpoint(
|
|
358
373
|
proposal: BlockProposal,
|
|
359
|
-
parentBlock:
|
|
374
|
+
parentBlock: BlockData,
|
|
360
375
|
proposalInfo: object,
|
|
361
376
|
): CheckpointComputationResult | undefined {
|
|
362
377
|
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
@@ -435,8 +450,48 @@ export class BlockProposalHandler {
|
|
|
435
450
|
return new Date(nextSlotTimestampSeconds * 1000);
|
|
436
451
|
}
|
|
437
452
|
|
|
438
|
-
|
|
439
|
-
|
|
453
|
+
/** Waits for the block source to sync L1 data up to at least the slot before the given one. */
|
|
454
|
+
private async waitForBlockSourceSync(slot: SlotNumber): Promise<boolean> {
|
|
455
|
+
const deadline = this.getReexecutionDeadline(slot, this.checkpointsBuilder.getConfig());
|
|
456
|
+
const timeoutMs = deadline.getTime() - this.dateProvider.now();
|
|
457
|
+
if (slot === 0) {
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Make a quick check before triggering an archiver sync
|
|
462
|
+
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
463
|
+
if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
try {
|
|
468
|
+
// Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
|
|
469
|
+
return await retryUntil(
|
|
470
|
+
async () => {
|
|
471
|
+
await this.blockSource.syncImmediate();
|
|
472
|
+
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
473
|
+
return syncedSlot !== undefined && syncedSlot + 1 >= slot;
|
|
474
|
+
},
|
|
475
|
+
'wait for block source sync',
|
|
476
|
+
timeoutMs / 1000,
|
|
477
|
+
0.5,
|
|
478
|
+
);
|
|
479
|
+
} catch (err) {
|
|
480
|
+
if (err instanceof TimeoutError) {
|
|
481
|
+
this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
|
|
482
|
+
return false;
|
|
483
|
+
} else {
|
|
484
|
+
throw err;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
private getReexecuteFailureReason(err: any): BlockProposalValidationFailureReason {
|
|
490
|
+
if (err instanceof TransactionsNotAvailableError) {
|
|
491
|
+
return 'txs_not_available';
|
|
492
|
+
} else if (err instanceof ReExInitialStateMismatchError) {
|
|
493
|
+
return 'initial_state_mismatch';
|
|
494
|
+
} else if (err instanceof ReExStateMismatchError) {
|
|
440
495
|
return 'state_mismatch';
|
|
441
496
|
} else if (err instanceof ReExFailedTxsError) {
|
|
442
497
|
return 'failed_txs';
|
|
@@ -475,13 +530,21 @@ export class BlockProposalHandler {
|
|
|
475
530
|
// Fork before the block to be built
|
|
476
531
|
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
477
532
|
await this.worldState.syncImmediate(parentBlockNumber);
|
|
478
|
-
using fork = await this.worldState.fork(parentBlockNumber);
|
|
533
|
+
await using fork = await this.worldState.fork(parentBlockNumber);
|
|
534
|
+
|
|
535
|
+
// Verify the fork's archive root matches the proposal's expected last archive.
|
|
536
|
+
// If they don't match, our world state synced to a different chain and reexecution would fail.
|
|
537
|
+
const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
538
|
+
if (!forkArchiveRoot.equals(proposal.blockHeader.lastArchive.root)) {
|
|
539
|
+
throw new ReExInitialStateMismatchError(proposal.blockHeader.lastArchive.root, forkArchiveRoot);
|
|
540
|
+
}
|
|
479
541
|
|
|
480
|
-
// Build checkpoint constants from proposal (excludes blockNumber
|
|
542
|
+
// Build checkpoint constants from proposal (excludes blockNumber which is per-block)
|
|
481
543
|
const constants: CheckpointGlobalVariables = {
|
|
482
544
|
chainId: new Fr(config.l1ChainId),
|
|
483
545
|
version: new Fr(config.rollupVersion),
|
|
484
546
|
slotNumber: slot,
|
|
547
|
+
timestamp: blockHeader.globalVariables.timestamp,
|
|
485
548
|
coinbase: blockHeader.globalVariables.coinbase,
|
|
486
549
|
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
487
550
|
gasFees: blockHeader.globalVariables.gasFees,
|
|
@@ -491,6 +554,7 @@ export class BlockProposalHandler {
|
|
|
491
554
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
492
555
|
checkpointNumber,
|
|
493
556
|
constants,
|
|
557
|
+
0n, // only takes effect in the following checkpoint.
|
|
494
558
|
l1ToL2Messages,
|
|
495
559
|
previousCheckpointOutHashes,
|
|
496
560
|
fork,
|
|
@@ -500,18 +564,25 @@ export class BlockProposalHandler {
|
|
|
500
564
|
|
|
501
565
|
// Build the new block
|
|
502
566
|
const deadline = this.getReexecutionDeadline(slot, config);
|
|
567
|
+
const maxBlockGas =
|
|
568
|
+
this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined
|
|
569
|
+
? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity)
|
|
570
|
+
: undefined;
|
|
503
571
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
504
572
|
deadline,
|
|
505
573
|
expectedEndState: blockHeader.state,
|
|
574
|
+
maxTransactions: this.config.validateMaxTxsPerBlock,
|
|
575
|
+
maxBlockGas,
|
|
506
576
|
});
|
|
507
577
|
|
|
508
578
|
const { block, failedTxs } = result;
|
|
509
579
|
const numFailedTxs = failedTxs.length;
|
|
510
580
|
|
|
511
|
-
this.log.verbose(`
|
|
581
|
+
this.log.verbose(`Block proposal ${blockNumber} at slot ${slot} transaction re-execution complete`, {
|
|
512
582
|
numFailedTxs,
|
|
513
583
|
numProposalTxs: txHashes.length,
|
|
514
584
|
numProcessedTxs: block.body.txEffects.length,
|
|
585
|
+
blockNumber,
|
|
515
586
|
slot,
|
|
516
587
|
});
|
|
517
588
|
|