@aztec/sequencer-client 0.0.1-commit.f2ce05ee → 0.0.1-commit.f5a9928

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 (133) hide show
  1. package/README.md +283 -21
  2. package/dest/client/sequencer-client.d.ts +34 -11
  3. package/dest/client/sequencer-client.d.ts.map +1 -1
  4. package/dest/client/sequencer-client.js +77 -39
  5. package/dest/config.d.ts +34 -5
  6. package/dest/config.d.ts.map +1 -1
  7. package/dest/config.js +103 -39
  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 +138 -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 +80 -0
  14. package/dest/global_variable_builder/global_builder.d.ts +13 -28
  15. package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
  16. package/dest/global_variable_builder/global_builder.js +9 -66
  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 +51 -17
  21. package/dest/publisher/config.d.ts.map +1 -1
  22. package/dest/publisher/config.js +131 -42
  23. package/dest/publisher/index.d.ts +2 -1
  24. package/dest/publisher/index.d.ts.map +1 -1
  25. package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
  26. package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
  27. package/dest/publisher/l1_to_l2_messaging.js +70 -0
  28. package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
  29. package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
  30. package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
  31. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
  32. package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
  33. package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
  34. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
  35. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
  36. package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
  37. package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
  38. package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
  39. package/dest/publisher/l1_tx_failed_store/index.js +2 -0
  40. package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
  41. package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
  42. package/dest/publisher/sequencer-bundle-simulator.js +198 -0
  43. package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
  44. package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
  45. package/dest/publisher/sequencer-publisher-factory.js +27 -3
  46. package/dest/publisher/sequencer-publisher.d.ts +112 -71
  47. package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
  48. package/dest/publisher/sequencer-publisher.js +571 -392
  49. package/dest/publisher/write_json.d.ts +11 -0
  50. package/dest/publisher/write_json.d.ts.map +1 -0
  51. package/dest/publisher/write_json.js +57 -0
  52. package/dest/sequencer/automine/automine_factory.d.ts +56 -0
  53. package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
  54. package/dest/sequencer/automine/automine_factory.js +85 -0
  55. package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
  56. package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
  57. package/dest/sequencer/automine/automine_sequencer.js +696 -0
  58. package/dest/sequencer/automine/index.d.ts +3 -0
  59. package/dest/sequencer/automine/index.d.ts.map +1 -0
  60. package/dest/sequencer/automine/index.js +2 -0
  61. package/dest/sequencer/checkpoint_proposal_job.d.ts +75 -19
  62. package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
  63. package/dest/sequencer/checkpoint_proposal_job.js +886 -264
  64. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
  65. package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
  66. package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
  67. package/dest/sequencer/checkpoint_voter.d.ts +1 -2
  68. package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
  69. package/dest/sequencer/checkpoint_voter.js +2 -5
  70. package/dest/sequencer/errors.d.ts +1 -8
  71. package/dest/sequencer/errors.d.ts.map +1 -1
  72. package/dest/sequencer/errors.js +0 -9
  73. package/dest/sequencer/events.d.ts +62 -5
  74. package/dest/sequencer/events.d.ts.map +1 -1
  75. package/dest/sequencer/metrics.d.ts +23 -8
  76. package/dest/sequencer/metrics.d.ts.map +1 -1
  77. package/dest/sequencer/metrics.js +117 -21
  78. package/dest/sequencer/requests_tracker.d.ts +22 -0
  79. package/dest/sequencer/requests_tracker.d.ts.map +1 -0
  80. package/dest/sequencer/requests_tracker.js +33 -0
  81. package/dest/sequencer/sequencer.d.ts +181 -44
  82. package/dest/sequencer/sequencer.d.ts.map +1 -1
  83. package/dest/sequencer/sequencer.js +635 -218
  84. package/dest/sequencer/types.d.ts +2 -2
  85. package/dest/sequencer/types.d.ts.map +1 -1
  86. package/dest/test/index.d.ts +5 -7
  87. package/dest/test/index.d.ts.map +1 -1
  88. package/dest/test/mock_checkpoint_builder.d.ts +11 -11
  89. package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
  90. package/dest/test/mock_checkpoint_builder.js +45 -34
  91. package/dest/test/utils.d.ts +17 -3
  92. package/dest/test/utils.d.ts.map +1 -1
  93. package/dest/test/utils.js +28 -9
  94. package/package.json +28 -28
  95. package/src/client/sequencer-client.ts +110 -47
  96. package/src/config.ts +126 -44
  97. package/src/global_variable_builder/README.md +44 -0
  98. package/src/global_variable_builder/fee_predictor.ts +182 -0
  99. package/src/global_variable_builder/fee_provider.ts +97 -0
  100. package/src/global_variable_builder/global_builder.ts +20 -89
  101. package/src/global_variable_builder/index.ts +3 -1
  102. package/src/publisher/config.ts +173 -40
  103. package/src/publisher/index.ts +3 -0
  104. package/src/publisher/l1_to_l2_messaging.ts +85 -0
  105. package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
  106. package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
  107. package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
  108. package/src/publisher/l1_tx_failed_store/index.ts +3 -0
  109. package/src/publisher/sequencer-bundle-simulator.ts +254 -0
  110. package/src/publisher/sequencer-publisher-factory.ts +38 -9
  111. package/src/publisher/sequencer-publisher.ts +667 -484
  112. package/src/publisher/write_json.ts +78 -0
  113. package/src/sequencer/automine/README.md +60 -0
  114. package/src/sequencer/automine/automine_factory.ts +152 -0
  115. package/src/sequencer/automine/automine_sequencer.ts +800 -0
  116. package/src/sequencer/automine/index.ts +6 -0
  117. package/src/sequencer/checkpoint_proposal_job.ts +1073 -290
  118. package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
  119. package/src/sequencer/checkpoint_voter.ts +1 -12
  120. package/src/sequencer/errors.ts +0 -15
  121. package/src/sequencer/events.ts +66 -5
  122. package/src/sequencer/metrics.ts +138 -26
  123. package/src/sequencer/requests_tracker.ts +43 -0
  124. package/src/sequencer/sequencer.ts +745 -243
  125. package/src/sequencer/types.ts +1 -1
  126. package/src/test/index.ts +4 -6
  127. package/src/test/mock_checkpoint_builder.ts +63 -49
  128. package/src/test/utils.ts +64 -10
  129. package/dest/sequencer/timetable.d.ts +0 -87
  130. package/dest/sequencer/timetable.d.ts.map +0 -1
  131. package/dest/sequencer/timetable.js +0 -223
  132. package/src/sequencer/README.md +0 -531
  133. package/src/sequencer/timetable.ts +0 -283
@@ -1,223 +0,0 @@
1
- import { createLogger } from '@aztec/aztec.js/log';
2
- import { CHECKPOINT_ASSEMBLE_TIME, CHECKPOINT_INITIALIZATION_TIME, DEFAULT_P2P_PROPAGATION_TIME, MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
3
- import { SequencerTooSlowError } from './errors.js';
4
- import { SequencerState } from './utils.js';
5
- export class SequencerTimetable {
6
- metrics;
7
- log;
8
- /**
9
- * How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
10
- * assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
11
- * starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
12
- */ initializeDeadline;
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
- */ initializationOffset;
18
- /**
19
- * Total time needed to finalize and publish a checkpoint, including:
20
- * - Assembling the checkpoint
21
- * - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
22
- * - Publishing to L1
23
- */ checkpointFinalizationTime;
24
- /**
25
- * How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
26
- * but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
27
- * we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
28
- */ l1PublishingTime;
29
- /**
30
- * What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
31
- * Defaults to half of the block duration if set, otherwise a constant.
32
- */ minExecutionTime;
33
- /** How long it takes to get ready to start building */ checkpointInitializationTime;
34
- /** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */ p2pPropagationTime;
35
- /** How much time we spend assembling a checkpoint after building the last block */ checkpointAssembleTime;
36
- /** Ethereum slot duration in seconds */ ethereumSlotDuration;
37
- /** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */ aztecSlotDuration;
38
- /** Whether assertTimeLeft will throw if not enough time. */ enforce;
39
- /** Duration per block when building multiple blocks per slot (undefined = single block per slot) */ blockDuration;
40
- /** Maximum number of blocks that can be built in this slot configuration */ maxNumberOfBlocks;
41
- constructor(opts, metrics, log = createLogger('sequencer:timetable')){
42
- this.metrics = metrics;
43
- this.log = log;
44
- this.minExecutionTime = MIN_EXECUTION_TIME;
45
- this.checkpointInitializationTime = CHECKPOINT_INITIALIZATION_TIME;
46
- this.checkpointAssembleTime = CHECKPOINT_ASSEMBLE_TIME;
47
- this.ethereumSlotDuration = opts.ethereumSlotDuration;
48
- this.aztecSlotDuration = opts.aztecSlotDuration;
49
- this.l1PublishingTime = opts.l1PublishingTime;
50
- this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
51
- this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
52
- this.enforce = opts.enforce;
53
- // Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
54
- if (this.ethereumSlotDuration < 8) {
55
- this.p2pPropagationTime = 0;
56
- this.checkpointAssembleTime = 0.5;
57
- this.checkpointInitializationTime = 0.5;
58
- this.minExecutionTime = 1;
59
- }
60
- // Min execution time cannot be less than the block duration if set
61
- if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
62
- this.minExecutionTime = this.blockDuration;
63
- }
64
- // Calculate initialization offset - estimate of time needed for sync + proposer check
65
- // This is the baseline for all sub-slot deadlines
66
- this.initializationOffset = this.checkpointInitializationTime;
67
- // Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
68
- this.checkpointFinalizationTime = this.checkpointAssembleTime + this.p2pPropagationTime * 2 + // Round-trip propagation
69
- this.l1PublishingTime; // L1 publishing
70
- // Calculate maximum number of blocks that fit in this slot
71
- if (!this.blockDuration) {
72
- this.maxNumberOfBlocks = 1; // Single block per slot
73
- } else {
74
- const timeReservedAtEnd = this.blockDuration + // Last sub-slot for validator re-execution
75
- this.checkpointFinalizationTime; // Checkpoint finalization
76
- const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
77
- this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
78
- }
79
- // Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
80
- const minWorkToDo = this.initializationOffset + this.minExecutionTime * 2 + // Execution and reexecution
81
- this.checkpointFinalizationTime;
82
- const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
83
- this.initializeDeadline = initializeDeadline;
84
- this.log.verbose(`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`, {
85
- ethereumSlotDuration: this.ethereumSlotDuration,
86
- aztecSlotDuration: this.aztecSlotDuration,
87
- l1PublishingTime: this.l1PublishingTime,
88
- minExecutionTime: this.minExecutionTime,
89
- blockPrepareTime: this.checkpointInitializationTime,
90
- p2pPropagationTime: this.p2pPropagationTime,
91
- blockAssembleTime: this.checkpointAssembleTime,
92
- initializeDeadline: this.initializeDeadline,
93
- enforce: this.enforce,
94
- minWorkToDo,
95
- blockDuration: this.blockDuration,
96
- maxNumberOfBlocks: this.maxNumberOfBlocks
97
- });
98
- if (initializeDeadline <= 0) {
99
- throw new Error(`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`);
100
- }
101
- }
102
- getMaxAllowedTime(state) {
103
- switch(state){
104
- case SequencerState.STOPPED:
105
- case SequencerState.STOPPING:
106
- case SequencerState.IDLE:
107
- case SequencerState.SYNCHRONIZING:
108
- return; // We don't really care about times for this states
109
- case SequencerState.PROPOSER_CHECK:
110
- case SequencerState.INITIALIZING_CHECKPOINT:
111
- return this.initializeDeadline;
112
- case SequencerState.WAITING_FOR_TXS:
113
- case SequencerState.CREATING_BLOCK:
114
- case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
115
- return this.initializeDeadline + this.checkpointInitializationTime;
116
- case SequencerState.ASSEMBLING_CHECKPOINT:
117
- case SequencerState.COLLECTING_ATTESTATIONS:
118
- return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
119
- case SequencerState.PUBLISHING_CHECKPOINT:
120
- return this.aztecSlotDuration - this.l1PublishingTime;
121
- default:
122
- {
123
- const _exhaustiveCheck = state;
124
- throw new Error(`Unexpected state: ${state}`);
125
- }
126
- }
127
- }
128
- assertTimeLeft(newState, secondsIntoSlot) {
129
- if (!this.enforce) {
130
- return;
131
- }
132
- const maxAllowedTime = this.getMaxAllowedTime(newState);
133
- if (maxAllowedTime === undefined) {
134
- return;
135
- }
136
- const bufferSeconds = maxAllowedTime - secondsIntoSlot;
137
- if (bufferSeconds < 0) {
138
- throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
139
- }
140
- this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
141
- this.log.trace(`Enough time to transition to ${newState}`, {
142
- maxAllowedTime,
143
- secondsIntoSlot
144
- });
145
- }
146
- /**
147
- * Determines if we can start building the next block and returns its deadline.
148
- *
149
- * The timetable divides the slot into fixed sub-slots. This method finds the next
150
- * available sub-slot that has enough time remaining to build a block.
151
- *
152
- * @param secondsIntoSlot - Current time (seconds into the slot)
153
- * @returns Object with canStart flag, deadline, and whether this is the last block
154
- */ canStartNextBlock(secondsIntoSlot) {
155
- // When timetable enforcement is disabled, always allow starting,
156
- // and build a single block with no deadline. This is here just to
157
- // satisfy a subset of e2e tests and the sandbox that assume that the
158
- // sequencer is permanently mining every tx sent.
159
- if (!this.enforce) {
160
- return {
161
- canStart: true,
162
- deadline: undefined,
163
- isLastBlock: true
164
- };
165
- }
166
- // If no block duration is set, then we're in single-block mode, which
167
- // is handled for backwards compatibility towards another subset of e2e tests.
168
- if (this.blockDuration === undefined) {
169
- // In single block mode, execution and re-execution happen sequentially, so we need to
170
- // split the available time between them. After building, we need time for attestations and L1.
171
- const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
172
- const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
173
- const canStart = available >= this.minExecutionTime;
174
- const deadline = secondsIntoSlot + available;
175
- this.log.verbose(`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`, {
176
- secondsIntoSlot,
177
- maxAllowed,
178
- available,
179
- deadline
180
- });
181
- return {
182
- canStart,
183
- deadline,
184
- isLastBlock: true
185
- };
186
- }
187
- // Otherwise, we're in multi-block-per-slot mode, the default when running in production
188
- // Find the next available sub-slot that has enough time remaining
189
- for(let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++){
190
- // Calculate end for this sub-slot
191
- const deadline = this.initializationOffset + subSlot * this.blockDuration;
192
- // Check if we have enough time to build a block with this deadline
193
- const timeUntilDeadline = deadline - secondsIntoSlot;
194
- if (timeUntilDeadline >= this.minExecutionTime) {
195
- // Found an available sub-slot! Is this the last one?
196
- const isLastBlock = subSlot === this.maxNumberOfBlocks;
197
- this.log.verbose(`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`, {
198
- secondsIntoSlot,
199
- deadline,
200
- timeUntilDeadline,
201
- subSlot,
202
- maxBlocks: this.maxNumberOfBlocks
203
- });
204
- return {
205
- canStart: true,
206
- deadline,
207
- isLastBlock
208
- };
209
- }
210
- }
211
- // No sub-slots available with enough time
212
- this.log.verbose(`No time left to start any more blocks`, {
213
- secondsIntoSlot,
214
- maxBlocks: this.maxNumberOfBlocks,
215
- initializationOffset: this.initializationOffset
216
- });
217
- return {
218
- canStart: false,
219
- deadline: undefined,
220
- isLastBlock: false
221
- };
222
- }
223
- }