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