@aztec/sequencer-client 4.0.0-nightly.20250907 → 4.0.0-nightly.20260108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/client/index.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts +10 -8
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +40 -28
- package/dest/config.d.ts +13 -5
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +82 -25
- package/dest/global_variable_builder/global_builder.d.ts +22 -16
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +52 -39
- package/dest/global_variable_builder/index.d.ts +1 -1
- 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 +11 -8
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/config.js +21 -13
- package/dest/publisher/index.d.ts +2 -2
- package/dest/publisher/index.d.ts.map +1 -1
- package/dest/publisher/index.js +1 -1
- package/dest/publisher/sequencer-publisher-factory.d.ts +11 -5
- package/dest/publisher/sequencer-publisher-factory.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-factory.js +9 -2
- package/dest/publisher/sequencer-publisher-metrics.d.ts +4 -4
- package/dest/publisher/sequencer-publisher-metrics.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher-metrics.js +1 -1
- package/dest/publisher/sequencer-publisher.d.ts +78 -70
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +687 -182
- package/dest/sequencer/block_builder.d.ts +6 -10
- package/dest/sequencer/block_builder.d.ts.map +1 -1
- package/dest/sequencer/block_builder.js +21 -10
- package/dest/sequencer/checkpoint_builder.d.ts +63 -0
- package/dest/sequencer/checkpoint_builder.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_builder.js +131 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts +76 -0
- package/dest/sequencer/checkpoint_proposal_job.d.ts.map +1 -0
- package/dest/sequencer/checkpoint_proposal_job.js +1070 -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 +85 -0
- package/dest/sequencer/config.d.ts +3 -2
- 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 +46 -0
- package/dest/sequencer/events.d.ts.map +1 -0
- package/dest/sequencer/events.js +1 -0
- package/dest/sequencer/index.d.ts +5 -1
- package/dest/sequencer/index.d.ts.map +1 -1
- package/dest/sequencer/index.js +4 -0
- package/dest/sequencer/metrics.d.ts +37 -20
- package/dest/sequencer/metrics.d.ts.map +1 -1
- package/dest/sequencer/metrics.js +211 -85
- package/dest/sequencer/sequencer.d.ts +110 -121
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +809 -524
- package/dest/sequencer/timetable.d.ts +57 -21
- package/dest/sequencer/timetable.d.ts.map +1 -1
- package/dest/sequencer/timetable.js +150 -68
- 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 -28
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +12 -24
- package/dest/test/index.d.ts +4 -2
- package/dest/test/index.d.ts.map +1 -1
- package/dest/test/mock_checkpoint_builder.d.ts +83 -0
- package/dest/test/mock_checkpoint_builder.d.ts.map +1 -0
- package/dest/test/mock_checkpoint_builder.js +179 -0
- package/dest/test/utils.d.ts +49 -0
- package/dest/test/utils.d.ts.map +1 -0
- package/dest/test/utils.js +94 -0
- package/dest/tx_validator/nullifier_cache.d.ts +1 -1
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.d.ts +4 -3
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -1
- package/dest/tx_validator/tx_validator_factory.js +12 -9
- package/package.json +32 -31
- package/src/client/sequencer-client.ts +34 -40
- package/src/config.ts +89 -29
- package/src/global_variable_builder/global_builder.ts +67 -59
- package/src/index.ts +2 -0
- package/src/publisher/config.ts +32 -19
- package/src/publisher/index.ts +1 -1
- package/src/publisher/sequencer-publisher-factory.ts +19 -6
- package/src/publisher/sequencer-publisher-metrics.ts +3 -3
- package/src/publisher/sequencer-publisher.ts +418 -242
- package/src/sequencer/README.md +531 -0
- package/src/sequencer/block_builder.ts +28 -30
- package/src/sequencer/checkpoint_builder.ts +217 -0
- package/src/sequencer/checkpoint_proposal_job.ts +722 -0
- package/src/sequencer/checkpoint_voter.ts +105 -0
- package/src/sequencer/config.ts +2 -1
- package/src/sequencer/errors.ts +21 -0
- package/src/sequencer/events.ts +27 -0
- package/src/sequencer/index.ts +4 -0
- package/src/sequencer/metrics.ts +269 -94
- package/src/sequencer/sequencer.ts +508 -675
- package/src/sequencer/timetable.ts +181 -91
- package/src/sequencer/types.ts +6 -0
- package/src/sequencer/utils.ts +24 -29
- package/src/test/index.ts +3 -1
- package/src/test/mock_checkpoint_builder.ts +247 -0
- package/src/test/utils.ts +137 -0
- package/src/tx_validator/tx_validator_factory.ts +13 -7
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { MerkleTreeId } from '@aztec/aztec.js/trees';
|
|
2
|
+
import { BlockNumber, CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { merge, pick } from '@aztec/foundation/collection';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
6
|
+
import { bufferToHex } from '@aztec/foundation/string';
|
|
7
|
+
import { DateProvider, Timer, elapsed } from '@aztec/foundation/timer';
|
|
8
|
+
import { getDefaultAllowedSetupFunctions } from '@aztec/p2p/msg_validators';
|
|
9
|
+
import { LightweightCheckpointBuilder } from '@aztec/prover-client/light';
|
|
10
|
+
import {
|
|
11
|
+
GuardedMerkleTreeOperations,
|
|
12
|
+
PublicContractsDB,
|
|
13
|
+
PublicProcessor,
|
|
14
|
+
createPublicTxSimulatorForBlockBuilding,
|
|
15
|
+
} from '@aztec/simulator/server';
|
|
16
|
+
import { L2BlockNew } from '@aztec/stdlib/block';
|
|
17
|
+
import { Checkpoint } from '@aztec/stdlib/checkpoint';
|
|
18
|
+
import type { ContractDataSource } from '@aztec/stdlib/contract';
|
|
19
|
+
import { Gas } from '@aztec/stdlib/gas';
|
|
20
|
+
import {
|
|
21
|
+
type FullNodeBlockBuilderConfig,
|
|
22
|
+
FullNodeBlockBuilderConfigKeys,
|
|
23
|
+
type MerkleTreeWriteOperations,
|
|
24
|
+
type PublicProcessorLimits,
|
|
25
|
+
} from '@aztec/stdlib/interfaces/server';
|
|
26
|
+
import { type CheckpointGlobalVariables, type FailedTx, GlobalVariables, Tx } from '@aztec/stdlib/tx';
|
|
27
|
+
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
|
|
28
|
+
|
|
29
|
+
import { createValidatorForBlockBuilding } from '../tx_validator/tx_validator_factory.js';
|
|
30
|
+
|
|
31
|
+
const log = createLogger('checkpoint-builder');
|
|
32
|
+
|
|
33
|
+
export interface BuildBlockInCheckpointResult {
|
|
34
|
+
block: L2BlockNew;
|
|
35
|
+
publicGas: Gas;
|
|
36
|
+
publicProcessorDuration: number;
|
|
37
|
+
numTxs: number;
|
|
38
|
+
failedTxs: FailedTx[];
|
|
39
|
+
blockBuildingTimer: Timer;
|
|
40
|
+
usedTxs: Tx[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builder for a single checkpoint. Handles building blocks within the checkpoint
|
|
45
|
+
* and completing it.
|
|
46
|
+
*/
|
|
47
|
+
export class CheckpointBuilder {
|
|
48
|
+
constructor(
|
|
49
|
+
private checkpointBuilder: LightweightCheckpointBuilder,
|
|
50
|
+
private fork: MerkleTreeWriteOperations,
|
|
51
|
+
private config: FullNodeBlockBuilderConfig,
|
|
52
|
+
private contractDataSource: ContractDataSource,
|
|
53
|
+
private dateProvider: DateProvider,
|
|
54
|
+
private telemetryClient: TelemetryClient,
|
|
55
|
+
) {}
|
|
56
|
+
|
|
57
|
+
getConstantData(): CheckpointGlobalVariables {
|
|
58
|
+
return this.checkpointBuilder.constants;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Builds a single block within this checkpoint.
|
|
63
|
+
*/
|
|
64
|
+
async buildBlock(
|
|
65
|
+
pendingTxs: Iterable<Tx> | AsyncIterable<Tx>,
|
|
66
|
+
blockNumber: BlockNumber,
|
|
67
|
+
timestamp: bigint,
|
|
68
|
+
opts: PublicProcessorLimits,
|
|
69
|
+
): Promise<BuildBlockInCheckpointResult> {
|
|
70
|
+
const blockBuildingTimer = new Timer();
|
|
71
|
+
const slot = this.checkpointBuilder.constants.slotNumber;
|
|
72
|
+
|
|
73
|
+
log.verbose(`Building block ${blockNumber} for slot ${slot} within checkpoint`, { slot, blockNumber, ...opts });
|
|
74
|
+
|
|
75
|
+
const constants = this.checkpointBuilder.constants;
|
|
76
|
+
const globalVariables = GlobalVariables.from({
|
|
77
|
+
chainId: constants.chainId,
|
|
78
|
+
version: constants.version,
|
|
79
|
+
blockNumber,
|
|
80
|
+
slotNumber: constants.slotNumber,
|
|
81
|
+
timestamp,
|
|
82
|
+
coinbase: constants.coinbase,
|
|
83
|
+
feeRecipient: constants.feeRecipient,
|
|
84
|
+
gasFees: constants.gasFees,
|
|
85
|
+
});
|
|
86
|
+
const { processor, validator } = await this.makeBlockBuilderDeps(globalVariables, this.fork);
|
|
87
|
+
|
|
88
|
+
const [publicProcessorDuration, [processedTxs, failedTxs, usedTxs]] = await elapsed(() =>
|
|
89
|
+
processor.process(pendingTxs, opts, validator),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// Add block to checkpoint
|
|
93
|
+
const block = await this.checkpointBuilder.addBlock(globalVariables, processedTxs);
|
|
94
|
+
|
|
95
|
+
// How much public gas was processed
|
|
96
|
+
const publicGas = processedTxs.reduce((acc, tx) => acc.add(tx.gasUsed.publicGas), Gas.empty());
|
|
97
|
+
|
|
98
|
+
const res = {
|
|
99
|
+
block,
|
|
100
|
+
publicGas,
|
|
101
|
+
publicProcessorDuration,
|
|
102
|
+
numTxs: processedTxs.length,
|
|
103
|
+
failedTxs,
|
|
104
|
+
blockBuildingTimer,
|
|
105
|
+
usedTxs,
|
|
106
|
+
};
|
|
107
|
+
log.debug('Built block within checkpoint', res.block.header);
|
|
108
|
+
return res;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Completes the checkpoint and returns it. */
|
|
112
|
+
async completeCheckpoint(): Promise<Checkpoint> {
|
|
113
|
+
const checkpoint = await this.checkpointBuilder.completeCheckpoint();
|
|
114
|
+
|
|
115
|
+
log.verbose(`Completed checkpoint ${checkpoint.number}`, {
|
|
116
|
+
checkpointNumber: checkpoint.number,
|
|
117
|
+
numBlocks: checkpoint.blocks.length,
|
|
118
|
+
archiveRoot: checkpoint.archive.root.toString(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return checkpoint;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Gets the checkpoint currently in progress. */
|
|
125
|
+
getCheckpoint(): Promise<Checkpoint> {
|
|
126
|
+
return this.checkpointBuilder.clone().completeCheckpoint();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
protected async makeBlockBuilderDeps(globalVariables: GlobalVariables, fork: MerkleTreeWriteOperations) {
|
|
130
|
+
const txPublicSetupAllowList = this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
131
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource);
|
|
132
|
+
const guardedFork = new GuardedMerkleTreeOperations(fork);
|
|
133
|
+
|
|
134
|
+
const publicTxSimulator = createPublicTxSimulatorForBlockBuilding(
|
|
135
|
+
guardedFork,
|
|
136
|
+
contractsDB,
|
|
137
|
+
globalVariables,
|
|
138
|
+
this.telemetryClient,
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const processor = new PublicProcessor(
|
|
142
|
+
globalVariables,
|
|
143
|
+
guardedFork,
|
|
144
|
+
contractsDB,
|
|
145
|
+
publicTxSimulator,
|
|
146
|
+
this.dateProvider,
|
|
147
|
+
this.telemetryClient,
|
|
148
|
+
undefined,
|
|
149
|
+
this.config,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const validator = createValidatorForBlockBuilding(
|
|
153
|
+
fork,
|
|
154
|
+
this.contractDataSource,
|
|
155
|
+
globalVariables,
|
|
156
|
+
txPublicSetupAllowList,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
processor,
|
|
161
|
+
validator,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Factory for creating checkpoint builders.
|
|
168
|
+
*/
|
|
169
|
+
export class FullNodeCheckpointsBuilder {
|
|
170
|
+
constructor(
|
|
171
|
+
private config: FullNodeBlockBuilderConfig,
|
|
172
|
+
private contractDataSource: ContractDataSource,
|
|
173
|
+
private dateProvider: DateProvider,
|
|
174
|
+
private telemetryClient: TelemetryClient = getTelemetryClient(),
|
|
175
|
+
) {}
|
|
176
|
+
|
|
177
|
+
public updateConfig(config: Partial<FullNodeBlockBuilderConfig>) {
|
|
178
|
+
this.config = merge(this.config, pick(config, ...FullNodeBlockBuilderConfigKeys));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Starts a new checkpoint and returns a CheckpointBuilder to build blocks within it.
|
|
183
|
+
*/
|
|
184
|
+
async startCheckpoint(
|
|
185
|
+
checkpointNumber: CheckpointNumber,
|
|
186
|
+
constants: CheckpointGlobalVariables,
|
|
187
|
+
l1ToL2Messages: Fr[],
|
|
188
|
+
fork: MerkleTreeWriteOperations,
|
|
189
|
+
): Promise<CheckpointBuilder> {
|
|
190
|
+
const stateReference = await fork.getStateReference();
|
|
191
|
+
const archiveTree = await fork.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
192
|
+
|
|
193
|
+
log.verbose(`Building checkpoint ${checkpointNumber}`, {
|
|
194
|
+
checkpointNumber,
|
|
195
|
+
msgCount: l1ToL2Messages.length,
|
|
196
|
+
initialStateReference: stateReference.toInspect(),
|
|
197
|
+
initialArchiveRoot: bufferToHex(archiveTree.root),
|
|
198
|
+
constants,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const lightweightBuilder = await LightweightCheckpointBuilder.startNewCheckpoint(
|
|
202
|
+
checkpointNumber,
|
|
203
|
+
constants,
|
|
204
|
+
l1ToL2Messages,
|
|
205
|
+
fork,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
return new CheckpointBuilder(
|
|
209
|
+
lightweightBuilder,
|
|
210
|
+
fork,
|
|
211
|
+
this.config,
|
|
212
|
+
this.contractDataSource,
|
|
213
|
+
this.dateProvider,
|
|
214
|
+
this.telemetryClient,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|