@aztec/sequencer-client 5.0.0-private.20260319 → 5.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +281 -21
  2. package/dest/client/sequencer-client.d.ts +8 -3
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +17 -32
  5. package/dest/config.d.ts +10 -4
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +48 -24
  8. package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
  9. package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
  10. package/dest/global_variable_builder/fee_predictor.js +128 -0
  11. package/dest/global_variable_builder/fee_provider.d.ts +21 -0
  12. package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
  13. package/dest/global_variable_builder/fee_provider.js +67 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +14 -14
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +16 -51
  17. package/dest/global_variable_builder/index.d.ts +4 -2
  18. package/dest/global_variable_builder/index.d.ts.map +1 -1
  19. package/dest/global_variable_builder/index.js +2 -0
  20. package/dest/publisher/config.d.ts +15 -3
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +19 -4
  23. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
  24. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  25. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  26. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  27. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  28. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  29. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  30. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  31. package/dest/publisher/sequencer-publisher.d.ts +70 -64
  32. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  33. package/dest/publisher/sequencer-publisher.js +312 -533
  34. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  35. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  36. package/dest/sequencer/automine/automine_factory.js +85 -0
  37. package/dest/sequencer/automine/automine_sequencer.d.ts +184 -0
  38. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  39. package/dest/sequencer/automine/automine_sequencer.js +677 -0
  40. package/dest/sequencer/automine/index.d.ts +3 -0
  41. package/dest/sequencer/automine/index.d.ts.map +1 -0
  42. package/dest/sequencer/automine/index.js +2 -0
  43. package/dest/sequencer/chain_state_overrides.d.ts +61 -0
  44. package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
  45. package/dest/sequencer/chain_state_overrides.js +98 -0
  46. package/dest/sequencer/checkpoint_proposal_job.d.ts +73 -21
  47. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  48. package/dest/sequencer/checkpoint_proposal_job.js +709 -199
  49. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  50. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  51. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  52. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  53. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  54. package/dest/sequencer/checkpoint_voter.js +2 -5
  55. package/dest/sequencer/errors.d.ts +1 -8
  56. package/dest/sequencer/errors.d.ts.map +1 -1
  57. package/dest/sequencer/errors.js +0 -9
  58. package/dest/sequencer/events.d.ts +61 -4
  59. package/dest/sequencer/events.d.ts.map +1 -1
  60. package/dest/sequencer/metrics.d.ts +9 -10
  61. package/dest/sequencer/metrics.d.ts.map +1 -1
  62. package/dest/sequencer/metrics.js +34 -20
  63. package/dest/sequencer/sequencer.d.ts +112 -27
  64. package/dest/sequencer/sequencer.d.ts.map +1 -1
  65. package/dest/sequencer/sequencer.js +467 -147
  66. package/dest/sequencer/types.d.ts +2 -2
  67. package/dest/sequencer/types.d.ts.map +1 -1
  68. package/dest/test/index.d.ts +3 -3
  69. package/dest/test/index.d.ts.map +1 -1
  70. package/dest/test/utils.d.ts +15 -1
  71. package/dest/test/utils.d.ts.map +1 -1
  72. package/dest/test/utils.js +23 -6
  73. package/package.json +28 -27
  74. package/src/client/sequencer-client.ts +29 -41
  75. package/src/config.ts +57 -24
  76. package/src/global_variable_builder/README.md +44 -0
  77. package/src/global_variable_builder/fee_predictor.ts +172 -0
  78. package/src/global_variable_builder/fee_provider.ts +80 -0
  79. package/src/global_variable_builder/global_builder.ts +25 -63
  80. package/src/global_variable_builder/index.ts +3 -1
  81. package/src/publisher/config.ts +40 -6
  82. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
  83. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  84. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  85. package/src/publisher/sequencer-publisher.ts +368 -577
  86. package/src/sequencer/automine/README.md +60 -0
  87. package/src/sequencer/automine/automine_factory.ts +152 -0
  88. package/src/sequencer/automine/automine_sequencer.ts +783 -0
  89. package/src/sequencer/automine/index.ts +6 -0
  90. package/src/sequencer/chain_state_overrides.ts +169 -0
  91. package/src/sequencer/checkpoint_proposal_job.ts +818 -224
  92. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  93. package/src/sequencer/checkpoint_voter.ts +1 -12
  94. package/src/sequencer/errors.ts +0 -15
  95. package/src/sequencer/events.ts +65 -4
  96. package/src/sequencer/metrics.ts +43 -24
  97. package/src/sequencer/sequencer.ts +542 -164
  98. package/src/sequencer/types.ts +1 -1
  99. package/src/test/index.ts +2 -2
  100. package/src/test/utils.ts +59 -10
  101. package/dest/sequencer/timetable.d.ts +0 -88
  102. package/dest/sequencer/timetable.d.ts.map +0 -1
  103. package/dest/sequencer/timetable.js +0 -222
  104. package/src/sequencer/README.md +0 -531
  105. package/src/sequencer/timetable.ts +0 -283
@@ -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' | 'rollupManaLimit'
5
+ 'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
6
6
  >;
package/src/test/index.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
2
2
  import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
3
3
  import type { PublicProcessorFactory } from '@aztec/simulator/server';
4
+ import type { ProposerTimetable } from '@aztec/stdlib/timetable';
4
5
  import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
5
6
 
6
7
  import { SequencerClient } from '../client/sequencer-client.js';
7
8
  import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
8
9
  import { Sequencer } from '../sequencer/sequencer.js';
9
- import type { SequencerTimetable } from '../sequencer/timetable.js';
10
10
 
11
11
  class TestSequencer_ extends Sequencer {
12
12
  declare public publicProcessorFactory: PublicProcessorFactory;
13
- declare public timetable: SequencerTimetable;
13
+ declare public timetable: ProposerTimetable;
14
14
  declare public publisherFactory: SequencerPublisherFactory;
15
15
  declare public validatorClient: ValidatorClient;
16
16
  declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
package/src/test/utils.ts CHANGED
@@ -8,9 +8,22 @@ import { Signature } from '@aztec/foundation/eth-signature';
8
8
  import type { P2P } from '@aztec/p2p';
9
9
  import { PublicDataWrite } from '@aztec/stdlib/avm';
10
10
  import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
+ import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
12
+ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
11
13
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
14
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
- import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
15
+ import {
16
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
17
+ makeAppendOnlyTreeSnapshot,
18
+ mockTxForRollup,
19
+ } from '@aztec/stdlib/testing';
20
+ import {
21
+ DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
22
+ DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
23
+ DEFAULT_MIN_BLOCK_DURATION,
24
+ DEFAULT_P2P_PROPAGATION_TIME,
25
+ ProposerTimetable,
26
+ } from '@aztec/stdlib/timetable';
14
27
  import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
15
28
 
16
29
  import type { MockProxy } from 'jest-mock-extended';
@@ -18,6 +31,28 @@ import type { MockProxy } from 'jest-mock-extended';
18
31
  // Re-export mock classes from their dedicated file
19
32
  export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
20
33
 
34
+ /**
35
+ * Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
36
+ * filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
37
+ * the sequencer constructs its timetable so tests exercise the same budget resolution.
38
+ */
39
+ export function makeProposerTimetable(opts: {
40
+ l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
41
+ blockDurationMs?: number;
42
+ minBlockDuration?: number;
43
+ p2pPropagationTime?: number;
44
+ checkpointProposalPrepareTime?: number;
45
+ }): ProposerTimetable {
46
+ return new ProposerTimetable({
47
+ l1Constants: opts.l1Constants,
48
+ blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
49
+ minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
50
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
51
+ checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
52
+ checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
53
+ });
54
+ }
55
+
21
56
  /**
22
57
  * Creates a mock transaction with a specific seed for deterministic testing
23
58
  */
@@ -109,6 +144,7 @@ export function createBlockProposal(block: L2Block, signature: Signature): Block
109
144
  block.archive.root,
110
145
  txHashes,
111
146
  signature,
147
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
112
148
  );
113
149
  }
114
150
 
@@ -123,12 +159,19 @@ export function createCheckpointProposal(
123
159
  ): CheckpointProposal {
124
160
  const txHashes = block.body.txEffects.map(tx => tx.txHash);
125
161
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
126
- return new CheckpointProposal(checkpointHeader, block.archive.root, feeAssetPriceModifier, checkpointSignature, {
127
- blockHeader: block.header,
128
- indexWithinCheckpoint: block.indexWithinCheckpoint,
129
- txHashes,
130
- signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
131
- });
162
+ return new CheckpointProposal(
163
+ checkpointHeader,
164
+ block.archive.root,
165
+ feeAssetPriceModifier,
166
+ checkpointSignature,
167
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
168
+ {
169
+ blockHeader: block.header,
170
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
171
+ txHashes,
172
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
173
+ },
174
+ );
132
175
  }
133
176
 
134
177
  /**
@@ -143,10 +186,16 @@ export function createCheckpointAttestation(
143
186
  feeAssetPriceModifier: bigint = 0n,
144
187
  ): CheckpointAttestation {
145
188
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
146
- const payload = new ConsensusPayload(checkpointHeader, block.archive.root, feeAssetPriceModifier);
189
+ const payload = new ConsensusPayload(
190
+ checkpointHeader,
191
+ block.archive.root,
192
+ feeAssetPriceModifier,
193
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
194
+ );
147
195
  const attestation = new CheckpointAttestation(payload, signature, signature);
148
- // Set sender directly for testing (bypasses signature recovery)
149
- (attestation as any).sender = sender;
196
+ // Bypass signature recovery for testing since we use random signatures
197
+ (attestation as any).getSender = () => sender;
198
+ (attestation as any).getProposer = () => sender;
150
199
  return attestation;
151
200
  }
152
201
 
@@ -1,88 +0,0 @@
1
- import type { Logger } from '@aztec/foundation/log';
2
- import type { SequencerMetrics } from './metrics.js';
3
- import { SequencerState } from './utils.js';
4
- export declare class SequencerTimetable {
5
- private readonly metrics?;
6
- private readonly log?;
7
- /**
8
- * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
9
- * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
10
- * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
11
- */
12
- readonly initializeDeadline: number;
13
- /**
14
- * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
15
- * This is an estimate of how long initialization (sync + proposer check) typically takes.
16
- * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
17
- */
18
- readonly initializationOffset: number;
19
- /**
20
- * Total time needed to finalize and publish a checkpoint, including:
21
- * - Assembling the checkpoint
22
- * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
23
- * - Publishing to L1
24
- */
25
- readonly checkpointFinalizationTime: number;
26
- /**
27
- * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
28
- * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
29
- * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
30
- */
31
- readonly l1PublishingTime: number;
32
- /**
33
- * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
34
- * Defaults to half of the block duration if set, otherwise a constant.
35
- */
36
- readonly minExecutionTime: number;
37
- /** How long it takes to get ready to start building */
38
- readonly checkpointInitializationTime: number;
39
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
40
- readonly p2pPropagationTime: number;
41
- /** How much time we spend assembling a checkpoint after building the last block */
42
- readonly checkpointAssembleTime: number;
43
- /** Ethereum slot duration in seconds */
44
- readonly ethereumSlotDuration: number;
45
- /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
46
- readonly aztecSlotDuration: number;
47
- /** Whether assertTimeLeft will throw if not enough time. */
48
- readonly enforce: boolean;
49
- /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
50
- readonly blockDuration: number | undefined;
51
- /** Maximum number of blocks that can be built in this slot configuration */
52
- readonly maxNumberOfBlocks: number;
53
- constructor(opts: {
54
- ethereumSlotDuration: number;
55
- aztecSlotDuration: number;
56
- l1PublishingTime: number;
57
- p2pPropagationTime?: number;
58
- blockDurationMs?: number;
59
- enforce: boolean;
60
- }, metrics?: SequencerMetrics | undefined, log?: Logger | undefined);
61
- getMaxAllowedTime(state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): undefined;
62
- getMaxAllowedTime(state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): number;
63
- getMaxAllowedTime(state: SequencerState): number | undefined;
64
- assertTimeLeft(newState: SequencerState, secondsIntoSlot: number): void;
65
- /**
66
- * Determines if we can start building the next block and returns its deadline.
67
- *
68
- * The timetable divides the slot into fixed sub-slots. This method finds the next
69
- * available sub-slot that has enough time remaining to build a block.
70
- *
71
- * @param secondsIntoSlot - Current time (seconds into the slot)
72
- * @returns Object with canStart flag, deadline, and whether this is the last block
73
- */
74
- canStartNextBlock(secondsIntoSlot: number): {
75
- canStart: true;
76
- deadline: undefined;
77
- isLastBlock: true;
78
- } | {
79
- canStart: false;
80
- deadline: undefined;
81
- isLastBlock: false;
82
- } | {
83
- canStart: boolean;
84
- deadline: number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ACI,iBAAiB,CACtB,eAAe,EAAE,MAAM,GAErB;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,IAAI,CAAA;KAAE,GAC1D;QAAE,QAAQ,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,KAAK,CAAA;KAAE,GAC5D;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAwDhE;CACF"}
@@ -1,222 +0,0 @@
1
- import { CHECKPOINT_ASSEMBLE_TIME, CHECKPOINT_INITIALIZATION_TIME, DEFAULT_P2P_PROPAGATION_TIME, MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
2
- import { SequencerTooSlowError } from './errors.js';
3
- import { SequencerState } from './utils.js';
4
- export class SequencerTimetable {
5
- metrics;
6
- log;
7
- /**
8
- * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
9
- * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
10
- * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
11
- */ initializeDeadline;
12
- /**
13
- * Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
14
- * This is an estimate of how long initialization (sync + proposer check) typically takes.
15
- * If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
16
- */ initializationOffset;
17
- /**
18
- * Total time needed to finalize and publish a checkpoint, including:
19
- * - Assembling the checkpoint
20
- * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
21
- * - Publishing to L1
22
- */ checkpointFinalizationTime;
23
- /**
24
- * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
25
- * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
26
- * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
27
- */ l1PublishingTime;
28
- /**
29
- * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
30
- * Defaults to half of the block duration if set, otherwise a constant.
31
- */ minExecutionTime;
32
- /** How long it takes to get ready to start building */ checkpointInitializationTime;
33
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */ p2pPropagationTime;
34
- /** How much time we spend assembling a checkpoint after building the last block */ checkpointAssembleTime;
35
- /** Ethereum slot duration in seconds */ ethereumSlotDuration;
36
- /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */ aztecSlotDuration;
37
- /** Whether assertTimeLeft will throw if not enough time. */ enforce;
38
- /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */ blockDuration;
39
- /** Maximum number of blocks that can be built in this slot configuration */ maxNumberOfBlocks;
40
- constructor(opts, metrics, log){
41
- this.metrics = metrics;
42
- this.log = log;
43
- this.minExecutionTime = MIN_EXECUTION_TIME;
44
- this.checkpointInitializationTime = CHECKPOINT_INITIALIZATION_TIME;
45
- this.checkpointAssembleTime = CHECKPOINT_ASSEMBLE_TIME;
46
- this.ethereumSlotDuration = opts.ethereumSlotDuration;
47
- this.aztecSlotDuration = opts.aztecSlotDuration;
48
- this.l1PublishingTime = opts.l1PublishingTime;
49
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
50
- this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
51
- this.enforce = opts.enforce;
52
- // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
53
- if (this.ethereumSlotDuration < 8) {
54
- this.p2pPropagationTime = 0;
55
- this.checkpointAssembleTime = 0.5;
56
- this.checkpointInitializationTime = 0.5;
57
- this.minExecutionTime = 1;
58
- }
59
- // Min execution time cannot be less than the block duration if set
60
- if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
61
- this.minExecutionTime = this.blockDuration;
62
- }
63
- // Calculate initialization offset - estimate of time needed for sync + proposer check
64
- // This is the baseline for all sub-slot deadlines
65
- this.initializationOffset = this.checkpointInitializationTime;
66
- // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
67
- this.checkpointFinalizationTime = this.checkpointAssembleTime + this.p2pPropagationTime * 2 + // Round-trip propagation
68
- this.l1PublishingTime; // L1 publishing
69
- // Calculate maximum number of blocks that fit in this slot
70
- if (!this.blockDuration) {
71
- this.maxNumberOfBlocks = 1; // Single block per slot
72
- } else {
73
- const timeReservedAtEnd = this.blockDuration + // Last sub-slot for validator re-execution
74
- this.checkpointFinalizationTime; // Checkpoint finalization
75
- const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
76
- this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
77
- }
78
- // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
79
- const minWorkToDo = this.initializationOffset + this.minExecutionTime * 2 + // Execution and reexecution
80
- this.checkpointFinalizationTime;
81
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
82
- this.initializeDeadline = initializeDeadline;
83
- this.log?.info(`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`, {
84
- ethereumSlotDuration: this.ethereumSlotDuration,
85
- aztecSlotDuration: this.aztecSlotDuration,
86
- l1PublishingTime: this.l1PublishingTime,
87
- minExecutionTime: this.minExecutionTime,
88
- blockPrepareTime: this.checkpointInitializationTime,
89
- p2pPropagationTime: this.p2pPropagationTime,
90
- blockAssembleTime: this.checkpointAssembleTime,
91
- initializeDeadline: this.initializeDeadline,
92
- enforce: this.enforce,
93
- minWorkToDo,
94
- blockDuration: this.blockDuration,
95
- maxNumberOfBlocks: this.maxNumberOfBlocks
96
- });
97
- if (initializeDeadline <= 0) {
98
- throw new Error(`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`);
99
- }
100
- }
101
- getMaxAllowedTime(state) {
102
- switch(state){
103
- case SequencerState.STOPPED:
104
- case SequencerState.STOPPING:
105
- case SequencerState.IDLE:
106
- case SequencerState.SYNCHRONIZING:
107
- return; // We don't really care about times for this states
108
- case SequencerState.PROPOSER_CHECK:
109
- case SequencerState.INITIALIZING_CHECKPOINT:
110
- return this.initializeDeadline;
111
- case SequencerState.WAITING_FOR_TXS:
112
- case SequencerState.CREATING_BLOCK:
113
- case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
114
- return this.initializeDeadline + this.checkpointInitializationTime;
115
- case SequencerState.ASSEMBLING_CHECKPOINT:
116
- case SequencerState.COLLECTING_ATTESTATIONS:
117
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
118
- case SequencerState.PUBLISHING_CHECKPOINT:
119
- return this.aztecSlotDuration - this.l1PublishingTime;
120
- default:
121
- {
122
- const _exhaustiveCheck = state;
123
- throw new Error(`Unexpected state: ${state}`);
124
- }
125
- }
126
- }
127
- assertTimeLeft(newState, secondsIntoSlot) {
128
- if (!this.enforce) {
129
- return;
130
- }
131
- const maxAllowedTime = this.getMaxAllowedTime(newState);
132
- if (maxAllowedTime === undefined) {
133
- return;
134
- }
135
- const bufferSeconds = maxAllowedTime - secondsIntoSlot;
136
- if (bufferSeconds < 0) {
137
- throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
138
- }
139
- this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
140
- this.log?.trace(`Enough time to transition to ${newState}`, {
141
- maxAllowedTime,
142
- secondsIntoSlot
143
- });
144
- }
145
- /**
146
- * Determines if we can start building the next block and returns its deadline.
147
- *
148
- * The timetable divides the slot into fixed sub-slots. This method finds the next
149
- * available sub-slot that has enough time remaining to build a block.
150
- *
151
- * @param secondsIntoSlot - Current time (seconds into the slot)
152
- * @returns Object with canStart flag, deadline, and whether this is the last block
153
- */ canStartNextBlock(secondsIntoSlot) {
154
- // When timetable enforcement is disabled, always allow starting,
155
- // and build a single block with no deadline. This is here just to
156
- // satisfy a subset of e2e tests and the sandbox that assume that the
157
- // sequencer is permanently mining every tx sent.
158
- if (!this.enforce) {
159
- return {
160
- canStart: true,
161
- deadline: undefined,
162
- isLastBlock: true
163
- };
164
- }
165
- // If no block duration is set, then we're in single-block mode, which
166
- // is handled for backwards compatibility towards another subset of e2e tests.
167
- if (this.blockDuration === undefined) {
168
- // In single block mode, execution and re-execution happen sequentially, so we need to
169
- // split the available time between them. After building, we need time for attestations and L1.
170
- const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
171
- const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
172
- const canStart = available >= this.minExecutionTime;
173
- const deadline = secondsIntoSlot + available;
174
- this.log?.verbose(`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`, {
175
- secondsIntoSlot,
176
- maxAllowed,
177
- available,
178
- deadline
179
- });
180
- return {
181
- canStart,
182
- deadline,
183
- isLastBlock: true
184
- };
185
- }
186
- // Otherwise, we're in multi-block-per-slot mode, the default when running in production
187
- // Find the next available sub-slot that has enough time remaining
188
- for(let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++){
189
- // Calculate end for this sub-slot
190
- const deadline = this.initializationOffset + subSlot * this.blockDuration;
191
- // Check if we have enough time to build a block with this deadline
192
- const timeUntilDeadline = deadline - secondsIntoSlot;
193
- if (timeUntilDeadline >= this.minExecutionTime) {
194
- // Found an available sub-slot! Is this the last one?
195
- const isLastBlock = subSlot === this.maxNumberOfBlocks;
196
- this.log?.verbose(`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`, {
197
- secondsIntoSlot,
198
- deadline,
199
- timeUntilDeadline,
200
- subSlot,
201
- maxBlocks: this.maxNumberOfBlocks
202
- });
203
- return {
204
- canStart: true,
205
- deadline,
206
- isLastBlock
207
- };
208
- }
209
- }
210
- // No sub-slots available with enough time
211
- this.log?.verbose(`No time left to start any more blocks`, {
212
- secondsIntoSlot,
213
- maxBlocks: this.maxNumberOfBlocks,
214
- initializationOffset: this.initializationOffset
215
- });
216
- return {
217
- canStart: false,
218
- deadline: undefined,
219
- isLastBlock: false
220
- };
221
- }
222
- }