@aztec/aztec-node 0.0.1-commit.fffb133c → 0.0.1-dev
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 +7 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -2
- 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 +8 -4
- package/dest/aztec-node/server.d.ts +47 -39
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +410 -208
- 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 +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +56 -30
- 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 +27 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +512 -256
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +59 -26
- package/src/sentinel/store.ts +12 -12
|
@@ -374,43 +374,47 @@ var _dec, _initProto;
|
|
|
374
374
|
import { createArchiver } from '@aztec/archiver';
|
|
375
375
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
376
376
|
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
377
|
+
import { Blob } from '@aztec/blob-lib';
|
|
377
378
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
378
379
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
379
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
380
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
380
381
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
381
|
-
import { BlockNumber
|
|
382
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
382
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
383
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
383
384
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
384
385
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
385
386
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
386
387
|
import { createLogger } from '@aztec/foundation/log';
|
|
388
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
387
389
|
import { count } from '@aztec/foundation/string';
|
|
388
390
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
389
391
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
390
392
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
391
393
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
392
|
-
import {
|
|
393
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
395
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
396
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
397
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
398
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
395
399
|
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
396
400
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
397
401
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
398
402
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
399
403
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
400
|
-
import {
|
|
404
|
+
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
401
405
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
402
406
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
403
407
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
404
408
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
409
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
405
410
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
406
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
407
411
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
408
412
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
409
413
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
410
414
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
411
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
415
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
412
416
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
413
|
-
import { createPublicClient
|
|
417
|
+
import { createPublicClient } from 'viem';
|
|
414
418
|
import { createSentinel } from '../sentinel/factory.js';
|
|
415
419
|
import { createKeyStoreForValidator } from './config.js';
|
|
416
420
|
import { NodeMetrics } from './node_metrics.js';
|
|
@@ -428,6 +432,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
428
432
|
l1ToL2MessageSource;
|
|
429
433
|
worldStateSynchronizer;
|
|
430
434
|
sequencer;
|
|
435
|
+
proverNode;
|
|
431
436
|
slasherClient;
|
|
432
437
|
validatorsSentinel;
|
|
433
438
|
epochPruneWatcher;
|
|
@@ -440,6 +445,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
440
445
|
telemetry;
|
|
441
446
|
log;
|
|
442
447
|
blobClient;
|
|
448
|
+
validatorClient;
|
|
449
|
+
keyStoreManager;
|
|
450
|
+
debugLogStore;
|
|
443
451
|
static{
|
|
444
452
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
445
453
|
[
|
|
@@ -454,7 +462,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
454
462
|
// Prevent two snapshot operations to happen simultaneously
|
|
455
463
|
isUploadingSnapshot;
|
|
456
464
|
tracer;
|
|
457
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient){
|
|
465
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
458
466
|
this.config = config;
|
|
459
467
|
this.p2pClient = p2pClient;
|
|
460
468
|
this.blockSource = blockSource;
|
|
@@ -463,6 +471,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
463
471
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
464
472
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
465
473
|
this.sequencer = sequencer;
|
|
474
|
+
this.proverNode = proverNode;
|
|
466
475
|
this.slasherClient = slasherClient;
|
|
467
476
|
this.validatorsSentinel = validatorsSentinel;
|
|
468
477
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
@@ -475,12 +484,21 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
475
484
|
this.telemetry = telemetry;
|
|
476
485
|
this.log = log;
|
|
477
486
|
this.blobClient = blobClient;
|
|
487
|
+
this.validatorClient = validatorClient;
|
|
488
|
+
this.keyStoreManager = keyStoreManager;
|
|
489
|
+
this.debugLogStore = debugLogStore;
|
|
478
490
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
479
491
|
this.isUploadingSnapshot = false;
|
|
480
492
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
481
493
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
482
494
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
483
495
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
496
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
497
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
498
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
499
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
500
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
501
|
+
}
|
|
484
502
|
}
|
|
485
503
|
async getWorldStateSyncStatus() {
|
|
486
504
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -498,20 +516,31 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
498
516
|
...inputConfig
|
|
499
517
|
}; // Copy the config so we dont mutate the input object
|
|
500
518
|
const log = deps.logger ?? createLogger('node');
|
|
501
|
-
const packageVersion = getPackageVersion()
|
|
519
|
+
const packageVersion = getPackageVersion();
|
|
502
520
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
503
521
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
504
522
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
505
|
-
// Build a key store from file if given or from environment otherwise
|
|
523
|
+
// Build a key store from file if given or from environment otherwise.
|
|
524
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
506
525
|
let keyStoreManager;
|
|
507
526
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
508
527
|
if (keyStoreProvided) {
|
|
509
528
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
510
529
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
530
|
} else {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
531
|
+
const rawKeyStores = [];
|
|
532
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
533
|
+
if (validatorKeyStore) {
|
|
534
|
+
rawKeyStores.push(validatorKeyStore);
|
|
535
|
+
}
|
|
536
|
+
if (config.enableProverNode) {
|
|
537
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
538
|
+
if (proverKeyStore) {
|
|
539
|
+
rawKeyStores.push(proverKeyStore);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (rawKeyStores.length > 0) {
|
|
543
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
515
544
|
}
|
|
516
545
|
}
|
|
517
546
|
await keyStoreManager?.validateSigners();
|
|
@@ -520,8 +549,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
520
549
|
if (keyStoreManager === undefined) {
|
|
521
550
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
551
|
}
|
|
523
|
-
if (!keyStoreProvided) {
|
|
524
|
-
log.warn(
|
|
552
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
553
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
525
554
|
}
|
|
526
555
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
556
|
}
|
|
@@ -531,9 +560,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
531
560
|
}
|
|
532
561
|
const publicClient = createPublicClient({
|
|
533
562
|
chain: ethereumChain.chainInfo,
|
|
534
|
-
transport:
|
|
535
|
-
|
|
536
|
-
|
|
563
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
564
|
+
timeout: config.l1HttpTimeoutMS
|
|
565
|
+
}),
|
|
537
566
|
pollingInterval: config.viemPollingIntervalMS
|
|
538
567
|
});
|
|
539
568
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -543,16 +572,17 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
543
572
|
...l1ContractsAddresses
|
|
544
573
|
};
|
|
545
574
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
575
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
547
576
|
rollupContract.getL1GenesisTime(),
|
|
548
577
|
rollupContract.getSlotDuration(),
|
|
549
|
-
rollupContract.getVersion()
|
|
578
|
+
rollupContract.getVersion(),
|
|
579
|
+
rollupContract.getManaLimit().then(Number)
|
|
550
580
|
]);
|
|
551
581
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
582
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
583
|
log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
|
|
554
584
|
}
|
|
555
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
585
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
556
586
|
// attempt snapshot sync if possible
|
|
557
587
|
await trySnapshotSync(config, log);
|
|
558
588
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
@@ -569,77 +599,98 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
569
599
|
// now create the merkle trees and the world state synchronizer
|
|
570
600
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
571
601
|
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
602
|
+
let debugLogStore;
|
|
572
603
|
if (!config.realProofs) {
|
|
573
604
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
605
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
606
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
607
|
+
} else {
|
|
608
|
+
debugLogStore = new NullDebugLogStore();
|
|
574
609
|
}
|
|
575
610
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
611
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
612
|
+
if (proverOnly) {
|
|
613
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
614
|
+
}
|
|
576
615
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
577
|
-
const p2pClient = await createP2PClient(
|
|
578
|
-
// We
|
|
579
|
-
|
|
580
|
-
// Create FullNodeCheckpointsBuilder for
|
|
616
|
+
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
617
|
+
// We'll accumulate sentinel watchers here
|
|
618
|
+
const watchers = [];
|
|
619
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
620
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
581
621
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
622
|
...config,
|
|
583
623
|
l1GenesisTime,
|
|
584
|
-
slotDuration: Number(slotDuration)
|
|
624
|
+
slotDuration: Number(slotDuration),
|
|
625
|
+
rollupManaLimit,
|
|
626
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
585
627
|
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
628
|
+
let validatorClient;
|
|
629
|
+
if (!proverOnly) {
|
|
630
|
+
// Create validator client if required
|
|
631
|
+
validatorClient = await createValidatorClient(config, {
|
|
632
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
633
|
+
worldState: worldStateSynchronizer,
|
|
634
|
+
p2pClient,
|
|
635
|
+
telemetry,
|
|
636
|
+
dateProvider,
|
|
637
|
+
epochCache,
|
|
638
|
+
blockSource: archiver,
|
|
639
|
+
l1ToL2MessageSource: archiver,
|
|
640
|
+
keyStoreManager,
|
|
641
|
+
blobClient,
|
|
642
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
643
|
+
});
|
|
644
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
645
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
646
|
+
// like attestations or auths will fail.
|
|
647
|
+
if (validatorClient) {
|
|
648
|
+
watchers.push(validatorClient);
|
|
649
|
+
if (!options.dontStartSequencer) {
|
|
650
|
+
await validatorClient.registerHandlers();
|
|
651
|
+
}
|
|
608
652
|
}
|
|
609
653
|
}
|
|
610
|
-
// If there's no validator client
|
|
611
|
-
//
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
654
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
655
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
656
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
657
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
658
|
+
if (!validatorClient) {
|
|
659
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
660
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
661
|
+
createProposalHandler(config, {
|
|
615
662
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
663
|
worldState: worldStateSynchronizer,
|
|
617
664
|
epochCache,
|
|
618
665
|
blockSource: archiver,
|
|
619
666
|
l1ToL2MessageSource: archiver,
|
|
620
667
|
p2pClient,
|
|
668
|
+
blobClient,
|
|
621
669
|
dateProvider,
|
|
622
670
|
telemetry
|
|
623
|
-
}).
|
|
671
|
+
}).register(p2pClient, reexecute);
|
|
624
672
|
}
|
|
625
673
|
// Start world state and wait for it to sync to the archiver.
|
|
626
674
|
await worldStateSynchronizer.start();
|
|
627
675
|
// Start p2p. Note that it depends on world state to be running.
|
|
628
676
|
await p2pClient.start();
|
|
629
|
-
|
|
630
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
-
watchers.push(validatorsSentinel);
|
|
632
|
-
}
|
|
677
|
+
let validatorsSentinel;
|
|
633
678
|
let epochPruneWatcher;
|
|
634
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
635
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
636
|
-
watchers.push(epochPruneWatcher);
|
|
637
|
-
}
|
|
638
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
639
679
|
let attestationsBlockWatcher;
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
|
|
680
|
+
if (!proverOnly) {
|
|
681
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
682
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
683
|
+
watchers.push(validatorsSentinel);
|
|
684
|
+
}
|
|
685
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
686
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
687
|
+
watchers.push(epochPruneWatcher);
|
|
688
|
+
}
|
|
689
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
690
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
691
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
692
|
+
watchers.push(attestationsBlockWatcher);
|
|
693
|
+
}
|
|
643
694
|
}
|
|
644
695
|
// Start p2p-related services once the archiver has completed sync
|
|
645
696
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
@@ -649,6 +700,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
649
700
|
await attestationsBlockWatcher?.start();
|
|
650
701
|
log.info(`All p2p services started`);
|
|
651
702
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
703
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
704
|
+
l1Contracts: config.l1Contracts,
|
|
705
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
706
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
707
|
+
l1GenesisTime,
|
|
708
|
+
slotDuration: Number(slotDuration)
|
|
709
|
+
});
|
|
652
710
|
// Validator enabled, create/start relevant service
|
|
653
711
|
let sequencer;
|
|
654
712
|
let slasherClient;
|
|
@@ -658,27 +716,30 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
658
716
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
717
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
718
|
await slasherClient.start();
|
|
661
|
-
const l1TxUtils = config.
|
|
719
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
662
720
|
...config,
|
|
663
721
|
scope: 'sequencer'
|
|
664
722
|
}, {
|
|
665
723
|
telemetry,
|
|
666
724
|
logger: log.createChild('l1-tx-utils'),
|
|
667
|
-
dateProvider
|
|
668
|
-
|
|
725
|
+
dateProvider,
|
|
726
|
+
kzg: Blob.getViemKzgInstance()
|
|
727
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
728
|
...config,
|
|
670
729
|
scope: 'sequencer'
|
|
671
730
|
}, {
|
|
672
731
|
telemetry,
|
|
673
732
|
logger: log.createChild('l1-tx-utils'),
|
|
674
|
-
dateProvider
|
|
733
|
+
dateProvider,
|
|
734
|
+
kzg: Blob.getViemKzgInstance()
|
|
675
735
|
});
|
|
676
736
|
// Create and start the sequencer client
|
|
677
737
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
678
738
|
...config,
|
|
679
739
|
l1GenesisTime,
|
|
680
|
-
slotDuration: Number(slotDuration)
|
|
681
|
-
|
|
740
|
+
slotDuration: Number(slotDuration),
|
|
741
|
+
rollupManaLimit
|
|
742
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
682
743
|
sequencer = await SequencerClient.new(config, {
|
|
683
744
|
...deps,
|
|
684
745
|
epochCache,
|
|
@@ -693,7 +754,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
693
754
|
telemetry,
|
|
694
755
|
dateProvider,
|
|
695
756
|
blobClient,
|
|
696
|
-
nodeKeyStore: keyStoreManager
|
|
757
|
+
nodeKeyStore: keyStoreManager,
|
|
758
|
+
globalVariableBuilder
|
|
697
759
|
});
|
|
698
760
|
}
|
|
699
761
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -702,13 +764,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
702
764
|
} else if (sequencer) {
|
|
703
765
|
log.warn(`Sequencer created but not started`);
|
|
704
766
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
767
|
+
// Create prover node subsystem if enabled
|
|
768
|
+
let proverNode;
|
|
769
|
+
if (config.enableProverNode) {
|
|
770
|
+
proverNode = await createProverNode(config, {
|
|
771
|
+
...deps.proverNodeDeps,
|
|
772
|
+
telemetry,
|
|
773
|
+
dateProvider,
|
|
774
|
+
archiver,
|
|
775
|
+
worldStateSynchronizer,
|
|
776
|
+
p2pClient,
|
|
777
|
+
epochCache,
|
|
778
|
+
blobClient,
|
|
779
|
+
keyStoreManager
|
|
780
|
+
});
|
|
781
|
+
if (!options.dontStartProverNode) {
|
|
782
|
+
await proverNode.start();
|
|
783
|
+
log.info(`Prover node subsystem started`);
|
|
784
|
+
} else {
|
|
785
|
+
log.info(`Prover node subsystem created but not started`);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
789
|
+
return node;
|
|
712
790
|
}
|
|
713
791
|
/**
|
|
714
792
|
* Returns the sequencer client instance.
|
|
@@ -716,6 +794,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
716
794
|
*/ getSequencer() {
|
|
717
795
|
return this.sequencer;
|
|
718
796
|
}
|
|
797
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
798
|
+
return this.proverNode;
|
|
799
|
+
}
|
|
719
800
|
getBlockSource() {
|
|
720
801
|
return this.blockSource;
|
|
721
802
|
}
|
|
@@ -735,7 +816,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
735
816
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
736
817
|
}
|
|
737
818
|
async getAllowedPublicSetup() {
|
|
738
|
-
return
|
|
819
|
+
return [
|
|
820
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
821
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
822
|
+
];
|
|
739
823
|
}
|
|
740
824
|
/**
|
|
741
825
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -758,7 +842,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
758
842
|
rollupVersion,
|
|
759
843
|
enr,
|
|
760
844
|
l1ContractAddresses: contractAddresses,
|
|
761
|
-
protocolContractAddresses: protocolContractAddresses
|
|
845
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
846
|
+
realProofs: !!this.config.realProofs
|
|
762
847
|
};
|
|
763
848
|
return nodeInfo;
|
|
764
849
|
}
|
|
@@ -767,8 +852,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
767
852
|
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
768
853
|
* @returns The requested block.
|
|
769
854
|
*/ async getBlock(block) {
|
|
770
|
-
if (
|
|
771
|
-
return this.getBlockByHash(
|
|
855
|
+
if (BlockHash.isBlockHash(block)) {
|
|
856
|
+
return this.getBlockByHash(block);
|
|
772
857
|
}
|
|
773
858
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
774
859
|
if (blockNumber === BlockNumber.ZERO) {
|
|
@@ -782,7 +867,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
782
867
|
* @returns The requested block.
|
|
783
868
|
*/ async getBlockByHash(blockHash) {
|
|
784
869
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
785
|
-
if (blockHash.equals(
|
|
870
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
786
871
|
return this.buildInitialBlock();
|
|
787
872
|
}
|
|
788
873
|
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
@@ -812,6 +897,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
812
897
|
async getCheckpointedBlocks(from, limit) {
|
|
813
898
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
814
899
|
}
|
|
900
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
901
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
902
|
+
}
|
|
815
903
|
/**
|
|
816
904
|
* Method to fetch the current min L2 fees.
|
|
817
905
|
* @returns The current min L2 fees.
|
|
@@ -839,6 +927,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
839
927
|
async getCheckpointedBlockNumber() {
|
|
840
928
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
929
|
}
|
|
930
|
+
getCheckpointNumber() {
|
|
931
|
+
return this.blockSource.getCheckpointNumber();
|
|
932
|
+
}
|
|
842
933
|
/**
|
|
843
934
|
* Method to fetch the version of the package.
|
|
844
935
|
* @returns The node package version
|
|
@@ -867,8 +958,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
867
958
|
if (referenceBlock) {
|
|
868
959
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
960
|
if (!referenceBlock.equals(initialBlockHash)) {
|
|
870
|
-
const
|
|
871
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
961
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
872
962
|
if (!header) {
|
|
873
963
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
874
964
|
}
|
|
@@ -880,8 +970,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
880
970
|
if (referenceBlock) {
|
|
881
971
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
882
972
|
if (!referenceBlock.equals(initialBlockHash)) {
|
|
883
|
-
const
|
|
884
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
973
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
885
974
|
if (!header) {
|
|
886
975
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
887
976
|
}
|
|
@@ -922,8 +1011,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
922
1011
|
throw new Error(`Invalid tx: ${reason}`);
|
|
923
1012
|
}
|
|
924
1013
|
await this.p2pClient.sendTx(tx);
|
|
925
|
-
|
|
926
|
-
this.
|
|
1014
|
+
const duration = timer.ms();
|
|
1015
|
+
this.metrics.receivedTx(duration, true);
|
|
1016
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
927
1017
|
txHash
|
|
928
1018
|
});
|
|
929
1019
|
}
|
|
@@ -934,18 +1024,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
934
1024
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
935
1025
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
936
1026
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1027
|
+
let receipt;
|
|
937
1028
|
if (settledTxReceipt) {
|
|
938
|
-
|
|
939
|
-
return settledTxReceipt;
|
|
1029
|
+
receipt = settledTxReceipt;
|
|
940
1030
|
} else if (isKnownToPool) {
|
|
941
1031
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
942
1032
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
943
1033
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
944
|
-
|
|
1034
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
945
1035
|
} else {
|
|
946
1036
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
947
|
-
|
|
1037
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
948
1038
|
}
|
|
1039
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1040
|
+
return receipt;
|
|
949
1041
|
}
|
|
950
1042
|
getTxEffect(txHash) {
|
|
951
1043
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -959,6 +1051,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
959
1051
|
await tryStop(this.slasherClient);
|
|
960
1052
|
await tryStop(this.proofVerifier);
|
|
961
1053
|
await tryStop(this.sequencer);
|
|
1054
|
+
await tryStop(this.proverNode);
|
|
962
1055
|
await tryStop(this.p2pClient);
|
|
963
1056
|
await tryStop(this.worldStateSynchronizer);
|
|
964
1057
|
await tryStop(this.blockSource);
|
|
@@ -997,79 +1090,89 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
997
1090
|
*/ async getTxsByHash(txHashes) {
|
|
998
1091
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
999
1092
|
}
|
|
1000
|
-
async findLeavesIndexes(
|
|
1001
|
-
const committedDb = await this
|
|
1093
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1094
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1002
1095
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1003
|
-
//
|
|
1004
|
-
const
|
|
1005
|
-
// Now we find the block numbers for the indices
|
|
1006
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1007
|
-
//
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1096
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1097
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1098
|
+
// Now we find the block numbers for the defined indices
|
|
1099
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1100
|
+
// Build a map from leaf index to block number
|
|
1101
|
+
const indexToBlockNumber = new Map();
|
|
1102
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1103
|
+
const blockNumber = blockNumbers[i];
|
|
1104
|
+
if (blockNumber === undefined) {
|
|
1105
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1011
1106
|
}
|
|
1107
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1012
1108
|
}
|
|
1013
1109
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1014
1110
|
const uniqueBlockNumbers = [
|
|
1015
|
-
...new Set(
|
|
1111
|
+
...new Set(indexToBlockNumber.values())
|
|
1016
1112
|
];
|
|
1017
|
-
// Now we obtain the block hashes from the archive tree
|
|
1018
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1113
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1019
1114
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1020
1115
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1021
1116
|
}));
|
|
1022
|
-
//
|
|
1117
|
+
// Build a map from block number to block hash
|
|
1118
|
+
const blockNumberToHash = new Map();
|
|
1023
1119
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1024
|
-
|
|
1120
|
+
const blockHash = blockHashes[i];
|
|
1121
|
+
if (blockHash === undefined) {
|
|
1025
1122
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1026
1123
|
}
|
|
1124
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1027
1125
|
}
|
|
1028
1126
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1029
|
-
return maybeIndices.map((index
|
|
1127
|
+
return maybeIndices.map((index)=>{
|
|
1030
1128
|
if (index === undefined) {
|
|
1031
1129
|
return undefined;
|
|
1032
1130
|
}
|
|
1033
|
-
const blockNumber =
|
|
1131
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1034
1132
|
if (blockNumber === undefined) {
|
|
1035
|
-
|
|
1133
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1036
1134
|
}
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return undefined;
|
|
1135
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1136
|
+
if (blockHash === undefined) {
|
|
1137
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1041
1138
|
}
|
|
1042
1139
|
return {
|
|
1043
|
-
l2BlockNumber:
|
|
1044
|
-
l2BlockHash:
|
|
1140
|
+
l2BlockNumber: blockNumber,
|
|
1141
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
1045
1142
|
data: index
|
|
1046
1143
|
};
|
|
1047
1144
|
});
|
|
1048
1145
|
}
|
|
1049
|
-
async
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1146
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1147
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1148
|
+
if (referenceBlock === BlockNumber.ZERO) {
|
|
1149
|
+
return undefined;
|
|
1150
|
+
}
|
|
1151
|
+
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1152
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1153
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1154
|
+
return undefined;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1158
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1159
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1160
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1161
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1059
1162
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1060
|
-
|
|
1163
|
+
blockHash
|
|
1061
1164
|
]);
|
|
1062
1165
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1063
1166
|
}
|
|
1064
|
-
async getNoteHashMembershipWitness(
|
|
1065
|
-
const committedDb = await this
|
|
1167
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1168
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1066
1169
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1067
1170
|
noteHash
|
|
1068
1171
|
]);
|
|
1069
1172
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1070
1173
|
}
|
|
1071
|
-
async getL1ToL2MessageMembershipWitness(
|
|
1072
|
-
const db = await this
|
|
1174
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1175
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1073
1176
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1074
1177
|
l1ToL2Message
|
|
1075
1178
|
]);
|
|
@@ -1082,9 +1185,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1082
1185
|
witness.path
|
|
1083
1186
|
];
|
|
1084
1187
|
}
|
|
1085
|
-
async
|
|
1188
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1086
1189
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1087
|
-
return messageIndex ?
|
|
1190
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1088
1191
|
}
|
|
1089
1192
|
/**
|
|
1090
1193
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1101,31 +1204,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1101
1204
|
*/ async getL2ToL1Messages(epoch) {
|
|
1102
1205
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1103
1206
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1104
|
-
const blocksInCheckpoints =
|
|
1105
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1106
|
-
let checkpointIndex = -1;
|
|
1107
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1108
|
-
const block = checkpointedBlock.block;
|
|
1109
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1110
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1111
|
-
checkpointIndex++;
|
|
1112
|
-
blocksInCheckpoints.push([]);
|
|
1113
|
-
previousSlotNumber = slotNumber;
|
|
1114
|
-
}
|
|
1115
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1116
|
-
}
|
|
1207
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1117
1208
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1118
1209
|
}
|
|
1119
|
-
async
|
|
1120
|
-
const
|
|
1121
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1122
|
-
}
|
|
1123
|
-
async getPublicDataSiblingPath(block, leafIndex) {
|
|
1124
|
-
const committedDb = await this.#getWorldState(block);
|
|
1125
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1126
|
-
}
|
|
1127
|
-
async getNullifierMembershipWitness(block, nullifier) {
|
|
1128
|
-
const db = await this.#getWorldState(block);
|
|
1210
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1211
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1129
1212
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1130
1213
|
nullifier.toBuffer()
|
|
1131
1214
|
]);
|
|
@@ -1139,35 +1222,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1139
1222
|
}
|
|
1140
1223
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1141
1224
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1145
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1146
|
-
* @returns The low nullifier membership witness (if found).
|
|
1147
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1148
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1149
|
-
* we are trying to prove non-inclusion for.
|
|
1150
|
-
*
|
|
1151
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1152
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1153
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1154
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1155
|
-
*/ async getLowNullifierMembershipWitness(block, nullifier) {
|
|
1156
|
-
const committedDb = await this.#getWorldState(block);
|
|
1225
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1226
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1157
1227
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1158
1228
|
if (!findResult) {
|
|
1159
1229
|
return undefined;
|
|
1160
1230
|
}
|
|
1161
1231
|
const { index, alreadyPresent } = findResult;
|
|
1162
1232
|
if (alreadyPresent) {
|
|
1163
|
-
|
|
1233
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1164
1234
|
}
|
|
1165
1235
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1166
1236
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1167
1237
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1168
1238
|
}
|
|
1169
|
-
async getPublicDataWitness(
|
|
1170
|
-
const committedDb = await this
|
|
1239
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1240
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1171
1241
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1172
1242
|
if (!lowLeafResult) {
|
|
1173
1243
|
return undefined;
|
|
@@ -1177,8 +1247,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1177
1247
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1178
1248
|
}
|
|
1179
1249
|
}
|
|
1180
|
-
async getPublicStorageAt(
|
|
1181
|
-
const committedDb = await this
|
|
1250
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1251
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1182
1252
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1183
1253
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1184
1254
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1188,14 +1258,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1188
1258
|
return preimage.leaf.value;
|
|
1189
1259
|
}
|
|
1190
1260
|
async getBlockHeader(block = 'latest') {
|
|
1191
|
-
if (
|
|
1261
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1192
1262
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1193
1263
|
if (block.equals(initialBlockHash)) {
|
|
1194
1264
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1195
1265
|
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1196
1266
|
}
|
|
1197
|
-
|
|
1198
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1267
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1199
1268
|
} else {
|
|
1200
1269
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1201
1270
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
@@ -1212,6 +1281,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1212
1281
|
*/ async getBlockHeaderByArchive(archive) {
|
|
1213
1282
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1214
1283
|
}
|
|
1284
|
+
getBlockData(number) {
|
|
1285
|
+
return this.blockSource.getBlockData(number);
|
|
1286
|
+
}
|
|
1287
|
+
getBlockDataByArchive(archive) {
|
|
1288
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1289
|
+
}
|
|
1215
1290
|
/**
|
|
1216
1291
|
* Simulates the public part of a transaction with the current state.
|
|
1217
1292
|
* @param tx - The transaction to simulate.
|
|
@@ -1224,17 +1299,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1224
1299
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1225
1300
|
}
|
|
1226
1301
|
const txHash = tx.getTxHash();
|
|
1227
|
-
const
|
|
1302
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1303
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1228
1304
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1229
1305
|
const coinbase = EthAddress.ZERO;
|
|
1230
1306
|
const feeRecipient = AztecAddress.ZERO;
|
|
1231
1307
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1232
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1308
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1233
1309
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1234
1310
|
globalVariables: newGlobalVariables.toInspect(),
|
|
1235
1311
|
txHash,
|
|
1236
1312
|
blockNumber
|
|
1237
1313
|
});
|
|
1314
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1315
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1238
1316
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1239
1317
|
try {
|
|
1240
1318
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1249,7 +1327,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1249
1327
|
});
|
|
1250
1328
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1251
1329
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1252
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1330
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1253
1331
|
tx
|
|
1254
1332
|
]);
|
|
1255
1333
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1260,7 +1338,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1260
1338
|
throw failedTxs[0].error;
|
|
1261
1339
|
}
|
|
1262
1340
|
const [processedTx] = processedTxs;
|
|
1263
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1341
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1264
1342
|
} finally{
|
|
1265
1343
|
await merkleTreeFork.close();
|
|
1266
1344
|
}
|
|
@@ -1268,19 +1346,26 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1268
1346
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1269
1347
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1270
1348
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1271
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1349
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1272
1350
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1273
1351
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1274
|
-
const
|
|
1352
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1353
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1275
1354
|
timestamp: nextSlotTimestamp,
|
|
1276
1355
|
blockNumber,
|
|
1277
1356
|
l1ChainId: this.l1ChainId,
|
|
1278
1357
|
rollupVersion: this.version,
|
|
1279
|
-
setupAllowList:
|
|
1358
|
+
setupAllowList: [
|
|
1359
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1360
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1361
|
+
],
|
|
1280
1362
|
gasFees: await this.getCurrentMinFees(),
|
|
1281
1363
|
skipFeeEnforcement,
|
|
1282
|
-
txsPermitted: !this.config.disableTransactions
|
|
1283
|
-
|
|
1364
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1365
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1366
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1367
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1368
|
+
}, this.log.getBindings());
|
|
1284
1369
|
return await validator.validateTx(tx);
|
|
1285
1370
|
}
|
|
1286
1371
|
getConfig() {
|
|
@@ -1422,6 +1507,100 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1422
1507
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1423
1508
|
}
|
|
1424
1509
|
}
|
|
1510
|
+
async reloadKeystore() {
|
|
1511
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1512
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1513
|
+
}
|
|
1514
|
+
if (!this.validatorClient) {
|
|
1515
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1516
|
+
}
|
|
1517
|
+
this.log.info('Reloading keystore from disk');
|
|
1518
|
+
// Re-read and validate keystore files
|
|
1519
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1520
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1521
|
+
await newManager.validateSigners();
|
|
1522
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1523
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1524
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1525
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1526
|
+
// would silently fail on every proposer slot.
|
|
1527
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1528
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1529
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1530
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1531
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1532
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1533
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1534
|
+
throw new BadRequestError(`Cannot reload keystore: validator ${attester} has publisher keys ` + `[${pubs.map((p)=>p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` + `[${[
|
|
1535
|
+
...availablePublishers
|
|
1536
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
// Build adapters for old and new keystores to compute diff
|
|
1541
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1542
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1543
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1544
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1545
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1546
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1547
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1548
|
+
if (added.length > 0) {
|
|
1549
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1550
|
+
}
|
|
1551
|
+
if (removed.length > 0) {
|
|
1552
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1553
|
+
}
|
|
1554
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1555
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1556
|
+
}
|
|
1557
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1558
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1559
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1560
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1561
|
+
if (this.sequencer) {
|
|
1562
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1563
|
+
}
|
|
1564
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1565
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1566
|
+
const slashValidatorsNever = unique([
|
|
1567
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1568
|
+
...newAddresses
|
|
1569
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1570
|
+
this.slasherClient.updateConfig({
|
|
1571
|
+
slashValidatorsNever
|
|
1572
|
+
});
|
|
1573
|
+
}
|
|
1574
|
+
this.keyStoreManager = newManager;
|
|
1575
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1576
|
+
}
|
|
1577
|
+
async mineBlock() {
|
|
1578
|
+
if (!this.sequencer) {
|
|
1579
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1580
|
+
}
|
|
1581
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1582
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1583
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1584
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1585
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1586
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1587
|
+
this.sequencer.updateConfig({
|
|
1588
|
+
minTxsPerBlock: 0
|
|
1589
|
+
});
|
|
1590
|
+
try {
|
|
1591
|
+
// Trigger the sequencer to produce a block immediately
|
|
1592
|
+
void this.sequencer.trigger();
|
|
1593
|
+
// Wait for the new L2 block to appear
|
|
1594
|
+
await retryUntil(async ()=>{
|
|
1595
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1596
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1597
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1598
|
+
} finally{
|
|
1599
|
+
this.sequencer.updateConfig({
|
|
1600
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1425
1604
|
#getInitialHeaderHash() {
|
|
1426
1605
|
if (!this.initialHeaderHashPromise) {
|
|
1427
1606
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1432,7 +1611,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1432
1611
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1433
1612
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1434
1613
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1435
|
-
*/ async
|
|
1614
|
+
*/ async getWorldState(block) {
|
|
1436
1615
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1437
1616
|
try {
|
|
1438
1617
|
// Attempt to sync the world state if necessary
|
|
@@ -1444,30 +1623,53 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1444
1623
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1445
1624
|
return this.worldStateSynchronizer.getCommitted();
|
|
1446
1625
|
}
|
|
1447
|
-
|
|
1626
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1627
|
+
let blockNumber;
|
|
1628
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1448
1629
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1449
1630
|
if (block.equals(initialBlockHash)) {
|
|
1450
1631
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1451
1632
|
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1452
1633
|
}
|
|
1453
|
-
const
|
|
1454
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1634
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1455
1635
|
if (!header) {
|
|
1456
1636
|
throw new Error(`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.`);
|
|
1457
1637
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1462
|
-
//
|
|
1463
|
-
{
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1638
|
+
blockNumber = header.getBlockNumber();
|
|
1639
|
+
} else {
|
|
1640
|
+
blockNumber = block;
|
|
1641
|
+
}
|
|
1642
|
+
// Check it's within world state sync range
|
|
1643
|
+
if (blockNumber > blockSyncedTo) {
|
|
1644
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1645
|
+
}
|
|
1646
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1647
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1648
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1649
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1650
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1651
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1652
|
+
throw new Error(`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.`);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
return snapshot;
|
|
1656
|
+
}
|
|
1657
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1658
|
+
if (block === 'latest') {
|
|
1659
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1660
|
+
}
|
|
1661
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1662
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1663
|
+
if (block.equals(initialBlockHash)) {
|
|
1664
|
+
return BlockNumber.ZERO;
|
|
1665
|
+
}
|
|
1666
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1667
|
+
if (!header) {
|
|
1668
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1467
1669
|
}
|
|
1468
|
-
|
|
1469
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1670
|
+
return header.getBlockNumber();
|
|
1470
1671
|
}
|
|
1672
|
+
return block;
|
|
1471
1673
|
}
|
|
1472
1674
|
/**
|
|
1473
1675
|
* Ensure we fully sync the world state
|