@aztec/aztec-node 0.0.1-commit.b1c78909e → 0.0.1-commit.b2a5d0dd1
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/server.d.ts +29 -31
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +397 -276
- package/dest/sentinel/sentinel.js +6 -6
- package/package.json +26 -27
- package/src/aztec-node/server.ts +485 -350
- package/src/sentinel/sentinel.ts +6 -6
|
@@ -372,19 +372,21 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
372
372
|
}
|
|
373
373
|
var _dec, _initProto;
|
|
374
374
|
import { createArchiver } from '@aztec/archiver';
|
|
375
|
-
import { BBCircuitVerifier,
|
|
375
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
376
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
376
377
|
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
377
378
|
import { Blob } from '@aztec/blob-lib';
|
|
378
379
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
379
380
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
381
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
382
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
-
import { BlockNumber
|
|
383
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
383
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
384
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
385
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
385
386
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
387
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
387
388
|
import { createLogger } from '@aztec/foundation/log';
|
|
389
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
388
390
|
import { count } from '@aztec/foundation/string';
|
|
389
391
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
390
392
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
@@ -395,7 +397,7 @@ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAll
|
|
|
395
397
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
398
|
import { createProverNode } from '@aztec/prover-node';
|
|
397
399
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
398
|
-
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
400
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
399
401
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
400
402
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
401
403
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
@@ -411,9 +413,9 @@ import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@az
|
|
|
411
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
412
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
413
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
415
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
416
|
-
import { createPublicClient
|
|
418
|
+
import { createPublicClient } from 'viem';
|
|
417
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
418
420
|
import { createKeyStoreForValidator } from './config.js';
|
|
419
421
|
import { NodeMetrics } from './node_metrics.js';
|
|
@@ -438,9 +440,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
438
440
|
l1ChainId;
|
|
439
441
|
version;
|
|
440
442
|
globalVariableBuilder;
|
|
443
|
+
feeProvider;
|
|
441
444
|
epochCache;
|
|
442
445
|
packageVersion;
|
|
443
|
-
|
|
446
|
+
peerProofVerifier;
|
|
447
|
+
rpcProofVerifier;
|
|
444
448
|
telemetry;
|
|
445
449
|
log;
|
|
446
450
|
blobClient;
|
|
@@ -461,7 +465,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
461
465
|
// Prevent two snapshot operations to happen simultaneously
|
|
462
466
|
isUploadingSnapshot;
|
|
463
467
|
tracer;
|
|
464
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
468
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
465
469
|
this.config = config;
|
|
466
470
|
this.p2pClient = p2pClient;
|
|
467
471
|
this.blockSource = blockSource;
|
|
@@ -477,9 +481,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
477
481
|
this.l1ChainId = l1ChainId;
|
|
478
482
|
this.version = version;
|
|
479
483
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
484
|
+
this.feeProvider = feeProvider;
|
|
480
485
|
this.epochCache = epochCache;
|
|
481
486
|
this.packageVersion = packageVersion;
|
|
482
|
-
this.
|
|
487
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
488
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
483
489
|
this.telemetry = telemetry;
|
|
484
490
|
this.log = log;
|
|
485
491
|
this.blobClient = blobClient;
|
|
@@ -499,6 +505,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
499
505
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
500
506
|
}
|
|
501
507
|
}
|
|
508
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
509
|
+
return this.rpcProofVerifier;
|
|
510
|
+
}
|
|
502
511
|
async getWorldStateSyncStatus() {
|
|
503
512
|
const status = await this.worldStateSynchronizer.status();
|
|
504
513
|
return status.syncSummary;
|
|
@@ -559,9 +568,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
559
568
|
}
|
|
560
569
|
const publicClient = createPublicClient({
|
|
561
570
|
chain: ethereumChain.chainInfo,
|
|
562
|
-
transport:
|
|
563
|
-
|
|
564
|
-
|
|
571
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
572
|
+
timeout: config.l1HttpTimeoutMS
|
|
573
|
+
}),
|
|
565
574
|
pollingInterval: config.viemPollingIntervalMS
|
|
566
575
|
});
|
|
567
576
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -587,200 +596,252 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
587
596
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
588
597
|
dateProvider
|
|
589
598
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}, {
|
|
596
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
597
|
-
});
|
|
598
|
-
// now create the merkle trees and the world state synchronizer
|
|
599
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
600
|
-
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
601
|
-
let debugLogStore;
|
|
602
|
-
if (!config.realProofs) {
|
|
603
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
604
|
-
debugLogStore = new InMemoryDebugLogStore();
|
|
605
|
-
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
606
|
-
} else {
|
|
607
|
-
debugLogStore = new NullDebugLogStore();
|
|
608
|
-
}
|
|
609
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
610
|
-
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
611
|
-
if (proverOnly) {
|
|
612
|
-
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
613
|
-
}
|
|
614
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
615
|
-
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
616
|
-
// We'll accumulate sentinel watchers here
|
|
617
|
-
const watchers = [];
|
|
618
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
619
|
-
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
620
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
621
|
-
...config,
|
|
622
|
-
l1GenesisTime,
|
|
623
|
-
slotDuration: Number(slotDuration),
|
|
624
|
-
rollupManaLimit,
|
|
625
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
626
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
627
|
-
let validatorClient;
|
|
628
|
-
if (!proverOnly) {
|
|
629
|
-
// Create validator client if required
|
|
630
|
-
validatorClient = await createValidatorClient(config, {
|
|
631
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
632
|
-
worldState: worldStateSynchronizer,
|
|
633
|
-
p2pClient,
|
|
634
|
-
telemetry,
|
|
635
|
-
dateProvider,
|
|
599
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
600
|
+
const started = [];
|
|
601
|
+
try {
|
|
602
|
+
const archiver = await createArchiver(config, {
|
|
603
|
+
blobClient,
|
|
636
604
|
epochCache,
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
605
|
+
telemetry,
|
|
606
|
+
dateProvider
|
|
607
|
+
}, {
|
|
608
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
641
609
|
});
|
|
642
|
-
|
|
643
|
-
//
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
657
|
-
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
658
|
-
createBlockProposalHandler(config, {
|
|
659
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
660
|
-
worldState: worldStateSynchronizer,
|
|
661
|
-
epochCache,
|
|
662
|
-
blockSource: archiver,
|
|
663
|
-
l1ToL2MessageSource: archiver,
|
|
664
|
-
p2pClient,
|
|
665
|
-
dateProvider,
|
|
666
|
-
telemetry
|
|
667
|
-
}).register(p2pClient, reexecute);
|
|
668
|
-
}
|
|
669
|
-
// Start world state and wait for it to sync to the archiver.
|
|
670
|
-
await worldStateSynchronizer.start();
|
|
671
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
672
|
-
await p2pClient.start();
|
|
673
|
-
let validatorsSentinel;
|
|
674
|
-
let epochPruneWatcher;
|
|
675
|
-
let attestationsBlockWatcher;
|
|
676
|
-
if (!proverOnly) {
|
|
677
|
-
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
678
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
679
|
-
watchers.push(validatorsSentinel);
|
|
610
|
+
started.push(archiver);
|
|
611
|
+
// now create the merkle trees and the world state synchronizer
|
|
612
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
613
|
+
started.push(worldStateSynchronizer);
|
|
614
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
615
|
+
let peerProofVerifier;
|
|
616
|
+
let rpcProofVerifier;
|
|
617
|
+
if (useRealVerifiers) {
|
|
618
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
619
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
620
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
621
|
+
} else {
|
|
622
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
623
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
680
624
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
625
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
626
|
+
let debugLogStore;
|
|
627
|
+
if (!config.realProofs) {
|
|
628
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
629
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
630
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
631
|
+
} else {
|
|
632
|
+
debugLogStore = new NullDebugLogStore();
|
|
684
633
|
}
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
634
|
+
const globalVariableBuilderConfig = {
|
|
635
|
+
l1Contracts: config.l1Contracts,
|
|
636
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
637
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
638
|
+
l1GenesisTime,
|
|
639
|
+
slotDuration: Number(slotDuration)
|
|
640
|
+
};
|
|
641
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
642
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
643
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
644
|
+
if (proverOnly) {
|
|
645
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
689
646
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
699
|
-
// Validator enabled, create/start relevant service
|
|
700
|
-
let sequencer;
|
|
701
|
-
let slasherClient;
|
|
702
|
-
if (!config.disableValidator && validatorClient) {
|
|
703
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
704
|
-
// as they are executed when the node is selected as proposer.
|
|
705
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
706
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
707
|
-
await slasherClient.start();
|
|
708
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
709
|
-
...config,
|
|
710
|
-
scope: 'sequencer'
|
|
711
|
-
}, {
|
|
712
|
-
telemetry,
|
|
713
|
-
logger: log.createChild('l1-tx-utils'),
|
|
714
|
-
dateProvider,
|
|
715
|
-
kzg: Blob.getViemKzgInstance()
|
|
716
|
-
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
717
|
-
...config,
|
|
718
|
-
scope: 'sequencer'
|
|
719
|
-
}, {
|
|
720
|
-
telemetry,
|
|
721
|
-
logger: log.createChild('l1-tx-utils'),
|
|
722
|
-
dateProvider,
|
|
723
|
-
kzg: Blob.getViemKzgInstance()
|
|
724
|
-
});
|
|
725
|
-
// Create and start the sequencer client
|
|
726
|
-
const checkpointsBuilder = new CheckpointsBuilder({
|
|
647
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
648
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
649
|
+
started.push(p2pClient);
|
|
650
|
+
// We'll accumulate sentinel watchers here
|
|
651
|
+
const watchers = [];
|
|
652
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
653
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
654
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
727
655
|
...config,
|
|
728
656
|
l1GenesisTime,
|
|
729
657
|
slotDuration: Number(slotDuration),
|
|
730
|
-
rollupManaLimit
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
validatorClient,
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
658
|
+
rollupManaLimit,
|
|
659
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
660
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
661
|
+
let validatorClient;
|
|
662
|
+
if (!proverOnly) {
|
|
663
|
+
// Create validator client if required
|
|
664
|
+
validatorClient = await createValidatorClient(config, {
|
|
665
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
666
|
+
worldState: worldStateSynchronizer,
|
|
667
|
+
p2pClient,
|
|
668
|
+
telemetry,
|
|
669
|
+
dateProvider,
|
|
670
|
+
epochCache,
|
|
671
|
+
blockSource: archiver,
|
|
672
|
+
l1ToL2MessageSource: archiver,
|
|
673
|
+
keyStoreManager,
|
|
674
|
+
blobClient,
|
|
675
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
676
|
+
});
|
|
677
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
678
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
679
|
+
// like attestations or auths will fail.
|
|
680
|
+
if (validatorClient) {
|
|
681
|
+
watchers.push(validatorClient);
|
|
682
|
+
const vc = validatorClient;
|
|
683
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
684
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
685
|
+
if (!options.dontStartSequencer) {
|
|
686
|
+
await validatorClient.registerHandlers();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
691
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
692
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
693
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
694
|
+
if (!validatorClient) {
|
|
695
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
696
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
697
|
+
createProposalHandler(config, {
|
|
698
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
699
|
+
worldState: worldStateSynchronizer,
|
|
700
|
+
epochCache,
|
|
701
|
+
blockSource: archiver,
|
|
702
|
+
l1ToL2MessageSource: archiver,
|
|
703
|
+
p2pClient,
|
|
704
|
+
blobClient,
|
|
705
|
+
dateProvider,
|
|
706
|
+
telemetry
|
|
707
|
+
}).register(p2pClient, reexecute, archiver);
|
|
774
708
|
}
|
|
709
|
+
// Start world state and wait for it to sync to the archiver.
|
|
710
|
+
await worldStateSynchronizer.start();
|
|
711
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
712
|
+
await p2pClient.start();
|
|
713
|
+
let validatorsSentinel;
|
|
714
|
+
let epochPruneWatcher;
|
|
715
|
+
let attestationsBlockWatcher;
|
|
716
|
+
if (!proverOnly) {
|
|
717
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
718
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
719
|
+
watchers.push(validatorsSentinel);
|
|
720
|
+
}
|
|
721
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
722
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
723
|
+
watchers.push(epochPruneWatcher);
|
|
724
|
+
}
|
|
725
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
726
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
727
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
728
|
+
watchers.push(attestationsBlockWatcher);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
// Start p2p-related services once the archiver has completed sync
|
|
732
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
733
|
+
await validatorsSentinel?.start();
|
|
734
|
+
await epochPruneWatcher?.start();
|
|
735
|
+
await attestationsBlockWatcher?.start();
|
|
736
|
+
log.info(`All p2p services started`);
|
|
737
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
738
|
+
// Validator enabled, create/start relevant service
|
|
739
|
+
let sequencer;
|
|
740
|
+
let slasherClient;
|
|
741
|
+
if (!config.disableValidator && validatorClient) {
|
|
742
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
743
|
+
// as they are executed when the node is selected as proposer.
|
|
744
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
745
|
+
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
746
|
+
await slasherClient.start();
|
|
747
|
+
started.push(slasherClient);
|
|
748
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
749
|
+
...config,
|
|
750
|
+
scope: 'sequencer'
|
|
751
|
+
}, {
|
|
752
|
+
telemetry,
|
|
753
|
+
logger: log.createChild('l1-tx-utils'),
|
|
754
|
+
dateProvider,
|
|
755
|
+
kzg: Blob.getViemKzgInstance()
|
|
756
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
757
|
+
...config,
|
|
758
|
+
scope: 'sequencer'
|
|
759
|
+
}, {
|
|
760
|
+
telemetry,
|
|
761
|
+
logger: log.createChild('l1-tx-utils'),
|
|
762
|
+
dateProvider,
|
|
763
|
+
kzg: Blob.getViemKzgInstance()
|
|
764
|
+
});
|
|
765
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
766
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
767
|
+
let funderL1TxUtils;
|
|
768
|
+
if (fundingSigner) {
|
|
769
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
770
|
+
fundingSigner
|
|
771
|
+
], {
|
|
772
|
+
...config,
|
|
773
|
+
scope: 'sequencer'
|
|
774
|
+
}, {
|
|
775
|
+
telemetry,
|
|
776
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
777
|
+
dateProvider
|
|
778
|
+
});
|
|
779
|
+
funderL1TxUtils = funder;
|
|
780
|
+
}
|
|
781
|
+
// Create and start the sequencer client
|
|
782
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
783
|
+
...config,
|
|
784
|
+
l1GenesisTime,
|
|
785
|
+
slotDuration: Number(slotDuration),
|
|
786
|
+
rollupManaLimit
|
|
787
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
788
|
+
sequencer = await SequencerClient.new(config, {
|
|
789
|
+
...deps,
|
|
790
|
+
epochCache,
|
|
791
|
+
l1TxUtils,
|
|
792
|
+
funderL1TxUtils,
|
|
793
|
+
validatorClient,
|
|
794
|
+
p2pClient,
|
|
795
|
+
worldStateSynchronizer,
|
|
796
|
+
slasherClient,
|
|
797
|
+
checkpointsBuilder,
|
|
798
|
+
l2BlockSource: archiver,
|
|
799
|
+
l1ToL2MessageSource: archiver,
|
|
800
|
+
telemetry,
|
|
801
|
+
dateProvider,
|
|
802
|
+
blobClient,
|
|
803
|
+
nodeKeyStore: keyStoreManager,
|
|
804
|
+
globalVariableBuilder
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
808
|
+
await sequencer.start();
|
|
809
|
+
started.push(sequencer);
|
|
810
|
+
log.verbose(`Sequencer started`);
|
|
811
|
+
} else if (sequencer) {
|
|
812
|
+
log.warn(`Sequencer created but not started`);
|
|
813
|
+
}
|
|
814
|
+
// Create prover node subsystem if enabled
|
|
815
|
+
let proverNode;
|
|
816
|
+
if (config.enableProverNode) {
|
|
817
|
+
proverNode = await createProverNode(config, {
|
|
818
|
+
...deps.proverNodeDeps,
|
|
819
|
+
telemetry,
|
|
820
|
+
dateProvider,
|
|
821
|
+
archiver,
|
|
822
|
+
worldStateSynchronizer,
|
|
823
|
+
p2pClient,
|
|
824
|
+
epochCache,
|
|
825
|
+
blobClient,
|
|
826
|
+
keyStoreManager
|
|
827
|
+
});
|
|
828
|
+
if (!options.dontStartProverNode) {
|
|
829
|
+
await proverNode.start();
|
|
830
|
+
started.push(proverNode);
|
|
831
|
+
log.info(`Prover node subsystem started`);
|
|
832
|
+
} else {
|
|
833
|
+
log.info(`Prover node subsystem created but not started`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
837
|
+
return node;
|
|
838
|
+
} catch (err) {
|
|
839
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
840
|
+
for (const resource of started.reverse()){
|
|
841
|
+
await tryStop(resource);
|
|
842
|
+
}
|
|
843
|
+
throw err;
|
|
775
844
|
}
|
|
776
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
777
|
-
...config,
|
|
778
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
779
|
-
l1GenesisTime,
|
|
780
|
-
slotDuration: Number(slotDuration)
|
|
781
|
-
});
|
|
782
|
-
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);
|
|
783
|
-
return node;
|
|
784
845
|
}
|
|
785
846
|
/**
|
|
786
847
|
* Returns the sequencer client instance.
|
|
@@ -891,11 +952,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
891
952
|
async getCheckpointedBlocks(from, limit) {
|
|
892
953
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
893
954
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
return await this.
|
|
955
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
956
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
957
|
+
}
|
|
958
|
+
async getCurrentMinFees() {
|
|
959
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
960
|
+
}
|
|
961
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
962
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
899
963
|
}
|
|
900
964
|
async getMaxPriorityFees() {
|
|
901
965
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -946,28 +1010,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
946
1010
|
return this.contractDataSource.getContract(address);
|
|
947
1011
|
}
|
|
948
1012
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
1013
|
+
let upToBlockNumber;
|
|
949
1014
|
if (referenceBlock) {
|
|
950
1015
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
951
|
-
if (
|
|
1016
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1017
|
+
upToBlockNumber = BlockNumber(0);
|
|
1018
|
+
} else {
|
|
952
1019
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
953
1020
|
if (!header) {
|
|
954
1021
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
955
1022
|
}
|
|
1023
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
956
1024
|
}
|
|
957
1025
|
}
|
|
958
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1026
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
959
1027
|
}
|
|
960
1028
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1029
|
+
let upToBlockNumber;
|
|
961
1030
|
if (referenceBlock) {
|
|
962
1031
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
963
|
-
if (
|
|
1032
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1033
|
+
upToBlockNumber = BlockNumber(0);
|
|
1034
|
+
} else {
|
|
964
1035
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
965
1036
|
if (!header) {
|
|
966
1037
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
967
1038
|
}
|
|
1039
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
968
1040
|
}
|
|
969
1041
|
}
|
|
970
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1042
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
971
1043
|
}
|
|
972
1044
|
/**
|
|
973
1045
|
* Gets public logs based on the provided filter.
|
|
@@ -1040,7 +1112,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1040
1112
|
await tryStop(this.validatorsSentinel);
|
|
1041
1113
|
await tryStop(this.epochPruneWatcher);
|
|
1042
1114
|
await tryStop(this.slasherClient);
|
|
1043
|
-
await
|
|
1115
|
+
await Promise.all([
|
|
1116
|
+
tryStop(this.peerProofVerifier),
|
|
1117
|
+
tryStop(this.rpcProofVerifier)
|
|
1118
|
+
]);
|
|
1044
1119
|
await tryStop(this.sequencer);
|
|
1045
1120
|
await tryStop(this.proverNode);
|
|
1046
1121
|
await tryStop(this.p2pClient);
|
|
@@ -1082,7 +1157,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1082
1157
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1083
1158
|
}
|
|
1084
1159
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1085
|
-
const committedDb = await this
|
|
1160
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1086
1161
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1087
1162
|
// Filter out undefined values to query block numbers only for found leaves
|
|
1088
1163
|
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
@@ -1123,33 +1198,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1123
1198
|
if (blockNumber === undefined) {
|
|
1124
1199
|
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1125
1200
|
}
|
|
1126
|
-
const
|
|
1127
|
-
if (
|
|
1201
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1202
|
+
if (l2BlockHash === undefined) {
|
|
1128
1203
|
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1129
1204
|
}
|
|
1130
1205
|
return {
|
|
1131
1206
|
l2BlockNumber: blockNumber,
|
|
1132
|
-
l2BlockHash
|
|
1207
|
+
l2BlockHash,
|
|
1133
1208
|
data: index
|
|
1134
1209
|
};
|
|
1135
1210
|
});
|
|
1136
1211
|
}
|
|
1137
1212
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1138
|
-
|
|
1213
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1214
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1215
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1216
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1217
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1218
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1219
|
+
return undefined;
|
|
1220
|
+
}
|
|
1221
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1139
1222
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1140
1223
|
blockHash
|
|
1141
1224
|
]);
|
|
1142
1225
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1143
1226
|
}
|
|
1144
1227
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1145
|
-
const committedDb = await this
|
|
1228
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1146
1229
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1147
1230
|
noteHash
|
|
1148
1231
|
]);
|
|
1149
1232
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1150
1233
|
}
|
|
1151
1234
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1152
|
-
const db = await this
|
|
1235
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1153
1236
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1154
1237
|
l1ToL2Message
|
|
1155
1238
|
]);
|
|
@@ -1181,23 +1264,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1181
1264
|
*/ async getL2ToL1Messages(epoch) {
|
|
1182
1265
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1183
1266
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1184
|
-
const blocksInCheckpoints =
|
|
1185
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1186
|
-
let checkpointIndex = -1;
|
|
1187
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1188
|
-
const block = checkpointedBlock.block;
|
|
1189
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1190
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1191
|
-
checkpointIndex++;
|
|
1192
|
-
blocksInCheckpoints.push([]);
|
|
1193
|
-
previousSlotNumber = slotNumber;
|
|
1194
|
-
}
|
|
1195
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1196
|
-
}
|
|
1267
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1197
1268
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1198
1269
|
}
|
|
1199
1270
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1200
|
-
const db = await this
|
|
1271
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1201
1272
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1202
1273
|
nullifier.toBuffer()
|
|
1203
1274
|
]);
|
|
@@ -1211,36 +1282,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1211
1282
|
}
|
|
1212
1283
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1213
1284
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1217
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1218
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1219
|
-
* @returns The low nullifier membership witness (if found).
|
|
1220
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1221
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1222
|
-
* we are trying to prove non-inclusion for.
|
|
1223
|
-
*
|
|
1224
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1225
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1226
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1227
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1228
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1229
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1285
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1286
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1230
1287
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1231
1288
|
if (!findResult) {
|
|
1232
1289
|
return undefined;
|
|
1233
1290
|
}
|
|
1234
1291
|
const { index, alreadyPresent } = findResult;
|
|
1235
1292
|
if (alreadyPresent) {
|
|
1236
|
-
|
|
1293
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1237
1294
|
}
|
|
1238
1295
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1239
1296
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1240
1297
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1241
1298
|
}
|
|
1242
1299
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1243
|
-
const committedDb = await this
|
|
1300
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1244
1301
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1245
1302
|
if (!lowLeafResult) {
|
|
1246
1303
|
return undefined;
|
|
@@ -1251,7 +1308,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1251
1308
|
}
|
|
1252
1309
|
}
|
|
1253
1310
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1254
|
-
const committedDb = await this
|
|
1311
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1255
1312
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1256
1313
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1257
1314
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1348,7 +1405,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1348
1405
|
}
|
|
1349
1406
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1350
1407
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1351
|
-
const verifier = isSimulation ? undefined : this.
|
|
1408
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1352
1409
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1353
1410
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1354
1411
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
@@ -1390,7 +1447,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1390
1447
|
archiver.updateConfig(config);
|
|
1391
1448
|
}
|
|
1392
1449
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1393
|
-
|
|
1450
|
+
await Promise.all([
|
|
1451
|
+
tryStop(this.peerProofVerifier),
|
|
1452
|
+
tryStop(this.rpcProofVerifier)
|
|
1453
|
+
]);
|
|
1454
|
+
if (newConfig.realProofs) {
|
|
1455
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1456
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1457
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1458
|
+
} else {
|
|
1459
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1460
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1461
|
+
}
|
|
1394
1462
|
}
|
|
1395
1463
|
this.config = newConfig;
|
|
1396
1464
|
}
|
|
@@ -1450,7 +1518,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1450
1518
|
});
|
|
1451
1519
|
return Promise.resolve();
|
|
1452
1520
|
}
|
|
1453
|
-
async rollbackTo(targetBlock, force) {
|
|
1521
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1454
1522
|
const archiver = this.blockSource;
|
|
1455
1523
|
if (!('rollbackTo' in archiver)) {
|
|
1456
1524
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1478,9 +1546,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1478
1546
|
this.log.error(`Error during rollback`, err);
|
|
1479
1547
|
throw err;
|
|
1480
1548
|
} finally{
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1549
|
+
if (resumeSync) {
|
|
1550
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1551
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1552
|
+
archiver.resume();
|
|
1553
|
+
} else {
|
|
1554
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1555
|
+
}
|
|
1484
1556
|
}
|
|
1485
1557
|
}
|
|
1486
1558
|
async pauseSync() {
|
|
@@ -1494,18 +1566,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1494
1566
|
this.blockSource.resume();
|
|
1495
1567
|
return Promise.resolve();
|
|
1496
1568
|
}
|
|
1497
|
-
getSlashPayloads() {
|
|
1498
|
-
if (!this.slasherClient) {
|
|
1499
|
-
throw new Error(`Slasher client not enabled`);
|
|
1500
|
-
}
|
|
1501
|
-
return this.slasherClient.getSlashPayloads();
|
|
1502
|
-
}
|
|
1503
1569
|
getSlashOffenses(round) {
|
|
1504
1570
|
if (!this.slasherClient) {
|
|
1505
1571
|
throw new Error(`Slasher client not enabled`);
|
|
1506
1572
|
}
|
|
1507
1573
|
if (round === 'all') {
|
|
1508
|
-
return this.slasherClient.
|
|
1574
|
+
return this.slasherClient.getOffenses();
|
|
1509
1575
|
} else {
|
|
1510
1576
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1511
1577
|
}
|
|
@@ -1577,6 +1643,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1577
1643
|
this.keyStoreManager = newManager;
|
|
1578
1644
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1579
1645
|
}
|
|
1646
|
+
async mineBlock() {
|
|
1647
|
+
if (!this.sequencer) {
|
|
1648
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1649
|
+
}
|
|
1650
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1651
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1652
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1653
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1654
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1655
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1656
|
+
this.sequencer.updateConfig({
|
|
1657
|
+
minTxsPerBlock: 0
|
|
1658
|
+
});
|
|
1659
|
+
try {
|
|
1660
|
+
// Trigger the sequencer to produce a block immediately
|
|
1661
|
+
void this.sequencer.trigger();
|
|
1662
|
+
// Wait for the new L2 block to appear
|
|
1663
|
+
await retryUntil(async ()=>{
|
|
1664
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1665
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1666
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1667
|
+
} finally{
|
|
1668
|
+
this.sequencer.updateConfig({
|
|
1669
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1580
1673
|
#getInitialHeaderHash() {
|
|
1581
1674
|
if (!this.initialHeaderHashPromise) {
|
|
1582
1675
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1587,7 +1680,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1587
1680
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1588
1681
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1589
1682
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1590
|
-
*/ async
|
|
1683
|
+
*/ async getWorldState(block) {
|
|
1591
1684
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1592
1685
|
try {
|
|
1593
1686
|
// Attempt to sync the world state if necessary
|
|
@@ -1599,29 +1692,57 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1599
1692
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1600
1693
|
return this.worldStateSynchronizer.getCommitted();
|
|
1601
1694
|
}
|
|
1695
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1696
|
+
let blockNumber;
|
|
1602
1697
|
if (BlockHash.isBlockHash(block)) {
|
|
1603
1698
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1604
1699
|
if (block.equals(initialBlockHash)) {
|
|
1605
|
-
// Block
|
|
1606
|
-
|
|
1700
|
+
// Block 0 is a first-class historical block: its state lives in the trees' persisted
|
|
1701
|
+
// block-0 payload. Resolving the genesis hash to block number 0 lets the snapshot path
|
|
1702
|
+
// pin reads to genesis state even after the node has advanced past it.
|
|
1703
|
+
blockNumber = BlockNumber.ZERO;
|
|
1704
|
+
} else {
|
|
1705
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1706
|
+
if (!header) {
|
|
1707
|
+
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.`);
|
|
1708
|
+
}
|
|
1709
|
+
blockNumber = header.getBlockNumber();
|
|
1710
|
+
}
|
|
1711
|
+
} else {
|
|
1712
|
+
blockNumber = block;
|
|
1713
|
+
}
|
|
1714
|
+
// Check it's within world state sync range
|
|
1715
|
+
if (blockNumber > blockSyncedTo) {
|
|
1716
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1717
|
+
}
|
|
1718
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1719
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1720
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1721
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1722
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1723
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1724
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1725
|
+
throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${initialBlockHash.toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return snapshot;
|
|
1729
|
+
}
|
|
1730
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1731
|
+
if (block === 'latest') {
|
|
1732
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1733
|
+
}
|
|
1734
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1735
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1736
|
+
if (block.equals(initialBlockHash)) {
|
|
1737
|
+
return BlockNumber.ZERO;
|
|
1607
1738
|
}
|
|
1608
1739
|
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1609
1740
|
if (!header) {
|
|
1610
|
-
throw new Error(`Block hash ${block.toString()} not found
|
|
1611
|
-
}
|
|
1612
|
-
const blockNumber = header.getBlockNumber();
|
|
1613
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1614
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1615
|
-
}
|
|
1616
|
-
// Block number provided
|
|
1617
|
-
{
|
|
1618
|
-
const blockNumber = block;
|
|
1619
|
-
if (blockNumber > blockSyncedTo) {
|
|
1620
|
-
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1741
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1621
1742
|
}
|
|
1622
|
-
|
|
1623
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1743
|
+
return header.getBlockNumber();
|
|
1624
1744
|
}
|
|
1745
|
+
return block;
|
|
1625
1746
|
}
|
|
1626
1747
|
/**
|
|
1627
1748
|
* Ensure we fully sync the world state
|