@aztec/validator-client 5.0.0-private.20260319 → 5.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -11
- package/dest/checkpoint_builder.d.ts +1 -1
- package/dest/checkpoint_builder.d.ts.map +1 -1
- package/dest/checkpoint_builder.js +4 -2
- package/dest/config.d.ts +9 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +23 -10
- 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 +8 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +18 -6
- package/dest/index.d.ts +2 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/metrics.d.ts +6 -2
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +12 -0
- package/dest/proposal_handler.d.ts +142 -0
- package/dest/proposal_handler.d.ts.map +1 -0
- package/dest/proposal_handler.js +1081 -0
- package/dest/validator.d.ts +27 -19
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +219 -245
- package/package.json +19 -19
- package/src/checkpoint_builder.ts +4 -2
- package/src/config.ts +31 -12
- package/src/duties/validation_service.ts +51 -47
- package/src/factory.ts +25 -4
- package/src/index.ts +1 -1
- package/src/metrics.ts +19 -1
- package/src/proposal_handler.ts +1160 -0
- package/src/validator.ts +278 -272
- package/dest/block_proposal_handler.d.ts +0 -64
- package/dest/block_proposal_handler.d.ts.map +0 -1
- package/dest/block_proposal_handler.js +0 -614
- package/src/block_proposal_handler.ts +0 -632
|
@@ -0,0 +1,1160 @@
|
|
|
1
|
+
import type { Archiver } from '@aztec/archiver';
|
|
2
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
3
|
+
import { type Blob, encodeCheckpointBlobDataFromBlocks, getBlobsPerL1Block } from '@aztec/blob-lib';
|
|
4
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
5
|
+
import type { EpochCache } from '@aztec/epoch-cache';
|
|
6
|
+
import { validateFeeAssetPriceModifier } from '@aztec/ethereum/contracts';
|
|
7
|
+
import {
|
|
8
|
+
BlockNumber,
|
|
9
|
+
CheckpointNumber,
|
|
10
|
+
type CheckpointProposalHash,
|
|
11
|
+
SlotNumber,
|
|
12
|
+
} from '@aztec/foundation/branded-types';
|
|
13
|
+
import { pick } from '@aztec/foundation/collection';
|
|
14
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
15
|
+
import { TimeoutError } from '@aztec/foundation/error';
|
|
16
|
+
import type { LogData } from '@aztec/foundation/log';
|
|
17
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
18
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
19
|
+
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
20
|
+
import type { P2P, PeerId } from '@aztec/p2p';
|
|
21
|
+
import { BlockProposalValidator } from '@aztec/p2p/msg_validators';
|
|
22
|
+
import type { BlockData, L2Block, L2BlockSink, L2BlockSource } from '@aztec/stdlib/block';
|
|
23
|
+
import type { CheckpointReexecutionTracker, ReexecutionOutcome } from '@aztec/stdlib/checkpoint';
|
|
24
|
+
import { getPreviousCheckpointOutHashes, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
25
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
26
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
27
|
+
import type { ITxProvider, ValidatorClientFullConfig, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
|
|
28
|
+
import {
|
|
29
|
+
type L1ToL2MessageSource,
|
|
30
|
+
accumulateCheckpointOutHashes,
|
|
31
|
+
computeInHashFromL1ToL2Messages,
|
|
32
|
+
} from '@aztec/stdlib/messaging';
|
|
33
|
+
import type { BlockProposal, CheckpointAttestation, CheckpointProposalCore } from '@aztec/stdlib/p2p';
|
|
34
|
+
import type { ConsensusTimetable } from '@aztec/stdlib/timetable';
|
|
35
|
+
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
36
|
+
import type { CheckpointGlobalVariables, FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
37
|
+
import {
|
|
38
|
+
ReExFailedTxsError,
|
|
39
|
+
ReExInitialStateMismatchError,
|
|
40
|
+
ReExStateMismatchError,
|
|
41
|
+
ReExTimeoutError,
|
|
42
|
+
TransactionsNotAvailableError,
|
|
43
|
+
} from '@aztec/stdlib/validators';
|
|
44
|
+
import { type TelemetryClient, type Tracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
45
|
+
|
|
46
|
+
import type { FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
47
|
+
import type { ValidatorMetrics } from './metrics.js';
|
|
48
|
+
|
|
49
|
+
export type BlockProposalValidationFailureReason =
|
|
50
|
+
| 'invalid_signature'
|
|
51
|
+
| 'invalid_proposal'
|
|
52
|
+
| 'parent_block_not_found'
|
|
53
|
+
| 'parent_block_wrong_slot'
|
|
54
|
+
| 'in_hash_mismatch'
|
|
55
|
+
| 'global_variables_mismatch'
|
|
56
|
+
| 'block_number_already_exists'
|
|
57
|
+
| 'txs_not_available'
|
|
58
|
+
| 'state_mismatch'
|
|
59
|
+
| 'failed_txs'
|
|
60
|
+
| 'initial_state_mismatch'
|
|
61
|
+
| 'timeout'
|
|
62
|
+
| 'block_proposal_beyond_checkpoint'
|
|
63
|
+
| 'checkpoint_proposal_equivocation'
|
|
64
|
+
| 'unknown_error';
|
|
65
|
+
|
|
66
|
+
type ReexecuteTransactionsResult = {
|
|
67
|
+
block: L2Block;
|
|
68
|
+
failedTxs: FailedTx[];
|
|
69
|
+
reexecutionTimeMs: number;
|
|
70
|
+
totalManaUsed: number;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type BlockProposalValidationSuccessResult = {
|
|
74
|
+
isValid: true;
|
|
75
|
+
blockNumber: BlockNumber;
|
|
76
|
+
reexecutionResult?: ReexecuteTransactionsResult;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type BlockProposalValidationFailureResult = {
|
|
80
|
+
isValid: false;
|
|
81
|
+
reason: BlockProposalValidationFailureReason;
|
|
82
|
+
blockNumber?: BlockNumber;
|
|
83
|
+
reexecutionResult?: ReexecuteTransactionsResult;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export type BlockProposalValidationResult = BlockProposalValidationSuccessResult | BlockProposalValidationFailureResult;
|
|
87
|
+
|
|
88
|
+
export type CheckpointProposalValidationFailureReason =
|
|
89
|
+
| 'invalid_signature'
|
|
90
|
+
| 'invalid_fee_asset_price_modifier'
|
|
91
|
+
| 'last_block_not_found'
|
|
92
|
+
| 'block_fetch_error'
|
|
93
|
+
| 'checkpoint_already_published'
|
|
94
|
+
| 'no_blocks_for_slot'
|
|
95
|
+
| 'last_block_archive_mismatch'
|
|
96
|
+
| 'too_many_blocks_in_checkpoint'
|
|
97
|
+
| 'checkpoint_header_mismatch'
|
|
98
|
+
| 'archive_mismatch'
|
|
99
|
+
| 'out_hash_mismatch'
|
|
100
|
+
| 'checkpoint_validation_failed';
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Mapping from a checkpoint-proposal validation failure reason to the tracker outcome that
|
|
104
|
+
* `handleCheckpointProposal` should record. `undefined` means do not record (signature
|
|
105
|
+
* couldn't be verified, or the checkpoint is already on L1 so the question is moot).
|
|
106
|
+
*/
|
|
107
|
+
/* eslint-disable camelcase */
|
|
108
|
+
const CHECKPOINT_VALIDATION_REASON_TO_OUTCOME: Record<
|
|
109
|
+
CheckpointProposalValidationFailureReason,
|
|
110
|
+
ReexecutionOutcome | undefined
|
|
111
|
+
> = {
|
|
112
|
+
invalid_signature: undefined,
|
|
113
|
+
invalid_fee_asset_price_modifier: 'invalid',
|
|
114
|
+
checkpoint_already_published: undefined,
|
|
115
|
+
last_block_not_found: 'unvalidated',
|
|
116
|
+
block_fetch_error: 'unvalidated',
|
|
117
|
+
no_blocks_for_slot: 'unvalidated',
|
|
118
|
+
last_block_archive_mismatch: 'invalid',
|
|
119
|
+
too_many_blocks_in_checkpoint: 'invalid',
|
|
120
|
+
checkpoint_header_mismatch: 'invalid',
|
|
121
|
+
archive_mismatch: 'invalid',
|
|
122
|
+
out_hash_mismatch: 'invalid',
|
|
123
|
+
checkpoint_validation_failed: 'invalid',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type CheckpointProposalValidationSuccessResult = {
|
|
127
|
+
isValid: true;
|
|
128
|
+
checkpointNumber: CheckpointNumber;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export type CheckpointProposalValidationFailureResult = {
|
|
132
|
+
isValid: false;
|
|
133
|
+
reason: CheckpointProposalValidationFailureReason;
|
|
134
|
+
checkpointNumber?: CheckpointNumber;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type CheckpointProposalValidationResult =
|
|
138
|
+
| CheckpointProposalValidationSuccessResult
|
|
139
|
+
| CheckpointProposalValidationFailureResult;
|
|
140
|
+
|
|
141
|
+
export type CheckpointProposalValidationFailureCallback = (
|
|
142
|
+
proposal: CheckpointProposalCore,
|
|
143
|
+
result: CheckpointProposalValidationFailureResult,
|
|
144
|
+
proposalInfo: LogData,
|
|
145
|
+
) => void | Promise<void>;
|
|
146
|
+
|
|
147
|
+
type CheckpointComputationResult =
|
|
148
|
+
| { checkpointNumber: CheckpointNumber; reason?: undefined }
|
|
149
|
+
| { checkpointNumber?: undefined; reason: 'invalid_proposal' | 'global_variables_mismatch' };
|
|
150
|
+
|
|
151
|
+
type BlockProposalSlotValidationResult =
|
|
152
|
+
| { isValid: true }
|
|
153
|
+
| { isValid: false; reason: 'block_proposal_beyond_checkpoint' | 'checkpoint_proposal_equivocation' };
|
|
154
|
+
|
|
155
|
+
/** Handles block and checkpoint proposals for both validator and non-validator nodes. */
|
|
156
|
+
export class ProposalHandler {
|
|
157
|
+
public readonly tracer: Tracer;
|
|
158
|
+
|
|
159
|
+
/** Cached last checkpoint validation result to avoid double-validation on validator nodes.
|
|
160
|
+
* Keyed by signed-payload hash so two proposals at the same (slot, archive) but with a
|
|
161
|
+
* different `feeAssetPriceModifier` (or any other signed field) are validated independently. */
|
|
162
|
+
private lastCheckpointValidationResult?: {
|
|
163
|
+
payloadHash: CheckpointProposalHash;
|
|
164
|
+
result: CheckpointProposalValidationResult;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/** Archiver reference for setting proposed checkpoints (pipelining). Set via register(). */
|
|
168
|
+
private archiver?: Pick<Archiver, 'addProposedCheckpoint' | 'getProposedCheckpointData'>;
|
|
169
|
+
|
|
170
|
+
/** Returns current validator addresses for own-proposal detection. Set via register(). */
|
|
171
|
+
private getOwnValidatorAddresses?: () => string[];
|
|
172
|
+
|
|
173
|
+
/** P2P proposal pool access for deciding when retained proposals should block archiver processing. */
|
|
174
|
+
private p2pClient?: Pick<P2P, 'getProposalsForSlot'>;
|
|
175
|
+
|
|
176
|
+
private checkpointProposalValidationFailureCallback?: CheckpointProposalValidationFailureCallback;
|
|
177
|
+
|
|
178
|
+
constructor(
|
|
179
|
+
private checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
180
|
+
private worldState: WorldStateSynchronizer,
|
|
181
|
+
private blockSource: L2BlockSource & L2BlockSink,
|
|
182
|
+
private l1ToL2MessageSource: L1ToL2MessageSource,
|
|
183
|
+
private txProvider: ITxProvider,
|
|
184
|
+
private blockProposalValidator: BlockProposalValidator,
|
|
185
|
+
private epochCache: EpochCache,
|
|
186
|
+
private timetable: ConsensusTimetable,
|
|
187
|
+
private config: ValidatorClientFullConfig,
|
|
188
|
+
private blobClient: BlobClientInterface,
|
|
189
|
+
private reexecutionTracker: CheckpointReexecutionTracker,
|
|
190
|
+
private metrics?: ValidatorMetrics,
|
|
191
|
+
private dateProvider: DateProvider = new DateProvider(),
|
|
192
|
+
telemetry: TelemetryClient = getTelemetryClient(),
|
|
193
|
+
private log = createLogger('validator:proposal-handler'),
|
|
194
|
+
) {
|
|
195
|
+
if (config.fishermanMode) {
|
|
196
|
+
this.log = this.log.createChild('[FISHERMAN]');
|
|
197
|
+
}
|
|
198
|
+
this.tracer = telemetry.getTracer('ProposalHandler');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public updateConfig(config: Partial<ValidatorClientFullConfig>): void {
|
|
202
|
+
this.config = { ...this.config, ...config };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
public setCheckpointProposalValidationFailureCallback(callback?: CheckpointProposalValidationFailureCallback): void {
|
|
206
|
+
this.checkpointProposalValidationFailureCallback = callback;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Records the proposer's own checkpoint proposal as a `valid` outcome in the re-execution
|
|
211
|
+
* tracker. Without this, the node's own checkpoint proposals never flow through
|
|
212
|
+
* `handleCheckpointProposal` (proposers don't validate their own proposals), so its sentinel
|
|
213
|
+
* sees no outcome for slots where it was the proposer and reports itself as inactive.
|
|
214
|
+
*
|
|
215
|
+
* `archive` should be the locally-computed archive (NOT the broadcast archive, which may have
|
|
216
|
+
* been deliberately corrupted in tests via `broadcastInvalidBlockProposal` /
|
|
217
|
+
* `broadcastInvalidCheckpointProposalOnly`). Recording the local archive correctly models the
|
|
218
|
+
* proposer's own view of its own work.
|
|
219
|
+
*/
|
|
220
|
+
public recordOwnCheckpointProposalAsValid(slot: SlotNumber, archive: Fr, checkpointNumber: CheckpointNumber): void {
|
|
221
|
+
this.reexecutionTracker.recordOutcome(slot, archive, 'valid', checkpointNumber);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Registers handlers for block and checkpoint proposals on the p2p client.
|
|
226
|
+
* Records the p2p client so validation can inspect retained proposals.
|
|
227
|
+
* Block proposals are registered for non-validator nodes (validators register their own enhanced handler).
|
|
228
|
+
* The all-nodes checkpoint proposal handler is always registered for validation, caching, and pipelining.
|
|
229
|
+
* @param archiver - Archiver reference for setting proposed checkpoints (pipelining)
|
|
230
|
+
* @param getOwnValidatorAddresses - Returns current validator addresses for own-proposal detection
|
|
231
|
+
*/
|
|
232
|
+
register(
|
|
233
|
+
p2pClient: P2P,
|
|
234
|
+
shouldReexecute: boolean,
|
|
235
|
+
archiver?: Pick<Archiver, 'addProposedCheckpoint' | 'getProposedCheckpointData'>,
|
|
236
|
+
getOwnValidatorAddresses?: () => string[],
|
|
237
|
+
): ProposalHandler {
|
|
238
|
+
this.p2pClient = p2pClient;
|
|
239
|
+
this.archiver = archiver;
|
|
240
|
+
this.getOwnValidatorAddresses = getOwnValidatorAddresses;
|
|
241
|
+
|
|
242
|
+
// Non-validator handler that processes or re-executes for monitoring but does not attest.
|
|
243
|
+
// Returns boolean indicating whether the proposal was valid.
|
|
244
|
+
const blockHandler = async (proposal: BlockProposal, proposalSender: PeerId): Promise<boolean> => {
|
|
245
|
+
try {
|
|
246
|
+
const { slotNumber, blockNumber } = proposal;
|
|
247
|
+
const result = await this.handleBlockProposal(proposal, proposalSender, shouldReexecute);
|
|
248
|
+
if (result.isValid) {
|
|
249
|
+
this.log.info(`Non-validator block proposal ${blockNumber} at slot ${slotNumber} handled`, {
|
|
250
|
+
blockNumber: result.blockNumber,
|
|
251
|
+
slotNumber,
|
|
252
|
+
reexecutionTimeMs: result.reexecutionResult?.reexecutionTimeMs,
|
|
253
|
+
totalManaUsed: result.reexecutionResult?.totalManaUsed,
|
|
254
|
+
numTxs: result.reexecutionResult?.block?.body?.txEffects?.length ?? 0,
|
|
255
|
+
reexecuted: shouldReexecute,
|
|
256
|
+
});
|
|
257
|
+
return true;
|
|
258
|
+
} else {
|
|
259
|
+
this.log.warn(
|
|
260
|
+
`Non-validator block proposal ${blockNumber} at slot ${slotNumber} failed processing with ${result.reason}`,
|
|
261
|
+
{ blockNumber: result.blockNumber, slotNumber, reason: result.reason },
|
|
262
|
+
);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
this.log.error('Error processing block proposal in non-validator handler', error);
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
p2pClient.registerBlockProposalHandler(blockHandler);
|
|
272
|
+
|
|
273
|
+
// All-nodes checkpoint proposal handler: validates, caches, and sets proposed checkpoint for pipelining.
|
|
274
|
+
// Runs for all nodes (validators and non-validators). Validators get the cached result in the
|
|
275
|
+
// validator-specific callback (attestToCheckpointProposal) which runs after this one.
|
|
276
|
+
const checkpointHandler = async (
|
|
277
|
+
proposal: CheckpointProposalCore,
|
|
278
|
+
_sender: PeerId,
|
|
279
|
+
): Promise<CheckpointAttestation[] | undefined> => {
|
|
280
|
+
try {
|
|
281
|
+
const pipeliningTimer = new Timer();
|
|
282
|
+
const proposalInfo: LogData = {
|
|
283
|
+
slot: proposal.slotNumber,
|
|
284
|
+
archive: proposal.archive.toString(),
|
|
285
|
+
proposer: proposal.getSender()?.toString(),
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
if (this.config.skipCheckpointProposalValidation) {
|
|
289
|
+
this.log.warn(`Skipping checkpoint proposal validation for slot ${proposal.slotNumber}`, proposalInfo);
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (await this.epochCache.isEscapeHatchOpenAtSlot(proposal.slotNumber)) {
|
|
294
|
+
this.log.warn(
|
|
295
|
+
`Escape hatch open for slot ${proposal.slotNumber}, skipping checkpoint proposal validation`,
|
|
296
|
+
proposalInfo,
|
|
297
|
+
);
|
|
298
|
+
return undefined;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// A proposal is "own" when it was signed by a validator key this node also owns. The true local
|
|
302
|
+
// proposer already built, validated, and stored this checkpoint before broadcasting, so a matching
|
|
303
|
+
// proposed checkpoint is already in its archiver — skip the redundant re-validation. An HA peer that
|
|
304
|
+
// shares the proposer's keys sees the same "own" proposal over gossip but never built it, so it has
|
|
305
|
+
// nothing stored; it falls through to the normal validate-and-persist path below to hydrate the
|
|
306
|
+
// proposed-checkpoint metadata it needs to build the next slot on top of this checkpoint.
|
|
307
|
+
const proposer = proposal.getSender();
|
|
308
|
+
const ownAddresses = this.getOwnValidatorAddresses?.();
|
|
309
|
+
const isOwnProposal = proposer && ownAddresses?.some(addr => addr === proposer.toString());
|
|
310
|
+
|
|
311
|
+
if (isOwnProposal) {
|
|
312
|
+
const existing = await this.archiver?.getProposedCheckpointData({ slot: proposal.slotNumber });
|
|
313
|
+
if (existing?.archive.root.equals(proposal.archive)) {
|
|
314
|
+
this.log.debug(`Skipping sync for existing own checkpoint proposal at slot ${proposal.slotNumber}`);
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const result = await this.handleCheckpointProposal(proposal, proposalInfo);
|
|
320
|
+
if (!result.isValid) {
|
|
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
|
+
}
|
|
327
|
+
}
|
|
328
|
+
} catch (err) {
|
|
329
|
+
this.log.warn(`Error handling checkpoint proposal for slot ${proposal.slotNumber}`, { err });
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
p2pClient.registerAllNodesCheckpointProposalHandler(checkpointHandler);
|
|
335
|
+
|
|
336
|
+
return this;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async handleBlockProposal(
|
|
340
|
+
proposal: BlockProposal,
|
|
341
|
+
proposalSender: PeerId,
|
|
342
|
+
shouldReexecute: boolean,
|
|
343
|
+
): Promise<BlockProposalValidationResult> {
|
|
344
|
+
const slotNumber = proposal.slotNumber;
|
|
345
|
+
const proposer = proposal.getSender();
|
|
346
|
+
|
|
347
|
+
// Reject proposals with invalid signatures
|
|
348
|
+
if (!proposer) {
|
|
349
|
+
this.log.warn(`Received proposal with invalid signature for slot ${slotNumber}`);
|
|
350
|
+
return { isValid: false, reason: 'invalid_signature' };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const proposalInfo = {
|
|
354
|
+
...proposal.toBlockInfo(),
|
|
355
|
+
proposer: proposer.toString(),
|
|
356
|
+
blockNumber: undefined as BlockNumber | undefined,
|
|
357
|
+
checkpointNumber: undefined as CheckpointNumber | undefined,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
this.log.info(`Processing proposal for slot ${slotNumber}`, {
|
|
361
|
+
...proposalInfo,
|
|
362
|
+
txHashes: proposal.txHashes.map(t => t.toString()),
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// Check that the proposal is from the current proposer, or the next proposer
|
|
366
|
+
// This should have been handled by the p2p layer, but we double check here out of caution
|
|
367
|
+
const validationResult = await this.blockProposalValidator.validate(proposal);
|
|
368
|
+
if (validationResult.result !== 'accept') {
|
|
369
|
+
this.log.warn(`Proposal is not valid, skipping processing`, proposalInfo);
|
|
370
|
+
return { isValid: false, reason: 'invalid_proposal' };
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const retainedSlotValidation = await this.validateNewBlockInSlot(proposal);
|
|
374
|
+
if (!retainedSlotValidation.isValid) {
|
|
375
|
+
this.log.info(`Block proposal conflicts with retained proposals, skipping archiver processing`, {
|
|
376
|
+
...proposalInfo,
|
|
377
|
+
indexWithinCheckpoint: proposal.indexWithinCheckpoint,
|
|
378
|
+
reason: retainedSlotValidation.reason,
|
|
379
|
+
});
|
|
380
|
+
return { isValid: false, blockNumber: proposal.blockNumber, reason: retainedSlotValidation.reason };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// The proposer builds ahead of L1 submission under pipelining, so the block source won't have
|
|
384
|
+
// synced to the proposed slot yet. We deliberately do not wait for it to sync here, to avoid
|
|
385
|
+
// eating into the attestation window.
|
|
386
|
+
|
|
387
|
+
// Check that the parent proposal is a block we know, otherwise reexecution would fail.
|
|
388
|
+
// If we don't find it immediately, we keep retrying for a while; it may be we still
|
|
389
|
+
// need to process other block proposals to get to it.
|
|
390
|
+
const parentBlock = await this.getParentBlock(proposal);
|
|
391
|
+
if (parentBlock === undefined) {
|
|
392
|
+
this.log.warn(`Parent block for proposal not found, skipping processing`, proposalInfo);
|
|
393
|
+
return { isValid: false, reason: 'parent_block_not_found' };
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Check that the parent block's slot is not greater than the proposal's slot.
|
|
397
|
+
if (parentBlock !== 'genesis' && parentBlock.header.getSlot() > slotNumber) {
|
|
398
|
+
this.log.warn(`Parent block slot is greater than proposal slot, skipping processing`, {
|
|
399
|
+
parentBlockSlot: parentBlock.header.getSlot().toString(),
|
|
400
|
+
proposalSlot: slotNumber.toString(),
|
|
401
|
+
...proposalInfo,
|
|
402
|
+
});
|
|
403
|
+
return { isValid: false, reason: 'parent_block_wrong_slot' };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Compute the block number based on the parent block
|
|
407
|
+
const blockNumber =
|
|
408
|
+
parentBlock === 'genesis'
|
|
409
|
+
? BlockNumber(INITIAL_L2_BLOCK_NUM)
|
|
410
|
+
: BlockNumber(parentBlock.header.getBlockNumber() + 1);
|
|
411
|
+
proposalInfo.blockNumber = blockNumber;
|
|
412
|
+
|
|
413
|
+
// Check that this block number does not exist already
|
|
414
|
+
const existingBlock = await this.blockSource.getBlockData({ number: blockNumber });
|
|
415
|
+
if (existingBlock) {
|
|
416
|
+
this.log.warn(`Block number ${blockNumber} already exists, skipping processing`, proposalInfo);
|
|
417
|
+
return { isValid: false, blockNumber, reason: 'block_number_already_exists' };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Collect txs from the proposal. We start doing this as early as possible,
|
|
421
|
+
// 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.
|
|
422
|
+
const { txs, missingTxs } = await this.txProvider.getTxsForBlockProposal(proposal, blockNumber, {
|
|
423
|
+
pinnedPeer: proposalSender,
|
|
424
|
+
deadline: this.getReexecutionDeadline(slotNumber),
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Record the tx-collection outcome on the re-execution tracker
|
|
428
|
+
this.reexecutionTracker.recordTxsCollected(slotNumber, proposal.indexWithinCheckpoint, missingTxs.length === 0);
|
|
429
|
+
|
|
430
|
+
// If reexecution is disabled, bail. We were just interested in triggering tx collection.
|
|
431
|
+
if (!shouldReexecute) {
|
|
432
|
+
this.log.info(
|
|
433
|
+
`Received valid block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
434
|
+
proposalInfo,
|
|
435
|
+
);
|
|
436
|
+
return { isValid: true, blockNumber };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Compute the checkpoint number for this block and validate checkpoint consistency
|
|
440
|
+
const checkpointResult = this.computeCheckpointNumber(proposal, parentBlock, proposalInfo);
|
|
441
|
+
if (checkpointResult.reason) {
|
|
442
|
+
return { isValid: false, blockNumber, reason: checkpointResult.reason };
|
|
443
|
+
}
|
|
444
|
+
const checkpointNumber = checkpointResult.checkpointNumber;
|
|
445
|
+
proposalInfo.checkpointNumber = checkpointNumber;
|
|
446
|
+
|
|
447
|
+
// Check that I have the same set of l1ToL2Messages as the proposal
|
|
448
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
449
|
+
const computedInHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
450
|
+
const proposalInHash = proposal.inHash;
|
|
451
|
+
if (!computedInHash.equals(proposalInHash)) {
|
|
452
|
+
this.log.warn(`L1 to L2 messages in hash mismatch, skipping processing`, {
|
|
453
|
+
proposalInHash: proposalInHash.toString(),
|
|
454
|
+
computedInHash: computedInHash.toString(),
|
|
455
|
+
...proposalInfo,
|
|
456
|
+
});
|
|
457
|
+
return { isValid: false, blockNumber, reason: 'in_hash_mismatch' };
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Check that all of the transactions in the proposal are available
|
|
461
|
+
if (missingTxs.length > 0) {
|
|
462
|
+
this.log.warn(`Missing ${missingTxs.length} txs to process proposal`, { ...proposalInfo, missingTxs });
|
|
463
|
+
return { isValid: false, blockNumber, reason: 'txs_not_available' };
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
467
|
+
// Mirror the proposer-side fallback: under pipelining the immediately-preceding cp may not
|
|
468
|
+
// yet be on L1, in which case the helper grafts the locally-known proposed cp's outHash.
|
|
469
|
+
const epoch = getEpochAtSlot(slotNumber, this.epochCache.getL1Constants());
|
|
470
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
471
|
+
blockSource: this.blockSource,
|
|
472
|
+
epoch,
|
|
473
|
+
checkpointNumber,
|
|
474
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
475
|
+
pipeliningEnabled: true,
|
|
476
|
+
log: this.log,
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// Try re-executing the transactions in the proposal if needed
|
|
480
|
+
let reexecutionResult;
|
|
481
|
+
try {
|
|
482
|
+
this.log.verbose(`Re-executing transactions in the proposal`, proposalInfo);
|
|
483
|
+
reexecutionResult = await this.reexecuteTransactions(
|
|
484
|
+
proposal,
|
|
485
|
+
blockNumber,
|
|
486
|
+
checkpointNumber,
|
|
487
|
+
txs,
|
|
488
|
+
l1ToL2Messages,
|
|
489
|
+
previousCheckpointOutHashes,
|
|
490
|
+
);
|
|
491
|
+
} catch (error) {
|
|
492
|
+
this.log.error(`Error reexecuting txs while processing block proposal`, error, proposalInfo);
|
|
493
|
+
const reason = this.getReexecuteFailureReason(error);
|
|
494
|
+
return { isValid: false, blockNumber, reason, reexecutionResult };
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// If we succeeded, push this block into the archiver (unless disabled)
|
|
498
|
+
if (reexecutionResult?.block && this.config.skipPushProposedBlocksToArchiver === false) {
|
|
499
|
+
await this.blockSource.addBlock(reexecutionResult.block);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
this.log.info(
|
|
503
|
+
`Successfully re-executed block ${blockNumber} proposal at index ${proposal.indexWithinCheckpoint} on slot ${slotNumber}`,
|
|
504
|
+
{ ...proposalInfo, ...pick(reexecutionResult, 'reexecutionTimeMs', 'totalManaUsed') },
|
|
505
|
+
);
|
|
506
|
+
|
|
507
|
+
return { isValid: true, blockNumber, reexecutionResult };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
private async validateNewBlockInSlot(blockProposal: BlockProposal): Promise<BlockProposalSlotValidationResult> {
|
|
511
|
+
if (!this.p2pClient) {
|
|
512
|
+
return { isValid: true };
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const { blockProposals, checkpointProposals } = await this.p2pClient.getProposalsForSlot(blockProposal.slotNumber);
|
|
516
|
+
|
|
517
|
+
if (checkpointProposals.length === 0) {
|
|
518
|
+
return { isValid: true };
|
|
519
|
+
} else if (checkpointProposals.length > 1) {
|
|
520
|
+
return { isValid: false, reason: 'checkpoint_proposal_equivocation' };
|
|
521
|
+
} else {
|
|
522
|
+
const checkpointProposal = checkpointProposals[0];
|
|
523
|
+
const terminalBlock = blockProposals.find(block => block.archive.equals(checkpointProposal.archive));
|
|
524
|
+
return terminalBlock !== undefined && blockProposal.indexWithinCheckpoint > terminalBlock.indexWithinCheckpoint
|
|
525
|
+
? { isValid: false, reason: 'block_proposal_beyond_checkpoint' }
|
|
526
|
+
: { isValid: true };
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
private async getParentBlock(proposal: BlockProposal): Promise<'genesis' | BlockData | undefined> {
|
|
531
|
+
const parentArchive = proposal.blockHeader.lastArchive.root;
|
|
532
|
+
const { genesisArchiveRoot } = await this.blockSource.getGenesisValues();
|
|
533
|
+
|
|
534
|
+
if (parentArchive.equals(genesisArchiveRoot)) {
|
|
535
|
+
return 'genesis';
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const deadline = this.getReexecutionDeadline(proposal.slotNumber);
|
|
539
|
+
const timeoutDurationMs = deadline.getTime() - this.dateProvider.now();
|
|
540
|
+
|
|
541
|
+
try {
|
|
542
|
+
return (
|
|
543
|
+
(await this.blockSource.getBlockData({ archive: parentArchive })) ??
|
|
544
|
+
(timeoutDurationMs <= 0
|
|
545
|
+
? undefined
|
|
546
|
+
: await retryUntil(
|
|
547
|
+
() =>
|
|
548
|
+
this.blockSource.syncImmediate().then(() => this.blockSource.getBlockData({ archive: parentArchive })),
|
|
549
|
+
'force archiver sync',
|
|
550
|
+
{ deadline, dateProvider: this.dateProvider },
|
|
551
|
+
0.5,
|
|
552
|
+
))
|
|
553
|
+
);
|
|
554
|
+
} catch (err) {
|
|
555
|
+
if (err instanceof TimeoutError) {
|
|
556
|
+
this.log.debug(`Timed out getting parent block by archive root`, { parentArchive });
|
|
557
|
+
} else {
|
|
558
|
+
this.log.error('Error getting parent block by archive root', err, { parentArchive });
|
|
559
|
+
}
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private computeCheckpointNumber(
|
|
565
|
+
proposal: BlockProposal,
|
|
566
|
+
parentBlock: 'genesis' | BlockData,
|
|
567
|
+
proposalInfo: object,
|
|
568
|
+
): CheckpointComputationResult {
|
|
569
|
+
if (parentBlock === 'genesis') {
|
|
570
|
+
// First block is in checkpoint 1
|
|
571
|
+
if (proposal.indexWithinCheckpoint !== 0) {
|
|
572
|
+
this.log.warn(`First block proposal has non-zero indexWithinCheckpoint`, proposalInfo);
|
|
573
|
+
return { reason: 'invalid_proposal' };
|
|
574
|
+
}
|
|
575
|
+
return { checkpointNumber: CheckpointNumber.INITIAL };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (proposal.indexWithinCheckpoint === 0) {
|
|
579
|
+
// If this is the first block in a new checkpoint, increment the checkpoint number
|
|
580
|
+
if (!(proposal.blockHeader.getSlot() > parentBlock.header.getSlot())) {
|
|
581
|
+
this.log.warn(`Slot should be greater than parent block slot for first block in checkpoint`, proposalInfo);
|
|
582
|
+
return { reason: 'invalid_proposal' };
|
|
583
|
+
}
|
|
584
|
+
return { checkpointNumber: CheckpointNumber(parentBlock.checkpointNumber + 1) };
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// Otherwise it should follow the previous block in the same checkpoint
|
|
588
|
+
if (proposal.indexWithinCheckpoint !== parentBlock.indexWithinCheckpoint + 1) {
|
|
589
|
+
this.log.warn(`Non-sequential indexWithinCheckpoint`, proposalInfo);
|
|
590
|
+
return { reason: 'invalid_proposal' };
|
|
591
|
+
}
|
|
592
|
+
if (proposal.blockHeader.getSlot() !== parentBlock.header.getSlot()) {
|
|
593
|
+
this.log.warn(`Slot should be equal to parent block slot for non-first block in checkpoint`, proposalInfo);
|
|
594
|
+
return { reason: 'invalid_proposal' };
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// For non-first blocks in a checkpoint, validate global variables match parent (except blockNumber)
|
|
598
|
+
const validationResult = this.validateNonFirstBlockInCheckpoint(proposal, parentBlock, proposalInfo);
|
|
599
|
+
if (validationResult) {
|
|
600
|
+
return validationResult;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
return { checkpointNumber: parentBlock.checkpointNumber };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Validates that a non-first block in a checkpoint has consistent global variables with its parent.
|
|
608
|
+
* For blocks with indexWithinCheckpoint > 0, all global variables except blockNumber must match the parent.
|
|
609
|
+
* @returns A failure result if validation fails, undefined if validation passes
|
|
610
|
+
*/
|
|
611
|
+
private validateNonFirstBlockInCheckpoint(
|
|
612
|
+
proposal: BlockProposal,
|
|
613
|
+
parentBlock: BlockData,
|
|
614
|
+
proposalInfo: object,
|
|
615
|
+
): CheckpointComputationResult | undefined {
|
|
616
|
+
const proposalGlobals = proposal.blockHeader.globalVariables;
|
|
617
|
+
const parentGlobals = parentBlock.header.globalVariables;
|
|
618
|
+
|
|
619
|
+
// All global variables except blockNumber should match the parent
|
|
620
|
+
// blockNumber naturally increments between blocks
|
|
621
|
+
if (!proposalGlobals.chainId.equals(parentGlobals.chainId)) {
|
|
622
|
+
this.log.warn(`Non-first block in checkpoint has mismatched chainId`, {
|
|
623
|
+
...proposalInfo,
|
|
624
|
+
proposalChainId: proposalGlobals.chainId.toString(),
|
|
625
|
+
parentChainId: parentGlobals.chainId.toString(),
|
|
626
|
+
});
|
|
627
|
+
return { reason: 'global_variables_mismatch' };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (!proposalGlobals.version.equals(parentGlobals.version)) {
|
|
631
|
+
this.log.warn(`Non-first block in checkpoint has mismatched version`, {
|
|
632
|
+
...proposalInfo,
|
|
633
|
+
proposalVersion: proposalGlobals.version.toString(),
|
|
634
|
+
parentVersion: parentGlobals.version.toString(),
|
|
635
|
+
});
|
|
636
|
+
return { reason: 'global_variables_mismatch' };
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if (proposalGlobals.slotNumber !== parentGlobals.slotNumber) {
|
|
640
|
+
this.log.warn(`Non-first block in checkpoint has mismatched slotNumber`, {
|
|
641
|
+
...proposalInfo,
|
|
642
|
+
proposalSlotNumber: proposalGlobals.slotNumber,
|
|
643
|
+
parentSlotNumber: parentGlobals.slotNumber,
|
|
644
|
+
});
|
|
645
|
+
return { reason: 'global_variables_mismatch' };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
if (proposalGlobals.timestamp !== parentGlobals.timestamp) {
|
|
649
|
+
this.log.warn(`Non-first block in checkpoint has mismatched timestamp`, {
|
|
650
|
+
...proposalInfo,
|
|
651
|
+
proposalTimestamp: proposalGlobals.timestamp.toString(),
|
|
652
|
+
parentTimestamp: parentGlobals.timestamp.toString(),
|
|
653
|
+
});
|
|
654
|
+
return { reason: 'global_variables_mismatch' };
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (!proposalGlobals.coinbase.equals(parentGlobals.coinbase)) {
|
|
658
|
+
this.log.warn(`Non-first block in checkpoint has mismatched coinbase`, {
|
|
659
|
+
...proposalInfo,
|
|
660
|
+
proposalCoinbase: proposalGlobals.coinbase.toString(),
|
|
661
|
+
parentCoinbase: parentGlobals.coinbase.toString(),
|
|
662
|
+
});
|
|
663
|
+
return { reason: 'global_variables_mismatch' };
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
if (!proposalGlobals.feeRecipient.equals(parentGlobals.feeRecipient)) {
|
|
667
|
+
this.log.warn(`Non-first block in checkpoint has mismatched feeRecipient`, {
|
|
668
|
+
...proposalInfo,
|
|
669
|
+
proposalFeeRecipient: proposalGlobals.feeRecipient.toString(),
|
|
670
|
+
parentFeeRecipient: parentGlobals.feeRecipient.toString(),
|
|
671
|
+
});
|
|
672
|
+
return { reason: 'global_variables_mismatch' };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
if (!proposalGlobals.gasFees.equals(parentGlobals.gasFees)) {
|
|
676
|
+
this.log.warn(`Non-first block in checkpoint has mismatched gasFees`, {
|
|
677
|
+
...proposalInfo,
|
|
678
|
+
proposalGasFees: proposalGlobals.gasFees.toInspect(),
|
|
679
|
+
parentGasFees: parentGlobals.gasFees.toInspect(),
|
|
680
|
+
});
|
|
681
|
+
return { reason: 'global_variables_mismatch' };
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return undefined;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Hard re-execution/validation deadline for any block or checkpoint proposal targeting `slotNumber`:
|
|
689
|
+
* the single consensus `attestation_deadline` (`target_slot_start + S - 2E`). This is the latest the
|
|
690
|
+
* checkpoint can land on L1 in the target slot; all nodes agree on it. Loosened from the previous
|
|
691
|
+
* next-wall-clock-slot-boundary bound (see the timetable spec / refactor notes).
|
|
692
|
+
*/
|
|
693
|
+
private getReexecutionDeadline(slotNumber: SlotNumber): Date {
|
|
694
|
+
return new Date(this.timetable.getAttestationDeadline(slotNumber) * 1000);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
private getReexecuteFailureReason(err: any): BlockProposalValidationFailureReason {
|
|
698
|
+
if (err instanceof TransactionsNotAvailableError) {
|
|
699
|
+
return 'txs_not_available';
|
|
700
|
+
} else if (err instanceof ReExInitialStateMismatchError) {
|
|
701
|
+
return 'initial_state_mismatch';
|
|
702
|
+
} else if (err instanceof ReExStateMismatchError) {
|
|
703
|
+
return 'state_mismatch';
|
|
704
|
+
} else if (err instanceof ReExFailedTxsError) {
|
|
705
|
+
return 'failed_txs';
|
|
706
|
+
} else if (err instanceof ReExTimeoutError) {
|
|
707
|
+
return 'timeout';
|
|
708
|
+
} else {
|
|
709
|
+
return 'unknown_error';
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
async reexecuteTransactions(
|
|
714
|
+
proposal: BlockProposal,
|
|
715
|
+
blockNumber: BlockNumber,
|
|
716
|
+
checkpointNumber: CheckpointNumber,
|
|
717
|
+
txs: Tx[],
|
|
718
|
+
l1ToL2Messages: Fr[],
|
|
719
|
+
previousCheckpointOutHashes: Fr[],
|
|
720
|
+
): Promise<ReexecuteTransactionsResult> {
|
|
721
|
+
const { blockHeader, txHashes } = proposal;
|
|
722
|
+
|
|
723
|
+
// If we do not have all of the transactions, then we should fail
|
|
724
|
+
if (txs.length !== txHashes.length) {
|
|
725
|
+
const foundTxHashes = txs.map(tx => tx.getTxHash());
|
|
726
|
+
const missingTxHashes = txHashes.filter(txHash => !foundTxHashes.some(h => h.equals(txHash)));
|
|
727
|
+
throw new TransactionsNotAvailableError(missingTxHashes);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const timer = new Timer();
|
|
731
|
+
const slot = proposal.slotNumber;
|
|
732
|
+
const config = this.checkpointsBuilder.getConfig();
|
|
733
|
+
|
|
734
|
+
// Get prior blocks in this checkpoint (same slot before current block)
|
|
735
|
+
const allBlocksInSlot = await this.blockSource.getBlocksForSlot(slot);
|
|
736
|
+
const priorBlocks = allBlocksInSlot.filter(b => b.number < blockNumber && b.header.getSlot() === slot);
|
|
737
|
+
|
|
738
|
+
// Fork before the block to be built
|
|
739
|
+
const parentBlockNumber = BlockNumber(blockNumber - 1);
|
|
740
|
+
await this.worldState.syncImmediate(parentBlockNumber);
|
|
741
|
+
await using fork = await this.worldState.fork(parentBlockNumber);
|
|
742
|
+
|
|
743
|
+
// Verify the fork's archive root matches the proposal's expected last archive.
|
|
744
|
+
// If they don't match, our world state synced to a different chain and reexecution would fail.
|
|
745
|
+
const forkArchiveRoot = new Fr((await fork.getTreeInfo(MerkleTreeId.ARCHIVE)).root);
|
|
746
|
+
if (!forkArchiveRoot.equals(proposal.blockHeader.lastArchive.root)) {
|
|
747
|
+
throw new ReExInitialStateMismatchError(proposal.blockHeader.lastArchive.root, forkArchiveRoot);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// Build checkpoint constants from proposal (excludes blockNumber which is per-block)
|
|
751
|
+
const constants: CheckpointGlobalVariables = {
|
|
752
|
+
chainId: new Fr(config.l1ChainId),
|
|
753
|
+
version: new Fr(config.rollupVersion),
|
|
754
|
+
slotNumber: slot,
|
|
755
|
+
timestamp: blockHeader.globalVariables.timestamp,
|
|
756
|
+
coinbase: blockHeader.globalVariables.coinbase,
|
|
757
|
+
feeRecipient: blockHeader.globalVariables.feeRecipient,
|
|
758
|
+
gasFees: blockHeader.globalVariables.gasFees,
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
// Create checkpoint builder with prior blocks
|
|
762
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
763
|
+
checkpointNumber,
|
|
764
|
+
constants,
|
|
765
|
+
0n, // only takes effect in the following checkpoint.
|
|
766
|
+
l1ToL2Messages,
|
|
767
|
+
previousCheckpointOutHashes,
|
|
768
|
+
fork,
|
|
769
|
+
priorBlocks,
|
|
770
|
+
this.log.getBindings(),
|
|
771
|
+
);
|
|
772
|
+
|
|
773
|
+
// Build the new block
|
|
774
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
775
|
+
const maxBlockGas =
|
|
776
|
+
this.config.validateMaxL2BlockGas !== undefined || this.config.validateMaxDABlockGas !== undefined
|
|
777
|
+
? new Gas(this.config.validateMaxDABlockGas ?? Infinity, this.config.validateMaxL2BlockGas ?? Infinity)
|
|
778
|
+
: undefined;
|
|
779
|
+
const result = await checkpointBuilder.buildBlock(txs, blockNumber, blockHeader.globalVariables.timestamp, {
|
|
780
|
+
isBuildingProposal: false,
|
|
781
|
+
minValidTxs: 0,
|
|
782
|
+
deadline,
|
|
783
|
+
expectedEndState: blockHeader.state,
|
|
784
|
+
maxTransactions: this.config.validateMaxTxsPerBlock,
|
|
785
|
+
maxBlockGas,
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
const { block, failedTxs } = result;
|
|
789
|
+
const numFailedTxs = failedTxs.length;
|
|
790
|
+
|
|
791
|
+
this.log.verbose(`Block proposal ${blockNumber} at slot ${slot} transaction re-execution complete`, {
|
|
792
|
+
numFailedTxs,
|
|
793
|
+
numProposalTxs: txHashes.length,
|
|
794
|
+
numProcessedTxs: block.body.txEffects.length,
|
|
795
|
+
blockNumber,
|
|
796
|
+
slot,
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
if (numFailedTxs > 0) {
|
|
800
|
+
this.metrics?.recordFailedReexecution(proposal);
|
|
801
|
+
throw new ReExFailedTxsError(numFailedTxs);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (block.body.txEffects.length !== txHashes.length) {
|
|
805
|
+
this.metrics?.recordFailedReexecution(proposal);
|
|
806
|
+
throw new ReExTimeoutError();
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// Throw a ReExStateMismatchError error if state updates do not match
|
|
810
|
+
// Compare the full block structure (archive and header) from the built block with the proposal
|
|
811
|
+
const archiveMatches = proposal.archive.equals(block.archive.root);
|
|
812
|
+
const headerMatches = proposal.blockHeader.equals(block.header);
|
|
813
|
+
if (!archiveMatches || !headerMatches) {
|
|
814
|
+
this.log.warn(`Re-execution state mismatch for slot ${slot}`, {
|
|
815
|
+
expectedArchive: block.archive.root.toString(),
|
|
816
|
+
actualArchive: proposal.archive.toString(),
|
|
817
|
+
expectedHeader: block.header.toInspect(),
|
|
818
|
+
actualHeader: proposal.blockHeader.toInspect(),
|
|
819
|
+
});
|
|
820
|
+
this.metrics?.recordFailedReexecution(proposal);
|
|
821
|
+
throw new ReExStateMismatchError(proposal.archive, block.archive.root);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const reexecutionTimeMs = timer.ms();
|
|
825
|
+
const totalManaUsed = block.header.totalManaUsed.toNumber() / 1e6;
|
|
826
|
+
|
|
827
|
+
this.metrics?.recordReex(reexecutionTimeMs, txs.length, totalManaUsed);
|
|
828
|
+
|
|
829
|
+
return {
|
|
830
|
+
block,
|
|
831
|
+
failedTxs,
|
|
832
|
+
reexecutionTimeMs,
|
|
833
|
+
totalManaUsed,
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Validates a checkpoint proposal, caches the result, and uploads blobs if configured.
|
|
839
|
+
* Returns a cached result if the same proposal (archive + slot) was already validated.
|
|
840
|
+
* Used by both the all-nodes callback (via register) and the validator client (via delegation).
|
|
841
|
+
*/
|
|
842
|
+
async handleCheckpointProposal(
|
|
843
|
+
proposal: CheckpointProposalCore,
|
|
844
|
+
proposalInfo: LogData,
|
|
845
|
+
): Promise<CheckpointProposalValidationResult> {
|
|
846
|
+
const slot = proposal.slotNumber;
|
|
847
|
+
const payloadHash = proposal.getPayloadHash();
|
|
848
|
+
|
|
849
|
+
// Check cache: same signed-payload hash means we already validated this exact proposal.
|
|
850
|
+
if (this.lastCheckpointValidationResult && this.lastCheckpointValidationResult.payloadHash === payloadHash) {
|
|
851
|
+
this.log.debug(`Returning cached validation result for checkpoint proposal at slot ${slot}`, proposalInfo);
|
|
852
|
+
return this.lastCheckpointValidationResult.result;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const proposer = proposal.getSender();
|
|
856
|
+
let result: CheckpointProposalValidationResult;
|
|
857
|
+
if (!proposer) {
|
|
858
|
+
this.log.warn(`Received checkpoint proposal with invalid signature for slot ${proposal.slotNumber}`);
|
|
859
|
+
result = { isValid: false as const, reason: 'invalid_signature' };
|
|
860
|
+
} else if (!validateFeeAssetPriceModifier(proposal.feeAssetPriceModifier)) {
|
|
861
|
+
this.log.warn(
|
|
862
|
+
`Received checkpoint proposal with invalid feeAssetPriceModifier ${proposal.feeAssetPriceModifier} for slot ${proposal.slotNumber}`,
|
|
863
|
+
);
|
|
864
|
+
result = { isValid: false, reason: 'invalid_fee_asset_price_modifier' };
|
|
865
|
+
} else {
|
|
866
|
+
result = await this.validateCheckpointProposal(proposal, proposalInfo);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
this.lastCheckpointValidationResult = { payloadHash, result };
|
|
870
|
+
|
|
871
|
+
// Record the outcome on the re-execution tracker.
|
|
872
|
+
const outcome = result.isValid ? ('valid' as const) : CHECKPOINT_VALIDATION_REASON_TO_OUTCOME[result.reason];
|
|
873
|
+
if (outcome !== undefined) {
|
|
874
|
+
this.reexecutionTracker.recordOutcome(slot, proposal.archive, outcome, result.checkpointNumber);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// Drop tracker entries for checkpoints that have reached L1 finality.
|
|
878
|
+
try {
|
|
879
|
+
const tips = await this.blockSource.getL2Tips();
|
|
880
|
+
const finalizedCheckpointNumber = tips.finalized.checkpoint.number;
|
|
881
|
+
if (finalizedCheckpointNumber > 0) {
|
|
882
|
+
this.reexecutionTracker.removeBefore(CheckpointNumber(finalizedCheckpointNumber + 1));
|
|
883
|
+
}
|
|
884
|
+
} catch (err) {
|
|
885
|
+
this.log.error(`Error pruning reexecution tracker`, err, proposalInfo);
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// Upload blobs to filestore if validation passed (fire and forget)
|
|
889
|
+
if (result.isValid) {
|
|
890
|
+
this.tryUploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
return result;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Validates a checkpoint proposal by building the full checkpoint and comparing it with the proposal.
|
|
898
|
+
* @returns Validation result with isValid flag and reason if invalid.
|
|
899
|
+
*/
|
|
900
|
+
async validateCheckpointProposal(
|
|
901
|
+
proposal: CheckpointProposalCore,
|
|
902
|
+
proposalInfo: LogData,
|
|
903
|
+
): Promise<CheckpointProposalValidationResult> {
|
|
904
|
+
const slot = proposal.slotNumber;
|
|
905
|
+
|
|
906
|
+
// Block-sync/validation deadline = the single consensus attestation_deadline (target_slot_start + S
|
|
907
|
+
// - 2E): the latest moment the proposer can submit this checkpoint and still have it land on L1 in
|
|
908
|
+
// the target slot. Keeping validation/attestation alive until then lets validators keep attesting
|
|
909
|
+
// right up to the proposer's real publish cutoff.
|
|
910
|
+
const deadline = this.getReexecutionDeadline(slot);
|
|
911
|
+
|
|
912
|
+
// Wait for last block to sync by archive. The deadline is passed to retryUntil as an absolute date so
|
|
913
|
+
// the remaining budget is derived from the date provider; a deadline already in the past times out
|
|
914
|
+
// after a single attempt instead of looping (the immediate-timeout semantics of the deadline overload).
|
|
915
|
+
let lastBlockData;
|
|
916
|
+
try {
|
|
917
|
+
lastBlockData = await retryUntil(
|
|
918
|
+
async () => {
|
|
919
|
+
await this.blockSource.syncImmediate();
|
|
920
|
+
return await this.blockSource.getBlockData({ archive: proposal.archive });
|
|
921
|
+
},
|
|
922
|
+
`waiting for block with archive ${proposal.archive.toString()} for slot ${slot}`,
|
|
923
|
+
{ deadline, dateProvider: this.dateProvider },
|
|
924
|
+
0.5,
|
|
925
|
+
);
|
|
926
|
+
} catch (err) {
|
|
927
|
+
if (err instanceof TimeoutError) {
|
|
928
|
+
this.log.warn(`Timed out waiting for block with archive matching checkpoint proposal`, proposalInfo);
|
|
929
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
930
|
+
}
|
|
931
|
+
this.log.error(`Error fetching last block for checkpoint proposal`, err, proposalInfo);
|
|
932
|
+
return { isValid: false, reason: 'block_fetch_error' };
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
if (!lastBlockData) {
|
|
936
|
+
this.log.warn(`Last block not found for checkpoint proposal`, proposalInfo);
|
|
937
|
+
return { isValid: false, reason: 'last_block_not_found' };
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// Refuse to attest if the block's enclosing checkpoint has already been published to L1.
|
|
941
|
+
const existingCheckpoint = await this.blockSource.getCheckpointData({ number: lastBlockData.checkpointNumber });
|
|
942
|
+
if (existingCheckpoint) {
|
|
943
|
+
this.log.warn(`Refusing to attest to checkpoint proposal whose checkpoint is already on L1`, {
|
|
944
|
+
...proposalInfo,
|
|
945
|
+
checkpointNumber: lastBlockData.checkpointNumber,
|
|
946
|
+
});
|
|
947
|
+
return {
|
|
948
|
+
isValid: false,
|
|
949
|
+
reason: 'checkpoint_already_published',
|
|
950
|
+
checkpointNumber: lastBlockData.checkpointNumber,
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// Get all full blocks for the slot and checkpoint
|
|
955
|
+
const blocks = await this.blockSource.getBlocksForSlot(slot);
|
|
956
|
+
if (blocks.length === 0) {
|
|
957
|
+
this.log.warn(`No blocks found for slot ${slot}`, proposalInfo);
|
|
958
|
+
return { isValid: false, reason: 'no_blocks_for_slot', checkpointNumber: lastBlockData.checkpointNumber };
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// Ensure the last block for this slot matches the archive in the checkpoint proposal
|
|
962
|
+
if (!blocks.at(-1)?.archive.root.equals(proposal.archive)) {
|
|
963
|
+
this.log.warn(`Last block archive mismatch for checkpoint proposal`, proposalInfo);
|
|
964
|
+
return {
|
|
965
|
+
isValid: false,
|
|
966
|
+
reason: 'last_block_archive_mismatch',
|
|
967
|
+
checkpointNumber: lastBlockData.checkpointNumber,
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
const maxBlocksPerCheckpoint = this.config.maxBlocksPerCheckpoint;
|
|
972
|
+
if (maxBlocksPerCheckpoint !== undefined && blocks.length > maxBlocksPerCheckpoint) {
|
|
973
|
+
this.log.warn(`Checkpoint proposal exceeds maxBlocksPerCheckpoint`, {
|
|
974
|
+
...proposalInfo,
|
|
975
|
+
blocksInProposal: blocks.length,
|
|
976
|
+
maxBlocksPerCheckpoint,
|
|
977
|
+
});
|
|
978
|
+
return {
|
|
979
|
+
isValid: false,
|
|
980
|
+
reason: 'too_many_blocks_in_checkpoint',
|
|
981
|
+
checkpointNumber: lastBlockData.checkpointNumber,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
this.log.debug(`Found ${blocks.length} blocks for slot ${slot}`, {
|
|
986
|
+
...proposalInfo,
|
|
987
|
+
blockNumbers: blocks.map(b => b.number),
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
// Get checkpoint constants from first block
|
|
991
|
+
const firstBlock = blocks[0];
|
|
992
|
+
const constants = this.extractCheckpointConstants(firstBlock);
|
|
993
|
+
const checkpointNumber = firstBlock.checkpointNumber;
|
|
994
|
+
|
|
995
|
+
// Get L1-to-L2 messages for this checkpoint
|
|
996
|
+
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(checkpointNumber);
|
|
997
|
+
|
|
998
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch.
|
|
999
|
+
// See note on the analogous block-proposal site: the helper handles pipelining lag.
|
|
1000
|
+
const epoch = getEpochAtSlot(slot, this.epochCache.getL1Constants());
|
|
1001
|
+
const previousCheckpointOutHashes = await getPreviousCheckpointOutHashes({
|
|
1002
|
+
blockSource: this.blockSource,
|
|
1003
|
+
epoch,
|
|
1004
|
+
checkpointNumber,
|
|
1005
|
+
l1Constants: this.epochCache.getL1Constants(),
|
|
1006
|
+
pipeliningEnabled: true,
|
|
1007
|
+
log: this.log,
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
// Fork world state at the block before the first block
|
|
1011
|
+
const parentBlockNumber = BlockNumber(firstBlock.number - 1);
|
|
1012
|
+
await using fork = await this.checkpointsBuilder.getFork(parentBlockNumber);
|
|
1013
|
+
|
|
1014
|
+
// Create checkpoint builder with all existing blocks
|
|
1015
|
+
const checkpointBuilder = await this.checkpointsBuilder.openCheckpoint(
|
|
1016
|
+
checkpointNumber,
|
|
1017
|
+
constants,
|
|
1018
|
+
proposal.feeAssetPriceModifier,
|
|
1019
|
+
l1ToL2Messages,
|
|
1020
|
+
previousCheckpointOutHashes,
|
|
1021
|
+
fork,
|
|
1022
|
+
blocks,
|
|
1023
|
+
this.log.getBindings(),
|
|
1024
|
+
);
|
|
1025
|
+
|
|
1026
|
+
// Complete the checkpoint to get computed values
|
|
1027
|
+
const computedCheckpoint = await checkpointBuilder.completeCheckpoint();
|
|
1028
|
+
|
|
1029
|
+
// Compare checkpoint header with proposal
|
|
1030
|
+
if (!computedCheckpoint.header.equals(proposal.checkpointHeader)) {
|
|
1031
|
+
this.log.warn(`Checkpoint header mismatch`, {
|
|
1032
|
+
...proposalInfo,
|
|
1033
|
+
computed: computedCheckpoint.header.toInspect(),
|
|
1034
|
+
proposal: proposal.checkpointHeader.toInspect(),
|
|
1035
|
+
});
|
|
1036
|
+
return { isValid: false, reason: 'checkpoint_header_mismatch', checkpointNumber };
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// Compare archive root with proposal
|
|
1040
|
+
if (!computedCheckpoint.archive.root.equals(proposal.archive)) {
|
|
1041
|
+
this.log.warn(`Archive root mismatch`, {
|
|
1042
|
+
...proposalInfo,
|
|
1043
|
+
computed: computedCheckpoint.archive.root.toString(),
|
|
1044
|
+
proposal: proposal.archive.toString(),
|
|
1045
|
+
});
|
|
1046
|
+
return { isValid: false, reason: 'archive_mismatch', checkpointNumber };
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Check that the accumulated epoch out hash matches the value in the proposal.
|
|
1050
|
+
// The epoch out hash is the accumulated hash of all checkpoint out hashes in the epoch.
|
|
1051
|
+
const checkpointOutHash = computedCheckpoint.getCheckpointOutHash();
|
|
1052
|
+
const computedEpochOutHash = accumulateCheckpointOutHashes([...previousCheckpointOutHashes, checkpointOutHash]);
|
|
1053
|
+
const proposalEpochOutHash = proposal.checkpointHeader.epochOutHash;
|
|
1054
|
+
if (!computedEpochOutHash.equals(proposalEpochOutHash)) {
|
|
1055
|
+
this.log.warn(`Epoch out hash mismatch`, {
|
|
1056
|
+
proposalEpochOutHash: proposalEpochOutHash.toString(),
|
|
1057
|
+
computedEpochOutHash: computedEpochOutHash.toString(),
|
|
1058
|
+
checkpointOutHash: checkpointOutHash.toString(),
|
|
1059
|
+
previousCheckpointOutHashes: previousCheckpointOutHashes.map(h => h.toString()),
|
|
1060
|
+
...proposalInfo,
|
|
1061
|
+
});
|
|
1062
|
+
return { isValid: false, reason: 'out_hash_mismatch', checkpointNumber };
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// Final round of validations on the checkpoint, just in case.
|
|
1066
|
+
try {
|
|
1067
|
+
validateCheckpoint(computedCheckpoint, {
|
|
1068
|
+
rollupManaLimit: this.checkpointsBuilder.getConfig().rollupManaLimit,
|
|
1069
|
+
maxDABlockGas: this.config.validateMaxDABlockGas,
|
|
1070
|
+
maxL2BlockGas: this.config.validateMaxL2BlockGas,
|
|
1071
|
+
maxTxsPerBlock: this.config.validateMaxTxsPerBlock,
|
|
1072
|
+
maxTxsPerCheckpoint: this.config.validateMaxTxsPerCheckpoint,
|
|
1073
|
+
});
|
|
1074
|
+
} catch (err) {
|
|
1075
|
+
this.log.warn(`Checkpoint validation failed: ${err}`, proposalInfo);
|
|
1076
|
+
return { isValid: false, reason: 'checkpoint_validation_failed', checkpointNumber };
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
this.log.verbose(`Checkpoint proposal validation successful for slot ${slot}`, proposalInfo);
|
|
1080
|
+
|
|
1081
|
+
return { isValid: true, checkpointNumber };
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/** Extracts checkpoint global variables from a block. */
|
|
1085
|
+
private extractCheckpointConstants(block: L2Block): CheckpointGlobalVariables {
|
|
1086
|
+
const gv = block.header.globalVariables;
|
|
1087
|
+
return {
|
|
1088
|
+
chainId: gv.chainId,
|
|
1089
|
+
version: gv.version,
|
|
1090
|
+
slotNumber: gv.slotNumber,
|
|
1091
|
+
timestamp: gv.timestamp,
|
|
1092
|
+
coinbase: gv.coinbase,
|
|
1093
|
+
feeRecipient: gv.feeRecipient,
|
|
1094
|
+
gasFees: gv.gasFees,
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
/** Triggers blob upload for a checkpoint if the blob client can upload (fire and forget). */
|
|
1099
|
+
protected tryUploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): void {
|
|
1100
|
+
if (this.blobClient.canUpload()) {
|
|
1101
|
+
void this.uploadBlobsForCheckpoint(proposal, proposalInfo);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/** Uploads blobs for a checkpoint to the filestore. */
|
|
1106
|
+
protected async uploadBlobsForCheckpoint(proposal: CheckpointProposalCore, proposalInfo: LogData): Promise<void> {
|
|
1107
|
+
try {
|
|
1108
|
+
const lastBlockHeader = (await this.blockSource.getBlockData({ archive: proposal.archive }))?.header;
|
|
1109
|
+
if (!lastBlockHeader) {
|
|
1110
|
+
this.log.warn(`Failed to get last block header for blob upload`, proposalInfo);
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
const blocks = await this.blockSource.getBlocksForSlot(proposal.slotNumber);
|
|
1115
|
+
if (blocks.length === 0) {
|
|
1116
|
+
this.log.warn(`No blocks found for blob upload`, proposalInfo);
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
const blockBlobData = blocks.map(b => b.toBlockBlobData());
|
|
1121
|
+
const blobFields = encodeCheckpointBlobDataFromBlocks(blockBlobData);
|
|
1122
|
+
const blobs: Blob[] = await getBlobsPerL1Block(blobFields);
|
|
1123
|
+
await this.blobClient.sendBlobsToFilestore(blobs);
|
|
1124
|
+
this.log.debug(`Uploaded ${blobs.length} blobs to filestore for checkpoint at slot ${proposal.slotNumber}`, {
|
|
1125
|
+
...proposalInfo,
|
|
1126
|
+
numBlobs: blobs.length,
|
|
1127
|
+
});
|
|
1128
|
+
} catch (err) {
|
|
1129
|
+
this.log.warn(`Failed to upload blobs for checkpoint: ${err}`, proposalInfo);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* Derives proposed checkpoint data from validated blocks and sets it on the archiver, so this node can
|
|
1135
|
+
* pipeline building on top of the checkpoint. Does not retry, since validation already waited for the
|
|
1136
|
+
* last block to sync.
|
|
1137
|
+
*/
|
|
1138
|
+
private async setProposedCheckpoint(proposal: CheckpointProposalCore): Promise<boolean> {
|
|
1139
|
+
if (!this.archiver) {
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
const blockData = await this.blockSource.getBlockData({ archive: proposal.archive });
|
|
1143
|
+
if (!blockData) {
|
|
1144
|
+
this.log.debug(`Block data not found for checkpoint proposal archive, cannot set proposed checkpoint`, {
|
|
1145
|
+
archive: proposal.archive.toString(),
|
|
1146
|
+
});
|
|
1147
|
+
return false;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
await this.archiver.addProposedCheckpoint({
|
|
1151
|
+
header: proposal.checkpointHeader,
|
|
1152
|
+
checkpointNumber: blockData.checkpointNumber,
|
|
1153
|
+
startBlock: BlockNumber(blockData.header.getBlockNumber() - blockData.indexWithinCheckpoint),
|
|
1154
|
+
blockCount: blockData.indexWithinCheckpoint + 1,
|
|
1155
|
+
totalManaUsed: proposal.checkpointHeader.totalManaUsed.toBigInt(),
|
|
1156
|
+
feeAssetPriceModifier: proposal.feeAssetPriceModifier,
|
|
1157
|
+
});
|
|
1158
|
+
return true;
|
|
1159
|
+
}
|
|
1160
|
+
}
|