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