@aztec/sequencer-client 0.0.1-commit.d431d1c → 0.0.1-commit.db765a8
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/dest/client/sequencer-client.d.ts +12 -7
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +15 -4
- package/dest/config.d.ts +3 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +29 -21
- package/dest/global_variable_builder/global_builder.d.ts +2 -4
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +2 -2
- package/dest/publisher/config.d.ts +35 -17
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +106 -42
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +59 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -3
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +27 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts +1 -1
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +12 -4
- package/dest/publisher/sequencer-publisher.d.ts +26 -8
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +338 -48
- package/dest/sequencer/checkpoint_proposal_job.d.ts +32 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +153 -74
- package/dest/sequencer/metrics.d.ts +17 -5
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +111 -30
- package/dest/sequencer/sequencer.d.ts +20 -8
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +31 -28
- package/dest/sequencer/timetable.d.ts +1 -4
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +2 -5
- package/dest/test/index.d.ts +3 -5
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +14 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +24 -10
- package/dest/test/utils.d.ts +8 -8
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +10 -9
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +25 -7
- package/src/config.ts +41 -30
- package/src/global_variable_builder/global_builder.ts +3 -3
- package/src/publisher/config.ts +121 -43
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +55 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-publisher-factory.ts +38 -6
- package/src/publisher/sequencer-publisher-metrics.ts +7 -3
- package/src/publisher/sequencer-publisher.ts +333 -60
- package/src/sequencer/checkpoint_proposal_job.ts +216 -96
- package/src/sequencer/metrics.ts +124 -32
- package/src/sequencer/sequencer.ts +41 -33
- package/src/sequencer/timetable.ts +7 -6
- package/src/test/index.ts +2 -4
- package/src/test/mock_checkpoint_builder.ts +44 -19
- package/src/test/utils.ts +22 -13
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
2
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
BlockNumber,
|
|
6
|
+
CheckpointNumber,
|
|
7
|
+
EpochNumber,
|
|
8
|
+
IndexWithinCheckpoint,
|
|
9
|
+
SlotNumber,
|
|
10
|
+
} from '@aztec/foundation/branded-types';
|
|
5
11
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
12
|
+
import {
|
|
13
|
+
flipSignature,
|
|
14
|
+
generateRecoverableSignature,
|
|
15
|
+
generateUnrecoverableSignature,
|
|
16
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
6
17
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
7
18
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
19
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
9
20
|
import { filter } from '@aztec/foundation/iterator';
|
|
10
|
-
import type
|
|
21
|
+
import { type Logger, type LoggerBindings, createLogger } from '@aztec/foundation/log';
|
|
11
22
|
import { sleep, sleepUntil } from '@aztec/foundation/sleep';
|
|
12
23
|
import { type DateProvider, Timer } from '@aztec/foundation/timer';
|
|
13
|
-
import { type TypedEventEmitter, unfreeze } from '@aztec/foundation/types';
|
|
24
|
+
import { type TypedEventEmitter, isErrorClass, unfreeze } from '@aztec/foundation/types';
|
|
14
25
|
import type { P2P } from '@aztec/p2p';
|
|
15
26
|
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
16
27
|
import {
|
|
17
28
|
CommitteeAttestation,
|
|
18
29
|
CommitteeAttestationsAndSigners,
|
|
19
|
-
|
|
30
|
+
L2Block,
|
|
20
31
|
type L2BlockSink,
|
|
21
32
|
type L2BlockSource,
|
|
22
33
|
MaliciousCommitteeAttestationsAndSigners,
|
|
@@ -24,14 +35,15 @@ import {
|
|
|
24
35
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
25
36
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
26
37
|
import { Gas } from '@aztec/stdlib/gas';
|
|
27
|
-
import
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
import {
|
|
39
|
+
NoValidTxsError,
|
|
40
|
+
type PublicProcessorLimits,
|
|
41
|
+
type ResolvedSequencerConfig,
|
|
42
|
+
type WorldStateSynchronizer,
|
|
31
43
|
} from '@aztec/stdlib/interfaces/server';
|
|
32
44
|
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
33
45
|
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
34
|
-
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
46
|
+
import { orderAttestations, trimAttestations } from '@aztec/stdlib/p2p';
|
|
35
47
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
36
48
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
37
49
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
@@ -59,6 +71,8 @@ const TXS_POLLING_MS = 500;
|
|
|
59
71
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
60
72
|
*/
|
|
61
73
|
export class CheckpointProposalJob implements Traceable {
|
|
74
|
+
protected readonly log: Logger;
|
|
75
|
+
|
|
62
76
|
constructor(
|
|
63
77
|
private readonly epoch: EpochNumber,
|
|
64
78
|
private readonly slot: SlotNumber,
|
|
@@ -86,9 +100,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
86
100
|
private readonly metrics: SequencerMetrics,
|
|
87
101
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
88
102
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
89
|
-
protected readonly log: Logger,
|
|
90
103
|
public readonly tracer: Tracer,
|
|
91
|
-
|
|
104
|
+
bindings?: LoggerBindings,
|
|
105
|
+
) {
|
|
106
|
+
this.log = createLogger('sequencer:checkpoint-proposal', { ...bindings, instanceId: `slot-${slot}` });
|
|
107
|
+
}
|
|
92
108
|
|
|
93
109
|
/**
|
|
94
110
|
* Executes the checkpoint proposal job.
|
|
@@ -118,7 +134,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
118
134
|
await Promise.all(votesPromises);
|
|
119
135
|
|
|
120
136
|
if (checkpoint) {
|
|
121
|
-
this.metrics.
|
|
137
|
+
this.metrics.recordCheckpointProposalSuccess();
|
|
122
138
|
}
|
|
123
139
|
|
|
124
140
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
@@ -175,21 +191,25 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
175
191
|
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
176
192
|
|
|
177
193
|
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
178
|
-
const
|
|
179
|
-
c => c.
|
|
180
|
-
|
|
181
|
-
|
|
194
|
+
const previousCheckpointOutHashes = (await this.l2BlockSource.getCheckpointsDataForEpoch(this.epoch))
|
|
195
|
+
.filter(c => c.checkpointNumber < this.checkpointNumber)
|
|
196
|
+
.map(c => c.checkpointOutHash);
|
|
197
|
+
|
|
198
|
+
// Get the fee asset price modifier from the oracle
|
|
199
|
+
const feeAssetPriceModifier = await this.publisher.getFeeAssetPriceModifier();
|
|
182
200
|
|
|
183
201
|
// Create a long-lived forked world state for the checkpoint builder
|
|
184
|
-
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
202
|
+
await using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
185
203
|
|
|
186
204
|
// Create checkpoint builder for the entire slot
|
|
187
205
|
const checkpointBuilder = await this.checkpointsBuilder.startCheckpoint(
|
|
188
206
|
this.checkpointNumber,
|
|
189
207
|
checkpointGlobalVariables,
|
|
208
|
+
feeAssetPriceModifier,
|
|
190
209
|
l1ToL2Messages,
|
|
191
210
|
previousCheckpointOutHashes,
|
|
192
211
|
fork,
|
|
212
|
+
this.log.getBindings(),
|
|
193
213
|
);
|
|
194
214
|
|
|
195
215
|
// Options for the validator client when creating block and checkpoint proposals
|
|
@@ -203,8 +223,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
203
223
|
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
204
224
|
};
|
|
205
225
|
|
|
206
|
-
let blocksInCheckpoint:
|
|
207
|
-
let blockPendingBroadcast: { block:
|
|
226
|
+
let blocksInCheckpoint: L2Block[] = [];
|
|
227
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
228
|
+
const checkpointBuildTimer = new Timer();
|
|
208
229
|
|
|
209
230
|
try {
|
|
210
231
|
// Main loop: build blocks for the checkpoint
|
|
@@ -220,19 +241,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
220
241
|
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
221
242
|
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
222
243
|
// which is normal for block building (may have picked different txs)
|
|
223
|
-
if (err
|
|
224
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
225
|
-
slot: this.slot,
|
|
226
|
-
signedByNode: err.signedByNode,
|
|
227
|
-
});
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
if (err instanceof SlashingProtectionError) {
|
|
231
|
-
this.log.info(`Checkpoint proposal for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
232
|
-
slot: this.slot,
|
|
233
|
-
existingMessageHash: err.existingMessageHash,
|
|
234
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
235
|
-
});
|
|
244
|
+
if (this.handleHASigningError(err, 'Block proposal')) {
|
|
236
245
|
return undefined;
|
|
237
246
|
}
|
|
238
247
|
throw err;
|
|
@@ -244,11 +253,28 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
244
253
|
return undefined;
|
|
245
254
|
}
|
|
246
255
|
|
|
256
|
+
const minBlocksForCheckpoint = this.config.minBlocksForCheckpoint;
|
|
257
|
+
if (minBlocksForCheckpoint !== undefined && blocksInCheckpoint.length < minBlocksForCheckpoint) {
|
|
258
|
+
this.log.warn(
|
|
259
|
+
`Checkpoint has fewer blocks than minimum (${blocksInCheckpoint.length} < ${minBlocksForCheckpoint}), skipping proposal`,
|
|
260
|
+
{ slot: this.slot, blocksBuilt: blocksInCheckpoint.length, minBlocksForCheckpoint },
|
|
261
|
+
);
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
|
|
247
265
|
// Assemble and broadcast the checkpoint proposal, including the last block that was not
|
|
248
266
|
// broadcasted yet, and wait to collect the committee attestations.
|
|
249
267
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
250
268
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
251
269
|
|
|
270
|
+
// Record checkpoint-level build metrics
|
|
271
|
+
this.metrics.recordCheckpointBuild(
|
|
272
|
+
checkpointBuildTimer.ms(),
|
|
273
|
+
blocksInCheckpoint.length,
|
|
274
|
+
checkpoint.getStats().txCount,
|
|
275
|
+
Number(checkpoint.header.totalManaUsed.toBigInt()),
|
|
276
|
+
);
|
|
277
|
+
|
|
252
278
|
// Do not collect attestations nor publish to L1 in fisherman mode
|
|
253
279
|
if (this.config.fishermanMode) {
|
|
254
280
|
this.log.info(
|
|
@@ -275,6 +301,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
275
301
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
276
302
|
checkpoint.header,
|
|
277
303
|
checkpoint.archive.root,
|
|
304
|
+
feeAssetPriceModifier,
|
|
278
305
|
lastBlock,
|
|
279
306
|
this.proposer,
|
|
280
307
|
checkpointProposalOptions,
|
|
@@ -301,20 +328,8 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
301
328
|
);
|
|
302
329
|
} catch (err) {
|
|
303
330
|
// We shouldn't really get here since we yield to another HA node
|
|
304
|
-
// as soon as we see these errors when creating block proposals.
|
|
305
|
-
if (err
|
|
306
|
-
this.log.info(`Attestations signature for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
307
|
-
slot: this.slot,
|
|
308
|
-
signedByNode: err.signedByNode,
|
|
309
|
-
});
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
if (err instanceof SlashingProtectionError) {
|
|
313
|
-
this.log.info(`Attestations signature for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
314
|
-
slot: this.slot,
|
|
315
|
-
existingMessageHash: err.existingMessageHash,
|
|
316
|
-
attemptedMessageHash: err.attemptedMessageHash,
|
|
317
|
-
});
|
|
331
|
+
// as soon as we see these errors when creating block or checkpoint proposals.
|
|
332
|
+
if (this.handleHASigningError(err, 'Attestations signature')) {
|
|
318
333
|
return undefined;
|
|
319
334
|
}
|
|
320
335
|
throw err;
|
|
@@ -325,6 +340,21 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
325
340
|
const aztecSlotDuration = this.l1Constants.slotDuration;
|
|
326
341
|
const slotStartBuildTimestamp = this.getSlotStartBuildTimestamp();
|
|
327
342
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
343
|
+
|
|
344
|
+
// If we have been configured to potentially skip publishing checkpoint then roll the dice here
|
|
345
|
+
if (
|
|
346
|
+
this.config.skipPublishingCheckpointsPercent !== undefined &&
|
|
347
|
+
this.config.skipPublishingCheckpointsPercent > 0
|
|
348
|
+
) {
|
|
349
|
+
const result = Math.max(0, randomInt(100));
|
|
350
|
+
if (result < this.config.skipPublishingCheckpointsPercent) {
|
|
351
|
+
this.log.warn(
|
|
352
|
+
`Skipping publishing proposal for checkpoint ${checkpoint.number}. Configured percentage: ${this.config.skipPublishingCheckpointsPercent}, generated value: ${result}`,
|
|
353
|
+
);
|
|
354
|
+
return checkpoint;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
328
358
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
329
359
|
txTimeoutAt,
|
|
330
360
|
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
@@ -352,10 +382,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
352
382
|
inHash: Fr,
|
|
353
383
|
blockProposalOptions: BlockProposalOptions,
|
|
354
384
|
): Promise<{
|
|
355
|
-
blocksInCheckpoint:
|
|
356
|
-
blockPendingBroadcast: { block:
|
|
385
|
+
blocksInCheckpoint: L2Block[];
|
|
386
|
+
blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
|
|
357
387
|
}> {
|
|
358
|
-
const blocksInCheckpoint:
|
|
388
|
+
const blocksInCheckpoint: L2Block[] = [];
|
|
359
389
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
360
390
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
361
391
|
|
|
@@ -363,11 +393,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
363
393
|
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
364
394
|
|
|
365
395
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
366
|
-
let blockPendingBroadcast: { block:
|
|
396
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
367
397
|
|
|
368
398
|
while (true) {
|
|
369
399
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
370
|
-
const indexWithinCheckpoint = blocksBuilt;
|
|
400
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(blocksBuilt);
|
|
371
401
|
const blockNumber = BlockNumber(initialBlockNumber + blocksBuilt);
|
|
372
402
|
|
|
373
403
|
const secondsIntoSlot = this.getSecondsIntoSlot();
|
|
@@ -397,6 +427,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
397
427
|
remainingBlobFields,
|
|
398
428
|
});
|
|
399
429
|
|
|
430
|
+
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
400
431
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
401
432
|
// If no block was produced due to not enough txs and this was the last subslot, exit
|
|
402
433
|
break;
|
|
@@ -428,7 +459,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
428
459
|
// Sync the proposed block to the archiver to make it available
|
|
429
460
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
430
461
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
431
|
-
|
|
462
|
+
// Fire and forget - don't block the critical path, but log errors
|
|
463
|
+
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
464
|
+
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
432
468
|
|
|
433
469
|
// If this is the last block, exit the loop now so we start collecting attestations
|
|
434
470
|
if (timingInfo.isLastBlock) {
|
|
@@ -478,18 +514,18 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
478
514
|
|
|
479
515
|
/** Builds a single block. Called from the main block building loop. */
|
|
480
516
|
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
481
|
-
|
|
517
|
+
protected async buildSingleBlock(
|
|
482
518
|
checkpointBuilder: CheckpointBuilder,
|
|
483
519
|
opts: {
|
|
484
520
|
forceCreate?: boolean;
|
|
485
521
|
blockTimestamp: bigint;
|
|
486
522
|
blockNumber: BlockNumber;
|
|
487
|
-
indexWithinCheckpoint:
|
|
523
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
488
524
|
buildDeadline: Date | undefined;
|
|
489
525
|
txHashesAlreadyIncluded: Set<string>;
|
|
490
526
|
remainingBlobFields: number;
|
|
491
527
|
},
|
|
492
|
-
): Promise<{ block:
|
|
528
|
+
): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
493
529
|
const {
|
|
494
530
|
blockTimestamp,
|
|
495
531
|
forceCreate,
|
|
@@ -522,7 +558,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
522
558
|
// Create iterator to pending txs. We filter out txs already included in previous blocks in the checkpoint
|
|
523
559
|
// just in case p2p failed to sync the provisional block and didn't get to remove those txs from the mempool yet.
|
|
524
560
|
const pendingTxs = filter(
|
|
525
|
-
this.p2pClient.
|
|
561
|
+
this.p2pClient.iterateEligiblePendingTxs(),
|
|
526
562
|
tx => !txHashesAlreadyIncluded.has(tx.txHash.toString()),
|
|
527
563
|
);
|
|
528
564
|
|
|
@@ -545,45 +581,38 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
545
581
|
};
|
|
546
582
|
|
|
547
583
|
// Actually build the block by executing txs
|
|
548
|
-
const
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
usedTxs,
|
|
556
|
-
failedTxs,
|
|
557
|
-
usedTxBlobFields,
|
|
558
|
-
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
559
|
-
const blockBuildDuration = workTimer.ms();
|
|
584
|
+
const buildResult = await this.buildSingleBlockWithCheckpointBuilder(
|
|
585
|
+
checkpointBuilder,
|
|
586
|
+
pendingTxs,
|
|
587
|
+
blockNumber,
|
|
588
|
+
blockTimestamp,
|
|
589
|
+
blockBuilderOptions,
|
|
590
|
+
);
|
|
560
591
|
|
|
561
592
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
562
|
-
await this.dropFailedTxsFromP2P(failedTxs);
|
|
593
|
+
await this.dropFailedTxsFromP2P(buildResult.failedTxs);
|
|
563
594
|
|
|
564
595
|
// Check if we have created a block with enough txs. If there were invalid txs in the pool, or if execution took
|
|
565
596
|
// too long, then we may not get to minTxsPerBlock after executing public functions.
|
|
566
597
|
const minValidTxs = this.config.minValidTxsPerBlock ?? minTxs;
|
|
567
|
-
|
|
598
|
+
const numTxs = buildResult.status === 'no-valid-txs' ? 0 : buildResult.numTxs;
|
|
599
|
+
if (buildResult.status === 'no-valid-txs' || (!forceCreate && numTxs < minValidTxs)) {
|
|
568
600
|
this.log.warn(
|
|
569
|
-
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed
|
|
570
|
-
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint },
|
|
601
|
+
`Block ${blockNumber} at index ${indexWithinCheckpoint} on slot ${this.slot} has too few valid txs to be proposed`,
|
|
602
|
+
{ slot: this.slot, blockNumber, numTxs, indexWithinCheckpoint, minValidTxs, buildResult: buildResult.status },
|
|
571
603
|
);
|
|
572
|
-
this.eventEmitter.emit('block-
|
|
573
|
-
minTxs: minValidTxs,
|
|
574
|
-
availableTxs: numTxs,
|
|
575
|
-
slot: this.slot,
|
|
576
|
-
});
|
|
604
|
+
this.eventEmitter.emit('block-build-failed', { reason: `Insufficient valid txs`, slot: this.slot });
|
|
577
605
|
this.metrics.recordBlockProposalFailed('insufficient_valid_txs');
|
|
578
606
|
return undefined;
|
|
579
607
|
}
|
|
580
608
|
|
|
581
609
|
// Block creation succeeded, emit stats and metrics
|
|
610
|
+
const { publicGas, block, publicProcessorDuration, usedTxs, usedTxBlobFields, blockBuildDuration } = buildResult;
|
|
611
|
+
|
|
582
612
|
const blockStats = {
|
|
583
613
|
eventName: 'l2-block-built',
|
|
584
614
|
duration: blockBuildDuration,
|
|
585
615
|
publicProcessDuration: publicProcessorDuration,
|
|
586
|
-
rollupCircuitsDuration: blockBuildingTimer.ms(),
|
|
587
616
|
...block.getStats(),
|
|
588
617
|
} satisfies L2BlockBuiltStats;
|
|
589
618
|
|
|
@@ -609,17 +638,40 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
609
638
|
}
|
|
610
639
|
}
|
|
611
640
|
|
|
641
|
+
/** Uses the checkpoint builder to build a block, catching specific txs */
|
|
642
|
+
private async buildSingleBlockWithCheckpointBuilder(
|
|
643
|
+
checkpointBuilder: CheckpointBuilder,
|
|
644
|
+
pendingTxs: AsyncIterable<Tx>,
|
|
645
|
+
blockNumber: BlockNumber,
|
|
646
|
+
blockTimestamp: bigint,
|
|
647
|
+
blockBuilderOptions: PublicProcessorLimits,
|
|
648
|
+
) {
|
|
649
|
+
try {
|
|
650
|
+
const workTimer = new Timer();
|
|
651
|
+
const result = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
652
|
+
const blockBuildDuration = workTimer.ms();
|
|
653
|
+
return { ...result, blockBuildDuration, status: 'success' as const };
|
|
654
|
+
} catch (err: unknown) {
|
|
655
|
+
if (isErrorClass(err, NoValidTxsError)) {
|
|
656
|
+
return { failedTxs: err.failedTxs, status: 'no-valid-txs' as const };
|
|
657
|
+
}
|
|
658
|
+
throw err;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
612
662
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
613
663
|
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
614
664
|
private async waitForMinTxs(opts: {
|
|
615
665
|
forceCreate?: boolean;
|
|
616
666
|
blockNumber: BlockNumber;
|
|
617
|
-
indexWithinCheckpoint:
|
|
667
|
+
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
618
668
|
buildDeadline: Date | undefined;
|
|
619
669
|
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
620
|
-
const minTxs = this.config.minTxsPerBlock;
|
|
621
670
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
622
671
|
|
|
672
|
+
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
673
|
+
const minTxs = indexWithinCheckpoint > 0 && this.config.minTxsPerBlock === 0 ? 1 : this.config.minTxsPerBlock;
|
|
674
|
+
|
|
623
675
|
// Deadline is undefined if we are not enforcing the timetable, meaning we'll exit immediately when out of time
|
|
624
676
|
const startBuildingDeadline = buildDeadline
|
|
625
677
|
? new Date(buildDeadline.getTime() - this.timetable.minExecutionTime * 1000)
|
|
@@ -640,7 +692,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
640
692
|
`Waiting for enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (have ${availableTxs} but need ${minTxs})`,
|
|
641
693
|
{ blockNumber, slot: this.slot, indexWithinCheckpoint },
|
|
642
694
|
);
|
|
643
|
-
await
|
|
695
|
+
await this.waitForTxsPollingInterval();
|
|
644
696
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
645
697
|
}
|
|
646
698
|
|
|
@@ -681,7 +733,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
681
733
|
const attestationTimeAllowed = this.config.enforceTimeTable
|
|
682
734
|
? this.timetable.getMaxAllowedTime(SequencerState.PUBLISHING_CHECKPOINT)!
|
|
683
735
|
: this.l1Constants.slotDuration;
|
|
684
|
-
const attestationDeadline = new Date(this.
|
|
736
|
+
const attestationDeadline = new Date((this.getSlotStartBuildTimestamp() + attestationTimeAllowed) * 1000);
|
|
685
737
|
|
|
686
738
|
this.metrics.recordRequiredAttestations(numberOfRequiredAttestations, attestationTimeAllowed);
|
|
687
739
|
|
|
@@ -696,11 +748,28 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
696
748
|
|
|
697
749
|
collectedAttestationsCount = attestations.length;
|
|
698
750
|
|
|
751
|
+
// Trim attestations to minimum required to save L1 calldata gas
|
|
752
|
+
const localAddresses = this.validatorClient.getValidatorAddresses();
|
|
753
|
+
const trimmed = trimAttestations(
|
|
754
|
+
attestations,
|
|
755
|
+
numberOfRequiredAttestations,
|
|
756
|
+
this.attestorAddress,
|
|
757
|
+
localAddresses,
|
|
758
|
+
);
|
|
759
|
+
if (trimmed.length < attestations.length) {
|
|
760
|
+
this.log.debug(`Trimmed attestations from ${attestations.length} to ${trimmed.length} for L1 submission`);
|
|
761
|
+
}
|
|
762
|
+
|
|
699
763
|
// Rollup contract requires that the signatures are provided in the order of the committee
|
|
700
|
-
const sorted = orderAttestations(
|
|
764
|
+
const sorted = orderAttestations(trimmed, committee);
|
|
701
765
|
|
|
702
766
|
// Manipulate the attestations if we've been configured to do so
|
|
703
|
-
if (
|
|
767
|
+
if (
|
|
768
|
+
this.config.injectFakeAttestation ||
|
|
769
|
+
this.config.injectHighSValueAttestation ||
|
|
770
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
771
|
+
this.config.shuffleAttestationOrdering
|
|
772
|
+
) {
|
|
704
773
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
705
774
|
}
|
|
706
775
|
|
|
@@ -729,7 +798,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
729
798
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
730
799
|
);
|
|
731
800
|
|
|
732
|
-
if (
|
|
801
|
+
if (
|
|
802
|
+
this.config.injectFakeAttestation ||
|
|
803
|
+
this.config.injectHighSValueAttestation ||
|
|
804
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
805
|
+
) {
|
|
733
806
|
// Find non-empty attestations that are not from the proposer
|
|
734
807
|
const nonProposerIndices: number[] = [];
|
|
735
808
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -739,8 +812,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
739
812
|
}
|
|
740
813
|
if (nonProposerIndices.length > 0) {
|
|
741
814
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
742
|
-
this.
|
|
743
|
-
|
|
815
|
+
if (this.config.injectHighSValueAttestation) {
|
|
816
|
+
this.log.warn(
|
|
817
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
818
|
+
);
|
|
819
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
820
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
821
|
+
this.log.warn(
|
|
822
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
823
|
+
);
|
|
824
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
825
|
+
} else {
|
|
826
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
827
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
828
|
+
}
|
|
744
829
|
}
|
|
745
830
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
746
831
|
}
|
|
@@ -749,11 +834,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
749
834
|
this.log.warn(`Shuffling attestation ordering in checkpoint for slot ${slotNumber} (proposer #${proposerIndex})`);
|
|
750
835
|
|
|
751
836
|
const shuffled = [...attestations];
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
837
|
+
|
|
838
|
+
// Find two non-proposer positions that both have non-empty signatures to swap.
|
|
839
|
+
// This ensures the bitmap doesn't change, so the MaliciousCommitteeAttestationsAndSigners
|
|
840
|
+
// signers array stays correctly aligned with L1's committee reconstruction.
|
|
841
|
+
const swappable: number[] = [];
|
|
842
|
+
for (let k = 0; k < shuffled.length; k++) {
|
|
843
|
+
if (!shuffled[k].signature.isEmpty() && k !== proposerIndex) {
|
|
844
|
+
swappable.push(k);
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (swappable.length >= 2) {
|
|
848
|
+
const [i, j] = [swappable[0], swappable[1]];
|
|
849
|
+
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
850
|
+
}
|
|
757
851
|
|
|
758
852
|
const signers = new CommitteeAttestationsAndSigners(attestations).getSigners();
|
|
759
853
|
return new MaliciousCommitteeAttestationsAndSigners(shuffled, signers);
|
|
@@ -769,7 +863,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
769
863
|
const failedTxData = failedTxs.map(fail => fail.tx);
|
|
770
864
|
const failedTxHashes = failedTxData.map(tx => tx.getTxHash());
|
|
771
865
|
this.log.verbose(`Dropping failed txs ${failedTxHashes.join(', ')}`);
|
|
772
|
-
await this.p2pClient.
|
|
866
|
+
await this.p2pClient.handleFailedExecution(failedTxHashes);
|
|
773
867
|
}
|
|
774
868
|
|
|
775
869
|
/**
|
|
@@ -777,8 +871,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
777
871
|
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
778
872
|
* would never receive its own block without this explicit sync.
|
|
779
873
|
*/
|
|
780
|
-
private async syncProposedBlockToArchiver(block:
|
|
781
|
-
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
874
|
+
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
782
875
|
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
783
876
|
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
784
877
|
blockNumber: block.number,
|
|
@@ -812,12 +905,34 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
812
905
|
slot: this.slot,
|
|
813
906
|
feeAnalysisId: feeAnalysis?.id,
|
|
814
907
|
});
|
|
815
|
-
this.metrics.
|
|
908
|
+
this.metrics.recordCheckpointProposalFailed('block_build_failed');
|
|
816
909
|
}
|
|
817
910
|
|
|
818
911
|
this.publisher.clearPendingRequests();
|
|
819
912
|
}
|
|
820
913
|
|
|
914
|
+
/**
|
|
915
|
+
* Helper to handle HA double-signing errors. Returns true if the error was handled (caller should yield).
|
|
916
|
+
*/
|
|
917
|
+
private handleHASigningError(err: any, errorContext: string): boolean {
|
|
918
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
919
|
+
this.log.info(`${errorContext} for slot ${this.slot} already signed by another HA node, yielding`, {
|
|
920
|
+
slot: this.slot,
|
|
921
|
+
signedByNode: err.signedByNode,
|
|
922
|
+
});
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
if (err instanceof SlashingProtectionError) {
|
|
926
|
+
this.log.info(`${errorContext} for slot ${this.slot} blocked by slashing protection, yielding`, {
|
|
927
|
+
slot: this.slot,
|
|
928
|
+
existingMessageHash: err.existingMessageHash,
|
|
929
|
+
attemptedMessageHash: err.attemptedMessageHash,
|
|
930
|
+
});
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
|
|
821
936
|
/** Waits until a specific time within the current slot */
|
|
822
937
|
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
823
938
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
@@ -826,6 +941,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
826
941
|
await sleepUntil(new Date(targetTimestamp * 1000), this.dateProvider.nowAsDate());
|
|
827
942
|
}
|
|
828
943
|
|
|
944
|
+
/** Waits the polling interval for transactions. Extracted for test overriding. */
|
|
945
|
+
protected async waitForTxsPollingInterval(): Promise<void> {
|
|
946
|
+
await sleep(TXS_POLLING_MS);
|
|
947
|
+
}
|
|
948
|
+
|
|
829
949
|
private getSlotStartBuildTimestamp(): number {
|
|
830
950
|
return getSlotStartBuildTimestamp(this.slot, this.l1Constants);
|
|
831
951
|
}
|