@aztec/aztec-node 0.0.1-commit.03f7ef2 → 0.0.1-commit.08c5969dc
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/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +9 -16
- package/dest/aztec-node/server.d.ts +41 -99
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +579 -188
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +6 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +67 -43
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +26 -26
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +242 -248
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +80 -47
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type BlobClientInterface,
|
|
4
|
-
import {
|
|
5
|
-
type BlobFileStoreMetadata,
|
|
6
|
-
createReadOnlyFileStoreBlobClients,
|
|
7
|
-
createWritableFileStoreBlobClient,
|
|
8
|
-
} from '@aztec/blob-client/filestore';
|
|
9
|
-
import {
|
|
10
|
-
ARCHIVE_HEIGHT,
|
|
11
|
-
INITIAL_L2_BLOCK_NUM,
|
|
12
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
13
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
14
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
15
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
16
|
-
} from '@aztec/constants';
|
|
3
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
17
5
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
18
6
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
19
7
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
20
8
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
21
9
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
22
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
10
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
23
11
|
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
24
12
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
25
13
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -36,14 +24,7 @@ import {
|
|
|
36
24
|
} from '@aztec/node-lib/factories';
|
|
37
25
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
38
26
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
39
|
-
import {
|
|
40
|
-
BlockBuilder,
|
|
41
|
-
GlobalVariableBuilder,
|
|
42
|
-
SequencerClient,
|
|
43
|
-
type SequencerPublisher,
|
|
44
|
-
createValidatorForAcceptingTxs,
|
|
45
|
-
} from '@aztec/sequencer-client';
|
|
46
|
-
import { CheckpointsBuilder } from '@aztec/sequencer-client';
|
|
27
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
47
28
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
48
29
|
import {
|
|
49
30
|
AttestationsBlockWatcher,
|
|
@@ -54,14 +35,8 @@ import {
|
|
|
54
35
|
} from '@aztec/slasher';
|
|
55
36
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
56
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
57
|
-
import {
|
|
58
|
-
|
|
59
|
-
type DataInBlock,
|
|
60
|
-
type L2Block,
|
|
61
|
-
L2BlockHash,
|
|
62
|
-
type L2BlockSource,
|
|
63
|
-
type PublishedL2Block,
|
|
64
|
-
} from '@aztec/stdlib/block';
|
|
38
|
+
import { BlockHash, type BlockParameter, type DataInBlock, L2Block, type L2BlockSource } from '@aztec/stdlib/block';
|
|
39
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
65
40
|
import type {
|
|
66
41
|
ContractClassPublic,
|
|
67
42
|
ContractDataSource,
|
|
@@ -116,10 +91,13 @@ import {
|
|
|
116
91
|
trackSpan,
|
|
117
92
|
} from '@aztec/telemetry-client';
|
|
118
93
|
import {
|
|
94
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
95
|
+
FullNodeCheckpointsBuilder,
|
|
119
96
|
NodeKeystoreAdapter,
|
|
120
97
|
ValidatorClient,
|
|
121
98
|
createBlockProposalHandler,
|
|
122
99
|
createValidatorClient,
|
|
100
|
+
createValidatorForAcceptingTxs,
|
|
123
101
|
} from '@aztec/validator-client';
|
|
124
102
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
125
103
|
|
|
@@ -135,6 +113,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
135
113
|
*/
|
|
136
114
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
137
115
|
private metrics: NodeMetrics;
|
|
116
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
138
117
|
|
|
139
118
|
// Prevent two snapshot operations to happen simultaneously
|
|
140
119
|
private isUploadingSnapshot = false;
|
|
@@ -161,6 +140,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
161
140
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
162
141
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
163
142
|
private log = createLogger('node'),
|
|
143
|
+
private blobClient?: BlobClientInterface,
|
|
164
144
|
) {
|
|
165
145
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
166
146
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
@@ -190,7 +170,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
190
170
|
logger?: Logger;
|
|
191
171
|
publisher?: SequencerPublisher;
|
|
192
172
|
dateProvider?: DateProvider;
|
|
193
|
-
blobClient?: BlobClientInterface;
|
|
194
173
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
195
174
|
} = {},
|
|
196
175
|
options: {
|
|
@@ -270,24 +249,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
270
249
|
);
|
|
271
250
|
}
|
|
272
251
|
|
|
273
|
-
const
|
|
274
|
-
l1ChainId: config.l1ChainId,
|
|
275
|
-
rollupVersion: config.rollupVersion,
|
|
276
|
-
rollupAddress: config.l1Contracts.rollupAddress.toString(),
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const [fileStoreClients, fileStoreUploadClient] = await Promise.all([
|
|
280
|
-
createReadOnlyFileStoreBlobClients(config.blobFileStoreUrls, blobFileStoreMetadata, log),
|
|
281
|
-
createWritableFileStoreBlobClient(config.blobFileStoreUploadUrl, blobFileStoreMetadata, log),
|
|
282
|
-
]);
|
|
283
|
-
|
|
284
|
-
const blobClient =
|
|
285
|
-
deps.blobClient ??
|
|
286
|
-
createBlobClient(config, {
|
|
287
|
-
logger: createLogger('node:blob-client:client'),
|
|
288
|
-
fileStoreClients,
|
|
289
|
-
fileStoreUploadClient,
|
|
290
|
-
});
|
|
252
|
+
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
291
253
|
|
|
292
254
|
// attempt snapshot sync if possible
|
|
293
255
|
await trySnapshotSync(config, log);
|
|
@@ -333,7 +295,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
333
295
|
// We should really not be modifying the config object
|
|
334
296
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
335
297
|
|
|
336
|
-
|
|
298
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
299
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
337
300
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
338
301
|
worldStateSynchronizer,
|
|
339
302
|
archiver,
|
|
@@ -345,16 +308,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
345
308
|
const watchers: Watcher[] = [];
|
|
346
309
|
|
|
347
310
|
// Create validator client if required
|
|
348
|
-
const validatorClient = createValidatorClient(config, {
|
|
311
|
+
const validatorClient = await createValidatorClient(config, {
|
|
312
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
313
|
+
worldState: worldStateSynchronizer,
|
|
349
314
|
p2pClient,
|
|
350
315
|
telemetry,
|
|
351
316
|
dateProvider,
|
|
352
317
|
epochCache,
|
|
353
|
-
blockBuilder,
|
|
354
318
|
blockSource: archiver,
|
|
355
319
|
l1ToL2MessageSource: archiver,
|
|
356
320
|
keyStoreManager,
|
|
357
|
-
|
|
321
|
+
blobClient,
|
|
358
322
|
});
|
|
359
323
|
|
|
360
324
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -372,7 +336,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
372
336
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
373
337
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
374
338
|
createBlockProposalHandler(config, {
|
|
375
|
-
|
|
339
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
340
|
+
worldState: worldStateSynchronizer,
|
|
376
341
|
epochCache,
|
|
377
342
|
blockSource: archiver,
|
|
378
343
|
l1ToL2MessageSource: archiver,
|
|
@@ -400,7 +365,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
400
365
|
archiver,
|
|
401
366
|
epochCache,
|
|
402
367
|
p2pClient.getTxProvider(),
|
|
403
|
-
|
|
368
|
+
validatorCheckpointsBuilder,
|
|
404
369
|
config,
|
|
405
370
|
);
|
|
406
371
|
watchers.push(epochPruneWatcher);
|
|
@@ -465,6 +430,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
465
430
|
// Create and start the sequencer client
|
|
466
431
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
467
432
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
433
|
+
worldStateSynchronizer,
|
|
468
434
|
archiver,
|
|
469
435
|
dateProvider,
|
|
470
436
|
telemetry,
|
|
@@ -522,6 +488,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
522
488
|
proofVerifier,
|
|
523
489
|
telemetry,
|
|
524
490
|
log,
|
|
491
|
+
blobClient,
|
|
525
492
|
);
|
|
526
493
|
}
|
|
527
494
|
|
|
@@ -586,19 +553,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
586
553
|
enr,
|
|
587
554
|
l1ContractAddresses: contractAddresses,
|
|
588
555
|
protocolContractAddresses: protocolContractAddresses,
|
|
556
|
+
realProofs: !!this.config.realProofs,
|
|
589
557
|
};
|
|
590
558
|
|
|
591
559
|
return nodeInfo;
|
|
592
560
|
}
|
|
593
561
|
|
|
594
562
|
/**
|
|
595
|
-
* Get a block specified by its number.
|
|
596
|
-
* @param
|
|
563
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
564
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
597
565
|
* @returns The requested block.
|
|
598
566
|
*/
|
|
599
|
-
public async getBlock(
|
|
600
|
-
|
|
601
|
-
|
|
567
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
568
|
+
if (BlockHash.isBlockHash(block)) {
|
|
569
|
+
return this.getBlockByHash(block);
|
|
570
|
+
}
|
|
571
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
572
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
573
|
+
return this.buildInitialBlock();
|
|
574
|
+
}
|
|
575
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
602
576
|
}
|
|
603
577
|
|
|
604
578
|
/**
|
|
@@ -606,9 +580,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
606
580
|
* @param blockHash - The block hash being requested.
|
|
607
581
|
* @returns The requested block.
|
|
608
582
|
*/
|
|
609
|
-
public async getBlockByHash(blockHash:
|
|
610
|
-
const
|
|
611
|
-
|
|
583
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
584
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
585
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
586
|
+
return this.buildInitialBlock();
|
|
587
|
+
}
|
|
588
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
private buildInitialBlock(): L2Block {
|
|
592
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
593
|
+
return L2Block.empty(initialHeader);
|
|
612
594
|
}
|
|
613
595
|
|
|
614
596
|
/**
|
|
@@ -617,8 +599,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
617
599
|
* @returns The requested block.
|
|
618
600
|
*/
|
|
619
601
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
620
|
-
|
|
621
|
-
return publishedBlock?.block;
|
|
602
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
622
603
|
}
|
|
623
604
|
|
|
624
605
|
/**
|
|
@@ -628,19 +609,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
628
609
|
* @returns The blocks requested.
|
|
629
610
|
*/
|
|
630
611
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
631
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
612
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
632
613
|
}
|
|
633
614
|
|
|
634
|
-
public async
|
|
635
|
-
return (await this.blockSource.
|
|
615
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
616
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
620
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
636
621
|
}
|
|
637
622
|
|
|
638
623
|
/**
|
|
639
|
-
* Method to fetch the current
|
|
640
|
-
* @returns The current
|
|
624
|
+
* Method to fetch the current min L2 fees.
|
|
625
|
+
* @returns The current min L2 fees.
|
|
641
626
|
*/
|
|
642
|
-
public async
|
|
643
|
-
return await this.globalVariableBuilder.
|
|
627
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
628
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
644
629
|
}
|
|
645
630
|
|
|
646
631
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -663,6 +648,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
648
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
649
|
}
|
|
665
650
|
|
|
651
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
652
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
653
|
+
}
|
|
654
|
+
|
|
666
655
|
/**
|
|
667
656
|
* Method to fetch the version of the package.
|
|
668
657
|
* @returns The node package version
|
|
@@ -695,12 +684,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
684
|
return this.contractDataSource.getContract(address);
|
|
696
685
|
}
|
|
697
686
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
687
|
+
public async getPrivateLogsByTags(
|
|
688
|
+
tags: SiloedTag[],
|
|
689
|
+
page?: number,
|
|
690
|
+
referenceBlock?: BlockHash,
|
|
691
|
+
): Promise<TxScopedL2Log[][]> {
|
|
692
|
+
if (referenceBlock) {
|
|
693
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
694
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
695
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
696
|
+
if (!header) {
|
|
697
|
+
throw new Error(
|
|
698
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
public async getPublicLogsByTagsFromContract(
|
|
707
|
+
contractAddress: AztecAddress,
|
|
708
|
+
tags: Tag[],
|
|
709
|
+
page?: number,
|
|
710
|
+
referenceBlock?: BlockHash,
|
|
711
|
+
): Promise<TxScopedL2Log[][]> {
|
|
712
|
+
if (referenceBlock) {
|
|
713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
714
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
715
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
716
|
+
if (!header) {
|
|
717
|
+
throw new Error(
|
|
718
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
704
724
|
}
|
|
705
725
|
|
|
706
726
|
/**
|
|
@@ -747,21 +767,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
747
767
|
}
|
|
748
768
|
|
|
749
769
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
755
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
756
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
757
|
-
}
|
|
770
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
771
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
772
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
773
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
774
|
|
|
775
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
776
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
777
|
+
|
|
760
778
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
779
|
+
// If the archiver has the receipt then return it.
|
|
780
|
+
return settledTxReceipt;
|
|
781
|
+
} else if (isKnownToPool) {
|
|
782
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
783
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
784
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
785
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
786
|
+
} else {
|
|
787
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
788
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
789
|
}
|
|
763
|
-
|
|
764
|
-
return txReceipt;
|
|
765
790
|
}
|
|
766
791
|
|
|
767
792
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -781,10 +806,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
781
806
|
await tryStop(this.p2pClient);
|
|
782
807
|
await tryStop(this.worldStateSynchronizer);
|
|
783
808
|
await tryStop(this.blockSource);
|
|
809
|
+
await tryStop(this.blobClient);
|
|
784
810
|
await tryStop(this.telemetry);
|
|
785
811
|
this.log.info(`Stopped Aztec Node`);
|
|
786
812
|
}
|
|
787
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Returns the blob client used by this node.
|
|
816
|
+
* @internal - Exposed for testing purposes only.
|
|
817
|
+
*/
|
|
818
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
819
|
+
return this.blobClient;
|
|
820
|
+
}
|
|
821
|
+
|
|
788
822
|
/**
|
|
789
823
|
* Method to retrieve pending txs.
|
|
790
824
|
* @param limit - The number of items to returns
|
|
@@ -817,20 +851,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
817
851
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
818
852
|
}
|
|
819
853
|
|
|
820
|
-
/**
|
|
821
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
822
|
-
* the leaves were inserted.
|
|
823
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
824
|
-
* @param treeId - The tree to search in.
|
|
825
|
-
* @param leafValues - The values to search for.
|
|
826
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
827
|
-
*/
|
|
828
854
|
public async findLeavesIndexes(
|
|
829
|
-
|
|
855
|
+
referenceBlock: BlockParameter,
|
|
830
856
|
treeId: MerkleTreeId,
|
|
831
857
|
leafValues: Fr[],
|
|
832
858
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
833
|
-
const committedDb = await this.#getWorldState(
|
|
859
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
834
860
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
835
861
|
treeId,
|
|
836
862
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -882,56 +908,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
882
908
|
}
|
|
883
909
|
return {
|
|
884
910
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
885
|
-
l2BlockHash:
|
|
911
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
886
912
|
data: index,
|
|
887
913
|
};
|
|
888
914
|
});
|
|
889
915
|
}
|
|
890
916
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
895
|
-
* @returns The sibling path for the leaf index.
|
|
896
|
-
*/
|
|
897
|
-
public async getNullifierSiblingPath(
|
|
898
|
-
blockNumber: BlockParameter,
|
|
899
|
-
leafIndex: bigint,
|
|
900
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
901
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
902
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Returns a sibling path for the given index in the data tree.
|
|
907
|
-
* @param blockNumber - The block number at which to get the data.
|
|
908
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
909
|
-
* @returns The sibling path for the leaf index.
|
|
910
|
-
*/
|
|
911
|
-
public async getNoteHashSiblingPath(
|
|
912
|
-
blockNumber: BlockParameter,
|
|
913
|
-
leafIndex: bigint,
|
|
914
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
915
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
916
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
public async getArchiveMembershipWitness(
|
|
920
|
-
blockNumber: BlockParameter,
|
|
921
|
-
archive: Fr,
|
|
917
|
+
public async getBlockHashMembershipWitness(
|
|
918
|
+
referenceBlock: BlockParameter,
|
|
919
|
+
blockHash: BlockHash,
|
|
922
920
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
923
|
-
const committedDb = await this.#getWorldState(
|
|
924
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
921
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
922
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
925
923
|
return pathAndIndex === undefined
|
|
926
924
|
? undefined
|
|
927
925
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
928
926
|
}
|
|
929
927
|
|
|
930
928
|
public async getNoteHashMembershipWitness(
|
|
931
|
-
|
|
929
|
+
referenceBlock: BlockParameter,
|
|
932
930
|
noteHash: Fr,
|
|
933
931
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
934
|
-
const committedDb = await this.#getWorldState(
|
|
932
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
935
933
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
936
934
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
937
935
|
[noteHash],
|
|
@@ -941,17 +939,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
941
939
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
942
940
|
}
|
|
943
941
|
|
|
944
|
-
/**
|
|
945
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
946
|
-
* @param blockNumber - The block number at which to get the data.
|
|
947
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
948
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
949
|
-
*/
|
|
950
942
|
public async getL1ToL2MessageMembershipWitness(
|
|
951
|
-
|
|
943
|
+
referenceBlock: BlockParameter,
|
|
952
944
|
l1ToL2Message: Fr,
|
|
953
945
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
954
|
-
const db = await this.#getWorldState(
|
|
946
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
955
947
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
956
948
|
if (!witness) {
|
|
957
949
|
return undefined;
|
|
@@ -979,56 +971,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
979
971
|
}
|
|
980
972
|
|
|
981
973
|
/**
|
|
982
|
-
* Returns all the L2 to L1 messages in
|
|
983
|
-
* @param
|
|
984
|
-
* @returns The L2 to L1 messages (
|
|
974
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
975
|
+
* @param epoch - The epoch at which to get the data.
|
|
976
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
985
977
|
*/
|
|
986
|
-
public async getL2ToL1Messages(
|
|
987
|
-
|
|
988
|
-
|
|
978
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
980
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
981
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
982
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
983
|
+
let checkpointIndex = -1;
|
|
984
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
985
|
+
const block = checkpointedBlock.block;
|
|
986
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
987
|
+
if (slotNumber !== previousSlotNumber) {
|
|
988
|
+
checkpointIndex++;
|
|
989
|
+
blocksInCheckpoints.push([]);
|
|
990
|
+
previousSlotNumber = slotNumber;
|
|
991
|
+
}
|
|
992
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
993
|
+
}
|
|
994
|
+
return blocksInCheckpoints.map(blocks =>
|
|
995
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
989
996
|
);
|
|
990
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
991
997
|
}
|
|
992
998
|
|
|
993
|
-
/**
|
|
994
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
995
|
-
* @param blockNumber - The block number at which to get the data.
|
|
996
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
997
|
-
* @returns The sibling path.
|
|
998
|
-
*/
|
|
999
|
-
public async getArchiveSiblingPath(
|
|
1000
|
-
blockNumber: BlockParameter,
|
|
1001
|
-
leafIndex: bigint,
|
|
1002
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1003
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1004
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1008
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1009
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1010
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1011
|
-
* @returns The sibling path.
|
|
1012
|
-
*/
|
|
1013
|
-
public async getPublicDataSiblingPath(
|
|
1014
|
-
blockNumber: BlockParameter,
|
|
1015
|
-
leafIndex: bigint,
|
|
1016
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1017
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1018
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1023
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1024
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1025
|
-
* @returns The nullifier membership witness (if found).
|
|
1026
|
-
*/
|
|
1027
999
|
public async getNullifierMembershipWitness(
|
|
1028
|
-
|
|
1000
|
+
referenceBlock: BlockParameter,
|
|
1029
1001
|
nullifier: Fr,
|
|
1030
1002
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1031
|
-
const db = await this.#getWorldState(
|
|
1003
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1032
1004
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1033
1005
|
if (!witness) {
|
|
1034
1006
|
return undefined;
|
|
@@ -1045,7 +1017,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1045
1017
|
|
|
1046
1018
|
/**
|
|
1047
1019
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1048
|
-
* @param
|
|
1020
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1021
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1049
1022
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1050
1023
|
* @returns The low nullifier membership witness (if found).
|
|
1051
1024
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1058,10 +1031,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1058
1031
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1059
1032
|
*/
|
|
1060
1033
|
public async getLowNullifierMembershipWitness(
|
|
1061
|
-
|
|
1034
|
+
referenceBlock: BlockParameter,
|
|
1062
1035
|
nullifier: Fr,
|
|
1063
1036
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1064
|
-
const committedDb = await this.#getWorldState(
|
|
1037
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1065
1038
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1066
1039
|
if (!findResult) {
|
|
1067
1040
|
return undefined;
|
|
@@ -1076,8 +1049,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1076
1049
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1077
1050
|
}
|
|
1078
1051
|
|
|
1079
|
-
async getPublicDataWitness(
|
|
1080
|
-
const committedDb = await this.#getWorldState(
|
|
1052
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1053
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1081
1054
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1082
1055
|
if (!lowLeafResult) {
|
|
1083
1056
|
return undefined;
|
|
@@ -1091,19 +1064,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1091
1064
|
}
|
|
1092
1065
|
}
|
|
1093
1066
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
*
|
|
1097
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1098
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1099
|
-
*
|
|
1100
|
-
* @param contract - Address of the contract to query.
|
|
1101
|
-
* @param slot - Slot to query.
|
|
1102
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1103
|
-
* @returns Storage value at the given contract slot.
|
|
1104
|
-
*/
|
|
1105
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1106
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1067
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1068
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1107
1069
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1108
1070
|
|
|
1109
1071
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1117,24 +1079,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1117
1079
|
return preimage.leaf.value;
|
|
1118
1080
|
}
|
|
1119
1081
|
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1137
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1082
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1083
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1084
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1085
|
+
if (block.equals(initialBlockHash)) {
|
|
1086
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1087
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1088
|
+
}
|
|
1089
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1090
|
+
} else {
|
|
1091
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1092
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1093
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1094
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1095
|
+
}
|
|
1096
|
+
return this.blockSource.getBlockHeader(block);
|
|
1097
|
+
}
|
|
1138
1098
|
}
|
|
1139
1099
|
|
|
1140
1100
|
/**
|
|
@@ -1184,6 +1144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1184
1144
|
this.contractDataSource,
|
|
1185
1145
|
new DateProvider(),
|
|
1186
1146
|
this.telemetry,
|
|
1147
|
+
this.log.getBindings(),
|
|
1187
1148
|
);
|
|
1188
1149
|
|
|
1189
1150
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1237,16 +1198,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1237
1198
|
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1238
1199
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1239
1200
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1240
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1201
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1202
|
+
db,
|
|
1203
|
+
this.contractDataSource,
|
|
1204
|
+
verifier,
|
|
1205
|
+
{
|
|
1206
|
+
timestamp: nextSlotTimestamp,
|
|
1207
|
+
blockNumber,
|
|
1208
|
+
l1ChainId: this.l1ChainId,
|
|
1209
|
+
rollupVersion: this.version,
|
|
1210
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1211
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1212
|
+
skipFeeEnforcement,
|
|
1213
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1214
|
+
},
|
|
1215
|
+
this.log.getBindings(),
|
|
1216
|
+
);
|
|
1250
1217
|
|
|
1251
1218
|
return await validator.validateTx(tx);
|
|
1252
1219
|
}
|
|
@@ -1315,7 +1282,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1315
1282
|
}
|
|
1316
1283
|
|
|
1317
1284
|
// And it has an L2 block hash
|
|
1318
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1285
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1319
1286
|
if (!l2BlockHash) {
|
|
1320
1287
|
this.metrics.recordSnapshotError();
|
|
1321
1288
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1349,7 +1316,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1349
1316
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1350
1317
|
}
|
|
1351
1318
|
|
|
1352
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1319
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1353
1320
|
if (targetBlock < finalizedBlock) {
|
|
1354
1321
|
if (force) {
|
|
1355
1322
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1410,16 +1377,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1410
1377
|
}
|
|
1411
1378
|
}
|
|
1412
1379
|
|
|
1380
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1381
|
+
if (!this.initialHeaderHashPromise) {
|
|
1382
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1383
|
+
}
|
|
1384
|
+
return this.initialHeaderHashPromise;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1413
1387
|
/**
|
|
1414
1388
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1415
|
-
* @param
|
|
1389
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1416
1390
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1417
1391
|
*/
|
|
1418
|
-
async #getWorldState(
|
|
1419
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1420
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1392
|
+
async #getWorldState(block: BlockParameter) {
|
|
1423
1393
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1424
1394
|
try {
|
|
1425
1395
|
// Attempt to sync the world state if necessary
|
|
@@ -1428,15 +1398,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1428
1398
|
this.log.error(`Error getting world state: ${err}`);
|
|
1429
1399
|
}
|
|
1430
1400
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1401
|
+
if (block === 'latest') {
|
|
1402
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1434
1403
|
return this.worldStateSynchronizer.getCommitted();
|
|
1435
|
-
}
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1407
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1408
|
+
if (block.equals(initialBlockHash)) {
|
|
1409
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1410
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1414
|
+
if (!header) {
|
|
1415
|
+
throw new Error(
|
|
1416
|
+
`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
const blockNumber = header.getBlockNumber();
|
|
1436
1420
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1437
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1421
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// Block number provided
|
|
1425
|
+
{
|
|
1426
|
+
const blockNumber = block as BlockNumber;
|
|
1427
|
+
|
|
1428
|
+
if (blockNumber > blockSyncedTo) {
|
|
1429
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1433
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1440
1434
|
}
|
|
1441
1435
|
}
|
|
1442
1436
|
|