@aztec/sequencer-client 4.0.4 → 4.1.0-nightly.20260311
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 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +85 -13
- package/dest/config.d.ts +23 -4
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +25 -13
- package/dest/sequencer/checkpoint_proposal_job.d.ts +2 -4
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +46 -31
- package/dest/sequencer/sequencer.d.ts +9 -6
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1 -1
- package/dest/sequencer/timetable.d.ts +4 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +6 -7
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +4 -6
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +41 -30
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +111 -12
- package/src/config.ts +29 -16
- package/src/sequencer/checkpoint_proposal_job.ts +66 -42
- package/src/sequencer/sequencer.ts +1 -1
- package/src/sequencer/timetable.ts +7 -7
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +50 -45
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
2
|
+
import { MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT } from '@aztec/constants';
|
|
2
3
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
3
4
|
import { isAnvilTestChain } from '@aztec/ethereum/chain';
|
|
4
5
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
@@ -18,10 +19,15 @@ import type { L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
|
18
19
|
import { L1Metrics, type TelemetryClient } from '@aztec/telemetry-client';
|
|
19
20
|
import { FullNodeCheckpointsBuilder, NodeKeystoreAdapter, type ValidatorClient } from '@aztec/validator-client';
|
|
20
21
|
|
|
21
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
DefaultSequencerConfig,
|
|
24
|
+
type SequencerClientConfig,
|
|
25
|
+
getPublisherConfigFromSequencerConfig,
|
|
26
|
+
} from '../config.js';
|
|
22
27
|
import { GlobalVariableBuilder } from '../global_variable_builder/index.js';
|
|
23
28
|
import { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
24
29
|
import { Sequencer, type SequencerConfig } from '../sequencer/index.js';
|
|
30
|
+
import { SequencerTimetable } from '../sequencer/timetable.js';
|
|
25
31
|
|
|
26
32
|
/**
|
|
27
33
|
* Encapsulates the full sequencer and publisher.
|
|
@@ -137,17 +143,14 @@ export class SequencerClient {
|
|
|
137
143
|
});
|
|
138
144
|
|
|
139
145
|
const ethereumSlotDuration = config.ethereumSlotDuration;
|
|
140
|
-
const l1Constants = { l1GenesisTime, slotDuration: Number(slotDuration), ethereumSlotDuration };
|
|
141
146
|
|
|
142
|
-
const globalsBuilder = new GlobalVariableBuilder({
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
sequencerManaLimit = rollupManaLimit;
|
|
150
|
-
}
|
|
147
|
+
const globalsBuilder = new GlobalVariableBuilder({
|
|
148
|
+
...config,
|
|
149
|
+
l1GenesisTime,
|
|
150
|
+
slotDuration: Number(slotDuration),
|
|
151
|
+
ethereumSlotDuration,
|
|
152
|
+
rollupVersion,
|
|
153
|
+
});
|
|
151
154
|
|
|
152
155
|
// When running in anvil, assume we can post a tx up until one second before the end of an L1 slot.
|
|
153
156
|
// Otherwise, we need the full L1 slot duration for publishing to ensure inclusion.
|
|
@@ -157,6 +160,15 @@ export class SequencerClient {
|
|
|
157
160
|
const l1PublishingTimeBasedOnChain = isAnvilTestChain(config.l1ChainId) ? 1 : ethereumSlotDuration;
|
|
158
161
|
const l1PublishingTime = config.l1PublishingTime ?? l1PublishingTimeBasedOnChain;
|
|
159
162
|
|
|
163
|
+
const { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock } = computeBlockLimits(
|
|
164
|
+
config,
|
|
165
|
+
rollupManaLimit,
|
|
166
|
+
l1PublishingTime,
|
|
167
|
+
log,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
const l1Constants = { l1GenesisTime, slotDuration: Number(slotDuration), ethereumSlotDuration, rollupManaLimit };
|
|
171
|
+
|
|
160
172
|
const sequencer = new Sequencer(
|
|
161
173
|
publisherFactory,
|
|
162
174
|
validatorClient,
|
|
@@ -171,7 +183,7 @@ export class SequencerClient {
|
|
|
171
183
|
deps.dateProvider,
|
|
172
184
|
epochCache,
|
|
173
185
|
rollupContract,
|
|
174
|
-
{ ...config, l1PublishingTime, maxL2BlockGas
|
|
186
|
+
{ ...config, l1PublishingTime, maxL2BlockGas, maxDABlockGas, maxTxsPerBlock },
|
|
175
187
|
telemetryClient,
|
|
176
188
|
log,
|
|
177
189
|
);
|
|
@@ -234,3 +246,90 @@ export class SequencerClient {
|
|
|
234
246
|
return this.sequencer.maxL2BlockGas;
|
|
235
247
|
}
|
|
236
248
|
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Computes per-block L2 gas, DA gas, and TX count budgets based on the L1 rollup limits and the timetable.
|
|
252
|
+
* If the user explicitly set a limit, it is capped at the corresponding checkpoint limit.
|
|
253
|
+
* Otherwise, derives it as (checkpointLimit / maxBlocks) * multiplier, capped at the checkpoint limit.
|
|
254
|
+
*/
|
|
255
|
+
export function computeBlockLimits(
|
|
256
|
+
config: SequencerClientConfig,
|
|
257
|
+
rollupManaLimit: number,
|
|
258
|
+
l1PublishingTime: number,
|
|
259
|
+
log: ReturnType<typeof createLogger>,
|
|
260
|
+
): { maxL2BlockGas: number; maxDABlockGas: number; maxTxsPerBlock: number } {
|
|
261
|
+
const maxNumberOfBlocks = new SequencerTimetable({
|
|
262
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
263
|
+
aztecSlotDuration: config.aztecSlotDuration,
|
|
264
|
+
l1PublishingTime,
|
|
265
|
+
p2pPropagationTime: config.attestationPropagationTime,
|
|
266
|
+
blockDurationMs: config.blockDurationMs,
|
|
267
|
+
enforce: config.enforceTimeTable ?? DefaultSequencerConfig.enforceTimeTable,
|
|
268
|
+
}).maxNumberOfBlocks;
|
|
269
|
+
|
|
270
|
+
const multiplier = config.perBlockAllocationMultiplier ?? DefaultSequencerConfig.perBlockAllocationMultiplier;
|
|
271
|
+
|
|
272
|
+
// Compute maxL2BlockGas
|
|
273
|
+
let maxL2BlockGas: number;
|
|
274
|
+
if (config.maxL2BlockGas !== undefined) {
|
|
275
|
+
if (config.maxL2BlockGas > rollupManaLimit) {
|
|
276
|
+
log.warn(
|
|
277
|
+
`Provided MAX_L2_BLOCK_GAS ${config.maxL2BlockGas} exceeds L1 rollup mana limit ${rollupManaLimit} (capping)`,
|
|
278
|
+
);
|
|
279
|
+
maxL2BlockGas = rollupManaLimit;
|
|
280
|
+
} else {
|
|
281
|
+
maxL2BlockGas = config.maxL2BlockGas;
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
maxL2BlockGas = Math.min(rollupManaLimit, Math.ceil((rollupManaLimit / maxNumberOfBlocks) * multiplier));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Compute maxDABlockGas
|
|
288
|
+
const daCheckpointLimit = MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT;
|
|
289
|
+
let maxDABlockGas: number;
|
|
290
|
+
if (config.maxDABlockGas !== undefined) {
|
|
291
|
+
if (config.maxDABlockGas > daCheckpointLimit) {
|
|
292
|
+
log.warn(
|
|
293
|
+
`Provided MAX_DA_BLOCK_GAS ${config.maxDABlockGas} exceeds DA checkpoint limit ${daCheckpointLimit} (capping)`,
|
|
294
|
+
);
|
|
295
|
+
maxDABlockGas = daCheckpointLimit;
|
|
296
|
+
} else {
|
|
297
|
+
maxDABlockGas = config.maxDABlockGas;
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
maxDABlockGas = Math.min(daCheckpointLimit, Math.ceil((daCheckpointLimit / maxNumberOfBlocks) * multiplier));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// Compute maxTxsPerBlock
|
|
304
|
+
const defaultMaxTxsPerBlock = 32;
|
|
305
|
+
let maxTxsPerBlock: number;
|
|
306
|
+
if (config.maxTxsPerBlock !== undefined) {
|
|
307
|
+
if (config.maxTxsPerCheckpoint !== undefined && config.maxTxsPerBlock > config.maxTxsPerCheckpoint) {
|
|
308
|
+
log.warn(
|
|
309
|
+
`Provided MAX_TX_PER_BLOCK ${config.maxTxsPerBlock} exceeds MAX_TX_PER_CHECKPOINT ${config.maxTxsPerCheckpoint} (capping)`,
|
|
310
|
+
);
|
|
311
|
+
maxTxsPerBlock = config.maxTxsPerCheckpoint;
|
|
312
|
+
} else {
|
|
313
|
+
maxTxsPerBlock = config.maxTxsPerBlock;
|
|
314
|
+
}
|
|
315
|
+
} else if (config.maxTxsPerCheckpoint !== undefined) {
|
|
316
|
+
maxTxsPerBlock = Math.min(
|
|
317
|
+
config.maxTxsPerCheckpoint,
|
|
318
|
+
Math.ceil((config.maxTxsPerCheckpoint / maxNumberOfBlocks) * multiplier),
|
|
319
|
+
);
|
|
320
|
+
} else {
|
|
321
|
+
maxTxsPerBlock = defaultMaxTxsPerBlock;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
log.info(`Computed block limits L2=${maxL2BlockGas} DA=${maxDABlockGas} maxTxs=${maxTxsPerBlock}`, {
|
|
325
|
+
maxL2BlockGas,
|
|
326
|
+
maxDABlockGas,
|
|
327
|
+
maxTxsPerBlock,
|
|
328
|
+
rollupManaLimit,
|
|
329
|
+
daCheckpointLimit,
|
|
330
|
+
maxNumberOfBlocks,
|
|
331
|
+
multiplier,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return { maxL2BlockGas, maxDABlockGas, maxTxsPerBlock };
|
|
335
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -13,7 +13,6 @@ import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p/config';
|
|
|
13
13
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
14
|
import {
|
|
15
15
|
type ChainConfig,
|
|
16
|
-
DEFAULT_MAX_TXS_PER_BLOCK,
|
|
17
16
|
type SequencerConfig,
|
|
18
17
|
chainConfigMappings,
|
|
19
18
|
sharedSequencerConfigMappings,
|
|
@@ -36,15 +35,12 @@ export type { SequencerConfig };
|
|
|
36
35
|
* Default values for SequencerConfig.
|
|
37
36
|
* Centralized location for all sequencer configuration defaults.
|
|
38
37
|
*/
|
|
39
|
-
export const DefaultSequencerConfig
|
|
38
|
+
export const DefaultSequencerConfig = {
|
|
40
39
|
sequencerPollingIntervalMS: 500,
|
|
41
|
-
maxTxsPerBlock: DEFAULT_MAX_TXS_PER_BLOCK,
|
|
42
40
|
minTxsPerBlock: 1,
|
|
43
41
|
buildCheckpointIfEmpty: false,
|
|
44
42
|
publishTxsWithProposals: false,
|
|
45
|
-
|
|
46
|
-
maxDABlockGas: 10e9,
|
|
47
|
-
maxBlockSizeInBytes: 1024 * 1024,
|
|
43
|
+
perBlockAllocationMultiplier: 2,
|
|
48
44
|
enforceTimeTable: true,
|
|
49
45
|
attestationPropagationTime: DEFAULT_P2P_PROPAGATION_TIME,
|
|
50
46
|
secondsBeforeInvalidatingBlockAsCommitteeMember: 144, // 12 L1 blocks
|
|
@@ -53,11 +49,13 @@ export const DefaultSequencerConfig: ResolvedSequencerConfig = {
|
|
|
53
49
|
skipInvalidateBlockAsProposer: false,
|
|
54
50
|
broadcastInvalidBlockProposal: false,
|
|
55
51
|
injectFakeAttestation: false,
|
|
52
|
+
injectHighSValueAttestation: false,
|
|
53
|
+
injectUnrecoverableSignatureAttestation: false,
|
|
56
54
|
fishermanMode: false,
|
|
57
55
|
shuffleAttestationOrdering: false,
|
|
58
56
|
skipPushProposedBlocksToArchiver: false,
|
|
59
57
|
skipPublishingCheckpointsPercent: 0,
|
|
60
|
-
};
|
|
58
|
+
} satisfies ResolvedSequencerConfig;
|
|
61
59
|
|
|
62
60
|
/**
|
|
63
61
|
* Configuration settings for the SequencerClient.
|
|
@@ -69,7 +67,7 @@ export type SequencerClientConfig = SequencerPublisherConfig &
|
|
|
69
67
|
SequencerConfig &
|
|
70
68
|
L1ReaderConfig &
|
|
71
69
|
ChainConfig &
|
|
72
|
-
Pick<P2PConfig, '
|
|
70
|
+
Pick<P2PConfig, 'txPublicSetupAllowListExtend'> &
|
|
73
71
|
Pick<L1ContractsConfig, 'ethereumSlotDuration' | 'aztecSlotDuration' | 'aztecEpochDuration'>;
|
|
74
72
|
|
|
75
73
|
export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
@@ -78,6 +76,11 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
78
76
|
description: 'The number of ms to wait between polling for checking to build on the next slot.',
|
|
79
77
|
...numberConfigHelper(DefaultSequencerConfig.sequencerPollingIntervalMS),
|
|
80
78
|
},
|
|
79
|
+
maxTxsPerCheckpoint: {
|
|
80
|
+
env: 'SEQ_MAX_TX_PER_CHECKPOINT',
|
|
81
|
+
description: 'The maximum number of txs across all blocks in a checkpoint.',
|
|
82
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
83
|
+
},
|
|
81
84
|
minTxsPerBlock: {
|
|
82
85
|
env: 'SEQ_MIN_TX_PER_BLOCK',
|
|
83
86
|
description: 'The minimum number of txs to include in a block.',
|
|
@@ -95,12 +98,19 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
95
98
|
maxL2BlockGas: {
|
|
96
99
|
env: 'SEQ_MAX_L2_BLOCK_GAS',
|
|
97
100
|
description: 'The maximum L2 block gas.',
|
|
98
|
-
|
|
101
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
99
102
|
},
|
|
100
103
|
maxDABlockGas: {
|
|
101
104
|
env: 'SEQ_MAX_DA_BLOCK_GAS',
|
|
102
105
|
description: 'The maximum DA block gas.',
|
|
103
|
-
|
|
106
|
+
parseEnv: (val: string) => (val ? parseInt(val, 10) : undefined),
|
|
107
|
+
},
|
|
108
|
+
perBlockAllocationMultiplier: {
|
|
109
|
+
env: 'SEQ_PER_BLOCK_ALLOCATION_MULTIPLIER',
|
|
110
|
+
description:
|
|
111
|
+
'Per-block gas budget multiplier for both L2 and DA gas. Budget per block is (checkpointLimit / maxBlocks) * multiplier.' +
|
|
112
|
+
' Values greater than one allow early blocks to use more than their even share, relying on checkpoint-level capping for later blocks.',
|
|
113
|
+
...numberConfigHelper(DefaultSequencerConfig.perBlockAllocationMultiplier),
|
|
104
114
|
},
|
|
105
115
|
coinbase: {
|
|
106
116
|
env: 'COINBASE',
|
|
@@ -120,11 +130,6 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
120
130
|
env: 'ACVM_BINARY_PATH',
|
|
121
131
|
description: 'The path to the ACVM binary',
|
|
122
132
|
},
|
|
123
|
-
maxBlockSizeInBytes: {
|
|
124
|
-
env: 'SEQ_MAX_BLOCK_SIZE_IN_BYTES',
|
|
125
|
-
description: 'Max block size',
|
|
126
|
-
...numberConfigHelper(DefaultSequencerConfig.maxBlockSizeInBytes),
|
|
127
|
-
},
|
|
128
133
|
enforceTimeTable: {
|
|
129
134
|
env: 'SEQ_ENFORCE_TIME_TABLE',
|
|
130
135
|
description: 'Whether to enforce the time table when building blocks',
|
|
@@ -182,6 +187,14 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
182
187
|
description: 'Inject a fake attestation (for testing only)',
|
|
183
188
|
...booleanConfigHelper(DefaultSequencerConfig.injectFakeAttestation),
|
|
184
189
|
},
|
|
190
|
+
injectHighSValueAttestation: {
|
|
191
|
+
description: 'Inject a malleable attestation with a high-s value (for testing only)',
|
|
192
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectHighSValueAttestation),
|
|
193
|
+
},
|
|
194
|
+
injectUnrecoverableSignatureAttestation: {
|
|
195
|
+
description: 'Inject an attestation with an unrecoverable signature (for testing only)',
|
|
196
|
+
...booleanConfigHelper(DefaultSequencerConfig.injectUnrecoverableSignatureAttestation),
|
|
197
|
+
},
|
|
185
198
|
fishermanMode: {
|
|
186
199
|
env: 'FISHERMAN_MODE',
|
|
187
200
|
description:
|
|
@@ -210,7 +223,7 @@ export const sequencerConfigMappings: ConfigMappingsType<SequencerConfig> = {
|
|
|
210
223
|
description: 'Percent probability (0 - 100) of sequencer skipping checkpoint publishing (testing only)',
|
|
211
224
|
...numberConfigHelper(DefaultSequencerConfig.skipPublishingCheckpointsPercent),
|
|
212
225
|
},
|
|
213
|
-
...pickConfigMappings(p2pConfigMappings, ['
|
|
226
|
+
...pickConfigMappings(p2pConfigMappings, ['txPublicSetupAllowListExtend']),
|
|
214
227
|
};
|
|
215
228
|
|
|
216
229
|
export const sequencerClientConfigMappings: ConfigMappingsType<SequencerClientConfig> = {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { NUM_CHECKPOINT_END_MARKER_FIELDS, getNumBlockEndBlobFields } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { BLOBS_PER_CHECKPOINT, FIELDS_PER_BLOB } from '@aztec/constants';
|
|
3
1
|
import type { EpochCache } from '@aztec/epoch-cache';
|
|
4
2
|
import {
|
|
5
3
|
BlockNumber,
|
|
@@ -9,6 +7,11 @@ import {
|
|
|
9
7
|
SlotNumber,
|
|
10
8
|
} from '@aztec/foundation/branded-types';
|
|
11
9
|
import { randomInt } from '@aztec/foundation/crypto/random';
|
|
10
|
+
import {
|
|
11
|
+
flipSignature,
|
|
12
|
+
generateRecoverableSignature,
|
|
13
|
+
generateUnrecoverableSignature,
|
|
14
|
+
} from '@aztec/foundation/crypto/secp256k1-signer';
|
|
12
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
17
|
import { Signature } from '@aztec/foundation/eth-signature';
|
|
@@ -27,7 +30,7 @@ import {
|
|
|
27
30
|
type L2BlockSource,
|
|
28
31
|
MaliciousCommitteeAttestationsAndSigners,
|
|
29
32
|
} from '@aztec/stdlib/block';
|
|
30
|
-
import type
|
|
33
|
+
import { type Checkpoint, validateCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
31
34
|
import { getSlotStartBuildTimestamp } from '@aztec/stdlib/epoch-helpers';
|
|
32
35
|
import { Gas } from '@aztec/stdlib/gas';
|
|
33
36
|
import {
|
|
@@ -262,6 +265,22 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
262
265
|
this.setStateFn(SequencerState.ASSEMBLING_CHECKPOINT, this.slot);
|
|
263
266
|
const checkpoint = await checkpointBuilder.completeCheckpoint();
|
|
264
267
|
|
|
268
|
+
// Final validation round for the checkpoint before we propose it, just for safety
|
|
269
|
+
try {
|
|
270
|
+
validateCheckpoint(checkpoint, {
|
|
271
|
+
rollupManaLimit: this.l1Constants.rollupManaLimit,
|
|
272
|
+
maxL2BlockGas: this.config.maxL2BlockGas,
|
|
273
|
+
maxDABlockGas: this.config.maxDABlockGas,
|
|
274
|
+
maxTxsPerBlock: this.config.maxTxsPerBlock,
|
|
275
|
+
maxTxsPerCheckpoint: this.config.maxTxsPerCheckpoint,
|
|
276
|
+
});
|
|
277
|
+
} catch (err) {
|
|
278
|
+
this.log.error(`Built an invalid checkpoint at slot ${this.slot} (skipping proposal)`, err, {
|
|
279
|
+
checkpoint: checkpoint.header.toInspect(),
|
|
280
|
+
});
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
265
284
|
// Record checkpoint-level build metrics
|
|
266
285
|
this.metrics.recordCheckpointBuild(
|
|
267
286
|
checkpointBuildTimer.ms(),
|
|
@@ -384,9 +403,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
384
403
|
const txHashesAlreadyIncluded = new Set<string>();
|
|
385
404
|
const initialBlockNumber = BlockNumber(this.syncedToBlockNumber + 1);
|
|
386
405
|
|
|
387
|
-
// Remaining blob fields available for blocks (checkpoint end marker already subtracted)
|
|
388
|
-
let remainingBlobFields = BLOBS_PER_CHECKPOINT * FIELDS_PER_BLOB - NUM_CHECKPOINT_END_MARKER_FIELDS;
|
|
389
|
-
|
|
390
406
|
// Last block in the checkpoint will usually be flagged as pending broadcast, so we send it along with the checkpoint proposal
|
|
391
407
|
let blockPendingBroadcast: { block: L2Block; txs: Tx[] } | undefined = undefined;
|
|
392
408
|
|
|
@@ -419,7 +435,6 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
419
435
|
blockNumber,
|
|
420
436
|
indexWithinCheckpoint,
|
|
421
437
|
txHashesAlreadyIncluded,
|
|
422
|
-
remainingBlobFields,
|
|
423
438
|
});
|
|
424
439
|
|
|
425
440
|
// TODO(palla/mbps): Review these conditions. We may want to keep trying in some scenarios.
|
|
@@ -445,12 +460,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
445
460
|
break;
|
|
446
461
|
}
|
|
447
462
|
|
|
448
|
-
const { block, usedTxs
|
|
463
|
+
const { block, usedTxs } = buildResult;
|
|
449
464
|
blocksInCheckpoint.push(block);
|
|
450
465
|
|
|
451
|
-
// Update remaining blob fields for the next block
|
|
452
|
-
remainingBlobFields = newRemainingBlobFields;
|
|
453
|
-
|
|
454
466
|
// Sync the proposed block to the archiver to make it available
|
|
455
467
|
// Note that the checkpoint builder uses its own fork so it should not need to wait for this syncing
|
|
456
468
|
// Eventually we should refactor the checkpoint builder to not need a separate long-lived fork
|
|
@@ -518,18 +530,10 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
518
530
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
519
531
|
buildDeadline: Date | undefined;
|
|
520
532
|
txHashesAlreadyIncluded: Set<string>;
|
|
521
|
-
remainingBlobFields: number;
|
|
522
533
|
},
|
|
523
|
-
): Promise<{ block: L2Block; usedTxs: Tx[]
|
|
524
|
-
const {
|
|
525
|
-
|
|
526
|
-
forceCreate,
|
|
527
|
-
blockNumber,
|
|
528
|
-
indexWithinCheckpoint,
|
|
529
|
-
buildDeadline,
|
|
530
|
-
txHashesAlreadyIncluded,
|
|
531
|
-
remainingBlobFields,
|
|
532
|
-
} = opts;
|
|
534
|
+
): Promise<{ block: L2Block; usedTxs: Tx[] } | { error: Error } | undefined> {
|
|
535
|
+
const { blockTimestamp, forceCreate, blockNumber, indexWithinCheckpoint, buildDeadline, txHashesAlreadyIncluded } =
|
|
536
|
+
opts;
|
|
533
537
|
|
|
534
538
|
this.log.verbose(
|
|
535
539
|
`Preparing block ${blockNumber} index ${indexWithinCheckpoint} at checkpoint ${this.checkpointNumber} for slot ${this.slot}`,
|
|
@@ -538,8 +542,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
538
542
|
|
|
539
543
|
try {
|
|
540
544
|
// Wait until we have enough txs to build the block
|
|
541
|
-
const minTxs = this.
|
|
542
|
-
const { availableTxs, canStartBuilding } = await this.waitForMinTxs(opts);
|
|
545
|
+
const { availableTxs, canStartBuilding, minTxs } = await this.waitForMinTxs(opts);
|
|
543
546
|
if (!canStartBuilding) {
|
|
544
547
|
this.log.warn(
|
|
545
548
|
`Not enough txs to build block ${blockNumber} at index ${indexWithinCheckpoint} in slot ${this.slot} (got ${availableTxs} txs but needs ${minTxs})`,
|
|
@@ -563,16 +566,16 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
563
566
|
);
|
|
564
567
|
this.setStateFn(SequencerState.CREATING_BLOCK, this.slot);
|
|
565
568
|
|
|
566
|
-
//
|
|
567
|
-
|
|
568
|
-
const maxBlobFieldsForTxs = remainingBlobFields - blockEndOverhead;
|
|
569
|
-
|
|
569
|
+
// Per-block limits derived at startup by computeBlockLimits(), further capped
|
|
570
|
+
// by remaining checkpoint-level budgets inside CheckpointBuilder before each block is built.
|
|
570
571
|
const blockBuilderOptions: PublicProcessorLimits = {
|
|
571
572
|
maxTransactions: this.config.maxTxsPerBlock,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
573
|
+
maxBlockGas:
|
|
574
|
+
this.config.maxL2BlockGas !== undefined || this.config.maxDABlockGas !== undefined
|
|
575
|
+
? new Gas(this.config.maxDABlockGas ?? Infinity, this.config.maxL2BlockGas ?? Infinity)
|
|
576
|
+
: undefined,
|
|
575
577
|
deadline: buildDeadline,
|
|
578
|
+
isBuildingProposal: true,
|
|
576
579
|
};
|
|
577
580
|
|
|
578
581
|
// Actually build the block by executing txs
|
|
@@ -602,7 +605,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
602
605
|
}
|
|
603
606
|
|
|
604
607
|
// Block creation succeeded, emit stats and metrics
|
|
605
|
-
const {
|
|
608
|
+
const { block, publicProcessorDuration, usedTxs, blockBuildDuration } = buildResult;
|
|
606
609
|
|
|
607
610
|
const blockStats = {
|
|
608
611
|
eventName: 'l2-block-built',
|
|
@@ -613,7 +616,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
613
616
|
|
|
614
617
|
const blockHash = await block.hash();
|
|
615
618
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
616
|
-
const manaPerSec =
|
|
619
|
+
const manaPerSec = block.header.totalManaUsed.toNumberUnsafe() / (blockBuildDuration / 1000);
|
|
617
620
|
|
|
618
621
|
this.log.info(
|
|
619
622
|
`Built block ${block.number} at checkpoint ${this.checkpointNumber} for slot ${this.slot} with ${numTxs} txs`,
|
|
@@ -621,9 +624,9 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
621
624
|
);
|
|
622
625
|
|
|
623
626
|
this.eventEmitter.emit('block-proposed', { blockNumber: block.number, slot: this.slot });
|
|
624
|
-
this.metrics.recordBuiltBlock(blockBuildDuration,
|
|
627
|
+
this.metrics.recordBuiltBlock(blockBuildDuration, block.header.totalManaUsed.toNumberUnsafe());
|
|
625
628
|
|
|
626
|
-
return { block, usedTxs
|
|
629
|
+
return { block, usedTxs };
|
|
627
630
|
} catch (err: any) {
|
|
628
631
|
this.eventEmitter.emit('block-build-failed', { reason: err.message, slot: this.slot });
|
|
629
632
|
this.log.error(`Error building block`, err, { blockNumber, slot: this.slot });
|
|
@@ -661,7 +664,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
661
664
|
blockNumber: BlockNumber;
|
|
662
665
|
indexWithinCheckpoint: IndexWithinCheckpoint;
|
|
663
666
|
buildDeadline: Date | undefined;
|
|
664
|
-
}): Promise<{ canStartBuilding: boolean; availableTxs: number }> {
|
|
667
|
+
}): Promise<{ canStartBuilding: boolean; availableTxs: number; minTxs: number }> {
|
|
665
668
|
const { indexWithinCheckpoint, blockNumber, buildDeadline, forceCreate } = opts;
|
|
666
669
|
|
|
667
670
|
// We only allow a block with 0 txs in the first block of the checkpoint
|
|
@@ -678,7 +681,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
678
681
|
// If we're past deadline, or we have no deadline, give up
|
|
679
682
|
const now = this.dateProvider.nowAsDate();
|
|
680
683
|
if (startBuildingDeadline === undefined || now >= startBuildingDeadline) {
|
|
681
|
-
return { canStartBuilding: false, availableTxs
|
|
684
|
+
return { canStartBuilding: false, availableTxs, minTxs };
|
|
682
685
|
}
|
|
683
686
|
|
|
684
687
|
// Wait a bit before checking again
|
|
@@ -691,7 +694,7 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
691
694
|
availableTxs = await this.p2pClient.getPendingTxCount();
|
|
692
695
|
}
|
|
693
696
|
|
|
694
|
-
return { canStartBuilding: true, availableTxs };
|
|
697
|
+
return { canStartBuilding: true, availableTxs, minTxs };
|
|
695
698
|
}
|
|
696
699
|
|
|
697
700
|
/**
|
|
@@ -759,7 +762,12 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
759
762
|
const sorted = orderAttestations(trimmed, committee);
|
|
760
763
|
|
|
761
764
|
// Manipulate the attestations if we've been configured to do so
|
|
762
|
-
if (
|
|
765
|
+
if (
|
|
766
|
+
this.config.injectFakeAttestation ||
|
|
767
|
+
this.config.injectHighSValueAttestation ||
|
|
768
|
+
this.config.injectUnrecoverableSignatureAttestation ||
|
|
769
|
+
this.config.shuffleAttestationOrdering
|
|
770
|
+
) {
|
|
763
771
|
return this.manipulateAttestations(proposal.slotNumber, epoch, seed, committee, sorted);
|
|
764
772
|
}
|
|
765
773
|
|
|
@@ -788,7 +796,11 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
788
796
|
this.epochCache.computeProposerIndex(slotNumber, epoch, seed, BigInt(committee.length)),
|
|
789
797
|
);
|
|
790
798
|
|
|
791
|
-
if (
|
|
799
|
+
if (
|
|
800
|
+
this.config.injectFakeAttestation ||
|
|
801
|
+
this.config.injectHighSValueAttestation ||
|
|
802
|
+
this.config.injectUnrecoverableSignatureAttestation
|
|
803
|
+
) {
|
|
792
804
|
// Find non-empty attestations that are not from the proposer
|
|
793
805
|
const nonProposerIndices: number[] = [];
|
|
794
806
|
for (let i = 0; i < attestations.length; i++) {
|
|
@@ -798,8 +810,20 @@ export class CheckpointProposalJob implements Traceable {
|
|
|
798
810
|
}
|
|
799
811
|
if (nonProposerIndices.length > 0) {
|
|
800
812
|
const targetIndex = nonProposerIndices[randomInt(nonProposerIndices.length)];
|
|
801
|
-
this.
|
|
802
|
-
|
|
813
|
+
if (this.config.injectHighSValueAttestation) {
|
|
814
|
+
this.log.warn(
|
|
815
|
+
`Injecting high-s value attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
816
|
+
);
|
|
817
|
+
unfreeze(attestations[targetIndex]).signature = flipSignature(attestations[targetIndex].signature);
|
|
818
|
+
} else if (this.config.injectUnrecoverableSignatureAttestation) {
|
|
819
|
+
this.log.warn(
|
|
820
|
+
`Injecting unrecoverable signature attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`,
|
|
821
|
+
);
|
|
822
|
+
unfreeze(attestations[targetIndex]).signature = generateUnrecoverableSignature();
|
|
823
|
+
} else {
|
|
824
|
+
this.log.warn(`Injecting fake attestation in checkpoint for slot ${slotNumber} at index ${targetIndex}`);
|
|
825
|
+
unfreeze(attestations[targetIndex]).signature = generateRecoverableSignature();
|
|
826
|
+
}
|
|
803
827
|
}
|
|
804
828
|
return new CommitteeAttestationsAndSigners(attestations);
|
|
805
829
|
}
|
|
@@ -110,7 +110,7 @@ export class Sequencer extends (EventEmitter as new () => TypedEventEmitter<Sequ
|
|
|
110
110
|
/** Updates sequencer config by the defined values and updates the timetable */
|
|
111
111
|
public updateConfig(config: Partial<SequencerConfig>) {
|
|
112
112
|
const filteredConfig = pickFromSchema(config, SequencerConfigSchema);
|
|
113
|
-
this.log.info(`Updated sequencer config`, omit(filteredConfig, '
|
|
113
|
+
this.log.info(`Updated sequencer config`, omit(filteredConfig, 'txPublicSetupAllowListExtend'));
|
|
114
114
|
this.config = merge(this.config, filteredConfig);
|
|
115
115
|
this.timetable = new SequencerTimetable(
|
|
116
116
|
{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import {
|
|
3
3
|
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
4
|
CHECKPOINT_INITIALIZATION_TIME,
|
|
@@ -80,7 +80,7 @@ export class SequencerTimetable {
|
|
|
80
80
|
enforce: boolean;
|
|
81
81
|
},
|
|
82
82
|
private readonly metrics?: SequencerMetrics,
|
|
83
|
-
private readonly log
|
|
83
|
+
private readonly log?: Logger,
|
|
84
84
|
) {
|
|
85
85
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
86
86
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
@@ -132,7 +132,7 @@ export class SequencerTimetable {
|
|
|
132
132
|
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
133
133
|
this.initializeDeadline = initializeDeadline;
|
|
134
134
|
|
|
135
|
-
this.log
|
|
135
|
+
this.log?.info(
|
|
136
136
|
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
137
137
|
{
|
|
138
138
|
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
@@ -206,7 +206,7 @@ export class SequencerTimetable {
|
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
209
|
-
this.log
|
|
209
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
/**
|
|
@@ -242,7 +242,7 @@ export class SequencerTimetable {
|
|
|
242
242
|
const canStart = available >= this.minExecutionTime;
|
|
243
243
|
const deadline = secondsIntoSlot + available;
|
|
244
244
|
|
|
245
|
-
this.log
|
|
245
|
+
this.log?.verbose(
|
|
246
246
|
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
247
247
|
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
248
248
|
);
|
|
@@ -262,7 +262,7 @@ export class SequencerTimetable {
|
|
|
262
262
|
// Found an available sub-slot! Is this the last one?
|
|
263
263
|
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
264
264
|
|
|
265
|
-
this.log
|
|
265
|
+
this.log?.verbose(
|
|
266
266
|
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
267
267
|
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
268
268
|
);
|
|
@@ -272,7 +272,7 @@ export class SequencerTimetable {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
// No sub-slots available with enough time
|
|
275
|
-
this.log
|
|
275
|
+
this.log?.verbose(`No time left to start any more blocks`, {
|
|
276
276
|
secondsIntoSlot,
|
|
277
277
|
maxBlocks: this.maxNumberOfBlocks,
|
|
278
278
|
initializationOffset: this.initializationOffset,
|
package/src/sequencer/types.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
|
2
2
|
|
|
3
3
|
export type SequencerRollupConstants = Pick<
|
|
4
4
|
L1RollupConstants,
|
|
5
|
-
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
|
|
5
|
+
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit'
|
|
6
6
|
>;
|