@aztec/sequencer-client 0.0.1-commit.fce3e4f → 0.0.1-commit.ff7989d6c
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 +21 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +45 -27
- package/dest/config.d.ts +14 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +83 -35
- package/dest/global_variable_builder/global_builder.d.ts +20 -13
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +51 -41
- package/dest/index.d.ts +2 -3
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -2
- package/dest/publisher/config.d.ts +37 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +104 -39
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -6
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +14 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts +3 -3
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +23 -86
- package/dest/publisher/sequencer-publisher.d.ts +63 -47
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +630 -137
- package/dest/sequencer/checkpoint_proposal_job.d.ts +102 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1213 -0
- package/dest/sequencer/checkpoint_voter.d.ts +35 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +109 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +4 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +3 -1
- package/dest/sequencer/metrics.d.ts +38 -6
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +216 -72
- package/dest/sequencer/sequencer.d.ts +119 -133
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +717 -625
- package/dest/sequencer/timetable.d.ts +51 -14
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +145 -59
- package/dest/sequencer/types.d.ts +3 -0
- package/dest/sequencer/types.d.ts.map +1 -0
- package/dest/sequencer/types.js +1 -0
- package/dest/sequencer/utils.d.ts +14 -8
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +7 -4
- package/dest/test/index.d.ts +6 -7
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +97 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +222 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +104 -0
- package/package.json +32 -30
- package/src/client/sequencer-client.ts +54 -47
- package/src/config.ts +95 -44
- package/src/global_variable_builder/global_builder.ts +65 -61
- package/src/index.ts +1 -7
- package/src/publisher/config.ts +122 -50
- package/src/publisher/sequencer-publisher-factory.ts +28 -10
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +350 -176
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/checkpoint_proposal_job.ts +914 -0
- package/src/sequencer/checkpoint_voter.ts +130 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +3 -1
- package/src/sequencer/metrics.ts +268 -82
- package/src/sequencer/sequencer.ts +464 -831
- package/src/sequencer/timetable.ts +175 -80
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +18 -9
- package/src/test/index.ts +5 -6
- package/src/test/mock_checkpoint_builder.ts +320 -0
- package/src/test/utils.ts +167 -0
- package/dest/sequencer/block_builder.d.ts +0 -27
- package/dest/sequencer/block_builder.d.ts.map +0 -1
- package/dest/sequencer/block_builder.js +0 -134
- package/dest/tx_validator/nullifier_cache.d.ts +0 -14
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -17
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -53
- package/src/sequencer/block_builder.ts +0 -222
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import {
|
|
3
|
+
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
|
+
CHECKPOINT_INITIALIZATION_TIME,
|
|
5
|
+
DEFAULT_P2P_PROPAGATION_TIME,
|
|
6
|
+
MIN_EXECUTION_TIME,
|
|
7
|
+
} from '@aztec/stdlib/timetable';
|
|
2
8
|
|
|
3
|
-
import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
|
|
4
9
|
import { SequencerTooSlowError } from './errors.js';
|
|
5
10
|
import type { SequencerMetrics } from './metrics.js';
|
|
6
11
|
import { SequencerState } from './utils.js';
|
|
7
12
|
|
|
8
|
-
const MIN_EXECUTION_TIME = 1;
|
|
9
|
-
const BLOCK_PREPARE_TIME = 1;
|
|
10
|
-
const BLOCK_VALIDATION_TIME = 1;
|
|
11
|
-
|
|
12
13
|
export class SequencerTimetable {
|
|
13
14
|
/**
|
|
14
15
|
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
@@ -17,24 +18,42 @@ export class SequencerTimetable {
|
|
|
17
18
|
*/
|
|
18
19
|
public readonly initializeDeadline: number;
|
|
19
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
23
|
+
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
24
|
+
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
25
|
+
*/
|
|
26
|
+
public readonly initializationOffset: number;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Total time needed to finalize and publish a checkpoint, including:
|
|
30
|
+
* - Assembling the checkpoint
|
|
31
|
+
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
32
|
+
* - Publishing to L1
|
|
33
|
+
*/
|
|
34
|
+
public readonly checkpointFinalizationTime: number;
|
|
35
|
+
|
|
20
36
|
/**
|
|
21
37
|
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
22
38
|
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
23
39
|
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
24
40
|
*/
|
|
25
|
-
public readonly l1PublishingTime;
|
|
41
|
+
public readonly l1PublishingTime: number;
|
|
26
42
|
|
|
27
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
45
|
+
* Defaults to half of the block duration if set, otherwise a constant.
|
|
46
|
+
*/
|
|
28
47
|
public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
|
|
29
48
|
|
|
30
49
|
/** How long it takes to get ready to start building */
|
|
31
|
-
public readonly
|
|
50
|
+
public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
|
|
32
51
|
|
|
33
52
|
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
34
|
-
public readonly
|
|
53
|
+
public readonly p2pPropagationTime: number;
|
|
35
54
|
|
|
36
|
-
/** How much time we spend
|
|
37
|
-
public readonly
|
|
55
|
+
/** How much time we spend assembling a checkpoint after building the last block */
|
|
56
|
+
public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
|
|
38
57
|
|
|
39
58
|
/** Ethereum slot duration in seconds */
|
|
40
59
|
public readonly ethereumSlotDuration: number;
|
|
@@ -42,18 +61,22 @@ export class SequencerTimetable {
|
|
|
42
61
|
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
43
62
|
public readonly aztecSlotDuration: number;
|
|
44
63
|
|
|
45
|
-
/** How late into an L1 slot we can send a tx to make sure it gets included in the immediate next block. Complement of l1PublishingTime. */
|
|
46
|
-
public readonly maxL1TxInclusionTimeIntoSlot: number;
|
|
47
|
-
|
|
48
64
|
/** Whether assertTimeLeft will throw if not enough time. */
|
|
49
65
|
public readonly enforce: boolean;
|
|
50
66
|
|
|
67
|
+
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
|
|
68
|
+
public readonly blockDuration: number | undefined;
|
|
69
|
+
|
|
70
|
+
/** Maximum number of blocks that can be built in this slot configuration */
|
|
71
|
+
public readonly maxNumberOfBlocks: number;
|
|
72
|
+
|
|
51
73
|
constructor(
|
|
52
74
|
opts: {
|
|
53
75
|
ethereumSlotDuration: number;
|
|
54
76
|
aztecSlotDuration: number;
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
l1PublishingTime: number;
|
|
78
|
+
p2pPropagationTime?: number;
|
|
79
|
+
blockDurationMs?: number;
|
|
57
80
|
enforce: boolean;
|
|
58
81
|
},
|
|
59
82
|
private readonly metrics?: SequencerMetrics,
|
|
@@ -61,80 +84,77 @@ export class SequencerTimetable {
|
|
|
61
84
|
) {
|
|
62
85
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
63
86
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
87
|
+
this.l1PublishingTime = opts.l1PublishingTime;
|
|
88
|
+
this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
|
|
89
|
+
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
67
90
|
this.enforce = opts.enforce;
|
|
68
91
|
|
|
69
92
|
// Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
|
|
70
93
|
if (this.ethereumSlotDuration < 8) {
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
94
|
+
this.p2pPropagationTime = 0;
|
|
95
|
+
this.checkpointAssembleTime = 0.5;
|
|
96
|
+
this.checkpointInitializationTime = 0.5;
|
|
97
|
+
this.minExecutionTime = 1;
|
|
74
98
|
}
|
|
75
99
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.minExecutionTime
|
|
79
|
-
|
|
80
|
-
this.blockValidationTime +
|
|
81
|
-
this.l1PublishingTime;
|
|
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
|
+
}
|
|
82
104
|
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
// Calculate initialization offset - estimate of time needed for sync + proposer check
|
|
106
|
+
// This is the baseline for all sub-slot deadlines
|
|
107
|
+
this.initializationOffset = this.checkpointInitializationTime;
|
|
85
108
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
minExecutionTime: this.minExecutionTime,
|
|
92
|
-
blockPrepareTime: this.blockPrepareTime,
|
|
93
|
-
attestationPropagationTime: this.attestationPropagationTime,
|
|
94
|
-
blockValidationTime: this.blockValidationTime,
|
|
95
|
-
initializeDeadline: this.initializeDeadline,
|
|
96
|
-
enforce: this.enforce,
|
|
97
|
-
allWorkToDo,
|
|
98
|
-
});
|
|
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
|
|
99
114
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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);
|
|
104
124
|
}
|
|
105
|
-
}
|
|
106
125
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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;
|
|
110
131
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// send then split the remaining time between the re-execution and the block building.
|
|
114
|
-
const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
|
|
115
|
-
const available = maxAllowed - secondsIntoSlot;
|
|
116
|
-
const executionTimeEnd = secondsIntoSlot + available / 2;
|
|
117
|
-
this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
|
|
118
|
-
secondsIntoSlot,
|
|
119
|
-
maxAllowed,
|
|
120
|
-
available,
|
|
121
|
-
executionTimeEnd,
|
|
122
|
-
});
|
|
123
|
-
return executionTimeEnd;
|
|
124
|
-
}
|
|
132
|
+
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
133
|
+
this.initializeDeadline = initializeDeadline;
|
|
125
134
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
135
|
+
this.log.verbose(
|
|
136
|
+
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
137
|
+
{
|
|
138
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
139
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
140
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
141
|
+
minExecutionTime: this.minExecutionTime,
|
|
142
|
+
blockPrepareTime: this.checkpointInitializationTime,
|
|
143
|
+
p2pPropagationTime: this.p2pPropagationTime,
|
|
144
|
+
blockAssembleTime: this.checkpointAssembleTime,
|
|
145
|
+
initializeDeadline: this.initializeDeadline,
|
|
146
|
+
enforce: this.enforce,
|
|
147
|
+
minWorkToDo,
|
|
148
|
+
blockDuration: this.blockDuration,
|
|
149
|
+
maxNumberOfBlocks: this.maxNumberOfBlocks,
|
|
150
|
+
},
|
|
151
|
+
);
|
|
129
152
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
validationTimeEnd,
|
|
136
|
-
});
|
|
137
|
-
return validationTimeEnd;
|
|
153
|
+
if (initializeDeadline <= 0) {
|
|
154
|
+
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}).`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
138
158
|
}
|
|
139
159
|
|
|
140
160
|
public getMaxAllowedTime(
|
|
@@ -152,13 +172,16 @@ export class SequencerTimetable {
|
|
|
152
172
|
case SequencerState.SYNCHRONIZING:
|
|
153
173
|
return; // We don't really care about times for this states
|
|
154
174
|
case SequencerState.PROPOSER_CHECK:
|
|
155
|
-
case SequencerState.
|
|
175
|
+
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
156
176
|
return this.initializeDeadline;
|
|
177
|
+
case SequencerState.WAITING_FOR_TXS:
|
|
157
178
|
case SequencerState.CREATING_BLOCK:
|
|
158
|
-
|
|
179
|
+
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
180
|
+
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
181
|
+
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
159
182
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
160
|
-
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.
|
|
161
|
-
case SequencerState.
|
|
183
|
+
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
|
|
184
|
+
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
162
185
|
return this.aztecSlotDuration - this.l1PublishingTime;
|
|
163
186
|
default: {
|
|
164
187
|
const _exhaustiveCheck: never = state;
|
|
@@ -185,4 +208,76 @@ export class SequencerTimetable {
|
|
|
185
208
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
186
209
|
this.log.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
187
210
|
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Determines if we can start building the next block and returns its deadline.
|
|
214
|
+
*
|
|
215
|
+
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
216
|
+
* available sub-slot that has enough time remaining to build a block.
|
|
217
|
+
*
|
|
218
|
+
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
219
|
+
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
220
|
+
*/
|
|
221
|
+
public canStartNextBlock(
|
|
222
|
+
secondsIntoSlot: number,
|
|
223
|
+
):
|
|
224
|
+
| { canStart: true; deadline: undefined; isLastBlock: true }
|
|
225
|
+
| { canStart: false; deadline: undefined; isLastBlock: false }
|
|
226
|
+
| { canStart: boolean; deadline: number; isLastBlock: boolean } {
|
|
227
|
+
// When timetable enforcement is disabled, always allow starting,
|
|
228
|
+
// and build a single block with no deadline. This is here just to
|
|
229
|
+
// satisfy a subset of e2e tests and the sandbox that assume that the
|
|
230
|
+
// sequencer is permanently mining every tx sent.
|
|
231
|
+
if (!this.enforce) {
|
|
232
|
+
return { canStart: true, deadline: undefined, isLastBlock: true };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// If no block duration is set, then we're in single-block mode, which
|
|
236
|
+
// is handled for backwards compatibility towards another subset of e2e tests.
|
|
237
|
+
if (this.blockDuration === undefined) {
|
|
238
|
+
// In single block mode, execution and re-execution happen sequentially, so we need to
|
|
239
|
+
// split the available time between them. After building, we need time for attestations and L1.
|
|
240
|
+
const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
|
|
241
|
+
const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
|
|
242
|
+
const canStart = available >= this.minExecutionTime;
|
|
243
|
+
const deadline = secondsIntoSlot + available;
|
|
244
|
+
|
|
245
|
+
this.log.verbose(
|
|
246
|
+
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
247
|
+
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
248
|
+
);
|
|
249
|
+
return { canStart, deadline, isLastBlock: true };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Otherwise, we're in multi-block-per-slot mode, the default when running in production
|
|
253
|
+
// Find the next available sub-slot that has enough time remaining
|
|
254
|
+
for (let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++) {
|
|
255
|
+
// Calculate end for this sub-slot
|
|
256
|
+
const deadline = this.initializationOffset + subSlot * this.blockDuration;
|
|
257
|
+
|
|
258
|
+
// Check if we have enough time to build a block with this deadline
|
|
259
|
+
const timeUntilDeadline = deadline - secondsIntoSlot;
|
|
260
|
+
|
|
261
|
+
if (timeUntilDeadline >= this.minExecutionTime) {
|
|
262
|
+
// Found an available sub-slot! Is this the last one?
|
|
263
|
+
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
264
|
+
|
|
265
|
+
this.log.verbose(
|
|
266
|
+
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
267
|
+
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
return { canStart: true, deadline, isLastBlock };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// No sub-slots available with enough time
|
|
275
|
+
this.log.verbose(`No time left to start any more blocks`, {
|
|
276
|
+
secondsIntoSlot,
|
|
277
|
+
maxBlocks: this.maxNumberOfBlocks,
|
|
278
|
+
initializationOffset: this.initializationOffset,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return { canStart: false, deadline: undefined, isLastBlock: false };
|
|
282
|
+
}
|
|
188
283
|
}
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -9,22 +9,31 @@ export enum SequencerState {
|
|
|
9
9
|
SYNCHRONIZING = 'SYNCHRONIZING',
|
|
10
10
|
/** Checking if we are the proposer for the current slot. */
|
|
11
11
|
PROPOSER_CHECK = 'PROPOSER_CHECK',
|
|
12
|
-
/** Initializing the
|
|
13
|
-
|
|
14
|
-
/**
|
|
12
|
+
/** Initializing the checkpoint proposal. */
|
|
13
|
+
INITIALIZING_CHECKPOINT = 'INITIALIZING_CHECKPOINT',
|
|
14
|
+
/** Waiting for transactions to arrive in the pool. */
|
|
15
|
+
WAITING_FOR_TXS = 'WAITING_FOR_TXS',
|
|
16
|
+
/** Creating a new L2 block. Includes processing public function calls. */
|
|
15
17
|
CREATING_BLOCK = 'CREATING_BLOCK',
|
|
16
|
-
/**
|
|
18
|
+
/** Waiting until the next block can be created. */
|
|
19
|
+
WAITING_UNTIL_NEXT_BLOCK = 'WAITING_UNTIL_NEXT_BLOCK',
|
|
20
|
+
/** Assembling and broadcasting the checkpoint. */
|
|
21
|
+
ASSEMBLING_CHECKPOINT = 'ASSEMBLING_CHECKPOINT',
|
|
22
|
+
/** Collecting attestations from its peers. */
|
|
17
23
|
COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
|
|
18
|
-
/** Sending the tx to L1 with the L2
|
|
19
|
-
|
|
24
|
+
/** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
|
|
25
|
+
PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
export type SequencerStateWithSlot =
|
|
23
|
-
| SequencerState.
|
|
29
|
+
| SequencerState.INITIALIZING_CHECKPOINT
|
|
30
|
+
| SequencerState.WAITING_FOR_TXS
|
|
24
31
|
| SequencerState.CREATING_BLOCK
|
|
32
|
+
| SequencerState.WAITING_UNTIL_NEXT_BLOCK
|
|
25
33
|
| SequencerState.COLLECTING_ATTESTATIONS
|
|
26
|
-
| SequencerState.
|
|
27
|
-
| SequencerState.PROPOSER_CHECK
|
|
34
|
+
| SequencerState.PUBLISHING_CHECKPOINT
|
|
35
|
+
| SequencerState.PROPOSER_CHECK
|
|
36
|
+
| SequencerState.ASSEMBLING_CHECKPOINT;
|
|
28
37
|
|
|
29
38
|
export type SequencerStateCallback = () => SequencerState;
|
|
30
39
|
|
package/src/test/index.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
2
|
+
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
3
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
|
-
import type { ValidatorClient } from '@aztec/validator-client';
|
|
4
|
+
import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
|
|
5
5
|
|
|
6
6
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
7
7
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
8
|
-
import type { SequencerPublisher } from '../publisher/sequencer-publisher.js';
|
|
9
8
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
10
9
|
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
11
10
|
|
|
12
11
|
class TestSequencer_ extends Sequencer {
|
|
13
12
|
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
14
13
|
declare public timetable: SequencerTimetable;
|
|
15
|
-
declare public publisher: SequencerPublisher;
|
|
16
14
|
declare public publisherFactory: SequencerPublisherFactory;
|
|
17
15
|
declare public validatorClient: ValidatorClient;
|
|
16
|
+
declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
export type TestSequencer = TestSequencer_;
|
|
21
20
|
|
|
22
21
|
class TestSequencerClient_ extends SequencerClient {
|
|
23
22
|
declare public sequencer: TestSequencer;
|
|
24
|
-
declare public publisherManager: PublisherManager<
|
|
23
|
+
declare public publisherManager: PublisherManager<L1TxUtils>;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export type TestSequencerClient = TestSequencerClient_;
|