@aztec/sequencer-client 0.0.1-commit.c7c42ec → 0.0.1-commit.f295ac2
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 +4 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/config.d.ts +1 -1
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -1
- package/dest/global_variable_builder/global_builder.d.ts +4 -4
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +12 -12
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -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 +15 -86
- package/dest/publisher/sequencer-publisher.d.ts +17 -16
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +442 -49
- package/dest/sequencer/checkpoint_proposal_job.d.ts +14 -9
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +551 -38
- package/dest/sequencer/checkpoint_voter.d.ts +3 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +34 -10
- package/dest/sequencer/index.d.ts +1 -3
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +0 -2
- package/dest/sequencer/metrics.d.ts +3 -3
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +30 -121
- package/dest/sequencer/sequencer.d.ts +24 -14
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +485 -41
- package/dest/test/index.d.ts +2 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +16 -7
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +32 -3
- package/dest/test/utils.d.ts +8 -4
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +23 -14
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +3 -4
- package/src/config.ts +7 -0
- package/src/global_variable_builder/global_builder.ts +12 -12
- package/src/index.ts +1 -9
- package/src/publisher/sequencer-publisher-metrics.ts +14 -70
- package/src/publisher/sequencer-publisher.ts +84 -73
- package/src/sequencer/checkpoint_proposal_job.ts +183 -53
- package/src/sequencer/checkpoint_voter.ts +32 -7
- package/src/sequencer/index.ts +0 -2
- package/src/sequencer/metrics.ts +23 -131
- package/src/sequencer/sequencer.ts +122 -39
- package/src/test/index.ts +1 -2
- package/src/test/mock_checkpoint_builder.ts +62 -14
- package/src/test/utils.ts +42 -21
- package/dest/sequencer/block_builder.d.ts +0 -26
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -129
- package/dest/sequencer/checkpoint_builder.d.ts +0 -63
- package/dest/sequencer/checkpoint_builder.d.ts.map +0 -1
- package/dest/sequencer/checkpoint_builder.js +0 -131
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -217
- package/src/sequencer/checkpoint_builder.ts +0 -217
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -133
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
1
2
|
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
2
3
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
3
4
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
6
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
7
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
6
8
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
7
9
|
import { filter } from '@aztec/foundation/iterator';
|
|
@@ -15,6 +17,8 @@ import {
|
|
|
15
17
|
CommitteeAttestation,
|
|
16
18
|
CommitteeAttestationsAndSigners,
|
|
17
19
|
L2BlockNew,
|
|
20
|
+
type L2BlockSink,
|
|
21
|
+
type L2BlockSource,
|
|
18
22
|
MaliciousCommitteeAttestationsAndSigners,
|
|
19
23
|
} from '@aztec/stdlib/block';
|
|
20
24
|
import type { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -25,18 +29,18 @@ import type {
|
|
|
25
29
|
ResolvedSequencerConfig,
|
|
26
30
|
WorldStateSynchronizer,
|
|
27
31
|
} from '@aztec/stdlib/interfaces/server';
|
|
28
|
-
import type
|
|
29
|
-
import type {
|
|
32
|
+
import { type L1ToL2MessageSource, computeInHashFromL1ToL2Messages } from '@aztec/stdlib/messaging';
|
|
33
|
+
import type { BlockProposalOptions, CheckpointProposal, CheckpointProposalOptions } from '@aztec/stdlib/p2p';
|
|
30
34
|
import { orderAttestations } from '@aztec/stdlib/p2p';
|
|
31
|
-
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
32
35
|
import type { L2BlockBuiltStats } from '@aztec/stdlib/stats';
|
|
33
36
|
import { type FailedTx, Tx } from '@aztec/stdlib/tx';
|
|
34
37
|
import { AttestationTimeoutError } from '@aztec/stdlib/validators';
|
|
35
|
-
import type
|
|
38
|
+
import { Attributes, type Traceable, type Tracer, trackSpan } from '@aztec/telemetry-client';
|
|
39
|
+
import { CheckpointBuilder, type FullNodeCheckpointsBuilder, type ValidatorClient } from '@aztec/validator-client';
|
|
40
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
36
41
|
|
|
37
42
|
import type { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
38
|
-
import type {
|
|
39
|
-
import { CheckpointBuilder, type FullNodeCheckpointsBuilder } from './checkpoint_builder.js';
|
|
43
|
+
import type { InvalidateCheckpointRequest, SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
40
44
|
import { CheckpointVoter } from './checkpoint_voter.js';
|
|
41
45
|
import { SequencerInterruptedError } from './errors.js';
|
|
42
46
|
import type { SequencerEvents } from './events.js';
|
|
@@ -54,8 +58,9 @@ const TXS_POLLING_MS = 500;
|
|
|
54
58
|
* as well as enqueueing votes for slashing and governance proposals. This class is created from
|
|
55
59
|
* the Sequencer once the check for being the proposer for the slot has succeeded.
|
|
56
60
|
*/
|
|
57
|
-
export class CheckpointProposalJob {
|
|
61
|
+
export class CheckpointProposalJob implements Traceable {
|
|
58
62
|
constructor(
|
|
63
|
+
private readonly epoch: EpochNumber,
|
|
59
64
|
private readonly slot: SlotNumber,
|
|
60
65
|
private readonly checkpointNumber: CheckpointNumber,
|
|
61
66
|
private readonly syncedToBlockNumber: BlockNumber,
|
|
@@ -63,13 +68,15 @@ export class CheckpointProposalJob {
|
|
|
63
68
|
private readonly proposer: EthAddress | undefined,
|
|
64
69
|
private readonly publisher: SequencerPublisher,
|
|
65
70
|
private readonly attestorAddress: EthAddress,
|
|
66
|
-
private readonly
|
|
71
|
+
private readonly invalidateCheckpoint: InvalidateCheckpointRequest | undefined,
|
|
67
72
|
private readonly validatorClient: ValidatorClient,
|
|
68
73
|
private readonly globalsBuilder: GlobalVariableBuilder,
|
|
69
74
|
private readonly p2pClient: P2P,
|
|
70
75
|
private readonly worldState: WorldStateSynchronizer,
|
|
71
76
|
private readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
77
|
+
private readonly l2BlockSource: L2BlockSource,
|
|
72
78
|
private readonly checkpointsBuilder: FullNodeCheckpointsBuilder,
|
|
79
|
+
private readonly blockSink: L2BlockSink,
|
|
73
80
|
private readonly l1Constants: SequencerRollupConstants,
|
|
74
81
|
protected config: ResolvedSequencerConfig,
|
|
75
82
|
protected timetable: SequencerTimetable,
|
|
@@ -80,12 +87,14 @@ export class CheckpointProposalJob {
|
|
|
80
87
|
private readonly eventEmitter: TypedEventEmitter<SequencerEvents>,
|
|
81
88
|
private readonly setStateFn: (state: SequencerState, slot?: SlotNumber) => void,
|
|
82
89
|
protected readonly log: Logger,
|
|
90
|
+
public readonly tracer: Tracer,
|
|
83
91
|
) {}
|
|
84
92
|
|
|
85
93
|
/**
|
|
86
94
|
* Executes the checkpoint proposal job.
|
|
87
95
|
* Returns the published checkpoint if successful, undefined otherwise.
|
|
88
96
|
*/
|
|
97
|
+
@trackSpan('CheckpointProposalJob.execute')
|
|
89
98
|
public async execute(): Promise<Checkpoint | undefined> {
|
|
90
99
|
// Enqueue governance and slashing votes (returns promises that will be awaited later)
|
|
91
100
|
// In fisherman mode, we simulate slashing but don't actually publish to L1
|
|
@@ -132,6 +141,13 @@ export class CheckpointProposalJob {
|
|
|
132
141
|
}
|
|
133
142
|
}
|
|
134
143
|
|
|
144
|
+
@trackSpan('CheckpointProposalJob.proposeCheckpoint', function () {
|
|
145
|
+
return {
|
|
146
|
+
// nullish operator needed for tests
|
|
147
|
+
[Attributes.COINBASE]: this.validatorClient.getCoinbaseForAttestor(this.attestorAddress)?.toString(),
|
|
148
|
+
[Attributes.SLOT_NUMBER]: this.slot,
|
|
149
|
+
};
|
|
150
|
+
})
|
|
135
151
|
private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
|
|
136
152
|
try {
|
|
137
153
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
@@ -142,9 +158,9 @@ export class CheckpointProposalJob {
|
|
|
142
158
|
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
|
|
143
159
|
this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
|
|
144
160
|
|
|
145
|
-
// Enqueues
|
|
146
|
-
if (this.
|
|
147
|
-
this.publisher.
|
|
161
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
162
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
163
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
// Create checkpoint builder for the slot
|
|
@@ -154,8 +170,15 @@ export class CheckpointProposalJob {
|
|
|
154
170
|
this.slot,
|
|
155
171
|
);
|
|
156
172
|
|
|
157
|
-
// Collect L1 to L2 messages for the checkpoint
|
|
173
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
158
174
|
const l1ToL2Messages = await this.l1ToL2MessageSource.getL1ToL2Messages(this.checkpointNumber);
|
|
175
|
+
const inHash = computeInHashFromL1ToL2Messages(l1ToL2Messages);
|
|
176
|
+
|
|
177
|
+
// Collect the out hashes of all the checkpoints before this one in the same epoch
|
|
178
|
+
const previousCheckpoints = (await this.l2BlockSource.getCheckpointsForEpoch(this.epoch)).filter(
|
|
179
|
+
c => c.number < this.checkpointNumber,
|
|
180
|
+
);
|
|
181
|
+
const previousCheckpointOutHashes = previousCheckpoints.map(c => c.getCheckpointOutHash());
|
|
159
182
|
|
|
160
183
|
// Create a long-lived forked world state for the checkpoint builder
|
|
161
184
|
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
@@ -165,6 +188,7 @@ export class CheckpointProposalJob {
|
|
|
165
188
|
this.checkpointNumber,
|
|
166
189
|
checkpointGlobalVariables,
|
|
167
190
|
l1ToL2Messages,
|
|
191
|
+
previousCheckpointOutHashes,
|
|
168
192
|
fork,
|
|
169
193
|
);
|
|
170
194
|
|
|
@@ -174,12 +198,45 @@ export class CheckpointProposalJob {
|
|
|
174
198
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
175
199
|
};
|
|
176
200
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
201
|
+
const checkpointProposalOptions: CheckpointProposalOptions = {
|
|
202
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
203
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
let blocksInCheckpoint: L2BlockNew[] = [];
|
|
207
|
+
let blockPendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined = undefined;
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
// Main loop: build blocks for the checkpoint
|
|
211
|
+
const result = await this.buildBlocksForCheckpoint(
|
|
212
|
+
checkpointBuilder,
|
|
213
|
+
checkpointGlobalVariables.timestamp,
|
|
214
|
+
inHash,
|
|
215
|
+
blockProposalOptions,
|
|
216
|
+
);
|
|
217
|
+
blocksInCheckpoint = result.blocksInCheckpoint;
|
|
218
|
+
blockPendingBroadcast = result.blockPendingBroadcast;
|
|
219
|
+
} catch (err) {
|
|
220
|
+
// These errors are expected in HA mode, so we yield and let another HA node handle the slot
|
|
221
|
+
// The only distinction between the 2 errors is SlashingProtectionError throws when the payload is different,
|
|
222
|
+
// which is normal for block building (may have picked different txs)
|
|
223
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
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
|
+
});
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
throw err;
|
|
239
|
+
}
|
|
183
240
|
|
|
184
241
|
if (blocksInCheckpoint.length === 0) {
|
|
185
242
|
this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
|
|
@@ -207,26 +264,61 @@ export class CheckpointProposalJob {
|
|
|
207
264
|
return checkpoint;
|
|
208
265
|
}
|
|
209
266
|
|
|
210
|
-
//
|
|
267
|
+
// Include the block pending broadcast in the checkpoint proposal if any
|
|
268
|
+
const lastBlock = blockPendingBroadcast && {
|
|
269
|
+
blockHeader: blockPendingBroadcast.block.header,
|
|
270
|
+
indexWithinCheckpoint: blockPendingBroadcast.block.indexWithinCheckpoint,
|
|
271
|
+
txs: blockPendingBroadcast.txs,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// Create the checkpoint proposal and broadcast it
|
|
211
275
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
212
276
|
checkpoint.header,
|
|
213
277
|
checkpoint.archive.root,
|
|
214
|
-
|
|
278
|
+
lastBlock,
|
|
215
279
|
this.proposer,
|
|
216
|
-
|
|
280
|
+
checkpointProposalOptions,
|
|
217
281
|
);
|
|
282
|
+
|
|
218
283
|
const blockProposedAt = this.dateProvider.now();
|
|
219
|
-
await this.p2pClient.
|
|
284
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
220
285
|
|
|
221
286
|
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
|
|
222
287
|
const attestations = await this.waitForAttestations(proposal);
|
|
223
288
|
const blockAttestedAt = this.dateProvider.now();
|
|
224
289
|
|
|
225
|
-
this.metrics.
|
|
290
|
+
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
226
291
|
|
|
227
292
|
// Proposer must sign over the attestations before pushing them to L1
|
|
228
293
|
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
229
|
-
|
|
294
|
+
let attestationsSignature: Signature;
|
|
295
|
+
try {
|
|
296
|
+
attestationsSignature = await this.validatorClient.signAttestationsAndSigners(
|
|
297
|
+
attestations,
|
|
298
|
+
signer,
|
|
299
|
+
this.slot,
|
|
300
|
+
this.checkpointNumber,
|
|
301
|
+
);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
// 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 instanceof DutyAlreadySignedError) {
|
|
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
|
+
});
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
throw err;
|
|
321
|
+
}
|
|
230
322
|
|
|
231
323
|
// Enqueue publishing the checkpoint to L1
|
|
232
324
|
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
@@ -235,7 +327,7 @@ export class CheckpointProposalJob {
|
|
|
235
327
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
236
328
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
237
329
|
txTimeoutAt,
|
|
238
|
-
|
|
330
|
+
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
239
331
|
});
|
|
240
332
|
|
|
241
333
|
return checkpoint;
|
|
@@ -248,20 +340,25 @@ export class CheckpointProposalJob {
|
|
|
248
340
|
/**
|
|
249
341
|
* Builds blocks for a checkpoint within the current slot.
|
|
250
342
|
*/
|
|
343
|
+
@trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint')
|
|
251
344
|
private async buildBlocksForCheckpoint(
|
|
252
345
|
checkpointBuilder: CheckpointBuilder,
|
|
253
346
|
timestamp: bigint,
|
|
347
|
+
inHash: Fr,
|
|
254
348
|
blockProposalOptions: BlockProposalOptions,
|
|
255
349
|
): Promise<{
|
|
256
350
|
blocksInCheckpoint: L2BlockNew[];
|
|
257
|
-
|
|
351
|
+
blockPendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined;
|
|
258
352
|
}> {
|
|
259
353
|
const blocksInCheckpoint: L2BlockNew[] = [];
|
|
260
354
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
261
355
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
262
356
|
|
|
357
|
+
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
358
|
+
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
359
|
+
|
|
263
360
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
264
|
-
let
|
|
361
|
+
let blockPendingBroadcast: { block: L2BlockNew; txs: Tx[] } | undefined = undefined;
|
|
265
362
|
|
|
266
363
|
while (true) {
|
|
267
364
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -292,6 +389,7 @@ export class CheckpointProposalJob {
|
|
|
292
389
|
blockNumber,
|
|
293
390
|
indexWithinCheckpoint,
|
|
294
391
|
txHashesAlreadyIncluded,
|
|
392
|
+
remainingBlobFields,
|
|
295
393
|
});
|
|
296
394
|
|
|
297
395
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
@@ -316,9 +414,12 @@ export class CheckpointProposalJob {
|
|
|
316
414
|
break;
|
|
317
415
|
}
|
|
318
416
|
|
|
319
|
-
const { block, usedTxs } = buildResult;
|
|
417
|
+
const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
|
|
320
418
|
blocksInCheckpoint.push(block);
|
|
321
419
|
|
|
420
|
+
// Update remaining blob fields for the next block
|
|
421
|
+
remainingBlobFields = newRemainingBlobFields;
|
|
422
|
+
|
|
322
423
|
// Sync the proposed block to the archiver to make it available
|
|
323
424
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
324
425
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
@@ -331,17 +432,17 @@ export class CheckpointProposalJob {
|
|
|
331
432
|
blockNumber,
|
|
332
433
|
blocksBuilt,
|
|
333
434
|
});
|
|
334
|
-
|
|
435
|
+
blockPendingBroadcast = { block, txs: usedTxs };
|
|
335
436
|
break;
|
|
336
437
|
}
|
|
337
438
|
|
|
338
439
|
// For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
|
|
339
440
|
// If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
|
|
340
441
|
if (!this.config.fishermanMode) {
|
|
341
|
-
// TODO(palla/mbps): Wire this to the new p2p API once available
|
|
342
442
|
const proposal = await this.validatorClient.createBlockProposal(
|
|
343
|
-
block.header
|
|
344
|
-
|
|
443
|
+
block.header,
|
|
444
|
+
block.indexWithinCheckpoint,
|
|
445
|
+
inHash,
|
|
345
446
|
block.archive.root,
|
|
346
447
|
usedTxs,
|
|
347
448
|
this.proposer,
|
|
@@ -359,13 +460,11 @@ export class CheckpointProposalJob {
|
|
|
359
460
|
blocksBuilt: blocksInCheckpoint.length,
|
|
360
461
|
});
|
|
361
462
|
|
|
362
|
-
return {
|
|
363
|
-
blocksInCheckpoint,
|
|
364
|
-
pendingBroadcast,
|
|
365
|
-
};
|
|
463
|
+
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
366
464
|
}
|
|
367
465
|
|
|
368
466
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
467
|
+
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
369
468
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
370
469
|
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
|
|
371
470
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
|
|
@@ -373,6 +472,7 @@ export class CheckpointProposalJob {
|
|
|
373
472
|
}
|
|
374
473
|
|
|
375
474
|
/** Builds a single block. Called from the main block building loop. */
|
|
475
|
+
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
376
476
|
private async buildSingleBlock(
|
|
377
477
|
checkpointBuilder: CheckpointBuilder,
|
|
378
478
|
opts: {
|
|
@@ -382,10 +482,18 @@ export class CheckpointProposalJob {
|
|
|
382
482
|
indexWithinCheckpoint: number;
|
|
383
483
|
buildDeadline: Date | undefined;
|
|
384
484
|
txHashesAlreadyIncluded: Set<string>;
|
|
485
|
+
remainingBlobFields: number;
|
|
385
486
|
},
|
|
386
|
-
): Promise<{ block: L2BlockNew; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
387
|
-
const {
|
|
388
|
-
|
|
487
|
+
): Promise<{ block: L2BlockNew; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
488
|
+
const {
|
|
489
|
+
blockTimestamp,
|
|
490
|
+
forceCreate,
|
|
491
|
+
blockNumber,
|
|
492
|
+
indexWithinCheckpoint,
|
|
493
|
+
buildDeadline,
|
|
494
|
+
txHashesAlreadyIncluded,
|
|
495
|
+
remainingBlobFields,
|
|
496
|
+
} = opts;
|
|
389
497
|
|
|
390
498
|
this.log.verbose(
|
|
391
499
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -418,18 +526,31 @@ export class CheckpointProposalJob {
|
|
|
418
526
|
{ slot: this.slot, blockNumber, indexWithinCheckpoint },
|
|
419
527
|
);
|
|
420
528
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
529
|
+
|
|
530
|
+
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
531
|
+
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
532
|
+
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
533
|
+
|
|
421
534
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
422
535
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
423
536
|
maxBlockSize: this.config.maxBlockSizeInBytes,
|
|
424
537
|
maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
|
|
425
|
-
maxBlobFields:
|
|
538
|
+
maxBlobFields: maxBlobFieldsForTxs,
|
|
426
539
|
deadline: buildDeadline,
|
|
427
540
|
};
|
|
428
541
|
|
|
429
542
|
// Actually build the block by executing txs
|
|
430
543
|
const workTimer = new Timer();
|
|
431
|
-
const {
|
|
432
|
-
|
|
544
|
+
const {
|
|
545
|
+
publicGas,
|
|
546
|
+
block,
|
|
547
|
+
publicProcessorDuration,
|
|
548
|
+
numTxs,
|
|
549
|
+
blockBuildingTimer,
|
|
550
|
+
usedTxs,
|
|
551
|
+
failedTxs,
|
|
552
|
+
usedTxBlobFields,
|
|
553
|
+
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
433
554
|
const blockBuildDuration = workTimer.ms();
|
|
434
555
|
|
|
435
556
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
@@ -473,7 +594,7 @@ export class CheckpointProposalJob {
|
|
|
473
594
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
474
595
|
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
475
596
|
|
|
476
|
-
return { block, usedTxs };
|
|
597
|
+
return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
|
|
477
598
|
} catch (err: any) {
|
|
478
599
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
479
600
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -484,6 +605,7 @@ export class CheckpointProposalJob {
|
|
|
484
605
|
}
|
|
485
606
|
|
|
486
607
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
608
|
+
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
487
609
|
private async waitForMinTxs(opts: {
|
|
488
610
|
forceCreate?: boolean;
|
|
489
611
|
blockNumber: BlockNumber;
|
|
@@ -524,7 +646,8 @@ export class CheckpointProposalJob {
|
|
|
524
646
|
* Waits for enough attestations to be collected via p2p.
|
|
525
647
|
* This is run after all blocks for the checkpoint have been built.
|
|
526
648
|
*/
|
|
527
|
-
|
|
649
|
+
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
650
|
+
private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
|
|
528
651
|
if (this.config.fishermanMode) {
|
|
529
652
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
530
653
|
return CommitteeAttestationsAndSigners.empty();
|
|
@@ -573,8 +696,7 @@ export class CheckpointProposalJob {
|
|
|
573
696
|
|
|
574
697
|
// Manipulate the attestations if we've been configured to do so
|
|
575
698
|
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
576
|
-
|
|
577
|
-
return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
|
|
699
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
578
700
|
}
|
|
579
701
|
|
|
580
702
|
return new CommitteeAttestationsAndSigners(sorted);
|
|
@@ -590,7 +712,7 @@ export class CheckpointProposalJob {
|
|
|
590
712
|
|
|
591
713
|
/** Breaks the attestations before publishing based on attack configs */
|
|
592
714
|
private manipulateAttestations(
|
|
593
|
-
|
|
715
|
+
slotNumber: SlotNumber,
|
|
594
716
|
epoch: EpochNumber,
|
|
595
717
|
seed: bigint,
|
|
596
718
|
committee: EthAddress[],
|
|
@@ -598,7 +720,6 @@ export class CheckpointProposalJob {
|
|
|
598
720
|
) {
|
|
599
721
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
600
722
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
601
|
-
const { slotNumber } = checkpoint;
|
|
602
723
|
const proposerIndex = Number(
|
|
603
724
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
604
725
|
);
|
|
@@ -647,16 +768,24 @@ export class CheckpointProposalJob {
|
|
|
647
768
|
}
|
|
648
769
|
|
|
649
770
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
771
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
772
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
773
|
+
* would never receive its own block without this explicit sync.
|
|
652
774
|
*/
|
|
653
775
|
private async syncProposedBlockToArchiver(block: L2BlockNew): Promise<void> {
|
|
654
|
-
|
|
776
|
+
// TODO(palla/mbps): Change default to false once block sync is stable.
|
|
777
|
+
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
778
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
779
|
+
blockNumber: block.number,
|
|
780
|
+
slot: block.header.globalVariables.slotNumber,
|
|
781
|
+
});
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
655
785
|
blockNumber: block.number,
|
|
656
786
|
slot: block.header.globalVariables.slotNumber,
|
|
657
787
|
});
|
|
658
|
-
|
|
659
|
-
await Promise.resolve();
|
|
788
|
+
await this.blockSink.addBlock(block);
|
|
660
789
|
}
|
|
661
790
|
|
|
662
791
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */
|
|
@@ -685,6 +814,7 @@ export class CheckpointProposalJob {
|
|
|
685
814
|
}
|
|
686
815
|
|
|
687
816
|
/** Waits until a specific time within the current slot */
|
|
817
|
+
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
688
818
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
689
819
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
690
820
|
const targetTimestamp = slotStartTimestamp + targetSecondsIntoSlot;
|
|
@@ -5,6 +5,8 @@ import type { SlasherClientInterface } from '@aztec/slasher';
|
|
|
5
5
|
import { getTimestampForSlot } from '@aztec/stdlib/epoch-helpers';
|
|
6
6
|
import type { ResolvedSequencerConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
import type { ValidatorClient } from '@aztec/validator-client';
|
|
8
|
+
import { DutyAlreadySignedError } from '@aztec/validator-ha-signer/errors';
|
|
9
|
+
import { DutyType, type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
8
10
|
|
|
9
11
|
import type { TypedDataDefinition } from 'viem';
|
|
10
12
|
|
|
@@ -17,7 +19,8 @@ import type { SequencerRollupConstants } from './types.js';
|
|
|
17
19
|
*/
|
|
18
20
|
export class CheckpointVoter {
|
|
19
21
|
private slotTimestamp: bigint;
|
|
20
|
-
private
|
|
22
|
+
private governanceSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
|
|
23
|
+
private slashingSigner: (msg: TypedDataDefinition) => Promise<`0x${string}`>;
|
|
21
24
|
|
|
22
25
|
constructor(
|
|
23
26
|
private readonly slot: SlotNumber,
|
|
@@ -31,8 +34,16 @@ export class CheckpointVoter {
|
|
|
31
34
|
private readonly log: Logger,
|
|
32
35
|
) {
|
|
33
36
|
this.slotTimestamp = getTimestampForSlot(this.slot, this.l1Constants);
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
|
|
38
|
+
// Create separate signers with appropriate duty contexts for governance and slashing votes
|
|
39
|
+
// These use HA protection to ensure only one node signs per slot/duty
|
|
40
|
+
const governanceContext: SigningContext = { slot: this.slot, dutyType: DutyType.GOVERNANCE_VOTE };
|
|
41
|
+
this.governanceSigner = (msg: TypedDataDefinition) =>
|
|
42
|
+
this.validatorClient.signWithAddress(this.attestorAddress, msg, governanceContext).then(s => s.toString());
|
|
43
|
+
|
|
44
|
+
const slashingContext: SigningContext = { slot: this.slot, dutyType: DutyType.SLASHING_VOTE };
|
|
45
|
+
this.slashingSigner = (msg: TypedDataDefinition) =>
|
|
46
|
+
this.validatorClient.signWithAddress(this.attestorAddress, msg, slashingContext).then(s => s.toString());
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
/**
|
|
@@ -68,10 +79,17 @@ export class CheckpointVoter {
|
|
|
68
79
|
this.slot,
|
|
69
80
|
this.slotTimestamp,
|
|
70
81
|
this.attestorAddress,
|
|
71
|
-
this.
|
|
82
|
+
this.governanceSigner,
|
|
72
83
|
);
|
|
73
84
|
} catch (err) {
|
|
74
|
-
|
|
85
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
86
|
+
this.log.info(`Governance vote already signed by another node`, {
|
|
87
|
+
slot: this.slot,
|
|
88
|
+
signedByNode: err.signedByNode,
|
|
89
|
+
});
|
|
90
|
+
} else {
|
|
91
|
+
this.log.error(`Error enqueueing governance vote`, err);
|
|
92
|
+
}
|
|
75
93
|
return false;
|
|
76
94
|
}
|
|
77
95
|
}
|
|
@@ -95,10 +113,17 @@ export class CheckpointVoter {
|
|
|
95
113
|
this.slot,
|
|
96
114
|
this.slotTimestamp,
|
|
97
115
|
this.attestorAddress,
|
|
98
|
-
this.
|
|
116
|
+
this.slashingSigner,
|
|
99
117
|
);
|
|
100
118
|
} catch (err) {
|
|
101
|
-
|
|
119
|
+
if (err instanceof DutyAlreadySignedError) {
|
|
120
|
+
this.log.info(`Slashing vote already signed by another node`, {
|
|
121
|
+
slot: this.slot,
|
|
122
|
+
signedByNode: err.signedByNode,
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
this.log.error(`Error enqueueing slashing vote`, err);
|
|
126
|
+
}
|
|
102
127
|
return false;
|
|
103
128
|
}
|
|
104
129
|
}
|