@aztec/sequencer-client 0.0.0-test.1 → 0.0.1-commit.017a351
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 +43 -33
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +117 -62
- package/dest/config.d.ts +38 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +172 -85
- 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 +26 -17
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +45 -61
- 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 -4
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -3
- package/dest/publisher/config.d.ts +60 -27
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +124 -32
- package/dest/publisher/index.d.ts +4 -1
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +3 -0
- 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 +50 -0
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -0
- package/dest/publisher/sequencer-publisher-factory.js +75 -0
- package/dest/publisher/sequencer-publisher-metrics.d.ts +5 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +34 -62
- package/dest/publisher/sequencer-publisher.d.ts +170 -97
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +1255 -276
- 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 +1792 -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 +7 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/errors.d.ts +11 -0
- package/dest/sequencer/errors.d.ts.map +1 -0
- package/dest/sequencer/errors.js +15 -0
- 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 +64 -13
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +309 -68
- package/dest/sequencer/sequencer.d.ts +205 -135
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +1208 -523
- package/dest/sequencer/timetable.d.ts +85 -25
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +177 -60
- 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 +20 -38
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -47
- package/dest/test/index.d.ts +9 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/index.js +0 -4
- 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 +46 -45
- package/src/client/sequencer-client.ts +158 -103
- package/src/config.ts +201 -99
- 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 +68 -76
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -3
- package/src/publisher/config.ts +184 -59
- package/src/publisher/index.ts +7 -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 +121 -0
- package/src/publisher/sequencer-publisher-metrics.ts +33 -63
- package/src/publisher/sequencer-publisher.ts +1101 -350
- 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 +1632 -0
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +119 -0
- package/src/sequencer/config.ts +8 -0
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +76 -0
- package/src/sequencer/index.ts +5 -1
- package/src/sequencer/metrics.ts +397 -75
- package/src/sequencer/sequencer.ts +1013 -579
- package/src/sequencer/timetable.ts +225 -60
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +28 -60
- package/src/test/index.ts +11 -5
- package/src/test/mock_checkpoint_builder.ts +323 -0
- package/src/test/utils.ts +185 -0
- package/dest/sequencer/allowed.d.ts +0 -3
- package/dest/sequencer/allowed.d.ts.map +0 -1
- package/dest/sequencer/allowed.js +0 -27
- package/dest/slasher/factory.d.ts +0 -7
- package/dest/slasher/factory.d.ts.map +0 -1
- package/dest/slasher/factory.js +0 -8
- package/dest/slasher/index.d.ts +0 -3
- package/dest/slasher/index.d.ts.map +0 -1
- package/dest/slasher/index.js +0 -2
- package/dest/slasher/slasher_client.d.ts +0 -75
- package/dest/slasher/slasher_client.d.ts.map +0 -1
- package/dest/slasher/slasher_client.js +0 -132
- package/dest/tx_validator/archive_cache.d.ts +0 -14
- package/dest/tx_validator/archive_cache.d.ts.map +0 -1
- package/dest/tx_validator/archive_cache.js +0 -22
- package/dest/tx_validator/gas_validator.d.ts +0 -14
- package/dest/tx_validator/gas_validator.d.ts.map +0 -1
- package/dest/tx_validator/gas_validator.js +0 -78
- package/dest/tx_validator/nullifier_cache.d.ts +0 -16
- package/dest/tx_validator/nullifier_cache.d.ts.map +0 -1
- package/dest/tx_validator/nullifier_cache.js +0 -24
- package/dest/tx_validator/phases_validator.d.ts +0 -12
- package/dest/tx_validator/phases_validator.d.ts.map +0 -1
- package/dest/tx_validator/phases_validator.js +0 -80
- package/dest/tx_validator/test_utils.d.ts +0 -23
- package/dest/tx_validator/test_utils.d.ts.map +0 -1
- package/dest/tx_validator/test_utils.js +0 -26
- package/dest/tx_validator/tx_validator_factory.d.ts +0 -18
- package/dest/tx_validator/tx_validator_factory.d.ts.map +0 -1
- package/dest/tx_validator/tx_validator_factory.js +0 -50
- package/src/sequencer/allowed.ts +0 -36
- package/src/slasher/factory.ts +0 -15
- package/src/slasher/index.ts +0 -2
- package/src/slasher/slasher_client.ts +0 -193
- package/src/tx_validator/archive_cache.ts +0 -28
- package/src/tx_validator/gas_validator.ts +0 -101
- package/src/tx_validator/nullifier_cache.ts +0 -30
- package/src/tx_validator/phases_validator.ts +0 -98
- package/src/tx_validator/test_utils.ts +0 -48
- package/src/tx_validator/tx_validator_factory.ts +0 -120
|
@@ -1,87 +1,193 @@
|
|
|
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
|
|
|
11
|
+
import { SequencerTooSlowError } from './errors.js';
|
|
3
12
|
import type { SequencerMetrics } from './metrics.js';
|
|
4
13
|
import { SequencerState } from './utils.js';
|
|
5
14
|
|
|
6
15
|
export class SequencerTimetable {
|
|
7
|
-
|
|
8
|
-
public readonly initialTime = 3;
|
|
16
|
+
private readonly checkpointTiming: CheckpointTiming;
|
|
9
17
|
|
|
10
|
-
/**
|
|
11
|
-
|
|
18
|
+
/**
|
|
19
|
+
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
20
|
+
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
21
|
+
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
22
|
+
*/
|
|
23
|
+
public readonly initializeDeadline: number;
|
|
12
24
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
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;
|
|
15
31
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
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;
|
|
18
39
|
|
|
19
40
|
/**
|
|
20
41
|
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
21
42
|
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
22
43
|
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
23
44
|
*/
|
|
24
|
-
public readonly l1PublishingTime;
|
|
45
|
+
public readonly l1PublishingTime: number;
|
|
46
|
+
|
|
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
|
+
*/
|
|
51
|
+
public readonly minExecutionTime: number = MIN_EXECUTION_TIME;
|
|
52
|
+
|
|
53
|
+
/** How long it takes to get ready to start building */
|
|
54
|
+
public readonly checkpointInitializationTime: number = CHECKPOINT_INITIALIZATION_TIME;
|
|
55
|
+
|
|
56
|
+
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
57
|
+
public readonly p2pPropagationTime: number;
|
|
58
|
+
|
|
59
|
+
/** How much time we spend assembling a checkpoint after building the last block */
|
|
60
|
+
public readonly checkpointAssembleTime: number = CHECKPOINT_ASSEMBLE_TIME;
|
|
61
|
+
|
|
62
|
+
/** Ethereum slot duration in seconds */
|
|
63
|
+
public readonly ethereumSlotDuration: number;
|
|
64
|
+
|
|
65
|
+
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
66
|
+
public readonly aztecSlotDuration: number;
|
|
67
|
+
|
|
68
|
+
/** Whether assertTimeLeft will throw if not enough time. */
|
|
69
|
+
public readonly enforce: boolean;
|
|
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;
|
|
25
82
|
|
|
26
83
|
constructor(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
84
|
+
opts: {
|
|
85
|
+
ethereumSlotDuration: number;
|
|
86
|
+
aztecSlotDuration: number;
|
|
87
|
+
l1PublishingTime: number;
|
|
88
|
+
p2pPropagationTime?: number;
|
|
89
|
+
blockDurationMs?: number;
|
|
90
|
+
enforce: boolean;
|
|
91
|
+
},
|
|
31
92
|
private readonly metrics?: SequencerMetrics,
|
|
32
|
-
private readonly log
|
|
93
|
+
private readonly log?: Logger,
|
|
33
94
|
) {
|
|
34
|
-
this.
|
|
95
|
+
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
96
|
+
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
97
|
+
this.l1PublishingTime = opts.l1PublishingTime;
|
|
98
|
+
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
99
|
+
this.enforce = opts.enforce;
|
|
100
|
+
|
|
101
|
+
this.checkpointTiming = createCheckpointTimingModel({
|
|
102
|
+
aztecSlotDuration: this.aztecSlotDuration,
|
|
103
|
+
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
104
|
+
blockDuration: this.blockDuration,
|
|
105
|
+
l1PublishingTime: this.l1PublishingTime,
|
|
106
|
+
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
107
|
+
});
|
|
108
|
+
|
|
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) {
|
|
142
|
+
throw new Error(
|
|
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}).`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
35
146
|
}
|
|
36
147
|
|
|
37
|
-
|
|
38
|
-
return this.
|
|
148
|
+
public getCheckpointAssemblyDeadline(): number {
|
|
149
|
+
return this.checkpointTiming.checkpointAssemblyDeadline;
|
|
39
150
|
}
|
|
40
151
|
|
|
41
|
-
public
|
|
42
|
-
|
|
43
|
-
// send then split the remaining time between the re-execution and the block building.
|
|
44
|
-
const maxAllowed = this.aztecSlotDuration - this.afterBlockBuildingTimeNeededWithoutReexec;
|
|
45
|
-
const available = maxAllowed - secondsIntoSlot;
|
|
46
|
-
const executionTimeEnd = secondsIntoSlot + available / 2;
|
|
47
|
-
this.log.debug(`Block proposal execution time deadline is ${executionTimeEnd}`, {
|
|
48
|
-
secondsIntoSlot,
|
|
49
|
-
maxAllowed,
|
|
50
|
-
available,
|
|
51
|
-
executionTimeEnd,
|
|
52
|
-
});
|
|
53
|
-
return executionTimeEnd;
|
|
152
|
+
public getCheckpointAttestationDeadline(): number {
|
|
153
|
+
return this.checkpointTiming.checkpointAttestationDeadline;
|
|
54
154
|
}
|
|
55
155
|
|
|
56
|
-
|
|
57
|
-
return this.
|
|
156
|
+
public getCheckpointAttestationStartDeadline(): number {
|
|
157
|
+
return this.checkpointTiming.checkpointAttestationStartDeadline;
|
|
58
158
|
}
|
|
59
159
|
|
|
60
|
-
public
|
|
61
|
-
|
|
62
|
-
const validationTimeEnd = this.aztecSlotDuration - this.afterBlockReexecTimeNeeded;
|
|
63
|
-
this.log.debug(`Validator re-execution time deadline is ${validationTimeEnd}`, {
|
|
64
|
-
secondsIntoSlot,
|
|
65
|
-
validationTimeEnd,
|
|
66
|
-
});
|
|
67
|
-
return validationTimeEnd;
|
|
160
|
+
public getCheckpointPublishingDeadline(): number {
|
|
161
|
+
return this.checkpointTiming.checkpointPublishingDeadline;
|
|
68
162
|
}
|
|
69
163
|
|
|
164
|
+
public getMaxAllowedTime(
|
|
165
|
+
state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
|
|
166
|
+
): undefined;
|
|
167
|
+
public getMaxAllowedTime(
|
|
168
|
+
state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
|
|
169
|
+
): number;
|
|
170
|
+
public getMaxAllowedTime(state: SequencerState): number | undefined;
|
|
70
171
|
public getMaxAllowedTime(state: SequencerState): number | undefined {
|
|
71
172
|
switch (state) {
|
|
72
173
|
case SequencerState.STOPPED:
|
|
174
|
+
case SequencerState.STOPPING:
|
|
73
175
|
case SequencerState.IDLE:
|
|
74
176
|
case SequencerState.SYNCHRONIZING:
|
|
75
|
-
case SequencerState.PROPOSER_CHECK:
|
|
76
177
|
return; // We don't really care about times for this states
|
|
77
|
-
case SequencerState.
|
|
78
|
-
|
|
178
|
+
case SequencerState.PROPOSER_CHECK:
|
|
179
|
+
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
180
|
+
return this.initializeDeadline;
|
|
181
|
+
case SequencerState.WAITING_FOR_TXS:
|
|
79
182
|
case SequencerState.CREATING_BLOCK:
|
|
80
|
-
|
|
183
|
+
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
184
|
+
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
185
|
+
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
186
|
+
return this.getCheckpointAssemblyDeadline();
|
|
81
187
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
82
|
-
return this.
|
|
83
|
-
case SequencerState.
|
|
84
|
-
return this.
|
|
188
|
+
return this.getCheckpointAttestationStartDeadline();
|
|
189
|
+
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
190
|
+
return this.getCheckpointPublishingDeadline();
|
|
85
191
|
default: {
|
|
86
192
|
const _exhaustiveCheck: never = state;
|
|
87
193
|
throw new Error(`Unexpected state: ${state}`);
|
|
@@ -105,19 +211,78 @@ export class SequencerTimetable {
|
|
|
105
211
|
}
|
|
106
212
|
|
|
107
213
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
108
|
-
this.log
|
|
214
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
109
215
|
}
|
|
110
|
-
}
|
|
111
216
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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 };
|
|
122
287
|
}
|
|
123
288
|
}
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -1,74 +1,42 @@
|
|
|
1
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { Signature } from '@aztec/foundation/eth-signature';
|
|
3
|
-
import type { BlockAttestation } from '@aztec/stdlib/p2p';
|
|
4
|
-
|
|
5
1
|
export enum SequencerState {
|
|
6
|
-
/**
|
|
7
|
-
* Sequencer is stopped and not processing any txs from the pool.
|
|
8
|
-
*/
|
|
2
|
+
/** Sequencer is stopped and not processing any txs from the pool. */
|
|
9
3
|
STOPPED = 'STOPPED',
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
/** Sequencer is being stopped. Will move to STOPPED shortly. */
|
|
5
|
+
STOPPING = 'STOPPING',
|
|
6
|
+
/** Sequencer is awaiting the next call to work(). */
|
|
13
7
|
IDLE = 'IDLE',
|
|
14
|
-
/**
|
|
15
|
-
* Synchronizing with the L2 chain.
|
|
16
|
-
*/
|
|
8
|
+
/** Synchronizing with the L2 chain. */
|
|
17
9
|
SYNCHRONIZING = 'SYNCHRONIZING',
|
|
18
|
-
/**
|
|
19
|
-
* Checking if we are the proposer for the current slot.
|
|
20
|
-
*/
|
|
10
|
+
/** Checking if we are the proposer for the current slot. */
|
|
21
11
|
PROPOSER_CHECK = 'PROPOSER_CHECK',
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Creating a new L2 block. Includes processing public function calls and running rollup circuits. Will move to PUBLISHING_CONTRACT_DATA.
|
|
28
|
-
*/
|
|
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. */
|
|
29
17
|
CREATING_BLOCK = 'CREATING_BLOCK',
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
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. */
|
|
33
23
|
COLLECTING_ATTESTATIONS = 'COLLECTING_ATTESTATIONS',
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
*/
|
|
37
|
-
PUBLISHING_BLOCK = 'PUBLISHING_BLOCK',
|
|
24
|
+
/** Sending the tx to L1 with the L2 checkpoint data and awaiting it to be mined.. */
|
|
25
|
+
PUBLISHING_CHECKPOINT = 'PUBLISHING_CHECKPOINT',
|
|
38
26
|
}
|
|
39
27
|
|
|
28
|
+
export type SequencerStateWithSlot =
|
|
29
|
+
| SequencerState.INITIALIZING_CHECKPOINT
|
|
30
|
+
| SequencerState.WAITING_FOR_TXS
|
|
31
|
+
| SequencerState.CREATING_BLOCK
|
|
32
|
+
| SequencerState.WAITING_UNTIL_NEXT_BLOCK
|
|
33
|
+
| SequencerState.COLLECTING_ATTESTATIONS
|
|
34
|
+
| SequencerState.PUBLISHING_CHECKPOINT
|
|
35
|
+
| SequencerState.PROPOSER_CHECK
|
|
36
|
+
| SequencerState.ASSEMBLING_CHECKPOINT;
|
|
37
|
+
|
|
40
38
|
export type SequencerStateCallback = () => SequencerState;
|
|
41
39
|
|
|
42
40
|
export function sequencerStateToNumber(state: SequencerState): number {
|
|
43
41
|
return Object.values(SequencerState).indexOf(state);
|
|
44
42
|
}
|
|
45
|
-
|
|
46
|
-
/** Order Attestations
|
|
47
|
-
*
|
|
48
|
-
* Returns attestation signatures in the order of a series of provided ethereum addresses
|
|
49
|
-
* The rollup smart contract expects attestations to appear in the order of the committee
|
|
50
|
-
*
|
|
51
|
-
* @todo: perform this logic within the memory attestation store instead?
|
|
52
|
-
*/
|
|
53
|
-
export async function orderAttestations(
|
|
54
|
-
attestations: BlockAttestation[],
|
|
55
|
-
orderAddresses: EthAddress[],
|
|
56
|
-
): Promise<Signature[]> {
|
|
57
|
-
// Create a map of sender addresses to BlockAttestations
|
|
58
|
-
const attestationMap = new Map<string, BlockAttestation>();
|
|
59
|
-
|
|
60
|
-
for (const attestation of attestations) {
|
|
61
|
-
const sender = await attestation.getSender();
|
|
62
|
-
if (sender) {
|
|
63
|
-
attestationMap.set(sender.toString(), attestation);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Create the ordered array based on the orderAddresses, else return an empty signature
|
|
68
|
-
const orderedAttestations = orderAddresses.map(address => {
|
|
69
|
-
const addressString = address.toString();
|
|
70
|
-
return attestationMap.get(addressString)?.signature || Signature.empty();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return orderedAttestations;
|
|
74
|
-
}
|
package/src/test/index.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
2
|
+
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
1
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
|
+
import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
|
|
2
5
|
|
|
3
6
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
4
|
-
import type {
|
|
7
|
+
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
5
8
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
6
9
|
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
7
10
|
|
|
8
11
|
class TestSequencer_ extends Sequencer {
|
|
9
|
-
public
|
|
10
|
-
public
|
|
11
|
-
public
|
|
12
|
+
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
13
|
+
declare public timetable: SequencerTimetable;
|
|
14
|
+
declare public publisherFactory: SequencerPublisherFactory;
|
|
15
|
+
declare public validatorClient: ValidatorClient;
|
|
16
|
+
declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
export type TestSequencer = TestSequencer_;
|
|
15
20
|
|
|
16
21
|
class TestSequencerClient_ extends SequencerClient {
|
|
17
|
-
public
|
|
22
|
+
declare public sequencer: TestSequencer;
|
|
23
|
+
declare public publisherManager: PublisherManager<L1TxUtils>;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export type TestSequencerClient = TestSequencerClient_;
|