@aztec/validator-client 0.0.1-commit.42ee6df9b → 0.0.1-commit.431c48d
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 +12 -4
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +14 -3
- 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 +5 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -6
- 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 +15 -1
- package/dest/proposal_handler.d.ts +84 -18
- package/dest/proposal_handler.d.ts.map +1 -1
- package/dest/proposal_handler.js +510 -171
- package/dest/validator.d.ts +32 -13
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +208 -65
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +16 -5
- package/src/config.ts +31 -7
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +12 -5
- package/src/key_store/web3signer_key_store.ts +43 -59
- package/src/metrics.ts +20 -0
- package/src/proposal_handler.ts +590 -199
- package/src/validator.ts +280 -88
package/dest/proposal_handler.js
CHANGED
|
@@ -66,62 +66,168 @@ 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 {
|
|
77
|
-
import {
|
|
77
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
78
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
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
|
+
/**
|
|
86
|
+
* Mapping from a checkpoint-proposal validation failure reason to the tracker outcome that
|
|
87
|
+
* `handleCheckpointProposal` should record. `undefined` means do not record (signature
|
|
88
|
+
* couldn't be verified, or the checkpoint is already on L1 so the question is moot).
|
|
89
|
+
*/ /* eslint-disable camelcase */ const CHECKPOINT_VALIDATION_REASON_TO_OUTCOME = {
|
|
90
|
+
invalid_signature: undefined,
|
|
91
|
+
invalid_fee_asset_price_modifier: 'invalid',
|
|
92
|
+
checkpoint_already_published: undefined,
|
|
93
|
+
last_block_not_found: 'unvalidated',
|
|
94
|
+
block_fetch_error: 'unvalidated',
|
|
95
|
+
world_state_not_synced: 'unvalidated',
|
|
96
|
+
initial_archive_mismatch: 'unvalidated',
|
|
97
|
+
no_blocks_for_slot: 'unvalidated',
|
|
98
|
+
last_block_archive_mismatch: 'invalid',
|
|
99
|
+
too_many_blocks_in_checkpoint: 'invalid',
|
|
100
|
+
checkpoint_header_mismatch: 'invalid',
|
|
101
|
+
archive_mismatch: 'invalid',
|
|
102
|
+
out_hash_mismatch: 'invalid',
|
|
103
|
+
checkpoint_validation_failed: 'invalid'
|
|
104
|
+
};
|
|
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 {
|
|
84
144
|
checkpointsBuilder;
|
|
85
145
|
worldState;
|
|
86
146
|
blockSource;
|
|
87
147
|
l1ToL2MessageSource;
|
|
88
148
|
txProvider;
|
|
89
|
-
blockProposalValidator;
|
|
90
149
|
epochCache;
|
|
150
|
+
timetable;
|
|
91
151
|
config;
|
|
92
152
|
blobClient;
|
|
153
|
+
reexecutionTracker;
|
|
93
154
|
metrics;
|
|
94
155
|
dateProvider;
|
|
95
156
|
log;
|
|
96
157
|
tracer;
|
|
97
|
-
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
158
|
+
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
159
|
+
* Keyed by signed-payload hash so two proposals at the same (slot, archive) but with a
|
|
160
|
+
* different `feeAssetPriceModifier` (or any other signed field) are validated independently. */ lastCheckpointValidationResult;
|
|
98
161
|
/** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */ archiver;
|
|
99
162
|
/** Returns current validator addresses for own-proposal detection. Set via register(). */ getOwnValidatorAddresses;
|
|
100
|
-
|
|
163
|
+
/** P2P proposal pool access for deciding when retained proposals should block archiver processing. */ p2pClient;
|
|
164
|
+
checkpointProposalValidationFailureCallback;
|
|
165
|
+
/** Slots at which a slashable invalid block or checkpoint proposal was observed. */ slotsWithInvalidProposals;
|
|
166
|
+
/** Slots at which a proposal equivocation was observed; suppresses attested-to-invalid-proposal slashing. */ slotsWithProposalEquivocation;
|
|
167
|
+
constructor(checkpointsBuilder, worldState, blockSource, l1ToL2MessageSource, txProvider, epochCache, timetable, config, blobClient, reexecutionTracker, metrics, dateProvider = new DateProvider(), telemetry = getTelemetryClient(), log = createLogger('validator:proposal-handler')){
|
|
101
168
|
this.checkpointsBuilder = checkpointsBuilder;
|
|
102
169
|
this.worldState = worldState;
|
|
103
170
|
this.blockSource = blockSource;
|
|
104
171
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
105
172
|
this.txProvider = txProvider;
|
|
106
|
-
this.blockProposalValidator = blockProposalValidator;
|
|
107
173
|
this.epochCache = epochCache;
|
|
174
|
+
this.timetable = timetable;
|
|
108
175
|
this.config = config;
|
|
109
176
|
this.blobClient = blobClient;
|
|
177
|
+
this.reexecutionTracker = reexecutionTracker;
|
|
110
178
|
this.metrics = metrics;
|
|
111
179
|
this.dateProvider = dateProvider;
|
|
112
180
|
this.log = log;
|
|
181
|
+
this.slotsWithInvalidProposals = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
182
|
+
this.slotsWithProposalEquivocation = FifoSet.withLimit(MAX_TRACKED_INVALID_PROPOSAL_SLOTS);
|
|
113
183
|
if (config.fishermanMode) {
|
|
114
184
|
this.log = this.log.createChild('[FISHERMAN]');
|
|
115
185
|
}
|
|
116
186
|
this.tracer = telemetry.getTracer('ProposalHandler');
|
|
117
187
|
}
|
|
188
|
+
updateConfig(config) {
|
|
189
|
+
this.config = {
|
|
190
|
+
...this.config,
|
|
191
|
+
...config
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
setCheckpointProposalValidationFailureCallback(callback) {
|
|
195
|
+
this.checkpointProposalValidationFailureCallback = callback;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Records the proposer's own checkpoint proposal as a `valid` outcome in the re-execution
|
|
199
|
+
* tracker. Without this, the node's own checkpoint proposals never flow through
|
|
200
|
+
* `handleCheckpointProposal` (proposers don't validate their own proposals), so its sentinel
|
|
201
|
+
* sees no outcome for slots where it was the proposer and reports itself as inactive.
|
|
202
|
+
*
|
|
203
|
+
* `archive` should be the locally-computed archive (NOT the broadcast archive, which may have
|
|
204
|
+
* been deliberately corrupted in tests via `broadcastInvalidBlockProposal` /
|
|
205
|
+
* `broadcastInvalidCheckpointProposalOnly`). Recording the local archive correctly models the
|
|
206
|
+
* proposer's own view of its own work.
|
|
207
|
+
*/ recordOwnCheckpointProposalAsValid(slot, archive, checkpointNumber) {
|
|
208
|
+
this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
|
|
209
|
+
}
|
|
210
|
+
/** Whether a slashable invalid block or checkpoint proposal was observed at the given slot (InvalidProposalSlotSource). */ hasInvalidProposals(slotNumber) {
|
|
211
|
+
return this.slotsWithInvalidProposals.has(slotNumber);
|
|
212
|
+
}
|
|
213
|
+
/** Whether a proposal equivocation was observed at the given slot (InvalidProposalSlotSource). */ hasProposalEquivocation(slotNumber) {
|
|
214
|
+
return this.slotsWithProposalEquivocation.has(slotNumber);
|
|
215
|
+
}
|
|
216
|
+
/** Records a slot as having a slashable invalid proposal, for offense observers (sentinel/slasher watchers). */ markInvalidProposalSlot(slotNumber) {
|
|
217
|
+
this.slotsWithInvalidProposals.add(slotNumber);
|
|
218
|
+
}
|
|
219
|
+
/** Records a slot as having a proposal equivocation, which suppresses attested-to-invalid-proposal slashing. */ markProposalEquivocation(slotNumber) {
|
|
220
|
+
this.slotsWithProposalEquivocation.add(slotNumber);
|
|
221
|
+
}
|
|
118
222
|
/**
|
|
119
223
|
* Registers handlers for block and checkpoint proposals on the p2p client.
|
|
224
|
+
* Records the p2p client so validation can inspect retained proposals.
|
|
120
225
|
* Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
|
|
121
226
|
* The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
|
|
122
227
|
* @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
|
|
123
228
|
* @param getOwnValidatorAddresses - Returns current validator addresses for own-proposal detection
|
|
124
229
|
*/ register(p2pClient, shouldReexecute, archiver, getOwnValidatorAddresses) {
|
|
230
|
+
this.p2pClient = p2pClient;
|
|
125
231
|
this.archiver = archiver;
|
|
126
232
|
this.getOwnValidatorAddresses = getOwnValidatorAddresses;
|
|
127
233
|
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
@@ -141,6 +247,15 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
141
247
|
});
|
|
142
248
|
return true;
|
|
143
249
|
} else {
|
|
250
|
+
// Track invalid proposals / equivocations so offense observers (the attested-invalid-proposal
|
|
251
|
+
// watcher) work on non-validator nodes too. Validators populate these via their own handlers.
|
|
252
|
+
// Skip invalid-proposal marking while the escape hatch is open, matching the validator path,
|
|
253
|
+
// which intentionally disables invalid-block slashing then.
|
|
254
|
+
if (result.reason === 'checkpoint_proposal_equivocation') {
|
|
255
|
+
this.markProposalEquivocation(slotNumber);
|
|
256
|
+
} else if (SLASHABLE_BLOCK_PROPOSAL_VALIDATION_RESULT.includes(result.reason) && !await this.epochCache.isEscapeHatchOpenAtSlot(slotNumber)) {
|
|
257
|
+
this.markInvalidProposalSlot(slotNumber);
|
|
258
|
+
}
|
|
144
259
|
this.log.warn(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`, {
|
|
145
260
|
blockNumber: result.blockNumber,
|
|
146
261
|
slotNumber,
|
|
@@ -154,30 +269,61 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
154
269
|
}
|
|
155
270
|
};
|
|
156
271
|
p2pClient.registerBlockProposalHandler(blockHandler);
|
|
272
|
+
// p2p detects duplicate (equivocated) proposals without routing them through the handlers above, so mark
|
|
273
|
+
// the slot as equivocated here. This suppresses false-positive attested-to-invalid-proposal slashing on
|
|
274
|
+
// non-validator offense collectors. Validators overwrite this with their own richer handler.
|
|
275
|
+
p2pClient.registerDuplicateProposalCallback((info)=>this.markProposalEquivocation(info.slot));
|
|
157
276
|
// All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
|
|
158
277
|
// Runs for all nodes (validators and non-validators). Validators get the cached result in the
|
|
159
278
|
// validator-specific callback (attestToCheckpointProposal) which runs after this one.
|
|
160
279
|
const checkpointHandler = async (proposal, _sender)=>{
|
|
161
280
|
try {
|
|
281
|
+
const pipeliningTimer = new Timer();
|
|
162
282
|
const proposalInfo = {
|
|
163
283
|
slot: proposal.slotNumber,
|
|
164
284
|
archive: proposal.archive.toString(),
|
|
165
285
|
proposer: proposal.getSender()?.toString()
|
|
166
286
|
};
|
|
167
|
-
|
|
287
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
288
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
|
|
292
|
+
this.log.warn(`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`, proposalInfo);
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
// A proposal is "own" when it was signed by a validator key this node also owns. The true local
|
|
296
|
+
// proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
|
|
297
|
+
// proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
|
|
298
|
+
// shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
|
|
299
|
+
// nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
|
|
300
|
+
// proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
|
|
168
301
|
const proposer = proposal.getSender();
|
|
169
302
|
const ownAddresses = this.getOwnValidatorAddresses?.();
|
|
170
303
|
const isOwnProposal = proposer && ownAddresses?.some((addr)=>addr === proposer.toString());
|
|
171
304
|
if (isOwnProposal) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
305
|
+
const existing = await this.archiver?.getProposedCheckpointData({
|
|
306
|
+
slot: proposal.slotNumber
|
|
307
|
+
});
|
|
308
|
+
if (existing?.archive.root.equals(proposal.archive)) {
|
|
309
|
+
this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
|
|
310
|
+
return undefined;
|
|
175
311
|
}
|
|
176
|
-
return undefined;
|
|
177
312
|
}
|
|
178
313
|
const result = await this.handleCheckpointProposal(proposal, proposalInfo);
|
|
179
|
-
if (result.isValid
|
|
180
|
-
|
|
314
|
+
if (!result.isValid) {
|
|
315
|
+
// Track invalid checkpoint proposals so offense observers (the attested-invalid-proposal watcher)
|
|
316
|
+
// work on non-validator nodes too. This handler runs for all nodes; validators also mark via the
|
|
317
|
+
// failure callback below (idempotent).
|
|
318
|
+
if (SLASHABLE_CHECKPOINT_PROPOSAL_VALIDATION_RESULT[result.reason]) {
|
|
319
|
+
this.markInvalidProposalSlot(proposal.slotNumber);
|
|
320
|
+
}
|
|
321
|
+
await this.checkpointProposalValidationFailureCallback?.(proposal, result, proposalInfo);
|
|
322
|
+
} else if (this.archiver) {
|
|
323
|
+
const set = await this.setProposedCheckpoint(proposal);
|
|
324
|
+
if (set) {
|
|
325
|
+
this.metrics?.recordCheckpointProposalToPipelinedStateDuration(pipeliningTimer.ms());
|
|
326
|
+
}
|
|
181
327
|
}
|
|
182
328
|
} catch (err) {
|
|
183
329
|
this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, {
|
|
@@ -189,16 +335,21 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
189
335
|
p2pClient.registerAllNodesCheckpointProposalHandler(checkpointHandler);
|
|
190
336
|
return this;
|
|
191
337
|
}
|
|
192
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Processes a block proposal: collects its txs and, if requested, re-executes them to check the resulting
|
|
340
|
+
* block against the proposal. Expects the proposal to have already passed p2p ingress validation (signature
|
|
341
|
+
* context, signature, expected proposer, index within checkpoint, tx field checks, and the receive-window
|
|
342
|
+
* timeliness check) — none of those are re-applied here, and only deterministic properties of the payload
|
|
343
|
+
* are validated before processing.
|
|
344
|
+
*/ async handleBlockProposal(proposal, proposalSender, shouldReexecute) {
|
|
193
345
|
const slotNumber = proposal.slotNumber;
|
|
194
346
|
const proposer = proposal.getSender();
|
|
195
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
196
347
|
// Reject proposals with invalid signatures
|
|
197
348
|
if (!proposer) {
|
|
198
349
|
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
199
350
|
return {
|
|
200
351
|
isValid: false,
|
|
201
|
-
reason: '
|
|
352
|
+
reason: 'invalid_signature'
|
|
202
353
|
};
|
|
203
354
|
}
|
|
204
355
|
const proposalInfo = {
|
|
@@ -211,33 +362,41 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
211
362
|
...proposalInfo,
|
|
212
363
|
txHashes: proposal.txHashes.map((t)=>t.toString())
|
|
213
364
|
});
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
365
|
+
// The receive-window check from p2p ingress is deliberately not re-applied here: its outcome depends on
|
|
366
|
+
// the wall clock at evaluation time, so re-running it turned node-local processing latency into an
|
|
367
|
+
// invalid-proposal verdict against an honest proposer, which then fed the invalid-block slashing path.
|
|
368
|
+
// A tx can only appear once in a block: the second copy would emit nullifiers already emitted by the
|
|
369
|
+
// first. This is not a relaying-peer fault, so it passes gossip validation and is classified here as
|
|
370
|
+
// proposer misbehavior. Tx collection also reconciles a deduplicated hash set against the full list,
|
|
371
|
+
// so it must not be handed a proposal with repeated hashes.
|
|
372
|
+
const uniqueTxHashes = new Set(proposal.txHashes.map((txHash)=>txHash.toString()));
|
|
373
|
+
if (uniqueTxHashes.size !== proposal.txHashes.length) {
|
|
374
|
+
this.log.warn(`Proposal lists duplicate tx hashes, skipping processing`, {
|
|
375
|
+
...proposalInfo,
|
|
376
|
+
txCount: proposal.txHashes.length,
|
|
377
|
+
uniqueTxCount: uniqueTxHashes.size
|
|
378
|
+
});
|
|
219
379
|
return {
|
|
220
380
|
isValid: false,
|
|
221
|
-
reason: '
|
|
381
|
+
reason: 'duplicate_txs'
|
|
222
382
|
};
|
|
223
383
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
isValid: false,
|
|
237
|
-
reason: 'block_source_not_synced'
|
|
238
|
-
};
|
|
239
|
-
}
|
|
384
|
+
const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
|
|
385
|
+
if (!retainedSlotValidation.isValid) {
|
|
386
|
+
this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
|
|
387
|
+
...proposalInfo,
|
|
388
|
+
indexWithinCheckpoint: proposal.indexWithinCheckpoint,
|
|
389
|
+
reason: retainedSlotValidation.reason
|
|
390
|
+
});
|
|
391
|
+
return {
|
|
392
|
+
isValid: false,
|
|
393
|
+
blockNumber: proposal.blockNumber,
|
|
394
|
+
reason: retainedSlotValidation.reason
|
|
395
|
+
};
|
|
240
396
|
}
|
|
397
|
+
// The proposer builds ahead of L1 submission under pipelining, so the block source won't have
|
|
398
|
+
// synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
|
|
399
|
+
// eating into the attestation window.
|
|
241
400
|
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
242
401
|
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
243
402
|
// need to process other block proposals to get to it.
|
|
@@ -264,8 +423,12 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
264
423
|
// Compute the block number based on the parent block
|
|
265
424
|
const blockNumber = parentBlock === 'genesis' ? BlockNumber(INITIAL_L2_BLOCK_NUM) : BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
266
425
|
proposalInfo.blockNumber = blockNumber;
|
|
267
|
-
// Check that this block number does not exist already
|
|
268
|
-
|
|
426
|
+
// Check that this block number does not exist already. During a reorg the archiver can still hold a
|
|
427
|
+
// stale block at this number (a different archive, about to be pruned) while the proposal carries the
|
|
428
|
+
// rebuilt replacement; resolveExistingBlockAtNumber waits for the local prune in that case so the
|
|
429
|
+
// rebuilt block is processed in time to attest, rather than being permanently dropped on a bare
|
|
430
|
+
// number collision.
|
|
431
|
+
const existingBlock = await this.resolveExistingBlockAtNumber(blockNumber, proposal.archive, slotNumber);
|
|
269
432
|
if (existingBlock) {
|
|
270
433
|
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
271
434
|
return {
|
|
@@ -276,10 +439,17 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
276
439
|
}
|
|
277
440
|
// Collect txs from the proposal. We start doing this as early as possible,
|
|
278
441
|
// 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
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
442
|
+
const collected = await this.collectProposalTxs(proposal, blockNumber, proposalSender, proposalInfo);
|
|
443
|
+
if (collected === 'invalid_embedded_txs') {
|
|
444
|
+
return {
|
|
445
|
+
isValid: false,
|
|
446
|
+
blockNumber,
|
|
447
|
+
reason: collected
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
const { txs, missingTxs } = collected;
|
|
451
|
+
// Record the tx-collection outcome on the re-execution tracker
|
|
452
|
+
this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
|
|
283
453
|
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
284
454
|
if (!shouldReexecute) {
|
|
285
455
|
this.log.info(`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, proposalInfo);
|
|
@@ -327,9 +497,18 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
327
497
|
reason: 'txs_not_available'
|
|
328
498
|
};
|
|
329
499
|
}
|
|
330
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
500
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
501
|
+
// Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
|
|
502
|
+
// yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
|
|
331
503
|
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
332
|
-
const previousCheckpointOutHashes =
|
|
504
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
505
|
+
blockSource: this.blockSource,
|
|
506
|
+
epoch,
|
|
507
|
+
checkpointNumber,
|
|
508
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
509
|
+
pipeliningEnabled: true,
|
|
510
|
+
log: this.log
|
|
511
|
+
});
|
|
333
512
|
// Try re-executing the transactions in the proposal if needed
|
|
334
513
|
let reexecutionResult;
|
|
335
514
|
try {
|
|
@@ -346,7 +525,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
346
525
|
};
|
|
347
526
|
}
|
|
348
527
|
// If we succeeded, push this block into the archiver (unless disabled)
|
|
349
|
-
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver
|
|
528
|
+
if (reexecutionResult?.block && !this.config.skipPushProposedBlocksToArchiver) {
|
|
350
529
|
await this.blockSource.addBlock(reexecutionResult.block);
|
|
351
530
|
}
|
|
352
531
|
this.log.info(`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`, {
|
|
@@ -359,19 +538,76 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
359
538
|
reexecutionResult
|
|
360
539
|
};
|
|
361
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Collects the txs for a proposal, returning `invalid_embedded_txs` if the proposal carries a tx that fails
|
|
543
|
+
* minimum integrity validation. That is proposer misbehavior — the proposal signs both the tx hashes and the
|
|
544
|
+
* tx objects — so the caller turns it into an invalid-proposal result that reaches slashing and invalid-slot
|
|
545
|
+
* accounting, rather than letting it escape as an exception. Any other collection error is a local failure
|
|
546
|
+
* and keeps propagating.
|
|
547
|
+
*/ async collectProposalTxs(proposal, blockNumber, proposalSender, proposalInfo) {
|
|
548
|
+
try {
|
|
549
|
+
return await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
550
|
+
pinnedPeer: proposalSender,
|
|
551
|
+
deadline: this.getReexecutionDeadline(proposal.slotNumber)
|
|
552
|
+
});
|
|
553
|
+
} catch (error) {
|
|
554
|
+
if (!isErrorClass(error, InvalidBlockProposalTxsError)) {
|
|
555
|
+
throw error;
|
|
556
|
+
}
|
|
557
|
+
this.log.warn(`Block proposal carries ${error.invalidTxs.length} invalid txs`, {
|
|
558
|
+
...proposalInfo,
|
|
559
|
+
invalidTxs: error.invalidTxs.map(({ txHash, reasons })=>({
|
|
560
|
+
txHash: txHash.toString(),
|
|
561
|
+
reasons
|
|
562
|
+
}))
|
|
563
|
+
});
|
|
564
|
+
return 'invalid_embedded_txs';
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
async validateNewBlockInSlot(blockProposal) {
|
|
568
|
+
if (!this.p2pClient) {
|
|
569
|
+
return {
|
|
570
|
+
isValid: true
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
const { blockProposals, checkpointProposals } = await this.p2pClient.getProposalsForSlot(blockProposal.slotNumber);
|
|
574
|
+
if (checkpointProposals.length === 0) {
|
|
575
|
+
return {
|
|
576
|
+
isValid: true
|
|
577
|
+
};
|
|
578
|
+
} else if (checkpointProposals.length > 1) {
|
|
579
|
+
return {
|
|
580
|
+
isValid: false,
|
|
581
|
+
reason: 'checkpoint_proposal_equivocation'
|
|
582
|
+
};
|
|
583
|
+
} else {
|
|
584
|
+
const checkpointProposal = checkpointProposals[0];
|
|
585
|
+
const terminalBlock = blockProposals.find((block)=>block.archive.equals(checkpointProposal.archive));
|
|
586
|
+
return terminalBlock !== undefined && blockProposal.indexWithinCheckpoint > terminalBlock.indexWithinCheckpoint ? {
|
|
587
|
+
isValid: false,
|
|
588
|
+
reason: 'block_proposal_beyond_checkpoint'
|
|
589
|
+
} : {
|
|
590
|
+
isValid: true
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
}
|
|
362
594
|
async getParentBlock(proposal) {
|
|
363
595
|
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
364
|
-
const slot = proposal.slotNumber;
|
|
365
|
-
const config = this.checkpointsBuilder.getConfig();
|
|
366
596
|
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
367
597
|
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
368
598
|
return 'genesis';
|
|
369
599
|
}
|
|
370
|
-
const deadline = this.getReexecutionDeadline(
|
|
371
|
-
const
|
|
372
|
-
const timeoutDurationMs = deadline.getTime() - currentTime;
|
|
600
|
+
const deadline = this.getReexecutionDeadline(proposal.slotNumber);
|
|
601
|
+
const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
|
|
373
602
|
try {
|
|
374
|
-
return await this.blockSource.
|
|
603
|
+
return await this.blockSource.getBlockData({
|
|
604
|
+
archive: parentArchive
|
|
605
|
+
}) ?? (timeoutDurationMs <= 0 ? undefined : await retryUntil(()=>this.blockSource.syncImmediate().then(()=>this.blockSource.getBlockData({
|
|
606
|
+
archive: parentArchive
|
|
607
|
+
})), 'force archiver sync', {
|
|
608
|
+
deadline,
|
|
609
|
+
dateProvider: this.dateProvider
|
|
610
|
+
}, 0.5));
|
|
375
611
|
} catch (err) {
|
|
376
612
|
if (err instanceof TimeoutError) {
|
|
377
613
|
this.log.debug(`Timed out getting parent block by archive root`, {
|
|
@@ -385,6 +621,60 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
385
621
|
return undefined;
|
|
386
622
|
}
|
|
387
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* Resolves whether a block genuinely already exists at `blockNumber`. Returns the existing block only if
|
|
626
|
+
* it is a true duplicate of the proposal (matching archive). During a reorg the archiver can still hold a
|
|
627
|
+
* stale fork at this number (different archive) that is about to be pruned; in that case this forces L1
|
|
628
|
+
* sync and waits, bounded by the re-execution deadline, for the prune to land, then returns `undefined` so
|
|
629
|
+
* the rebuilt block proposal can be processed in time to attest. If the prune does not complete before the
|
|
630
|
+
* deadline it returns the stale block, so the caller falls back to the safe `block_number_already_exists`
|
|
631
|
+
* rejection.
|
|
632
|
+
*/ async resolveExistingBlockAtNumber(blockNumber, proposalArchive, slotNumber) {
|
|
633
|
+
const existingBlock = await this.blockSource.getBlockData({
|
|
634
|
+
number: blockNumber
|
|
635
|
+
});
|
|
636
|
+
if (!existingBlock || existingBlock.archive.root.equals(proposalArchive)) {
|
|
637
|
+
return existingBlock;
|
|
638
|
+
}
|
|
639
|
+
// A different block already occupies this number: it may be a stale fork being pruned during a reorg, not a
|
|
640
|
+
// genuine duplicate. Wait for the local prune rather than permanently rejecting the proposal.
|
|
641
|
+
const deadline = this.getReexecutionDeadline(slotNumber);
|
|
642
|
+
if (deadline.getTime() - this.dateProvider.now() <= 0) {
|
|
643
|
+
return existingBlock;
|
|
644
|
+
}
|
|
645
|
+
this.log.warn(`Block number ${blockNumber} already exists, awaiting potential prune`, {
|
|
646
|
+
blockNumber,
|
|
647
|
+
existingArchive: existingBlock.archive.root.toString(),
|
|
648
|
+
proposalArchive: proposalArchive.toString()
|
|
649
|
+
});
|
|
650
|
+
try {
|
|
651
|
+
const { block } = await retryUntil(async ()=>{
|
|
652
|
+
await this.blockSource.syncImmediate();
|
|
653
|
+
const block = await this.blockSource.getBlockData({
|
|
654
|
+
number: blockNumber
|
|
655
|
+
});
|
|
656
|
+
// Resolve once the existing block is gone (pruned) or has been replaced by one matching the
|
|
657
|
+
// proposal — the same condition as the early return above. A matching block is returned so the
|
|
658
|
+
// caller still treats it as a genuine duplicate; an `undefined` (pruned) block lets the proposal
|
|
659
|
+
// be processed. Wrap in an object so the `undefined` case is still a truthy retry result.
|
|
660
|
+
return block === undefined || block.archive.root.equals(proposalArchive) ? {
|
|
661
|
+
block
|
|
662
|
+
} : undefined;
|
|
663
|
+
}, `prune of stale block ${blockNumber}`, {
|
|
664
|
+
deadline,
|
|
665
|
+
dateProvider: this.dateProvider
|
|
666
|
+
}, 0.5);
|
|
667
|
+
return block;
|
|
668
|
+
} catch (err) {
|
|
669
|
+
if (err instanceof TimeoutError) {
|
|
670
|
+
this.log.warn(`Timed out waiting for stale block ${blockNumber} to be pruned`, {
|
|
671
|
+
blockNumber
|
|
672
|
+
});
|
|
673
|
+
return existingBlock;
|
|
674
|
+
}
|
|
675
|
+
throw err;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
388
678
|
computeCheckpointNumber(proposal, parentBlock, proposalInfo) {
|
|
389
679
|
if (parentBlock === 'genesis') {
|
|
390
680
|
// First block is in checkpoint 1
|
|
@@ -513,36 +803,13 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
513
803
|
}
|
|
514
804
|
return undefined;
|
|
515
805
|
}
|
|
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
|
-
}
|
|
806
|
+
/**
|
|
807
|
+
* Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
|
|
808
|
+
* the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
|
|
809
|
+
* checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
|
|
810
|
+
* next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
|
|
811
|
+
*/ getReexecutionDeadline(slotNumber) {
|
|
812
|
+
return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
|
|
546
813
|
}
|
|
547
814
|
getReexecuteFailureReason(err) {
|
|
548
815
|
if (err instanceof TransactionsNotAvailableError) {
|
|
@@ -570,7 +837,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
570
837
|
// If we do not have all of the transactions, then we should fail
|
|
571
838
|
if (txs.length !== txHashes.length) {
|
|
572
839
|
const foundTxHashes = txs.map((tx)=>tx.getTxHash());
|
|
573
|
-
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.
|
|
840
|
+
const missingTxHashes = txHashes.filter((txHash)=>!foundTxHashes.some((h)=>h.equals(txHash)));
|
|
574
841
|
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
575
842
|
}
|
|
576
843
|
const timer = new Timer();
|
|
@@ -602,7 +869,7 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
602
869
|
// Create checkpoint builder with prior blocks
|
|
603
870
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, 0n, l1ToL2Messages, previousCheckpointOutHashes, fork, priorBlocks, this.log.getBindings());
|
|
604
871
|
// Build the new block
|
|
605
|
-
const deadline = this.getReexecutionDeadline(slot
|
|
872
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
606
873
|
const maxBlockGas = this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined ? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity) : undefined;
|
|
607
874
|
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
608
875
|
isBuildingProposal: false,
|
|
@@ -664,46 +931,52 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
664
931
|
* Validates a checkpoint proposal, caches the result, and uploads blobs if configured.
|
|
665
932
|
* Returns a cached result if the same proposal (archive + slot) was already validated.
|
|
666
933
|
* Used by both the all-nodes callback (via register) and the validator client (via delegation).
|
|
934
|
+
* Expects the proposal to have already passed p2p ingress validation (expected proposer and receive-window
|
|
935
|
+
* timeliness); only deterministic properties of the signed payload are checked here.
|
|
667
936
|
*/ async handleCheckpointProposal(proposal, proposalInfo) {
|
|
668
937
|
const slot = proposal.slotNumber;
|
|
669
|
-
|
|
670
|
-
|
|
938
|
+
const payloadHash = proposal.getPayloadHash();
|
|
939
|
+
// Check cache: same signed-payload hash means we already validated this exact proposal.
|
|
940
|
+
if (this.lastCheckpointValidationResult && this.lastCheckpointValidationResult.payloadHash === payloadHash) {
|
|
671
941
|
this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
|
|
672
942
|
return this.lastCheckpointValidationResult.result;
|
|
673
943
|
}
|
|
674
944
|
const proposer = proposal.getSender();
|
|
945
|
+
let result;
|
|
675
946
|
if (!proposer) {
|
|
676
947
|
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
|
|
677
|
-
|
|
948
|
+
result = {
|
|
678
949
|
isValid: false,
|
|
679
950
|
reason: 'invalid_signature'
|
|
680
951
|
};
|
|
681
|
-
|
|
682
|
-
archive: proposal.archive,
|
|
683
|
-
slotNumber: slot,
|
|
684
|
-
result
|
|
685
|
-
};
|
|
686
|
-
return result;
|
|
687
|
-
}
|
|
688
|
-
if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
952
|
+
} else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
689
953
|
this.log.warn(`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`);
|
|
690
|
-
|
|
954
|
+
result = {
|
|
691
955
|
isValid: false,
|
|
692
956
|
reason: 'invalid_fee_asset_price_modifier'
|
|
693
957
|
};
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
slotNumber: slot,
|
|
697
|
-
result
|
|
698
|
-
};
|
|
699
|
-
return result;
|
|
958
|
+
} else {
|
|
959
|
+
result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
700
960
|
}
|
|
701
|
-
const result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
702
961
|
this.lastCheckpointValidationResult = {
|
|
703
|
-
|
|
704
|
-
slotNumber: slot,
|
|
962
|
+
payloadHash,
|
|
705
963
|
result
|
|
706
964
|
};
|
|
965
|
+
// Record the outcome on the re-execution tracker.
|
|
966
|
+
const outcome = result.isValid ? 'valid' : CHECKPOINT_VALIDATION_REASON_TO_OUTCOME[result.reason];
|
|
967
|
+
if (outcome !== undefined) {
|
|
968
|
+
this.reexecutionTracker.recordOutcome(slot, proposal.archive, outcome, result.checkpointNumber);
|
|
969
|
+
}
|
|
970
|
+
// Drop tracker entries for checkpoints that have reached L1 finality.
|
|
971
|
+
try {
|
|
972
|
+
const tips = await this.blockSource.getL2Tips();
|
|
973
|
+
const finalizedCheckpointNumber = tips.finalized.checkpoint.number;
|
|
974
|
+
if (finalizedCheckpointNumber > 0) {
|
|
975
|
+
this.reexecutionTracker.removeBefore(CheckpointNumber(finalizedCheckpointNumber + 1));
|
|
976
|
+
}
|
|
977
|
+
} catch (err) {
|
|
978
|
+
this.log.error(`Error pruning reexecution tracker`, err, proposalInfo);
|
|
979
|
+
}
|
|
707
980
|
// Upload blobs to filestore if validation passed (fire and forget)
|
|
708
981
|
if (result.isValid) {
|
|
709
982
|
this.tryUploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
@@ -721,17 +994,25 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
721
994
|
};
|
|
722
995
|
try {
|
|
723
996
|
const slot = proposal.slotNumber;
|
|
724
|
-
//
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
997
|
+
// Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
|
|
998
|
+
// - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
|
|
999
|
+
// the target slot. Keeping validation/attestation alive until then lets validators keep attesting
|
|
1000
|
+
// right up to the proposer's real publish cutoff.
|
|
1001
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
1002
|
+
// Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
|
|
1003
|
+
// the remaining budget is derived from the date provider; a deadline already in the past times out
|
|
1004
|
+
// after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
|
|
1005
|
+
let lastBlockData;
|
|
730
1006
|
try {
|
|
731
|
-
|
|
1007
|
+
lastBlockData = await retryUntil(async ()=>{
|
|
732
1008
|
await this.blockSource.syncImmediate();
|
|
733
|
-
return this.blockSource.
|
|
734
|
-
|
|
1009
|
+
return await this.blockSource.getBlockData({
|
|
1010
|
+
archive: proposal.archive
|
|
1011
|
+
});
|
|
1012
|
+
}, `waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`, {
|
|
1013
|
+
deadline,
|
|
1014
|
+
dateProvider: this.dateProvider
|
|
1015
|
+
}, 0.5);
|
|
735
1016
|
} catch (err) {
|
|
736
1017
|
if (err instanceof TimeoutError) {
|
|
737
1018
|
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
@@ -746,20 +1027,36 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
746
1027
|
reason: 'block_fetch_error'
|
|
747
1028
|
};
|
|
748
1029
|
}
|
|
749
|
-
if (!
|
|
1030
|
+
if (!lastBlockData) {
|
|
750
1031
|
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
751
1032
|
return {
|
|
752
1033
|
isValid: false,
|
|
753
1034
|
reason: 'last_block_not_found'
|
|
754
1035
|
};
|
|
755
1036
|
}
|
|
1037
|
+
// Refuse to attest if the block's enclosing checkpoint has already been published to L1.
|
|
1038
|
+
const existingCheckpoint = await this.blockSource.getCheckpointData({
|
|
1039
|
+
number: lastBlockData.checkpointNumber
|
|
1040
|
+
});
|
|
1041
|
+
if (existingCheckpoint) {
|
|
1042
|
+
this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
|
|
1043
|
+
...proposalInfo,
|
|
1044
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1045
|
+
});
|
|
1046
|
+
return {
|
|
1047
|
+
isValid: false,
|
|
1048
|
+
reason: 'checkpoint_already_published',
|
|
1049
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
756
1052
|
// Get all full blocks for the slot and checkpoint
|
|
757
1053
|
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
758
1054
|
if (blocks.length === 0) {
|
|
759
1055
|
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
760
1056
|
return {
|
|
761
1057
|
isValid: false,
|
|
762
|
-
reason: 'no_blocks_for_slot'
|
|
1058
|
+
reason: 'no_blocks_for_slot',
|
|
1059
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
763
1060
|
};
|
|
764
1061
|
}
|
|
765
1062
|
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
@@ -767,7 +1064,22 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
767
1064
|
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
768
1065
|
return {
|
|
769
1066
|
isValid: false,
|
|
770
|
-
reason: 'last_block_archive_mismatch'
|
|
1067
|
+
reason: 'last_block_archive_mismatch',
|
|
1068
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
// Note this condition should never trigger, since we dont process block proposals that exceed indexWithinCheckpoint
|
|
1072
|
+
const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
|
|
1073
|
+
if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
|
|
1074
|
+
this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
|
|
1075
|
+
...proposalInfo,
|
|
1076
|
+
blocksInProposal: blocks.length,
|
|
1077
|
+
maxBlocksPerCheckpoint
|
|
1078
|
+
});
|
|
1079
|
+
return {
|
|
1080
|
+
isValid: false,
|
|
1081
|
+
reason: 'too_many_blocks_in_checkpoint',
|
|
1082
|
+
checkpointNumber: lastBlockData.checkpointNumber
|
|
771
1083
|
};
|
|
772
1084
|
}
|
|
773
1085
|
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
@@ -780,12 +1092,61 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
780
1092
|
const checkpointNumber = firstBlock.checkpointNumber;
|
|
781
1093
|
// Get L1-to-L2 messages for this checkpoint
|
|
782
1094
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
783
|
-
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
1095
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
1096
|
+
// See note on the analogous block-proposal site: the helper handles pipelining lag.
|
|
784
1097
|
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
785
|
-
const previousCheckpointOutHashes =
|
|
786
|
-
|
|
1098
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
1099
|
+
blockSource: this.blockSource,
|
|
1100
|
+
epoch,
|
|
1101
|
+
checkpointNumber,
|
|
1102
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
1103
|
+
pipeliningEnabled: true,
|
|
1104
|
+
log: this.log
|
|
1105
|
+
});
|
|
1106
|
+
// Fork world state at the block before the first block. getFork syncs world state to the parent block
|
|
1107
|
+
// first (see its doc): the block source (archiver) can already hold the block while world state still
|
|
1108
|
+
// trails it by one, and forking a not-yet-applied block throws a raw tree error that would otherwise
|
|
1109
|
+
// escape as an uncaught gossipsub error. We pass the parent's expected block hash so the sync detects a
|
|
1110
|
+
// world-state reorg (undefined for the genesis parent, where no block exists to pin). On failure we map
|
|
1111
|
+
// to a clean validation result rather than letting it escape.
|
|
787
1112
|
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
788
|
-
|
|
1113
|
+
let forkResult;
|
|
1114
|
+
try {
|
|
1115
|
+
const parentBlockHash = (await this.blockSource.getBlockData({
|
|
1116
|
+
number: parentBlockNumber
|
|
1117
|
+
}))?.blockHash;
|
|
1118
|
+
forkResult = await this.checkpointsBuilder.getFork(parentBlockNumber, parentBlockHash);
|
|
1119
|
+
} catch (err) {
|
|
1120
|
+
this.log.warn(`Failed to fork world state at block ${parentBlockNumber} for checkpoint proposal`, {
|
|
1121
|
+
...proposalInfo,
|
|
1122
|
+
parentBlockNumber,
|
|
1123
|
+
err
|
|
1124
|
+
});
|
|
1125
|
+
return {
|
|
1126
|
+
isValid: false,
|
|
1127
|
+
reason: 'world_state_not_synced',
|
|
1128
|
+
checkpointNumber
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
const fork = _ts_add_disposable_resource(env, forkResult, true);
|
|
1132
|
+
// Verify the fork's archive root matches the checkpoint's expected starting archive (the archive after
|
|
1133
|
+
// the parent block). A mismatch means world state forked from a different chain than the proposal was
|
|
1134
|
+
// built on (e.g. a reorg), so recomputing the checkpoint against it would be meaningless. This mirrors
|
|
1135
|
+
// the block-proposal re-execution check and fails fast with a clean, non-slashable result instead of a
|
|
1136
|
+
// confusing downstream mismatch.
|
|
1137
|
+
const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
1138
|
+
if (!forkArchiveRoot.equals(proposal.checkpointHeader.lastArchiveRoot)) {
|
|
1139
|
+
this.log.warn(`Fork archive root does not match checkpoint proposal's last archive`, {
|
|
1140
|
+
...proposalInfo,
|
|
1141
|
+
forkArchiveRoot: forkArchiveRoot.toString(),
|
|
1142
|
+
expectedLastArchiveRoot: proposal.checkpointHeader.lastArchiveRoot.toString()
|
|
1143
|
+
});
|
|
1144
|
+
return {
|
|
1145
|
+
isValid: false,
|
|
1146
|
+
reason: 'initial_archive_mismatch',
|
|
1147
|
+
checkpointNumber
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
789
1150
|
// Create checkpoint builder with all existing blocks
|
|
790
1151
|
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(checkpointNumber, constants, proposal.feeAssetPriceModifier, l1ToL2Messages, previousCheckpointOutHashes, fork, blocks, this.log.getBindings());
|
|
791
1152
|
// Complete the checkpoint to get computed values
|
|
@@ -799,7 +1160,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
799
1160
|
});
|
|
800
1161
|
return {
|
|
801
1162
|
isValid: false,
|
|
802
|
-
reason: 'checkpoint_header_mismatch'
|
|
1163
|
+
reason: 'checkpoint_header_mismatch',
|
|
1164
|
+
checkpointNumber
|
|
803
1165
|
};
|
|
804
1166
|
}
|
|
805
1167
|
// Compare archive root with proposal
|
|
@@ -811,7 +1173,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
811
1173
|
});
|
|
812
1174
|
return {
|
|
813
1175
|
isValid: false,
|
|
814
|
-
reason: 'archive_mismatch'
|
|
1176
|
+
reason: 'archive_mismatch',
|
|
1177
|
+
checkpointNumber
|
|
815
1178
|
};
|
|
816
1179
|
}
|
|
817
1180
|
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
@@ -832,7 +1195,8 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
832
1195
|
});
|
|
833
1196
|
return {
|
|
834
1197
|
isValid: false,
|
|
835
|
-
reason: 'out_hash_mismatch'
|
|
1198
|
+
reason: 'out_hash_mismatch',
|
|
1199
|
+
checkpointNumber
|
|
836
1200
|
};
|
|
837
1201
|
}
|
|
838
1202
|
// Final round of validations on the checkpoint, just in case.
|
|
@@ -848,12 +1212,14 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
848
1212
|
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
849
1213
|
return {
|
|
850
1214
|
isValid: false,
|
|
851
|
-
reason: 'checkpoint_validation_failed'
|
|
1215
|
+
reason: 'checkpoint_validation_failed',
|
|
1216
|
+
checkpointNumber
|
|
852
1217
|
};
|
|
853
1218
|
}
|
|
854
1219
|
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
855
1220
|
return {
|
|
856
|
-
isValid: true
|
|
1221
|
+
isValid: true,
|
|
1222
|
+
checkpointNumber
|
|
857
1223
|
};
|
|
858
1224
|
} catch (e) {
|
|
859
1225
|
env.error = e;
|
|
@@ -882,7 +1248,9 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
882
1248
|
}
|
|
883
1249
|
/** Uploads blobs for a checkpoint to the filestore. */ async uploadBlobsForCheckpoint(proposal, proposalInfo) {
|
|
884
1250
|
try {
|
|
885
|
-
const lastBlockHeader = await this.blockSource.
|
|
1251
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({
|
|
1252
|
+
archive: proposal.archive
|
|
1253
|
+
}))?.header;
|
|
886
1254
|
if (!lastBlockHeader) {
|
|
887
1255
|
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
888
1256
|
return;
|
|
@@ -905,21 +1273,23 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
905
1273
|
}
|
|
906
1274
|
}
|
|
907
1275
|
/**
|
|
908
|
-
* Derives proposed checkpoint data from validated blocks and sets it on the archiver
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
*/ async
|
|
1276
|
+
* Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
|
|
1277
|
+
* pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
|
|
1278
|
+
* last block to sync.
|
|
1279
|
+
*/ async setProposedCheckpoint(proposal) {
|
|
912
1280
|
if (!this.archiver) {
|
|
913
|
-
return;
|
|
1281
|
+
return false;
|
|
914
1282
|
}
|
|
915
|
-
const blockData = await this.blockSource.
|
|
1283
|
+
const blockData = await this.blockSource.getBlockData({
|
|
1284
|
+
archive: proposal.archive
|
|
1285
|
+
});
|
|
916
1286
|
if (!blockData) {
|
|
917
1287
|
this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
|
|
918
1288
|
archive: proposal.archive.toString()
|
|
919
1289
|
});
|
|
920
|
-
return;
|
|
1290
|
+
return false;
|
|
921
1291
|
}
|
|
922
|
-
await this.archiver.
|
|
1292
|
+
await this.archiver.addProposedCheckpoint({
|
|
923
1293
|
header: proposal.checkpointHeader,
|
|
924
1294
|
checkpointNumber: blockData.checkpointNumber,
|
|
925
1295
|
startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
|
|
@@ -927,37 +1297,6 @@ import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
|
927
1297
|
totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
|
|
928
1298
|
feeAssetPriceModifier: proposal.feeAssetPriceModifier
|
|
929
1299
|
});
|
|
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
|
-
}
|
|
1300
|
+
return true;
|
|
962
1301
|
}
|
|
963
1302
|
}
|