@aztec/sequencer-client 0.0.1-commit.b6e433891 → 0.0.1-commit.b9865e97

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 (102) 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 -23
  5. package/dest/config.d.ts +6 -3
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +35 -15
  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 +58 -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/index.d.ts +2 -2
  21. package/dest/index.d.ts.map +1 -1
  22. package/dest/index.js +1 -1
  23. package/dest/publisher/config.d.ts +15 -3
  24. package/dest/publisher/config.d.ts.map +1 -1
  25. package/dest/publisher/config.js +19 -4
  26. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
  27. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
  28. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  29. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  30. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  31. package/dest/publisher/sequencer-publisher-factory.d.ts +3 -5
  32. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  33. package/dest/publisher/sequencer-publisher-factory.js +2 -3
  34. package/dest/publisher/sequencer-publisher.d.ts +70 -64
  35. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  36. package/dest/publisher/sequencer-publisher.js +312 -533
  37. package/dest/sequencer/automine/automine_factory.d.ts +54 -0
  38. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  39. package/dest/sequencer/automine/automine_factory.js +84 -0
  40. package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
  41. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  42. package/dest/sequencer/automine/automine_sequencer.js +509 -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 +55 -13
  47. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  48. package/dest/sequencer/checkpoint_proposal_job.js +668 -164
  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/events.d.ts +47 -2
  56. package/dest/sequencer/events.d.ts.map +1 -1
  57. package/dest/sequencer/index.d.ts +3 -1
  58. package/dest/sequencer/index.d.ts.map +1 -1
  59. package/dest/sequencer/index.js +2 -0
  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 +59 -11
  64. package/dest/sequencer/sequencer.d.ts.map +1 -1
  65. package/dest/sequencer/sequencer.js +304 -74
  66. package/dest/sequencer/timetable.d.ts +11 -1
  67. package/dest/sequencer/timetable.d.ts.map +1 -1
  68. package/dest/sequencer/timetable.js +41 -36
  69. package/dest/sequencer/types.d.ts +2 -2
  70. package/dest/sequencer/types.d.ts.map +1 -1
  71. package/dest/test/utils.d.ts +1 -1
  72. package/dest/test/utils.d.ts.map +1 -1
  73. package/dest/test/utils.js +7 -6
  74. package/package.json +27 -27
  75. package/src/client/sequencer-client.ts +28 -31
  76. package/src/config.ts +40 -15
  77. package/src/global_variable_builder/README.md +44 -0
  78. package/src/global_variable_builder/fee_predictor.ts +172 -0
  79. package/src/global_variable_builder/fee_provider.ts +75 -0
  80. package/src/global_variable_builder/global_builder.ts +25 -63
  81. package/src/global_variable_builder/index.ts +3 -1
  82. package/src/index.ts +10 -1
  83. package/src/publisher/config.ts +40 -6
  84. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
  85. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  86. package/src/publisher/sequencer-publisher-factory.ts +3 -6
  87. package/src/publisher/sequencer-publisher.ts +368 -577
  88. package/src/sequencer/README.md +162 -450
  89. package/src/sequencer/automine/README.md +46 -0
  90. package/src/sequencer/automine/automine_factory.ts +145 -0
  91. package/src/sequencer/automine/automine_sequencer.ts +595 -0
  92. package/src/sequencer/chain_state_overrides.ts +162 -0
  93. package/src/sequencer/checkpoint_proposal_job.ts +769 -185
  94. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  95. package/src/sequencer/checkpoint_voter.ts +1 -12
  96. package/src/sequencer/events.ts +51 -2
  97. package/src/sequencer/index.ts +2 -0
  98. package/src/sequencer/metrics.ts +43 -24
  99. package/src/sequencer/sequencer.ts +360 -83
  100. package/src/sequencer/timetable.ts +49 -44
  101. package/src/sequencer/types.ts +1 -1
  102. package/src/test/utils.ts +28 -10
@@ -2,8 +2,10 @@ import type { Logger } from '@aztec/foundation/log';
2
2
  import {
3
3
  CHECKPOINT_ASSEMBLE_TIME,
4
4
  CHECKPOINT_INITIALIZATION_TIME,
5
+ type CheckpointTiming,
5
6
  DEFAULT_P2P_PROPAGATION_TIME,
6
7
  MIN_EXECUTION_TIME,
8
+ createCheckpointTimingModel,
7
9
  } from '@aztec/stdlib/timetable';
8
10
 
9
11
  import { SequencerTooSlowError } from './errors.js';
@@ -11,6 +13,8 @@ import type { SequencerMetrics } from './metrics.js';
11
13
  import { SequencerState } from './utils.js';
12
14
 
13
15
  export class SequencerTimetable {
16
+ private readonly checkpointTiming: CheckpointTiming;
17
+
14
18
  /**
15
19
  * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
16
20
  * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
@@ -70,6 +74,12 @@ export class SequencerTimetable {
70
74
  /** Maximum number of blocks that can be built in this slot configuration */
71
75
  public readonly maxNumberOfBlocks: number;
72
76
 
77
+ /**
78
+ * How far into the target slot assembly and attestation collection can start when pipelining.
79
+ * Production-like timing keeps this at zero; fast local publishing profiles can use the attestation window.
80
+ */
81
+ public readonly pipeliningAttestationGracePeriod: number;
82
+
73
83
  constructor(
74
84
  opts: {
75
85
  ethereumSlotDuration: number;
@@ -85,52 +95,29 @@ export class SequencerTimetable {
85
95
  this.ethereumSlotDuration = opts.ethereumSlotDuration;
86
96
  this.aztecSlotDuration = opts.aztecSlotDuration;
87
97
  this.l1PublishingTime = opts.l1PublishingTime;
88
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
89
98
  this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
90
99
  this.enforce = opts.enforce;
91
100
 
92
- // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
93
- if (this.ethereumSlotDuration < 8) {
94
- this.p2pPropagationTime = 0;
95
- this.checkpointAssembleTime = 0.5;
96
- this.checkpointInitializationTime = 0.5;
97
- this.minExecutionTime = 1;
98
- }
101
+ this.checkpointTiming = createCheckpointTimingModel({
102
+ aztecSlotDuration: this.aztecSlotDuration,
103
+ ethereumSlotDuration: this.ethereumSlotDuration,
104
+ blockDuration: this.blockDuration,
105
+ l1PublishingTime: this.l1PublishingTime,
106
+ p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
107
+ });
99
108
 
100
- // Min execution time cannot be less than the block duration if set
101
- if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
102
- this.minExecutionTime = this.blockDuration;
103
- }
109
+ this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
110
+ this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
111
+ this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
112
+ this.minExecutionTime = this.checkpointTiming.minExecutionTime;
104
113
 
105
114
  // Calculate initialization offset - estimate of time needed for sync + proposer check
106
115
  // This is the baseline for all sub-slot deadlines
107
- this.initializationOffset = this.checkpointInitializationTime;
108
-
109
- // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
110
- this.checkpointFinalizationTime =
111
- this.checkpointAssembleTime +
112
- this.p2pPropagationTime * 2 + // Round-trip propagation
113
- this.l1PublishingTime; // L1 publishing
114
-
115
- // Calculate maximum number of blocks that fit in this slot
116
- if (!this.blockDuration) {
117
- this.maxNumberOfBlocks = 1; // Single block per slot
118
- } else {
119
- const timeReservedAtEnd =
120
- this.blockDuration + // Last sub-slot for validator re-execution
121
- this.checkpointFinalizationTime; // Checkpoint finalization
122
- const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
123
- this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
124
- }
125
-
126
- // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
127
- const minWorkToDo =
128
- this.initializationOffset +
129
- this.minExecutionTime * 2 + // Execution and reexecution
130
- this.checkpointFinalizationTime;
131
-
132
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
133
- this.initializeDeadline = initializeDeadline;
116
+ this.initializationOffset = this.checkpointTiming.checkpointInitializationTime;
117
+ this.checkpointFinalizationTime = this.checkpointTiming.checkpointFinalizationTime;
118
+ this.pipeliningAttestationGracePeriod = this.checkpointTiming.pipeliningAttestationGracePeriod;
119
+ this.maxNumberOfBlocks = this.checkpointTiming.calculateMaxBlocksPerSlot();
120
+ this.initializeDeadline = this.checkpointTiming.initializeDeadline;
134
121
 
135
122
  this.log?.info(
136
123
  `Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
@@ -144,19 +131,36 @@ export class SequencerTimetable {
144
131
  blockAssembleTime: this.checkpointAssembleTime,
145
132
  initializeDeadline: this.initializeDeadline,
146
133
  enforce: this.enforce,
147
- minWorkToDo,
134
+ pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
135
+ minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
148
136
  blockDuration: this.blockDuration,
149
137
  maxNumberOfBlocks: this.maxNumberOfBlocks,
150
138
  },
151
139
  );
152
140
 
153
- if (initializeDeadline <= 0) {
141
+ if (this.initializeDeadline <= 0) {
154
142
  throw new Error(
155
- `Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`,
143
+ `Block proposal initialize deadline cannot be negative (got ${this.initializeDeadline} from total time needed ${this.checkpointTiming.minimumBuildSlotWork} and a slot duration of ${this.aztecSlotDuration}).`,
156
144
  );
157
145
  }
158
146
  }
159
147
 
148
+ public getCheckpointAssemblyDeadline(): number {
149
+ return this.checkpointTiming.checkpointAssemblyDeadline;
150
+ }
151
+
152
+ public getCheckpointAttestationDeadline(): number {
153
+ return this.checkpointTiming.checkpointAttestationDeadline;
154
+ }
155
+
156
+ public getCheckpointAttestationStartDeadline(): number {
157
+ return this.checkpointTiming.checkpointAttestationStartDeadline;
158
+ }
159
+
160
+ public getCheckpointPublishingDeadline(): number {
161
+ return this.checkpointTiming.checkpointPublishingDeadline;
162
+ }
163
+
160
164
  public getMaxAllowedTime(
161
165
  state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
162
166
  ): undefined;
@@ -179,10 +183,11 @@ export class SequencerTimetable {
179
183
  case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
180
184
  return this.initializeDeadline + this.checkpointInitializationTime;
181
185
  case SequencerState.ASSEMBLING_CHECKPOINT:
186
+ return this.getCheckpointAssemblyDeadline();
182
187
  case SequencerState.COLLECTING_ATTESTATIONS:
183
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
188
+ return this.getCheckpointAttestationStartDeadline();
184
189
  case SequencerState.PUBLISHING_CHECKPOINT:
185
- return this.aztecSlotDuration - this.l1PublishingTime;
190
+ return this.getCheckpointPublishingDeadline();
186
191
  default: {
187
192
  const _exhaustiveCheck: never = state;
188
193
  throw new Error(`Unexpected state: ${state}`);
@@ -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/utils.ts CHANGED
@@ -10,7 +10,11 @@ import { PublicDataWrite } from '@aztec/stdlib/avm';
10
10
  import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
11
11
  import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
12
12
  import { CheckpointHeader } from '@aztec/stdlib/rollup';
13
- import { makeAppendOnlyTreeSnapshot, mockTxForRollup } from '@aztec/stdlib/testing';
13
+ import {
14
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
15
+ makeAppendOnlyTreeSnapshot,
16
+ mockTxForRollup,
17
+ } from '@aztec/stdlib/testing';
14
18
  import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
15
19
 
16
20
  import type { MockProxy } from 'jest-mock-extended';
@@ -109,6 +113,7 @@ export function createBlockProposal(block: L2Block, signature: Signature): Block
109
113
  block.archive.root,
110
114
  txHashes,
111
115
  signature,
116
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
112
117
  );
113
118
  }
114
119
 
@@ -123,12 +128,19 @@ export function createCheckpointProposal(
123
128
  ): CheckpointProposal {
124
129
  const txHashes = block.body.txEffects.map(tx => tx.txHash);
125
130
  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
- });
131
+ return new CheckpointProposal(
132
+ checkpointHeader,
133
+ block.archive.root,
134
+ feeAssetPriceModifier,
135
+ checkpointSignature,
136
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
137
+ {
138
+ blockHeader: block.header,
139
+ indexWithinCheckpoint: block.indexWithinCheckpoint,
140
+ txHashes,
141
+ signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
142
+ },
143
+ );
132
144
  }
133
145
 
134
146
  /**
@@ -143,10 +155,16 @@ export function createCheckpointAttestation(
143
155
  feeAssetPriceModifier: bigint = 0n,
144
156
  ): CheckpointAttestation {
145
157
  const checkpointHeader = createCheckpointHeaderFromBlock(block);
146
- const payload = new ConsensusPayload(checkpointHeader, block.archive.root, feeAssetPriceModifier);
158
+ const payload = new ConsensusPayload(
159
+ checkpointHeader,
160
+ block.archive.root,
161
+ feeAssetPriceModifier,
162
+ TEST_COORDINATION_SIGNATURE_CONTEXT,
163
+ );
147
164
  const attestation = new CheckpointAttestation(payload, signature, signature);
148
- // Set sender directly for testing (bypasses signature recovery)
149
- (attestation as any).sender = sender;
165
+ // Bypass signature recovery for testing since we use random signatures
166
+ (attestation as any).getSender = () => sender;
167
+ (attestation as any).getProposer = () => sender;
150
168
  return attestation;
151
169
  }
152
170