@aztec/aztec-node 0.0.1-commit.db765a8 → 0.0.1-commit.df81a97b5
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/config.d.ts +2 -2
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +1 -1
- package/dest/aztec-node/server.d.ts +19 -19
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +204 -124
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +8 -8
- package/package.json +26 -27
- package/src/aztec-node/config.ts +1 -1
- package/src/aztec-node/server.ts +207 -121
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +8 -8
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
5
|
import { Blob } from '@aztec/blob-lib';
|
|
5
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
11
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -111,9 +113,10 @@ import {
|
|
|
111
113
|
createBlockProposalHandler,
|
|
112
114
|
createValidatorClient,
|
|
113
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
114
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
115
118
|
|
|
116
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
117
120
|
|
|
118
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
119
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -150,7 +153,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
150
153
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
151
154
|
protected readonly epochCache: EpochCacheInterface,
|
|
152
155
|
protected readonly packageVersion: string,
|
|
153
|
-
private
|
|
156
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
154
158
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
159
|
private log = createLogger('node'),
|
|
156
160
|
private blobClient?: BlobClientInterface,
|
|
@@ -172,6 +176,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
|
|
179
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
180
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
181
|
+
return this.rpcProofVerifier;
|
|
182
|
+
}
|
|
183
|
+
|
|
175
184
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
176
185
|
const status = await this.worldStateSynchronizer.status();
|
|
177
186
|
return status.syncSummary;
|
|
@@ -195,6 +204,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
195
204
|
dateProvider?: DateProvider;
|
|
196
205
|
p2pClientDeps?: P2PClientDeps;
|
|
197
206
|
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
207
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
198
208
|
} = {},
|
|
199
209
|
options: {
|
|
200
210
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
@@ -257,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
257
267
|
|
|
258
268
|
const publicClient = createPublicClient({
|
|
259
269
|
chain: ethereumChain.chainInfo,
|
|
260
|
-
transport:
|
|
270
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
261
271
|
pollingInterval: config.viemPollingIntervalMS,
|
|
262
272
|
});
|
|
263
273
|
|
|
@@ -271,10 +281,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
271
281
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
272
282
|
|
|
273
283
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
274
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
284
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
275
285
|
rollupContract.getL1GenesisTime(),
|
|
276
286
|
rollupContract.getSlotDuration(),
|
|
277
287
|
rollupContract.getVersion(),
|
|
288
|
+
rollupContract.getManaLimit().then(Number),
|
|
278
289
|
] as const);
|
|
279
290
|
|
|
280
291
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -305,10 +316,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
305
316
|
options.prefilledPublicData,
|
|
306
317
|
telemetry,
|
|
307
318
|
);
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
319
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
320
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
321
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
322
|
+
if (useRealVerifiers) {
|
|
323
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
324
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
325
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
326
|
+
} else {
|
|
327
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
328
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
329
|
+
}
|
|
312
330
|
|
|
313
331
|
let debugLogStore: DebugLogStore;
|
|
314
332
|
if (!config.realProofs) {
|
|
@@ -322,8 +340,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
322
340
|
debugLogStore = new NullDebugLogStore();
|
|
323
341
|
}
|
|
324
342
|
|
|
325
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
326
|
-
|
|
327
343
|
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
328
344
|
if (proverOnly) {
|
|
329
345
|
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
@@ -333,7 +349,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
333
349
|
const p2pClient = await createP2PClient(
|
|
334
350
|
config,
|
|
335
351
|
archiver,
|
|
336
|
-
|
|
352
|
+
peerProofVerifier,
|
|
337
353
|
worldStateSynchronizer,
|
|
338
354
|
epochCache,
|
|
339
355
|
packageVersion,
|
|
@@ -345,9 +361,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
345
361
|
// We'll accumulate sentinel watchers here
|
|
346
362
|
const watchers: Watcher[] = [];
|
|
347
363
|
|
|
348
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
|
|
364
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
365
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
349
366
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
350
|
-
{
|
|
367
|
+
{
|
|
368
|
+
...config,
|
|
369
|
+
l1GenesisTime,
|
|
370
|
+
slotDuration: Number(slotDuration),
|
|
371
|
+
rollupManaLimit,
|
|
372
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
373
|
+
},
|
|
351
374
|
worldStateSynchronizer,
|
|
352
375
|
archiver,
|
|
353
376
|
dateProvider,
|
|
@@ -369,6 +392,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
369
392
|
l1ToL2MessageSource: archiver,
|
|
370
393
|
keyStoreManager,
|
|
371
394
|
blobClient,
|
|
395
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
372
396
|
});
|
|
373
397
|
|
|
374
398
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -380,22 +404,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
380
404
|
await validatorClient.registerHandlers();
|
|
381
405
|
}
|
|
382
406
|
}
|
|
407
|
+
}
|
|
383
408
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
409
|
+
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
410
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
411
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
412
|
+
if (!validatorClient) {
|
|
413
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
414
|
+
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
415
|
+
createBlockProposalHandler(config, {
|
|
416
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
417
|
+
worldState: worldStateSynchronizer,
|
|
418
|
+
epochCache,
|
|
419
|
+
blockSource: archiver,
|
|
420
|
+
l1ToL2MessageSource: archiver,
|
|
421
|
+
p2pClient,
|
|
422
|
+
dateProvider,
|
|
423
|
+
telemetry,
|
|
424
|
+
}).register(p2pClient, reexecute);
|
|
399
425
|
}
|
|
400
426
|
|
|
401
427
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -445,6 +471,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
445
471
|
})
|
|
446
472
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
447
473
|
|
|
474
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
475
|
+
l1Contracts: config.l1Contracts,
|
|
476
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
477
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
478
|
+
l1GenesisTime,
|
|
479
|
+
slotDuration: Number(slotDuration),
|
|
480
|
+
});
|
|
481
|
+
|
|
448
482
|
// Validator enabled, create/start relevant service
|
|
449
483
|
let sequencer: SequencerClient | undefined;
|
|
450
484
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -482,9 +516,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
482
516
|
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
483
517
|
);
|
|
484
518
|
|
|
519
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
520
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
521
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
522
|
+
if (fundingSigner) {
|
|
523
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
524
|
+
publicClient,
|
|
525
|
+
[fundingSigner],
|
|
526
|
+
{ ...config, scope: 'sequencer' },
|
|
527
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
528
|
+
);
|
|
529
|
+
funderL1TxUtils = funder;
|
|
530
|
+
}
|
|
531
|
+
|
|
485
532
|
// Create and start the sequencer client
|
|
486
533
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
487
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
534
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
488
535
|
worldStateSynchronizer,
|
|
489
536
|
archiver,
|
|
490
537
|
dateProvider,
|
|
@@ -496,6 +543,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
496
543
|
...deps,
|
|
497
544
|
epochCache,
|
|
498
545
|
l1TxUtils,
|
|
546
|
+
funderL1TxUtils,
|
|
499
547
|
validatorClient,
|
|
500
548
|
p2pClient,
|
|
501
549
|
worldStateSynchronizer,
|
|
@@ -507,6 +555,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
507
555
|
dateProvider,
|
|
508
556
|
blobClient,
|
|
509
557
|
nodeKeyStore: keyStoreManager!,
|
|
558
|
+
globalVariableBuilder,
|
|
510
559
|
});
|
|
511
560
|
}
|
|
512
561
|
|
|
@@ -540,13 +589,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
589
|
}
|
|
541
590
|
}
|
|
542
591
|
|
|
543
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
544
|
-
...config,
|
|
545
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
546
|
-
l1GenesisTime,
|
|
547
|
-
slotDuration: Number(slotDuration),
|
|
548
|
-
});
|
|
549
|
-
|
|
550
592
|
const node = new AztecNodeService(
|
|
551
593
|
config,
|
|
552
594
|
p2pClient,
|
|
@@ -565,7 +607,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
565
607
|
globalVariableBuilder,
|
|
566
608
|
epochCache,
|
|
567
609
|
packageVersion,
|
|
568
|
-
|
|
610
|
+
peerProofVerifier,
|
|
611
|
+
rpcProofVerifier,
|
|
569
612
|
telemetry,
|
|
570
613
|
log,
|
|
571
614
|
blobClient,
|
|
@@ -710,6 +753,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
710
753
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
711
754
|
}
|
|
712
755
|
|
|
756
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
757
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
758
|
+
}
|
|
759
|
+
|
|
713
760
|
/**
|
|
714
761
|
* Method to fetch the current min L2 fees.
|
|
715
762
|
* @returns The current min L2 fees.
|
|
@@ -742,6 +789,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
742
789
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
743
790
|
}
|
|
744
791
|
|
|
792
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
793
|
+
return this.blockSource.getCheckpointNumber();
|
|
794
|
+
}
|
|
795
|
+
|
|
745
796
|
/**
|
|
746
797
|
* Method to fetch the version of the package.
|
|
747
798
|
* @returns The node package version
|
|
@@ -779,18 +830,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
779
830
|
page?: number,
|
|
780
831
|
referenceBlock?: BlockHash,
|
|
781
832
|
): Promise<TxScopedL2Log[][]> {
|
|
833
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
782
834
|
if (referenceBlock) {
|
|
783
835
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
784
|
-
if (
|
|
836
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
837
|
+
upToBlockNumber = BlockNumber(0);
|
|
838
|
+
} else {
|
|
785
839
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
786
840
|
if (!header) {
|
|
787
841
|
throw new Error(
|
|
788
842
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
789
843
|
);
|
|
790
844
|
}
|
|
845
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
791
846
|
}
|
|
792
847
|
}
|
|
793
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
848
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
794
849
|
}
|
|
795
850
|
|
|
796
851
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -799,18 +854,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
799
854
|
page?: number,
|
|
800
855
|
referenceBlock?: BlockHash,
|
|
801
856
|
): Promise<TxScopedL2Log[][]> {
|
|
857
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
802
858
|
if (referenceBlock) {
|
|
803
859
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
804
|
-
if (
|
|
860
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
861
|
+
upToBlockNumber = BlockNumber(0);
|
|
862
|
+
} else {
|
|
805
863
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
806
864
|
if (!header) {
|
|
807
865
|
throw new Error(
|
|
808
866
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
809
867
|
);
|
|
810
868
|
}
|
|
869
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
811
870
|
}
|
|
812
871
|
}
|
|
813
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
872
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
814
873
|
}
|
|
815
874
|
|
|
816
875
|
/**
|
|
@@ -896,7 +955,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
896
955
|
await tryStop(this.validatorsSentinel);
|
|
897
956
|
await tryStop(this.epochPruneWatcher);
|
|
898
957
|
await tryStop(this.slasherClient);
|
|
899
|
-
await tryStop(this.
|
|
958
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
900
959
|
await tryStop(this.sequencer);
|
|
901
960
|
await tryStop(this.proverNode);
|
|
902
961
|
await tryStop(this.p2pClient);
|
|
@@ -952,58 +1011,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
952
1011
|
treeId: MerkleTreeId,
|
|
953
1012
|
leafValues: Fr[],
|
|
954
1013
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
955
|
-
const committedDb = await this
|
|
1014
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
956
1015
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
957
1016
|
treeId,
|
|
958
1017
|
leafValues.map(x => x.toBuffer()),
|
|
959
1018
|
);
|
|
960
|
-
//
|
|
961
|
-
const
|
|
1019
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1020
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
962
1021
|
|
|
963
|
-
// Now we find the block numbers for the indices
|
|
964
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1022
|
+
// Now we find the block numbers for the defined indices
|
|
1023
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
965
1024
|
|
|
966
|
-
//
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1025
|
+
// Build a map from leaf index to block number
|
|
1026
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1027
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1028
|
+
const blockNumber = blockNumbers[i];
|
|
1029
|
+
if (blockNumber === undefined) {
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1032
|
+
);
|
|
970
1033
|
}
|
|
1034
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
971
1035
|
}
|
|
972
1036
|
|
|
973
1037
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
974
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1038
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
975
1039
|
|
|
976
|
-
// Now we obtain the block hashes from the archive tree
|
|
977
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1040
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
978
1041
|
const blockHashes = await Promise.all(
|
|
979
1042
|
uniqueBlockNumbers.map(blockNumber => {
|
|
980
1043
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
981
1044
|
}),
|
|
982
1045
|
);
|
|
983
1046
|
|
|
984
|
-
//
|
|
1047
|
+
// Build a map from block number to block hash
|
|
1048
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
985
1049
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
986
|
-
|
|
1050
|
+
const blockHash = blockHashes[i];
|
|
1051
|
+
if (blockHash === undefined) {
|
|
987
1052
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
988
1053
|
}
|
|
1054
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
989
1055
|
}
|
|
990
1056
|
|
|
991
1057
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
992
|
-
return maybeIndices.map(
|
|
1058
|
+
return maybeIndices.map(index => {
|
|
993
1059
|
if (index === undefined) {
|
|
994
1060
|
return undefined;
|
|
995
1061
|
}
|
|
996
|
-
const blockNumber =
|
|
1062
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
997
1063
|
if (blockNumber === undefined) {
|
|
998
|
-
|
|
1064
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
999
1065
|
}
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
return undefined;
|
|
1066
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1067
|
+
if (blockHash === undefined) {
|
|
1068
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1004
1069
|
}
|
|
1005
1070
|
return {
|
|
1006
|
-
l2BlockNumber:
|
|
1071
|
+
l2BlockNumber: blockNumber,
|
|
1007
1072
|
l2BlockHash: new BlockHash(blockHash),
|
|
1008
1073
|
data: index,
|
|
1009
1074
|
};
|
|
@@ -1014,7 +1079,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1079
|
referenceBlock: BlockParameter,
|
|
1015
1080
|
blockHash: BlockHash,
|
|
1016
1081
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1017
|
-
|
|
1082
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1083
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1084
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1085
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1086
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1018
1087
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1019
1088
|
return pathAndIndex === undefined
|
|
1020
1089
|
? undefined
|
|
@@ -1025,7 +1094,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1025
1094
|
referenceBlock: BlockParameter,
|
|
1026
1095
|
noteHash: Fr,
|
|
1027
1096
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1028
|
-
const committedDb = await this
|
|
1097
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1029
1098
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1030
1099
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
1031
1100
|
[noteHash],
|
|
@@ -1039,7 +1108,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1039
1108
|
referenceBlock: BlockParameter,
|
|
1040
1109
|
l1ToL2Message: Fr,
|
|
1041
1110
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1042
|
-
const db = await this
|
|
1111
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1043
1112
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1044
1113
|
if (!witness) {
|
|
1045
1114
|
return undefined;
|
|
@@ -1049,11 +1118,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1049
1118
|
return [witness.index, witness.path];
|
|
1050
1119
|
}
|
|
1051
1120
|
|
|
1052
|
-
public async
|
|
1121
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
1053
1122
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1054
|
-
return messageIndex
|
|
1055
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
1056
|
-
: undefined;
|
|
1123
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1057
1124
|
}
|
|
1058
1125
|
|
|
1059
1126
|
/**
|
|
@@ -1074,19 +1141,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1074
1141
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1075
1142
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1076
1143
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1077
|
-
const blocksInCheckpoints
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1081
|
-
const block = checkpointedBlock.block;
|
|
1082
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1083
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1084
|
-
checkpointIndex++;
|
|
1085
|
-
blocksInCheckpoints.push([]);
|
|
1086
|
-
previousSlotNumber = slotNumber;
|
|
1087
|
-
}
|
|
1088
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1089
|
-
}
|
|
1144
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1145
|
+
group => group.map(cb => cb.block),
|
|
1146
|
+
);
|
|
1090
1147
|
return blocksInCheckpoints.map(blocks =>
|
|
1091
1148
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1092
1149
|
);
|
|
@@ -1096,7 +1153,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1096
1153
|
referenceBlock: BlockParameter,
|
|
1097
1154
|
nullifier: Fr,
|
|
1098
1155
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1099
|
-
const db = await this
|
|
1156
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1100
1157
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1101
1158
|
if (!witness) {
|
|
1102
1159
|
return undefined;
|
|
@@ -1111,33 +1168,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1111
1168
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1112
1169
|
}
|
|
1113
1170
|
|
|
1114
|
-
/**
|
|
1115
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1116
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1117
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1118
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1119
|
-
* @returns The low nullifier membership witness (if found).
|
|
1120
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1121
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1122
|
-
* we are trying to prove non-inclusion for.
|
|
1123
|
-
*
|
|
1124
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1125
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1126
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1127
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1128
|
-
*/
|
|
1129
1171
|
public async getLowNullifierMembershipWitness(
|
|
1130
1172
|
referenceBlock: BlockParameter,
|
|
1131
1173
|
nullifier: Fr,
|
|
1132
1174
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1133
|
-
const committedDb = await this
|
|
1175
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1134
1176
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1135
1177
|
if (!findResult) {
|
|
1136
1178
|
return undefined;
|
|
1137
1179
|
}
|
|
1138
1180
|
const { index, alreadyPresent } = findResult;
|
|
1139
1181
|
if (alreadyPresent) {
|
|
1140
|
-
|
|
1182
|
+
throw new Error(
|
|
1183
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1184
|
+
);
|
|
1141
1185
|
}
|
|
1142
1186
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1143
1187
|
|
|
@@ -1146,7 +1190,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1146
1190
|
}
|
|
1147
1191
|
|
|
1148
1192
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1149
|
-
const committedDb = await this
|
|
1193
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1150
1194
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1151
1195
|
if (!lowLeafResult) {
|
|
1152
1196
|
return undefined;
|
|
@@ -1161,7 +1205,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1161
1205
|
}
|
|
1162
1206
|
|
|
1163
1207
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1164
|
-
const committedDb = await this
|
|
1208
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1165
1209
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1166
1210
|
|
|
1167
1211
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1275,7 +1319,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1275
1319
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1276
1320
|
|
|
1277
1321
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1278
|
-
const [processedTxs, failedTxs, _usedTxs, returns,
|
|
1322
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1279
1323
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1280
1324
|
if (failedTxs.length) {
|
|
1281
1325
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1301,11 +1345,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1301
1345
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1302
1346
|
): Promise<TxValidationResult> {
|
|
1303
1347
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1304
|
-
const verifier = isSimulation ? undefined : this.
|
|
1348
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1305
1349
|
|
|
1306
1350
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1307
1351
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1308
1352
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1353
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1309
1354
|
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1310
1355
|
db,
|
|
1311
1356
|
this.contractDataSource,
|
|
@@ -1322,6 +1367,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1322
1367
|
gasFees: await this.getCurrentMinFees(),
|
|
1323
1368
|
skipFeeEnforcement,
|
|
1324
1369
|
txsPermitted: !this.config.disableTransactions,
|
|
1370
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1371
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1372
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1325
1373
|
},
|
|
1326
1374
|
this.log.getBindings(),
|
|
1327
1375
|
);
|
|
@@ -1346,7 +1394,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1346
1394
|
archiver.updateConfig(config);
|
|
1347
1395
|
}
|
|
1348
1396
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1349
|
-
|
|
1397
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1398
|
+
if (newConfig.realProofs) {
|
|
1399
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1400
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1401
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1402
|
+
} else {
|
|
1403
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1404
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1405
|
+
}
|
|
1350
1406
|
}
|
|
1351
1407
|
|
|
1352
1408
|
this.config = newConfig;
|
|
@@ -1588,7 +1644,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1588
1644
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1589
1645
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1590
1646
|
*/
|
|
1591
|
-
async
|
|
1647
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1592
1648
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1593
1649
|
try {
|
|
1594
1650
|
// Attempt to sync the world state if necessary
|
|
@@ -1602,6 +1658,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1602
1658
|
return this.worldStateSynchronizer.getCommitted();
|
|
1603
1659
|
}
|
|
1604
1660
|
|
|
1661
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1662
|
+
let blockNumber: BlockNumber;
|
|
1605
1663
|
if (BlockHash.isBlockHash(block)) {
|
|
1606
1664
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1607
1665
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1615,22 +1673,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1615
1673
|
`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.`,
|
|
1616
1674
|
);
|
|
1617
1675
|
}
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1676
|
+
|
|
1677
|
+
blockNumber = header.getBlockNumber();
|
|
1678
|
+
} else {
|
|
1679
|
+
blockNumber = block as BlockNumber;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// Check it's within world state sync range
|
|
1683
|
+
if (blockNumber > blockSyncedTo) {
|
|
1684
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1621
1685
|
}
|
|
1686
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1622
1687
|
|
|
1623
|
-
|
|
1624
|
-
{
|
|
1625
|
-
const blockNumber = block as BlockNumber;
|
|
1688
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1626
1689
|
|
|
1627
|
-
|
|
1628
|
-
|
|
1690
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1691
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1692
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1693
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1694
|
+
throw new Error(
|
|
1695
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1696
|
+
);
|
|
1629
1697
|
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
return snapshot;
|
|
1701
|
+
}
|
|
1630
1702
|
|
|
1631
|
-
|
|
1632
|
-
|
|
1703
|
+
/** Resolves a block parameter to a block number. */
|
|
1704
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1705
|
+
if (block === 'latest') {
|
|
1706
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1707
|
+
}
|
|
1708
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1709
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1710
|
+
if (block.equals(initialBlockHash)) {
|
|
1711
|
+
return BlockNumber.ZERO;
|
|
1712
|
+
}
|
|
1713
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1714
|
+
if (!header) {
|
|
1715
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1716
|
+
}
|
|
1717
|
+
return header.getBlockNumber();
|
|
1633
1718
|
}
|
|
1719
|
+
return block as BlockNumber;
|
|
1634
1720
|
}
|
|
1635
1721
|
|
|
1636
1722
|
/**
|