@aztec/sequencer-client 0.73.0 → 0.74.0
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/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +9 -4
- package/dest/publisher/sequencer-publisher.d.ts +10 -5
- package/dest/publisher/sequencer-publisher.d.ts.map +1 -1
- package/dest/publisher/sequencer-publisher.js +52 -79
- package/dest/slasher/factory.d.ts +2 -2
- package/dest/slasher/factory.d.ts.map +1 -1
- package/dest/slasher/factory.js +2 -2
- package/dest/slasher/slasher_client.d.ts +4 -4
- package/dest/slasher/slasher_client.d.ts.map +1 -1
- package/dest/slasher/slasher_client.js +34 -25
- package/package.json +21 -21
- package/src/client/sequencer-client.ts +23 -2
- package/src/publisher/sequencer-publisher.ts +70 -90
- package/src/slasher/factory.ts +3 -3
- package/src/slasher/slasher_client.ts +40 -31
|
@@ -10,7 +10,7 @@ import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
|
|
|
10
10
|
import { type L1ContractsConfig, type L1ReaderConfig, createEthereumChain } from '@aztec/ethereum';
|
|
11
11
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
12
12
|
import { createLogger } from '@aztec/foundation/log';
|
|
13
|
-
import {
|
|
13
|
+
import type { AztecAsyncKVStore, AztecAsyncMap, AztecAsyncSingleton } from '@aztec/kv-store';
|
|
14
14
|
import { SlashFactoryAbi } from '@aztec/l1-artifacts';
|
|
15
15
|
import { type TelemetryClient, WithTracer, getTelemetryClient } from '@aztec/telemetry-client';
|
|
16
16
|
|
|
@@ -92,9 +92,9 @@ export class SlasherClient extends WithTracer {
|
|
|
92
92
|
private latestBlockNumberAtStart = -1;
|
|
93
93
|
private provenBlockNumberAtStart = -1;
|
|
94
94
|
|
|
95
|
-
private synchedBlockHashes:
|
|
96
|
-
private synchedLatestBlockNumber:
|
|
97
|
-
private synchedProvenBlockNumber:
|
|
95
|
+
private synchedBlockHashes: AztecAsyncMap<number, string>;
|
|
96
|
+
private synchedLatestBlockNumber: AztecAsyncSingleton<number>;
|
|
97
|
+
private synchedProvenBlockNumber: AztecAsyncSingleton<number>;
|
|
98
98
|
|
|
99
99
|
private blockStream;
|
|
100
100
|
|
|
@@ -110,7 +110,7 @@ export class SlasherClient extends WithTracer {
|
|
|
110
110
|
|
|
111
111
|
constructor(
|
|
112
112
|
private config: SlasherConfig & L1ContractsConfig & L1ReaderConfig,
|
|
113
|
-
private store:
|
|
113
|
+
private store: AztecAsyncKVStore,
|
|
114
114
|
private l2BlockSource: L2BlockSource,
|
|
115
115
|
telemetry: TelemetryClient = getTelemetryClient(),
|
|
116
116
|
private log = createLogger('slasher'),
|
|
@@ -178,17 +178,17 @@ export class SlasherClient extends WithTracer {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
public getL2BlockHash(number: number): Promise<string | undefined> {
|
|
181
|
-
return
|
|
181
|
+
return this.synchedBlockHashes.getAsync(number);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
public getL2Tips(): Promise<L2Tips> {
|
|
185
|
-
const latestBlockNumber = this.getSyncedLatestBlockNum();
|
|
184
|
+
public async getL2Tips(): Promise<L2Tips> {
|
|
185
|
+
const latestBlockNumber = await this.getSyncedLatestBlockNum();
|
|
186
186
|
let latestBlockHash: string | undefined;
|
|
187
|
-
const provenBlockNumber = this.getSyncedProvenBlockNum();
|
|
187
|
+
const provenBlockNumber = await this.getSyncedProvenBlockNum();
|
|
188
188
|
let provenBlockHash: string | undefined;
|
|
189
189
|
|
|
190
190
|
if (latestBlockNumber > 0) {
|
|
191
|
-
latestBlockHash = this.synchedBlockHashes.
|
|
191
|
+
latestBlockHash = await this.synchedBlockHashes.getAsync(latestBlockNumber);
|
|
192
192
|
if (typeof latestBlockHash === 'undefined') {
|
|
193
193
|
this.log.warn(`Block hash for latest block ${latestBlockNumber} not found`);
|
|
194
194
|
throw new Error();
|
|
@@ -196,7 +196,7 @@ export class SlasherClient extends WithTracer {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
if (provenBlockNumber > 0) {
|
|
199
|
-
provenBlockHash = this.synchedBlockHashes.
|
|
199
|
+
provenBlockHash = await this.synchedBlockHashes.getAsync(provenBlockNumber);
|
|
200
200
|
if (typeof provenBlockHash === 'undefined') {
|
|
201
201
|
this.log.warn(`Block hash for proven block ${provenBlockNumber} not found`);
|
|
202
202
|
throw new Error();
|
|
@@ -220,7 +220,7 @@ export class SlasherClient extends WithTracer {
|
|
|
220
220
|
// TODO (alexg): I think we can prune the block hashes map here
|
|
221
221
|
break;
|
|
222
222
|
case 'chain-proven': {
|
|
223
|
-
const from = this.getSyncedProvenBlockNum() + 1;
|
|
223
|
+
const from = (await this.getSyncedProvenBlockNum()) + 1;
|
|
224
224
|
const limit = event.blockNumber - from + 1;
|
|
225
225
|
await this.handleProvenL2Blocks(await this.l2BlockSource.getBlocks(from, limit));
|
|
226
226
|
break;
|
|
@@ -247,8 +247,8 @@ export class SlasherClient extends WithTracer {
|
|
|
247
247
|
this.latestBlockNumberAtStart = await this.l2BlockSource.getBlockNumber();
|
|
248
248
|
this.provenBlockNumberAtStart = await this.l2BlockSource.getProvenBlockNumber();
|
|
249
249
|
|
|
250
|
-
const syncedLatestBlock = this.getSyncedLatestBlockNum() + 1;
|
|
251
|
-
const syncedProvenBlock = this.getSyncedProvenBlockNum() + 1;
|
|
250
|
+
const syncedLatestBlock = (await this.getSyncedLatestBlockNum()) + 1;
|
|
251
|
+
const syncedProvenBlock = (await this.getSyncedProvenBlockNum()) + 1;
|
|
252
252
|
|
|
253
253
|
// if there are blocks to be retrieved, go to a synching state
|
|
254
254
|
if (syncedLatestBlock <= this.latestBlockNumberAtStart || syncedProvenBlock <= this.provenBlockNumberAtStart) {
|
|
@@ -278,6 +278,8 @@ export class SlasherClient extends WithTracer {
|
|
|
278
278
|
this.log.debug('Stopping Slasher client...');
|
|
279
279
|
await this.blockStream.stop();
|
|
280
280
|
this.log.debug('Stopped block downloader');
|
|
281
|
+
await this.store.close();
|
|
282
|
+
this.log.debug('Stopped slasher store');
|
|
281
283
|
this.setCurrentState(SlasherClientState.STOPPED);
|
|
282
284
|
this.log.info('Slasher client stopped.');
|
|
283
285
|
}
|
|
@@ -294,16 +296,16 @@ export class SlasherClient extends WithTracer {
|
|
|
294
296
|
* Public function to check the latest block number that the slasher client is synced to.
|
|
295
297
|
* @returns Block number of latest L2 Block we've synced with.
|
|
296
298
|
*/
|
|
297
|
-
public getSyncedLatestBlockNum() {
|
|
298
|
-
return this.synchedLatestBlockNumber.
|
|
299
|
+
public async getSyncedLatestBlockNum(): Promise<number> {
|
|
300
|
+
return (await this.synchedLatestBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
|
|
299
301
|
}
|
|
300
302
|
|
|
301
303
|
/**
|
|
302
304
|
* Public function to check the latest proven block number that the slasher client is synced to.
|
|
303
305
|
* @returns Block number of latest proven L2 Block we've synced with.
|
|
304
306
|
*/
|
|
305
|
-
public getSyncedProvenBlockNum() {
|
|
306
|
-
return this.synchedProvenBlockNumber.
|
|
307
|
+
public async getSyncedProvenBlockNum(): Promise<number> {
|
|
308
|
+
return (await this.synchedProvenBlockNumber.getAsync()) ?? INITIAL_L2_BLOCK_NUM - 1;
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
/**
|
|
@@ -311,7 +313,7 @@ export class SlasherClient extends WithTracer {
|
|
|
311
313
|
* @returns Information about slasher client status: state & syncedToBlockNum.
|
|
312
314
|
*/
|
|
313
315
|
public async getStatus(): Promise<SlasherSyncState> {
|
|
314
|
-
const blockNumber = this.getSyncedLatestBlockNum();
|
|
316
|
+
const blockNumber = await this.getSyncedLatestBlockNum();
|
|
315
317
|
const blockHash =
|
|
316
318
|
blockNumber == 0
|
|
317
319
|
? ''
|
|
@@ -332,16 +334,19 @@ export class SlasherClient extends WithTracer {
|
|
|
332
334
|
*/
|
|
333
335
|
private async handleLatestL2Blocks(blocks: L2Block[]): Promise<void> {
|
|
334
336
|
if (!blocks.length) {
|
|
335
|
-
return
|
|
337
|
+
return;
|
|
336
338
|
}
|
|
337
339
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
await this.store.transactionAsync(async () => {
|
|
341
|
+
for (const block of blocks) {
|
|
342
|
+
await this.synchedBlockHashes.set(block.number, (await block.hash()).toString());
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const lastBlockNum = blocks[blocks.length - 1].number;
|
|
346
|
+
await this.synchedLatestBlockNumber.set(lastBlockNum);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
await this.startServiceIfSynched();
|
|
345
350
|
}
|
|
346
351
|
|
|
347
352
|
/**
|
|
@@ -357,7 +362,7 @@ export class SlasherClient extends WithTracer {
|
|
|
357
362
|
await this.synchedProvenBlockNumber.set(lastBlockNum);
|
|
358
363
|
this.log.debug(`Synched to proven block ${lastBlockNum}`);
|
|
359
364
|
|
|
360
|
-
this.startServiceIfSynched();
|
|
365
|
+
await this.startServiceIfSynched();
|
|
361
366
|
}
|
|
362
367
|
|
|
363
368
|
private async handlePruneL2Blocks(latestBlock: number): Promise<void> {
|
|
@@ -381,11 +386,15 @@ export class SlasherClient extends WithTracer {
|
|
|
381
386
|
await this.synchedLatestBlockNumber.set(latestBlock);
|
|
382
387
|
}
|
|
383
388
|
|
|
384
|
-
private startServiceIfSynched() {
|
|
389
|
+
private async startServiceIfSynched() {
|
|
390
|
+
const [latestBlock, provenBlock] = await Promise.all([
|
|
391
|
+
this.getSyncedLatestBlockNum(),
|
|
392
|
+
this.getSyncedProvenBlockNum(),
|
|
393
|
+
]);
|
|
385
394
|
if (
|
|
386
395
|
this.currentState === SlasherClientState.SYNCHING &&
|
|
387
|
-
|
|
388
|
-
|
|
396
|
+
latestBlock >= this.latestBlockNumberAtStart &&
|
|
397
|
+
provenBlock >= this.provenBlockNumberAtStart
|
|
389
398
|
) {
|
|
390
399
|
this.log.debug(`Synched to blocks at start`);
|
|
391
400
|
this.setCurrentState(SlasherClientState.RUNNING);
|