@aztec/aztec-node 0.0.1-commit.9d2bcf6d → 0.0.1-commit.9ef841308
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/server.d.ts +36 -23
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +420 -179
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +61 -35
- 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 +26 -25
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/server.ts +486 -194
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +64 -31
- package/src/sentinel/store.ts +12 -12
|
@@ -372,14 +372,16 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
372
372
|
}
|
|
373
373
|
var _dec, _initProto;
|
|
374
374
|
import { createArchiver } from '@aztec/archiver';
|
|
375
|
-
import { BBCircuitVerifier,
|
|
375
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
376
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
376
377
|
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
378
|
+
import { Blob } from '@aztec/blob-lib';
|
|
377
379
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
378
380
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
379
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
381
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
380
382
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
381
|
-
import { BlockNumber
|
|
382
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
383
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
384
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
383
385
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
384
386
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
385
387
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -389,9 +391,11 @@ 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;
|
|
@@ -436,10 +441,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
436
441
|
globalVariableBuilder;
|
|
437
442
|
epochCache;
|
|
438
443
|
packageVersion;
|
|
439
|
-
|
|
444
|
+
peerProofVerifier;
|
|
445
|
+
rpcProofVerifier;
|
|
440
446
|
telemetry;
|
|
441
447
|
log;
|
|
442
448
|
blobClient;
|
|
449
|
+
validatorClient;
|
|
450
|
+
keyStoreManager;
|
|
451
|
+
debugLogStore;
|
|
443
452
|
static{
|
|
444
453
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
445
454
|
[
|
|
@@ -454,7 +463,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
454
463
|
// Prevent two snapshot operations to happen simultaneously
|
|
455
464
|
isUploadingSnapshot;
|
|
456
465
|
tracer;
|
|
457
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
466
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
458
467
|
this.config = config;
|
|
459
468
|
this.p2pClient = p2pClient;
|
|
460
469
|
this.blockSource = blockSource;
|
|
@@ -463,6 +472,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
463
472
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
464
473
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
465
474
|
this.sequencer = sequencer;
|
|
475
|
+
this.proverNode = proverNode;
|
|
466
476
|
this.slasherClient = slasherClient;
|
|
467
477
|
this.validatorsSentinel = validatorsSentinel;
|
|
468
478
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
@@ -471,16 +481,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
471
481
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
472
482
|
this.epochCache = epochCache;
|
|
473
483
|
this.packageVersion = packageVersion;
|
|
474
|
-
this.
|
|
484
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
485
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
475
486
|
this.telemetry = telemetry;
|
|
476
487
|
this.log = log;
|
|
477
488
|
this.blobClient = blobClient;
|
|
489
|
+
this.validatorClient = validatorClient;
|
|
490
|
+
this.keyStoreManager = keyStoreManager;
|
|
491
|
+
this.debugLogStore = debugLogStore;
|
|
478
492
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
479
493
|
this.isUploadingSnapshot = false;
|
|
480
494
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
481
495
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
482
496
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
483
497
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
498
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
499
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
500
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
501
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
502
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
506
|
+
return this.rpcProofVerifier;
|
|
484
507
|
}
|
|
485
508
|
async getWorldStateSyncStatus() {
|
|
486
509
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -502,16 +525,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
502
525
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
503
526
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
504
527
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
505
|
-
// Build a key store from file if given or from environment otherwise
|
|
528
|
+
// Build a key store from file if given or from environment otherwise.
|
|
529
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
506
530
|
let keyStoreManager;
|
|
507
531
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
508
532
|
if (keyStoreProvided) {
|
|
509
533
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
510
534
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
535
|
} else {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
536
|
+
const rawKeyStores = [];
|
|
537
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
538
|
+
if (validatorKeyStore) {
|
|
539
|
+
rawKeyStores.push(validatorKeyStore);
|
|
540
|
+
}
|
|
541
|
+
if (config.enableProverNode) {
|
|
542
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
543
|
+
if (proverKeyStore) {
|
|
544
|
+
rawKeyStores.push(proverKeyStore);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (rawKeyStores.length > 0) {
|
|
548
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
515
549
|
}
|
|
516
550
|
}
|
|
517
551
|
await keyStoreManager?.validateSigners();
|
|
@@ -520,8 +554,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
520
554
|
if (keyStoreManager === undefined) {
|
|
521
555
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
556
|
}
|
|
523
|
-
if (!keyStoreProvided) {
|
|
524
|
-
log.warn(
|
|
557
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
558
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
525
559
|
}
|
|
526
560
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
561
|
}
|
|
@@ -531,9 +565,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
531
565
|
}
|
|
532
566
|
const publicClient = createPublicClient({
|
|
533
567
|
chain: ethereumChain.chainInfo,
|
|
534
|
-
transport:
|
|
535
|
-
|
|
536
|
-
|
|
568
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
569
|
+
timeout: config.l1HttpTimeoutMS
|
|
570
|
+
}),
|
|
537
571
|
pollingInterval: config.viemPollingIntervalMS
|
|
538
572
|
});
|
|
539
573
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -543,16 +577,17 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
543
577
|
...l1ContractsAddresses
|
|
544
578
|
};
|
|
545
579
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
580
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
547
581
|
rollupContract.getL1GenesisTime(),
|
|
548
582
|
rollupContract.getSlotDuration(),
|
|
549
|
-
rollupContract.getVersion()
|
|
583
|
+
rollupContract.getVersion(),
|
|
584
|
+
rollupContract.getManaLimit().then(Number)
|
|
550
585
|
]);
|
|
551
586
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
587
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
588
|
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
589
|
}
|
|
555
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
590
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
556
591
|
// attempt snapshot sync if possible
|
|
557
592
|
await trySnapshotSync(config, log);
|
|
558
593
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
@@ -568,78 +603,108 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
568
603
|
});
|
|
569
604
|
// now create the merkle trees and the world state synchronizer
|
|
570
605
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
571
|
-
const
|
|
606
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
607
|
+
let peerProofVerifier;
|
|
608
|
+
let rpcProofVerifier;
|
|
609
|
+
if (useRealVerifiers) {
|
|
610
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
611
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
612
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
613
|
+
} else {
|
|
614
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
615
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
616
|
+
}
|
|
617
|
+
let debugLogStore;
|
|
572
618
|
if (!config.realProofs) {
|
|
573
619
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
620
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
621
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
622
|
+
} else {
|
|
623
|
+
debugLogStore = new NullDebugLogStore();
|
|
624
|
+
}
|
|
625
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
626
|
+
if (proverOnly) {
|
|
627
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
574
628
|
}
|
|
575
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
576
629
|
// 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
|
|
630
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
631
|
+
// We'll accumulate sentinel watchers here
|
|
632
|
+
const watchers = [];
|
|
633
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
634
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
581
635
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
636
|
...config,
|
|
583
637
|
l1GenesisTime,
|
|
584
|
-
slotDuration: Number(slotDuration)
|
|
638
|
+
slotDuration: Number(slotDuration),
|
|
639
|
+
rollupManaLimit,
|
|
640
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
585
641
|
}, 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
|
-
|
|
642
|
+
let validatorClient;
|
|
643
|
+
if (!proverOnly) {
|
|
644
|
+
// Create validator client if required
|
|
645
|
+
validatorClient = await createValidatorClient(config, {
|
|
646
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
647
|
+
worldState: worldStateSynchronizer,
|
|
648
|
+
p2pClient,
|
|
649
|
+
telemetry,
|
|
650
|
+
dateProvider,
|
|
651
|
+
epochCache,
|
|
652
|
+
blockSource: archiver,
|
|
653
|
+
l1ToL2MessageSource: archiver,
|
|
654
|
+
keyStoreManager,
|
|
655
|
+
blobClient,
|
|
656
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
657
|
+
});
|
|
658
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
659
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
660
|
+
// like attestations or auths will fail.
|
|
661
|
+
if (validatorClient) {
|
|
662
|
+
watchers.push(validatorClient);
|
|
663
|
+
if (!options.dontStartSequencer) {
|
|
664
|
+
await validatorClient.registerHandlers();
|
|
665
|
+
}
|
|
608
666
|
}
|
|
609
667
|
}
|
|
610
|
-
// If there's no validator client
|
|
611
|
-
//
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
668
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
669
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
670
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
671
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
672
|
+
if (!validatorClient) {
|
|
673
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
674
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
675
|
+
createProposalHandler(config, {
|
|
615
676
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
677
|
worldState: worldStateSynchronizer,
|
|
617
678
|
epochCache,
|
|
618
679
|
blockSource: archiver,
|
|
619
680
|
l1ToL2MessageSource: archiver,
|
|
620
681
|
p2pClient,
|
|
682
|
+
blobClient,
|
|
621
683
|
dateProvider,
|
|
622
684
|
telemetry
|
|
623
|
-
}).
|
|
685
|
+
}).register(p2pClient, reexecute);
|
|
624
686
|
}
|
|
625
687
|
// Start world state and wait for it to sync to the archiver.
|
|
626
688
|
await worldStateSynchronizer.start();
|
|
627
689
|
// Start p2p. Note that it depends on world state to be running.
|
|
628
690
|
await p2pClient.start();
|
|
629
|
-
|
|
630
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
-
watchers.push(validatorsSentinel);
|
|
632
|
-
}
|
|
691
|
+
let validatorsSentinel;
|
|
633
692
|
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
693
|
let attestationsBlockWatcher;
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
|
|
694
|
+
if (!proverOnly) {
|
|
695
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
696
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
697
|
+
watchers.push(validatorsSentinel);
|
|
698
|
+
}
|
|
699
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
700
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
701
|
+
watchers.push(epochPruneWatcher);
|
|
702
|
+
}
|
|
703
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
704
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
705
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
706
|
+
watchers.push(attestationsBlockWatcher);
|
|
707
|
+
}
|
|
643
708
|
}
|
|
644
709
|
// Start p2p-related services once the archiver has completed sync
|
|
645
710
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
@@ -649,6 +714,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
649
714
|
await attestationsBlockWatcher?.start();
|
|
650
715
|
log.info(`All p2p services started`);
|
|
651
716
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
717
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
718
|
+
l1Contracts: config.l1Contracts,
|
|
719
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
720
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
721
|
+
l1GenesisTime,
|
|
722
|
+
slotDuration: Number(slotDuration)
|
|
723
|
+
});
|
|
652
724
|
// Validator enabled, create/start relevant service
|
|
653
725
|
let sequencer;
|
|
654
726
|
let slasherClient;
|
|
@@ -658,31 +730,51 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
658
730
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
731
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
732
|
await slasherClient.start();
|
|
661
|
-
const l1TxUtils = config.
|
|
733
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
662
734
|
...config,
|
|
663
735
|
scope: 'sequencer'
|
|
664
736
|
}, {
|
|
665
737
|
telemetry,
|
|
666
738
|
logger: log.createChild('l1-tx-utils'),
|
|
667
|
-
dateProvider
|
|
668
|
-
|
|
739
|
+
dateProvider,
|
|
740
|
+
kzg: Blob.getViemKzgInstance()
|
|
741
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
742
|
...config,
|
|
670
743
|
scope: 'sequencer'
|
|
671
744
|
}, {
|
|
672
745
|
telemetry,
|
|
673
746
|
logger: log.createChild('l1-tx-utils'),
|
|
674
|
-
dateProvider
|
|
747
|
+
dateProvider,
|
|
748
|
+
kzg: Blob.getViemKzgInstance()
|
|
675
749
|
});
|
|
750
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
751
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
752
|
+
let funderL1TxUtils;
|
|
753
|
+
if (fundingSigner) {
|
|
754
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
755
|
+
fundingSigner
|
|
756
|
+
], {
|
|
757
|
+
...config,
|
|
758
|
+
scope: 'sequencer'
|
|
759
|
+
}, {
|
|
760
|
+
telemetry,
|
|
761
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
762
|
+
dateProvider
|
|
763
|
+
});
|
|
764
|
+
funderL1TxUtils = funder;
|
|
765
|
+
}
|
|
676
766
|
// Create and start the sequencer client
|
|
677
767
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
678
768
|
...config,
|
|
679
769
|
l1GenesisTime,
|
|
680
|
-
slotDuration: Number(slotDuration)
|
|
681
|
-
|
|
770
|
+
slotDuration: Number(slotDuration),
|
|
771
|
+
rollupManaLimit
|
|
772
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
682
773
|
sequencer = await SequencerClient.new(config, {
|
|
683
774
|
...deps,
|
|
684
775
|
epochCache,
|
|
685
776
|
l1TxUtils,
|
|
777
|
+
funderL1TxUtils,
|
|
686
778
|
validatorClient,
|
|
687
779
|
p2pClient,
|
|
688
780
|
worldStateSynchronizer,
|
|
@@ -693,7 +785,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
693
785
|
telemetry,
|
|
694
786
|
dateProvider,
|
|
695
787
|
blobClient,
|
|
696
|
-
nodeKeyStore: keyStoreManager
|
|
788
|
+
nodeKeyStore: keyStoreManager,
|
|
789
|
+
globalVariableBuilder
|
|
697
790
|
});
|
|
698
791
|
}
|
|
699
792
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -702,13 +795,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
702
795
|
} else if (sequencer) {
|
|
703
796
|
log.warn(`Sequencer created but not started`);
|
|
704
797
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
798
|
+
// Create prover node subsystem if enabled
|
|
799
|
+
let proverNode;
|
|
800
|
+
if (config.enableProverNode) {
|
|
801
|
+
proverNode = await createProverNode(config, {
|
|
802
|
+
...deps.proverNodeDeps,
|
|
803
|
+
telemetry,
|
|
804
|
+
dateProvider,
|
|
805
|
+
archiver,
|
|
806
|
+
worldStateSynchronizer,
|
|
807
|
+
p2pClient,
|
|
808
|
+
epochCache,
|
|
809
|
+
blobClient,
|
|
810
|
+
keyStoreManager
|
|
811
|
+
});
|
|
812
|
+
if (!options.dontStartProverNode) {
|
|
813
|
+
await proverNode.start();
|
|
814
|
+
log.info(`Prover node subsystem started`);
|
|
815
|
+
} else {
|
|
816
|
+
log.info(`Prover node subsystem created but not started`);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
820
|
+
return node;
|
|
712
821
|
}
|
|
713
822
|
/**
|
|
714
823
|
* Returns the sequencer client instance.
|
|
@@ -716,6 +825,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
716
825
|
*/ getSequencer() {
|
|
717
826
|
return this.sequencer;
|
|
718
827
|
}
|
|
828
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
829
|
+
return this.proverNode;
|
|
830
|
+
}
|
|
719
831
|
getBlockSource() {
|
|
720
832
|
return this.blockSource;
|
|
721
833
|
}
|
|
@@ -735,7 +847,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
735
847
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
736
848
|
}
|
|
737
849
|
async getAllowedPublicSetup() {
|
|
738
|
-
return
|
|
850
|
+
return [
|
|
851
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
852
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
853
|
+
];
|
|
739
854
|
}
|
|
740
855
|
/**
|
|
741
856
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -758,7 +873,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
758
873
|
rollupVersion,
|
|
759
874
|
enr,
|
|
760
875
|
l1ContractAddresses: contractAddresses,
|
|
761
|
-
protocolContractAddresses: protocolContractAddresses
|
|
876
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
877
|
+
realProofs: !!this.config.realProofs
|
|
762
878
|
};
|
|
763
879
|
return nodeInfo;
|
|
764
880
|
}
|
|
@@ -812,6 +928,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
812
928
|
async getCheckpointedBlocks(from, limit) {
|
|
813
929
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
814
930
|
}
|
|
931
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
932
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
933
|
+
}
|
|
815
934
|
/**
|
|
816
935
|
* Method to fetch the current min L2 fees.
|
|
817
936
|
* @returns The current min L2 fees.
|
|
@@ -839,6 +958,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
839
958
|
async getCheckpointedBlockNumber() {
|
|
840
959
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
960
|
}
|
|
961
|
+
getCheckpointNumber() {
|
|
962
|
+
return this.blockSource.getCheckpointNumber();
|
|
963
|
+
}
|
|
842
964
|
/**
|
|
843
965
|
* Method to fetch the version of the package.
|
|
844
966
|
* @returns The node package version
|
|
@@ -864,28 +986,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
864
986
|
return this.contractDataSource.getContract(address);
|
|
865
987
|
}
|
|
866
988
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
989
|
+
let upToBlockNumber;
|
|
867
990
|
if (referenceBlock) {
|
|
868
991
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
|
-
if (
|
|
992
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
993
|
+
upToBlockNumber = BlockNumber(0);
|
|
994
|
+
} else {
|
|
870
995
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
871
996
|
if (!header) {
|
|
872
997
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
873
998
|
}
|
|
999
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
874
1000
|
}
|
|
875
1001
|
}
|
|
876
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1002
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
877
1003
|
}
|
|
878
1004
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1005
|
+
let upToBlockNumber;
|
|
879
1006
|
if (referenceBlock) {
|
|
880
1007
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
881
|
-
if (
|
|
1008
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1009
|
+
upToBlockNumber = BlockNumber(0);
|
|
1010
|
+
} else {
|
|
882
1011
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
883
1012
|
if (!header) {
|
|
884
1013
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
885
1014
|
}
|
|
1015
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
886
1016
|
}
|
|
887
1017
|
}
|
|
888
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1018
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
889
1019
|
}
|
|
890
1020
|
/**
|
|
891
1021
|
* Gets public logs based on the provided filter.
|
|
@@ -920,8 +1050,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
920
1050
|
throw new Error(`Invalid tx: ${reason}`);
|
|
921
1051
|
}
|
|
922
1052
|
await this.p2pClient.sendTx(tx);
|
|
923
|
-
|
|
924
|
-
this.
|
|
1053
|
+
const duration = timer.ms();
|
|
1054
|
+
this.metrics.receivedTx(duration, true);
|
|
1055
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
925
1056
|
txHash
|
|
926
1057
|
});
|
|
927
1058
|
}
|
|
@@ -932,18 +1063,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
932
1063
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
933
1064
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
934
1065
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1066
|
+
let receipt;
|
|
935
1067
|
if (settledTxReceipt) {
|
|
936
|
-
|
|
937
|
-
return settledTxReceipt;
|
|
1068
|
+
receipt = settledTxReceipt;
|
|
938
1069
|
} else if (isKnownToPool) {
|
|
939
1070
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
940
1071
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
941
1072
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
942
|
-
|
|
1073
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
943
1074
|
} else {
|
|
944
1075
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
945
|
-
|
|
1076
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
946
1077
|
}
|
|
1078
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1079
|
+
return receipt;
|
|
947
1080
|
}
|
|
948
1081
|
getTxEffect(txHash) {
|
|
949
1082
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -955,8 +1088,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
955
1088
|
await tryStop(this.validatorsSentinel);
|
|
956
1089
|
await tryStop(this.epochPruneWatcher);
|
|
957
1090
|
await tryStop(this.slasherClient);
|
|
958
|
-
await
|
|
1091
|
+
await Promise.all([
|
|
1092
|
+
tryStop(this.peerProofVerifier),
|
|
1093
|
+
tryStop(this.rpcProofVerifier)
|
|
1094
|
+
]);
|
|
959
1095
|
await tryStop(this.sequencer);
|
|
1096
|
+
await tryStop(this.proverNode);
|
|
960
1097
|
await tryStop(this.p2pClient);
|
|
961
1098
|
await tryStop(this.worldStateSynchronizer);
|
|
962
1099
|
await tryStop(this.blockSource);
|
|
@@ -996,70 +1133,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
996
1133
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
997
1134
|
}
|
|
998
1135
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
999
|
-
const committedDb = await this
|
|
1136
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1000
1137
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1001
|
-
//
|
|
1002
|
-
const
|
|
1003
|
-
// Now we find the block numbers for the indices
|
|
1004
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1005
|
-
//
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1138
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1139
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1140
|
+
// Now we find the block numbers for the defined indices
|
|
1141
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1142
|
+
// Build a map from leaf index to block number
|
|
1143
|
+
const indexToBlockNumber = new Map();
|
|
1144
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1145
|
+
const blockNumber = blockNumbers[i];
|
|
1146
|
+
if (blockNumber === undefined) {
|
|
1147
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1009
1148
|
}
|
|
1149
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1010
1150
|
}
|
|
1011
1151
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1012
1152
|
const uniqueBlockNumbers = [
|
|
1013
|
-
...new Set(
|
|
1153
|
+
...new Set(indexToBlockNumber.values())
|
|
1014
1154
|
];
|
|
1015
|
-
// Now we obtain the block hashes from the archive tree
|
|
1016
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1155
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1017
1156
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1018
1157
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1019
1158
|
}));
|
|
1020
|
-
//
|
|
1159
|
+
// Build a map from block number to block hash
|
|
1160
|
+
const blockNumberToHash = new Map();
|
|
1021
1161
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1022
|
-
|
|
1162
|
+
const blockHash = blockHashes[i];
|
|
1163
|
+
if (blockHash === undefined) {
|
|
1023
1164
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1024
1165
|
}
|
|
1166
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1025
1167
|
}
|
|
1026
1168
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1027
|
-
return maybeIndices.map((index
|
|
1169
|
+
return maybeIndices.map((index)=>{
|
|
1028
1170
|
if (index === undefined) {
|
|
1029
1171
|
return undefined;
|
|
1030
1172
|
}
|
|
1031
|
-
const blockNumber =
|
|
1173
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1032
1174
|
if (blockNumber === undefined) {
|
|
1033
|
-
|
|
1175
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1034
1176
|
}
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
return undefined;
|
|
1177
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1178
|
+
if (blockHash === undefined) {
|
|
1179
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1039
1180
|
}
|
|
1040
1181
|
return {
|
|
1041
|
-
l2BlockNumber:
|
|
1182
|
+
l2BlockNumber: blockNumber,
|
|
1042
1183
|
l2BlockHash: new BlockHash(blockHash),
|
|
1043
1184
|
data: index
|
|
1044
1185
|
};
|
|
1045
1186
|
});
|
|
1046
1187
|
}
|
|
1047
1188
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1048
|
-
|
|
1189
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1190
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1191
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1192
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1193
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1194
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1195
|
+
return undefined;
|
|
1196
|
+
}
|
|
1197
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1049
1198
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1050
1199
|
blockHash
|
|
1051
1200
|
]);
|
|
1052
1201
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1053
1202
|
}
|
|
1054
1203
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1055
|
-
const committedDb = await this
|
|
1204
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1056
1205
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1057
1206
|
noteHash
|
|
1058
1207
|
]);
|
|
1059
1208
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1060
1209
|
}
|
|
1061
1210
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1062
|
-
const db = await this
|
|
1211
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1063
1212
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1064
1213
|
l1ToL2Message
|
|
1065
1214
|
]);
|
|
@@ -1072,9 +1221,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1072
1221
|
witness.path
|
|
1073
1222
|
];
|
|
1074
1223
|
}
|
|
1075
|
-
async
|
|
1224
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1076
1225
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1077
|
-
return messageIndex ?
|
|
1226
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1078
1227
|
}
|
|
1079
1228
|
/**
|
|
1080
1229
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1091,23 +1240,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1091
1240
|
*/ async getL2ToL1Messages(epoch) {
|
|
1092
1241
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1093
1242
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1094
|
-
const blocksInCheckpoints =
|
|
1095
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1096
|
-
let checkpointIndex = -1;
|
|
1097
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1098
|
-
const block = checkpointedBlock.block;
|
|
1099
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1100
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1101
|
-
checkpointIndex++;
|
|
1102
|
-
blocksInCheckpoints.push([]);
|
|
1103
|
-
previousSlotNumber = slotNumber;
|
|
1104
|
-
}
|
|
1105
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1106
|
-
}
|
|
1243
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1107
1244
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1108
1245
|
}
|
|
1109
1246
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1110
|
-
const db = await this
|
|
1247
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1111
1248
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1112
1249
|
nullifier.toBuffer()
|
|
1113
1250
|
]);
|
|
@@ -1121,36 +1258,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1121
1258
|
}
|
|
1122
1259
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1123
1260
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1127
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1128
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1129
|
-
* @returns The low nullifier membership witness (if found).
|
|
1130
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1131
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1132
|
-
* we are trying to prove non-inclusion for.
|
|
1133
|
-
*
|
|
1134
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1135
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1136
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1137
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1138
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1139
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1261
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1262
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1140
1263
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1141
1264
|
if (!findResult) {
|
|
1142
1265
|
return undefined;
|
|
1143
1266
|
}
|
|
1144
1267
|
const { index, alreadyPresent } = findResult;
|
|
1145
1268
|
if (alreadyPresent) {
|
|
1146
|
-
|
|
1269
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1147
1270
|
}
|
|
1148
1271
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1149
1272
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1150
1273
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1151
1274
|
}
|
|
1152
1275
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1153
|
-
const committedDb = await this
|
|
1276
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1154
1277
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1155
1278
|
if (!lowLeafResult) {
|
|
1156
1279
|
return undefined;
|
|
@@ -1161,7 +1284,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1161
1284
|
}
|
|
1162
1285
|
}
|
|
1163
1286
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1164
|
-
const committedDb = await this
|
|
1287
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1165
1288
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1166
1289
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1167
1290
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1194,6 +1317,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1194
1317
|
*/ async getBlockHeaderByArchive(archive) {
|
|
1195
1318
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1196
1319
|
}
|
|
1320
|
+
getBlockData(number) {
|
|
1321
|
+
return this.blockSource.getBlockData(number);
|
|
1322
|
+
}
|
|
1323
|
+
getBlockDataByArchive(archive) {
|
|
1324
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1325
|
+
}
|
|
1197
1326
|
/**
|
|
1198
1327
|
* Simulates the public part of a transaction with the current state.
|
|
1199
1328
|
* @param tx - The transaction to simulate.
|
|
@@ -1206,7 +1335,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1206
1335
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1207
1336
|
}
|
|
1208
1337
|
const txHash = tx.getTxHash();
|
|
1209
|
-
const
|
|
1338
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1339
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1210
1340
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1211
1341
|
const coinbase = EthAddress.ZERO;
|
|
1212
1342
|
const feeRecipient = AztecAddress.ZERO;
|
|
@@ -1217,6 +1347,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1217
1347
|
txHash,
|
|
1218
1348
|
blockNumber
|
|
1219
1349
|
});
|
|
1350
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1351
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1220
1352
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1221
1353
|
try {
|
|
1222
1354
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1231,7 +1363,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1231
1363
|
});
|
|
1232
1364
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1233
1365
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1234
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1366
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1235
1367
|
tx
|
|
1236
1368
|
]);
|
|
1237
1369
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1242,26 +1374,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1242
1374
|
throw failedTxs[0].error;
|
|
1243
1375
|
}
|
|
1244
1376
|
const [processedTx] = processedTxs;
|
|
1245
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1377
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1246
1378
|
} finally{
|
|
1247
1379
|
await merkleTreeFork.close();
|
|
1248
1380
|
}
|
|
1249
1381
|
}
|
|
1250
1382
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1251
1383
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1252
|
-
const verifier = isSimulation ? undefined : this.
|
|
1253
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1384
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1385
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1254
1386
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1255
1387
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1256
|
-
const
|
|
1388
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1389
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1257
1390
|
timestamp: nextSlotTimestamp,
|
|
1258
1391
|
blockNumber,
|
|
1259
1392
|
l1ChainId: this.l1ChainId,
|
|
1260
1393
|
rollupVersion: this.version,
|
|
1261
|
-
setupAllowList:
|
|
1394
|
+
setupAllowList: [
|
|
1395
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1396
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1397
|
+
],
|
|
1262
1398
|
gasFees: await this.getCurrentMinFees(),
|
|
1263
1399
|
skipFeeEnforcement,
|
|
1264
|
-
txsPermitted: !this.config.disableTransactions
|
|
1400
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1401
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1402
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1403
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1265
1404
|
}, this.log.getBindings());
|
|
1266
1405
|
return await validator.validateTx(tx);
|
|
1267
1406
|
}
|
|
@@ -1284,7 +1423,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1284
1423
|
archiver.updateConfig(config);
|
|
1285
1424
|
}
|
|
1286
1425
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1287
|
-
|
|
1426
|
+
await Promise.all([
|
|
1427
|
+
tryStop(this.peerProofVerifier),
|
|
1428
|
+
tryStop(this.rpcProofVerifier)
|
|
1429
|
+
]);
|
|
1430
|
+
if (newConfig.realProofs) {
|
|
1431
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1432
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1433
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1434
|
+
} else {
|
|
1435
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1436
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1437
|
+
}
|
|
1288
1438
|
}
|
|
1289
1439
|
this.config = newConfig;
|
|
1290
1440
|
}
|
|
@@ -1404,6 +1554,73 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1404
1554
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1405
1555
|
}
|
|
1406
1556
|
}
|
|
1557
|
+
async reloadKeystore() {
|
|
1558
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1559
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1560
|
+
}
|
|
1561
|
+
if (!this.validatorClient) {
|
|
1562
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1563
|
+
}
|
|
1564
|
+
this.log.info('Reloading keystore from disk');
|
|
1565
|
+
// Re-read and validate keystore files
|
|
1566
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1567
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1568
|
+
await newManager.validateSigners();
|
|
1569
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1570
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1571
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1572
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1573
|
+
// would silently fail on every proposer slot.
|
|
1574
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1575
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1576
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1577
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1578
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1579
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1580
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1581
|
+
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 ` + `[${[
|
|
1582
|
+
...availablePublishers
|
|
1583
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
// Build adapters for old and new keystores to compute diff
|
|
1588
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1589
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1590
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1591
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1592
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1593
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1594
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1595
|
+
if (added.length > 0) {
|
|
1596
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1597
|
+
}
|
|
1598
|
+
if (removed.length > 0) {
|
|
1599
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1600
|
+
}
|
|
1601
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1602
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1603
|
+
}
|
|
1604
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1605
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1606
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1607
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1608
|
+
if (this.sequencer) {
|
|
1609
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1610
|
+
}
|
|
1611
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1612
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1613
|
+
const slashValidatorsNever = unique([
|
|
1614
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1615
|
+
...newAddresses
|
|
1616
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1617
|
+
this.slasherClient.updateConfig({
|
|
1618
|
+
slashValidatorsNever
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
this.keyStoreManager = newManager;
|
|
1622
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1623
|
+
}
|
|
1407
1624
|
#getInitialHeaderHash() {
|
|
1408
1625
|
if (!this.initialHeaderHashPromise) {
|
|
1409
1626
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1414,7 +1631,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1414
1631
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1415
1632
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1416
1633
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1417
|
-
*/ async
|
|
1634
|
+
*/ async getWorldState(block) {
|
|
1418
1635
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1419
1636
|
try {
|
|
1420
1637
|
// Attempt to sync the world state if necessary
|
|
@@ -1426,6 +1643,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1426
1643
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1427
1644
|
return this.worldStateSynchronizer.getCommitted();
|
|
1428
1645
|
}
|
|
1646
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1647
|
+
let blockNumber;
|
|
1429
1648
|
if (BlockHash.isBlockHash(block)) {
|
|
1430
1649
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1431
1650
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1436,19 +1655,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1436
1655
|
if (!header) {
|
|
1437
1656
|
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.`);
|
|
1438
1657
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
}
|
|
1443
|
-
//
|
|
1444
|
-
{
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1658
|
+
blockNumber = header.getBlockNumber();
|
|
1659
|
+
} else {
|
|
1660
|
+
blockNumber = block;
|
|
1661
|
+
}
|
|
1662
|
+
// Check it's within world state sync range
|
|
1663
|
+
if (blockNumber > blockSyncedTo) {
|
|
1664
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1665
|
+
}
|
|
1666
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1667
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1668
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1669
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1670
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1671
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1672
|
+
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.`);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
return snapshot;
|
|
1676
|
+
}
|
|
1677
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1678
|
+
if (block === 'latest') {
|
|
1679
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1680
|
+
}
|
|
1681
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1682
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1683
|
+
if (block.equals(initialBlockHash)) {
|
|
1684
|
+
return BlockNumber.ZERO;
|
|
1685
|
+
}
|
|
1686
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1687
|
+
if (!header) {
|
|
1688
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1448
1689
|
}
|
|
1449
|
-
|
|
1450
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1690
|
+
return header.getBlockNumber();
|
|
1451
1691
|
}
|
|
1692
|
+
return block;
|
|
1452
1693
|
}
|
|
1453
1694
|
/**
|
|
1454
1695
|
* Ensure we fully sync the world state
|