@aztec/sequencer-client 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701
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 +5 -6
- 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 +6 -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 +13 -13
- 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-factory.d.ts +2 -2
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- 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 +19 -18
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +443 -53
- 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 +565 -40
- 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 +25 -15
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +486 -42
- 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 +23 -11
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +50 -7
- package/dest/test/utils.d.ts +13 -9
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +26 -17
- package/package.json +30 -28
- package/src/client/sequencer-client.ts +4 -5
- package/src/config.ts +5 -0
- package/src/global_variable_builder/global_builder.ts +13 -13
- package/src/index.ts +1 -9
- package/src/publisher/sequencer-publisher-factory.ts +1 -1
- package/src/publisher/sequencer-publisher-metrics.ts +14 -70
- package/src/publisher/sequencer-publisher.ts +87 -77
- package/src/sequencer/checkpoint_proposal_job.ts +201 -59
- 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 +124 -41
- package/src/test/index.ts +1 -2
- package/src/test/mock_checkpoint_builder.ts +92 -28
- package/src/test/utils.ts +55 -28
- 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';
|
|
@@ -14,7 +16,9 @@ import type { SlasherClientInterface } from '@aztec/slasher';
|
|
|
14
16
|
import {
|
|
15
17
|
CommitteeAttestation,
|
|
16
18
|
CommitteeAttestationsAndSigners,
|
|
17
|
-
|
|
19
|
+
L2Block,
|
|
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
|
|
@@ -108,6 +117,10 @@ export class CheckpointProposalJob {
|
|
|
108
117
|
// Wait until the voting promises have resolved, so all requests are enqueued (not sent)
|
|
109
118
|
await Promise.all(votesPromises);
|
|
110
119
|
|
|
120
|
+
if (checkpoint) {
|
|
121
|
+
this.metrics.recordBlockProposalSuccess();
|
|
122
|
+
}
|
|
123
|
+
|
|
111
124
|
// Do not post anything to L1 if we are fishermen, but do perform L1 fee analysis
|
|
112
125
|
if (this.config.fishermanMode) {
|
|
113
126
|
await this.handleCheckpointEndAsFisherman(checkpoint);
|
|
@@ -128,6 +141,13 @@ export class CheckpointProposalJob {
|
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
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
|
+
})
|
|
131
151
|
private async proposeCheckpoint(): Promise<Checkpoint | undefined> {
|
|
132
152
|
try {
|
|
133
153
|
// Get operator configured coinbase and fee recipient for this attestor
|
|
@@ -138,9 +158,9 @@ export class CheckpointProposalJob {
|
|
|
138
158
|
this.setStateFn(SequencerState.INITIALIZING_CHECKPOINT, this.slot);
|
|
139
159
|
this.metrics.incOpenSlot(this.slot, this.proposer?.toString() ?? 'unknown');
|
|
140
160
|
|
|
141
|
-
// Enqueues
|
|
142
|
-
if (this.
|
|
143
|
-
this.publisher.
|
|
161
|
+
// Enqueues checkpoint invalidation (constant for the whole slot)
|
|
162
|
+
if (this.invalidateCheckpoint && !this.config.skipInvalidateBlockAsProposer) {
|
|
163
|
+
this.publisher.enqueueInvalidateCheckpoint(this.invalidateCheckpoint);
|
|
144
164
|
}
|
|
145
165
|
|
|
146
166
|
// Create checkpoint builder for the slot
|
|
@@ -150,8 +170,15 @@ export class CheckpointProposalJob {
|
|
|
150
170
|
this.slot,
|
|
151
171
|
);
|
|
152
172
|
|
|
153
|
-
// Collect L1 to L2 messages for the checkpoint
|
|
173
|
+
// Collect L1 to L2 messages for the checkpoint and compute their hash
|
|
154
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());
|
|
155
182
|
|
|
156
183
|
// Create a long-lived forked world state for the checkpoint builder
|
|
157
184
|
using fork = await this.worldState.fork(this.syncedToBlockNumber, { closeDelayMs: 12_000 });
|
|
@@ -161,6 +188,7 @@ export class CheckpointProposalJob {
|
|
|
161
188
|
this.checkpointNumber,
|
|
162
189
|
checkpointGlobalVariables,
|
|
163
190
|
l1ToL2Messages,
|
|
191
|
+
previousCheckpointOutHashes,
|
|
164
192
|
fork,
|
|
165
193
|
);
|
|
166
194
|
|
|
@@ -170,12 +198,45 @@ export class CheckpointProposalJob {
|
|
|
170
198
|
broadcastInvalidBlockProposal: this.config.broadcastInvalidBlockProposal,
|
|
171
199
|
};
|
|
172
200
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
201
|
+
const checkpointProposalOptions: CheckpointProposalOptions = {
|
|
202
|
+
publishFullTxs: !!this.config.publishTxsWithProposals,
|
|
203
|
+
broadcastInvalidCheckpointProposal: this.config.broadcastInvalidBlockProposal,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
let blocksInCheckpoint: L2Block[] = [];
|
|
207
|
+
let blockPendingBroadcast: { block: L2Block; 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
|
+
}
|
|
179
240
|
|
|
180
241
|
if (blocksInCheckpoint.length === 0) {
|
|
181
242
|
this.log.warn(`No blocks were built for slot ${this.slot}`, { slot: this.slot });
|
|
@@ -203,26 +264,61 @@ export class CheckpointProposalJob {
|
|
|
203
264
|
return checkpoint;
|
|
204
265
|
}
|
|
205
266
|
|
|
206
|
-
//
|
|
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
|
|
207
275
|
const proposal = await this.validatorClient.createCheckpointProposal(
|
|
208
276
|
checkpoint.header,
|
|
209
277
|
checkpoint.archive.root,
|
|
210
|
-
|
|
278
|
+
lastBlock,
|
|
211
279
|
this.proposer,
|
|
212
|
-
|
|
280
|
+
checkpointProposalOptions,
|
|
213
281
|
);
|
|
282
|
+
|
|
214
283
|
const blockProposedAt = this.dateProvider.now();
|
|
215
|
-
await this.p2pClient.
|
|
284
|
+
await this.p2pClient.broadcastCheckpointProposal(proposal);
|
|
216
285
|
|
|
217
286
|
this.setStateFn(SequencerState.COLLECTING_ATTESTATIONS, this.slot);
|
|
218
287
|
const attestations = await this.waitForAttestations(proposal);
|
|
219
288
|
const blockAttestedAt = this.dateProvider.now();
|
|
220
289
|
|
|
221
|
-
this.metrics.
|
|
290
|
+
this.metrics.recordCheckpointAttestationDelay(blockAttestedAt - blockProposedAt);
|
|
222
291
|
|
|
223
292
|
// Proposer must sign over the attestations before pushing them to L1
|
|
224
293
|
const signer = this.proposer ?? this.publisher.getSenderAddress();
|
|
225
|
-
|
|
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
|
+
}
|
|
226
322
|
|
|
227
323
|
// Enqueue publishing the checkpoint to L1
|
|
228
324
|
this.setStateFn(SequencerState.PUBLISHING_CHECKPOINT, this.slot);
|
|
@@ -231,11 +327,16 @@ export class CheckpointProposalJob {
|
|
|
231
327
|
const txTimeoutAt = new Date((slotStartBuildTimestamp + aztecSlotDuration) * 1000);
|
|
232
328
|
await this.publisher.enqueueProposeCheckpoint(checkpoint, attestations, attestationsSignature, {
|
|
233
329
|
txTimeoutAt,
|
|
234
|
-
|
|
330
|
+
forcePendingCheckpointNumber: this.invalidateCheckpoint?.forcePendingCheckpointNumber,
|
|
235
331
|
});
|
|
236
332
|
|
|
237
333
|
return checkpoint;
|
|
238
334
|
} catch (err) {
|
|
335
|
+
if (err && (err instanceof DutyAlreadySignedError || err instanceof SlashingProtectionError)) {
|
|
336
|
+
// swallow this error. It's already been logged by a function deeper in the stack
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
239
340
|
this.log.error(`Error building checkpoint at slot ${this.slot}`, err);
|
|
240
341
|
return undefined;
|
|
241
342
|
}
|
|
@@ -244,20 +345,25 @@ export class CheckpointProposalJob {
|
|
|
244
345
|
/**
|
|
245
346
|
* Builds blocks for a checkpoint within the current slot.
|
|
246
347
|
*/
|
|
348
|
+
@trackSpan('CheckpointProposalJob.buildBlocksForCheckpoint')
|
|
247
349
|
private async buildBlocksForCheckpoint(
|
|
248
350
|
checkpointBuilder: CheckpointBuilder,
|
|
249
351
|
timestamp: bigint,
|
|
352
|
+
inHash: Fr,
|
|
250
353
|
blockProposalOptions: BlockProposalOptions,
|
|
251
354
|
): Promise<{
|
|
252
|
-
blocksInCheckpoint:
|
|
253
|
-
|
|
355
|
+
blocksInCheckpoint: L2Block[];
|
|
356
|
+
blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined;
|
|
254
357
|
}> {
|
|
255
|
-
const blocksInCheckpoint:
|
|
358
|
+
const blocksInCheckpoint: L2Block[] = [];
|
|
256
359
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
257
360
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
258
361
|
|
|
362
|
+
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
363
|
+
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
364
|
+
|
|
259
365
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
260
|
-
let
|
|
366
|
+
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
261
367
|
|
|
262
368
|
while (true) {
|
|
263
369
|
const blocksBuilt = blocksInCheckpoint.length;
|
|
@@ -288,6 +394,7 @@ export class CheckpointProposalJob {
|
|
|
288
394
|
blockNumber,
|
|
289
395
|
indexWithinCheckpoint,
|
|
290
396
|
txHashesAlreadyIncluded,
|
|
397
|
+
remainingBlobFields,
|
|
291
398
|
});
|
|
292
399
|
|
|
293
400
|
if (!buildResult && timingInfo.isLastBlock) {
|
|
@@ -312,13 +419,21 @@ export class CheckpointProposalJob {
|
|
|
312
419
|
break;
|
|
313
420
|
}
|
|
314
421
|
|
|
315
|
-
const { block, usedTxs } = buildResult;
|
|
422
|
+
const { block, usedTxs, remainingBlobFields: newRemainingBlobFields } = buildResult;
|
|
316
423
|
blocksInCheckpoint.push(block);
|
|
317
424
|
|
|
425
|
+
// Update remaining blob fields for the next block
|
|
426
|
+
remainingBlobFields = newRemainingBlobFields;
|
|
427
|
+
|
|
318
428
|
// Sync the proposed block to the archiver to make it available
|
|
319
429
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
320
430
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
321
|
-
|
|
431
|
+
// Fire and forget - don't block the critical path, but log errors
|
|
432
|
+
this.syncProposedBlockToArchiver(block).catch(err => {
|
|
433
|
+
this.log.error(`Failed to sync proposed block ${block.number} to archiver`, { blockNumber: block.number, err });
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
usedTxs.forEach(tx => txHashesAlreadyIncluded.add(tx.txHash.toString()));
|
|
322
437
|
|
|
323
438
|
// If this is the last block, exit the loop now so we start collecting attestations
|
|
324
439
|
if (timingInfo.isLastBlock) {
|
|
@@ -327,17 +442,17 @@ export class CheckpointProposalJob {
|
|
|
327
442
|
blockNumber,
|
|
328
443
|
blocksBuilt,
|
|
329
444
|
});
|
|
330
|
-
|
|
445
|
+
blockPendingBroadcast = { block, txs: usedTxs };
|
|
331
446
|
break;
|
|
332
447
|
}
|
|
333
448
|
|
|
334
449
|
// For non-last blocks, broadcast the block proposal (unless we're in fisherman mode)
|
|
335
450
|
// If the block is the last one, we'll broadcast it along with the checkpoint at the end of the loop
|
|
336
451
|
if (!this.config.fishermanMode) {
|
|
337
|
-
// TODO(palla/mbps): Wire this to the new p2p API once available
|
|
338
452
|
const proposal = await this.validatorClient.createBlockProposal(
|
|
339
|
-
block.header
|
|
340
|
-
|
|
453
|
+
block.header,
|
|
454
|
+
block.indexWithinCheckpoint,
|
|
455
|
+
inHash,
|
|
341
456
|
block.archive.root,
|
|
342
457
|
usedTxs,
|
|
343
458
|
this.proposer,
|
|
@@ -355,13 +470,11 @@ export class CheckpointProposalJob {
|
|
|
355
470
|
blocksBuilt: blocksInCheckpoint.length,
|
|
356
471
|
});
|
|
357
472
|
|
|
358
|
-
return {
|
|
359
|
-
blocksInCheckpoint,
|
|
360
|
-
pendingBroadcast,
|
|
361
|
-
};
|
|
473
|
+
return { blocksInCheckpoint, blockPendingBroadcast };
|
|
362
474
|
}
|
|
363
475
|
|
|
364
476
|
/** Sleeps until it is time to produce the next block in the slot */
|
|
477
|
+
@trackSpan('CheckpointProposalJob.waitUntilNextSubslot')
|
|
365
478
|
private async waitUntilNextSubslot(nextSubslotStart: number) {
|
|
366
479
|
this.setStateFn(SequencerState.WAITING_UNTIL_NEXT_BLOCK, this.slot);
|
|
367
480
|
this.log.verbose(`Waiting until time for the next block at ${nextSubslotStart}s into slot`, { slot: this.slot });
|
|
@@ -369,6 +482,7 @@ export class CheckpointProposalJob {
|
|
|
369
482
|
}
|
|
370
483
|
|
|
371
484
|
/** Builds a single block. Called from the main block building loop. */
|
|
485
|
+
@trackSpan('CheckpointProposalJob.buildSingleBlock')
|
|
372
486
|
private async buildSingleBlock(
|
|
373
487
|
checkpointBuilder: CheckpointBuilder,
|
|
374
488
|
opts: {
|
|
@@ -378,10 +492,18 @@ export class CheckpointProposalJob {
|
|
|
378
492
|
indexWithinCheckpoint: number;
|
|
379
493
|
buildDeadline: Date | undefined;
|
|
380
494
|
txHashesAlreadyIncluded: Set<string>;
|
|
495
|
+
remainingBlobFields: number;
|
|
381
496
|
},
|
|
382
|
-
): Promise<{ block:
|
|
383
|
-
const {
|
|
384
|
-
|
|
497
|
+
): Promise<{ block: L2Block; usedTxs: Tx[]; remainingBlobFields: number } | { error: Error } | undefined> {
|
|
498
|
+
const {
|
|
499
|
+
blockTimestamp,
|
|
500
|
+
forceCreate,
|
|
501
|
+
blockNumber,
|
|
502
|
+
indexWithinCheckpoint,
|
|
503
|
+
buildDeadline,
|
|
504
|
+
txHashesAlreadyIncluded,
|
|
505
|
+
remainingBlobFields,
|
|
506
|
+
} = opts;
|
|
385
507
|
|
|
386
508
|
this.log.verbose(
|
|
387
509
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -414,18 +536,31 @@ export class CheckpointProposalJob {
|
|
|
414
536
|
{ slot: this.slot, blockNumber, indexWithinCheckpoint },
|
|
415
537
|
);
|
|
416
538
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
539
|
+
|
|
540
|
+
// Calculate blob fields limit for txs (remaining capacity - this block's end overhead)
|
|
541
|
+
const blockEndOverhead = getNumBlockEndBlobFields(indexWithinCheckpoint === 0);
|
|
542
|
+
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
543
|
+
|
|
417
544
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
418
545
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
419
546
|
maxBlockSize: this.config.maxBlockSizeInBytes,
|
|
420
547
|
maxBlockGas: new Gas(this.config.maxDABlockGas, this.config.maxL2BlockGas),
|
|
421
|
-
maxBlobFields:
|
|
548
|
+
maxBlobFields: maxBlobFieldsForTxs,
|
|
422
549
|
deadline: buildDeadline,
|
|
423
550
|
};
|
|
424
551
|
|
|
425
552
|
// Actually build the block by executing txs
|
|
426
553
|
const workTimer = new Timer();
|
|
427
|
-
const {
|
|
428
|
-
|
|
554
|
+
const {
|
|
555
|
+
publicGas,
|
|
556
|
+
block,
|
|
557
|
+
publicProcessorDuration,
|
|
558
|
+
numTxs,
|
|
559
|
+
blockBuildingTimer,
|
|
560
|
+
usedTxs,
|
|
561
|
+
failedTxs,
|
|
562
|
+
usedTxBlobFields,
|
|
563
|
+
} = await checkpointBuilder.buildBlock(pendingTxs, blockNumber, blockTimestamp, blockBuilderOptions);
|
|
429
564
|
const blockBuildDuration = workTimer.ms();
|
|
430
565
|
|
|
431
566
|
// If any txs failed during execution, drop them from the mempool so we don't pick them up again
|
|
@@ -469,7 +604,7 @@ export class CheckpointProposalJob {
|
|
|
469
604
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
470
605
|
this.metrics.recordBuiltBlock(blockBuildDuration, publicGas.l2Gas);
|
|
471
606
|
|
|
472
|
-
return { block, usedTxs };
|
|
607
|
+
return { block, usedTxs, remainingBlobFields: maxBlobFieldsForTxs - usedTxBlobFields };
|
|
473
608
|
} catch (err: any) {
|
|
474
609
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
475
610
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -480,6 +615,7 @@ export class CheckpointProposalJob {
|
|
|
480
615
|
}
|
|
481
616
|
|
|
482
617
|
/** Waits until minTxs are available on the pool for building a block. */
|
|
618
|
+
@trackSpan('CheckpointProposalJob.waitForMinTxs')
|
|
483
619
|
private async waitForMinTxs(opts: {
|
|
484
620
|
forceCreate?: boolean;
|
|
485
621
|
blockNumber: BlockNumber;
|
|
@@ -520,7 +656,8 @@ export class CheckpointProposalJob {
|
|
|
520
656
|
* Waits for enough attestations to be collected via p2p.
|
|
521
657
|
* This is run after all blocks for the checkpoint have been built.
|
|
522
658
|
*/
|
|
523
|
-
|
|
659
|
+
@trackSpan('CheckpointProposalJob.waitForAttestations')
|
|
660
|
+
private async waitForAttestations(proposal: CheckpointProposal): Promise<CommitteeAttestationsAndSigners> {
|
|
524
661
|
if (this.config.fishermanMode) {
|
|
525
662
|
this.log.debug('Skipping attestation collection in fisherman mode');
|
|
526
663
|
return CommitteeAttestationsAndSigners.empty();
|
|
@@ -569,8 +706,7 @@ export class CheckpointProposalJob {
|
|
|
569
706
|
|
|
570
707
|
// Manipulate the attestations if we've been configured to do so
|
|
571
708
|
if (this.config.injectFakeAttestation || this.config.shuffleAttestationOrdering) {
|
|
572
|
-
|
|
573
|
-
return this.manipulateAttestations(checkpoint, epoch, seed, committee, sorted);
|
|
709
|
+
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
574
710
|
}
|
|
575
711
|
|
|
576
712
|
return new CommitteeAttestationsAndSigners(sorted);
|
|
@@ -586,7 +722,7 @@ export class CheckpointProposalJob {
|
|
|
586
722
|
|
|
587
723
|
/** Breaks the attestations before publishing based on attack configs */
|
|
588
724
|
private manipulateAttestations(
|
|
589
|
-
|
|
725
|
+
slotNumber: SlotNumber,
|
|
590
726
|
epoch: EpochNumber,
|
|
591
727
|
seed: bigint,
|
|
592
728
|
committee: EthAddress[],
|
|
@@ -594,7 +730,6 @@ export class CheckpointProposalJob {
|
|
|
594
730
|
) {
|
|
595
731
|
// Compute the proposer index in the committee, since we dont want to tweak it.
|
|
596
732
|
// Otherwise, the L1 rollup contract will reject the block outright.
|
|
597
|
-
const { slotNumber } = checkpoint;
|
|
598
733
|
const proposerIndex = Number(
|
|
599
734
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
600
735
|
);
|
|
@@ -643,16 +778,23 @@ export class CheckpointProposalJob {
|
|
|
643
778
|
}
|
|
644
779
|
|
|
645
780
|
/**
|
|
646
|
-
*
|
|
647
|
-
*
|
|
781
|
+
* Adds the proposed block to the archiver so it's available via P2P.
|
|
782
|
+
* Gossip doesn't echo messages back to the sender, so the proposer's archiver/world-state
|
|
783
|
+
* would never receive its own block without this explicit sync.
|
|
648
784
|
*/
|
|
649
|
-
private async syncProposedBlockToArchiver(block:
|
|
650
|
-
this.
|
|
785
|
+
private async syncProposedBlockToArchiver(block: L2Block): Promise<void> {
|
|
786
|
+
if (this.config.skipPushProposedBlocksToArchiver !== false) {
|
|
787
|
+
this.log.warn(`Skipping push of proposed block ${block.number} to archiver`, {
|
|
788
|
+
blockNumber: block.number,
|
|
789
|
+
slot: block.header.globalVariables.slotNumber,
|
|
790
|
+
});
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
this.log.debug(`Syncing proposed block ${block.number} to archiver`, {
|
|
651
794
|
blockNumber: block.number,
|
|
652
795
|
slot: block.header.globalVariables.slotNumber,
|
|
653
796
|
});
|
|
654
|
-
|
|
655
|
-
await Promise.resolve();
|
|
797
|
+
await this.blockSink.addBlock(block);
|
|
656
798
|
}
|
|
657
799
|
|
|
658
800
|
/** Runs fee analysis and logs checkpoint outcome as fisherman */
|
|
@@ -669,7 +811,6 @@ export class CheckpointProposalJob {
|
|
|
669
811
|
...checkpoint.getStats(),
|
|
670
812
|
feeAnalysisId: feeAnalysis?.id,
|
|
671
813
|
});
|
|
672
|
-
this.metrics.recordBlockProposalSuccess();
|
|
673
814
|
} else {
|
|
674
815
|
this.log.warn(`Validation block building FAILED for slot ${this.slot}`, {
|
|
675
816
|
slot: this.slot,
|
|
@@ -682,6 +823,7 @@ export class CheckpointProposalJob {
|
|
|
682
823
|
}
|
|
683
824
|
|
|
684
825
|
/** Waits until a specific time within the current slot */
|
|
826
|
+
@trackSpan('CheckpointProposalJob.waitUntilTimeInSlot')
|
|
685
827
|
protected async waitUntilTimeInSlot(targetSecondsIntoSlot: number): Promise<void> {
|
|
686
828
|
const slotStartTimestamp = this.getSlotStartBuildTimestamp();
|
|
687
829
|
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
|
}
|