@aztec/aztec-node 0.0.1-commit.8afd444 → 0.0.1-commit.8cb2d04d8
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 +48 -36
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +472 -199
- 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 +62 -36
- 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 +562 -225
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +65 -32
- package/src/sentinel/store.ts +12 -12
|
@@ -372,27 +372,32 @@ 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';
|
|
386
388
|
import { createLogger } from '@aztec/foundation/log';
|
|
389
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
387
390
|
import { count } from '@aztec/foundation/string';
|
|
388
391
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
389
392
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
390
393
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
391
394
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
392
|
-
import {
|
|
393
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
395
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
396
|
+
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
397
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
395
|
-
import {
|
|
398
|
+
import { createProverNode } from '@aztec/prover-node';
|
|
399
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
400
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
396
401
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
397
402
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
398
403
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
@@ -402,15 +407,15 @@ import { GasFees } from '@aztec/stdlib/gas';
|
|
|
402
407
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
403
408
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
404
409
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
410
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
405
411
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
406
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
407
412
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
408
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
409
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
410
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
411
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
412
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
413
|
-
import { createPublicClient
|
|
418
|
+
import { createPublicClient } from 'viem';
|
|
414
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
415
420
|
import { createKeyStoreForValidator } from './config.js';
|
|
416
421
|
import { NodeMetrics } from './node_metrics.js';
|
|
@@ -428,18 +433,24 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
428
433
|
l1ToL2MessageSource;
|
|
429
434
|
worldStateSynchronizer;
|
|
430
435
|
sequencer;
|
|
436
|
+
proverNode;
|
|
431
437
|
slasherClient;
|
|
432
438
|
validatorsSentinel;
|
|
433
439
|
epochPruneWatcher;
|
|
434
440
|
l1ChainId;
|
|
435
441
|
version;
|
|
436
442
|
globalVariableBuilder;
|
|
443
|
+
feeProvider;
|
|
437
444
|
epochCache;
|
|
438
445
|
packageVersion;
|
|
439
|
-
|
|
446
|
+
peerProofVerifier;
|
|
447
|
+
rpcProofVerifier;
|
|
440
448
|
telemetry;
|
|
441
449
|
log;
|
|
442
450
|
blobClient;
|
|
451
|
+
validatorClient;
|
|
452
|
+
keyStoreManager;
|
|
453
|
+
debugLogStore;
|
|
443
454
|
static{
|
|
444
455
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
445
456
|
[
|
|
@@ -454,7 +465,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
454
465
|
// Prevent two snapshot operations to happen simultaneously
|
|
455
466
|
isUploadingSnapshot;
|
|
456
467
|
tracer;
|
|
457
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
468
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
458
469
|
this.config = config;
|
|
459
470
|
this.p2pClient = p2pClient;
|
|
460
471
|
this.blockSource = blockSource;
|
|
@@ -463,24 +474,39 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
463
474
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
464
475
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
465
476
|
this.sequencer = sequencer;
|
|
477
|
+
this.proverNode = proverNode;
|
|
466
478
|
this.slasherClient = slasherClient;
|
|
467
479
|
this.validatorsSentinel = validatorsSentinel;
|
|
468
480
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
469
481
|
this.l1ChainId = l1ChainId;
|
|
470
482
|
this.version = version;
|
|
471
483
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
484
|
+
this.feeProvider = feeProvider;
|
|
472
485
|
this.epochCache = epochCache;
|
|
473
486
|
this.packageVersion = packageVersion;
|
|
474
|
-
this.
|
|
487
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
488
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
475
489
|
this.telemetry = telemetry;
|
|
476
490
|
this.log = log;
|
|
477
491
|
this.blobClient = blobClient;
|
|
492
|
+
this.validatorClient = validatorClient;
|
|
493
|
+
this.keyStoreManager = keyStoreManager;
|
|
494
|
+
this.debugLogStore = debugLogStore;
|
|
478
495
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
479
496
|
this.isUploadingSnapshot = false;
|
|
480
497
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
481
498
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
482
499
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
483
500
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
501
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
502
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
503
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
504
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
505
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
509
|
+
return this.rpcProofVerifier;
|
|
484
510
|
}
|
|
485
511
|
async getWorldStateSyncStatus() {
|
|
486
512
|
const status = await this.worldStateSynchronizer.status();
|
|
@@ -502,16 +528,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
502
528
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
503
529
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
504
530
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
505
|
-
// Build a key store from file if given or from environment otherwise
|
|
531
|
+
// Build a key store from file if given or from environment otherwise.
|
|
532
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
506
533
|
let keyStoreManager;
|
|
507
534
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
508
535
|
if (keyStoreProvided) {
|
|
509
536
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
510
537
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
538
|
} else {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
539
|
+
const rawKeyStores = [];
|
|
540
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
541
|
+
if (validatorKeyStore) {
|
|
542
|
+
rawKeyStores.push(validatorKeyStore);
|
|
543
|
+
}
|
|
544
|
+
if (config.enableProverNode) {
|
|
545
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
546
|
+
if (proverKeyStore) {
|
|
547
|
+
rawKeyStores.push(proverKeyStore);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (rawKeyStores.length > 0) {
|
|
551
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
515
552
|
}
|
|
516
553
|
}
|
|
517
554
|
await keyStoreManager?.validateSigners();
|
|
@@ -520,8 +557,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
520
557
|
if (keyStoreManager === undefined) {
|
|
521
558
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
559
|
}
|
|
523
|
-
if (!keyStoreProvided) {
|
|
524
|
-
log.warn(
|
|
560
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
561
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
525
562
|
}
|
|
526
563
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
564
|
}
|
|
@@ -531,9 +568,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
531
568
|
}
|
|
532
569
|
const publicClient = createPublicClient({
|
|
533
570
|
chain: ethereumChain.chainInfo,
|
|
534
|
-
transport:
|
|
535
|
-
|
|
536
|
-
|
|
571
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
572
|
+
timeout: config.l1HttpTimeoutMS
|
|
573
|
+
}),
|
|
537
574
|
pollingInterval: config.viemPollingIntervalMS
|
|
538
575
|
});
|
|
539
576
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -543,16 +580,17 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
543
580
|
...l1ContractsAddresses
|
|
544
581
|
};
|
|
545
582
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
583
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
547
584
|
rollupContract.getL1GenesisTime(),
|
|
548
585
|
rollupContract.getSlotDuration(),
|
|
549
|
-
rollupContract.getVersion()
|
|
586
|
+
rollupContract.getVersion(),
|
|
587
|
+
rollupContract.getManaLimit().then(Number)
|
|
550
588
|
]);
|
|
551
589
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
590
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
591
|
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
592
|
}
|
|
555
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
593
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
556
594
|
// attempt snapshot sync if possible
|
|
557
595
|
await trySnapshotSync(config, log);
|
|
558
596
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
@@ -567,88 +605,129 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
567
605
|
blockUntilSync: !config.skipArchiverInitialSync
|
|
568
606
|
});
|
|
569
607
|
// now create the merkle trees and the world state synchronizer
|
|
570
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.
|
|
571
|
-
const
|
|
608
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
609
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
610
|
+
let peerProofVerifier;
|
|
611
|
+
let rpcProofVerifier;
|
|
612
|
+
if (useRealVerifiers) {
|
|
613
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
614
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
615
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
616
|
+
} else {
|
|
617
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
618
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
619
|
+
}
|
|
620
|
+
let debugLogStore;
|
|
572
621
|
if (!config.realProofs) {
|
|
573
622
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
623
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
624
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
625
|
+
} else {
|
|
626
|
+
debugLogStore = new NullDebugLogStore();
|
|
627
|
+
}
|
|
628
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
629
|
+
if (proverOnly) {
|
|
630
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
574
631
|
}
|
|
575
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
576
632
|
// 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
|
|
633
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
634
|
+
// We'll accumulate sentinel watchers here
|
|
635
|
+
const watchers = [];
|
|
636
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
637
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
581
638
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
639
|
...config,
|
|
583
640
|
l1GenesisTime,
|
|
584
|
-
slotDuration: Number(slotDuration)
|
|
641
|
+
slotDuration: Number(slotDuration),
|
|
642
|
+
rollupManaLimit,
|
|
643
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
585
644
|
}, 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
|
-
|
|
645
|
+
let validatorClient;
|
|
646
|
+
if (!proverOnly) {
|
|
647
|
+
// Create validator client if required
|
|
648
|
+
validatorClient = await createValidatorClient(config, {
|
|
649
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
650
|
+
worldState: worldStateSynchronizer,
|
|
651
|
+
p2pClient,
|
|
652
|
+
telemetry,
|
|
653
|
+
dateProvider,
|
|
654
|
+
epochCache,
|
|
655
|
+
blockSource: archiver,
|
|
656
|
+
l1ToL2MessageSource: archiver,
|
|
657
|
+
keyStoreManager,
|
|
658
|
+
blobClient,
|
|
659
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
660
|
+
});
|
|
661
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
662
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
663
|
+
// like attestations or auths will fail.
|
|
664
|
+
if (validatorClient) {
|
|
665
|
+
watchers.push(validatorClient);
|
|
666
|
+
const vc = validatorClient;
|
|
667
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
668
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
669
|
+
if (!options.dontStartSequencer) {
|
|
670
|
+
await validatorClient.registerHandlers();
|
|
671
|
+
}
|
|
608
672
|
}
|
|
609
673
|
}
|
|
610
|
-
// If there's no validator client
|
|
611
|
-
//
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
674
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
675
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
676
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
677
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
678
|
+
if (!validatorClient) {
|
|
679
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
680
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
681
|
+
createProposalHandler(config, {
|
|
615
682
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
683
|
worldState: worldStateSynchronizer,
|
|
617
684
|
epochCache,
|
|
618
685
|
blockSource: archiver,
|
|
619
686
|
l1ToL2MessageSource: archiver,
|
|
620
687
|
p2pClient,
|
|
688
|
+
blobClient,
|
|
621
689
|
dateProvider,
|
|
622
690
|
telemetry
|
|
623
|
-
}).
|
|
691
|
+
}).register(p2pClient, reexecute, archiver);
|
|
624
692
|
}
|
|
625
693
|
// Start world state and wait for it to sync to the archiver.
|
|
626
694
|
await worldStateSynchronizer.start();
|
|
627
695
|
// Start p2p. Note that it depends on world state to be running.
|
|
628
696
|
await p2pClient.start();
|
|
629
|
-
|
|
630
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
-
watchers.push(validatorsSentinel);
|
|
632
|
-
}
|
|
697
|
+
let validatorsSentinel;
|
|
633
698
|
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
699
|
let attestationsBlockWatcher;
|
|
640
|
-
if (
|
|
641
|
-
|
|
642
|
-
|
|
700
|
+
if (!proverOnly) {
|
|
701
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
702
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
703
|
+
watchers.push(validatorsSentinel);
|
|
704
|
+
}
|
|
705
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
706
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
707
|
+
watchers.push(epochPruneWatcher);
|
|
708
|
+
}
|
|
709
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
710
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
711
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
712
|
+
watchers.push(attestationsBlockWatcher);
|
|
713
|
+
}
|
|
643
714
|
}
|
|
644
715
|
// Start p2p-related services once the archiver has completed sync
|
|
645
716
|
void archiver.waitForInitialSync().then(async ()=>{
|
|
646
|
-
await p2pClient.start();
|
|
647
717
|
await validatorsSentinel?.start();
|
|
648
718
|
await epochPruneWatcher?.start();
|
|
649
719
|
await attestationsBlockWatcher?.start();
|
|
650
720
|
log.info(`All p2p services started`);
|
|
651
721
|
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
722
|
+
const globalVariableBuilderConfig = {
|
|
723
|
+
l1Contracts: config.l1Contracts,
|
|
724
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
725
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
726
|
+
l1GenesisTime,
|
|
727
|
+
slotDuration: Number(slotDuration)
|
|
728
|
+
};
|
|
729
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
730
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
652
731
|
// Validator enabled, create/start relevant service
|
|
653
732
|
let sequencer;
|
|
654
733
|
let slasherClient;
|
|
@@ -658,31 +737,51 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
658
737
|
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
738
|
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
739
|
await slasherClient.start();
|
|
661
|
-
const l1TxUtils = config.
|
|
740
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
662
741
|
...config,
|
|
663
742
|
scope: 'sequencer'
|
|
664
743
|
}, {
|
|
665
744
|
telemetry,
|
|
666
745
|
logger: log.createChild('l1-tx-utils'),
|
|
667
|
-
dateProvider
|
|
668
|
-
|
|
746
|
+
dateProvider,
|
|
747
|
+
kzg: Blob.getViemKzgInstance()
|
|
748
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
749
|
...config,
|
|
670
750
|
scope: 'sequencer'
|
|
671
751
|
}, {
|
|
672
752
|
telemetry,
|
|
673
753
|
logger: log.createChild('l1-tx-utils'),
|
|
674
|
-
dateProvider
|
|
754
|
+
dateProvider,
|
|
755
|
+
kzg: Blob.getViemKzgInstance()
|
|
675
756
|
});
|
|
757
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
758
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
759
|
+
let funderL1TxUtils;
|
|
760
|
+
if (fundingSigner) {
|
|
761
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
762
|
+
fundingSigner
|
|
763
|
+
], {
|
|
764
|
+
...config,
|
|
765
|
+
scope: 'sequencer'
|
|
766
|
+
}, {
|
|
767
|
+
telemetry,
|
|
768
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
769
|
+
dateProvider
|
|
770
|
+
});
|
|
771
|
+
funderL1TxUtils = funder;
|
|
772
|
+
}
|
|
676
773
|
// Create and start the sequencer client
|
|
677
774
|
const checkpointsBuilder = new CheckpointsBuilder({
|
|
678
775
|
...config,
|
|
679
776
|
l1GenesisTime,
|
|
680
|
-
slotDuration: Number(slotDuration)
|
|
681
|
-
|
|
777
|
+
slotDuration: Number(slotDuration),
|
|
778
|
+
rollupManaLimit
|
|
779
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
682
780
|
sequencer = await SequencerClient.new(config, {
|
|
683
781
|
...deps,
|
|
684
782
|
epochCache,
|
|
685
783
|
l1TxUtils,
|
|
784
|
+
funderL1TxUtils,
|
|
686
785
|
validatorClient,
|
|
687
786
|
p2pClient,
|
|
688
787
|
worldStateSynchronizer,
|
|
@@ -693,7 +792,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
693
792
|
telemetry,
|
|
694
793
|
dateProvider,
|
|
695
794
|
blobClient,
|
|
696
|
-
nodeKeyStore: keyStoreManager
|
|
795
|
+
nodeKeyStore: keyStoreManager,
|
|
796
|
+
globalVariableBuilder
|
|
697
797
|
});
|
|
698
798
|
}
|
|
699
799
|
if (!options.dontStartSequencer && sequencer) {
|
|
@@ -702,13 +802,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
702
802
|
} else if (sequencer) {
|
|
703
803
|
log.warn(`Sequencer created but not started`);
|
|
704
804
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
805
|
+
// Create prover node subsystem if enabled
|
|
806
|
+
let proverNode;
|
|
807
|
+
if (config.enableProverNode) {
|
|
808
|
+
proverNode = await createProverNode(config, {
|
|
809
|
+
...deps.proverNodeDeps,
|
|
810
|
+
telemetry,
|
|
811
|
+
dateProvider,
|
|
812
|
+
archiver,
|
|
813
|
+
worldStateSynchronizer,
|
|
814
|
+
p2pClient,
|
|
815
|
+
epochCache,
|
|
816
|
+
blobClient,
|
|
817
|
+
keyStoreManager
|
|
818
|
+
});
|
|
819
|
+
if (!options.dontStartProverNode) {
|
|
820
|
+
await proverNode.start();
|
|
821
|
+
log.info(`Prover node subsystem started`);
|
|
822
|
+
} else {
|
|
823
|
+
log.info(`Prover node subsystem created but not started`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
827
|
+
return node;
|
|
712
828
|
}
|
|
713
829
|
/**
|
|
714
830
|
* Returns the sequencer client instance.
|
|
@@ -716,6 +832,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
716
832
|
*/ getSequencer() {
|
|
717
833
|
return this.sequencer;
|
|
718
834
|
}
|
|
835
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
836
|
+
return this.proverNode;
|
|
837
|
+
}
|
|
719
838
|
getBlockSource() {
|
|
720
839
|
return this.blockSource;
|
|
721
840
|
}
|
|
@@ -735,7 +854,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
735
854
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
736
855
|
}
|
|
737
856
|
async getAllowedPublicSetup() {
|
|
738
|
-
return
|
|
857
|
+
return [
|
|
858
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
859
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
860
|
+
];
|
|
739
861
|
}
|
|
740
862
|
/**
|
|
741
863
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -758,7 +880,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
758
880
|
rollupVersion,
|
|
759
881
|
enr,
|
|
760
882
|
l1ContractAddresses: contractAddresses,
|
|
761
|
-
protocolContractAddresses: protocolContractAddresses
|
|
883
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
884
|
+
realProofs: !!this.config.realProofs
|
|
762
885
|
};
|
|
763
886
|
return nodeInfo;
|
|
764
887
|
}
|
|
@@ -812,11 +935,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
812
935
|
async getCheckpointedBlocks(from, limit) {
|
|
813
936
|
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
814
937
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
return await this.
|
|
938
|
+
getCheckpointsDataForEpoch(epochNumber) {
|
|
939
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
940
|
+
}
|
|
941
|
+
async getCurrentMinFees() {
|
|
942
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
943
|
+
}
|
|
944
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
945
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
820
946
|
}
|
|
821
947
|
async getMaxPriorityFees() {
|
|
822
948
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -839,6 +965,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
839
965
|
async getCheckpointedBlockNumber() {
|
|
840
966
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
967
|
}
|
|
968
|
+
getCheckpointNumber() {
|
|
969
|
+
return this.blockSource.getCheckpointNumber();
|
|
970
|
+
}
|
|
842
971
|
/**
|
|
843
972
|
* Method to fetch the version of the package.
|
|
844
973
|
* @returns The node package version
|
|
@@ -864,28 +993,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
864
993
|
return this.contractDataSource.getContract(address);
|
|
865
994
|
}
|
|
866
995
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
996
|
+
let upToBlockNumber;
|
|
867
997
|
if (referenceBlock) {
|
|
868
998
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
|
-
if (
|
|
999
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1000
|
+
upToBlockNumber = BlockNumber(0);
|
|
1001
|
+
} else {
|
|
870
1002
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
871
1003
|
if (!header) {
|
|
872
1004
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
873
1005
|
}
|
|
1006
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
874
1007
|
}
|
|
875
1008
|
}
|
|
876
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1009
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
877
1010
|
}
|
|
878
1011
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1012
|
+
let upToBlockNumber;
|
|
879
1013
|
if (referenceBlock) {
|
|
880
1014
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
881
|
-
if (
|
|
1015
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1016
|
+
upToBlockNumber = BlockNumber(0);
|
|
1017
|
+
} else {
|
|
882
1018
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
883
1019
|
if (!header) {
|
|
884
1020
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
885
1021
|
}
|
|
1022
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
886
1023
|
}
|
|
887
1024
|
}
|
|
888
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1025
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
889
1026
|
}
|
|
890
1027
|
/**
|
|
891
1028
|
* Gets public logs based on the provided filter.
|
|
@@ -920,8 +1057,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
920
1057
|
throw new Error(`Invalid tx: ${reason}`);
|
|
921
1058
|
}
|
|
922
1059
|
await this.p2pClient.sendTx(tx);
|
|
923
|
-
|
|
924
|
-
this.
|
|
1060
|
+
const duration = timer.ms();
|
|
1061
|
+
this.metrics.receivedTx(duration, true);
|
|
1062
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
925
1063
|
txHash
|
|
926
1064
|
});
|
|
927
1065
|
}
|
|
@@ -932,18 +1070,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
932
1070
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
933
1071
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
934
1072
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1073
|
+
let receipt;
|
|
935
1074
|
if (settledTxReceipt) {
|
|
936
|
-
|
|
937
|
-
return settledTxReceipt;
|
|
1075
|
+
receipt = settledTxReceipt;
|
|
938
1076
|
} else if (isKnownToPool) {
|
|
939
1077
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
940
1078
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
941
1079
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
942
|
-
|
|
1080
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
943
1081
|
} else {
|
|
944
1082
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
945
|
-
|
|
1083
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
946
1084
|
}
|
|
1085
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1086
|
+
return receipt;
|
|
947
1087
|
}
|
|
948
1088
|
getTxEffect(txHash) {
|
|
949
1089
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -955,8 +1095,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
955
1095
|
await tryStop(this.validatorsSentinel);
|
|
956
1096
|
await tryStop(this.epochPruneWatcher);
|
|
957
1097
|
await tryStop(this.slasherClient);
|
|
958
|
-
await
|
|
1098
|
+
await Promise.all([
|
|
1099
|
+
tryStop(this.peerProofVerifier),
|
|
1100
|
+
tryStop(this.rpcProofVerifier)
|
|
1101
|
+
]);
|
|
959
1102
|
await tryStop(this.sequencer);
|
|
1103
|
+
await tryStop(this.proverNode);
|
|
960
1104
|
await tryStop(this.p2pClient);
|
|
961
1105
|
await tryStop(this.worldStateSynchronizer);
|
|
962
1106
|
await tryStop(this.blockSource);
|
|
@@ -996,70 +1140,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
996
1140
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
997
1141
|
}
|
|
998
1142
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
999
|
-
const committedDb = await this
|
|
1143
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1000
1144
|
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
|
-
|
|
1145
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1146
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1147
|
+
// Now we find the block numbers for the defined indices
|
|
1148
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1149
|
+
// Build a map from leaf index to block number
|
|
1150
|
+
const indexToBlockNumber = new Map();
|
|
1151
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1152
|
+
const blockNumber = blockNumbers[i];
|
|
1153
|
+
if (blockNumber === undefined) {
|
|
1154
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1009
1155
|
}
|
|
1156
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1010
1157
|
}
|
|
1011
1158
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1012
1159
|
const uniqueBlockNumbers = [
|
|
1013
|
-
...new Set(
|
|
1160
|
+
...new Set(indexToBlockNumber.values())
|
|
1014
1161
|
];
|
|
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).
|
|
1162
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1017
1163
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1018
1164
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1019
1165
|
}));
|
|
1020
|
-
//
|
|
1166
|
+
// Build a map from block number to block hash
|
|
1167
|
+
const blockNumberToHash = new Map();
|
|
1021
1168
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1022
|
-
|
|
1169
|
+
const blockHash = blockHashes[i];
|
|
1170
|
+
if (blockHash === undefined) {
|
|
1023
1171
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1024
1172
|
}
|
|
1173
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1025
1174
|
}
|
|
1026
1175
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1027
|
-
return maybeIndices.map((index
|
|
1176
|
+
return maybeIndices.map((index)=>{
|
|
1028
1177
|
if (index === undefined) {
|
|
1029
1178
|
return undefined;
|
|
1030
1179
|
}
|
|
1031
|
-
const blockNumber =
|
|
1180
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1032
1181
|
if (blockNumber === undefined) {
|
|
1033
|
-
|
|
1182
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1034
1183
|
}
|
|
1035
|
-
const
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
return undefined;
|
|
1184
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1185
|
+
if (l2BlockHash === undefined) {
|
|
1186
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1039
1187
|
}
|
|
1040
1188
|
return {
|
|
1041
|
-
l2BlockNumber:
|
|
1042
|
-
l2BlockHash
|
|
1189
|
+
l2BlockNumber: blockNumber,
|
|
1190
|
+
l2BlockHash,
|
|
1043
1191
|
data: index
|
|
1044
1192
|
};
|
|
1045
1193
|
});
|
|
1046
1194
|
}
|
|
1047
1195
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1048
|
-
|
|
1196
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1197
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1198
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1199
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1200
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1201
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1202
|
+
return undefined;
|
|
1203
|
+
}
|
|
1204
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1049
1205
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1050
1206
|
blockHash
|
|
1051
1207
|
]);
|
|
1052
1208
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1053
1209
|
}
|
|
1054
1210
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1055
|
-
const committedDb = await this
|
|
1211
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1056
1212
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1057
1213
|
noteHash
|
|
1058
1214
|
]);
|
|
1059
1215
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1060
1216
|
}
|
|
1061
1217
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1062
|
-
const db = await this
|
|
1218
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1063
1219
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1064
1220
|
l1ToL2Message
|
|
1065
1221
|
]);
|
|
@@ -1072,9 +1228,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1072
1228
|
witness.path
|
|
1073
1229
|
];
|
|
1074
1230
|
}
|
|
1075
|
-
async
|
|
1231
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1076
1232
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1077
|
-
return messageIndex ?
|
|
1233
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1078
1234
|
}
|
|
1079
1235
|
/**
|
|
1080
1236
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1091,23 +1247,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1091
1247
|
*/ async getL2ToL1Messages(epoch) {
|
|
1092
1248
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1093
1249
|
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
|
-
}
|
|
1250
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1107
1251
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1108
1252
|
}
|
|
1109
1253
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1110
|
-
const db = await this
|
|
1254
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1111
1255
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1112
1256
|
nullifier.toBuffer()
|
|
1113
1257
|
]);
|
|
@@ -1121,36 +1265,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1121
1265
|
}
|
|
1122
1266
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1123
1267
|
}
|
|
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);
|
|
1268
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1269
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1140
1270
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1141
1271
|
if (!findResult) {
|
|
1142
1272
|
return undefined;
|
|
1143
1273
|
}
|
|
1144
1274
|
const { index, alreadyPresent } = findResult;
|
|
1145
1275
|
if (alreadyPresent) {
|
|
1146
|
-
|
|
1276
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1147
1277
|
}
|
|
1148
1278
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1149
1279
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1150
1280
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1151
1281
|
}
|
|
1152
1282
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1153
|
-
const committedDb = await this
|
|
1283
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1154
1284
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1155
1285
|
if (!lowLeafResult) {
|
|
1156
1286
|
return undefined;
|
|
@@ -1161,7 +1291,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1161
1291
|
}
|
|
1162
1292
|
}
|
|
1163
1293
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1164
|
-
const committedDb = await this
|
|
1294
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1165
1295
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1166
1296
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1167
1297
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1194,6 +1324,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1194
1324
|
*/ async getBlockHeaderByArchive(archive) {
|
|
1195
1325
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1196
1326
|
}
|
|
1327
|
+
getBlockData(number) {
|
|
1328
|
+
return this.blockSource.getBlockData(number);
|
|
1329
|
+
}
|
|
1330
|
+
getBlockDataByArchive(archive) {
|
|
1331
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1332
|
+
}
|
|
1197
1333
|
/**
|
|
1198
1334
|
* Simulates the public part of a transaction with the current state.
|
|
1199
1335
|
* @param tx - The transaction to simulate.
|
|
@@ -1206,7 +1342,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1206
1342
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1207
1343
|
}
|
|
1208
1344
|
const txHash = tx.getTxHash();
|
|
1209
|
-
const
|
|
1345
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1346
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1210
1347
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1211
1348
|
const coinbase = EthAddress.ZERO;
|
|
1212
1349
|
const feeRecipient = AztecAddress.ZERO;
|
|
@@ -1217,6 +1354,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1217
1354
|
txHash,
|
|
1218
1355
|
blockNumber
|
|
1219
1356
|
});
|
|
1357
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1358
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1220
1359
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1221
1360
|
try {
|
|
1222
1361
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1231,7 +1370,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1231
1370
|
});
|
|
1232
1371
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1233
1372
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1234
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1373
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1235
1374
|
tx
|
|
1236
1375
|
]);
|
|
1237
1376
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1242,26 +1381,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1242
1381
|
throw failedTxs[0].error;
|
|
1243
1382
|
}
|
|
1244
1383
|
const [processedTx] = processedTxs;
|
|
1245
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1384
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1246
1385
|
} finally{
|
|
1247
1386
|
await merkleTreeFork.close();
|
|
1248
1387
|
}
|
|
1249
1388
|
}
|
|
1250
1389
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1251
1390
|
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
|
|
1391
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1392
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1254
1393
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1255
1394
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1256
|
-
const
|
|
1395
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1396
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1257
1397
|
timestamp: nextSlotTimestamp,
|
|
1258
1398
|
blockNumber,
|
|
1259
1399
|
l1ChainId: this.l1ChainId,
|
|
1260
1400
|
rollupVersion: this.version,
|
|
1261
|
-
setupAllowList:
|
|
1401
|
+
setupAllowList: [
|
|
1402
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1403
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1404
|
+
],
|
|
1262
1405
|
gasFees: await this.getCurrentMinFees(),
|
|
1263
1406
|
skipFeeEnforcement,
|
|
1264
|
-
txsPermitted: !this.config.disableTransactions
|
|
1407
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1408
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1409
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1410
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1265
1411
|
}, this.log.getBindings());
|
|
1266
1412
|
return await validator.validateTx(tx);
|
|
1267
1413
|
}
|
|
@@ -1284,7 +1430,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1284
1430
|
archiver.updateConfig(config);
|
|
1285
1431
|
}
|
|
1286
1432
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1287
|
-
|
|
1433
|
+
await Promise.all([
|
|
1434
|
+
tryStop(this.peerProofVerifier),
|
|
1435
|
+
tryStop(this.rpcProofVerifier)
|
|
1436
|
+
]);
|
|
1437
|
+
if (newConfig.realProofs) {
|
|
1438
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1439
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1440
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1441
|
+
} else {
|
|
1442
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1443
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1444
|
+
}
|
|
1288
1445
|
}
|
|
1289
1446
|
this.config = newConfig;
|
|
1290
1447
|
}
|
|
@@ -1344,7 +1501,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1344
1501
|
});
|
|
1345
1502
|
return Promise.resolve();
|
|
1346
1503
|
}
|
|
1347
|
-
async rollbackTo(targetBlock, force) {
|
|
1504
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1348
1505
|
const archiver = this.blockSource;
|
|
1349
1506
|
if (!('rollbackTo' in archiver)) {
|
|
1350
1507
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1372,9 +1529,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1372
1529
|
this.log.error(`Error during rollback`, err);
|
|
1373
1530
|
throw err;
|
|
1374
1531
|
} finally{
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1532
|
+
if (resumeSync) {
|
|
1533
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1534
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1535
|
+
archiver.resume();
|
|
1536
|
+
} else {
|
|
1537
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1538
|
+
}
|
|
1378
1539
|
}
|
|
1379
1540
|
}
|
|
1380
1541
|
async pauseSync() {
|
|
@@ -1388,22 +1549,110 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1388
1549
|
this.blockSource.resume();
|
|
1389
1550
|
return Promise.resolve();
|
|
1390
1551
|
}
|
|
1391
|
-
getSlashPayloads() {
|
|
1392
|
-
if (!this.slasherClient) {
|
|
1393
|
-
throw new Error(`Slasher client not enabled`);
|
|
1394
|
-
}
|
|
1395
|
-
return this.slasherClient.getSlashPayloads();
|
|
1396
|
-
}
|
|
1397
1552
|
getSlashOffenses(round) {
|
|
1398
1553
|
if (!this.slasherClient) {
|
|
1399
1554
|
throw new Error(`Slasher client not enabled`);
|
|
1400
1555
|
}
|
|
1401
1556
|
if (round === 'all') {
|
|
1402
|
-
return this.slasherClient.
|
|
1557
|
+
return this.slasherClient.getOffenses();
|
|
1403
1558
|
} else {
|
|
1404
1559
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1405
1560
|
}
|
|
1406
1561
|
}
|
|
1562
|
+
async reloadKeystore() {
|
|
1563
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1564
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1565
|
+
}
|
|
1566
|
+
if (!this.validatorClient) {
|
|
1567
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1568
|
+
}
|
|
1569
|
+
this.log.info('Reloading keystore from disk');
|
|
1570
|
+
// Re-read and validate keystore files
|
|
1571
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1572
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1573
|
+
await newManager.validateSigners();
|
|
1574
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1575
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1576
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1577
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1578
|
+
// would silently fail on every proposer slot.
|
|
1579
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1580
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1581
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1582
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1583
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1584
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1585
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1586
|
+
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 ` + `[${[
|
|
1587
|
+
...availablePublishers
|
|
1588
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
// Build adapters for old and new keystores to compute diff
|
|
1593
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1594
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1595
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1596
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1597
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1598
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1599
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1600
|
+
if (added.length > 0) {
|
|
1601
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1602
|
+
}
|
|
1603
|
+
if (removed.length > 0) {
|
|
1604
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1605
|
+
}
|
|
1606
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1607
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1608
|
+
}
|
|
1609
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1610
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1611
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1612
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1613
|
+
if (this.sequencer) {
|
|
1614
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1615
|
+
}
|
|
1616
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1617
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1618
|
+
const slashValidatorsNever = unique([
|
|
1619
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1620
|
+
...newAddresses
|
|
1621
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1622
|
+
this.slasherClient.updateConfig({
|
|
1623
|
+
slashValidatorsNever
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
this.keyStoreManager = newManager;
|
|
1627
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1628
|
+
}
|
|
1629
|
+
async mineBlock() {
|
|
1630
|
+
if (!this.sequencer) {
|
|
1631
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1632
|
+
}
|
|
1633
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1634
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1635
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1636
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1637
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1638
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1639
|
+
this.sequencer.updateConfig({
|
|
1640
|
+
minTxsPerBlock: 0
|
|
1641
|
+
});
|
|
1642
|
+
try {
|
|
1643
|
+
// Trigger the sequencer to produce a block immediately
|
|
1644
|
+
void this.sequencer.trigger();
|
|
1645
|
+
// Wait for the new L2 block to appear
|
|
1646
|
+
await retryUntil(async ()=>{
|
|
1647
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1648
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1649
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1650
|
+
} finally{
|
|
1651
|
+
this.sequencer.updateConfig({
|
|
1652
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1407
1656
|
#getInitialHeaderHash() {
|
|
1408
1657
|
if (!this.initialHeaderHashPromise) {
|
|
1409
1658
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1414,7 +1663,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1414
1663
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1415
1664
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1416
1665
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1417
|
-
*/ async
|
|
1666
|
+
*/ async getWorldState(block) {
|
|
1418
1667
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1419
1668
|
try {
|
|
1420
1669
|
// Attempt to sync the world state if necessary
|
|
@@ -1426,6 +1675,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1426
1675
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1427
1676
|
return this.worldStateSynchronizer.getCommitted();
|
|
1428
1677
|
}
|
|
1678
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1679
|
+
let blockNumber;
|
|
1429
1680
|
if (BlockHash.isBlockHash(block)) {
|
|
1430
1681
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1431
1682
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1436,19 +1687,41 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1436
1687
|
if (!header) {
|
|
1437
1688
|
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
1689
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
}
|
|
1443
|
-
//
|
|
1444
|
-
{
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1690
|
+
blockNumber = header.getBlockNumber();
|
|
1691
|
+
} else {
|
|
1692
|
+
blockNumber = block;
|
|
1693
|
+
}
|
|
1694
|
+
// Check it's within world state sync range
|
|
1695
|
+
if (blockNumber > blockSyncedTo) {
|
|
1696
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1697
|
+
}
|
|
1698
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1699
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1700
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1701
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1702
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1703
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1704
|
+
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.`);
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
return snapshot;
|
|
1708
|
+
}
|
|
1709
|
+
/** Resolves a block parameter to a block number. */ async resolveBlockNumber(block) {
|
|
1710
|
+
if (block === 'latest') {
|
|
1711
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1712
|
+
}
|
|
1713
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1714
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1715
|
+
if (block.equals(initialBlockHash)) {
|
|
1716
|
+
return BlockNumber.ZERO;
|
|
1717
|
+
}
|
|
1718
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1719
|
+
if (!header) {
|
|
1720
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1448
1721
|
}
|
|
1449
|
-
|
|
1450
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1722
|
+
return header.getBlockNumber();
|
|
1451
1723
|
}
|
|
1724
|
+
return block;
|
|
1452
1725
|
}
|
|
1453
1726
|
/**
|
|
1454
1727
|
* Ensure we fully sync the world state
|