@aztec/validator-client 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f
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 +12 -11
- package/dest/checkpoint_builder.d.ts +17 -7
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +27 -10
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +25 -11
- package/dest/duties/validation_service.d.ts +12 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +32 -38
- package/dest/factory.d.ts +4 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +16 -4
- package/dest/key_store/web3signer_key_store.d.ts +10 -2
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -1
- package/dest/key_store/web3signer_key_store.js +32 -41
- package/dest/metrics.d.ts +5 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +85 -14
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +561 -160
- package/dest/validator.d.ts +41 -14
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +282 -97
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +29 -11
- package/src/config.ts +33 -13
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +20 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +18 -0
- package/src/proposal_handler.ts +651 -196
- package/src/validator.ts +366 -126
package/dest/proposal_handler.js
CHANGED
|
@@ -66,21 +66,78 @@ function _ts_dispose_resources(env) {
|
|
|
66
66
|
import { encodeCheckpointBlobDataFromBlocks, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
67
67
|
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
68
68
|
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
69
|
-
import { BlockNumber, CheckpointNumber
|
|
69
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
70
70
|
import { pick } from '@aztec/foundation/collection';
|
|
71
71
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
72
72
|
import { TimeoutError } from '@aztec/foundation/error';
|
|
73
|
+
import { FifoSet } from '@aztec/foundation/fifo-set';
|
|
73
74
|
import { createLogger } from '@aztec/foundation/log';
|
|
74
75
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
75
76
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
76
|
-
import { validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
77
|
-
import { getEpochAtSlot
|
|
77
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
78
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
78
79
|
import { Gas } from '@aztec/stdlib/gas';
|
|
79
80
|
import { accumulateCheckpointOutHashes, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
80
81
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
81
82
|
import { ReExFailedTxsError, ReExInitialStateMismatchError, ReExStateMismatchError, ReExTimeoutError, TransactionsNotAvailableError } from '@aztec/stdlib/validators';
|
|
82
83
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
83
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Mapping from a checkpoint-proposal validation failure reason to the tracker outcome that
|
|
86
|
+
* `handleCheckpointProposal` should record. `undefined` means do not record (signature
|
|
87
|
+
* couldn't be verified, or the checkpoint is already on L1 so the question is moot).
|
|
88
|
+
*/ /* eslint-disable camelcase */ const CHECKPOINT_VALIDATION_REASON_TO_OUTCOME = {
|
|
89
|
+
invalid_signature: undefined,
|
|
90
|
+
invalid_fee_asset_price_modifier: 'invalid',
|
|
91
|
+
checkpoint_already_published: undefined,
|
|
92
|
+
last_block_not_found: 'unvalidated',
|
|
93
|
+
block_fetch_error: 'unvalidated',
|
|
94
|
+
world_state_not_synced: 'unvalidated',
|
|
95
|
+
initial_archive_mismatch: 'unvalidated',
|
|
96
|
+
no_blocks_for_slot: 'unvalidated',
|
|
97
|
+
last_block_archive_mismatch: 'invalid',
|
|
98
|
+
too_many_blocks_in_checkpoint: 'invalid',
|
|
99
|
+
checkpoint_header_mismatch: 'invalid',
|
|
100
|
+
archive_mismatch: 'invalid',
|
|
101
|
+
out_hash_mismatch: 'invalid',
|
|
102
|
+
checkpoint_validation_failed: 'invalid'
|
|
103
|
+
};
|
|
104
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
105
|
+
/** Block-proposal validation failures that constitute a slashable invalid-block offense. */ export const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
106
|
+
'state_mismatch',
|
|
107
|
+
'failed_txs',
|
|
108
|
+
'global_variables_mismatch',
|
|
109
|
+
'invalid_proposal',
|
|
110
|
+
'parent_block_wrong_slot',
|
|
111
|
+
'in_hash_mismatch'
|
|
112
|
+
];
|
|
113
|
+
/** Checkpoint-proposal validation failures that constitute a slashable invalid-checkpoint offense. */ export const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT = {
|
|
114
|
+
// enabled
|
|
115
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
116
|
+
['checkpoint_header_mismatch']: true,
|
|
117
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
118
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
119
|
+
['archive_mismatch']: true,
|
|
120
|
+
['out_hash_mismatch']: true,
|
|
121
|
+
['no_blocks_for_slot']: true,
|
|
122
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
123
|
+
['checkpoint_validation_failed']: true,
|
|
124
|
+
['last_block_archive_mismatch']: true,
|
|
125
|
+
// disabled
|
|
126
|
+
['invalid_signature']: false,
|
|
127
|
+
['last_block_not_found']: false,
|
|
128
|
+
['block_fetch_error']: false,
|
|
129
|
+
['world_state_not_synced']: false,
|
|
130
|
+
// A reorg / divergent local chain, not a proposer offense (mirrors the block path's initial_state_mismatch).
|
|
131
|
+
['initial_archive_mismatch']: false,
|
|
132
|
+
['checkpoint_already_published']: false
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Handles block and checkpoint proposals for both validator and non-validator nodes. Also tracks which slots
|
|
136
|
+
* had a slashable invalid proposal or a proposal equivocation, exposing them via the
|
|
137
|
+
* `InvalidProposalSlotSource` interface consumed by the attested-invalid-proposal slashing watcher. The
|
|
138
|
+
* tracking is populated as a side effect of validating/re-executing proposals, so any node that re-executes
|
|
139
|
+
* proposals (the default) can serve it — not only validators.
|
|
140
|
+
*/ export class ProposalHandler {
|
|
84
141
|
checkpointsBuilder;
|
|
85
142
|
worldState;
|
|
86
143
|
blockSource;
|
|
@@ -88,13 +145,24 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
88
145
|
txProvider;
|
|
89
146
|
blockProposalValidator;
|
|
90
147
|
epochCache;
|
|
148
|
+
timetable;
|
|
91
149
|
config;
|
|
92
150
|
blobClient;
|
|
151
|
+
reexecutionTracker;
|
|
93
152
|
metrics;
|
|
94
153
|
dateProvider;
|
|
95
154
|
log;
|
|
96
155
|
tracer;
|
|
97
|
-
|
|
156
|
+
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
157
|
+
* Keyed by signed-payload hash so two proposals at the same (slot, archive) but with a
|
|
158
|
+
* different `feeAssetPriceModifier` (or any other signed field) are validated independently. */ lastCheckpointValidationResult;
|
|
159
|
+
/** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */ archiver;
|
|
160
|
+
/** Returns current validator addresses for own-proposal detection. Set via register(). */ getOwnValidatorAddresses;
|
|
161
|
+
/** P2P proposal pool access for deciding when retained proposals should block archiver processing. */ p2pClient;
|
|
162
|
+
checkpointProposalValidationFailureCallback;
|
|
163
|
+
/** Slots at which a slashable invalid block or checkpoint proposal was observed. */ slotsWithInvalidProposals;
|
|
164
|
+
/** Slots at which a proposal equivocation was observed; suppresses attested-to-invalid-proposal slashing. */ slotsWithProposalEquivocation;
|
|
165
|
+
constructor(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, timetable, config, blobClient, reexecutionTracker, metrics, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator:proposal-handler')){
|
|
98
166
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
99
167
|
this.worldState = worldState;
|
|
100
168
|
this.blockSource = blockSource;
|
|
@@ -102,20 +170,65 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
102
170
|
this.txProvider = txProvider;
|
|
103
171
|
this.blockProposalValidator = blockProposalValidator;
|
|
104
172
|
this.epochCache = epochCache;
|
|
173
|
+
this.timetable = timetable;
|
|
105
174
|
this.config = config;
|
|
106
175
|
this.blobClient = blobClient;
|
|
176
|
+
this.reexecutionTracker = reexecutionTracker;
|
|
107
177
|
this.metrics = metrics;
|
|
108
178
|
this.dateProvider = dateProvider;
|
|
109
179
|
this.log = log;
|
|
180
|
+
this.slotsWithInvalidProposals = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
181
|
+
this.slotsWithProposalEquivocation = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
110
182
|
if (config.fishermanMode) {
|
|
111
183
|
this.log = this.log.createChild('[FISHERMAN]');
|
|
112
184
|
}
|
|
113
185
|
this.tracer = telemetry.getTracer('ProposalHandler');
|
|
114
186
|
}
|
|
187
|
+
updateConfig(config) {
|
|
188
|
+
this.config = {
|
|
189
|
+
...this.config,
|
|
190
|
+
...config
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
setCheckpointProposalValidationFailureCallback(callback) {
|
|
194
|
+
this.checkpointProposalValidationFailureCallback = callback;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Records the proposer's own checkpoint proposal as a `valid` outcome in the re-execution
|
|
198
|
+
* tracker. Without this, the node's own checkpoint proposals never flow through
|
|
199
|
+
* `handleCheckpointProposal` (proposers don't validate their own proposals), so its sentinel
|
|
200
|
+
* sees no outcome for slots where it was the proposer and reports itself as inactive.
|
|
201
|
+
*
|
|
202
|
+
* `archive` should be the locally-computed archive (NOT the broadcast archive, which may have
|
|
203
|
+
* been deliberately corrupted in tests via `broadcastInvalidBlockProposal` /
|
|
204
|
+
* `broadcastInvalidCheckpointProposalOnly`). Recording the local archive correctly models the
|
|
205
|
+
* proposer's own view of its own work.
|
|
206
|
+
*/ recordOwnCheckpointProposalAsValid(slot, archive, checkpointNumber) {
|
|
207
|
+
this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
|
|
208
|
+
}
|
|
209
|
+
/** Whether a slashable invalid block or checkpoint proposal was observed at the given slot (InvalidProposalSlotSource). */ hasInvalidProposals(slotNumber) {
|
|
210
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
211
|
+
}
|
|
212
|
+
/** Whether a proposal equivocation was observed at the given slot (InvalidProposalSlotSource). */ hasProposalEquivocation(slotNumber) {
|
|
213
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
214
|
+
}
|
|
215
|
+
/** Records a slot as having a slashable invalid proposal, for offense observers (sentinel/slasher watchers). */ markInvalidProposalSlot(slotNumber) {
|
|
216
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
217
|
+
}
|
|
218
|
+
/** Records a slot as having a proposal equivocation, which suppresses attested-to-invalid-proposal slashing. */ markProposalEquivocation(slotNumber) {
|
|
219
|
+
this.slotsWithProposalEquivocation.add(slotNumber);
|
|
220
|
+
}
|
|
115
221
|
/**
|
|
116
|
-
* Registers
|
|
117
|
-
*
|
|
118
|
-
|
|
222
|
+
* Registers handlers for block and checkpoint proposals on the p2p client.
|
|
223
|
+
* Records the p2p client so validation can inspect retained proposals.
|
|
224
|
+
* Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
|
|
225
|
+
* The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
|
|
226
|
+
* @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
|
|
227
|
+
* @param getOwnValidatorAddresses - Returns current validator addresses for own-proposal detection
|
|
228
|
+
*/ register(p2pClient, shouldReexecute, archiver, getOwnValidatorAddresses) {
|
|
229
|
+
this.p2pClient = p2pClient;
|
|
230
|
+
this.archiver = archiver;
|
|
231
|
+
this.getOwnValidatorAddresses = getOwnValidatorAddresses;
|
|
119
232
|
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
120
233
|
// Returns boolean indicating whether the proposal was valid.
|
|
121
234
|
const blockHandler = async (proposal, proposalSender)=>{
|
|
@@ -133,6 +246,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
133
246
|
});
|
|
134
247
|
return true;
|
|
135
248
|
} else {
|
|
249
|
+
// Track invalid proposals / equivocations so offense observers (the attested-invalid-proposal
|
|
250
|
+
// watcher) work on non-validator nodes too. Validators populate these via their own handlers.
|
|
251
|
+
// Skip invalid-proposal marking while the escape hatch is open, matching the validator path,
|
|
252
|
+
// which intentionally disables invalid-block slashing then.
|
|
253
|
+
if (result.reason === 'checkpoint_proposal_equivocation') {
|
|
254
|
+
this.markProposalEquivocation(slotNumber);
|
|
255
|
+
} else if (SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(result.reason) && !await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
256
|
+
this.markInvalidProposalSlot(slotNumber);
|
|
257
|
+
}
|
|
136
258
|
this.log.warn(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`, {
|
|
137
259
|
blockNumber: result.blockNumber,
|
|
138
260
|
slotNumber,
|
|
@@ -146,41 +268,81 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
146
268
|
}
|
|
147
269
|
};
|
|
148
270
|
p2pClient.registerBlockProposalHandler(blockHandler);
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
271
|
+
// p2p detects duplicate (equivocated) proposals without routing them through the handlers above, so mark
|
|
272
|
+
// the slot as equivocated here. This suppresses false-positive attested-to-invalid-proposal slashing on
|
|
273
|
+
// non-validator offense collectors. Validators overwrite this with their own richer handler.
|
|
274
|
+
p2pClient.registerDuplicateProposalCallback((info)=>this.markProposalEquivocation(info.slot));
|
|
275
|
+
// All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
|
|
276
|
+
// Runs for all nodes (validators and non-validators). Validators get the cached result in the
|
|
277
|
+
// validator-specific callback (attestToCheckpointProposal) which runs after this one.
|
|
278
|
+
const checkpointHandler = async (proposal, _sender)=>{
|
|
279
|
+
try {
|
|
280
|
+
const pipeliningTimer = new Timer();
|
|
281
|
+
const proposalInfo = {
|
|
282
|
+
slot: proposal.slotNumber,
|
|
283
|
+
archive: proposal.archive.toString(),
|
|
284
|
+
proposer: proposal.getSender()?.toString()
|
|
285
|
+
};
|
|
286
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
287
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
|
|
291
|
+
this.log.warn(`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`, proposalInfo);
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
// A proposal is "own" when it was signed by a validator key this node also owns. The true local
|
|
295
|
+
// proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
|
|
296
|
+
// proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
|
|
297
|
+
// shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
|
|
298
|
+
// nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
|
|
299
|
+
// proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
|
|
300
|
+
const proposer = proposal.getSender();
|
|
301
|
+
const ownAddresses = this.getOwnValidatorAddresses?.();
|
|
302
|
+
const isOwnProposal = proposer && ownAddresses?.some((addr)=>addr === proposer.toString());
|
|
303
|
+
if (isOwnProposal) {
|
|
304
|
+
const existing = await this.archiver?.getProposedCheckpointData({
|
|
305
|
+
slot: proposal.slotNumber
|
|
306
|
+
});
|
|
307
|
+
if (existing?.archive.root.equals(proposal.archive)) {
|
|
308
|
+
this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
|
|
309
|
+
return undefined;
|
|
163
310
|
}
|
|
164
|
-
} catch (error) {
|
|
165
|
-
this.log.error('Error processing checkpoint proposal in non-validator handler', error);
|
|
166
311
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
312
|
+
const result = await this.handleCheckpointProposal(proposal, proposalInfo);
|
|
313
|
+
if (!result.isValid) {
|
|
314
|
+
// Track invalid checkpoint proposals so offense observers (the attested-invalid-proposal watcher)
|
|
315
|
+
// work on non-validator nodes too. This handler runs for all nodes; validators also mark via the
|
|
316
|
+
// failure callback below (idempotent).
|
|
317
|
+
if (SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
318
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
319
|
+
}
|
|
320
|
+
await this.checkpointProposalValidationFailureCallback?.(proposal, result, proposalInfo);
|
|
321
|
+
} else if (this.archiver) {
|
|
322
|
+
const set = await this.setProposedCheckpoint(proposal);
|
|
323
|
+
if (set) {
|
|
324
|
+
this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
} catch (err) {
|
|
328
|
+
this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, {
|
|
329
|
+
err
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return undefined;
|
|
333
|
+
};
|
|
334
|
+
p2pClient.registerAllNodesCheckpointProposalHandler(checkpointHandler);
|
|
172
335
|
return this;
|
|
173
336
|
}
|
|
174
337
|
async handleBlockProposal(proposal, proposalSender, shouldReexecute) {
|
|
175
338
|
const slotNumber = proposal.slotNumber;
|
|
176
339
|
const proposer = proposal.getSender();
|
|
177
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
178
340
|
// Reject proposals with invalid signatures
|
|
179
341
|
if (!proposer) {
|
|
180
342
|
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
181
343
|
return {
|
|
182
344
|
isValid: false,
|
|
183
|
-
reason: '
|
|
345
|
+
reason: 'invalid_signature'
|
|
184
346
|
};
|
|
185
347
|
}
|
|
186
348
|
const proposalInfo = {
|
|
@@ -203,19 +365,22 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
203
365
|
reason: 'invalid_proposal'
|
|
204
366
|
};
|
|
205
367
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
|
|
368
|
+
const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
|
|
369
|
+
if (!retainedSlotValidation.isValid) {
|
|
370
|
+
this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
|
|
371
|
+
...proposalInfo,
|
|
372
|
+
indexWithinCheckpoint: proposal.indexWithinCheckpoint,
|
|
373
|
+
reason: retainedSlotValidation.reason
|
|
374
|
+
});
|
|
214
375
|
return {
|
|
215
376
|
isValid: false,
|
|
216
|
-
|
|
377
|
+
blockNumber: proposal.blockNumber,
|
|
378
|
+
reason: retainedSlotValidation.reason
|
|
217
379
|
};
|
|
218
380
|
}
|
|
381
|
+
// The proposer builds ahead of L1 submission under pipelining, so the block source won't have
|
|
382
|
+
// synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
|
|
383
|
+
// eating into the attestation window.
|
|
219
384
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
220
385
|
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
221
386
|
// need to process other block proposals to get to it.
|
|
@@ -242,8 +407,12 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
242
407
|
// Compute the block number based on the parent block
|
|
243
408
|
const blockNumber = parentBlock === 'genesis' ? BlockNumber(INITIAL_L2_BLOCK_NUM) : BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
244
409
|
proposalInfo.blockNumber = blockNumber;
|
|
245
|
-
// Check that this block number does not exist already
|
|
246
|
-
|
|
410
|
+
// Check that this block number does not exist already. During a reorg the archiver can still hold a
|
|
411
|
+
// stale block at this number (a different archive, about to be pruned) while the proposal carries the
|
|
412
|
+
// rebuilt replacement; resolveExistingBlockAtNumber waits for the local prune in that case so the
|
|
413
|
+
// rebuilt block is processed in time to attest, rather than being permanently dropped on a bare
|
|
414
|
+
// number collision.
|
|
415
|
+
const existingBlock = await this.resolveExistingBlockAtNumber(blockNumber, proposal.archive, slotNumber);
|
|
247
416
|
if (existingBlock) {
|
|
248
417
|
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
249
418
|
return {
|
|
@@ -256,8 +425,10 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
256
425
|
// and we do it even if we don't plan to re-execute the txs, so that we have them if another node needs them.
|
|
257
426
|
const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
258
427
|
pinnedPeer: proposalSender,
|
|
259
|
-
deadline: this.getReexecutionDeadline(slotNumber
|
|
428
|
+
deadline: this.getReexecutionDeadline(slotNumber)
|
|
260
429
|
});
|
|
430
|
+
// Record the tx-collection outcome on the re-execution tracker
|
|
431
|
+
this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
|
|
261
432
|
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
262
433
|
if (!shouldReexecute) {
|
|
263
434
|
this.log.info(`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, proposalInfo);
|
|
@@ -305,9 +476,18 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
305
476
|
reason: 'txs_not_available'
|
|
306
477
|
};
|
|
307
478
|
}
|
|
308
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
479
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
480
|
+
// Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
|
|
481
|
+
// yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
|
|
309
482
|
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
310
|
-
const previousCheckpointOutHashes =
|
|
483
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
484
|
+
blockSource: this.blockSource,
|
|
485
|
+
epoch,
|
|
486
|
+
checkpointNumber,
|
|
487
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
488
|
+
pipeliningEnabled: true,
|
|
489
|
+
log: this.log
|
|
490
|
+
});
|
|
311
491
|
// Try re-executing the transactions in the proposal if needed
|
|
312
492
|
let reexecutionResult;
|
|
313
493
|
try {
|
|
@@ -324,8 +504,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
324
504
|
};
|
|
325
505
|
}
|
|
326
506
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
327
|
-
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver
|
|
328
|
-
await this.blockSource.addBlock(reexecutionResult
|
|
507
|
+
if (reexecutionResult?.block && !this.config.skipPushProposedBlocksToArchiver) {
|
|
508
|
+
await this.blockSource.addBlock(reexecutionResult.block);
|
|
329
509
|
}
|
|
330
510
|
this.log.info(`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, {
|
|
331
511
|
...proposalInfo,
|
|
@@ -337,19 +517,50 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
337
517
|
reexecutionResult
|
|
338
518
|
};
|
|
339
519
|
}
|
|
520
|
+
async validateNewBlockInSlot(blockProposal) {
|
|
521
|
+
if (!this.p2pClient) {
|
|
522
|
+
return {
|
|
523
|
+
isValid: true
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
const { blockProposals, checkpointProposals } = await this.p2pClient.getProposalsForSlot(blockProposal.slotNumber);
|
|
527
|
+
if (checkpointProposals.length === 0) {
|
|
528
|
+
return {
|
|
529
|
+
isValid: true
|
|
530
|
+
};
|
|
531
|
+
} else if (checkpointProposals.length > 1) {
|
|
532
|
+
return {
|
|
533
|
+
isValid: false,
|
|
534
|
+
reason: 'checkpoint_proposal_equivocation'
|
|
535
|
+
};
|
|
536
|
+
} else {
|
|
537
|
+
const checkpointProposal = checkpointProposals[0];
|
|
538
|
+
const terminalBlock = blockProposals.find((block)=>block.archive.equals(checkpointProposal.archive));
|
|
539
|
+
return terminalBlock !== undefined && blockProposal.indexWithinCheckpoint > terminalBlock.indexWithinCheckpoint ? {
|
|
540
|
+
isValid: false,
|
|
541
|
+
reason: 'block_proposal_beyond_checkpoint'
|
|
542
|
+
} : {
|
|
543
|
+
isValid: true
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}
|
|
340
547
|
async getParentBlock(proposal) {
|
|
341
548
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
342
|
-
const slot = proposal.slotNumber;
|
|
343
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
344
549
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
345
550
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
346
551
|
return 'genesis';
|
|
347
552
|
}
|
|
348
|
-
const deadline = this.getReexecutionDeadline(
|
|
349
|
-
const
|
|
350
|
-
const timeoutDurationMs = deadline.getTime() - currentTime;
|
|
553
|
+
const deadline = this.getReexecutionDeadline(proposal.slotNumber);
|
|
554
|
+
const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
|
|
351
555
|
try {
|
|
352
|
-
return await this.blockSource.
|
|
556
|
+
return await this.blockSource.getBlockData({
|
|
557
|
+
archive: parentArchive
|
|
558
|
+
}) ?? (timeoutDurationMs <= 0 ? undefined : await retryUntil(()=>this.blockSource.syncImmediate().then(()=>this.blockSource.getBlockData({
|
|
559
|
+
archive: parentArchive
|
|
560
|
+
})), 'force archiver sync', {
|
|
561
|
+
deadline,
|
|
562
|
+
dateProvider: this.dateProvider
|
|
563
|
+
}, 0.5));
|
|
353
564
|
} catch (err) {
|
|
354
565
|
if (err instanceof TimeoutError) {
|
|
355
566
|
this.log.debug(`Timed out getting parent block by archive root`, {
|
|
@@ -363,6 +574,60 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
363
574
|
return undefined;
|
|
364
575
|
}
|
|
365
576
|
}
|
|
577
|
+
/**
|
|
578
|
+
* Resolves whether a block genuinely already exists at `blockNumber`. Returns the existing block only if
|
|
579
|
+
* it is a true duplicate of the proposal (matching archive). During a reorg the archiver can still hold a
|
|
580
|
+
* stale fork at this number (different archive) that is about to be pruned; in that case this forces L1
|
|
581
|
+
* sync and waits, bounded by the re-execution deadline, for the prune to land, then returns `undefined` so
|
|
582
|
+
* the rebuilt block proposal can be processed in time to attest. If the prune does not complete before the
|
|
583
|
+
* deadline it returns the stale block, so the caller falls back to the safe `block_number_already_exists`
|
|
584
|
+
* rejection.
|
|
585
|
+
*/ async resolveExistingBlockAtNumber(blockNumber, proposalArchive, slotNumber) {
|
|
586
|
+
const existingBlock = await this.blockSource.getBlockData({
|
|
587
|
+
number: blockNumber
|
|
588
|
+
});
|
|
589
|
+
if (!existingBlock || existingBlock.archive.root.equals(proposalArchive)) {
|
|
590
|
+
return existingBlock;
|
|
591
|
+
}
|
|
592
|
+
// A different block already occupies this number: it may be a stale fork being pruned during a reorg, not a
|
|
593
|
+
// genuine duplicate. Wait for the local prune rather than permanently rejecting the proposal.
|
|
594
|
+
const deadline = this.getReexecutionDeadline(slotNumber);
|
|
595
|
+
if (deadline.getTime() - this.dateProvider.now() <= 0) {
|
|
596
|
+
return existingBlock;
|
|
597
|
+
}
|
|
598
|
+
this.log.warn(`Block number ${blockNumber} already exists, awaiting potential prune`, {
|
|
599
|
+
blockNumber,
|
|
600
|
+
existingArchive: existingBlock.archive.root.toString(),
|
|
601
|
+
proposalArchive: proposalArchive.toString()
|
|
602
|
+
});
|
|
603
|
+
try {
|
|
604
|
+
const { block } = await retryUntil(async ()=>{
|
|
605
|
+
await this.blockSource.syncImmediate();
|
|
606
|
+
const block = await this.blockSource.getBlockData({
|
|
607
|
+
number: blockNumber
|
|
608
|
+
});
|
|
609
|
+
// Resolve once the existing block is gone (pruned) or has been replaced by one matching the
|
|
610
|
+
// proposal — the same condition as the early return above. A matching block is returned so the
|
|
611
|
+
// caller still treats it as a genuine duplicate; an `undefined` (pruned) block lets the proposal
|
|
612
|
+
// be processed. Wrap in an object so the `undefined` case is still a truthy retry result.
|
|
613
|
+
return block === undefined || block.archive.root.equals(proposalArchive) ? {
|
|
614
|
+
block
|
|
615
|
+
} : undefined;
|
|
616
|
+
}, `prune of stale block ${blockNumber}`, {
|
|
617
|
+
deadline,
|
|
618
|
+
dateProvider: this.dateProvider
|
|
619
|
+
}, 0.5);
|
|
620
|
+
return block;
|
|
621
|
+
} catch (err) {
|
|
622
|
+
if (err instanceof TimeoutError) {
|
|
623
|
+
this.log.warn(`Timed out waiting for stale block ${blockNumber} to be pruned`, {
|
|
624
|
+
blockNumber
|
|
625
|
+
});
|
|
626
|
+
return existingBlock;
|
|
627
|
+
}
|
|
628
|
+
throw err;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
366
631
|
computeCheckpointNumber(proposal, parentBlock, proposalInfo) {
|
|
367
632
|
if (parentBlock === 'genesis') {
|
|
368
633
|
// First block is in checkpoint 1
|
|
@@ -491,36 +756,13 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
491
756
|
}
|
|
492
757
|
return undefined;
|
|
493
758
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (slot === 0) {
|
|
502
|
-
return true;
|
|
503
|
-
}
|
|
504
|
-
// Make a quick check before triggering an archiver sync
|
|
505
|
-
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
506
|
-
if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
|
-
try {
|
|
510
|
-
// Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
|
|
511
|
-
return await retryUntil(async ()=>{
|
|
512
|
-
await this.blockSource.syncImmediate();
|
|
513
|
-
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
514
|
-
return syncedSlot !== undefined && syncedSlot + 1 >= slot;
|
|
515
|
-
}, 'wait for block source sync', timeoutMs / 1000, 0.5);
|
|
516
|
-
} catch (err) {
|
|
517
|
-
if (err instanceof TimeoutError) {
|
|
518
|
-
this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
|
|
519
|
-
return false;
|
|
520
|
-
} else {
|
|
521
|
-
throw err;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
759
|
+
/**
|
|
760
|
+
* Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
|
|
761
|
+
* the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
|
|
762
|
+
* checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
|
|
763
|
+
* next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
|
|
764
|
+
*/ getReexecutionDeadline(slotNumber) {
|
|
765
|
+
return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
|
|
524
766
|
}
|
|
525
767
|
getReexecuteFailureReason(err) {
|
|
526
768
|
if (err instanceof TransactionsNotAvailableError) {
|
|
@@ -548,7 +790,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
548
790
|
// If we do not have all of the transactions, then we should fail
|
|
549
791
|
if (txs.length !== txHashes.length) {
|
|
550
792
|
const foundTxHashes = txs.map((tx)=>tx.getTxHash());
|
|
551
|
-
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.
|
|
793
|
+
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.some((h)=>h.equals(txHash)));
|
|
552
794
|
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
553
795
|
}
|
|
554
796
|
const timer = new Timer();
|
|
@@ -580,7 +822,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
580
822
|
// Create checkpoint builder with prior blocks
|
|
581
823
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, priorBlocks, this.log.getBindings());
|
|
582
824
|
// Build the new block
|
|
583
|
-
const deadline = this.getReexecutionDeadline(slot
|
|
825
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
584
826
|
const maxBlockGas = this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity) : undefined;
|
|
585
827
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
586
828
|
isBuildingProposal: false,
|
|
@@ -639,25 +881,53 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
639
881
|
}
|
|
640
882
|
}
|
|
641
883
|
/**
|
|
642
|
-
* Validates a checkpoint proposal and uploads blobs if configured.
|
|
643
|
-
*
|
|
884
|
+
* Validates a checkpoint proposal, caches the result, and uploads blobs if configured.
|
|
885
|
+
* Returns a cached result if the same proposal (archive + slot) was already validated.
|
|
886
|
+
* Used by both the all-nodes callback (via register) and the validator client (via delegation).
|
|
644
887
|
*/ async handleCheckpointProposal(proposal, proposalInfo) {
|
|
888
|
+
const slot = proposal.slotNumber;
|
|
889
|
+
const payloadHash = proposal.getPayloadHash();
|
|
890
|
+
// Check cache: same signed-payload hash means we already validated this exact proposal.
|
|
891
|
+
if (this.lastCheckpointValidationResult && this.lastCheckpointValidationResult.payloadHash === payloadHash) {
|
|
892
|
+
this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
|
|
893
|
+
return this.lastCheckpointValidationResult.result;
|
|
894
|
+
}
|
|
645
895
|
const proposer = proposal.getSender();
|
|
896
|
+
let result;
|
|
646
897
|
if (!proposer) {
|
|
647
898
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
|
|
648
|
-
|
|
899
|
+
result = {
|
|
649
900
|
isValid: false,
|
|
650
901
|
reason: 'invalid_signature'
|
|
651
902
|
};
|
|
652
|
-
}
|
|
653
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
903
|
+
} else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
654
904
|
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`);
|
|
655
|
-
|
|
905
|
+
result = {
|
|
656
906
|
isValid: false,
|
|
657
907
|
reason: 'invalid_fee_asset_price_modifier'
|
|
658
908
|
};
|
|
909
|
+
} else {
|
|
910
|
+
result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
911
|
+
}
|
|
912
|
+
this.lastCheckpointValidationResult = {
|
|
913
|
+
payloadHash,
|
|
914
|
+
result
|
|
915
|
+
};
|
|
916
|
+
// Record the outcome on the re-execution tracker.
|
|
917
|
+
const outcome = result.isValid ? 'valid' : CHECKPOINT_VALIDATION_REASON_TO_OUTCOME[result.reason];
|
|
918
|
+
if (outcome !== undefined) {
|
|
919
|
+
this.reexecutionTracker.recordOutcome(slot, proposal.archive, outcome, result.checkpointNumber);
|
|
920
|
+
}
|
|
921
|
+
// Drop tracker entries for checkpoints that have reached L1 finality.
|
|
922
|
+
try {
|
|
923
|
+
const tips = await this.blockSource.getL2Tips();
|
|
924
|
+
const finalizedCheckpointNumber = tips.finalized.checkpoint.number;
|
|
925
|
+
if (finalizedCheckpointNumber > 0) {
|
|
926
|
+
this.reexecutionTracker.removeBefore(CheckpointNumber(finalizedCheckpointNumber + 1));
|
|
927
|
+
}
|
|
928
|
+
} catch (err) {
|
|
929
|
+
this.log.error(`Error pruning reexecution tracker`, err, proposalInfo);
|
|
659
930
|
}
|
|
660
|
-
const result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
661
931
|
// Upload blobs to filestore if validation passed (fire and forget)
|
|
662
932
|
if (result.isValid) {
|
|
663
933
|
this.tryUploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
@@ -668,73 +938,166 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
668
938
|
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
669
939
|
* @returns Validation result with isValid flag and reason if invalid.
|
|
670
940
|
*/ async validateCheckpointProposal(proposal, proposalInfo) {
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
// Wait for last block to sync by archive
|
|
677
|
-
let lastBlockHeader;
|
|
941
|
+
const env = {
|
|
942
|
+
stack: [],
|
|
943
|
+
error: void 0,
|
|
944
|
+
hasError: false
|
|
945
|
+
};
|
|
678
946
|
try {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
947
|
+
const slot = proposal.slotNumber;
|
|
948
|
+
// Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
|
|
949
|
+
// - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
|
|
950
|
+
// the target slot. Keeping validation/attestation alive until then lets validators keep attesting
|
|
951
|
+
// right up to the proposer's real publish cutoff.
|
|
952
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
953
|
+
// Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
|
|
954
|
+
// the remaining budget is derived from the date provider; a deadline already in the past times out
|
|
955
|
+
// after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
|
|
956
|
+
let lastBlockData;
|
|
957
|
+
try {
|
|
958
|
+
lastBlockData = await retryUntil(async ()=>{
|
|
959
|
+
await this.blockSource.syncImmediate();
|
|
960
|
+
return await this.blockSource.getBlockData({
|
|
961
|
+
archive: proposal.archive
|
|
962
|
+
});
|
|
963
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
|
|
964
|
+
deadline,
|
|
965
|
+
dateProvider: this.dateProvider
|
|
966
|
+
}, 0.5);
|
|
967
|
+
} catch (err) {
|
|
968
|
+
if (err instanceof TimeoutError) {
|
|
969
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
970
|
+
return {
|
|
971
|
+
isValid: false,
|
|
972
|
+
reason: 'last_block_not_found'
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
976
|
+
return {
|
|
977
|
+
isValid: false,
|
|
978
|
+
reason: 'block_fetch_error'
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
if (!lastBlockData) {
|
|
982
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
686
983
|
return {
|
|
687
984
|
isValid: false,
|
|
688
985
|
reason: 'last_block_not_found'
|
|
689
986
|
};
|
|
690
987
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
988
|
+
// Refuse to attest if the block's enclosing checkpoint has already been published to L1.
|
|
989
|
+
const existingCheckpoint = await this.blockSource.getCheckpointData({
|
|
990
|
+
number: lastBlockData.checkpointNumber
|
|
991
|
+
});
|
|
992
|
+
if (existingCheckpoint) {
|
|
993
|
+
this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
|
|
994
|
+
...proposalInfo,
|
|
995
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
996
|
+
});
|
|
997
|
+
return {
|
|
998
|
+
isValid: false,
|
|
999
|
+
reason: 'checkpoint_already_published',
|
|
1000
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
// Get all full blocks for the slot and checkpoint
|
|
1004
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
1005
|
+
if (blocks.length === 0) {
|
|
1006
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
1007
|
+
return {
|
|
1008
|
+
isValid: false,
|
|
1009
|
+
reason: 'no_blocks_for_slot',
|
|
1010
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
1014
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
1015
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
1016
|
+
return {
|
|
1017
|
+
isValid: false,
|
|
1018
|
+
reason: 'last_block_archive_mismatch',
|
|
1019
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
// Note this condition should never trigger, since we dont process block proposals that exceed indexWithinCheckpoint
|
|
1023
|
+
const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
|
|
1024
|
+
if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
|
|
1025
|
+
this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
|
|
1026
|
+
...proposalInfo,
|
|
1027
|
+
blocksInProposal: blocks.length,
|
|
1028
|
+
maxBlocksPerCheckpoint
|
|
1029
|
+
});
|
|
1030
|
+
return {
|
|
1031
|
+
isValid: false,
|
|
1032
|
+
reason: 'too_many_blocks_in_checkpoint',
|
|
1033
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
1037
|
+
...proposalInfo,
|
|
1038
|
+
blockNumbers: blocks.map((b)=>b.number)
|
|
1039
|
+
});
|
|
1040
|
+
// Get checkpoint constants from first block
|
|
1041
|
+
const firstBlock = blocks[0];
|
|
1042
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
1043
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
1044
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
1045
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
1046
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
1047
|
+
// See note on the analogous block-proposal site: the helper handles pipelining lag.
|
|
1048
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
1049
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
1050
|
+
blockSource: this.blockSource,
|
|
1051
|
+
epoch,
|
|
1052
|
+
checkpointNumber,
|
|
1053
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
1054
|
+
pipeliningEnabled: true,
|
|
1055
|
+
log: this.log
|
|
1056
|
+
});
|
|
1057
|
+
// Fork world state at the block before the first block. getFork syncs world state to the parent block
|
|
1058
|
+
// first (see its doc): the block source (archiver) can already hold the block while world state still
|
|
1059
|
+
// trails it by one, and forking a not-yet-applied block throws a raw tree error that would otherwise
|
|
1060
|
+
// escape as an uncaught gossipsub error. We pass the parent's expected block hash so the sync detects a
|
|
1061
|
+
// world-state reorg (undefined for the genesis parent, where no block exists to pin). On failure we map
|
|
1062
|
+
// to a clean validation result rather than letting it escape.
|
|
1063
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
1064
|
+
let forkResult;
|
|
1065
|
+
try {
|
|
1066
|
+
const parentBlockHash = (await this.blockSource.getBlockData({
|
|
1067
|
+
number: parentBlockNumber
|
|
1068
|
+
}))?.blockHash;
|
|
1069
|
+
forkResult = await this.checkpointsBuilder.getFork(parentBlockNumber, parentBlockHash);
|
|
1070
|
+
} catch (err) {
|
|
1071
|
+
this.log.warn(`Failed to fork world state at block ${parentBlockNumber} for checkpoint proposal`, {
|
|
1072
|
+
...proposalInfo,
|
|
1073
|
+
parentBlockNumber,
|
|
1074
|
+
err
|
|
1075
|
+
});
|
|
1076
|
+
return {
|
|
1077
|
+
isValid: false,
|
|
1078
|
+
reason: 'world_state_not_synced',
|
|
1079
|
+
checkpointNumber
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
const fork = _ts_add_disposable_resource(env, forkResult, true);
|
|
1083
|
+
// Verify the fork's archive root matches the checkpoint's expected starting archive (the archive after
|
|
1084
|
+
// the parent block). A mismatch means world state forked from a different chain than the proposal was
|
|
1085
|
+
// built on (e.g. a reorg), so recomputing the checkpoint against it would be meaningless. This mirrors
|
|
1086
|
+
// the block-proposal re-execution check and fails fast with a clean, non-slashable result instead of a
|
|
1087
|
+
// confusing downstream mismatch.
|
|
1088
|
+
const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
1089
|
+
if (!forkArchiveRoot.equals(proposal.checkpointHeader.lastArchiveRoot)) {
|
|
1090
|
+
this.log.warn(`Fork archive root does not match checkpoint proposal's last archive`, {
|
|
1091
|
+
...proposalInfo,
|
|
1092
|
+
forkArchiveRoot: forkArchiveRoot.toString(),
|
|
1093
|
+
expectedLastArchiveRoot: proposal.checkpointHeader.lastArchiveRoot.toString()
|
|
1094
|
+
});
|
|
1095
|
+
return {
|
|
1096
|
+
isValid: false,
|
|
1097
|
+
reason: 'initial_archive_mismatch',
|
|
1098
|
+
checkpointNumber
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
738
1101
|
// Create checkpoint builder with all existing blocks
|
|
739
1102
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
740
1103
|
// Complete the checkpoint to get computed values
|
|
@@ -748,7 +1111,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
748
1111
|
});
|
|
749
1112
|
return {
|
|
750
1113
|
isValid: false,
|
|
751
|
-
reason: 'checkpoint_header_mismatch'
|
|
1114
|
+
reason: 'checkpoint_header_mismatch',
|
|
1115
|
+
checkpointNumber
|
|
752
1116
|
};
|
|
753
1117
|
}
|
|
754
1118
|
// Compare archive root with proposal
|
|
@@ -760,7 +1124,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
760
1124
|
});
|
|
761
1125
|
return {
|
|
762
1126
|
isValid: false,
|
|
763
|
-
reason: 'archive_mismatch'
|
|
1127
|
+
reason: 'archive_mismatch',
|
|
1128
|
+
checkpointNumber
|
|
764
1129
|
};
|
|
765
1130
|
}
|
|
766
1131
|
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
@@ -781,7 +1146,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
781
1146
|
});
|
|
782
1147
|
return {
|
|
783
1148
|
isValid: false,
|
|
784
|
-
reason: 'out_hash_mismatch'
|
|
1149
|
+
reason: 'out_hash_mismatch',
|
|
1150
|
+
checkpointNumber
|
|
785
1151
|
};
|
|
786
1152
|
}
|
|
787
1153
|
// Final round of validations on the checkpoint, just in case.
|
|
@@ -797,15 +1163,21 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
797
1163
|
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
798
1164
|
return {
|
|
799
1165
|
isValid: false,
|
|
800
|
-
reason: 'checkpoint_validation_failed'
|
|
1166
|
+
reason: 'checkpoint_validation_failed',
|
|
1167
|
+
checkpointNumber
|
|
801
1168
|
};
|
|
802
1169
|
}
|
|
803
1170
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
804
1171
|
return {
|
|
805
|
-
isValid: true
|
|
1172
|
+
isValid: true,
|
|
1173
|
+
checkpointNumber
|
|
806
1174
|
};
|
|
1175
|
+
} catch (e) {
|
|
1176
|
+
env.error = e;
|
|
1177
|
+
env.hasError = true;
|
|
807
1178
|
} finally{
|
|
808
|
-
|
|
1179
|
+
const result = _ts_dispose_resources(env);
|
|
1180
|
+
if (result) await result;
|
|
809
1181
|
}
|
|
810
1182
|
}
|
|
811
1183
|
/** Extracts checkpoint global variables from a block. */ extractCheckpointConstants(block) {
|
|
@@ -827,7 +1199,9 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
827
1199
|
}
|
|
828
1200
|
/** Uploads blobs for a checkpoint to the filestore. */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
829
1201
|
try {
|
|
830
|
-
const lastBlockHeader = await this.blockSource.
|
|
1202
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
1203
|
+
archive: proposal.archive
|
|
1204
|
+
}))?.header;
|
|
831
1205
|
if (!lastBlockHeader) {
|
|
832
1206
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
833
1207
|
return;
|
|
@@ -849,4 +1223,31 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
849
1223
|
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
850
1224
|
}
|
|
851
1225
|
}
|
|
1226
|
+
/**
|
|
1227
|
+
* Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
|
|
1228
|
+
* pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
|
|
1229
|
+
* last block to sync.
|
|
1230
|
+
*/ async setProposedCheckpoint(proposal) {
|
|
1231
|
+
if (!this.archiver) {
|
|
1232
|
+
return false;
|
|
1233
|
+
}
|
|
1234
|
+
const blockData = await this.blockSource.getBlockData({
|
|
1235
|
+
archive: proposal.archive
|
|
1236
|
+
});
|
|
1237
|
+
if (!blockData) {
|
|
1238
|
+
this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
|
|
1239
|
+
archive: proposal.archive.toString()
|
|
1240
|
+
});
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
await this.archiver.addProposedCheckpoint({
|
|
1244
|
+
header: proposal.checkpointHeader,
|
|
1245
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
1246
|
+
startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
|
|
1247
|
+
blockCount: blockData.indexWithinCheckpoint + 1,
|
|
1248
|
+
totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
|
|
1249
|
+
feeAssetPriceModifier: proposal.feeAssetPriceModifier
|
|
1250
|
+
});
|
|
1251
|
+
return true;
|
|
1252
|
+
}
|
|
852
1253
|
}
|