@aztec/validator-client 4.0.0-nightly.20260112 → 4.0.0-nightly.20260113
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 +256 -0
- package/dest/block_proposal_handler.d.ts +20 -10
- package/dest/block_proposal_handler.d.ts.map +1 -1
- package/dest/block_proposal_handler.js +333 -72
- package/dest/checkpoint_builder.d.ts +70 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +155 -0
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -0
- package/dest/duties/validation_service.d.ts +26 -10
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +51 -21
- package/dest/factory.d.ts +10 -7
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +2 -2
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +18 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +53 -0
- package/dest/validator.d.ts +39 -15
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +297 -449
- package/package.json +16 -12
- package/src/block_proposal_handler.ts +249 -39
- package/src/checkpoint_builder.ts +267 -0
- package/src/config.ts +10 -0
- package/src/duties/validation_service.ts +79 -25
- package/src/factory.ts +13 -8
- package/src/index.ts +2 -0
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +133 -0
- package/src/validator.ts +400 -94
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-client",
|
|
3
|
-
"version": "4.0.0-nightly.
|
|
3
|
+
"version": "4.0.0-nightly.20260113",
|
|
4
4
|
"main": "dest/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -64,17 +64,21 @@
|
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@aztec/blob-client": "4.0.0-nightly.
|
|
68
|
-
"@aztec/blob-lib": "4.0.0-nightly.
|
|
69
|
-
"@aztec/constants": "4.0.0-nightly.
|
|
70
|
-
"@aztec/epoch-cache": "4.0.0-nightly.
|
|
71
|
-
"@aztec/ethereum": "4.0.0-nightly.
|
|
72
|
-
"@aztec/foundation": "4.0.0-nightly.
|
|
73
|
-
"@aztec/node-keystore": "4.0.0-nightly.
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
77
|
-
"@aztec/
|
|
67
|
+
"@aztec/blob-client": "4.0.0-nightly.20260113",
|
|
68
|
+
"@aztec/blob-lib": "4.0.0-nightly.20260113",
|
|
69
|
+
"@aztec/constants": "4.0.0-nightly.20260113",
|
|
70
|
+
"@aztec/epoch-cache": "4.0.0-nightly.20260113",
|
|
71
|
+
"@aztec/ethereum": "4.0.0-nightly.20260113",
|
|
72
|
+
"@aztec/foundation": "4.0.0-nightly.20260113",
|
|
73
|
+
"@aztec/node-keystore": "4.0.0-nightly.20260113",
|
|
74
|
+
"@aztec/noir-protocol-circuits-types": "4.0.0-nightly.20260113",
|
|
75
|
+
"@aztec/p2p": "4.0.0-nightly.20260113",
|
|
76
|
+
"@aztec/protocol-contracts": "4.0.0-nightly.20260113",
|
|
77
|
+
"@aztec/prover-client": "4.0.0-nightly.20260113",
|
|
78
|
+
"@aztec/simulator": "4.0.0-nightly.20260113",
|
|
79
|
+
"@aztec/slasher": "4.0.0-nightly.20260113",
|
|
80
|
+
"@aztec/stdlib": "4.0.0-nightly.20260113",
|
|
81
|
+
"@aztec/telemetry-client": "4.0.0-nightly.20260113",
|
|
78
82
|
"koa": "^2.16.1",
|
|
79
83
|
"koa-router": "^13.1.1",
|
|
80
84
|
"tslib": "^2.4.0",
|
|
@@ -8,12 +8,12 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
|
8
8
|
import type { P2P, PeerId } from '@aztec/p2p';
|
|
9
9
|
import { TxProvider } from '@aztec/p2p';
|
|
10
10
|
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
11
|
-
import type {
|
|
11
|
+
import type { L2BlockNew, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
12
12
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
13
|
-
import type {
|
|
13
|
+
import type { ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
14
14
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
15
|
-
import {
|
|
16
|
-
import { BlockHeader, type
|
|
15
|
+
import type { BlockProposal } from '@aztec/stdlib/p2p';
|
|
16
|
+
import { BlockHeader, type CheckpointGlobalVariables, type FailedTx, type Tx } from '@aztec/stdlib/tx';
|
|
17
17
|
import {
|
|
18
18
|
ReExFailedTxsError,
|
|
19
19
|
ReExStateMismatchError,
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from '@aztec/stdlib/validators';
|
|
23
23
|
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
24
24
|
|
|
25
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
25
26
|
import type { ValidatorMetrics } from './metrics.js';
|
|
26
27
|
|
|
27
28
|
export type BlockProposalValidationFailureReason =
|
|
@@ -29,6 +30,7 @@ export type BlockProposalValidationFailureReason =
|
|
|
29
30
|
| 'parent_block_not_found'
|
|
30
31
|
| 'parent_block_wrong_slot'
|
|
31
32
|
| 'in_hash_mismatch'
|
|
33
|
+
| 'global_variables_mismatch'
|
|
32
34
|
| 'block_number_already_exists'
|
|
33
35
|
| 'txs_not_available'
|
|
34
36
|
| 'state_mismatch'
|
|
@@ -37,7 +39,7 @@ export type BlockProposalValidationFailureReason =
|
|
|
37
39
|
| 'unknown_error';
|
|
38
40
|
|
|
39
41
|
type ReexecuteTransactionsResult = {
|
|
40
|
-
block:
|
|
42
|
+
block: L2BlockNew;
|
|
41
43
|
failedTxs: FailedTx[];
|
|
42
44
|
reexecutionTimeMs: number;
|
|
43
45
|
totalManaUsed: number;
|
|
@@ -58,12 +60,17 @@ export type BlockProposalValidationFailureResult = {
|
|
|
58
60
|
|
|
59
61
|
export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
|
|
60
62
|
|
|
63
|
+
type CheckpointComputationResult =
|
|
64
|
+
| { checkpointNumber: CheckpointNumber; reason?: undefined }
|
|
65
|
+
| { checkpointNumber?: undefined; reason: 'invalid_proposal' | 'global_variables_mismatch' };
|
|
66
|
+
|
|
61
67
|
export class BlockProposalHandler {
|
|
62
68
|
public readonly tracer: Tracer;
|
|
63
69
|
|
|
64
70
|
constructor(
|
|
65
|
-
private
|
|
66
|
-
private
|
|
71
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
72
|
+
private worldState: WorldStateSynchronizer,
|
|
73
|
+
private blockSource: L2BlockSource & L2BlockSink,
|
|
67
74
|
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
68
75
|
private txProvider: TxProvider,
|
|
69
76
|
private blockProposalValidator: BlockProposalValidator,
|
|
@@ -80,7 +87,9 @@ export class BlockProposalHandler {
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
registerForReexecution(p2pClient: P2P): BlockProposalHandler {
|
|
83
|
-
|
|
90
|
+
// Non-validator handler that re-executes for monitoring but does not attest.
|
|
91
|
+
// Returns boolean indicating whether the proposal was valid.
|
|
92
|
+
const handler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
|
|
84
93
|
try {
|
|
85
94
|
const result = await this.handleBlockProposal(proposal, proposalSender, true);
|
|
86
95
|
if (result.isValid) {
|
|
@@ -90,16 +99,18 @@ export class BlockProposalHandler {
|
|
|
90
99
|
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
91
100
|
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
92
101
|
});
|
|
102
|
+
return true;
|
|
93
103
|
} else {
|
|
94
104
|
this.log.warn(`Non-validator reexecution failed for slot ${proposal.slotNumber}`, {
|
|
95
105
|
blockNumber: result.blockNumber,
|
|
96
106
|
reason: result.reason,
|
|
97
107
|
});
|
|
108
|
+
return false;
|
|
98
109
|
}
|
|
99
110
|
} catch (error) {
|
|
100
111
|
this.log.error('Error processing block proposal in non-validator handler', error);
|
|
112
|
+
return false;
|
|
101
113
|
}
|
|
102
|
-
return undefined; // Non-validator nodes don't return attestations
|
|
103
114
|
};
|
|
104
115
|
|
|
105
116
|
p2pClient.registerBlockProposalHandler(handler);
|
|
@@ -113,7 +124,7 @@ export class BlockProposalHandler {
|
|
|
113
124
|
): Promise<BlockProposalValidationResult> {
|
|
114
125
|
const slotNumber = proposal.slotNumber;
|
|
115
126
|
const proposer = proposal.getSender();
|
|
116
|
-
const config = this.
|
|
127
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
117
128
|
|
|
118
129
|
// Reject proposals with invalid signatures
|
|
119
130
|
if (!proposer) {
|
|
@@ -172,12 +183,17 @@ export class BlockProposalHandler {
|
|
|
172
183
|
deadline: this.getReexecutionDeadline(slotNumber, config),
|
|
173
184
|
});
|
|
174
185
|
|
|
186
|
+
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
187
|
+
const checkpointResult = await this.computeCheckpointNumber(proposal, parentBlockHeader, proposalInfo);
|
|
188
|
+
if (checkpointResult.reason) {
|
|
189
|
+
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
190
|
+
}
|
|
191
|
+
const checkpointNumber = checkpointResult.checkpointNumber;
|
|
192
|
+
|
|
175
193
|
// Check that I have the same set of l1ToL2Messages as the proposal
|
|
176
|
-
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(
|
|
177
|
-
CheckpointNumber.fromBlockNumber(blockNumber),
|
|
178
|
-
);
|
|
194
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
179
195
|
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
180
|
-
const proposalInHash = proposal.
|
|
196
|
+
const proposalInHash = proposal.inHash;
|
|
181
197
|
if (!computedInHash.equals(proposalInHash)) {
|
|
182
198
|
this.log.warn(`L1 to L2 messages in hash mismatch, skipping processing`, {
|
|
183
199
|
proposalInHash: proposalInHash.toString(),
|
|
@@ -198,7 +214,13 @@ export class BlockProposalHandler {
|
|
|
198
214
|
if (shouldReexecute) {
|
|
199
215
|
try {
|
|
200
216
|
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
201
|
-
reexecutionResult = await this.reexecuteTransactions(
|
|
217
|
+
reexecutionResult = await this.reexecuteTransactions(
|
|
218
|
+
proposal,
|
|
219
|
+
blockNumber,
|
|
220
|
+
checkpointNumber,
|
|
221
|
+
txs,
|
|
222
|
+
l1ToL2Messages,
|
|
223
|
+
);
|
|
202
224
|
} catch (error) {
|
|
203
225
|
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
204
226
|
const reason = this.getReexecuteFailureReason(error);
|
|
@@ -206,14 +228,24 @@ export class BlockProposalHandler {
|
|
|
206
228
|
}
|
|
207
229
|
}
|
|
208
230
|
|
|
209
|
-
this
|
|
231
|
+
// If we succeeded, push this block into the archiver (unless disabled)
|
|
232
|
+
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
233
|
+
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
|
|
234
|
+
await this.blockSource.addBlock(reexecutionResult?.block);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
this.log.info(
|
|
238
|
+
`Successfully processed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
239
|
+
proposalInfo,
|
|
240
|
+
);
|
|
241
|
+
|
|
210
242
|
return { isValid: true, blockNumber, reexecutionResult };
|
|
211
243
|
}
|
|
212
244
|
|
|
213
245
|
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockHeader | undefined> {
|
|
214
|
-
const parentArchive = proposal.
|
|
246
|
+
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
215
247
|
const slot = proposal.slotNumber;
|
|
216
|
-
const config = this.
|
|
248
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
217
249
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
218
250
|
|
|
219
251
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
@@ -247,12 +279,168 @@ export class BlockProposalHandler {
|
|
|
247
279
|
}
|
|
248
280
|
}
|
|
249
281
|
|
|
282
|
+
private async computeCheckpointNumber(
|
|
283
|
+
proposal: BlockProposal,
|
|
284
|
+
parentBlockHeader: 'genesis' | BlockHeader,
|
|
285
|
+
proposalInfo: object,
|
|
286
|
+
): Promise<CheckpointComputationResult> {
|
|
287
|
+
if (parentBlockHeader === 'genesis') {
|
|
288
|
+
// First block is in checkpoint 1
|
|
289
|
+
if (proposal.indexWithinCheckpoint !== 0) {
|
|
290
|
+
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
291
|
+
return { reason: 'invalid_proposal' };
|
|
292
|
+
}
|
|
293
|
+
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Get the parent block to find its checkpoint number
|
|
297
|
+
// TODO(palla/mbps): The block header should include the checkpoint number to avoid this lookup,
|
|
298
|
+
// or at least the L2BlockSource should return a different struct that includes it.
|
|
299
|
+
const parentBlockNumber = parentBlockHeader.getBlockNumber();
|
|
300
|
+
const parentBlock = await this.blockSource.getL2BlockNew(parentBlockNumber);
|
|
301
|
+
if (!parentBlock) {
|
|
302
|
+
this.log.warn(`Parent block ${parentBlockNumber} not found in archiver`, proposalInfo);
|
|
303
|
+
return { reason: 'invalid_proposal' };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (proposal.indexWithinCheckpoint === 0) {
|
|
307
|
+
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
308
|
+
if (!(proposal.blockHeader.getSlot() > parentBlockHeader.getSlot())) {
|
|
309
|
+
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
310
|
+
return { reason: 'invalid_proposal' };
|
|
311
|
+
}
|
|
312
|
+
return { checkpointNumber: CheckpointNumber(parentBlock.checkpointNumber + 1) };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Otherwise it should follow the previous block in the same checkpoint
|
|
316
|
+
if (proposal.indexWithinCheckpoint !== parentBlock.indexWithinCheckpoint + 1) {
|
|
317
|
+
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
318
|
+
return { reason: 'invalid_proposal' };
|
|
319
|
+
}
|
|
320
|
+
if (proposal.blockHeader.getSlot() !== parentBlockHeader.getSlot()) {
|
|
321
|
+
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
322
|
+
return { reason: 'invalid_proposal' };
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// For non-first blocks in a checkpoint, validate global variables match parent (except blockNumber)
|
|
326
|
+
const validationResult = this.validateNonFirstBlockInCheckpoint(proposal, parentBlock, proposalInfo);
|
|
327
|
+
if (validationResult) {
|
|
328
|
+
return validationResult;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return { checkpointNumber: parentBlock.checkpointNumber };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Validates that a non-first block in a checkpoint has consistent global variables with its parent.
|
|
336
|
+
* For blocks with indexWithinCheckpoint > 0, all global variables except blockNumber must match the parent.
|
|
337
|
+
* @returns A failure result if validation fails, undefined if validation passes
|
|
338
|
+
*/
|
|
339
|
+
private validateNonFirstBlockInCheckpoint(
|
|
340
|
+
proposal: BlockProposal,
|
|
341
|
+
parentBlock: L2BlockNew,
|
|
342
|
+
proposalInfo: object,
|
|
343
|
+
): CheckpointComputationResult | undefined {
|
|
344
|
+
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
345
|
+
const parentGlobals = parentBlock.header.globalVariables;
|
|
346
|
+
|
|
347
|
+
// All global variables except blockNumber should match the parent
|
|
348
|
+
// blockNumber naturally increments between blocks
|
|
349
|
+
if (!proposalGlobals.chainId.equals(parentGlobals.chainId)) {
|
|
350
|
+
this.log.warn(`Non-first block in checkpoint has mismatched chainId`, {
|
|
351
|
+
...proposalInfo,
|
|
352
|
+
proposalChainId: proposalGlobals.chainId.toString(),
|
|
353
|
+
parentChainId: parentGlobals.chainId.toString(),
|
|
354
|
+
});
|
|
355
|
+
return { reason: 'global_variables_mismatch' };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (!proposalGlobals.version.equals(parentGlobals.version)) {
|
|
359
|
+
this.log.warn(`Non-first block in checkpoint has mismatched version`, {
|
|
360
|
+
...proposalInfo,
|
|
361
|
+
proposalVersion: proposalGlobals.version.toString(),
|
|
362
|
+
parentVersion: parentGlobals.version.toString(),
|
|
363
|
+
});
|
|
364
|
+
return { reason: 'global_variables_mismatch' };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (proposalGlobals.slotNumber !== parentGlobals.slotNumber) {
|
|
368
|
+
this.log.warn(`Non-first block in checkpoint has mismatched slotNumber`, {
|
|
369
|
+
...proposalInfo,
|
|
370
|
+
proposalSlotNumber: proposalGlobals.slotNumber,
|
|
371
|
+
parentSlotNumber: parentGlobals.slotNumber,
|
|
372
|
+
});
|
|
373
|
+
return { reason: 'global_variables_mismatch' };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (proposalGlobals.timestamp !== parentGlobals.timestamp) {
|
|
377
|
+
this.log.warn(`Non-first block in checkpoint has mismatched timestamp`, {
|
|
378
|
+
...proposalInfo,
|
|
379
|
+
proposalTimestamp: proposalGlobals.timestamp.toString(),
|
|
380
|
+
parentTimestamp: parentGlobals.timestamp.toString(),
|
|
381
|
+
});
|
|
382
|
+
return { reason: 'global_variables_mismatch' };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (!proposalGlobals.coinbase.equals(parentGlobals.coinbase)) {
|
|
386
|
+
this.log.warn(`Non-first block in checkpoint has mismatched coinbase`, {
|
|
387
|
+
...proposalInfo,
|
|
388
|
+
proposalCoinbase: proposalGlobals.coinbase.toString(),
|
|
389
|
+
parentCoinbase: parentGlobals.coinbase.toString(),
|
|
390
|
+
});
|
|
391
|
+
return { reason: 'global_variables_mismatch' };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
if (!proposalGlobals.feeRecipient.equals(parentGlobals.feeRecipient)) {
|
|
395
|
+
this.log.warn(`Non-first block in checkpoint has mismatched feeRecipient`, {
|
|
396
|
+
...proposalInfo,
|
|
397
|
+
proposalFeeRecipient: proposalGlobals.feeRecipient.toString(),
|
|
398
|
+
parentFeeRecipient: parentGlobals.feeRecipient.toString(),
|
|
399
|
+
});
|
|
400
|
+
return { reason: 'global_variables_mismatch' };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (!proposalGlobals.gasFees.equals(parentGlobals.gasFees)) {
|
|
404
|
+
this.log.warn(`Non-first block in checkpoint has mismatched gasFees`, {
|
|
405
|
+
...proposalInfo,
|
|
406
|
+
proposalGasFees: proposalGlobals.gasFees.toInspect(),
|
|
407
|
+
parentGasFees: parentGlobals.gasFees.toInspect(),
|
|
408
|
+
});
|
|
409
|
+
return { reason: 'global_variables_mismatch' };
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
|
|
250
415
|
private getReexecutionDeadline(slot: SlotNumber, config: { l1GenesisTime: bigint; slotDuration: number }): Date {
|
|
251
416
|
const nextSlotTimestampSeconds = Number(getTimestampForSlot(SlotNumber(slot + 1), config));
|
|
252
417
|
const msNeededForPropagationAndPublishing = this.config.validatorReexecuteDeadlineMs;
|
|
253
418
|
return new Date(nextSlotTimestampSeconds * 1000 - msNeededForPropagationAndPublishing);
|
|
254
419
|
}
|
|
255
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Gets all prior blocks in the same checkpoint (same slot and checkpoint number) up to but not including upToBlockNumber.
|
|
423
|
+
*/
|
|
424
|
+
private async getBlocksInCheckpoint(
|
|
425
|
+
slot: SlotNumber,
|
|
426
|
+
upToBlockNumber: BlockNumber,
|
|
427
|
+
checkpointNumber: CheckpointNumber,
|
|
428
|
+
): Promise<L2BlockNew[]> {
|
|
429
|
+
const blocks: L2BlockNew[] = [];
|
|
430
|
+
let currentBlockNumber = BlockNumber(upToBlockNumber - 1);
|
|
431
|
+
|
|
432
|
+
while (currentBlockNumber >= INITIAL_L2_BLOCK_NUM) {
|
|
433
|
+
const block = await this.blockSource.getL2BlockNew(currentBlockNumber);
|
|
434
|
+
if (!block || block.header.getSlot() !== slot || block.checkpointNumber !== checkpointNumber) {
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
blocks.unshift(block);
|
|
438
|
+
currentBlockNumber = BlockNumber(currentBlockNumber - 1);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return blocks;
|
|
442
|
+
}
|
|
443
|
+
|
|
256
444
|
private getReexecuteFailureReason(err: any) {
|
|
257
445
|
if (err instanceof ReExStateMismatchError) {
|
|
258
446
|
return 'state_mismatch';
|
|
@@ -268,11 +456,11 @@ export class BlockProposalHandler {
|
|
|
268
456
|
async reexecuteTransactions(
|
|
269
457
|
proposal: BlockProposal,
|
|
270
458
|
blockNumber: BlockNumber,
|
|
459
|
+
checkpointNumber: CheckpointNumber,
|
|
271
460
|
txs: Tx[],
|
|
272
461
|
l1ToL2Messages: Fr[],
|
|
273
462
|
): Promise<ReexecuteTransactionsResult> {
|
|
274
|
-
const {
|
|
275
|
-
const { txHashes } = proposal;
|
|
463
|
+
const { blockHeader, txHashes } = proposal;
|
|
276
464
|
|
|
277
465
|
// If we do not have all of the transactions, then we should fail
|
|
278
466
|
if (txs.length !== txHashes.length) {
|
|
@@ -281,28 +469,46 @@ export class BlockProposalHandler {
|
|
|
281
469
|
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
282
470
|
}
|
|
283
471
|
|
|
284
|
-
// Use the sequencer's block building logic to re-execute the transactions
|
|
285
472
|
const timer = new Timer();
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
473
|
+
const slot = proposal.slotNumber;
|
|
474
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
475
|
+
|
|
476
|
+
// Get prior blocks in this checkpoint (same slot and checkpoint number)
|
|
477
|
+
const priorBlocks = await this.getBlocksInCheckpoint(slot, blockNumber, checkpointNumber);
|
|
478
|
+
|
|
479
|
+
// Fork before the block to be built
|
|
480
|
+
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
481
|
+
using fork = await this.worldState.fork(parentBlockNumber);
|
|
482
|
+
|
|
483
|
+
// Build checkpoint constants from proposal (excludes blockNumber and timestamp which are per-block)
|
|
484
|
+
const constants: CheckpointGlobalVariables = {
|
|
296
485
|
chainId: new Fr(config.l1ChainId),
|
|
297
486
|
version: new Fr(config.rollupVersion),
|
|
298
|
-
|
|
487
|
+
slotNumber: slot,
|
|
488
|
+
coinbase: blockHeader.globalVariables.coinbase,
|
|
489
|
+
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
490
|
+
gasFees: blockHeader.globalVariables.gasFees,
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
// Create checkpoint builder with prior blocks
|
|
494
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
495
|
+
checkpointNumber,
|
|
496
|
+
constants,
|
|
497
|
+
l1ToL2Messages,
|
|
498
|
+
fork,
|
|
499
|
+
priorBlocks,
|
|
500
|
+
);
|
|
299
501
|
|
|
300
|
-
|
|
301
|
-
|
|
502
|
+
// Build the new block
|
|
503
|
+
const deadline = this.getReexecutionDeadline(slot, config);
|
|
504
|
+
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
505
|
+
deadline,
|
|
506
|
+
expectedEndState: blockHeader.state,
|
|
302
507
|
});
|
|
303
508
|
|
|
509
|
+
const { block, failedTxs } = result;
|
|
304
510
|
const numFailedTxs = failedTxs.length;
|
|
305
|
-
|
|
511
|
+
|
|
306
512
|
this.log.verbose(`Transaction re-execution complete for slot ${slot}`, {
|
|
307
513
|
numFailedTxs,
|
|
308
514
|
numProposalTxs: txHashes.length,
|
|
@@ -321,11 +527,15 @@ export class BlockProposalHandler {
|
|
|
321
527
|
}
|
|
322
528
|
|
|
323
529
|
// Throw a ReExStateMismatchError error if state updates do not match
|
|
324
|
-
|
|
325
|
-
|
|
530
|
+
// Compare the full block structure (archive and header) from the built block with the proposal
|
|
531
|
+
const archiveMatches = proposal.archive.equals(block.archive.root);
|
|
532
|
+
const headerMatches = proposal.blockHeader.equals(block.header);
|
|
533
|
+
if (!archiveMatches || !headerMatches) {
|
|
326
534
|
this.log.warn(`Re-execution state mismatch for slot ${slot}`, {
|
|
327
|
-
|
|
328
|
-
|
|
535
|
+
expectedArchive: block.archive.root.toString(),
|
|
536
|
+
actualArchive: proposal.archive.toString(),
|
|
537
|
+
expectedHeader: block.header.toInspect(),
|
|
538
|
+
actualHeader: proposal.blockHeader.toInspect(),
|
|
329
539
|
});
|
|
330
540
|
this.metrics?.recordFailedReexecution(proposal);
|
|
331
541
|
throw new ReExStateMismatchError(proposal.archive, block.archive.root);
|