@aztec/sequencer-client 0.0.1-commit.181e2d196 → 0.0.1-commit.189eedb3
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/sequencer-client.d.ts +8 -3
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +51 -29
- package/dest/config.d.ts +26 -3
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +51 -22
- 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 +14 -14
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +16 -50
- 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 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -1
- package/dest/publisher/config.d.ts +15 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +19 -4
- 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 +73 -65
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +318 -523
- 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 +60 -12
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -1
- package/dest/sequencer/checkpoint_proposal_job.js +774 -219
- 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/events.d.ts +48 -2
- package/dest/sequencer/events.d.ts.map +1 -1
- package/dest/sequencer/index.d.ts +3 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +2 -0
- package/dest/sequencer/metrics.d.ts +13 -10
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +45 -20
- package/dest/sequencer/sequencer.d.ts +68 -17
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +359 -119
- package/dest/sequencer/timetable.d.ts +14 -3
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +47 -43
- package/dest/sequencer/types.d.ts +2 -2
- package/dest/sequencer/types.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 +1 -1
- package/dest/test/utils.d.ts.map +1 -1
- package/dest/test/utils.js +7 -6
- package/package.json +27 -28
- package/src/client/sequencer-client.ts +71 -33
- package/src/config.ts +61 -22
- 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 +25 -62
- package/src/global_variable_builder/index.ts +3 -1
- package/src/index.ts +10 -1
- package/src/publisher/config.ts +40 -6
- 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 +377 -568
- package/src/sequencer/README.md +162 -450
- 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 +923 -251
- package/src/sequencer/checkpoint_proposal_job_metrics.ts +128 -0
- package/src/sequencer/checkpoint_voter.ts +1 -12
- package/src/sequencer/events.ts +51 -2
- package/src/sequencer/index.ts +2 -0
- package/src/sequencer/metrics.ts +57 -24
- package/src/sequencer/sequencer.ts +440 -134
- package/src/sequencer/timetable.ts +56 -51
- package/src/sequencer/types.ts +1 -1
- package/src/test/mock_checkpoint_builder.ts +51 -48
- package/src/test/utils.ts +28 -10
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
2
2
|
import {
|
|
3
3
|
CHECKPOINT_ASSEMBLE_TIME,
|
|
4
4
|
CHECKPOINT_INITIALIZATION_TIME,
|
|
5
|
+
type CheckpointTiming,
|
|
5
6
|
DEFAULT_P2P_PROPAGATION_TIME,
|
|
6
7
|
MIN_EXECUTION_TIME,
|
|
8
|
+
createCheckpointTimingModel,
|
|
7
9
|
} from '@aztec/stdlib/timetable';
|
|
8
10
|
|
|
9
11
|
import { SequencerTooSlowError } from './errors.js';
|
|
@@ -11,6 +13,8 @@ import type { SequencerMetrics } from './metrics.js';
|
|
|
11
13
|
import { SequencerState } from './utils.js';
|
|
12
14
|
|
|
13
15
|
export class SequencerTimetable {
|
|
16
|
+
private readonly checkpointTiming: CheckpointTiming;
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
* How late into the slot can we be to start working. Computed as the total time needed for assembling and publishing a block,
|
|
16
20
|
* assuming an execution time equal to `minExecutionTime`, subtracted from the slot duration. This means that, if the proposer
|
|
@@ -70,6 +74,12 @@ export class SequencerTimetable {
|
|
|
70
74
|
/** Maximum number of blocks that can be built in this slot configuration */
|
|
71
75
|
public readonly maxNumberOfBlocks: number;
|
|
72
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
|
+
|
|
73
83
|
constructor(
|
|
74
84
|
opts: {
|
|
75
85
|
ethereumSlotDuration: number;
|
|
@@ -80,59 +90,36 @@ export class SequencerTimetable {
|
|
|
80
90
|
enforce: boolean;
|
|
81
91
|
},
|
|
82
92
|
private readonly metrics?: SequencerMetrics,
|
|
83
|
-
private readonly log
|
|
93
|
+
private readonly log?: Logger,
|
|
84
94
|
) {
|
|
85
95
|
this.ethereumSlotDuration = opts.ethereumSlotDuration;
|
|
86
96
|
this.aztecSlotDuration = opts.aztecSlotDuration;
|
|
87
97
|
this.l1PublishingTime = opts.l1PublishingTime;
|
|
88
|
-
this.p2pPropagationTime = opts.p2pPropagationTime ?? DEFAULT_P2P_PROPAGATION_TIME;
|
|
89
98
|
this.blockDuration = opts.blockDurationMs ? opts.blockDurationMs / 1000 : undefined;
|
|
90
99
|
this.enforce = opts.enforce;
|
|
91
100
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.
|
|
95
|
-
this.
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
}
|
|
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
|
+
});
|
|
99
108
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
109
|
+
this.p2pPropagationTime = this.checkpointTiming.p2pPropagationTime;
|
|
110
|
+
this.checkpointAssembleTime = this.checkpointTiming.checkpointAssembleTime;
|
|
111
|
+
this.checkpointInitializationTime = this.checkpointTiming.checkpointInitializationTime;
|
|
112
|
+
this.minExecutionTime = this.checkpointTiming.minExecutionTime;
|
|
104
113
|
|
|
105
114
|
// Calculate initialization offset - estimate of time needed for sync + proposer check
|
|
106
115
|
// This is the baseline for all sub-slot deadlines
|
|
107
|
-
this.initializationOffset = this.checkpointInitializationTime;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
this.p2pPropagationTime * 2 + // Round-trip propagation
|
|
113
|
-
this.l1PublishingTime; // L1 publishing
|
|
114
|
-
|
|
115
|
-
// Calculate maximum number of blocks that fit in this slot
|
|
116
|
-
if (!this.blockDuration) {
|
|
117
|
-
this.maxNumberOfBlocks = 1; // Single block per slot
|
|
118
|
-
} else {
|
|
119
|
-
const timeReservedAtEnd =
|
|
120
|
-
this.blockDuration + // Last sub-slot for validator re-execution
|
|
121
|
-
this.checkpointFinalizationTime; // Checkpoint finalization
|
|
122
|
-
const timeAvailableForBlocks = this.aztecSlotDuration - this.initializationOffset - timeReservedAtEnd;
|
|
123
|
-
this.maxNumberOfBlocks = Math.floor(timeAvailableForBlocks / this.blockDuration);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Minimum work to do within a slot for building a block with the minimum time for execution and publishing its checkpoint
|
|
127
|
-
const minWorkToDo =
|
|
128
|
-
this.initializationOffset +
|
|
129
|
-
this.minExecutionTime * 2 + // Execution and reexecution
|
|
130
|
-
this.checkpointFinalizationTime;
|
|
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;
|
|
131
121
|
|
|
132
|
-
|
|
133
|
-
this.initializeDeadline = initializeDeadline;
|
|
134
|
-
|
|
135
|
-
this.log.info(
|
|
122
|
+
this.log?.info(
|
|
136
123
|
`Sequencer timetable initialized with ${this.maxNumberOfBlocks} blocks per slot (${this.enforce ? 'enforced' : 'not enforced'})`,
|
|
137
124
|
{
|
|
138
125
|
ethereumSlotDuration: this.ethereumSlotDuration,
|
|
@@ -144,19 +131,36 @@ export class SequencerTimetable {
|
|
|
144
131
|
blockAssembleTime: this.checkpointAssembleTime,
|
|
145
132
|
initializeDeadline: this.initializeDeadline,
|
|
146
133
|
enforce: this.enforce,
|
|
147
|
-
|
|
134
|
+
pipeliningAttestationGracePeriod: this.pipeliningAttestationGracePeriod,
|
|
135
|
+
minWorkToDo: this.checkpointTiming.minimumBuildSlotWork,
|
|
148
136
|
blockDuration: this.blockDuration,
|
|
149
137
|
maxNumberOfBlocks: this.maxNumberOfBlocks,
|
|
150
138
|
},
|
|
151
139
|
);
|
|
152
140
|
|
|
153
|
-
if (initializeDeadline <= 0) {
|
|
141
|
+
if (this.initializeDeadline <= 0) {
|
|
154
142
|
throw new Error(
|
|
155
|
-
`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}).`,
|
|
156
144
|
);
|
|
157
145
|
}
|
|
158
146
|
}
|
|
159
147
|
|
|
148
|
+
public getCheckpointAssemblyDeadline(): number {
|
|
149
|
+
return this.checkpointTiming.checkpointAssemblyDeadline;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public getCheckpointAttestationDeadline(): number {
|
|
153
|
+
return this.checkpointTiming.checkpointAttestationDeadline;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public getCheckpointAttestationStartDeadline(): number {
|
|
157
|
+
return this.checkpointTiming.checkpointAttestationStartDeadline;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getCheckpointPublishingDeadline(): number {
|
|
161
|
+
return this.checkpointTiming.checkpointPublishingDeadline;
|
|
162
|
+
}
|
|
163
|
+
|
|
160
164
|
public getMaxAllowedTime(
|
|
161
165
|
state: Extract<SequencerState, SequencerState.STOPPED | SequencerState.IDLE | SequencerState.SYNCHRONIZING>,
|
|
162
166
|
): undefined;
|
|
@@ -179,10 +183,11 @@ export class SequencerTimetable {
|
|
|
179
183
|
case SequencerState.WAITING_UNTIL_NEXT_BLOCK:
|
|
180
184
|
return this.initializeDeadline + this.checkpointInitializationTime;
|
|
181
185
|
case SequencerState.ASSEMBLING_CHECKPOINT:
|
|
186
|
+
return this.getCheckpointAssemblyDeadline();
|
|
182
187
|
case SequencerState.COLLECTING_ATTESTATIONS:
|
|
183
|
-
return this.
|
|
188
|
+
return this.getCheckpointAttestationStartDeadline();
|
|
184
189
|
case SequencerState.PUBLISHING_CHECKPOINT:
|
|
185
|
-
return this.
|
|
190
|
+
return this.getCheckpointPublishingDeadline();
|
|
186
191
|
default: {
|
|
187
192
|
const _exhaustiveCheck: never = state;
|
|
188
193
|
throw new Error(`Unexpected state: ${state}`);
|
|
@@ -206,7 +211,7 @@ export class SequencerTimetable {
|
|
|
206
211
|
}
|
|
207
212
|
|
|
208
213
|
this.metrics?.recordStateTransitionBufferMs(Math.floor(bufferSeconds * 1000), newState);
|
|
209
|
-
this.log
|
|
214
|
+
this.log?.trace(`Enough time to transition to ${newState}`, { maxAllowedTime, secondsIntoSlot });
|
|
210
215
|
}
|
|
211
216
|
|
|
212
217
|
/**
|
|
@@ -242,7 +247,7 @@ export class SequencerTimetable {
|
|
|
242
247
|
const canStart = available >= this.minExecutionTime;
|
|
243
248
|
const deadline = secondsIntoSlot + available;
|
|
244
249
|
|
|
245
|
-
this.log
|
|
250
|
+
this.log?.verbose(
|
|
246
251
|
`${canStart ? 'Can' : 'Cannot'} start single-block checkpoint at ${secondsIntoSlot}s into slot`,
|
|
247
252
|
{ secondsIntoSlot, maxAllowed, available, deadline },
|
|
248
253
|
);
|
|
@@ -262,7 +267,7 @@ export class SequencerTimetable {
|
|
|
262
267
|
// Found an available sub-slot! Is this the last one?
|
|
263
268
|
const isLastBlock = subSlot === this.maxNumberOfBlocks;
|
|
264
269
|
|
|
265
|
-
this.log
|
|
270
|
+
this.log?.verbose(
|
|
266
271
|
`Can start ${isLastBlock ? 'last block' : 'block'} in sub-slot ${subSlot} with deadline ${deadline}s`,
|
|
267
272
|
{ secondsIntoSlot, deadline, timeUntilDeadline, subSlot, maxBlocks: this.maxNumberOfBlocks },
|
|
268
273
|
);
|
|
@@ -272,7 +277,7 @@ export class SequencerTimetable {
|
|
|
272
277
|
}
|
|
273
278
|
|
|
274
279
|
// No sub-slots available with enough time
|
|
275
|
-
this.log
|
|
280
|
+
this.log?.verbose(`No time left to start any more blocks`, {
|
|
276
281
|
secondsIntoSlot,
|
|
277
282
|
maxBlocks: this.maxNumberOfBlocks,
|
|
278
283
|
initializationOffset: this.initializationOffset,
|
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
|
>;
|
|
@@ -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
|
@@ -10,7 +10,11 @@ import { PublicDataWrite } from '@aztec/stdlib/avm';
|
|
|
10
10
|
import { CommitteeAttestation, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { BlockProposal, CheckpointAttestation, CheckpointProposal, ConsensusPayload } from '@aztec/stdlib/p2p';
|
|
12
12
|
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
15
|
+
makeAppendOnlyTreeSnapshot,
|
|
16
|
+
mockTxForRollup,
|
|
17
|
+
} from '@aztec/stdlib/testing';
|
|
14
18
|
import { BlockHeader, GlobalVariables, type Tx, makeProcessedTxFromPrivateOnlyTx } from '@aztec/stdlib/tx';
|
|
15
19
|
|
|
16
20
|
import type { MockProxy } from 'jest-mock-extended';
|
|
@@ -109,6 +113,7 @@ export function createBlockProposal(block: L2Block, signature: Signature): Block
|
|
|
109
113
|
block.archive.root,
|
|
110
114
|
txHashes,
|
|
111
115
|
signature,
|
|
116
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
112
117
|
);
|
|
113
118
|
}
|
|
114
119
|
|
|
@@ -123,12 +128,19 @@ export function createCheckpointProposal(
|
|
|
123
128
|
): CheckpointProposal {
|
|
124
129
|
const txHashes = block.body.txEffects.map(tx => tx.txHash);
|
|
125
130
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
126
|
-
return new CheckpointProposal(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
return new CheckpointProposal(
|
|
132
|
+
checkpointHeader,
|
|
133
|
+
block.archive.root,
|
|
134
|
+
feeAssetPriceModifier,
|
|
135
|
+
checkpointSignature,
|
|
136
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
137
|
+
{
|
|
138
|
+
blockHeader: block.header,
|
|
139
|
+
indexWithinCheckpoint: block.indexWithinCheckpoint,
|
|
140
|
+
txHashes,
|
|
141
|
+
signature: blockSignature ?? checkpointSignature, // Use checkpoint signature as block signature if not provided
|
|
142
|
+
},
|
|
143
|
+
);
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
/**
|
|
@@ -143,10 +155,16 @@ export function createCheckpointAttestation(
|
|
|
143
155
|
feeAssetPriceModifier: bigint = 0n,
|
|
144
156
|
): CheckpointAttestation {
|
|
145
157
|
const checkpointHeader = createCheckpointHeaderFromBlock(block);
|
|
146
|
-
const payload = new ConsensusPayload(
|
|
158
|
+
const payload = new ConsensusPayload(
|
|
159
|
+
checkpointHeader,
|
|
160
|
+
block.archive.root,
|
|
161
|
+
feeAssetPriceModifier,
|
|
162
|
+
TEST_COORDINATION_SIGNATURE_CONTEXT,
|
|
163
|
+
);
|
|
147
164
|
const attestation = new CheckpointAttestation(payload, signature, signature);
|
|
148
|
-
//
|
|
149
|
-
(attestation as any).
|
|
165
|
+
// Bypass signature recovery for testing since we use random signatures
|
|
166
|
+
(attestation as any).getSender = () => sender;
|
|
167
|
+
(attestation as any).getProposer = () => sender;
|
|
150
168
|
return attestation;
|
|
151
169
|
}
|
|
152
170
|
|