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