@aztec/sequencer-client 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065

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