@aztec/validator-client 0.0.1-commit.993d240 → 0.0.1-commit.9a89641
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 +2 -0
- package/dest/checkpoint_builder.d.ts +17 -7
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +26 -9
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +9 -1
- package/dest/factory.d.ts +1 -1
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +10 -3
- 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 +1 -1
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +3 -1
- package/dest/proposal_handler.d.ts +39 -8
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +290 -98
- package/dest/validator.d.ts +11 -5
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +54 -43
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +28 -10
- package/src/config.ts +16 -3
- package/src/factory.ts +9 -1
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +2 -0
- package/src/proposal_handler.ts +309 -107
- package/src/validator.ts +63 -46
package/dest/proposal_handler.js
CHANGED
|
@@ -66,19 +66,21 @@ 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';
|
|
77
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
76
78
|
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
77
|
-
import { getEpochAtSlot
|
|
79
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
78
80
|
import { Gas } from '@aztec/stdlib/gas';
|
|
79
81
|
import { accumulateCheckpointOutHashes, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
80
82
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
81
|
-
import { ReExFailedTxsError, ReExInitialStateMismatchError, ReExStateMismatchError, ReExTimeoutError, TransactionsNotAvailableError } from '@aztec/stdlib/validators';
|
|
83
|
+
import { InvalidBlockProposalTxsError, ReExFailedTxsError, ReExInitialStateMismatchError, ReExStateMismatchError, ReExTimeoutError, TransactionsNotAvailableError } from '@aztec/stdlib/validators';
|
|
82
84
|
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
83
85
|
/**
|
|
84
86
|
* Mapping from a checkpoint-proposal validation failure reason to the tracker outcome that
|
|
@@ -90,6 +92,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
90
92
|
checkpoint_already_published: undefined,
|
|
91
93
|
last_block_not_found: 'unvalidated',
|
|
92
94
|
block_fetch_error: 'unvalidated',
|
|
95
|
+
world_state_not_synced: 'unvalidated',
|
|
96
|
+
initial_archive_mismatch: 'unvalidated',
|
|
93
97
|
no_blocks_for_slot: 'unvalidated',
|
|
94
98
|
last_block_archive_mismatch: 'invalid',
|
|
95
99
|
too_many_blocks_in_checkpoint: 'invalid',
|
|
@@ -98,7 +102,45 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
98
102
|
out_hash_mismatch: 'invalid',
|
|
99
103
|
checkpoint_validation_failed: 'invalid'
|
|
100
104
|
};
|
|
101
|
-
|
|
105
|
+
const MAX_TRACKED_INVALID_PROPOSAL_SLOTS = 1000;
|
|
106
|
+
/** Block-proposal validation failures that constitute a slashable invalid-block offense. */ export const SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT = [
|
|
107
|
+
'state_mismatch',
|
|
108
|
+
'failed_txs',
|
|
109
|
+
'global_variables_mismatch',
|
|
110
|
+
'invalid_proposal',
|
|
111
|
+
'parent_block_wrong_slot',
|
|
112
|
+
'in_hash_mismatch',
|
|
113
|
+
'duplicate_txs',
|
|
114
|
+
'invalid_embedded_txs'
|
|
115
|
+
];
|
|
116
|
+
/** Checkpoint-proposal validation failures that constitute a slashable invalid-checkpoint offense. */ export const SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT = {
|
|
117
|
+
// enabled
|
|
118
|
+
['invalid_fee_asset_price_modifier']: true,
|
|
119
|
+
['checkpoint_header_mismatch']: true,
|
|
120
|
+
// These late mismatches should normally be caught by earlier checks, but if reached after validating the local
|
|
121
|
+
// checkpoint inputs, the proposer-signed payload disagrees with deterministic recomputation.
|
|
122
|
+
['archive_mismatch']: true,
|
|
123
|
+
['out_hash_mismatch']: true,
|
|
124
|
+
['no_blocks_for_slot']: true,
|
|
125
|
+
['too_many_blocks_in_checkpoint']: true,
|
|
126
|
+
['checkpoint_validation_failed']: true,
|
|
127
|
+
['last_block_archive_mismatch']: true,
|
|
128
|
+
// disabled
|
|
129
|
+
['invalid_signature']: false,
|
|
130
|
+
['last_block_not_found']: false,
|
|
131
|
+
['block_fetch_error']: false,
|
|
132
|
+
['world_state_not_synced']: false,
|
|
133
|
+
// A reorg / divergent local chain, not a proposer offense (mirrors the block path's initial_state_mismatch).
|
|
134
|
+
['initial_archive_mismatch']: false,
|
|
135
|
+
['checkpoint_already_published']: false
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Handles block and checkpoint proposals for both validator and non-validator nodes. Also tracks which slots
|
|
139
|
+
* had a slashable invalid proposal or a proposal equivocation, exposing them via the
|
|
140
|
+
* `InvalidProposalSlotSource` interface consumed by the attested-invalid-proposal slashing watcher. The
|
|
141
|
+
* tracking is populated as a side effect of validating/re-executing proposals, so any node that re-executes
|
|
142
|
+
* proposals (the default) can serve it — not only validators.
|
|
143
|
+
*/ export class ProposalHandler {
|
|
102
144
|
checkpointsBuilder;
|
|
103
145
|
worldState;
|
|
104
146
|
blockSource;
|
|
@@ -106,6 +148,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
106
148
|
txProvider;
|
|
107
149
|
blockProposalValidator;
|
|
108
150
|
epochCache;
|
|
151
|
+
timetable;
|
|
109
152
|
config;
|
|
110
153
|
blobClient;
|
|
111
154
|
reexecutionTracker;
|
|
@@ -120,7 +163,9 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
120
163
|
/** Returns current validator addresses for own-proposal detection. Set via register(). */ getOwnValidatorAddresses;
|
|
121
164
|
/** P2P proposal pool access for deciding when retained proposals should block archiver processing. */ p2pClient;
|
|
122
165
|
checkpointProposalValidationFailureCallback;
|
|
123
|
-
|
|
166
|
+
/** Slots at which a slashable invalid block or checkpoint proposal was observed. */ slotsWithInvalidProposals;
|
|
167
|
+
/** Slots at which a proposal equivocation was observed; suppresses attested-to-invalid-proposal slashing. */ slotsWithProposalEquivocation;
|
|
168
|
+
constructor(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, blockProposalValidator, epochCache, timetable, config, blobClient, reexecutionTracker, metrics, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator:proposal-handler')){
|
|
124
169
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
125
170
|
this.worldState = worldState;
|
|
126
171
|
this.blockSource = blockSource;
|
|
@@ -128,12 +173,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
128
173
|
this.txProvider = txProvider;
|
|
129
174
|
this.blockProposalValidator = blockProposalValidator;
|
|
130
175
|
this.epochCache = epochCache;
|
|
176
|
+
this.timetable = timetable;
|
|
131
177
|
this.config = config;
|
|
132
178
|
this.blobClient = blobClient;
|
|
133
179
|
this.reexecutionTracker = reexecutionTracker;
|
|
134
180
|
this.metrics = metrics;
|
|
135
181
|
this.dateProvider = dateProvider;
|
|
136
182
|
this.log = log;
|
|
183
|
+
this.slotsWithInvalidProposals = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
184
|
+
this.slotsWithProposalEquivocation = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
137
185
|
if (config.fishermanMode) {
|
|
138
186
|
this.log = this.log.createChild('[FISHERMAN]');
|
|
139
187
|
}
|
|
@@ -161,6 +209,18 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
161
209
|
*/ recordOwnCheckpointProposalAsValid(slot, archive, checkpointNumber) {
|
|
162
210
|
this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
|
|
163
211
|
}
|
|
212
|
+
/** Whether a slashable invalid block or checkpoint proposal was observed at the given slot (InvalidProposalSlotSource). */ hasInvalidProposals(slotNumber) {
|
|
213
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
214
|
+
}
|
|
215
|
+
/** Whether a proposal equivocation was observed at the given slot (InvalidProposalSlotSource). */ hasProposalEquivocation(slotNumber) {
|
|
216
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
217
|
+
}
|
|
218
|
+
/** Records a slot as having a slashable invalid proposal, for offense observers (sentinel/slasher watchers). */ markInvalidProposalSlot(slotNumber) {
|
|
219
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
220
|
+
}
|
|
221
|
+
/** Records a slot as having a proposal equivocation, which suppresses attested-to-invalid-proposal slashing. */ markProposalEquivocation(slotNumber) {
|
|
222
|
+
this.slotsWithProposalEquivocation.add(slotNumber);
|
|
223
|
+
}
|
|
164
224
|
/**
|
|
165
225
|
* Registers handlers for block and checkpoint proposals on the p2p client.
|
|
166
226
|
* Records the p2p client so validation can inspect retained proposals.
|
|
@@ -189,6 +249,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
189
249
|
});
|
|
190
250
|
return true;
|
|
191
251
|
} else {
|
|
252
|
+
// Track invalid proposals / equivocations so offense observers (the attested-invalid-proposal
|
|
253
|
+
// watcher) work on non-validator nodes too. Validators populate these via their own handlers.
|
|
254
|
+
// Skip invalid-proposal marking while the escape hatch is open, matching the validator path,
|
|
255
|
+
// which intentionally disables invalid-block slashing then.
|
|
256
|
+
if (result.reason === 'checkpoint_proposal_equivocation') {
|
|
257
|
+
this.markProposalEquivocation(slotNumber);
|
|
258
|
+
} else if (SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(result.reason) && !await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
259
|
+
this.markInvalidProposalSlot(slotNumber);
|
|
260
|
+
}
|
|
192
261
|
this.log.warn(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`, {
|
|
193
262
|
blockNumber: result.blockNumber,
|
|
194
263
|
slotNumber,
|
|
@@ -202,6 +271,10 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
202
271
|
}
|
|
203
272
|
};
|
|
204
273
|
p2pClient.registerBlockProposalHandler(blockHandler);
|
|
274
|
+
// p2p detects duplicate (equivocated) proposals without routing them through the handlers above, so mark
|
|
275
|
+
// the slot as equivocated here. This suppresses false-positive attested-to-invalid-proposal slashing on
|
|
276
|
+
// non-validator offense collectors. Validators overwrite this with their own richer handler.
|
|
277
|
+
p2pClient.registerDuplicateProposalCallback((info)=>this.markProposalEquivocation(info.slot));
|
|
205
278
|
// All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
|
|
206
279
|
// Runs for all nodes (validators and non-validators). Validators get the cached result in the
|
|
207
280
|
// validator-specific callback (attestToCheckpointProposal) which runs after this one.
|
|
@@ -221,23 +294,35 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
221
294
|
this.log.warn(`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`, proposalInfo);
|
|
222
295
|
return undefined;
|
|
223
296
|
}
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
297
|
+
// A proposal is "own" when it was signed by a validator key this node also owns. The true local
|
|
298
|
+
// proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
|
|
299
|
+
// proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
|
|
300
|
+
// shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
|
|
301
|
+
// nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
|
|
302
|
+
// proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
|
|
229
303
|
const proposer = proposal.getSender();
|
|
230
304
|
const ownAddresses = this.getOwnValidatorAddresses?.();
|
|
231
305
|
const isOwnProposal = proposer && ownAddresses?.some((addr)=>addr === proposer.toString());
|
|
232
306
|
if (isOwnProposal) {
|
|
233
|
-
|
|
234
|
-
|
|
307
|
+
const existing = await this.archiver?.getProposedCheckpointData({
|
|
308
|
+
slot: proposal.slotNumber
|
|
309
|
+
});
|
|
310
|
+
if (existing?.archive.root.equals(proposal.archive)) {
|
|
311
|
+
this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
235
314
|
}
|
|
236
315
|
const result = await this.handleCheckpointProposal(proposal, proposalInfo);
|
|
237
316
|
if (!result.isValid) {
|
|
317
|
+
// Track invalid checkpoint proposals so offense observers (the attested-invalid-proposal watcher)
|
|
318
|
+
// work on non-validator nodes too. This handler runs for all nodes; validators also mark via the
|
|
319
|
+
// failure callback below (idempotent).
|
|
320
|
+
if (SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
321
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
322
|
+
}
|
|
238
323
|
await this.checkpointProposalValidationFailureCallback?.(proposal, result, proposalInfo);
|
|
239
|
-
} else if (this.archiver
|
|
240
|
-
const set = await this.
|
|
324
|
+
} else if (this.archiver) {
|
|
325
|
+
const set = await this.setProposedCheckpoint(proposal);
|
|
241
326
|
if (set) {
|
|
242
327
|
this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
|
|
243
328
|
}
|
|
@@ -255,7 +340,6 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
255
340
|
async handleBlockProposal(proposal, proposalSender, shouldReexecute) {
|
|
256
341
|
const slotNumber = proposal.slotNumber;
|
|
257
342
|
const proposer = proposal.getSender();
|
|
258
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
259
343
|
// Reject proposals with invalid signatures
|
|
260
344
|
if (!proposer) {
|
|
261
345
|
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
@@ -284,6 +368,22 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
284
368
|
reason: 'invalid_proposal'
|
|
285
369
|
};
|
|
286
370
|
}
|
|
371
|
+
// A tx can only appear once in a block: the second copy would emit nullifiers already emitted by the
|
|
372
|
+
// first. This is not a relaying-peer fault, so it passes gossip validation and is classified here as
|
|
373
|
+
// proposer misbehavior. Tx collection also reconciles a deduplicated hash set against the full list,
|
|
374
|
+
// so it must not be handed a proposal with repeated hashes.
|
|
375
|
+
const uniqueTxHashes = new Set(proposal.txHashes.map((txHash)=>txHash.toString()));
|
|
376
|
+
if (uniqueTxHashes.size !== proposal.txHashes.length) {
|
|
377
|
+
this.log.warn(`Proposal lists duplicate tx hashes, skipping processing`, {
|
|
378
|
+
...proposalInfo,
|
|
379
|
+
txCount: proposal.txHashes.length,
|
|
380
|
+
uniqueTxCount: uniqueTxHashes.size
|
|
381
|
+
});
|
|
382
|
+
return {
|
|
383
|
+
isValid: false,
|
|
384
|
+
reason: 'duplicate_txs'
|
|
385
|
+
};
|
|
386
|
+
}
|
|
287
387
|
const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
|
|
288
388
|
if (!retainedSlotValidation.isValid) {
|
|
289
389
|
this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
|
|
@@ -297,23 +397,9 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
297
397
|
reason: retainedSlotValidation.reason
|
|
298
398
|
};
|
|
299
399
|
}
|
|
300
|
-
//
|
|
301
|
-
//
|
|
302
|
-
//
|
|
303
|
-
// checkpoint prune could remove a block that would conflict with this proposal.
|
|
304
|
-
// When pipelining is enabled, the proposer builds ahead of L1 submission, so the
|
|
305
|
-
// block source won't have synced to the proposed slot yet. Skip the sync wait to
|
|
306
|
-
// avoid eating into the attestation window.
|
|
307
|
-
if (!this.epochCache.isProposerPipeliningEnabled()) {
|
|
308
|
-
const blockSourceSync = await this.waitForBlockSourceSync(slotNumber);
|
|
309
|
-
if (!blockSourceSync) {
|
|
310
|
-
this.log.warn(`Block source is not synced, skipping processing`, proposalInfo);
|
|
311
|
-
return {
|
|
312
|
-
isValid: false,
|
|
313
|
-
reason: 'block_source_not_synced'
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
}
|
|
400
|
+
// The proposer builds ahead of L1 submission under pipelining, so the block source won't have
|
|
401
|
+
// synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
|
|
402
|
+
// eating into the attestation window.
|
|
317
403
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
318
404
|
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
319
405
|
// need to process other block proposals to get to it.
|
|
@@ -340,10 +426,12 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
340
426
|
// Compute the block number based on the parent block
|
|
341
427
|
const blockNumber = parentBlock === 'genesis' ? BlockNumber(INITIAL_L2_BLOCK_NUM) : BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
342
428
|
proposalInfo.blockNumber = blockNumber;
|
|
343
|
-
// Check that this block number does not exist already
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
429
|
+
// Check that this block number does not exist already. During a reorg the archiver can still hold a
|
|
430
|
+
// stale block at this number (a different archive, about to be pruned) while the proposal carries the
|
|
431
|
+
// rebuilt replacement; resolveExistingBlockAtNumber waits for the local prune in that case so the
|
|
432
|
+
// rebuilt block is processed in time to attest, rather than being permanently dropped on a bare
|
|
433
|
+
// number collision.
|
|
434
|
+
const existingBlock = await this.resolveExistingBlockAtNumber(blockNumber, proposal.archive, slotNumber);
|
|
347
435
|
if (existingBlock) {
|
|
348
436
|
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
349
437
|
return {
|
|
@@ -354,10 +442,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
354
442
|
}
|
|
355
443
|
// Collect txs from the proposal. We start doing this as early as possible,
|
|
356
444
|
// 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.
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
445
|
+
const collected = await this.collectProposalTxs(proposal, blockNumber, proposalSender, proposalInfo);
|
|
446
|
+
if (collected === 'invalid_embedded_txs') {
|
|
447
|
+
return {
|
|
448
|
+
isValid: false,
|
|
449
|
+
blockNumber,
|
|
450
|
+
reason: collected
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
const { txs, missingTxs } = collected;
|
|
361
454
|
// Record the tx-collection outcome on the re-execution tracker
|
|
362
455
|
this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
|
|
363
456
|
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
@@ -416,7 +509,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
416
509
|
epoch,
|
|
417
510
|
checkpointNumber,
|
|
418
511
|
l1Constants: this.epochCache.getL1Constants(),
|
|
419
|
-
pipeliningEnabled:
|
|
512
|
+
pipeliningEnabled: true,
|
|
420
513
|
log: this.log
|
|
421
514
|
});
|
|
422
515
|
// Try re-executing the transactions in the proposal if needed
|
|
@@ -435,7 +528,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
435
528
|
};
|
|
436
529
|
}
|
|
437
530
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
438
|
-
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver
|
|
531
|
+
if (reexecutionResult?.block && !this.config.skipPushProposedBlocksToArchiver) {
|
|
439
532
|
await this.blockSource.addBlock(reexecutionResult.block);
|
|
440
533
|
}
|
|
441
534
|
this.log.info(`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, {
|
|
@@ -448,6 +541,32 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
448
541
|
reexecutionResult
|
|
449
542
|
};
|
|
450
543
|
}
|
|
544
|
+
/**
|
|
545
|
+
* Collects the txs for a proposal, returning `invalid_embedded_txs` if the proposal carries a tx that fails
|
|
546
|
+
* minimum integrity validation. That is proposer misbehavior — the proposal signs both the tx hashes and the
|
|
547
|
+
* tx objects — so the caller turns it into an invalid-proposal result that reaches slashing and invalid-slot
|
|
548
|
+
* accounting, rather than letting it escape as an exception. Any other collection error is a local failure
|
|
549
|
+
* and keeps propagating.
|
|
550
|
+
*/ async collectProposalTxs(proposal, blockNumber, proposalSender, proposalInfo) {
|
|
551
|
+
try {
|
|
552
|
+
return await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
553
|
+
pinnedPeer: proposalSender,
|
|
554
|
+
deadline: this.getReexecutionDeadline(proposal.slotNumber)
|
|
555
|
+
});
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (!isErrorClass(error, InvalidBlockProposalTxsError)) {
|
|
558
|
+
throw error;
|
|
559
|
+
}
|
|
560
|
+
this.log.warn(`Block proposal carries ${error.invalidTxs.length} invalid txs`, {
|
|
561
|
+
...proposalInfo,
|
|
562
|
+
invalidTxs: error.invalidTxs.map(({ txHash, reasons })=>({
|
|
563
|
+
txHash: txHash.toString(),
|
|
564
|
+
reasons
|
|
565
|
+
}))
|
|
566
|
+
});
|
|
567
|
+
return 'invalid_embedded_txs';
|
|
568
|
+
}
|
|
569
|
+
}
|
|
451
570
|
async validateNewBlockInSlot(blockProposal) {
|
|
452
571
|
if (!this.p2pClient) {
|
|
453
572
|
return {
|
|
@@ -477,20 +596,21 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
477
596
|
}
|
|
478
597
|
async getParentBlock(proposal) {
|
|
479
598
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
480
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
481
599
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
482
600
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
483
601
|
return 'genesis';
|
|
484
602
|
}
|
|
485
|
-
const deadline = this.getReexecutionDeadline(proposal.slotNumber
|
|
486
|
-
const
|
|
487
|
-
const timeoutDurationMs = deadline.getTime() - currentTime;
|
|
603
|
+
const deadline = this.getReexecutionDeadline(proposal.slotNumber);
|
|
604
|
+
const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
|
|
488
605
|
try {
|
|
489
606
|
return await this.blockSource.getBlockData({
|
|
490
607
|
archive: parentArchive
|
|
491
608
|
}) ?? (timeoutDurationMs <= 0 ? undefined : await retryUntil(()=>this.blockSource.syncImmediate().then(()=>this.blockSource.getBlockData({
|
|
492
609
|
archive: parentArchive
|
|
493
|
-
})), 'force archiver sync',
|
|
610
|
+
})), 'force archiver sync', {
|
|
611
|
+
deadline,
|
|
612
|
+
dateProvider: this.dateProvider
|
|
613
|
+
}, 0.5));
|
|
494
614
|
} catch (err) {
|
|
495
615
|
if (err instanceof TimeoutError) {
|
|
496
616
|
this.log.debug(`Timed out getting parent block by archive root`, {
|
|
@@ -504,6 +624,60 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
504
624
|
return undefined;
|
|
505
625
|
}
|
|
506
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Resolves whether a block genuinely already exists at `blockNumber`. Returns the existing block only if
|
|
629
|
+
* it is a true duplicate of the proposal (matching archive). During a reorg the archiver can still hold a
|
|
630
|
+
* stale fork at this number (different archive) that is about to be pruned; in that case this forces L1
|
|
631
|
+
* sync and waits, bounded by the re-execution deadline, for the prune to land, then returns `undefined` so
|
|
632
|
+
* the rebuilt block proposal can be processed in time to attest. If the prune does not complete before the
|
|
633
|
+
* deadline it returns the stale block, so the caller falls back to the safe `block_number_already_exists`
|
|
634
|
+
* rejection.
|
|
635
|
+
*/ async resolveExistingBlockAtNumber(blockNumber, proposalArchive, slotNumber) {
|
|
636
|
+
const existingBlock = await this.blockSource.getBlockData({
|
|
637
|
+
number: blockNumber
|
|
638
|
+
});
|
|
639
|
+
if (!existingBlock || existingBlock.archive.root.equals(proposalArchive)) {
|
|
640
|
+
return existingBlock;
|
|
641
|
+
}
|
|
642
|
+
// A different block already occupies this number: it may be a stale fork being pruned during a reorg, not a
|
|
643
|
+
// genuine duplicate. Wait for the local prune rather than permanently rejecting the proposal.
|
|
644
|
+
const deadline = this.getReexecutionDeadline(slotNumber);
|
|
645
|
+
if (deadline.getTime() - this.dateProvider.now() <= 0) {
|
|
646
|
+
return existingBlock;
|
|
647
|
+
}
|
|
648
|
+
this.log.warn(`Block number ${blockNumber} already exists, awaiting potential prune`, {
|
|
649
|
+
blockNumber,
|
|
650
|
+
existingArchive: existingBlock.archive.root.toString(),
|
|
651
|
+
proposalArchive: proposalArchive.toString()
|
|
652
|
+
});
|
|
653
|
+
try {
|
|
654
|
+
const { block } = await retryUntil(async ()=>{
|
|
655
|
+
await this.blockSource.syncImmediate();
|
|
656
|
+
const block = await this.blockSource.getBlockData({
|
|
657
|
+
number: blockNumber
|
|
658
|
+
});
|
|
659
|
+
// Resolve once the existing block is gone (pruned) or has been replaced by one matching the
|
|
660
|
+
// proposal — the same condition as the early return above. A matching block is returned so the
|
|
661
|
+
// caller still treats it as a genuine duplicate; an `undefined` (pruned) block lets the proposal
|
|
662
|
+
// be processed. Wrap in an object so the `undefined` case is still a truthy retry result.
|
|
663
|
+
return block === undefined || block.archive.root.equals(proposalArchive) ? {
|
|
664
|
+
block
|
|
665
|
+
} : undefined;
|
|
666
|
+
}, `prune of stale block ${blockNumber}`, {
|
|
667
|
+
deadline,
|
|
668
|
+
dateProvider: this.dateProvider
|
|
669
|
+
}, 0.5);
|
|
670
|
+
return block;
|
|
671
|
+
} catch (err) {
|
|
672
|
+
if (err instanceof TimeoutError) {
|
|
673
|
+
this.log.warn(`Timed out waiting for stale block ${blockNumber} to be pruned`, {
|
|
674
|
+
blockNumber
|
|
675
|
+
});
|
|
676
|
+
return existingBlock;
|
|
677
|
+
}
|
|
678
|
+
throw err;
|
|
679
|
+
}
|
|
680
|
+
}
|
|
507
681
|
computeCheckpointNumber(proposal, parentBlock, proposalInfo) {
|
|
508
682
|
if (parentBlock === 'genesis') {
|
|
509
683
|
// First block is in checkpoint 1
|
|
@@ -632,40 +806,13 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
632
806
|
}
|
|
633
807
|
return undefined;
|
|
634
808
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
/** Waits for the block source to sync L1 data up to at least the slot before the given one. */ async waitForBlockSourceSync(slot) {
|
|
643
|
-
const deadline = this.getReexecutionDeadline(slot, this.checkpointsBuilder.getConfig());
|
|
644
|
-
const timeoutMs = deadline.getTime() - this.dateProvider.now();
|
|
645
|
-
if (slot === 0) {
|
|
646
|
-
return true;
|
|
647
|
-
}
|
|
648
|
-
// Make a quick check before triggering an archiver sync
|
|
649
|
-
// If we are pipelining and have a pending checkpoint number stored, we will allow the block proposal to be for a slot further
|
|
650
|
-
const syncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
651
|
-
if (syncedSlot !== undefined && syncedSlot + 1 + this.epochCache.pipeliningOffset() >= slot) {
|
|
652
|
-
return true;
|
|
653
|
-
}
|
|
654
|
-
try {
|
|
655
|
-
// Trigger an immediate sync of the block source, and wait until it reports being synced to the required slot
|
|
656
|
-
return await retryUntil(async ()=>{
|
|
657
|
-
await this.blockSource.syncImmediate();
|
|
658
|
-
const updatedSyncedSlot = await this.blockSource.getSyncedL2SlotNumber();
|
|
659
|
-
return updatedSyncedSlot !== undefined && updatedSyncedSlot + 1 >= slot;
|
|
660
|
-
}, 'wait for block source sync', timeoutMs / 1000, 0.5);
|
|
661
|
-
} catch (err) {
|
|
662
|
-
if (err instanceof TimeoutError) {
|
|
663
|
-
this.log.warn(`Timed out waiting for block source to sync to slot ${slot}`);
|
|
664
|
-
return false;
|
|
665
|
-
} else {
|
|
666
|
-
throw err;
|
|
667
|
-
}
|
|
668
|
-
}
|
|
809
|
+
/**
|
|
810
|
+
* Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
|
|
811
|
+
* the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
|
|
812
|
+
* checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
|
|
813
|
+
* next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
|
|
814
|
+
*/ getReexecutionDeadline(slotNumber) {
|
|
815
|
+
return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
|
|
669
816
|
}
|
|
670
817
|
getReexecuteFailureReason(err) {
|
|
671
818
|
if (err instanceof TransactionsNotAvailableError) {
|
|
@@ -725,7 +872,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
725
872
|
// Create checkpoint builder with prior blocks
|
|
726
873
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, priorBlocks, this.log.getBindings());
|
|
727
874
|
// Build the new block
|
|
728
|
-
const deadline = this.getReexecutionDeadline(slot
|
|
875
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
729
876
|
const maxBlockGas = this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity) : undefined;
|
|
730
877
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
731
878
|
isBuildingProposal: false,
|
|
@@ -848,14 +995,14 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
848
995
|
};
|
|
849
996
|
try {
|
|
850
997
|
const slot = proposal.slotNumber;
|
|
851
|
-
// Block-sync deadline = the
|
|
852
|
-
//
|
|
853
|
-
//
|
|
854
|
-
//
|
|
855
|
-
const
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
//
|
|
998
|
+
// Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
|
|
999
|
+
// - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
|
|
1000
|
+
// the target slot. Keeping validation/attestation alive until then lets validators keep attesting
|
|
1001
|
+
// right up to the proposer's real publish cutoff.
|
|
1002
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
1003
|
+
// Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
|
|
1004
|
+
// the remaining budget is derived from the date provider; a deadline already in the past times out
|
|
1005
|
+
// after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
|
|
859
1006
|
let lastBlockData;
|
|
860
1007
|
try {
|
|
861
1008
|
lastBlockData = await retryUntil(async ()=>{
|
|
@@ -863,7 +1010,10 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
863
1010
|
return await this.blockSource.getBlockData({
|
|
864
1011
|
archive: proposal.archive
|
|
865
1012
|
});
|
|
866
|
-
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
1013
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
|
|
1014
|
+
deadline,
|
|
1015
|
+
dateProvider: this.dateProvider
|
|
1016
|
+
}, 0.5);
|
|
867
1017
|
} catch (err) {
|
|
868
1018
|
if (err instanceof TimeoutError) {
|
|
869
1019
|
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
@@ -919,6 +1069,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
919
1069
|
checkpointNumber: lastBlockData.checkpointNumber
|
|
920
1070
|
};
|
|
921
1071
|
}
|
|
1072
|
+
// Note this condition should never trigger, since we dont process block proposals that exceed indexWithinCheckpoint
|
|
922
1073
|
const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
|
|
923
1074
|
if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
|
|
924
1075
|
this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
|
|
@@ -950,12 +1101,53 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
950
1101
|
epoch,
|
|
951
1102
|
checkpointNumber,
|
|
952
1103
|
l1Constants: this.epochCache.getL1Constants(),
|
|
953
|
-
pipeliningEnabled:
|
|
1104
|
+
pipeliningEnabled: true,
|
|
954
1105
|
log: this.log
|
|
955
1106
|
});
|
|
956
|
-
// Fork world state at the block before the first block
|
|
1107
|
+
// Fork world state at the block before the first block. getFork syncs world state to the parent block
|
|
1108
|
+
// first (see its doc): the block source (archiver) can already hold the block while world state still
|
|
1109
|
+
// trails it by one, and forking a not-yet-applied block throws a raw tree error that would otherwise
|
|
1110
|
+
// escape as an uncaught gossipsub error. We pass the parent's expected block hash so the sync detects a
|
|
1111
|
+
// world-state reorg (undefined for the genesis parent, where no block exists to pin). On failure we map
|
|
1112
|
+
// to a clean validation result rather than letting it escape.
|
|
957
1113
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
958
|
-
|
|
1114
|
+
let forkResult;
|
|
1115
|
+
try {
|
|
1116
|
+
const parentBlockHash = (await this.blockSource.getBlockData({
|
|
1117
|
+
number: parentBlockNumber
|
|
1118
|
+
}))?.blockHash;
|
|
1119
|
+
forkResult = await this.checkpointsBuilder.getFork(parentBlockNumber, parentBlockHash);
|
|
1120
|
+
} catch (err) {
|
|
1121
|
+
this.log.warn(`Failed to fork world state at block ${parentBlockNumber} for checkpoint proposal`, {
|
|
1122
|
+
...proposalInfo,
|
|
1123
|
+
parentBlockNumber,
|
|
1124
|
+
err
|
|
1125
|
+
});
|
|
1126
|
+
return {
|
|
1127
|
+
isValid: false,
|
|
1128
|
+
reason: 'world_state_not_synced',
|
|
1129
|
+
checkpointNumber
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
const fork = _ts_add_disposable_resource(env, forkResult, true);
|
|
1133
|
+
// Verify the fork's archive root matches the checkpoint's expected starting archive (the archive after
|
|
1134
|
+
// the parent block). A mismatch means world state forked from a different chain than the proposal was
|
|
1135
|
+
// built on (e.g. a reorg), so recomputing the checkpoint against it would be meaningless. This mirrors
|
|
1136
|
+
// the block-proposal re-execution check and fails fast with a clean, non-slashable result instead of a
|
|
1137
|
+
// confusing downstream mismatch.
|
|
1138
|
+
const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
1139
|
+
if (!forkArchiveRoot.equals(proposal.checkpointHeader.lastArchiveRoot)) {
|
|
1140
|
+
this.log.warn(`Fork archive root does not match checkpoint proposal's last archive`, {
|
|
1141
|
+
...proposalInfo,
|
|
1142
|
+
forkArchiveRoot: forkArchiveRoot.toString(),
|
|
1143
|
+
expectedLastArchiveRoot: proposal.checkpointHeader.lastArchiveRoot.toString()
|
|
1144
|
+
});
|
|
1145
|
+
return {
|
|
1146
|
+
isValid: false,
|
|
1147
|
+
reason: 'initial_archive_mismatch',
|
|
1148
|
+
checkpointNumber
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
959
1151
|
// Create checkpoint builder with all existing blocks
|
|
960
1152
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
961
1153
|
// Complete the checkpoint to get computed values
|
|
@@ -1082,10 +1274,10 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
1082
1274
|
}
|
|
1083
1275
|
}
|
|
1084
1276
|
/**
|
|
1085
|
-
* Derives proposed checkpoint data from validated blocks and sets it on the archiver
|
|
1086
|
-
*
|
|
1087
|
-
*
|
|
1088
|
-
*/ async
|
|
1277
|
+
* Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
|
|
1278
|
+
* pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
|
|
1279
|
+
* last block to sync.
|
|
1280
|
+
*/ async setProposedCheckpoint(proposal) {
|
|
1089
1281
|
if (!this.archiver) {
|
|
1090
1282
|
return false;
|
|
1091
1283
|
}
|