@aztec/aztec-node 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2c0ee1788
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/block_response_helpers.d.ts +21 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +88 -0
- 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 +69 -92
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +870 -400
- package/dest/sentinel/factory.d.ts +4 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +7 -4
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +69 -37
- 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/block_response_helpers.ts +131 -0
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +1049 -530
- package/src/sentinel/factory.ts +4 -8
- package/src/sentinel/sentinel.ts +82 -37
- package/src/sentinel/store.ts +12 -12
|
@@ -372,46 +372,52 @@ 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';
|
|
399
404
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
400
|
-
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
405
|
+
import { BlockHash, L2Block, inspectBlockParameter } 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';
|
|
420
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint } from './block_response_helpers.js';
|
|
415
421
|
import { createKeyStoreForValidator } from './config.js';
|
|
416
422
|
import { NodeMetrics } from './node_metrics.js';
|
|
417
423
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
@@ -428,18 +434,25 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
428
434
|
l1ToL2MessageSource;
|
|
429
435
|
worldStateSynchronizer;
|
|
430
436
|
sequencer;
|
|
437
|
+
proverNode;
|
|
431
438
|
slasherClient;
|
|
432
439
|
validatorsSentinel;
|
|
433
440
|
epochPruneWatcher;
|
|
441
|
+
attestationsBlockWatcher;
|
|
434
442
|
l1ChainId;
|
|
435
443
|
version;
|
|
436
444
|
globalVariableBuilder;
|
|
445
|
+
feeProvider;
|
|
437
446
|
epochCache;
|
|
438
447
|
packageVersion;
|
|
439
|
-
|
|
448
|
+
peerProofVerifier;
|
|
449
|
+
rpcProofVerifier;
|
|
440
450
|
telemetry;
|
|
441
451
|
log;
|
|
442
452
|
blobClient;
|
|
453
|
+
validatorClient;
|
|
454
|
+
keyStoreManager;
|
|
455
|
+
debugLogStore;
|
|
443
456
|
static{
|
|
444
457
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
445
458
|
[
|
|
@@ -454,7 +467,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
454
467
|
// Prevent two snapshot operations to happen simultaneously
|
|
455
468
|
isUploadingSnapshot;
|
|
456
469
|
tracer;
|
|
457
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion,
|
|
470
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore()){
|
|
458
471
|
this.config = config;
|
|
459
472
|
this.p2pClient = p2pClient;
|
|
460
473
|
this.blockSource = blockSource;
|
|
@@ -463,32 +476,312 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
463
476
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
464
477
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
465
478
|
this.sequencer = sequencer;
|
|
479
|
+
this.proverNode = proverNode;
|
|
466
480
|
this.slasherClient = slasherClient;
|
|
467
481
|
this.validatorsSentinel = validatorsSentinel;
|
|
468
482
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
483
|
+
this.attestationsBlockWatcher = attestationsBlockWatcher;
|
|
469
484
|
this.l1ChainId = l1ChainId;
|
|
470
485
|
this.version = version;
|
|
471
486
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
487
|
+
this.feeProvider = feeProvider;
|
|
472
488
|
this.epochCache = epochCache;
|
|
473
489
|
this.packageVersion = packageVersion;
|
|
474
|
-
this.
|
|
490
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
491
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
475
492
|
this.telemetry = telemetry;
|
|
476
493
|
this.log = log;
|
|
477
494
|
this.blobClient = blobClient;
|
|
495
|
+
this.validatorClient = validatorClient;
|
|
496
|
+
this.keyStoreManager = keyStoreManager;
|
|
497
|
+
this.debugLogStore = debugLogStore;
|
|
478
498
|
this.initialHeaderHashPromise = (_initProto(this), undefined);
|
|
479
499
|
this.isUploadingSnapshot = false;
|
|
480
500
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
481
501
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
482
502
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
483
503
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
504
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
505
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
506
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
507
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
508
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
512
|
+
return this.rpcProofVerifier;
|
|
484
513
|
}
|
|
485
514
|
async getWorldStateSyncStatus() {
|
|
486
515
|
const status = await this.worldStateSynchronizer.status();
|
|
487
516
|
return status.syncSummary;
|
|
488
517
|
}
|
|
518
|
+
async getChainTips() {
|
|
519
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
520
|
+
return {
|
|
521
|
+
proposed,
|
|
522
|
+
checkpointed,
|
|
523
|
+
proven,
|
|
524
|
+
finalized
|
|
525
|
+
};
|
|
526
|
+
}
|
|
489
527
|
getL2Tips() {
|
|
490
528
|
return this.blockSource.getL2Tips();
|
|
491
529
|
}
|
|
530
|
+
async getBlockHeader(number) {
|
|
531
|
+
const resolvedNumber = number === 'latest' ? await this.blockSource.getBlockNumber() : number;
|
|
532
|
+
if (resolvedNumber === BlockNumber.ZERO) {
|
|
533
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
534
|
+
}
|
|
535
|
+
return this.blockSource.getBlockHeader(resolvedNumber);
|
|
536
|
+
}
|
|
537
|
+
async getCheckpointedBlocks(from, limit) {
|
|
538
|
+
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
539
|
+
}
|
|
540
|
+
getCheckpointsDataForEpoch(epoch) {
|
|
541
|
+
return this.blockSource.getCheckpointsDataForEpoch(epoch);
|
|
542
|
+
}
|
|
543
|
+
getBlockNumber(tip) {
|
|
544
|
+
switch(tip){
|
|
545
|
+
case undefined:
|
|
546
|
+
case 'proposed':
|
|
547
|
+
return this.blockSource.getBlockNumber();
|
|
548
|
+
case 'checkpointed':
|
|
549
|
+
return this.blockSource.getCheckpointedL2BlockNumber();
|
|
550
|
+
case 'proven':
|
|
551
|
+
return this.blockSource.getProvenBlockNumber();
|
|
552
|
+
case 'finalized':
|
|
553
|
+
return this.blockSource.getFinalizedL2BlockNumber();
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
async getCheckpointNumber(tip) {
|
|
557
|
+
switch(tip){
|
|
558
|
+
case undefined:
|
|
559
|
+
case 'proposed':
|
|
560
|
+
case 'checkpointed':
|
|
561
|
+
return await this.blockSource.getCheckpointNumber();
|
|
562
|
+
case 'proven':
|
|
563
|
+
case 'finalized':
|
|
564
|
+
{
|
|
565
|
+
const tips = await this.blockSource.getL2Tips();
|
|
566
|
+
return tip === 'proven' ? tips.proven.checkpoint.number : tips.finalized.checkpoint.number;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
isChainTip(value) {
|
|
571
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
572
|
+
}
|
|
573
|
+
async resolveBlockParameter(param) {
|
|
574
|
+
if (BlockHash.isBlockHash(param)) {
|
|
575
|
+
return {
|
|
576
|
+
hash: param
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
if (typeof param === 'number') {
|
|
580
|
+
return {
|
|
581
|
+
number: param
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
if (param === 'latest') {
|
|
585
|
+
return {
|
|
586
|
+
number: await this.blockSource.getBlockNumber()
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
if (this.isChainTip(param)) {
|
|
590
|
+
return {
|
|
591
|
+
number: await this.getBlockNumber(param)
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if (typeof param === 'object' && param !== null) {
|
|
595
|
+
if ('number' in param) {
|
|
596
|
+
return {
|
|
597
|
+
number: param.number
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
if ('hash' in param) {
|
|
601
|
+
return {
|
|
602
|
+
hash: param.hash
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
if ('archive' in param) {
|
|
606
|
+
return {
|
|
607
|
+
archive: param.archive
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
612
|
+
}
|
|
613
|
+
async resolveCheckpointParameter(param) {
|
|
614
|
+
if (typeof param === 'number') {
|
|
615
|
+
return {
|
|
616
|
+
number: param
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
if (param === 'latest') {
|
|
620
|
+
return {
|
|
621
|
+
number: await this.blockSource.getCheckpointNumber()
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
if (this.isChainTip(param)) {
|
|
625
|
+
return {
|
|
626
|
+
number: await this.getCheckpointNumber(param)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
if (typeof param === 'object' && param !== null) {
|
|
630
|
+
if ('number' in param) {
|
|
631
|
+
return {
|
|
632
|
+
number: param.number
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
if ('slot' in param) {
|
|
636
|
+
return {
|
|
637
|
+
slot: param.slot
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
642
|
+
}
|
|
643
|
+
async getBlock(param, options = {}) {
|
|
644
|
+
const resolved = await this.resolveBlockParameter(param);
|
|
645
|
+
const wantTxs = !!options.includeTransactions;
|
|
646
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
647
|
+
if (resolved.hash !== undefined) {
|
|
648
|
+
const initial = await this.#getInitialHeaderHash();
|
|
649
|
+
if (resolved.hash.equals(initial)) {
|
|
650
|
+
return await this.buildGenesisBlockResponse(options);
|
|
651
|
+
}
|
|
652
|
+
if (wantTxs) {
|
|
653
|
+
const block = await this.blockSource.getL2BlockByHash(resolved.hash);
|
|
654
|
+
if (!block) {
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
658
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
659
|
+
}
|
|
660
|
+
const data = await this.blockSource.getBlockHeaderByHash(resolved.hash);
|
|
661
|
+
if (!data) {
|
|
662
|
+
return undefined;
|
|
663
|
+
}
|
|
664
|
+
const blockNumber = data.globalVariables.blockNumber;
|
|
665
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
666
|
+
if (ctx) {
|
|
667
|
+
return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
|
|
668
|
+
}
|
|
669
|
+
const blockData = await this.blockSource.getBlockData(blockNumber);
|
|
670
|
+
if (!blockData) {
|
|
671
|
+
return undefined;
|
|
672
|
+
}
|
|
673
|
+
return blockResponseFromBlockData(blockData, blockNumber, options);
|
|
674
|
+
}
|
|
675
|
+
if (resolved.archive !== undefined) {
|
|
676
|
+
if (wantTxs) {
|
|
677
|
+
const block = await this.blockSource.getL2BlockByArchive(resolved.archive);
|
|
678
|
+
if (!block) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
682
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
683
|
+
}
|
|
684
|
+
const data = await this.blockSource.getBlockDataByArchive(resolved.archive);
|
|
685
|
+
if (!data) {
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
const blockNumber = data.header.globalVariables.blockNumber;
|
|
689
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
690
|
+
return blockResponseFromBlockData(data, blockNumber, options, ctx);
|
|
691
|
+
}
|
|
692
|
+
const blockNumber = resolved.number;
|
|
693
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
694
|
+
return await this.buildGenesisBlockResponse(options);
|
|
695
|
+
}
|
|
696
|
+
if (wantTxs) {
|
|
697
|
+
const block = await this.blockSource.getL2Block(blockNumber);
|
|
698
|
+
if (!block) {
|
|
699
|
+
return undefined;
|
|
700
|
+
}
|
|
701
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(blockNumber) : undefined;
|
|
702
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
703
|
+
}
|
|
704
|
+
const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
|
|
705
|
+
if (!ctx) {
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
return blockResponseFromBlockData(ctx.data, blockNumber, options, ctx);
|
|
709
|
+
}
|
|
710
|
+
async getBlocks(from, limit, options = {}) {
|
|
711
|
+
const wantTxs = !!options.includeTransactions;
|
|
712
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
713
|
+
if (wantTxs) {
|
|
714
|
+
const blocks = await this.blockSource.getBlocks(from, limit);
|
|
715
|
+
return await Promise.all(blocks.map(async (block)=>{
|
|
716
|
+
const ctx = wantContext ? await this.blockSource.getBlockDataWithCheckpointContext(block.number) : undefined;
|
|
717
|
+
return blockResponseFromL2Block(block, options, ctx);
|
|
718
|
+
}));
|
|
719
|
+
}
|
|
720
|
+
const results = [];
|
|
721
|
+
for(let i = 0; i < limit; i++){
|
|
722
|
+
const blockNumber = BlockNumber(from + i);
|
|
723
|
+
const ctx = await this.blockSource.getBlockDataWithCheckpointContext(blockNumber);
|
|
724
|
+
if (!ctx) {
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
results.push(blockResponseFromBlockData(ctx.data, blockNumber, options, ctx));
|
|
728
|
+
}
|
|
729
|
+
return results;
|
|
730
|
+
}
|
|
731
|
+
async getCheckpoint(param, options = {}) {
|
|
732
|
+
const resolved = await this.resolveCheckpointParameter(param);
|
|
733
|
+
let checkpointNumber = resolved.number;
|
|
734
|
+
if (checkpointNumber === undefined && resolved.slot !== undefined) {
|
|
735
|
+
checkpointNumber = await this.blockSource.getCheckpointNumberBySlot(resolved.slot);
|
|
736
|
+
}
|
|
737
|
+
if (checkpointNumber === undefined) {
|
|
738
|
+
return undefined;
|
|
739
|
+
}
|
|
740
|
+
if (options.includeBlocks) {
|
|
741
|
+
const [checkpoint] = await this.blockSource.getCheckpoints(checkpointNumber, 1);
|
|
742
|
+
if (!checkpoint) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
return await checkpointResponseFromPublishedCheckpoint(checkpoint, options);
|
|
746
|
+
}
|
|
747
|
+
const data = await this.blockSource.getCheckpointData(checkpointNumber);
|
|
748
|
+
if (!data) {
|
|
749
|
+
return undefined;
|
|
750
|
+
}
|
|
751
|
+
return checkpointResponseFromCheckpointData(data, options);
|
|
752
|
+
}
|
|
753
|
+
async getCheckpoints(from, limit, options = {}) {
|
|
754
|
+
if (options.includeBlocks) {
|
|
755
|
+
const checkpoints = await this.blockSource.getCheckpoints(from, limit);
|
|
756
|
+
return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
|
|
757
|
+
}
|
|
758
|
+
const datas = await this.blockSource.getCheckpointDataRange(from, limit);
|
|
759
|
+
return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
|
|
760
|
+
}
|
|
761
|
+
async buildGenesisBlockResponse(options) {
|
|
762
|
+
const initial = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
763
|
+
const empty = L2Block.empty(initial);
|
|
764
|
+
const response = {
|
|
765
|
+
header: empty.header,
|
|
766
|
+
archive: empty.archive,
|
|
767
|
+
hash: await this.#getInitialHeaderHash(),
|
|
768
|
+
checkpointNumber: empty.checkpointNumber,
|
|
769
|
+
indexWithinCheckpoint: empty.indexWithinCheckpoint,
|
|
770
|
+
number: empty.number
|
|
771
|
+
};
|
|
772
|
+
if (options.includeTransactions) {
|
|
773
|
+
response.body = empty.body;
|
|
774
|
+
}
|
|
775
|
+
if (options.includeL1PublishInfo) {
|
|
776
|
+
response.l1 = {
|
|
777
|
+
published: false
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
if (options.includeAttestations) {
|
|
781
|
+
response.attestations = [];
|
|
782
|
+
}
|
|
783
|
+
return response;
|
|
784
|
+
}
|
|
492
785
|
/**
|
|
493
786
|
* initializes the Aztec Node, wait for component to sync.
|
|
494
787
|
* @param config - The configuration to be used by the aztec node.
|
|
@@ -502,16 +795,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
502
795
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
503
796
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
504
797
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
505
|
-
// Build a key store from file if given or from environment otherwise
|
|
798
|
+
// Build a key store from file if given or from environment otherwise.
|
|
799
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
506
800
|
let keyStoreManager;
|
|
507
801
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
508
802
|
if (keyStoreProvided) {
|
|
509
803
|
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
510
804
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
805
|
} else {
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
806
|
+
const rawKeyStores = [];
|
|
807
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
808
|
+
if (validatorKeyStore) {
|
|
809
|
+
rawKeyStores.push(validatorKeyStore);
|
|
810
|
+
}
|
|
811
|
+
if (config.enableProverNode) {
|
|
812
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
813
|
+
if (proverKeyStore) {
|
|
814
|
+
rawKeyStores.push(proverKeyStore);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (rawKeyStores.length > 0) {
|
|
818
|
+
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
515
819
|
}
|
|
516
820
|
}
|
|
517
821
|
await keyStoreManager?.validateSigners();
|
|
@@ -520,8 +824,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
520
824
|
if (keyStoreManager === undefined) {
|
|
521
825
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
826
|
}
|
|
523
|
-
if (!keyStoreProvided) {
|
|
524
|
-
log.warn(
|
|
827
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
828
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
525
829
|
}
|
|
526
830
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
831
|
}
|
|
@@ -531,9 +835,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
531
835
|
}
|
|
532
836
|
const publicClient = createPublicClient({
|
|
533
837
|
chain: ethereumChain.chainInfo,
|
|
534
|
-
transport:
|
|
535
|
-
|
|
536
|
-
|
|
838
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
839
|
+
timeout: config.l1HttpTimeoutMS
|
|
840
|
+
}),
|
|
537
841
|
pollingInterval: config.viemPollingIntervalMS
|
|
538
842
|
});
|
|
539
843
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -543,172 +847,277 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
543
847
|
...l1ContractsAddresses
|
|
544
848
|
};
|
|
545
849
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
850
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
547
851
|
rollupContract.getL1GenesisTime(),
|
|
548
852
|
rollupContract.getSlotDuration(),
|
|
549
|
-
rollupContract.getVersion()
|
|
853
|
+
rollupContract.getVersion(),
|
|
854
|
+
rollupContract.getManaLimit().then(Number)
|
|
550
855
|
]);
|
|
551
856
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
857
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
858
|
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
859
|
}
|
|
555
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
860
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
556
861
|
// attempt snapshot sync if possible
|
|
557
862
|
await trySnapshotSync(config, log);
|
|
558
863
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
559
864
|
dateProvider
|
|
560
865
|
});
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}, {
|
|
567
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
568
|
-
});
|
|
569
|
-
// now create the merkle trees and the world state synchronizer
|
|
570
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
571
|
-
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
572
|
-
if (!config.realProofs) {
|
|
573
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
574
|
-
}
|
|
575
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
576
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
577
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
578
|
-
// We should really not be modifying the config object
|
|
579
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
580
|
-
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
581
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
|
-
...config,
|
|
583
|
-
l1GenesisTime,
|
|
584
|
-
slotDuration: Number(slotDuration)
|
|
585
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
586
|
-
// We'll accumulate sentinel watchers here
|
|
587
|
-
const watchers = [];
|
|
588
|
-
// Create validator client if required
|
|
589
|
-
const validatorClient = await createValidatorClient(config, {
|
|
590
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
591
|
-
worldState: worldStateSynchronizer,
|
|
592
|
-
p2pClient,
|
|
593
|
-
telemetry,
|
|
594
|
-
dateProvider,
|
|
595
|
-
epochCache,
|
|
596
|
-
blockSource: archiver,
|
|
597
|
-
l1ToL2MessageSource: archiver,
|
|
598
|
-
keyStoreManager,
|
|
599
|
-
blobClient
|
|
600
|
-
});
|
|
601
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
602
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
603
|
-
// like attestations or auths will fail.
|
|
604
|
-
if (validatorClient) {
|
|
605
|
-
watchers.push(validatorClient);
|
|
606
|
-
if (!options.dontStartSequencer) {
|
|
607
|
-
await validatorClient.registerHandlers();
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
611
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
612
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
613
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
614
|
-
createBlockProposalHandler(config, {
|
|
615
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
|
-
worldState: worldStateSynchronizer,
|
|
866
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
867
|
+
const started = [];
|
|
868
|
+
try {
|
|
869
|
+
const archiver = await createArchiver(config, {
|
|
870
|
+
blobClient,
|
|
617
871
|
epochCache,
|
|
618
|
-
blockSource: archiver,
|
|
619
|
-
l1ToL2MessageSource: archiver,
|
|
620
|
-
p2pClient,
|
|
621
|
-
dateProvider,
|
|
622
|
-
telemetry
|
|
623
|
-
}).registerForReexecution(p2pClient);
|
|
624
|
-
}
|
|
625
|
-
// Start world state and wait for it to sync to the archiver.
|
|
626
|
-
await worldStateSynchronizer.start();
|
|
627
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
628
|
-
await p2pClient.start();
|
|
629
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
630
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
-
watchers.push(validatorsSentinel);
|
|
632
|
-
}
|
|
633
|
-
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
|
-
let attestationsBlockWatcher;
|
|
640
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
641
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
642
|
-
watchers.push(attestationsBlockWatcher);
|
|
643
|
-
}
|
|
644
|
-
// Start p2p-related services once the archiver has completed sync
|
|
645
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
646
|
-
await p2pClient.start();
|
|
647
|
-
await validatorsSentinel?.start();
|
|
648
|
-
await epochPruneWatcher?.start();
|
|
649
|
-
await attestationsBlockWatcher?.start();
|
|
650
|
-
log.info(`All p2p services started`);
|
|
651
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
652
|
-
// Validator enabled, create/start relevant service
|
|
653
|
-
let sequencer;
|
|
654
|
-
let slasherClient;
|
|
655
|
-
if (!config.disableValidator && validatorClient) {
|
|
656
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
657
|
-
// as they are executed when the node is selected as proposer.
|
|
658
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
|
-
await slasherClient.start();
|
|
661
|
-
const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
|
|
662
|
-
...config,
|
|
663
|
-
scope: 'sequencer'
|
|
664
|
-
}, {
|
|
665
872
|
telemetry,
|
|
666
|
-
logger: log.createChild('l1-tx-utils'),
|
|
667
873
|
dateProvider
|
|
668
|
-
}) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
|
-
...config,
|
|
670
|
-
scope: 'sequencer'
|
|
671
874
|
}, {
|
|
672
|
-
|
|
673
|
-
logger: log.createChild('l1-tx-utils'),
|
|
674
|
-
dateProvider
|
|
875
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
675
876
|
});
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
877
|
+
started.push(archiver);
|
|
878
|
+
// now create the merkle trees and the world state synchronizer
|
|
879
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
880
|
+
started.push(worldStateSynchronizer);
|
|
881
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
882
|
+
let peerProofVerifier;
|
|
883
|
+
let rpcProofVerifier;
|
|
884
|
+
if (useRealVerifiers) {
|
|
885
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
886
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
887
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
888
|
+
} else {
|
|
889
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
890
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
891
|
+
}
|
|
892
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
893
|
+
let debugLogStore;
|
|
894
|
+
if (!config.realProofs) {
|
|
895
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
896
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
897
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
898
|
+
} else {
|
|
899
|
+
debugLogStore = new NullDebugLogStore();
|
|
900
|
+
}
|
|
901
|
+
const globalVariableBuilderConfig = {
|
|
902
|
+
l1Contracts: config.l1Contracts,
|
|
903
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
904
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
679
905
|
l1GenesisTime,
|
|
680
906
|
slotDuration: Number(slotDuration)
|
|
907
|
+
};
|
|
908
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
909
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
910
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
911
|
+
if (proverOnly) {
|
|
912
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
913
|
+
}
|
|
914
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
915
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
916
|
+
started.push(p2pClient);
|
|
917
|
+
// We'll accumulate sentinel watchers here
|
|
918
|
+
const watchers = [];
|
|
919
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
920
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
921
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
922
|
+
...config,
|
|
923
|
+
l1GenesisTime,
|
|
924
|
+
slotDuration: Number(slotDuration),
|
|
925
|
+
rollupManaLimit,
|
|
926
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
681
927
|
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
928
|
+
let validatorClient;
|
|
929
|
+
if (!config.disableValidator) {
|
|
930
|
+
// Create validator client if required
|
|
931
|
+
validatorClient = await createValidatorClient(config, {
|
|
932
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
933
|
+
worldState: worldStateSynchronizer,
|
|
934
|
+
p2pClient,
|
|
935
|
+
telemetry,
|
|
936
|
+
dateProvider,
|
|
937
|
+
epochCache,
|
|
938
|
+
blockSource: archiver,
|
|
939
|
+
l1ToL2MessageSource: archiver,
|
|
940
|
+
keyStoreManager,
|
|
941
|
+
blobClient,
|
|
942
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
943
|
+
});
|
|
944
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
945
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
946
|
+
// like attestations or auths will fail.
|
|
947
|
+
if (validatorClient) {
|
|
948
|
+
watchers.push(validatorClient);
|
|
949
|
+
const vc = validatorClient;
|
|
950
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
951
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
952
|
+
if (!options.dontStartSequencer) {
|
|
953
|
+
await validatorClient.registerHandlers();
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
958
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
959
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
960
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
961
|
+
if (!validatorClient) {
|
|
962
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
963
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
964
|
+
createProposalHandler(config, {
|
|
965
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
966
|
+
worldState: worldStateSynchronizer,
|
|
967
|
+
epochCache,
|
|
968
|
+
blockSource: archiver,
|
|
969
|
+
l1ToL2MessageSource: archiver,
|
|
970
|
+
p2pClient,
|
|
971
|
+
blobClient,
|
|
972
|
+
dateProvider,
|
|
973
|
+
telemetry
|
|
974
|
+
}).register(p2pClient, reexecute, archiver);
|
|
975
|
+
}
|
|
976
|
+
// Start world state and wait for it to sync to the archiver.
|
|
977
|
+
await worldStateSynchronizer.start();
|
|
978
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
979
|
+
await p2pClient.start();
|
|
980
|
+
let validatorsSentinel;
|
|
981
|
+
let epochPruneWatcher;
|
|
982
|
+
let attestationsBlockWatcher;
|
|
983
|
+
if (!proverOnly) {
|
|
984
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
985
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
986
|
+
watchers.push(validatorsSentinel);
|
|
987
|
+
}
|
|
988
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
989
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
990
|
+
watchers.push(epochPruneWatcher);
|
|
991
|
+
}
|
|
992
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
993
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
994
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
995
|
+
watchers.push(attestationsBlockWatcher);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
// Start p2p-related services once the archiver has completed sync
|
|
999
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
1000
|
+
if (validatorsSentinel) {
|
|
1001
|
+
await validatorsSentinel.start();
|
|
1002
|
+
started.push(validatorsSentinel);
|
|
1003
|
+
}
|
|
1004
|
+
if (epochPruneWatcher) {
|
|
1005
|
+
await epochPruneWatcher.start();
|
|
1006
|
+
started.push(epochPruneWatcher);
|
|
1007
|
+
}
|
|
1008
|
+
if (attestationsBlockWatcher) {
|
|
1009
|
+
await attestationsBlockWatcher.start();
|
|
1010
|
+
started.push(attestationsBlockWatcher);
|
|
1011
|
+
}
|
|
1012
|
+
log.info(`All p2p services started`);
|
|
1013
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
1014
|
+
// Validator enabled, create/start relevant service
|
|
1015
|
+
let sequencer;
|
|
1016
|
+
let slasherClient;
|
|
1017
|
+
if (!config.disableValidator && validatorClient) {
|
|
1018
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
1019
|
+
// as they are executed when the node is selected as proposer.
|
|
1020
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
1021
|
+
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
1022
|
+
await slasherClient.start();
|
|
1023
|
+
started.push(slasherClient);
|
|
1024
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
1025
|
+
...config,
|
|
1026
|
+
scope: 'sequencer'
|
|
1027
|
+
}, {
|
|
1028
|
+
telemetry,
|
|
1029
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1030
|
+
dateProvider,
|
|
1031
|
+
kzg: Blob.getViemKzgInstance()
|
|
1032
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
1033
|
+
...config,
|
|
1034
|
+
scope: 'sequencer'
|
|
1035
|
+
}, {
|
|
1036
|
+
telemetry,
|
|
1037
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1038
|
+
dateProvider,
|
|
1039
|
+
kzg: Blob.getViemKzgInstance()
|
|
1040
|
+
});
|
|
1041
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
1042
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
1043
|
+
let funderL1TxUtils;
|
|
1044
|
+
if (fundingSigner) {
|
|
1045
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
1046
|
+
fundingSigner
|
|
1047
|
+
], {
|
|
1048
|
+
...config,
|
|
1049
|
+
scope: 'sequencer'
|
|
1050
|
+
}, {
|
|
1051
|
+
telemetry,
|
|
1052
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
1053
|
+
dateProvider
|
|
1054
|
+
});
|
|
1055
|
+
funderL1TxUtils = funder;
|
|
1056
|
+
}
|
|
1057
|
+
// Create and start the sequencer client
|
|
1058
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
1059
|
+
...config,
|
|
1060
|
+
l1GenesisTime,
|
|
1061
|
+
slotDuration: Number(slotDuration),
|
|
1062
|
+
rollupManaLimit
|
|
1063
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
1064
|
+
sequencer = await SequencerClient.new(config, {
|
|
1065
|
+
...deps,
|
|
1066
|
+
epochCache,
|
|
1067
|
+
l1TxUtils,
|
|
1068
|
+
funderL1TxUtils,
|
|
1069
|
+
validatorClient,
|
|
1070
|
+
p2pClient,
|
|
1071
|
+
worldStateSynchronizer,
|
|
1072
|
+
slasherClient,
|
|
1073
|
+
checkpointsBuilder,
|
|
1074
|
+
l2BlockSource: archiver,
|
|
1075
|
+
l1ToL2MessageSource: archiver,
|
|
1076
|
+
telemetry,
|
|
1077
|
+
dateProvider,
|
|
1078
|
+
blobClient,
|
|
1079
|
+
nodeKeyStore: keyStoreManager,
|
|
1080
|
+
globalVariableBuilder
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
1084
|
+
await sequencer.start();
|
|
1085
|
+
started.push(sequencer);
|
|
1086
|
+
log.verbose(`Sequencer started`);
|
|
1087
|
+
} else if (sequencer) {
|
|
1088
|
+
log.warn(`Sequencer created but not started`);
|
|
1089
|
+
}
|
|
1090
|
+
// Create prover node subsystem if enabled
|
|
1091
|
+
let proverNode;
|
|
1092
|
+
if (config.enableProverNode) {
|
|
1093
|
+
proverNode = await createProverNode(config, {
|
|
1094
|
+
...deps.proverNodeDeps,
|
|
1095
|
+
telemetry,
|
|
1096
|
+
dateProvider,
|
|
1097
|
+
archiver,
|
|
1098
|
+
worldStateSynchronizer,
|
|
1099
|
+
p2pClient,
|
|
1100
|
+
epochCache,
|
|
1101
|
+
blobClient,
|
|
1102
|
+
keyStoreManager
|
|
1103
|
+
});
|
|
1104
|
+
if (!options.dontStartProverNode) {
|
|
1105
|
+
await proverNode.start();
|
|
1106
|
+
started.push(proverNode);
|
|
1107
|
+
log.info(`Prover node subsystem started`);
|
|
1108
|
+
} else {
|
|
1109
|
+
log.info(`Prover node subsystem created but not started`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, attestationsBlockWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
1113
|
+
return node;
|
|
1114
|
+
} catch (err) {
|
|
1115
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1116
|
+
for (const resource of started.reverse()){
|
|
1117
|
+
await tryStop(resource);
|
|
1118
|
+
}
|
|
1119
|
+
throw err;
|
|
698
1120
|
}
|
|
699
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
700
|
-
await sequencer.start();
|
|
701
|
-
log.verbose(`Sequencer started`);
|
|
702
|
-
} else if (sequencer) {
|
|
703
|
-
log.warn(`Sequencer created but not started`);
|
|
704
|
-
}
|
|
705
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
706
|
-
...config,
|
|
707
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
708
|
-
l1GenesisTime,
|
|
709
|
-
slotDuration: Number(slotDuration)
|
|
710
|
-
});
|
|
711
|
-
return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient);
|
|
712
1121
|
}
|
|
713
1122
|
/**
|
|
714
1123
|
* Returns the sequencer client instance.
|
|
@@ -716,6 +1125,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
716
1125
|
*/ getSequencer() {
|
|
717
1126
|
return this.sequencer;
|
|
718
1127
|
}
|
|
1128
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
1129
|
+
return this.proverNode;
|
|
1130
|
+
}
|
|
719
1131
|
getBlockSource() {
|
|
720
1132
|
return this.blockSource;
|
|
721
1133
|
}
|
|
@@ -735,7 +1147,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
735
1147
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
736
1148
|
}
|
|
737
1149
|
async getAllowedPublicSetup() {
|
|
738
|
-
return
|
|
1150
|
+
return [
|
|
1151
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1152
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1153
|
+
];
|
|
739
1154
|
}
|
|
740
1155
|
/**
|
|
741
1156
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -758,65 +1173,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
758
1173
|
rollupVersion,
|
|
759
1174
|
enr,
|
|
760
1175
|
l1ContractAddresses: contractAddresses,
|
|
761
|
-
protocolContractAddresses: protocolContractAddresses
|
|
1176
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
1177
|
+
realProofs: !!this.config.realProofs
|
|
762
1178
|
};
|
|
763
1179
|
return nodeInfo;
|
|
764
1180
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
768
|
-
* @returns The requested block.
|
|
769
|
-
*/ async getBlock(block) {
|
|
770
|
-
if (BlockHash.isL2BlockHash(block)) {
|
|
771
|
-
return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
|
|
772
|
-
}
|
|
773
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
774
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
775
|
-
return this.buildInitialBlock();
|
|
776
|
-
}
|
|
777
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Get a block specified by its hash.
|
|
781
|
-
* @param blockHash - The block hash being requested.
|
|
782
|
-
* @returns The requested block.
|
|
783
|
-
*/ async getBlockByHash(blockHash) {
|
|
784
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
785
|
-
if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
|
|
786
|
-
return this.buildInitialBlock();
|
|
787
|
-
}
|
|
788
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
1181
|
+
async getCurrentMinFees() {
|
|
1182
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
789
1183
|
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
return L2Block.empty(initialHeader);
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Get a block specified by its archive root.
|
|
796
|
-
* @param archive - The archive root being requested.
|
|
797
|
-
* @returns The requested block.
|
|
798
|
-
*/ async getBlockByArchive(archive) {
|
|
799
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
803
|
-
* @param from - The start of the range of blocks to return.
|
|
804
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
805
|
-
* @returns The blocks requested.
|
|
806
|
-
*/ async getBlocks(from, limit) {
|
|
807
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
808
|
-
}
|
|
809
|
-
async getCheckpoints(from, limit) {
|
|
810
|
-
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
811
|
-
}
|
|
812
|
-
async getCheckpointedBlocks(from, limit) {
|
|
813
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Method to fetch the current min L2 fees.
|
|
817
|
-
* @returns The current min L2 fees.
|
|
818
|
-
*/ async getCurrentMinFees() {
|
|
819
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
1184
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
1185
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
820
1186
|
}
|
|
821
1187
|
async getMaxPriorityFees() {
|
|
822
1188
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -828,18 +1194,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
828
1194
|
});
|
|
829
1195
|
}
|
|
830
1196
|
/**
|
|
831
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
832
|
-
* @returns The block number.
|
|
833
|
-
*/ async getBlockNumber() {
|
|
834
|
-
return await this.blockSource.getBlockNumber();
|
|
835
|
-
}
|
|
836
|
-
async getProvenBlockNumber() {
|
|
837
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
838
|
-
}
|
|
839
|
-
async getCheckpointedBlockNumber() {
|
|
840
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
1197
|
* Method to fetch the version of the package.
|
|
844
1198
|
* @returns The node package version
|
|
845
1199
|
*/ getNodeVersion() {
|
|
@@ -864,30 +1218,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
864
1218
|
return this.contractDataSource.getContract(address);
|
|
865
1219
|
}
|
|
866
1220
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
1221
|
+
let upToBlockNumber;
|
|
867
1222
|
if (referenceBlock) {
|
|
868
1223
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
|
-
if (
|
|
870
|
-
|
|
871
|
-
|
|
1224
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1225
|
+
upToBlockNumber = BlockNumber(0);
|
|
1226
|
+
} else {
|
|
1227
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
872
1228
|
if (!header) {
|
|
873
1229
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
874
1230
|
}
|
|
1231
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
875
1232
|
}
|
|
876
1233
|
}
|
|
877
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1234
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
878
1235
|
}
|
|
879
1236
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1237
|
+
let upToBlockNumber;
|
|
880
1238
|
if (referenceBlock) {
|
|
881
1239
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
882
|
-
if (
|
|
883
|
-
|
|
884
|
-
|
|
1240
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1241
|
+
upToBlockNumber = BlockNumber(0);
|
|
1242
|
+
} else {
|
|
1243
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
885
1244
|
if (!header) {
|
|
886
1245
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
887
1246
|
}
|
|
1247
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
888
1248
|
}
|
|
889
1249
|
}
|
|
890
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1250
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
891
1251
|
}
|
|
892
1252
|
/**
|
|
893
1253
|
* Gets public logs based on the provided filter.
|
|
@@ -921,9 +1281,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
921
1281
|
});
|
|
922
1282
|
throw new Error(`Invalid tx: ${reason}`);
|
|
923
1283
|
}
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1284
|
+
try {
|
|
1285
|
+
await this.p2pClient.sendTx(tx);
|
|
1286
|
+
} catch (err) {
|
|
1287
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1288
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
|
|
1289
|
+
txHash
|
|
1290
|
+
});
|
|
1291
|
+
throw err;
|
|
1292
|
+
}
|
|
1293
|
+
const duration = timer.ms();
|
|
1294
|
+
this.metrics.receivedTx(duration, true);
|
|
1295
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
927
1296
|
txHash
|
|
928
1297
|
});
|
|
929
1298
|
}
|
|
@@ -934,18 +1303,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
934
1303
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
935
1304
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
936
1305
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1306
|
+
let receipt;
|
|
937
1307
|
if (settledTxReceipt) {
|
|
938
|
-
|
|
939
|
-
return settledTxReceipt;
|
|
1308
|
+
receipt = settledTxReceipt;
|
|
940
1309
|
} else if (isKnownToPool) {
|
|
941
1310
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
942
1311
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
943
1312
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
944
|
-
|
|
1313
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
945
1314
|
} else {
|
|
946
1315
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
947
|
-
|
|
1316
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
|
|
948
1317
|
}
|
|
1318
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1319
|
+
return receipt;
|
|
949
1320
|
}
|
|
950
1321
|
getTxEffect(txHash) {
|
|
951
1322
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -954,11 +1325,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
954
1325
|
* Method to stop the aztec node.
|
|
955
1326
|
*/ async stop() {
|
|
956
1327
|
this.log.info(`Stopping Aztec Node`);
|
|
1328
|
+
await tryStop(this.attestationsBlockWatcher);
|
|
957
1329
|
await tryStop(this.validatorsSentinel);
|
|
958
1330
|
await tryStop(this.epochPruneWatcher);
|
|
959
1331
|
await tryStop(this.slasherClient);
|
|
960
|
-
await
|
|
1332
|
+
await Promise.all([
|
|
1333
|
+
tryStop(this.peerProofVerifier),
|
|
1334
|
+
tryStop(this.rpcProofVerifier)
|
|
1335
|
+
]);
|
|
961
1336
|
await tryStop(this.sequencer);
|
|
1337
|
+
await tryStop(this.proverNode);
|
|
962
1338
|
await tryStop(this.p2pClient);
|
|
963
1339
|
await tryStop(this.worldStateSynchronizer);
|
|
964
1340
|
await tryStop(this.blockSource);
|
|
@@ -997,79 +1373,83 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
997
1373
|
*/ async getTxsByHash(txHashes) {
|
|
998
1374
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
999
1375
|
}
|
|
1000
|
-
async findLeavesIndexes(
|
|
1001
|
-
const committedDb = await this
|
|
1376
|
+
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1377
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1002
1378
|
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
|
-
|
|
1379
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1380
|
+
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1381
|
+
// Now we find the block numbers for the defined indices
|
|
1382
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1383
|
+
// Build a map from leaf index to block number
|
|
1384
|
+
const indexToBlockNumber = new Map();
|
|
1385
|
+
for(let i = 0; i < definedIndices.length; i++){
|
|
1386
|
+
const blockNumber = blockNumbers[i];
|
|
1387
|
+
if (blockNumber === undefined) {
|
|
1388
|
+
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1011
1389
|
}
|
|
1390
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1012
1391
|
}
|
|
1013
1392
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1014
1393
|
const uniqueBlockNumbers = [
|
|
1015
|
-
...new Set(
|
|
1394
|
+
...new Set(indexToBlockNumber.values())
|
|
1016
1395
|
];
|
|
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).
|
|
1396
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1019
1397
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1020
1398
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1021
1399
|
}));
|
|
1022
|
-
//
|
|
1400
|
+
// Build a map from block number to block hash
|
|
1401
|
+
const blockNumberToHash = new Map();
|
|
1023
1402
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1024
|
-
|
|
1403
|
+
const blockHash = blockHashes[i];
|
|
1404
|
+
if (blockHash === undefined) {
|
|
1025
1405
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1026
1406
|
}
|
|
1407
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1027
1408
|
}
|
|
1028
1409
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1029
|
-
return maybeIndices.map((index
|
|
1410
|
+
return maybeIndices.map((index)=>{
|
|
1030
1411
|
if (index === undefined) {
|
|
1031
1412
|
return undefined;
|
|
1032
1413
|
}
|
|
1033
|
-
const blockNumber =
|
|
1414
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1034
1415
|
if (blockNumber === undefined) {
|
|
1035
|
-
|
|
1416
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1036
1417
|
}
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
return undefined;
|
|
1418
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1419
|
+
if (l2BlockHash === undefined) {
|
|
1420
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1041
1421
|
}
|
|
1042
1422
|
return {
|
|
1043
|
-
l2BlockNumber:
|
|
1044
|
-
l2BlockHash
|
|
1423
|
+
l2BlockNumber: blockNumber,
|
|
1424
|
+
l2BlockHash,
|
|
1045
1425
|
data: index
|
|
1046
1426
|
};
|
|
1047
1427
|
});
|
|
1048
1428
|
}
|
|
1049
|
-
async
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
const committedDb = await this
|
|
1429
|
+
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1430
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1431
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1432
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1433
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1434
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1435
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1436
|
+
return undefined;
|
|
1437
|
+
}
|
|
1438
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1059
1439
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1060
|
-
|
|
1440
|
+
blockHash
|
|
1061
1441
|
]);
|
|
1062
1442
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1063
1443
|
}
|
|
1064
|
-
async getNoteHashMembershipWitness(
|
|
1065
|
-
const committedDb = await this
|
|
1444
|
+
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1445
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1066
1446
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1067
1447
|
noteHash
|
|
1068
1448
|
]);
|
|
1069
1449
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1070
1450
|
}
|
|
1071
|
-
async getL1ToL2MessageMembershipWitness(
|
|
1072
|
-
const db = await this
|
|
1451
|
+
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1452
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1073
1453
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1074
1454
|
l1ToL2Message
|
|
1075
1455
|
]);
|
|
@@ -1082,9 +1462,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1082
1462
|
witness.path
|
|
1083
1463
|
];
|
|
1084
1464
|
}
|
|
1085
|
-
async
|
|
1465
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1086
1466
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1087
|
-
return messageIndex ?
|
|
1467
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1088
1468
|
}
|
|
1089
1469
|
/**
|
|
1090
1470
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1101,31 +1481,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1101
1481
|
*/ async getL2ToL1Messages(epoch) {
|
|
1102
1482
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1103
1483
|
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
|
-
}
|
|
1484
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1117
1485
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1118
1486
|
}
|
|
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);
|
|
1487
|
+
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1488
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1129
1489
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1130
1490
|
nullifier.toBuffer()
|
|
1131
1491
|
]);
|
|
@@ -1139,35 +1499,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1139
1499
|
}
|
|
1140
1500
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1141
1501
|
}
|
|
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);
|
|
1502
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1503
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1157
1504
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1158
1505
|
if (!findResult) {
|
|
1159
1506
|
return undefined;
|
|
1160
1507
|
}
|
|
1161
1508
|
const { index, alreadyPresent } = findResult;
|
|
1162
1509
|
if (alreadyPresent) {
|
|
1163
|
-
|
|
1510
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1164
1511
|
}
|
|
1165
1512
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1166
1513
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1167
1514
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1168
1515
|
}
|
|
1169
|
-
async getPublicDataWitness(
|
|
1170
|
-
const committedDb = await this
|
|
1516
|
+
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1517
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1171
1518
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1172
1519
|
if (!lowLeafResult) {
|
|
1173
1520
|
return undefined;
|
|
@@ -1177,8 +1524,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1177
1524
|
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1178
1525
|
}
|
|
1179
1526
|
}
|
|
1180
|
-
async getPublicStorageAt(
|
|
1181
|
-
const committedDb = await this
|
|
1527
|
+
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1528
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1182
1529
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1183
1530
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1184
1531
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1187,31 +1534,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1187
1534
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1188
1535
|
return preimage.leaf.value;
|
|
1189
1536
|
}
|
|
1190
|
-
async getBlockHeader(block = 'latest') {
|
|
1191
|
-
if (BlockHash.isL2BlockHash(block)) {
|
|
1192
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1193
|
-
if (block.equals(initialBlockHash)) {
|
|
1194
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1195
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1196
|
-
}
|
|
1197
|
-
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1198
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1199
|
-
} else {
|
|
1200
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1201
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1202
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1203
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1204
|
-
}
|
|
1205
|
-
return this.blockSource.getBlockHeader(block);
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Get a block header specified by its archive root.
|
|
1210
|
-
* @param archive - The archive root being requested.
|
|
1211
|
-
* @returns The requested block header.
|
|
1212
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
1213
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1214
|
-
}
|
|
1215
1537
|
/**
|
|
1216
1538
|
* Simulates the public part of a transaction with the current state.
|
|
1217
1539
|
* @param tx - The transaction to simulate.
|
|
@@ -1224,17 +1546,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1224
1546
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1225
1547
|
}
|
|
1226
1548
|
const txHash = tx.getTxHash();
|
|
1227
|
-
const
|
|
1549
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1550
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1228
1551
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1229
1552
|
const coinbase = EthAddress.ZERO;
|
|
1230
1553
|
const feeRecipient = AztecAddress.ZERO;
|
|
1231
1554
|
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1232
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
1555
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1233
1556
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1234
1557
|
globalVariables: newGlobalVariables.toInspect(),
|
|
1235
1558
|
txHash,
|
|
1236
1559
|
blockNumber
|
|
1237
1560
|
});
|
|
1561
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1562
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1238
1563
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1239
1564
|
try {
|
|
1240
1565
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1249,7 +1574,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1249
1574
|
});
|
|
1250
1575
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1251
1576
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1252
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1577
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1253
1578
|
tx
|
|
1254
1579
|
]);
|
|
1255
1580
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1260,27 +1585,34 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1260
1585
|
throw failedTxs[0].error;
|
|
1261
1586
|
}
|
|
1262
1587
|
const [processedTx] = processedTxs;
|
|
1263
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1588
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1264
1589
|
} finally{
|
|
1265
1590
|
await merkleTreeFork.close();
|
|
1266
1591
|
}
|
|
1267
1592
|
}
|
|
1268
1593
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1269
1594
|
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
|
|
1595
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1596
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1272
1597
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1273
1598
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1274
|
-
const
|
|
1599
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1600
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1275
1601
|
timestamp: nextSlotTimestamp,
|
|
1276
1602
|
blockNumber,
|
|
1277
1603
|
l1ChainId: this.l1ChainId,
|
|
1278
1604
|
rollupVersion: this.version,
|
|
1279
|
-
setupAllowList:
|
|
1605
|
+
setupAllowList: [
|
|
1606
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1607
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1608
|
+
],
|
|
1280
1609
|
gasFees: await this.getCurrentMinFees(),
|
|
1281
1610
|
skipFeeEnforcement,
|
|
1282
|
-
txsPermitted: !this.config.disableTransactions
|
|
1283
|
-
|
|
1611
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1612
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1613
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1614
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1615
|
+
}, this.log.getBindings());
|
|
1284
1616
|
return await validator.validateTx(tx);
|
|
1285
1617
|
}
|
|
1286
1618
|
getConfig() {
|
|
@@ -1302,7 +1634,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1302
1634
|
archiver.updateConfig(config);
|
|
1303
1635
|
}
|
|
1304
1636
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1305
|
-
|
|
1637
|
+
await Promise.all([
|
|
1638
|
+
tryStop(this.peerProofVerifier),
|
|
1639
|
+
tryStop(this.rpcProofVerifier)
|
|
1640
|
+
]);
|
|
1641
|
+
if (newConfig.realProofs) {
|
|
1642
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1643
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1644
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1645
|
+
} else {
|
|
1646
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1647
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1648
|
+
}
|
|
1306
1649
|
}
|
|
1307
1650
|
this.config = newConfig;
|
|
1308
1651
|
}
|
|
@@ -1362,7 +1705,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1362
1705
|
});
|
|
1363
1706
|
return Promise.resolve();
|
|
1364
1707
|
}
|
|
1365
|
-
async rollbackTo(targetBlock, force) {
|
|
1708
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1366
1709
|
const archiver = this.blockSource;
|
|
1367
1710
|
if (!('rollbackTo' in archiver)) {
|
|
1368
1711
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1390,9 +1733,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1390
1733
|
this.log.error(`Error during rollback`, err);
|
|
1391
1734
|
throw err;
|
|
1392
1735
|
} finally{
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1736
|
+
if (resumeSync) {
|
|
1737
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1738
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1739
|
+
archiver.resume();
|
|
1740
|
+
} else {
|
|
1741
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1742
|
+
}
|
|
1396
1743
|
}
|
|
1397
1744
|
}
|
|
1398
1745
|
async pauseSync() {
|
|
@@ -1406,22 +1753,110 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1406
1753
|
this.blockSource.resume();
|
|
1407
1754
|
return Promise.resolve();
|
|
1408
1755
|
}
|
|
1409
|
-
getSlashPayloads() {
|
|
1410
|
-
if (!this.slasherClient) {
|
|
1411
|
-
throw new Error(`Slasher client not enabled`);
|
|
1412
|
-
}
|
|
1413
|
-
return this.slasherClient.getSlashPayloads();
|
|
1414
|
-
}
|
|
1415
1756
|
getSlashOffenses(round) {
|
|
1416
1757
|
if (!this.slasherClient) {
|
|
1417
1758
|
throw new Error(`Slasher client not enabled`);
|
|
1418
1759
|
}
|
|
1419
1760
|
if (round === 'all') {
|
|
1420
|
-
return this.slasherClient.
|
|
1761
|
+
return this.slasherClient.getOffenses();
|
|
1421
1762
|
} else {
|
|
1422
1763
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1423
1764
|
}
|
|
1424
1765
|
}
|
|
1766
|
+
async reloadKeystore() {
|
|
1767
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1768
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1769
|
+
}
|
|
1770
|
+
if (!this.validatorClient) {
|
|
1771
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1772
|
+
}
|
|
1773
|
+
this.log.info('Reloading keystore from disk');
|
|
1774
|
+
// Re-read and validate keystore files
|
|
1775
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1776
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1777
|
+
await newManager.validateSigners();
|
|
1778
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1779
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1780
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1781
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1782
|
+
// would silently fail on every proposer slot.
|
|
1783
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1784
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1785
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1786
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1787
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1788
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1789
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1790
|
+
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 ` + `[${[
|
|
1791
|
+
...availablePublishers
|
|
1792
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
// Build adapters for old and new keystores to compute diff
|
|
1797
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1798
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1799
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1800
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1801
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1802
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1803
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1804
|
+
if (added.length > 0) {
|
|
1805
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1806
|
+
}
|
|
1807
|
+
if (removed.length > 0) {
|
|
1808
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1809
|
+
}
|
|
1810
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1811
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1812
|
+
}
|
|
1813
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1814
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1815
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1816
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1817
|
+
if (this.sequencer) {
|
|
1818
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1819
|
+
}
|
|
1820
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1821
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1822
|
+
const slashValidatorsNever = unique([
|
|
1823
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1824
|
+
...newAddresses
|
|
1825
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1826
|
+
this.slasherClient.updateConfig({
|
|
1827
|
+
slashValidatorsNever
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
this.keyStoreManager = newManager;
|
|
1831
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1832
|
+
}
|
|
1833
|
+
async mineBlock() {
|
|
1834
|
+
if (!this.sequencer) {
|
|
1835
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1836
|
+
}
|
|
1837
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1838
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1839
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1840
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1841
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1842
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1843
|
+
this.sequencer.updateConfig({
|
|
1844
|
+
minTxsPerBlock: 0
|
|
1845
|
+
});
|
|
1846
|
+
try {
|
|
1847
|
+
// Trigger the sequencer to produce a block immediately
|
|
1848
|
+
void this.sequencer.trigger();
|
|
1849
|
+
// Wait for the new L2 block to appear
|
|
1850
|
+
await retryUntil(async ()=>{
|
|
1851
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1852
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1853
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1854
|
+
} finally{
|
|
1855
|
+
this.sequencer.updateConfig({
|
|
1856
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1857
|
+
});
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1425
1860
|
#getInitialHeaderHash() {
|
|
1426
1861
|
if (!this.initialHeaderHashPromise) {
|
|
1427
1862
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1432,7 +1867,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1432
1867
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1433
1868
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1434
1869
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1435
|
-
*/ async
|
|
1870
|
+
*/ async getWorldState(block) {
|
|
1436
1871
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1437
1872
|
try {
|
|
1438
1873
|
// Attempt to sync the world state if necessary
|
|
@@ -1444,30 +1879,65 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1444
1879
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1445
1880
|
return this.worldStateSynchronizer.getCommitted();
|
|
1446
1881
|
}
|
|
1447
|
-
|
|
1882
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1883
|
+
let blockNumber;
|
|
1884
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1448
1885
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1449
1886
|
if (block.equals(initialBlockHash)) {
|
|
1450
|
-
// Block
|
|
1451
|
-
|
|
1887
|
+
// Block 0 is a first-class historical block: its state lives in the trees' persisted
|
|
1888
|
+
// block-0 payload. Resolving the genesis hash to block number 0 lets the snapshot path
|
|
1889
|
+
// pin reads to genesis state even after the node has advanced past it.
|
|
1890
|
+
blockNumber = BlockNumber.ZERO;
|
|
1891
|
+
} else {
|
|
1892
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1893
|
+
if (!header) {
|
|
1894
|
+
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.`);
|
|
1895
|
+
}
|
|
1896
|
+
blockNumber = header.getBlockNumber();
|
|
1897
|
+
}
|
|
1898
|
+
} else {
|
|
1899
|
+
blockNumber = block;
|
|
1900
|
+
}
|
|
1901
|
+
// Check it's within world state sync range
|
|
1902
|
+
if (blockNumber > blockSyncedTo) {
|
|
1903
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1904
|
+
}
|
|
1905
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1906
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1907
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1908
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1909
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1910
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1911
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1912
|
+
throw new Error(`Block hash ${block.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${initialBlockHash.toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1452
1913
|
}
|
|
1453
|
-
|
|
1454
|
-
|
|
1914
|
+
}
|
|
1915
|
+
return snapshot;
|
|
1916
|
+
}
|
|
1917
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
|
|
1918
|
+
const resolved = await this.resolveBlockParameter(block);
|
|
1919
|
+
if (resolved.number !== undefined) {
|
|
1920
|
+
return resolved.number;
|
|
1921
|
+
}
|
|
1922
|
+
if (resolved.hash !== undefined) {
|
|
1923
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1924
|
+
if (resolved.hash.equals(initialBlockHash)) {
|
|
1925
|
+
return BlockNumber.ZERO;
|
|
1926
|
+
}
|
|
1927
|
+
const header = await this.blockSource.getBlockHeaderByHash(resolved.hash);
|
|
1455
1928
|
if (!header) {
|
|
1456
|
-
throw new Error(`Block hash ${
|
|
1929
|
+
throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
|
|
1457
1930
|
}
|
|
1458
|
-
|
|
1459
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1460
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1931
|
+
return header.getBlockNumber();
|
|
1461
1932
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1933
|
+
if (resolved.archive !== undefined) {
|
|
1934
|
+
const header = await this.blockSource.getBlockHeaderByArchive(resolved.archive);
|
|
1935
|
+
if (!header) {
|
|
1936
|
+
throw new Error(`Block with archive ${resolved.archive.toString()} not found.`);
|
|
1467
1937
|
}
|
|
1468
|
-
|
|
1469
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1938
|
+
return header.getBlockNumber();
|
|
1470
1939
|
}
|
|
1940
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
|
|
1471
1941
|
}
|
|
1472
1942
|
/**
|
|
1473
1943
|
* Ensure we fully sync the world state
|