@aztec/validator-client 0.0.1-commit.4d3c002 → 0.0.1-commit.4d9804df
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 -9
- package/dest/checkpoint_builder.d.ts +6 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +16 -8
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -5
- 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 +71 -13
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +400 -156
- package/dest/validator.d.ts +30 -11
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +215 -62
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -7
- package/src/config.ts +31 -7
- 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 +466 -179
- package/src/validator.ts +281 -80
package/dest/proposal_handler.js
CHANGED
|
@@ -66,21 +66,73 @@ 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
|
+
no_blocks_for_slot: 'unvalidated',
|
|
95
|
+
last_block_archive_mismatch: 'invalid',
|
|
96
|
+
too_many_blocks_in_checkpoint: 'invalid',
|
|
97
|
+
checkpoint_header_mismatch: 'invalid',
|
|
98
|
+
archive_mismatch: 'invalid',
|
|
99
|
+
out_hash_mismatch: 'invalid',
|
|
100
|
+
checkpoint_validation_failed: 'invalid'
|
|
101
|
+
};
|
|
102
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
103
|
+
/** Block-proposal validation failures that constitute a slashable invalid-block offense. */ export const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
104
|
+
'state_mismatch',
|
|
105
|
+
'failed_txs',
|
|
106
|
+
'global_variables_mismatch',
|
|
107
|
+
'invalid_proposal',
|
|
108
|
+
'parent_block_wrong_slot',
|
|
109
|
+
'in_hash_mismatch'
|
|
110
|
+
];
|
|
111
|
+
/** Checkpoint-proposal validation failures that constitute a slashable invalid-checkpoint offense. */ export const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT = {
|
|
112
|
+
// enabled
|
|
113
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
114
|
+
['checkpoint_header_mismatch']: true,
|
|
115
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
116
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
117
|
+
['archive_mismatch']: true,
|
|
118
|
+
['out_hash_mismatch']: true,
|
|
119
|
+
['no_blocks_for_slot']: true,
|
|
120
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
121
|
+
['checkpoint_validation_failed']: true,
|
|
122
|
+
['last_block_archive_mismatch']: true,
|
|
123
|
+
// disabled
|
|
124
|
+
['invalid_signature']: false,
|
|
125
|
+
['last_block_not_found']: false,
|
|
126
|
+
['block_fetch_error']: false,
|
|
127
|
+
['checkpoint_already_published']: false
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Handles block and checkpoint proposals for both validator and non-validator nodes. Also tracks which slots
|
|
131
|
+
* had a slashable invalid proposal or a proposal equivocation, exposing them via the
|
|
132
|
+
* `InvalidProposalSlotSource` interface consumed by the attested-invalid-proposal slashing watcher. The
|
|
133
|
+
* tracking is populated as a side effect of validating/re-executing proposals, so any node that re-executes
|
|
134
|
+
* proposals (the default) can serve it — not only validators.
|
|
135
|
+
*/ export class ProposalHandler {
|
|
84
136
|
checkpointsBuilder;
|
|
85
137
|
worldState;
|
|
86
138
|
blockSource;
|
|
@@ -88,16 +140,24 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
88
140
|
txProvider;
|
|
89
141
|
blockProposalValidator;
|
|
90
142
|
epochCache;
|
|
143
|
+
timetable;
|
|
91
144
|
config;
|
|
92
145
|
blobClient;
|
|
146
|
+
reexecutionTracker;
|
|
93
147
|
metrics;
|
|
94
148
|
dateProvider;
|
|
95
149
|
log;
|
|
96
150
|
tracer;
|
|
97
|
-
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
151
|
+
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
152
|
+
* Keyed by signed-payload hash so two proposals at the same (slot, archive) but with a
|
|
153
|
+
* different `feeAssetPriceModifier` (or any other signed field) are validated independently. */ lastCheckpointValidationResult;
|
|
98
154
|
/** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */ archiver;
|
|
99
155
|
/** Returns current validator addresses for own-proposal detection. Set via register(). */ getOwnValidatorAddresses;
|
|
100
|
-
|
|
156
|
+
/** P2P proposal pool access for deciding when retained proposals should block archiver processing. */ p2pClient;
|
|
157
|
+
checkpointProposalValidationFailureCallback;
|
|
158
|
+
/** Slots at which a slashable invalid block or checkpoint proposal was observed. */ slotsWithInvalidProposals;
|
|
159
|
+
/** Slots at which a proposal equivocation was observed; suppresses attested-to-invalid-proposal slashing. */ slotsWithProposalEquivocation;
|
|
160
|
+
constructor(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, timetable, config, blobClient, reexecutionTracker, metrics, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator:proposal-handler')){
|
|
101
161
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
102
162
|
this.worldState = worldState;
|
|
103
163
|
this.blockSource = blockSource;
|
|
@@ -105,23 +165,63 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
105
165
|
this.txProvider = txProvider;
|
|
106
166
|
this.blockProposalValidator = blockProposalValidator;
|
|
107
167
|
this.epochCache = epochCache;
|
|
168
|
+
this.timetable = timetable;
|
|
108
169
|
this.config = config;
|
|
109
170
|
this.blobClient = blobClient;
|
|
171
|
+
this.reexecutionTracker = reexecutionTracker;
|
|
110
172
|
this.metrics = metrics;
|
|
111
173
|
this.dateProvider = dateProvider;
|
|
112
174
|
this.log = log;
|
|
175
|
+
this.slotsWithInvalidProposals = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
176
|
+
this.slotsWithProposalEquivocation = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
113
177
|
if (config.fishermanMode) {
|
|
114
178
|
this.log = this.log.createChild('[FISHERMAN]');
|
|
115
179
|
}
|
|
116
180
|
this.tracer = telemetry.getTracer('ProposalHandler');
|
|
117
181
|
}
|
|
182
|
+
updateConfig(config) {
|
|
183
|
+
this.config = {
|
|
184
|
+
...this.config,
|
|
185
|
+
...config
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
setCheckpointProposalValidationFailureCallback(callback) {
|
|
189
|
+
this.checkpointProposalValidationFailureCallback = callback;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Records the proposer's own checkpoint proposal as a `valid` outcome in the re-execution
|
|
193
|
+
* tracker. Without this, the node's own checkpoint proposals never flow through
|
|
194
|
+
* `handleCheckpointProposal` (proposers don't validate their own proposals), so its sentinel
|
|
195
|
+
* sees no outcome for slots where it was the proposer and reports itself as inactive.
|
|
196
|
+
*
|
|
197
|
+
* `archive` should be the locally-computed archive (NOT the broadcast archive, which may have
|
|
198
|
+
* been deliberately corrupted in tests via `broadcastInvalidBlockProposal` /
|
|
199
|
+
* `broadcastInvalidCheckpointProposalOnly`). Recording the local archive correctly models the
|
|
200
|
+
* proposer's own view of its own work.
|
|
201
|
+
*/ recordOwnCheckpointProposalAsValid(slot, archive, checkpointNumber) {
|
|
202
|
+
this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
|
|
203
|
+
}
|
|
204
|
+
/** Whether a slashable invalid block or checkpoint proposal was observed at the given slot (InvalidProposalSlotSource). */ hasInvalidProposals(slotNumber) {
|
|
205
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
206
|
+
}
|
|
207
|
+
/** Whether a proposal equivocation was observed at the given slot (InvalidProposalSlotSource). */ hasProposalEquivocation(slotNumber) {
|
|
208
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
209
|
+
}
|
|
210
|
+
/** Records a slot as having a slashable invalid proposal, for offense observers (sentinel/slasher watchers). */ markInvalidProposalSlot(slotNumber) {
|
|
211
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
212
|
+
}
|
|
213
|
+
/** Records a slot as having a proposal equivocation, which suppresses attested-to-invalid-proposal slashing. */ markProposalEquivocation(slotNumber) {
|
|
214
|
+
this.slotsWithProposalEquivocation.add(slotNumber);
|
|
215
|
+
}
|
|
118
216
|
/**
|
|
119
217
|
* Registers handlers for block and checkpoint proposals on the p2p client.
|
|
218
|
+
* Records the p2p client so validation can inspect retained proposals.
|
|
120
219
|
* Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
|
|
121
220
|
* The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
|
|
122
221
|
* @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
|
|
123
222
|
* @param getOwnValidatorAddresses - Returns current validator addresses for own-proposal detection
|
|
124
223
|
*/ register(p2pClient, shouldReexecute, archiver, getOwnValidatorAddresses) {
|
|
224
|
+
this.p2pClient = p2pClient;
|
|
125
225
|
this.archiver = archiver;
|
|
126
226
|
this.getOwnValidatorAddresses = getOwnValidatorAddresses;
|
|
127
227
|
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
@@ -141,6 +241,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
141
241
|
});
|
|
142
242
|
return true;
|
|
143
243
|
} else {
|
|
244
|
+
// Track invalid proposals / equivocations so offense observers (the attested-invalid-proposal
|
|
245
|
+
// watcher) work on non-validator nodes too. Validators populate these via their own handlers.
|
|
246
|
+
// Skip invalid-proposal marking while the escape hatch is open, matching the validator path,
|
|
247
|
+
// which intentionally disables invalid-block slashing then.
|
|
248
|
+
if (result.reason === 'checkpoint_proposal_equivocation') {
|
|
249
|
+
this.markProposalEquivocation(slotNumber);
|
|
250
|
+
} else if (SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(result.reason) && !await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
251
|
+
this.markInvalidProposalSlot(slotNumber);
|
|
252
|
+
}
|
|
144
253
|
this.log.warn(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`, {
|
|
145
254
|
blockNumber: result.blockNumber,
|
|
146
255
|
slotNumber,
|
|
@@ -154,30 +263,61 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
154
263
|
}
|
|
155
264
|
};
|
|
156
265
|
p2pClient.registerBlockProposalHandler(blockHandler);
|
|
266
|
+
// p2p detects duplicate (equivocated) proposals without routing them through the handlers above, so mark
|
|
267
|
+
// the slot as equivocated here. This suppresses false-positive attested-to-invalid-proposal slashing on
|
|
268
|
+
// non-validator offense collectors. Validators overwrite this with their own richer handler.
|
|
269
|
+
p2pClient.registerDuplicateProposalCallback((info)=>this.markProposalEquivocation(info.slot));
|
|
157
270
|
// All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
|
|
158
271
|
// Runs for all nodes (validators and non-validators). Validators get the cached result in the
|
|
159
272
|
// validator-specific callback (attestToCheckpointProposal) which runs after this one.
|
|
160
273
|
const checkpointHandler = async (proposal, _sender)=>{
|
|
161
274
|
try {
|
|
275
|
+
const pipeliningTimer = new Timer();
|
|
162
276
|
const proposalInfo = {
|
|
163
277
|
slot: proposal.slotNumber,
|
|
164
278
|
archive: proposal.archive.toString(),
|
|
165
279
|
proposer: proposal.getSender()?.toString()
|
|
166
280
|
};
|
|
167
|
-
|
|
281
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
282
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
|
|
283
|
+
return undefined;
|
|
284
|
+
}
|
|
285
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
|
|
286
|
+
this.log.warn(`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`, proposalInfo);
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
// A proposal is "own" when it was signed by a validator key this node also owns. The true local
|
|
290
|
+
// proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
|
|
291
|
+
// proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
|
|
292
|
+
// shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
|
|
293
|
+
// nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
|
|
294
|
+
// proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
|
|
168
295
|
const proposer = proposal.getSender();
|
|
169
296
|
const ownAddresses = this.getOwnValidatorAddresses?.();
|
|
170
297
|
const isOwnProposal = proposer && ownAddresses?.some((addr)=>addr === proposer.toString());
|
|
171
298
|
if (isOwnProposal) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
299
|
+
const existing = await this.archiver?.getProposedCheckpointData({
|
|
300
|
+
slot: proposal.slotNumber
|
|
301
|
+
});
|
|
302
|
+
if (existing?.archive.root.equals(proposal.archive)) {
|
|
303
|
+
this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
|
|
304
|
+
return undefined;
|
|
175
305
|
}
|
|
176
|
-
return undefined;
|
|
177
306
|
}
|
|
178
307
|
const result = await this.handleCheckpointProposal(proposal, proposalInfo);
|
|
179
|
-
if (result.isValid
|
|
180
|
-
|
|
308
|
+
if (!result.isValid) {
|
|
309
|
+
// Track invalid checkpoint proposals so offense observers (the attested-invalid-proposal watcher)
|
|
310
|
+
// work on non-validator nodes too. This handler runs for all nodes; validators also mark via the
|
|
311
|
+
// failure callback below (idempotent).
|
|
312
|
+
if (SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
313
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
314
|
+
}
|
|
315
|
+
await this.checkpointProposalValidationFailureCallback?.(proposal, result, proposalInfo);
|
|
316
|
+
} else if (this.archiver) {
|
|
317
|
+
const set = await this.setProposedCheckpoint(proposal);
|
|
318
|
+
if (set) {
|
|
319
|
+
this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
|
|
320
|
+
}
|
|
181
321
|
}
|
|
182
322
|
} catch (err) {
|
|
183
323
|
this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, {
|
|
@@ -192,13 +332,12 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
192
332
|
async handleBlockProposal(proposal, proposalSender, shouldReexecute) {
|
|
193
333
|
const slotNumber = proposal.slotNumber;
|
|
194
334
|
const proposer = proposal.getSender();
|
|
195
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
196
335
|
// Reject proposals with invalid signatures
|
|
197
336
|
if (!proposer) {
|
|
198
337
|
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
199
338
|
return {
|
|
200
339
|
isValid: false,
|
|
201
|
-
reason: '
|
|
340
|
+
reason: 'invalid_signature'
|
|
202
341
|
};
|
|
203
342
|
}
|
|
204
343
|
const proposalInfo = {
|
|
@@ -221,23 +360,22 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
221
360
|
reason: 'invalid_proposal'
|
|
222
361
|
};
|
|
223
362
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
isValid: false,
|
|
237
|
-
reason: 'block_source_not_synced'
|
|
238
|
-
};
|
|
239
|
-
}
|
|
363
|
+
const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
|
|
364
|
+
if (!retainedSlotValidation.isValid) {
|
|
365
|
+
this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
|
|
366
|
+
...proposalInfo,
|
|
367
|
+
indexWithinCheckpoint: proposal.indexWithinCheckpoint,
|
|
368
|
+
reason: retainedSlotValidation.reason
|
|
369
|
+
});
|
|
370
|
+
return {
|
|
371
|
+
isValid: false,
|
|
372
|
+
blockNumber: proposal.blockNumber,
|
|
373
|
+
reason: retainedSlotValidation.reason
|
|
374
|
+
};
|
|
240
375
|
}
|
|
376
|
+
// The proposer builds ahead of L1 submission under pipelining, so the block source won't have
|
|
377
|
+
// synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
|
|
378
|
+
// eating into the attestation window.
|
|
241
379
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
242
380
|
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
243
381
|
// need to process other block proposals to get to it.
|
|
@@ -264,8 +402,12 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
264
402
|
// Compute the block number based on the parent block
|
|
265
403
|
const blockNumber = parentBlock === 'genesis' ? BlockNumber(INITIAL_L2_BLOCK_NUM) : BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
266
404
|
proposalInfo.blockNumber = blockNumber;
|
|
267
|
-
// Check that this block number does not exist already
|
|
268
|
-
|
|
405
|
+
// Check that this block number does not exist already. During a reorg the archiver can still hold a
|
|
406
|
+
// stale block at this number (a different archive, about to be pruned) while the proposal carries the
|
|
407
|
+
// rebuilt replacement; resolveExistingBlockAtNumber waits for the local prune in that case so the
|
|
408
|
+
// rebuilt block is processed in time to attest, rather than being permanently dropped on a bare
|
|
409
|
+
// number collision.
|
|
410
|
+
const existingBlock = await this.resolveExistingBlockAtNumber(blockNumber, proposal.archive, slotNumber);
|
|
269
411
|
if (existingBlock) {
|
|
270
412
|
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
271
413
|
return {
|
|
@@ -278,8 +420,10 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
278
420
|
// 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.
|
|
279
421
|
const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
280
422
|
pinnedPeer: proposalSender,
|
|
281
|
-
deadline: this.getReexecutionDeadline(slotNumber
|
|
423
|
+
deadline: this.getReexecutionDeadline(slotNumber)
|
|
282
424
|
});
|
|
425
|
+
// Record the tx-collection outcome on the re-execution tracker
|
|
426
|
+
this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
|
|
283
427
|
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
284
428
|
if (!shouldReexecute) {
|
|
285
429
|
this.log.info(`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, proposalInfo);
|
|
@@ -327,9 +471,18 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
327
471
|
reason: 'txs_not_available'
|
|
328
472
|
};
|
|
329
473
|
}
|
|
330
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
474
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
475
|
+
// Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
|
|
476
|
+
// yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
|
|
331
477
|
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
332
|
-
const previousCheckpointOutHashes =
|
|
478
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
479
|
+
blockSource: this.blockSource,
|
|
480
|
+
epoch,
|
|
481
|
+
checkpointNumber,
|
|
482
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
483
|
+
pipeliningEnabled: true,
|
|
484
|
+
log: this.log
|
|
485
|
+
});
|
|
333
486
|
// Try re-executing the transactions in the proposal if needed
|
|
334
487
|
let reexecutionResult;
|
|
335
488
|
try {
|
|
@@ -346,7 +499,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
346
499
|
};
|
|
347
500
|
}
|
|
348
501
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
349
|
-
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver
|
|
502
|
+
if (reexecutionResult?.block && !this.config.skipPushProposedBlocksToArchiver) {
|
|
350
503
|
await this.blockSource.addBlock(reexecutionResult.block);
|
|
351
504
|
}
|
|
352
505
|
this.log.info(`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, {
|
|
@@ -359,19 +512,50 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
359
512
|
reexecutionResult
|
|
360
513
|
};
|
|
361
514
|
}
|
|
515
|
+
async validateNewBlockInSlot(blockProposal) {
|
|
516
|
+
if (!this.p2pClient) {
|
|
517
|
+
return {
|
|
518
|
+
isValid: true
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const { blockProposals, checkpointProposals } = await this.p2pClient.getProposalsForSlot(blockProposal.slotNumber);
|
|
522
|
+
if (checkpointProposals.length === 0) {
|
|
523
|
+
return {
|
|
524
|
+
isValid: true
|
|
525
|
+
};
|
|
526
|
+
} else if (checkpointProposals.length > 1) {
|
|
527
|
+
return {
|
|
528
|
+
isValid: false,
|
|
529
|
+
reason: 'checkpoint_proposal_equivocation'
|
|
530
|
+
};
|
|
531
|
+
} else {
|
|
532
|
+
const checkpointProposal = checkpointProposals[0];
|
|
533
|
+
const terminalBlock = blockProposals.find((block)=>block.archive.equals(checkpointProposal.archive));
|
|
534
|
+
return terminalBlock !== undefined && blockProposal.indexWithinCheckpoint > terminalBlock.indexWithinCheckpoint ? {
|
|
535
|
+
isValid: false,
|
|
536
|
+
reason: 'block_proposal_beyond_checkpoint'
|
|
537
|
+
} : {
|
|
538
|
+
isValid: true
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
}
|
|
362
542
|
async getParentBlock(proposal) {
|
|
363
543
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
364
|
-
const slot = proposal.slotNumber;
|
|
365
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
366
544
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
367
545
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
368
546
|
return 'genesis';
|
|
369
547
|
}
|
|
370
|
-
const deadline = this.getReexecutionDeadline(
|
|
371
|
-
const
|
|
372
|
-
const timeoutDurationMs = deadline.getTime() - currentTime;
|
|
548
|
+
const deadline = this.getReexecutionDeadline(proposal.slotNumber);
|
|
549
|
+
const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
|
|
373
550
|
try {
|
|
374
|
-
return await this.blockSource.
|
|
551
|
+
return await this.blockSource.getBlockData({
|
|
552
|
+
archive: parentArchive
|
|
553
|
+
}) ?? (timeoutDurationMs <= 0 ? undefined : await retryUntil(()=>this.blockSource.syncImmediate().then(()=>this.blockSource.getBlockData({
|
|
554
|
+
archive: parentArchive
|
|
555
|
+
})), 'force archiver sync', {
|
|
556
|
+
deadline,
|
|
557
|
+
dateProvider: this.dateProvider
|
|
558
|
+
}, 0.5));
|
|
375
559
|
} catch (err) {
|
|
376
560
|
if (err instanceof TimeoutError) {
|
|
377
561
|
this.log.debug(`Timed out getting parent block by archive root`, {
|
|
@@ -385,6 +569,60 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
385
569
|
return undefined;
|
|
386
570
|
}
|
|
387
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* Resolves whether a block genuinely already exists at `blockNumber`. Returns the existing block only if
|
|
574
|
+
* it is a true duplicate of the proposal (matching archive). During a reorg the archiver can still hold a
|
|
575
|
+
* stale fork at this number (different archive) that is about to be pruned; in that case this forces L1
|
|
576
|
+
* sync and waits, bounded by the re-execution deadline, for the prune to land, then returns `undefined` so
|
|
577
|
+
* the rebuilt block proposal can be processed in time to attest. If the prune does not complete before the
|
|
578
|
+
* deadline it returns the stale block, so the caller falls back to the safe `block_number_already_exists`
|
|
579
|
+
* rejection.
|
|
580
|
+
*/ async resolveExistingBlockAtNumber(blockNumber, proposalArchive, slotNumber) {
|
|
581
|
+
const existingBlock = await this.blockSource.getBlockData({
|
|
582
|
+
number: blockNumber
|
|
583
|
+
});
|
|
584
|
+
if (!existingBlock || existingBlock.archive.root.equals(proposalArchive)) {
|
|
585
|
+
return existingBlock;
|
|
586
|
+
}
|
|
587
|
+
// A different block already occupies this number: it may be a stale fork being pruned during a reorg, not a
|
|
588
|
+
// genuine duplicate. Wait for the local prune rather than permanently rejecting the proposal.
|
|
589
|
+
const deadline = this.getReexecutionDeadline(slotNumber);
|
|
590
|
+
if (deadline.getTime() - this.dateProvider.now() <= 0) {
|
|
591
|
+
return existingBlock;
|
|
592
|
+
}
|
|
593
|
+
this.log.warn(`Block number ${blockNumber} already exists, awaiting potential prune`, {
|
|
594
|
+
blockNumber,
|
|
595
|
+
existingArchive: existingBlock.archive.root.toString(),
|
|
596
|
+
proposalArchive: proposalArchive.toString()
|
|
597
|
+
});
|
|
598
|
+
try {
|
|
599
|
+
const { block } = await retryUntil(async ()=>{
|
|
600
|
+
await this.blockSource.syncImmediate();
|
|
601
|
+
const block = await this.blockSource.getBlockData({
|
|
602
|
+
number: blockNumber
|
|
603
|
+
});
|
|
604
|
+
// Resolve once the existing block is gone (pruned) or has been replaced by one matching the
|
|
605
|
+
// proposal — the same condition as the early return above. A matching block is returned so the
|
|
606
|
+
// caller still treats it as a genuine duplicate; an `undefined` (pruned) block lets the proposal
|
|
607
|
+
// be processed. Wrap in an object so the `undefined` case is still a truthy retry result.
|
|
608
|
+
return block === undefined || block.archive.root.equals(proposalArchive) ? {
|
|
609
|
+
block
|
|
610
|
+
} : undefined;
|
|
611
|
+
}, `prune of stale block ${blockNumber}`, {
|
|
612
|
+
deadline,
|
|
613
|
+
dateProvider: this.dateProvider
|
|
614
|
+
}, 0.5);
|
|
615
|
+
return block;
|
|
616
|
+
} catch (err) {
|
|
617
|
+
if (err instanceof TimeoutError) {
|
|
618
|
+
this.log.warn(`Timed out waiting for stale block ${blockNumber} to be pruned`, {
|
|
619
|
+
blockNumber
|
|
620
|
+
});
|
|
621
|
+
return existingBlock;
|
|
622
|
+
}
|
|
623
|
+
throw err;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
388
626
|
computeCheckpointNumber(proposal, parentBlock, proposalInfo) {
|
|
389
627
|
if (parentBlock === 'genesis') {
|
|
390
628
|
// First block is in checkpoint 1
|
|
@@ -513,36 +751,13 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
513
751
|
}
|
|
514
752
|
return undefined;
|
|
515
753
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
if (slot === 0) {
|
|
524
|
-
return true;
|
|
525
|
-
}
|
|
526
|
-
// Make a quick check before triggering an archiver sync
|
|
527
|
-
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
528
|
-
if (syncedSlot !== undefined && syncedSlot + 1 >= slot) {
|
|
529
|
-
return true;
|
|
530
|
-
}
|
|
531
|
-
try {
|
|
532
|
-
// Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
|
|
533
|
-
return await retryUntil(async ()=>{
|
|
534
|
-
await this.blockSource.syncImmediate();
|
|
535
|
-
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
536
|
-
return syncedSlot !== undefined && syncedSlot + 1 >= slot;
|
|
537
|
-
}, 'wait for block source sync', timeoutMs / 1000, 0.5);
|
|
538
|
-
} catch (err) {
|
|
539
|
-
if (err instanceof TimeoutError) {
|
|
540
|
-
this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
|
|
541
|
-
return false;
|
|
542
|
-
} else {
|
|
543
|
-
throw err;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
754
|
+
/**
|
|
755
|
+
* Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
|
|
756
|
+
* the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
|
|
757
|
+
* checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
|
|
758
|
+
* next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
|
|
759
|
+
*/ getReexecutionDeadline(slotNumber) {
|
|
760
|
+
return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
|
|
546
761
|
}
|
|
547
762
|
getReexecuteFailureReason(err) {
|
|
548
763
|
if (err instanceof TransactionsNotAvailableError) {
|
|
@@ -570,7 +785,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
570
785
|
// If we do not have all of the transactions, then we should fail
|
|
571
786
|
if (txs.length !== txHashes.length) {
|
|
572
787
|
const foundTxHashes = txs.map((tx)=>tx.getTxHash());
|
|
573
|
-
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.
|
|
788
|
+
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.some((h)=>h.equals(txHash)));
|
|
574
789
|
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
575
790
|
}
|
|
576
791
|
const timer = new Timer();
|
|
@@ -602,7 +817,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
602
817
|
// Create checkpoint builder with prior blocks
|
|
603
818
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, priorBlocks, this.log.getBindings());
|
|
604
819
|
// Build the new block
|
|
605
|
-
const deadline = this.getReexecutionDeadline(slot
|
|
820
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
606
821
|
const maxBlockGas = this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity) : undefined;
|
|
607
822
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
608
823
|
isBuildingProposal: false,
|
|
@@ -666,44 +881,48 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
666
881
|
* Used by both the all-nodes callback (via register) and the validator client (via delegation).
|
|
667
882
|
*/ async handleCheckpointProposal(proposal, proposalInfo) {
|
|
668
883
|
const slot = proposal.slotNumber;
|
|
669
|
-
|
|
670
|
-
|
|
884
|
+
const payloadHash = proposal.getPayloadHash();
|
|
885
|
+
// Check cache: same signed-payload hash means we already validated this exact proposal.
|
|
886
|
+
if (this.lastCheckpointValidationResult && this.lastCheckpointValidationResult.payloadHash === payloadHash) {
|
|
671
887
|
this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
|
|
672
888
|
return this.lastCheckpointValidationResult.result;
|
|
673
889
|
}
|
|
674
890
|
const proposer = proposal.getSender();
|
|
891
|
+
let result;
|
|
675
892
|
if (!proposer) {
|
|
676
893
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
|
|
677
|
-
|
|
894
|
+
result = {
|
|
678
895
|
isValid: false,
|
|
679
896
|
reason: 'invalid_signature'
|
|
680
897
|
};
|
|
681
|
-
|
|
682
|
-
archive: proposal.archive,
|
|
683
|
-
slotNumber: slot,
|
|
684
|
-
result
|
|
685
|
-
};
|
|
686
|
-
return result;
|
|
687
|
-
}
|
|
688
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
898
|
+
} else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
689
899
|
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`);
|
|
690
|
-
|
|
900
|
+
result = {
|
|
691
901
|
isValid: false,
|
|
692
902
|
reason: 'invalid_fee_asset_price_modifier'
|
|
693
903
|
};
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
slotNumber: slot,
|
|
697
|
-
result
|
|
698
|
-
};
|
|
699
|
-
return result;
|
|
904
|
+
} else {
|
|
905
|
+
result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
700
906
|
}
|
|
701
|
-
const result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
702
907
|
this.lastCheckpointValidationResult = {
|
|
703
|
-
|
|
704
|
-
slotNumber: slot,
|
|
908
|
+
payloadHash,
|
|
705
909
|
result
|
|
706
910
|
};
|
|
911
|
+
// Record the outcome on the re-execution tracker.
|
|
912
|
+
const outcome = result.isValid ? 'valid' : CHECKPOINT_VALIDATION_REASON_TO_OUTCOME[result.reason];
|
|
913
|
+
if (outcome !== undefined) {
|
|
914
|
+
this.reexecutionTracker.recordOutcome(slot, proposal.archive, outcome, result.checkpointNumber);
|
|
915
|
+
}
|
|
916
|
+
// Drop tracker entries for checkpoints that have reached L1 finality.
|
|
917
|
+
try {
|
|
918
|
+
const tips = await this.blockSource.getL2Tips();
|
|
919
|
+
const finalizedCheckpointNumber = tips.finalized.checkpoint.number;
|
|
920
|
+
if (finalizedCheckpointNumber > 0) {
|
|
921
|
+
this.reexecutionTracker.removeBefore(CheckpointNumber(finalizedCheckpointNumber + 1));
|
|
922
|
+
}
|
|
923
|
+
} catch (err) {
|
|
924
|
+
this.log.error(`Error pruning reexecution tracker`, err, proposalInfo);
|
|
925
|
+
}
|
|
707
926
|
// Upload blobs to filestore if validation passed (fire and forget)
|
|
708
927
|
if (result.isValid) {
|
|
709
928
|
this.tryUploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
@@ -721,17 +940,25 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
721
940
|
};
|
|
722
941
|
try {
|
|
723
942
|
const slot = proposal.slotNumber;
|
|
724
|
-
//
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
943
|
+
// Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
|
|
944
|
+
// - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
|
|
945
|
+
// the target slot. Keeping validation/attestation alive until then lets validators keep attesting
|
|
946
|
+
// right up to the proposer's real publish cutoff.
|
|
947
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
948
|
+
// Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
|
|
949
|
+
// the remaining budget is derived from the date provider; a deadline already in the past times out
|
|
950
|
+
// after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
|
|
951
|
+
let lastBlockData;
|
|
730
952
|
try {
|
|
731
|
-
|
|
953
|
+
lastBlockData = await retryUntil(async ()=>{
|
|
732
954
|
await this.blockSource.syncImmediate();
|
|
733
|
-
return this.blockSource.
|
|
734
|
-
|
|
955
|
+
return await this.blockSource.getBlockData({
|
|
956
|
+
archive: proposal.archive
|
|
957
|
+
});
|
|
958
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
|
|
959
|
+
deadline,
|
|
960
|
+
dateProvider: this.dateProvider
|
|
961
|
+
}, 0.5);
|
|
735
962
|
} catch (err) {
|
|
736
963
|
if (err instanceof TimeoutError) {
|
|
737
964
|
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
@@ -746,20 +973,36 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
746
973
|
reason: 'block_fetch_error'
|
|
747
974
|
};
|
|
748
975
|
}
|
|
749
|
-
if (!
|
|
976
|
+
if (!lastBlockData) {
|
|
750
977
|
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
751
978
|
return {
|
|
752
979
|
isValid: false,
|
|
753
980
|
reason: 'last_block_not_found'
|
|
754
981
|
};
|
|
755
982
|
}
|
|
983
|
+
// Refuse to attest if the block's enclosing checkpoint has already been published to L1.
|
|
984
|
+
const existingCheckpoint = await this.blockSource.getCheckpointData({
|
|
985
|
+
number: lastBlockData.checkpointNumber
|
|
986
|
+
});
|
|
987
|
+
if (existingCheckpoint) {
|
|
988
|
+
this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
|
|
989
|
+
...proposalInfo,
|
|
990
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
991
|
+
});
|
|
992
|
+
return {
|
|
993
|
+
isValid: false,
|
|
994
|
+
reason: 'checkpoint_already_published',
|
|
995
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
996
|
+
};
|
|
997
|
+
}
|
|
756
998
|
// Get all full blocks for the slot and checkpoint
|
|
757
999
|
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
758
1000
|
if (blocks.length === 0) {
|
|
759
1001
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
760
1002
|
return {
|
|
761
1003
|
isValid: false,
|
|
762
|
-
reason: 'no_blocks_for_slot'
|
|
1004
|
+
reason: 'no_blocks_for_slot',
|
|
1005
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
763
1006
|
};
|
|
764
1007
|
}
|
|
765
1008
|
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
@@ -767,7 +1010,22 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
767
1010
|
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
768
1011
|
return {
|
|
769
1012
|
isValid: false,
|
|
770
|
-
reason: 'last_block_archive_mismatch'
|
|
1013
|
+
reason: 'last_block_archive_mismatch',
|
|
1014
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
// Note this condition should never trigger, since we dont process block proposals that exceed indexWithinCheckpoint
|
|
1018
|
+
const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
|
|
1019
|
+
if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
|
|
1020
|
+
this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
|
|
1021
|
+
...proposalInfo,
|
|
1022
|
+
blocksInProposal: blocks.length,
|
|
1023
|
+
maxBlocksPerCheckpoint
|
|
1024
|
+
});
|
|
1025
|
+
return {
|
|
1026
|
+
isValid: false,
|
|
1027
|
+
reason: 'too_many_blocks_in_checkpoint',
|
|
1028
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
771
1029
|
};
|
|
772
1030
|
}
|
|
773
1031
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
@@ -780,9 +1038,17 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
780
1038
|
const checkpointNumber = firstBlock.checkpointNumber;
|
|
781
1039
|
// Get L1-to-L2 messages for this checkpoint
|
|
782
1040
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
783
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
1041
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
1042
|
+
// See note on the analogous block-proposal site: the helper handles pipelining lag.
|
|
784
1043
|
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
785
|
-
const previousCheckpointOutHashes =
|
|
1044
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
1045
|
+
blockSource: this.blockSource,
|
|
1046
|
+
epoch,
|
|
1047
|
+
checkpointNumber,
|
|
1048
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
1049
|
+
pipeliningEnabled: true,
|
|
1050
|
+
log: this.log
|
|
1051
|
+
});
|
|
786
1052
|
// Fork world state at the block before the first block
|
|
787
1053
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
788
1054
|
const fork = _ts_add_disposable_resource(env, await this.checkpointsBuilder.getFork(parentBlockNumber), true);
|
|
@@ -799,7 +1065,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
799
1065
|
});
|
|
800
1066
|
return {
|
|
801
1067
|
isValid: false,
|
|
802
|
-
reason: 'checkpoint_header_mismatch'
|
|
1068
|
+
reason: 'checkpoint_header_mismatch',
|
|
1069
|
+
checkpointNumber
|
|
803
1070
|
};
|
|
804
1071
|
}
|
|
805
1072
|
// Compare archive root with proposal
|
|
@@ -811,7 +1078,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
811
1078
|
});
|
|
812
1079
|
return {
|
|
813
1080
|
isValid: false,
|
|
814
|
-
reason: 'archive_mismatch'
|
|
1081
|
+
reason: 'archive_mismatch',
|
|
1082
|
+
checkpointNumber
|
|
815
1083
|
};
|
|
816
1084
|
}
|
|
817
1085
|
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
@@ -832,7 +1100,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
832
1100
|
});
|
|
833
1101
|
return {
|
|
834
1102
|
isValid: false,
|
|
835
|
-
reason: 'out_hash_mismatch'
|
|
1103
|
+
reason: 'out_hash_mismatch',
|
|
1104
|
+
checkpointNumber
|
|
836
1105
|
};
|
|
837
1106
|
}
|
|
838
1107
|
// Final round of validations on the checkpoint, just in case.
|
|
@@ -848,12 +1117,14 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
848
1117
|
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
849
1118
|
return {
|
|
850
1119
|
isValid: false,
|
|
851
|
-
reason: 'checkpoint_validation_failed'
|
|
1120
|
+
reason: 'checkpoint_validation_failed',
|
|
1121
|
+
checkpointNumber
|
|
852
1122
|
};
|
|
853
1123
|
}
|
|
854
1124
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
855
1125
|
return {
|
|
856
|
-
isValid: true
|
|
1126
|
+
isValid: true,
|
|
1127
|
+
checkpointNumber
|
|
857
1128
|
};
|
|
858
1129
|
} catch (e) {
|
|
859
1130
|
env.error = e;
|
|
@@ -882,7 +1153,9 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
882
1153
|
}
|
|
883
1154
|
/** Uploads blobs for a checkpoint to the filestore. */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
884
1155
|
try {
|
|
885
|
-
const lastBlockHeader = await this.blockSource.
|
|
1156
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
1157
|
+
archive: proposal.archive
|
|
1158
|
+
}))?.header;
|
|
886
1159
|
if (!lastBlockHeader) {
|
|
887
1160
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
888
1161
|
return;
|
|
@@ -905,21 +1178,23 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
905
1178
|
}
|
|
906
1179
|
}
|
|
907
1180
|
/**
|
|
908
|
-
* Derives proposed checkpoint data from validated blocks and sets it on the archiver
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*/ async
|
|
1181
|
+
* Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
|
|
1182
|
+
* pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
|
|
1183
|
+
* last block to sync.
|
|
1184
|
+
*/ async setProposedCheckpoint(proposal) {
|
|
912
1185
|
if (!this.archiver) {
|
|
913
|
-
return;
|
|
1186
|
+
return false;
|
|
914
1187
|
}
|
|
915
|
-
const blockData = await this.blockSource.
|
|
1188
|
+
const blockData = await this.blockSource.getBlockData({
|
|
1189
|
+
archive: proposal.archive
|
|
1190
|
+
});
|
|
916
1191
|
if (!blockData) {
|
|
917
1192
|
this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
|
|
918
1193
|
archive: proposal.archive.toString()
|
|
919
1194
|
});
|
|
920
|
-
return;
|
|
1195
|
+
return false;
|
|
921
1196
|
}
|
|
922
|
-
await this.archiver.
|
|
1197
|
+
await this.archiver.addProposedCheckpoint({
|
|
923
1198
|
header: proposal.checkpointHeader,
|
|
924
1199
|
checkpointNumber: blockData.checkpointNumber,
|
|
925
1200
|
startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
|
|
@@ -927,37 +1202,6 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
927
1202
|
totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
|
|
928
1203
|
feeAssetPriceModifier: proposal.feeAssetPriceModifier
|
|
929
1204
|
});
|
|
930
|
-
|
|
931
|
-
/**
|
|
932
|
-
* Sets proposed checkpoint from blocks for own proposals (skips full validation).
|
|
933
|
-
* Retries fetching block data since the checkpoint proposal often arrives before the last block
|
|
934
|
-
* finishes re-execution.
|
|
935
|
-
*/ async setProposedCheckpointFromBlocks(proposal) {
|
|
936
|
-
if (!this.archiver) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
let blockData = await this.blockSource.getBlockDataByArchive(proposal.archive);
|
|
940
|
-
if (!blockData) {
|
|
941
|
-
// The checkpoint proposal often arrives before the last block finishes re-execution.
|
|
942
|
-
// Retry until we find the data or give up at the end of the slot.
|
|
943
|
-
const nextSlot = this.epochCache.getSlotNow() + 1;
|
|
944
|
-
const timeOfNextSlot = getTimestampForSlot(SlotNumber(nextSlot), await this.archiver.getL1Constants());
|
|
945
|
-
const timeoutSeconds = Math.max(1, Number(timeOfNextSlot) - Math.floor(this.dateProvider.now() / 1000));
|
|
946
|
-
blockData = await retryUntil(()=>this.blockSource.getBlockDataByArchive(proposal.archive), 'block data for own checkpoint proposal', timeoutSeconds, 0.25).catch(()=>undefined);
|
|
947
|
-
}
|
|
948
|
-
if (blockData) {
|
|
949
|
-
await this.archiver.setProposedCheckpoint({
|
|
950
|
-
header: proposal.checkpointHeader,
|
|
951
|
-
checkpointNumber: blockData.checkpointNumber,
|
|
952
|
-
startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
|
|
953
|
-
blockCount: blockData.indexWithinCheckpoint + 1,
|
|
954
|
-
totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
|
|
955
|
-
feeAssetPriceModifier: proposal.feeAssetPriceModifier
|
|
956
|
-
});
|
|
957
|
-
} else {
|
|
958
|
-
this.log.debug(`Block data not found for own checkpoint proposal archive, cannot set proposed checkpoint`, {
|
|
959
|
-
archive: proposal.archive.toString()
|
|
960
|
-
});
|
|
961
|
-
}
|
|
1205
|
+
return true;
|
|
962
1206
|
}
|
|
963
1207
|
}
|