@aztec/sequencer-client 0.0.1-commit.f504929 → 0.0.1-commit.f5a9928
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +283 -21
- package/dest/client/sequencer-client.d.ts +23 -5
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +63 -36
- package/dest/config.d.ts +32 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +81 -31
- 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 +138 -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 +80 -0
- package/dest/global_variable_builder/global_builder.d.ts +13 -26
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +9 -66
- 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/publisher/config.d.ts +19 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +30 -5
- package/dest/publisher/l1_to_l2_messaging.d.ts +21 -0
- package/dest/publisher/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/publisher/l1_to_l2_messaging.js +70 -0
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts +3 -4
- package/dest/publisher/l1_tx_failed_store/failed_tx_store.d.ts.map +1 -1
- 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 +3 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +2 -3
- package/dest/publisher/sequencer-publisher.d.ts +91 -69
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +445 -535
- package/dest/publisher/write_json.d.ts +11 -0
- package/dest/publisher/write_json.d.ts.map +1 -0
- package/dest/publisher/write_json.js +57 -0
- package/dest/sequencer/automine/automine_factory.d.ts +56 -0
- package/dest/sequencer/automine/automine_factory.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_factory.js +85 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts +189 -0
- package/dest/sequencer/automine/automine_sequencer.d.ts.map +1 -0
- package/dest/sequencer/automine/automine_sequencer.js +696 -0
- package/dest/sequencer/automine/index.d.ts +3 -0
- package/dest/sequencer/automine/index.d.ts.map +1 -0
- package/dest/sequencer/automine/index.js +2 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +75 -19
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +831 -256
- 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 +1 -2
- package/dest/sequencer/checkpoint_voter.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_voter.js +2 -5
- package/dest/sequencer/errors.d.ts +1 -8
- package/dest/sequencer/errors.d.ts.map +1 -1
- package/dest/sequencer/errors.js +0 -9
- package/dest/sequencer/events.d.ts +62 -5
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/metrics.d.ts +14 -11
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- package/dest/sequencer/requests_tracker.d.ts +22 -0
- package/dest/sequencer/requests_tracker.d.ts.map +1 -0
- package/dest/sequencer/requests_tracker.js +33 -0
- package/dest/sequencer/sequencer.d.ts +166 -39
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +616 -198
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.d.ts.map +1 -1
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +7 -9
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.js +39 -30
- package/dest/test/utils.d.ts +15 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +25 -7
- package/package.json +28 -28
- package/src/client/sequencer-client.ts +90 -45
- package/src/config.ts +98 -31
- package/src/global_variable_builder/README.md +44 -0
- package/src/global_variable_builder/fee_predictor.ts +182 -0
- package/src/global_variable_builder/fee_provider.ts +97 -0
- package/src/global_variable_builder/global_builder.ts +19 -88
- package/src/global_variable_builder/index.ts +3 -1
- package/src/publisher/config.ts +62 -7
- package/src/publisher/l1_to_l2_messaging.ts +85 -0
- package/src/publisher/l1_tx_failed_store/failed_tx_store.ts +3 -1
- package/src/publisher/sequencer-bundle-simulator.ts +254 -0
- package/src/publisher/sequencer-publisher-factory.ts +3 -6
- package/src/publisher/sequencer-publisher.ts +510 -584
- package/src/publisher/write_json.ts +78 -0
- package/src/sequencer/automine/README.md +60 -0
- package/src/sequencer/automine/automine_factory.ts +152 -0
- package/src/sequencer/automine/automine_sequencer.ts +800 -0
- package/src/sequencer/automine/index.ts +6 -0
- package/src/sequencer/checkpoint_proposal_job.ts +993 -294
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/errors.ts +0 -15
- package/src/sequencer/events.ts +66 -5
- package/src/sequencer/metrics.ts +63 -25
- package/src/sequencer/requests_tracker.ts +43 -0
- package/src/sequencer/sequencer.ts +720 -220
- package/src/sequencer/types.ts +1 -1
- package/src/test/index.ts +2 -2
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +61 -10
- package/dest/sequencer/timetable.d.ts +0 -87
- package/dest/sequencer/timetable.d.ts.map +0 -1
- package/dest/sequencer/timetable.js +0 -223
- package/src/sequencer/README.md +0 -531
- package/src/sequencer/timetable.ts +0 -283
package/src/sequencer/types.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
|
2
2
|
|
|
3
3
|
export type SequencerRollupConstants = Pick<
|
|
4
4
|
L1RollupConstants,
|
|
5
|
-
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration'
|
|
5
|
+
'ethereumSlotDuration' | 'l1GenesisTime' | 'slotDuration' | 'rollupManaLimit' | 'epochDuration'
|
|
6
6
|
>;
|
package/src/test/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
2
2
|
import type { PublisherManager } from '@aztec/ethereum/publisher-manager';
|
|
3
3
|
import type { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
4
|
+
import type { ProposerTimetable } from '@aztec/stdlib/timetable';
|
|
4
5
|
import type { FullNodeCheckpointsBuilder, ValidatorClient } from '@aztec/validator-client';
|
|
5
6
|
|
|
6
7
|
import { SequencerClient } from '../client/sequencer-client.js';
|
|
7
8
|
import type { SequencerPublisherFactory } from '../publisher/sequencer-publisher-factory.js';
|
|
8
9
|
import { Sequencer } from '../sequencer/sequencer.js';
|
|
9
|
-
import type { SequencerTimetable } from '../sequencer/timetable.js';
|
|
10
10
|
|
|
11
11
|
class TestSequencer_ extends Sequencer {
|
|
12
12
|
declare public publicProcessorFactory: PublicProcessorFactory;
|
|
13
|
-
declare public timetable:
|
|
13
|
+
declare public timetable: ProposerTimetable;
|
|
14
14
|
declare public publisherFactory: SequencerPublisherFactory;
|
|
15
15
|
declare public validatorClient: ValidatorClient;
|
|
16
16
|
declare public checkpointsBuilder: FullNodeCheckpointsBuilder;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { type BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { type BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import { unfreeze } from '@aztec/foundation/types';
|
|
3
4
|
import { L2Block } from '@aztec/stdlib/block';
|
|
4
5
|
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
5
|
-
import { Gas } from '@aztec/stdlib/gas';
|
|
6
6
|
import type {
|
|
7
|
+
BlockBuilderOptions,
|
|
7
8
|
FullNodeBlockBuilderConfig,
|
|
8
9
|
ICheckpointBlockBuilder,
|
|
9
10
|
ICheckpointsBuilder,
|
|
10
11
|
MerkleTreeWriteOperations,
|
|
11
|
-
PublicProcessorLimits,
|
|
12
12
|
} from '@aztec/stdlib/interfaces/server';
|
|
13
13
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
14
14
|
import { makeAppendOnlyTreeSnapshot } from '@aztec/stdlib/testing';
|
|
@@ -32,7 +32,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
32
32
|
public buildBlockCalls: Array<{
|
|
33
33
|
blockNumber: BlockNumber;
|
|
34
34
|
timestamp: bigint;
|
|
35
|
-
opts:
|
|
35
|
+
opts: BlockBuilderOptions;
|
|
36
36
|
}> = [];
|
|
37
37
|
/** Track all consumed transaction hashes across buildBlock calls */
|
|
38
38
|
public consumedTxHashes: Set<string> = new Set();
|
|
@@ -74,7 +74,7 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
74
74
|
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
75
75
|
blockNumber: BlockNumber,
|
|
76
76
|
timestamp: bigint,
|
|
77
|
-
opts:
|
|
77
|
+
opts: BlockBuilderOptions,
|
|
78
78
|
): Promise<BuildBlockInCheckpointResult> {
|
|
79
79
|
this.buildBlockCalls.push({ blockNumber, timestamp, opts });
|
|
80
80
|
|
|
@@ -86,8 +86,10 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
86
86
|
let usedTxs: Tx[];
|
|
87
87
|
|
|
88
88
|
if (this.blockProvider) {
|
|
89
|
-
// Dynamic mode: get block from provider
|
|
90
|
-
block = this.blockProvider();
|
|
89
|
+
// Dynamic mode: get block from provider, cloning to avoid shared references across multiple buildBlock calls
|
|
90
|
+
block = L2Block.fromBuffer(this.blockProvider().toBuffer());
|
|
91
|
+
block.header.globalVariables.blockNumber = blockNumber;
|
|
92
|
+
await block.header.recomputeHash();
|
|
91
93
|
usedTxs = [];
|
|
92
94
|
this.builtBlocks.push(block);
|
|
93
95
|
} else {
|
|
@@ -113,81 +115,79 @@ export class MockCheckpointBuilder implements ICheckpointBlockBuilder {
|
|
|
113
115
|
|
|
114
116
|
return {
|
|
115
117
|
block,
|
|
116
|
-
publicGas: Gas.empty(),
|
|
117
118
|
publicProcessorDuration: 0,
|
|
118
119
|
numTxs: block?.body?.txEffects?.length ?? usedTxs.length,
|
|
119
120
|
usedTxs,
|
|
120
121
|
failedTxs: [],
|
|
121
|
-
usedTxBlobFields: block?.body?.txEffects?.reduce((sum, tx) => sum + tx.getNumBlobFields(), 0) ?? 0,
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
completeCheckpoint(): Promise<Checkpoint> {
|
|
126
126
|
this.completeCheckpointCalled = true;
|
|
127
127
|
const allBlocks = this.blockProvider ? this.builtBlocks : this.blocks;
|
|
128
|
-
|
|
129
|
-
// Create a CheckpointHeader from the last block's header for testing
|
|
130
|
-
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
131
|
-
return Promise.resolve(
|
|
132
|
-
new Checkpoint(
|
|
133
|
-
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
134
|
-
checkpointHeader,
|
|
135
|
-
allBlocks,
|
|
136
|
-
this.checkpointNumber,
|
|
137
|
-
),
|
|
138
|
-
);
|
|
128
|
+
return this.buildCheckpoint(allBlocks);
|
|
139
129
|
}
|
|
140
130
|
|
|
141
131
|
getCheckpoint(): Promise<Checkpoint> {
|
|
142
132
|
this.getCheckpointCalled = true;
|
|
143
133
|
const builtBlocks = this.blockProvider ? this.builtBlocks : this.blocks.slice(0, this.blockIndex);
|
|
144
|
-
|
|
145
|
-
if (!lastBlock) {
|
|
134
|
+
if (builtBlocks.length === 0) {
|
|
146
135
|
throw new Error('No blocks built yet');
|
|
147
136
|
}
|
|
148
|
-
|
|
149
|
-
const checkpointHeader = this.createCheckpointHeader(lastBlock);
|
|
150
|
-
return Promise.resolve(
|
|
151
|
-
new Checkpoint(
|
|
152
|
-
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
153
|
-
checkpointHeader,
|
|
154
|
-
builtBlocks,
|
|
155
|
-
this.checkpointNumber,
|
|
156
|
-
),
|
|
157
|
-
);
|
|
137
|
+
return this.buildCheckpoint(builtBlocks);
|
|
158
138
|
}
|
|
159
139
|
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
140
|
+
/** Builds a structurally valid Checkpoint from a list of blocks, fixing up indexes and archive chaining. */
|
|
141
|
+
private async buildCheckpoint(blocks: L2Block[]): Promise<Checkpoint> {
|
|
142
|
+
// Fix up indexWithinCheckpoint and archive chaining so the checkpoint passes structural validation.
|
|
143
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
144
|
+
blocks[i].indexWithinCheckpoint = IndexWithinCheckpoint(i);
|
|
145
|
+
if (i > 0) {
|
|
146
|
+
unfreeze(blocks[i].header).lastArchive = blocks[i - 1].archive;
|
|
147
|
+
await blocks[i].header.recomputeHash();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const firstBlock = blocks[0];
|
|
152
|
+
const lastBlock = blocks[blocks.length - 1];
|
|
153
|
+
const gv = firstBlock.header.globalVariables;
|
|
154
|
+
|
|
155
|
+
const checkpointHeader = CheckpointHeader.empty({
|
|
156
|
+
lastArchiveRoot: firstBlock.header.lastArchive.root,
|
|
157
|
+
blockHeadersHash: Fr.random(),
|
|
170
158
|
slotNumber: gv.slotNumber,
|
|
171
159
|
timestamp: gv.timestamp,
|
|
172
160
|
coinbase: gv.coinbase,
|
|
173
161
|
feeRecipient: gv.feeRecipient,
|
|
174
162
|
gasFees: gv.gasFees,
|
|
175
|
-
totalManaUsed: header.totalManaUsed,
|
|
163
|
+
totalManaUsed: lastBlock.header.totalManaUsed,
|
|
176
164
|
});
|
|
165
|
+
|
|
166
|
+
return new Checkpoint(
|
|
167
|
+
makeAppendOnlyTreeSnapshot(lastBlock.header.globalVariables.blockNumber + 1),
|
|
168
|
+
checkpointHeader,
|
|
169
|
+
blocks,
|
|
170
|
+
this.checkpointNumber,
|
|
171
|
+
);
|
|
177
172
|
}
|
|
178
173
|
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
this.blocks = [];
|
|
174
|
+
/** Resets per-checkpoint state (built blocks, consumed txs) while preserving config (blockProvider, seeded blocks). */
|
|
175
|
+
resetCheckpointState(): void {
|
|
182
176
|
this.builtBlocks = [];
|
|
183
|
-
this.usedTxsPerBlock = [];
|
|
184
177
|
this.blockIndex = 0;
|
|
185
|
-
this.buildBlockCalls = [];
|
|
186
178
|
this.consumedTxHashes.clear();
|
|
187
179
|
this.completeCheckpointCalled = false;
|
|
188
180
|
this.getCheckpointCalled = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Reset for reuse in another test */
|
|
184
|
+
reset(): void {
|
|
185
|
+
this.blocks = [];
|
|
186
|
+
this.usedTxsPerBlock = [];
|
|
187
|
+
this.buildBlockCalls = [];
|
|
189
188
|
this.errorOnBuild = undefined;
|
|
190
189
|
this.blockProvider = undefined;
|
|
190
|
+
this.resetCheckpointState();
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -249,6 +249,7 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
249
249
|
slotDuration: 24,
|
|
250
250
|
l1ChainId: 1,
|
|
251
251
|
rollupVersion: 1,
|
|
252
|
+
rollupManaLimit: 200_000_000,
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
255
|
|
|
@@ -275,6 +276,8 @@ export class MockCheckpointsBuilder implements ICheckpointsBuilder {
|
|
|
275
276
|
if (!this.checkpointBuilder) {
|
|
276
277
|
// Auto-create a builder if none was set
|
|
277
278
|
this.checkpointBuilder = new MockCheckpointBuilder(constants, checkpointNumber);
|
|
279
|
+
} else {
|
|
280
|
+
this.checkpointBuilder.resetCheckpointState();
|
|
278
281
|
}
|
|
279
282
|
|
|
280
283
|
return Promise.resolve(this.checkpointBuilder);
|
package/src/test/utils.ts
CHANGED
|
@@ -8,9 +8,22 @@ import { Signature } from '@aztec/foundation/eth-signature';
|
|
|
8
8
|
import type { P2P } from '@aztec/p2p';
|
|
9
9
|
import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
10
10
|
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
|
+
import { DEFAULT_BLOCK_DURATION_MS } from '@aztec/stdlib/config';
|
|
12
|
+
import type { L1RollupConstants } from '@aztec/stdlib/epoch-helpers';
|
|
11
13
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
14
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
17
|
+
makeAppendOnlyTreeSnapshot,
|
|
18
|
+
mockTxForRollup,
|
|
19
|
+
} from '@aztec/stdlib/testing';
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
|
|
22
|
+
DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
|
|
23
|
+
DEFAULT_MIN_BLOCK_DURATION,
|
|
24
|
+
DEFAULT_P2P_PROPAGATION_TIME,
|
|
25
|
+
ProposerTimetable,
|
|
26
|
+
} from '@aztec/stdlib/timetable';
|
|
14
27
|
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
15
28
|
|
|
16
29
|
import type { MockProxy } from 'jest-mock-extended';
|
|
@@ -18,6 +31,28 @@ import type { MockProxy } from 'jest-mock-extended';
|
|
|
18
31
|
// Re-export mock classes from their dedicated file
|
|
19
32
|
export { MockCheckpointBuilder, MockCheckpointsBuilder } from './mock_checkpoint_builder.js';
|
|
20
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Builds a {@link ProposerTimetable} for tests from a millisecond block duration and optional budgets,
|
|
36
|
+
* filling unset budgets with the shared `DEFAULT_*` values the sequencer config layer applies. Mirrors how
|
|
37
|
+
* the sequencer constructs its timetable so tests exercise the same budget resolution.
|
|
38
|
+
*/
|
|
39
|
+
export function makeProposerTimetable(opts: {
|
|
40
|
+
l1Constants: Pick<L1RollupConstants, 'l1GenesisTime' | 'slotDuration' | 'ethereumSlotDuration'>;
|
|
41
|
+
blockDurationMs?: number;
|
|
42
|
+
minBlockDuration?: number;
|
|
43
|
+
p2pPropagationTime?: number;
|
|
44
|
+
checkpointProposalPrepareTime?: number;
|
|
45
|
+
}): ProposerTimetable {
|
|
46
|
+
return new ProposerTimetable({
|
|
47
|
+
l1Constants: opts.l1Constants,
|
|
48
|
+
blockDuration: (opts.blockDurationMs ?? DEFAULT_BLOCK_DURATION_MS) / 1000,
|
|
49
|
+
minBlockDuration: opts.minBlockDuration ?? DEFAULT_MIN_BLOCK_DURATION,
|
|
50
|
+
p2pPropagationTime: opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME,
|
|
51
|
+
checkpointProposalPrepareTime: opts.checkpointProposalPrepareTime ?? DEFAULT_CHECKPOINT_PROPOSAL_PREPARE_TIME,
|
|
52
|
+
checkpointProposalInitTime: DEFAULT_CHECKPOINT_PROPOSAL_INIT_TIME,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
21
56
|
/**
|
|
22
57
|
* Creates a mock transaction with a specific seed for deterministic testing
|
|
23
58
|
*/
|
|
@@ -55,6 +90,7 @@ export async function makeBlock(txs: Tx[], globalVariables: GlobalVariables): Pr
|
|
|
55
90
|
*/
|
|
56
91
|
export function mockPendingTxs(p2p: MockProxy<P2P>, txs: Tx[]): void {
|
|
57
92
|
p2p.getPendingTxCount.mockResolvedValue(txs.length);
|
|
93
|
+
p2p.hasEligiblePendingTxs.mockImplementation(minCount => Promise.resolve(txs.length >= minCount));
|
|
58
94
|
p2p.iteratePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
59
95
|
p2p.iterateEligiblePendingTxs.mockImplementation(() => mockTxIterator(Promise.resolve(txs)));
|
|
60
96
|
}
|
|
@@ -94,6 +130,7 @@ function createCheckpointHeaderFromBlock(block: L2Block): CheckpointHeader {
|
|
|
94
130
|
gv.feeRecipient,
|
|
95
131
|
gv.gasFees,
|
|
96
132
|
block.header.totalManaUsed,
|
|
133
|
+
block.header.totalFees,
|
|
97
134
|
);
|
|
98
135
|
}
|
|
99
136
|
|
|
@@ -109,6 +146,7 @@ export function createBlockProposal(block: L2Block, signature: Signature): Block
|
|
|
109
146
|
block.archive.root,
|
|
110
147
|
txHashes,
|
|
111
148
|
signature,
|
|
149
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
112
150
|
);
|
|
113
151
|
}
|
|
114
152
|
|
|
@@ -123,12 +161,19 @@ export function createCheckpointProposal(
|
|
|
123
161
|
): CheckpointProposal {
|
|
124
162
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
125
163
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
126
|
-
return new CheckpointProposal(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
164
|
+
return new CheckpointProposal(
|
|
165
|
+
checkpointHeader,
|
|
166
|
+
block.archive.root,
|
|
167
|
+
feeAssetPriceModifier,
|
|
168
|
+
checkpointSignature,
|
|
169
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
170
|
+
{
|
|
171
|
+
blockHeader: block.header,
|
|
172
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
173
|
+
txHashes,
|
|
174
|
+
signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
|
|
175
|
+
},
|
|
176
|
+
);
|
|
132
177
|
}
|
|
133
178
|
|
|
134
179
|
/**
|
|
@@ -143,10 +188,16 @@ export function createCheckpointAttestation(
|
|
|
143
188
|
feeAssetPriceModifier: bigint = 0n,
|
|
144
189
|
): CheckpointAttestation {
|
|
145
190
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
146
|
-
const payload = new ConsensusPayload(
|
|
191
|
+
const payload = new ConsensusPayload(
|
|
192
|
+
checkpointHeader,
|
|
193
|
+
block.archive.root,
|
|
194
|
+
feeAssetPriceModifier,
|
|
195
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
196
|
+
);
|
|
147
197
|
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
148
|
-
//
|
|
149
|
-
(attestation as any).
|
|
198
|
+
// Bypass signature recovery for testing since we use random signatures
|
|
199
|
+
(attestation as any).getSender = () => sender;
|
|
200
|
+
(attestation as any).getProposer = () => sender;
|
|
150
201
|
return attestation;
|
|
151
202
|
}
|
|
152
203
|
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { SequencerMetrics } from './metrics.js';
|
|
2
|
-
import { SequencerState } from './utils.js';
|
|
3
|
-
export declare class SequencerTimetable {
|
|
4
|
-
private readonly metrics?;
|
|
5
|
-
private readonly log;
|
|
6
|
-
/**
|
|
7
|
-
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
8
|
-
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
9
|
-
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
10
|
-
*/
|
|
11
|
-
readonly initializeDeadline: number;
|
|
12
|
-
/**
|
|
13
|
-
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
14
|
-
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
15
|
-
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
16
|
-
*/
|
|
17
|
-
readonly initializationOffset: number;
|
|
18
|
-
/**
|
|
19
|
-
* Total time needed to finalize and publish a checkpoint, including:
|
|
20
|
-
* - Assembling the checkpoint
|
|
21
|
-
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
22
|
-
* - Publishing to L1
|
|
23
|
-
*/
|
|
24
|
-
readonly checkpointFinalizationTime: number;
|
|
25
|
-
/**
|
|
26
|
-
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
27
|
-
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
28
|
-
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
29
|
-
*/
|
|
30
|
-
readonly l1PublishingTime: number;
|
|
31
|
-
/**
|
|
32
|
-
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
33
|
-
* Defaults to half of the block duration if set, otherwise a constant.
|
|
34
|
-
*/
|
|
35
|
-
readonly minExecutionTime: number;
|
|
36
|
-
/** How long it takes to get ready to start building */
|
|
37
|
-
readonly checkpointInitializationTime: number;
|
|
38
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */
|
|
39
|
-
readonly p2pPropagationTime: number;
|
|
40
|
-
/** How much time we spend assembling a checkpoint after building the last block */
|
|
41
|
-
readonly checkpointAssembleTime: number;
|
|
42
|
-
/** Ethereum slot duration in seconds */
|
|
43
|
-
readonly ethereumSlotDuration: number;
|
|
44
|
-
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */
|
|
45
|
-
readonly aztecSlotDuration: number;
|
|
46
|
-
/** Whether assertTimeLeft will throw if not enough time. */
|
|
47
|
-
readonly enforce: boolean;
|
|
48
|
-
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */
|
|
49
|
-
readonly blockDuration: number | undefined;
|
|
50
|
-
/** Maximum number of blocks that can be built in this slot configuration */
|
|
51
|
-
readonly maxNumberOfBlocks: number;
|
|
52
|
-
constructor(opts: {
|
|
53
|
-
ethereumSlotDuration: number;
|
|
54
|
-
aztecSlotDuration: number;
|
|
55
|
-
l1PublishingTime: number;
|
|
56
|
-
p2pPropagationTime?: number;
|
|
57
|
-
blockDurationMs?: number;
|
|
58
|
-
enforce: boolean;
|
|
59
|
-
}, metrics?: SequencerMetrics | undefined, log?: import("@aztec/aztec.js/log").Logger);
|
|
60
|
-
getMaxAllowedTime(state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): undefined;
|
|
61
|
-
getMaxAllowedTime(state: Exclude<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>): number;
|
|
62
|
-
getMaxAllowedTime(state: SequencerState): number | undefined;
|
|
63
|
-
assertTimeLeft(newState: SequencerState, secondsIntoSlot: number): void;
|
|
64
|
-
/**
|
|
65
|
-
* Determines if we can start building the next block and returns its deadline.
|
|
66
|
-
*
|
|
67
|
-
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
68
|
-
* available sub-slot that has enough time remaining to build a block.
|
|
69
|
-
*
|
|
70
|
-
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
71
|
-
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
72
|
-
*/
|
|
73
|
-
canStartNextBlock(secondsIntoSlot: number): {
|
|
74
|
-
canStart: true;
|
|
75
|
-
deadline: undefined;
|
|
76
|
-
isLastBlock: true;
|
|
77
|
-
} | {
|
|
78
|
-
canStart: false;
|
|
79
|
-
deadline: undefined;
|
|
80
|
-
isLastBlock: false;
|
|
81
|
-
} | {
|
|
82
|
-
canStart: boolean;
|
|
83
|
-
deadline: number;
|
|
84
|
-
isLastBlock: boolean;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGltZXRhYmxlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VxdWVuY2VyL3RpbWV0YWJsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFTQSxPQUFPLEtBQUssRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUNyRCxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sWUFBWSxDQUFDO0FBRTVDLHFCQUFhLGtCQUFrQjtJQXFFM0IsT0FBTyxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUM7SUFDekIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxHQUFHO0lBckV0Qjs7OztPQUlHO0lBQ0gsU0FBZ0Isa0JBQWtCLEVBQUUsTUFBTSxDQUFDO0lBRTNDOzs7O09BSUc7SUFDSCxTQUFnQixvQkFBb0IsRUFBRSxNQUFNLENBQUM7SUFFN0M7Ozs7O09BS0c7SUFDSCxTQUFnQiwwQkFBMEIsRUFBRSxNQUFNLENBQUM7SUFFbkQ7Ozs7T0FJRztJQUNILFNBQWdCLGdCQUFnQixFQUFFLE1BQU0sQ0FBQztJQUV6Qzs7O09BR0c7SUFDSCxTQUFnQixnQkFBZ0IsRUFBRSxNQUFNLENBQXNCO0lBRTlELHVEQUF1RDtJQUN2RCxTQUFnQiw0QkFBNEIsRUFBRSxNQUFNLENBQWtDO0lBRXRGLG1HQUFtRztJQUNuRyxTQ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2B7D,cAAc,CAAC,QAAQ,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,QAiBtE;IAED;;;;;;;;OAQG;IACI,iBAAiB,CACtB,eAAe,EAAE,MAAM,GAErB;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,IAAI,CAAA;KAAE,GAC1D;QAAE,QAAQ,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAC;QAAC,WAAW,EAAE,KAAK,CAAA;KAAE,GAC5D;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,CAwDhE;CACF"}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
-
import { CHECKPOINT_ASSEMBLE_TIME, CHECKPOINT_INITIALIZATION_TIME, DEFAULT_P2P_PROPAGATION_TIME, MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
3
|
-
import { SequencerTooSlowError } from './errors.js';
|
|
4
|
-
import { SequencerState } from './utils.js';
|
|
5
|
-
export class SequencerTimetable {
|
|
6
|
-
metrics;
|
|
7
|
-
log;
|
|
8
|
-
/**
|
|
9
|
-
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
10
|
-
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
11
|
-
* starts building at this time, and all times hold, it will have at least `minExecutionTime` to execute txs for the block.
|
|
12
|
-
*/ initializeDeadline;
|
|
13
|
-
/**
|
|
14
|
-
* Fixed time offset (in seconds) when the first sub-slot starts, used as baseline for all block deadlines.
|
|
15
|
-
* This is an estimate of how long initialization (sync + proposer check) typically takes.
|
|
16
|
-
* If actual initialization takes longer/shorter, blocks just get less/more time accordingly.
|
|
17
|
-
*/ initializationOffset;
|
|
18
|
-
/**
|
|
19
|
-
* Total time needed to finalize and publish a checkpoint, including:
|
|
20
|
-
* - Assembling the checkpoint
|
|
21
|
-
* - Round-trip p2p propagation for the checkpoint proposal and its corresponding attestations
|
|
22
|
-
* - Publishing to L1
|
|
23
|
-
*/ checkpointFinalizationTime;
|
|
24
|
-
/**
|
|
25
|
-
* How long it takes to get a published block into L1. L1 builders typically accept txs up to 4 seconds into their slot,
|
|
26
|
-
* but we'll timeout sooner to give it more time to propagate (remember we also have blobs!). Still, when working in anvil,
|
|
27
|
-
* we can just post in the very last second of the L1 slot and still expect the tx to be accepted.
|
|
28
|
-
*/ l1PublishingTime;
|
|
29
|
-
/**
|
|
30
|
-
* What's the minimum time we want to leave available for execution and reexecution (used to derive init deadline)
|
|
31
|
-
* Defaults to half of the block duration if set, otherwise a constant.
|
|
32
|
-
*/ minExecutionTime;
|
|
33
|
-
/** How long it takes to get ready to start building */ checkpointInitializationTime;
|
|
34
|
-
/** How long it takes to for proposals and attestations to travel across the p2p layer (one-way) */ p2pPropagationTime;
|
|
35
|
-
/** How much time we spend assembling a checkpoint after building the last block */ checkpointAssembleTime;
|
|
36
|
-
/** Ethereum slot duration in seconds */ ethereumSlotDuration;
|
|
37
|
-
/** Aztec slot duration in seconds (must be multiple of ethereum slot duration) */ aztecSlotDuration;
|
|
38
|
-
/** Whether assertTimeLeft will throw if not enough time. */ enforce;
|
|
39
|
-
/** Duration per block when building multiple blocks per slot (undefined = single block per slot) */ blockDuration;
|
|
40
|
-
/** Maximum number of blocks that can be built in this slot configuration */ maxNumberOfBlocks;
|
|
41
|
-
constructor(opts, metrics, log = createLogger('sequencer:timetable')){
|
|
42
|
-
this.metrics = metrics;
|
|
43
|
-
this.log = log;
|
|
44
|
-
this.minExecutionTime = MIN_EXECUTION_TIME;
|
|
45
|
-
this.checkpointInitializationTime = CHECKPOINT_INITIALIZATION_TIME;
|
|
46
|
-
this.checkpointAssembleTime = CHECKPOINT_ASSEMBLE_TIME;
|
|
47
|
-
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
48
|
-
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
49
|
-
this.l1PublishingTime = opts.l1PublishingTime;
|
|
50
|
-
this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
|
|
51
|
-
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
52
|
-
this.enforce = opts.enforce;
|
|
53
|
-
// Assume zero-cost propagation time and faster runs in test environments where L1 slot duration is shortened
|
|
54
|
-
if (this.ethereumSlotDuration < 8) {
|
|
55
|
-
this.p2pPropagationTime = 0;
|
|
56
|
-
this.checkpointAssembleTime = 0.5;
|
|
57
|
-
this.checkpointInitializationTime = 0.5;
|
|
58
|
-
this.minExecutionTime = 1;
|
|
59
|
-
}
|
|
60
|
-
// Min execution time cannot be less than the block duration if set
|
|
61
|
-
if (this.blockDuration !== undefined && this.minExecutionTime > this.blockDuration) {
|
|
62
|
-
this.minExecutionTime = this.blockDuration;
|
|
63
|
-
}
|
|
64
|
-
// Calculate initialization offset - estimate of time needed for sync + proposer check
|
|
65
|
-
// This is the baseline for all sub-slot deadlines
|
|
66
|
-
this.initializationOffset = this.checkpointInitializationTime;
|
|
67
|
-
// Calculate total checkpoint finalization time (assembly + attestations + L1 publishing)
|
|
68
|
-
this.checkpointFinalizationTime = this.checkpointAssembleTime + this.p2pPropagationTime * 2 + // Round-trip propagation
|
|
69
|
-
this.l1PublishingTime; // L1 publishing
|
|
70
|
-
// Calculate maximum number of blocks that fit in this slot
|
|
71
|
-
if (!this.blockDuration) {
|
|
72
|
-
this.maxNumberOfBlocks = 1; // Single block per slot
|
|
73
|
-
} else {
|
|
74
|
-
const timeReservedAtEnd = this.blockDuration + // Last sub-slot for validator re-execution
|
|
75
|
-
this.checkpointFinalizationTime; // Checkpoint finalization
|
|
76
|
-
const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
|
|
77
|
-
this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
|
|
78
|
-
}
|
|
79
|
-
// Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
|
|
80
|
-
const minWorkToDo = this.initializationOffset + this.minExecutionTime * 2 + // Execution and reexecution
|
|
81
|
-
this.checkpointFinalizationTime;
|
|
82
|
-
const initializeDeadline = this.aztecSlotDuration - minWorkToDo;
|
|
83
|
-
this.initializeDeadline = initializeDeadline;
|
|
84
|
-
this.log.info(`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`, {
|
|
85
|
-
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
86
|
-
aztecSlotDuration: this.aztecSlotDuration,
|
|
87
|
-
l1PublishingTime: this.l1PublishingTime,
|
|
88
|
-
minExecutionTime: this.minExecutionTime,
|
|
89
|
-
blockPrepareTime: this.checkpointInitializationTime,
|
|
90
|
-
p2pPropagationTime: this.p2pPropagationTime,
|
|
91
|
-
blockAssembleTime: this.checkpointAssembleTime,
|
|
92
|
-
initializeDeadline: this.initializeDeadline,
|
|
93
|
-
enforce: this.enforce,
|
|
94
|
-
minWorkToDo,
|
|
95
|
-
blockDuration: this.blockDuration,
|
|
96
|
-
maxNumberOfBlocks: this.maxNumberOfBlocks
|
|
97
|
-
});
|
|
98
|
-
if (initializeDeadline <= 0) {
|
|
99
|
-
throw new Error(`Block proposal initialize deadline cannot be negative (got ${initializeDeadline} from total time needed ${minWorkToDo} and a slot duration of ${this.aztecSlotDuration}).`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
getMaxAllowedTime(state) {
|
|
103
|
-
switch(state){
|
|
104
|
-
case SequencerState.STOPPED:
|
|
105
|
-
case SequencerState.STOPPING:
|
|
106
|
-
case SequencerState.IDLE:
|
|
107
|
-
case SequencerState.SYNCHRONIZING:
|
|
108
|
-
return; // We don't really care about times for this states
|
|
109
|
-
case SequencerState.PROPOSER_CHECK:
|
|
110
|
-
case SequencerState.INITIALIZING_CHECKPOINT:
|
|
111
|
-
return this.initializeDeadline;
|
|
112
|
-
case SequencerState.WAITING_FOR_TXS:
|
|
113
|
-
case SequencerState.CREATING_BLOCK:
|
|
114
|
-
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
115
|
-
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
116
|
-
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
117
|
-
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
118
|
-
return this.aztecSlotDuration - this.l1PublishingTime - 2 * this.p2pPropagationTime;
|
|
119
|
-
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
120
|
-
return this.aztecSlotDuration - this.l1PublishingTime;
|
|
121
|
-
default:
|
|
122
|
-
{
|
|
123
|
-
const _exhaustiveCheck = state;
|
|
124
|
-
throw new Error(`Unexpected state: ${state}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
assertTimeLeft(newState, secondsIntoSlot) {
|
|
129
|
-
if (!this.enforce) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const maxAllowedTime = this.getMaxAllowedTime(newState);
|
|
133
|
-
if (maxAllowedTime === undefined) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const bufferSeconds = maxAllowedTime - secondsIntoSlot;
|
|
137
|
-
if (bufferSeconds < 0) {
|
|
138
|
-
throw new SequencerTooSlowError(newState, maxAllowedTime, secondsIntoSlot);
|
|
139
|
-
}
|
|
140
|
-
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
141
|
-
this.log.trace(`Enough time to transition to ${newState}`, {
|
|
142
|
-
maxAllowedTime,
|
|
143
|
-
secondsIntoSlot
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Determines if we can start building the next block and returns its deadline.
|
|
148
|
-
*
|
|
149
|
-
* The timetable divides the slot into fixed sub-slots. This method finds the next
|
|
150
|
-
* available sub-slot that has enough time remaining to build a block.
|
|
151
|
-
*
|
|
152
|
-
* @param secondsIntoSlot - Current time (seconds into the slot)
|
|
153
|
-
* @returns Object with canStart flag, deadline, and whether this is the last block
|
|
154
|
-
*/ canStartNextBlock(secondsIntoSlot) {
|
|
155
|
-
// When timetable enforcement is disabled, always allow starting,
|
|
156
|
-
// and build a single block with no deadline. This is here just to
|
|
157
|
-
// satisfy a subset of e2e tests and the sandbox that assume that the
|
|
158
|
-
// sequencer is permanently mining every tx sent.
|
|
159
|
-
if (!this.enforce) {
|
|
160
|
-
return {
|
|
161
|
-
canStart: true,
|
|
162
|
-
deadline: undefined,
|
|
163
|
-
isLastBlock: true
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
// If no block duration is set, then we're in single-block mode, which
|
|
167
|
-
// is handled for backwards compatibility towards another subset of e2e tests.
|
|
168
|
-
if (this.blockDuration === undefined) {
|
|
169
|
-
// In single block mode, execution and re-execution happen sequentially, so we need to
|
|
170
|
-
// split the available time between them. After building, we need time for attestations and L1.
|
|
171
|
-
const maxAllowed = this.aztecSlotDuration - this.checkpointFinalizationTime;
|
|
172
|
-
const available = (maxAllowed - secondsIntoSlot) / 2; // Split remaining time: half for execution, half for re-execution
|
|
173
|
-
const canStart = available >= this.minExecutionTime;
|
|
174
|
-
const deadline = secondsIntoSlot + available;
|
|
175
|
-
this.log.verbose(`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`, {
|
|
176
|
-
secondsIntoSlot,
|
|
177
|
-
maxAllowed,
|
|
178
|
-
available,
|
|
179
|
-
deadline
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
canStart,
|
|
183
|
-
deadline,
|
|
184
|
-
isLastBlock: true
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
// Otherwise, we're in multi-block-per-slot mode, the default when running in production
|
|
188
|
-
// Find the next available sub-slot that has enough time remaining
|
|
189
|
-
for(let subSlot = 1; subSlot <= this.maxNumberOfBlocks; subSlot++){
|
|
190
|
-
// Calculate end for this sub-slot
|
|
191
|
-
const deadline = this.initializationOffset + subSlot * this.blockDuration;
|
|
192
|
-
// Check if we have enough time to build a block with this deadline
|
|
193
|
-
const timeUntilDeadline = deadline - secondsIntoSlot;
|
|
194
|
-
if (timeUntilDeadline >= this.minExecutionTime) {
|
|
195
|
-
// Found an available sub-slot! Is this the last one?
|
|
196
|
-
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
197
|
-
this.log.verbose(`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`, {
|
|
198
|
-
secondsIntoSlot,
|
|
199
|
-
deadline,
|
|
200
|
-
timeUntilDeadline,
|
|
201
|
-
subSlot,
|
|
202
|
-
maxBlocks: this.maxNumberOfBlocks
|
|
203
|
-
});
|
|
204
|
-
return {
|
|
205
|
-
canStart: true,
|
|
206
|
-
deadline,
|
|
207
|
-
isLastBlock
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// No sub-slots available with enough time
|
|
212
|
-
this.log.verbose(`No time left to start any more blocks`, {
|
|
213
|
-
secondsIntoSlot,
|
|
214
|
-
maxBlocks: this.maxNumberOfBlocks,
|
|
215
|
-
initializationOffset: this.initializationOffset
|
|
216
|
-
});
|
|
217
|
-
return {
|
|
218
|
-
canStart: false,
|
|
219
|
-
deadline: undefined,
|
|
220
|
-
isLastBlock: false
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
}
|