@aztec/sequencer-client 0.0.1-commit.b655e406 → 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.
- package/README.md +281 -21
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +26 -16
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +78 -37
- package/dest/config.d.ts +37 -8
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +139 -48
- package/dest/global_variable_builder/fee_predictor.d.ts +37 -0
- package/dest/global_variable_builder/fee_predictor.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_predictor.js +128 -0
- package/dest/global_variable_builder/fee_provider.d.ts +21 -0
- package/dest/global_variable_builder/fee_provider.d.ts.map +1 -0
- package/dest/global_variable_builder/fee_provider.js +58 -0
- package/dest/global_variable_builder/global_builder.d.ts +24 -20
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +44 -65
- package/dest/global_variable_builder/index.d.ts +4 -2
- package/dest/global_variable_builder/index.d.ts.map +1 -1
- package/dest/global_variable_builder/index.js +2 -0
- 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 +55 -20
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -34
- package/dest/publisher/index.d.ts +2 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/l1_tx_failed_store/factory.d.ts +11 -0
- package/dest/publisher/l1_tx_failed_store/factory.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/factory.js +22 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +58 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.js +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts +15 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/file_store_failed_tx_store.js +34 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts +4 -0
- package/dest/publisher/l1_tx_failed_store/index.d.ts.map +1 -0
- package/dest/publisher/l1_tx_failed_store/index.js +2 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts +96 -0
- package/dest/publisher/sequencer-bundle-simulator.d.ts.map +1 -0
- package/dest/publisher/sequencer-bundle-simulator.js +198 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts +15 -8
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +28 -4
- 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 +137 -97
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1004 -416
- package/dest/sequencer/automine/automine_factory.d.ts +54 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +84 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +151 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +509 -0
- package/dest/sequencer/chain_state_overrides.d.ts +61 -0
- package/dest/sequencer/chain_state_overrides.d.ts.map +1 -0
- package/dest/sequencer/chain_state_overrides.js +98 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +150 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1793 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts +34 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job_metrics.js +72 -0
- package/dest/sequencer/checkpoint_voter.d.ts +34 -0
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_voter.js +106 -0
- package/dest/sequencer/config.d.ts +3 -2
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +1 -1
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/events.d.ts +92 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +6 -2
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +5 -1
- package/dest/sequencer/metrics.d.ts +48 -4
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +257 -50
- package/dest/sequencer/sequencer.d.ts +175 -144
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1022 -567
- package/dest/sequencer/timetable.d.ts +64 -16
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +154 -64
- 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 +95 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +231 -0
- package/dest/test/utils.d.ts +53 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +105 -0
- package/package.json +32 -30
- package/src/client/sequencer-client.ts +105 -60
- package/src/config.ts +163 -57
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +172 -0
- package/src/global_variable_builder/fee_provider.ts +75 -0
- package/src/global_variable_builder/global_builder.ts +63 -92
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +5 -2
- package/src/publisher/config.ts +174 -51
- package/src/publisher/index.ts +3 -0
- package/src/publisher/l1_tx_failed_store/factory.ts +32 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +57 -0
- package/src/publisher/l1_tx_failed_store/file_store_failed_tx_store.ts +46 -0
- package/src/publisher/l1_tx_failed_store/index.ts +3 -0
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +45 -14
- package/src/publisher/sequencer-publisher-metrics.ts +19 -71
- package/src/publisher/sequencer-publisher.ts +798 -538
- package/src/sequencer/README.md +243 -0
- package/src/sequencer/automine/README.md +46 -0
- package/src/sequencer/automine/automine_factory.ts +145 -0
- package/src/sequencer/automine/automine_sequencer.ts +595 -0
- package/src/sequencer/chain_state_overrides.ts +162 -0
- package/src/sequencer/checkpoint_proposal_job.ts +1633 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/events.ts +76 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +330 -62
- package/src/sequencer/sequencer.ts +831 -748
- package/src/sequencer/timetable.ts +181 -81
- 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 +323 -0
- package/src/test/utils.ts +185 -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 -130
- 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 -218
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/tx_validator_factory.ts +0 -132
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
+
import {
|
|
3
|
+
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
|
+
CHECKPOINT_INITIALIZATION_TIME,
|
|
5
|
+
type CheckpointTiming,
|
|
6
|
+
DEFAULT_P2P_PROPAGATION_TIME,
|
|
7
|
+
MIN_EXECUTION_TIME,
|
|
8
|
+
createCheckpointTimingModel,
|
|
9
|
+
} from '@aztec/stdlib/timetable';
|
|
2
10
|
|
|
3
|
-
import { DEFAULT_ATTESTATION_PROPAGATION_TIME } from '../config.js';
|
|
4
11
|
import { SequencerTooSlowError } from './errors.js';
|
|
5
12
|
import type { SequencerMetrics } from './metrics.js';
|
|
6
13
|
import { SequencerState } from './utils.js';
|
|
7
14
|
|
|
8
|
-
const MIN_EXECUTION_TIME = 1;
|
|
9
|
-
const BLOCK_PREPARE_TIME = 1;
|
|
10
|
-
const BLOCK_VALIDATION_TIME = 1;
|
|
11
|
-
|
|
12
15
|
export class SequencerTimetable {
|
|
16
|
+
private readonly checkpointTiming: CheckpointTiming;
|
|
17
|
+
|
|
13
18
|
/**
|
|
14
19
|
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
15
20
|
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
@@ -17,24 +22,42 @@ export class SequencerTimetable {
|
|
|
17
22
|
*/
|
|
18
23
|
public readonly initializeDeadline: number;
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
27
|
+
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
28
|
+
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
29
|
+
*/
|
|
30
|
+
public readonly initializationOffset: number;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Total time needed to finalize and publish a checkpoint, including:
|
|
34
|
+
* - Assembling the checkpoint
|
|
35
|
+
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
36
|
+
* - Publishing to L1
|
|
37
|
+
*/
|
|
38
|
+
public readonly checkpointFinalizationTime: number;
|
|
39
|
+
|
|
20
40
|
/**
|
|
21
41
|
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
22
42
|
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
23
43
|
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
24
44
|
*/
|
|
25
|
-
public readonly l1PublishingTime;
|
|
45
|
+
public readonly l1PublishingTime: number;
|
|
26
46
|
|
|
27
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
49
|
+
* Defaults to half of the block duration if set, otherwise a constant.
|
|
50
|
+
*/
|
|
28
51
|
public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
|
|
29
52
|
|
|
30
53
|
/** How long it takes to get ready to start building */
|
|
31
|
-
public readonly
|
|
54
|
+
public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
|
|
32
55
|
|
|
33
56
|
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
34
|
-
public readonly
|
|
57
|
+
public readonly p2pPropagationTime: number;
|
|
35
58
|
|
|
36
|
-
/** How much time we spend
|
|
37
|
-
public readonly
|
|
59
|
+
/** How much time we spend assembling a checkpoint after building the last block */
|
|
60
|
+
public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
|
|
38
61
|
|
|
39
62
|
/** Ethereum slot duration in seconds */
|
|
40
63
|
public readonly ethereumSlotDuration: number;
|
|
@@ -42,99 +65,100 @@ export class SequencerTimetable {
|
|
|
42
65
|
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
43
66
|
public readonly aztecSlotDuration: number;
|
|
44
67
|
|
|
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
68
|
/** Whether assertTimeLeft will throw if not enough time. */
|
|
49
69
|
public readonly enforce: boolean;
|
|
50
70
|
|
|
71
|
+
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
|
|
72
|
+
public readonly blockDuration: number | undefined;
|
|
73
|
+
|
|
74
|
+
/** Maximum number of blocks that can be built in this slot configuration */
|
|
75
|
+
public readonly maxNumberOfBlocks: number;
|
|
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
|
+
|
|
51
83
|
constructor(
|
|
52
84
|
opts: {
|
|
53
85
|
ethereumSlotDuration: number;
|
|
54
86
|
aztecSlotDuration: number;
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
l1PublishingTime: number;
|
|
88
|
+
p2pPropagationTime?: number;
|
|
89
|
+
blockDurationMs?: number;
|
|
57
90
|
enforce: boolean;
|
|
58
91
|
},
|
|
59
92
|
private readonly metrics?: SequencerMetrics,
|
|
60
|
-
private readonly log
|
|
93
|
+
private readonly log?: Logger,
|
|
61
94
|
) {
|
|
62
95
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
63
96
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.l1PublishingTime = this.ethereumSlotDuration - this.maxL1TxInclusionTimeIntoSlot;
|
|
97
|
+
this.l1PublishingTime = opts.l1PublishingTime;
|
|
98
|
+
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
67
99
|
this.enforce = opts.enforce;
|
|
68
100
|
|
|
69
|
-
|
|
70
|
-
if (this.ethereumSlotDuration < 8) {
|
|
71
|
-
this.attestationPropagationTime = 0;
|
|
72
|
-
this.blockValidationTime = 0.5;
|
|
73
|
-
this.blockPrepareTime = 0.5;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const allWorkToDo =
|
|
77
|
-
this.blockPrepareTime +
|
|
78
|
-
this.minExecutionTime * 2 +
|
|
79
|
-
this.attestationPropagationTime * 2 +
|
|
80
|
-
this.blockValidationTime +
|
|
81
|
-
this.l1PublishingTime;
|
|
82
|
-
|
|
83
|
-
const initializeDeadline = this.aztecSlotDuration - allWorkToDo;
|
|
84
|
-
this.initializeDeadline = initializeDeadline;
|
|
85
|
-
|
|
86
|
-
this.log.verbose(`Sequencer timetable initialized (${this.enforce ? 'enforced' : 'not enforced'})`, {
|
|
87
|
-
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
101
|
+
this.checkpointTiming = createCheckpointTimingModel({
|
|
88
102
|
aztecSlotDuration: this.aztecSlotDuration,
|
|
89
|
-
|
|
103
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
104
|
+
blockDuration: this.blockDuration,
|
|
90
105
|
l1PublishingTime: this.l1PublishingTime,
|
|
91
|
-
|
|
92
|
-
blockPrepareTime: this.blockPrepareTime,
|
|
93
|
-
attestationPropagationTime: this.attestationPropagationTime,
|
|
94
|
-
blockValidationTime: this.blockValidationTime,
|
|
95
|
-
initializeDeadline: this.initializeDeadline,
|
|
96
|
-
enforce: this.enforce,
|
|
97
|
-
allWorkToDo,
|
|
106
|
+
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
98
107
|
});
|
|
99
108
|
|
|
100
|
-
|
|
109
|
+
this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
|
|
110
|
+
this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
|
|
111
|
+
this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
|
|
112
|
+
this.minExecutionTime = this.checkpointTiming.minExecutionTime;
|
|
113
|
+
|
|
114
|
+
// Calculate initialization offset - estimate of time needed for sync + proposer check
|
|
115
|
+
// This is the baseline for all sub-slot deadlines
|
|
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;
|
|
121
|
+
|
|
122
|
+
this.log?.info(
|
|
123
|
+
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
124
|
+
{
|
|
125
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
126
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
127
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
128
|
+
minExecutionTime: this.minExecutionTime,
|
|
129
|
+
blockPrepareTime: this.checkpointInitializationTime,
|
|
130
|
+
p2pPropagationTime: this.p2pPropagationTime,
|
|
131
|
+
blockAssembleTime: this.checkpointAssembleTime,
|
|
132
|
+
initializeDeadline: this.initializeDeadline,
|
|
133
|
+
enforce: this.enforce,
|
|
134
|
+
pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
|
|
135
|
+
minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
|
|
136
|
+
blockDuration: this.blockDuration,
|
|
137
|
+
maxNumberOfBlocks: this.maxNumberOfBlocks,
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (this.initializeDeadline <= 0) {
|
|
101
142
|
throw new Error(
|
|
102
|
-
`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${
|
|
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}).`,
|
|
103
144
|
);
|
|
104
145
|
}
|
|
105
146
|
}
|
|
106
147
|
|
|
107
|
-
|
|
108
|
-
return this.
|
|
148
|
+
public getCheckpointAssemblyDeadline(): number {
|
|
149
|
+
return this.checkpointTiming.checkpointAssemblyDeadline;
|
|
109
150
|
}
|
|
110
151
|
|
|
111
|
-
public
|
|
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;
|
|
152
|
+
public getCheckpointAttestationDeadline(): number {
|
|
153
|
+
return this.checkpointTiming.checkpointAttestationDeadline;
|
|
124
154
|
}
|
|
125
155
|
|
|
126
|
-
|
|
127
|
-
return this.
|
|
156
|
+
public getCheckpointAttestationStartDeadline(): number {
|
|
157
|
+
return this.checkpointTiming.checkpointAttestationStartDeadline;
|
|
128
158
|
}
|
|
129
159
|
|
|
130
|
-
public
|
|
131
|
-
|
|
132
|
-
const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
|
|
133
|
-
this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
|
|
134
|
-
secondsIntoSlot,
|
|
135
|
-
validationTimeEnd,
|
|
136
|
-
});
|
|
137
|
-
return validationTimeEnd;
|
|
160
|
+
public getCheckpointPublishingDeadline(): number {
|
|
161
|
+
return this.checkpointTiming.checkpointPublishingDeadline;
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
public getMaxAllowedTime(
|
|
@@ -152,14 +176,18 @@ export class SequencerTimetable {
|
|
|
152
176
|
case SequencerState.SYNCHRONIZING:
|
|
153
177
|
return; // We don't really care about times for this states
|
|
154
178
|
case SequencerState.PROPOSER_CHECK:
|
|
155
|
-
case SequencerState.
|
|
179
|
+
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
156
180
|
return this.initializeDeadline;
|
|
181
|
+
case SequencerState.WAITING_FOR_TXS:
|
|
157
182
|
case SequencerState.CREATING_BLOCK:
|
|
158
|
-
|
|
183
|
+
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
184
|
+
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
185
|
+
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
186
|
+
return this.getCheckpointAssemblyDeadline();
|
|
159
187
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
160
|
-
return this.
|
|
161
|
-
case SequencerState.
|
|
162
|
-
return this.
|
|
188
|
+
return this.getCheckpointAttestationStartDeadline();
|
|
189
|
+
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
190
|
+
return this.getCheckpointPublishingDeadline();
|
|
163
191
|
default: {
|
|
164
192
|
const _exhaustiveCheck: never = state;
|
|
165
193
|
throw new Error(`Unexpected state: ${state}`);
|
|
@@ -183,6 +211,78 @@ export class SequencerTimetable {
|
|
|
183
211
|
}
|
|
184
212
|
|
|
185
213
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
186
|
-
this.log
|
|
214
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Determines if we can start building the next block and returns its deadline.
|
|
219
|
+
*
|
|
220
|
+
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
221
|
+
* available sub-slot that has enough time remaining to build a block.
|
|
222
|
+
*
|
|
223
|
+
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
224
|
+
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
225
|
+
*/
|
|
226
|
+
public canStartNextBlock(
|
|
227
|
+
secondsIntoSlot: number,
|
|
228
|
+
):
|
|
229
|
+
| { canStart: true; deadline: undefined; isLastBlock: true }
|
|
230
|
+
| { canStart: false; deadline: undefined; isLastBlock: false }
|
|
231
|
+
| { canStart: boolean; deadline: number; isLastBlock: boolean } {
|
|
232
|
+
// When timetable enforcement is disabled, always allow starting,
|
|
233
|
+
// and build a single block with no deadline. This is here just to
|
|
234
|
+
// satisfy a subset of e2e tests and the sandbox that assume that the
|
|
235
|
+
// sequencer is permanently mining every tx sent.
|
|
236
|
+
if (!this.enforce) {
|
|
237
|
+
return { canStart: true, deadline: undefined, isLastBlock: true };
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// If no block duration is set, then we're in single-block mode, which
|
|
241
|
+
// is handled for backwards compatibility towards another subset of e2e tests.
|
|
242
|
+
if (this.blockDuration === undefined) {
|
|
243
|
+
// In single block mode, execution and re-execution happen sequentially, so we need to
|
|
244
|
+
// split the available time between them. After building, we need time for attestations and L1.
|
|
245
|
+
const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
|
|
246
|
+
const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
|
|
247
|
+
const canStart = available >= this.minExecutionTime;
|
|
248
|
+
const deadline = secondsIntoSlot + available;
|
|
249
|
+
|
|
250
|
+
this.log?.verbose(
|
|
251
|
+
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
252
|
+
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
253
|
+
);
|
|
254
|
+
return { canStart, deadline, isLastBlock: true };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Otherwise, we're in multi-block-per-slot mode, the default when running in production
|
|
258
|
+
// Find the next available sub-slot that has enough time remaining
|
|
259
|
+
for (let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++) {
|
|
260
|
+
// Calculate end for this sub-slot
|
|
261
|
+
const deadline = this.initializationOffset + subSlot * this.blockDuration;
|
|
262
|
+
|
|
263
|
+
// Check if we have enough time to build a block with this deadline
|
|
264
|
+
const timeUntilDeadline = deadline - secondsIntoSlot;
|
|
265
|
+
|
|
266
|
+
if (timeUntilDeadline >= this.minExecutionTime) {
|
|
267
|
+
// Found an available sub-slot! Is this the last one?
|
|
268
|
+
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
269
|
+
|
|
270
|
+
this.log?.verbose(
|
|
271
|
+
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
272
|
+
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return { canStart: true, deadline, isLastBlock };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// No sub-slots available with enough time
|
|
280
|
+
this.log?.verbose(`No time left to start any more blocks`, {
|
|
281
|
+
secondsIntoSlot,
|
|
282
|
+
maxBlocks: this.maxNumberOfBlocks,
|
|
283
|
+
initializationOffset: this.initializationOffset,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
return { canStart: false, deadline: undefined, isLastBlock: false };
|
|
187
287
|
}
|
|
188
288
|
}
|
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_;
|