@aztec/aztec-node 0.0.1-commit.21ecf947b → 0.0.1-commit.2448fdb
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/server.d.ts +35 -24
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +385 -169
- package/dest/sentinel/sentinel.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +18 -11
- package/package.json +27 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/server.ts +467 -182
- package/src/sentinel/sentinel.ts +18 -9
|
@@ -374,24 +374,28 @@ 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';
|
|
@@ -402,15 +406,15 @@ 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();
|
|
@@ -502,16 +520,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
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.
|
|
@@ -813,6 +897,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
813
897
|
async getCheckpointedBlocks(from, limit) {
|
|
814
898
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
815
899
|
}
|
|
900
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
901
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
902
|
+
}
|
|
816
903
|
/**
|
|
817
904
|
* Method to fetch the current min L2 fees.
|
|
818
905
|
* @returns The current min L2 fees.
|
|
@@ -840,6 +927,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
840
927
|
async getCheckpointedBlockNumber() {
|
|
841
928
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
842
929
|
}
|
|
930
|
+
getCheckpointNumber() {
|
|
931
|
+
return this.blockSource.getCheckpointNumber();
|
|
932
|
+
}
|
|
843
933
|
/**
|
|
844
934
|
* Method to fetch the version of the package.
|
|
845
935
|
* @returns The node package version
|
|
@@ -921,8 +1011,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
921
1011
|
throw new Error(`Invalid tx: ${reason}`);
|
|
922
1012
|
}
|
|
923
1013
|
await this.p2pClient.sendTx(tx);
|
|
924
|
-
|
|
925
|
-
this.
|
|
1014
|
+
const duration = timer.ms();
|
|
1015
|
+
this.metrics.receivedTx(duration, true);
|
|
1016
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
926
1017
|
txHash
|
|
927
1018
|
});
|
|
928
1019
|
}
|
|
@@ -933,18 +1024,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
933
1024
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
934
1025
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
935
1026
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1027
|
+
let receipt;
|
|
936
1028
|
if (settledTxReceipt) {
|
|
937
|
-
|
|
938
|
-
return settledTxReceipt;
|
|
1029
|
+
receipt = settledTxReceipt;
|
|
939
1030
|
} else if (isKnownToPool) {
|
|
940
1031
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
941
1032
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
942
1033
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
943
|
-
|
|
1034
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
944
1035
|
} else {
|
|
945
1036
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
946
|
-
|
|
1037
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
947
1038
|
}
|
|
1039
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1040
|
+
return receipt;
|
|
948
1041
|
}
|
|
949
1042
|
getTxEffect(txHash) {
|
|
950
1043
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -958,6 +1051,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
958
1051
|
await tryStop(this.slasherClient);
|
|
959
1052
|
await tryStop(this.proofVerifier);
|
|
960
1053
|
await tryStop(this.sequencer);
|
|
1054
|
+
await tryStop(this.proverNode);
|
|
961
1055
|
await tryStop(this.p2pClient);
|
|
962
1056
|
await tryStop(this.worldStateSynchronizer);
|
|
963
1057
|
await tryStop(this.blockSource);
|
|
@@ -997,70 +1091,88 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
997
1091
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
998
1092
|
}
|
|
999
1093
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1000
|
-
const committedDb = await this
|
|
1094
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1001
1095
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1002
|
-
//
|
|
1003
|
-
const
|
|
1004
|
-
// Now we find the block numbers for the indices
|
|
1005
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1006
|
-
//
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
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]}`);
|
|
1010
1106
|
}
|
|
1107
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1011
1108
|
}
|
|
1012
1109
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1013
1110
|
const uniqueBlockNumbers = [
|
|
1014
|
-
...new Set(
|
|
1111
|
+
...new Set(indexToBlockNumber.values())
|
|
1015
1112
|
];
|
|
1016
|
-
// Now we obtain the block hashes from the archive tree
|
|
1017
|
-
// (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).
|
|
1018
1114
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1019
1115
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1020
1116
|
}));
|
|
1021
|
-
//
|
|
1117
|
+
// Build a map from block number to block hash
|
|
1118
|
+
const blockNumberToHash = new Map();
|
|
1022
1119
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1023
|
-
|
|
1120
|
+
const blockHash = blockHashes[i];
|
|
1121
|
+
if (blockHash === undefined) {
|
|
1024
1122
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1025
1123
|
}
|
|
1124
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1026
1125
|
}
|
|
1027
1126
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1028
|
-
return maybeIndices.map((index
|
|
1127
|
+
return maybeIndices.map((index)=>{
|
|
1029
1128
|
if (index === undefined) {
|
|
1030
1129
|
return undefined;
|
|
1031
1130
|
}
|
|
1032
|
-
const blockNumber =
|
|
1131
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1033
1132
|
if (blockNumber === undefined) {
|
|
1034
|
-
|
|
1133
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1035
1134
|
}
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
return undefined;
|
|
1135
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1136
|
+
if (blockHash === undefined) {
|
|
1137
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1040
1138
|
}
|
|
1041
1139
|
return {
|
|
1042
|
-
l2BlockNumber:
|
|
1140
|
+
l2BlockNumber: blockNumber,
|
|
1043
1141
|
l2BlockHash: new BlockHash(blockHash),
|
|
1044
1142
|
data: index
|
|
1045
1143
|
};
|
|
1046
1144
|
});
|
|
1047
1145
|
}
|
|
1048
1146
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1049
|
-
|
|
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));
|
|
1050
1162
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1051
1163
|
blockHash
|
|
1052
1164
|
]);
|
|
1053
1165
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1054
1166
|
}
|
|
1055
1167
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1056
|
-
const committedDb = await this
|
|
1168
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1057
1169
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1058
1170
|
noteHash
|
|
1059
1171
|
]);
|
|
1060
1172
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1061
1173
|
}
|
|
1062
1174
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1063
|
-
const db = await this
|
|
1175
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1064
1176
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1065
1177
|
l1ToL2Message
|
|
1066
1178
|
]);
|
|
@@ -1073,9 +1185,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1073
1185
|
witness.path
|
|
1074
1186
|
];
|
|
1075
1187
|
}
|
|
1076
|
-
async
|
|
1188
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1077
1189
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1078
|
-
return messageIndex ?
|
|
1190
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1079
1191
|
}
|
|
1080
1192
|
/**
|
|
1081
1193
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1092,23 +1204,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1092
1204
|
*/ async getL2ToL1Messages(epoch) {
|
|
1093
1205
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1094
1206
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1095
|
-
const blocksInCheckpoints =
|
|
1096
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1097
|
-
let checkpointIndex = -1;
|
|
1098
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1099
|
-
const block = checkpointedBlock.block;
|
|
1100
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1101
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1102
|
-
checkpointIndex++;
|
|
1103
|
-
blocksInCheckpoints.push([]);
|
|
1104
|
-
previousSlotNumber = slotNumber;
|
|
1105
|
-
}
|
|
1106
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1107
|
-
}
|
|
1207
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1108
1208
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1109
1209
|
}
|
|
1110
1210
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1111
|
-
const db = await this
|
|
1211
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1212
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1113
1213
|
nullifier.toBuffer()
|
|
1114
1214
|
]);
|
|
@@ -1122,36 +1222,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1122
1222
|
}
|
|
1123
1223
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1124
1224
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1128
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1129
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1130
|
-
* @returns The low nullifier membership witness (if found).
|
|
1131
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1132
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1133
|
-
* we are trying to prove non-inclusion for.
|
|
1134
|
-
*
|
|
1135
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1136
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1137
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1138
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1139
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1140
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1225
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1226
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1141
1227
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1142
1228
|
if (!findResult) {
|
|
1143
1229
|
return undefined;
|
|
1144
1230
|
}
|
|
1145
1231
|
const { index, alreadyPresent } = findResult;
|
|
1146
1232
|
if (alreadyPresent) {
|
|
1147
|
-
|
|
1233
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1148
1234
|
}
|
|
1149
1235
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1150
1236
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1151
1237
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1152
1238
|
}
|
|
1153
1239
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1154
|
-
const committedDb = await this
|
|
1240
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1155
1241
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1156
1242
|
if (!lowLeafResult) {
|
|
1157
1243
|
return undefined;
|
|
@@ -1162,7 +1248,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1162
1248
|
}
|
|
1163
1249
|
}
|
|
1164
1250
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1165
|
-
const committedDb = await this
|
|
1251
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1166
1252
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1167
1253
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1168
1254
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1195,6 +1281,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1195
1281
|
*/ async getBlockHeaderByArchive(archive) {
|
|
1196
1282
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1197
1283
|
}
|
|
1284
|
+
getBlockData(number) {
|
|
1285
|
+
return this.blockSource.getBlockData(number);
|
|
1286
|
+
}
|
|
1287
|
+
getBlockDataByArchive(archive) {
|
|
1288
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1289
|
+
}
|
|
1198
1290
|
/**
|
|
1199
1291
|
* Simulates the public part of a transaction with the current state.
|
|
1200
1292
|
* @param tx - The transaction to simulate.
|
|
@@ -1207,7 +1299,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1207
1299
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1208
1300
|
}
|
|
1209
1301
|
const txHash = tx.getTxHash();
|
|
1210
|
-
const
|
|
1302
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1303
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1211
1304
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1212
1305
|
const coinbase = EthAddress.ZERO;
|
|
1213
1306
|
const feeRecipient = AztecAddress.ZERO;
|
|
@@ -1218,10 +1311,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1218
1311
|
txHash,
|
|
1219
1312
|
blockNumber
|
|
1220
1313
|
});
|
|
1221
|
-
// Ensure world
|
|
1222
|
-
|
|
1223
|
-
// (e.g. L1-to-L2 message existence checks) to fail against stale state.
|
|
1224
|
-
await this.#syncWorldState();
|
|
1314
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1315
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1225
1316
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1226
1317
|
try {
|
|
1227
1318
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1236,7 +1327,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1236
1327
|
});
|
|
1237
1328
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1238
1329
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1239
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1330
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1240
1331
|
tx
|
|
1241
1332
|
]);
|
|
1242
1333
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1247,7 +1338,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1247
1338
|
throw failedTxs[0].error;
|
|
1248
1339
|
}
|
|
1249
1340
|
const [processedTx] = processedTxs;
|
|
1250
|
-
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);
|
|
1251
1342
|
} finally{
|
|
1252
1343
|
await merkleTreeFork.close();
|
|
1253
1344
|
}
|
|
@@ -1258,15 +1349,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1258
1349
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1259
1350
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1260
1351
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1261
|
-
const
|
|
1352
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1353
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1262
1354
|
timestamp: nextSlotTimestamp,
|
|
1263
1355
|
blockNumber,
|
|
1264
1356
|
l1ChainId: this.l1ChainId,
|
|
1265
1357
|
rollupVersion: this.version,
|
|
1266
|
-
setupAllowList:
|
|
1358
|
+
setupAllowList: [
|
|
1359
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1360
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1361
|
+
],
|
|
1267
1362
|
gasFees: await this.getCurrentMinFees(),
|
|
1268
1363
|
skipFeeEnforcement,
|
|
1269
|
-
txsPermitted: !this.config.disableTransactions
|
|
1364
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1365
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1366
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1367
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1270
1368
|
}, this.log.getBindings());
|
|
1271
1369
|
return await validator.validateTx(tx);
|
|
1272
1370
|
}
|
|
@@ -1409,6 +1507,100 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1409
1507
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1410
1508
|
}
|
|
1411
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
|
+
}
|
|
1412
1604
|
#getInitialHeaderHash() {
|
|
1413
1605
|
if (!this.initialHeaderHashPromise) {
|
|
1414
1606
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1419,7 +1611,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1419
1611
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1420
1612
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1421
1613
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1422
|
-
*/ async
|
|
1614
|
+
*/ async getWorldState(block) {
|
|
1423
1615
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1424
1616
|
try {
|
|
1425
1617
|
// Attempt to sync the world state if necessary
|
|
@@ -1431,6 +1623,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1431
1623
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1432
1624
|
return this.worldStateSynchronizer.getCommitted();
|
|
1433
1625
|
}
|
|
1626
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1627
|
+
let blockNumber;
|
|
1434
1628
|
if (BlockHash.isBlockHash(block)) {
|
|
1435
1629
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1436
1630
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1441,19 +1635,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1441
1635
|
if (!header) {
|
|
1442
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.`);
|
|
1443
1637
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
}
|
|
1448
|
-
//
|
|
1449
|
-
{
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
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.`);
|
|
1453
1669
|
}
|
|
1454
|
-
|
|
1455
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1670
|
+
return header.getBlockNumber();
|
|
1456
1671
|
}
|
|
1672
|
+
return block;
|
|
1457
1673
|
}
|
|
1458
1674
|
/**
|
|
1459
1675
|
* Ensure we fully sync the world state
|