@aztec/aztec-node 0.0.1-commit.0c875d939 → 0.0.1-commit.0ec55a70b
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/server.d.ts +60 -80
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +855 -367
- package/dest/sentinel/factory.d.ts +4 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.d.ts +6 -3
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +31 -18
- 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/server.ts +1018 -466
- package/src/sentinel/factory.ts +3 -2
- package/src/sentinel/sentinel.ts +41 -20
|
@@ -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.
|
|
@@ -763,61 +1178,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
763
1178
|
};
|
|
764
1179
|
return nodeInfo;
|
|
765
1180
|
}
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
769
|
-
* @returns The requested block.
|
|
770
|
-
*/ async getBlock(block) {
|
|
771
|
-
if (BlockHash.isBlockHash(block)) {
|
|
772
|
-
return this.getBlockByHash(block);
|
|
773
|
-
}
|
|
774
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
775
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
776
|
-
return this.buildInitialBlock();
|
|
777
|
-
}
|
|
778
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
779
|
-
}
|
|
780
|
-
/**
|
|
781
|
-
* Get a block specified by its hash.
|
|
782
|
-
* @param blockHash - The block hash being requested.
|
|
783
|
-
* @returns The requested block.
|
|
784
|
-
*/ async getBlockByHash(blockHash) {
|
|
785
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
786
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
787
|
-
return this.buildInitialBlock();
|
|
788
|
-
}
|
|
789
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
1181
|
+
async getCurrentMinFees() {
|
|
1182
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
790
1183
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
return L2Block.empty(initialHeader);
|
|
794
|
-
}
|
|
795
|
-
/**
|
|
796
|
-
* Get a block specified by its archive root.
|
|
797
|
-
* @param archive - The archive root being requested.
|
|
798
|
-
* @returns The requested block.
|
|
799
|
-
*/ async getBlockByArchive(archive) {
|
|
800
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
801
|
-
}
|
|
802
|
-
/**
|
|
803
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
804
|
-
* @param from - The start of the range of blocks to return.
|
|
805
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
806
|
-
* @returns The blocks requested.
|
|
807
|
-
*/ async getBlocks(from, limit) {
|
|
808
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
809
|
-
}
|
|
810
|
-
async getCheckpoints(from, limit) {
|
|
811
|
-
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
812
|
-
}
|
|
813
|
-
async getCheckpointedBlocks(from, limit) {
|
|
814
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
* Method to fetch the current min L2 fees.
|
|
818
|
-
* @returns The current min L2 fees.
|
|
819
|
-
*/ async getCurrentMinFees() {
|
|
820
|
-
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);
|
|
821
1186
|
}
|
|
822
1187
|
async getMaxPriorityFees() {
|
|
823
1188
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -829,18 +1194,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
829
1194
|
});
|
|
830
1195
|
}
|
|
831
1196
|
/**
|
|
832
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
833
|
-
* @returns The block number.
|
|
834
|
-
*/ async getBlockNumber() {
|
|
835
|
-
return await this.blockSource.getBlockNumber();
|
|
836
|
-
}
|
|
837
|
-
async getProvenBlockNumber() {
|
|
838
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
839
|
-
}
|
|
840
|
-
async getCheckpointedBlockNumber() {
|
|
841
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
1197
|
* Method to fetch the version of the package.
|
|
845
1198
|
* @returns The node package version
|
|
846
1199
|
*/ getNodeVersion() {
|
|
@@ -865,28 +1218,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
865
1218
|
return this.contractDataSource.getContract(address);
|
|
866
1219
|
}
|
|
867
1220
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
1221
|
+
let upToBlockNumber;
|
|
868
1222
|
if (referenceBlock) {
|
|
869
1223
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
870
|
-
if (
|
|
1224
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1225
|
+
upToBlockNumber = BlockNumber(0);
|
|
1226
|
+
} else {
|
|
871
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 (
|
|
1240
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1241
|
+
upToBlockNumber = BlockNumber(0);
|
|
1242
|
+
} else {
|
|
883
1243
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
884
1244
|
if (!header) {
|
|
885
1245
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
886
1246
|
}
|
|
1247
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
887
1248
|
}
|
|
888
1249
|
}
|
|
889
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1250
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
890
1251
|
}
|
|
891
1252
|
/**
|
|
892
1253
|
* Gets public logs based on the provided filter.
|
|
@@ -920,9 +1281,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
920
1281
|
});
|
|
921
1282
|
throw new Error(`Invalid tx: ${reason}`);
|
|
922
1283
|
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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`, {
|
|
926
1296
|
txHash
|
|
927
1297
|
});
|
|
928
1298
|
}
|
|
@@ -933,18 +1303,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
933
1303
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
934
1304
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
935
1305
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1306
|
+
let receipt;
|
|
936
1307
|
if (settledTxReceipt) {
|
|
937
|
-
|
|
938
|
-
return settledTxReceipt;
|
|
1308
|
+
receipt = settledTxReceipt;
|
|
939
1309
|
} else if (isKnownToPool) {
|
|
940
1310
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
941
1311
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
942
1312
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
943
|
-
|
|
1313
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
944
1314
|
} else {
|
|
945
1315
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
946
|
-
|
|
1316
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
|
|
947
1317
|
}
|
|
1318
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1319
|
+
return receipt;
|
|
948
1320
|
}
|
|
949
1321
|
getTxEffect(txHash) {
|
|
950
1322
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -953,11 +1325,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
953
1325
|
* Method to stop the aztec node.
|
|
954
1326
|
*/ async stop() {
|
|
955
1327
|
this.log.info(`Stopping Aztec Node`);
|
|
1328
|
+
await tryStop(this.attestationsBlockWatcher);
|
|
956
1329
|
await tryStop(this.validatorsSentinel);
|
|
957
1330
|
await tryStop(this.epochPruneWatcher);
|
|
958
1331
|
await tryStop(this.slasherClient);
|
|
959
|
-
await
|
|
1332
|
+
await Promise.all([
|
|
1333
|
+
tryStop(this.peerProofVerifier),
|
|
1334
|
+
tryStop(this.rpcProofVerifier)
|
|
1335
|
+
]);
|
|
960
1336
|
await tryStop(this.sequencer);
|
|
1337
|
+
await tryStop(this.proverNode);
|
|
961
1338
|
await tryStop(this.p2pClient);
|
|
962
1339
|
await tryStop(this.worldStateSynchronizer);
|
|
963
1340
|
await tryStop(this.blockSource);
|
|
@@ -997,70 +1374,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
997
1374
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
998
1375
|
}
|
|
999
1376
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1000
|
-
const committedDb = await this
|
|
1377
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1001
1378
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1002
|
-
//
|
|
1003
|
-
const
|
|
1004
|
-
// Now we find the block numbers for the indices
|
|
1005
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1006
|
-
//
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
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]}`);
|
|
1010
1389
|
}
|
|
1390
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1011
1391
|
}
|
|
1012
1392
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1013
1393
|
const uniqueBlockNumbers = [
|
|
1014
|
-
...new Set(
|
|
1394
|
+
...new Set(indexToBlockNumber.values())
|
|
1015
1395
|
];
|
|
1016
|
-
// Now we obtain the block hashes from the archive tree
|
|
1017
|
-
// (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).
|
|
1018
1397
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1019
1398
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1020
1399
|
}));
|
|
1021
|
-
//
|
|
1400
|
+
// Build a map from block number to block hash
|
|
1401
|
+
const blockNumberToHash = new Map();
|
|
1022
1402
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1023
|
-
|
|
1403
|
+
const blockHash = blockHashes[i];
|
|
1404
|
+
if (blockHash === undefined) {
|
|
1024
1405
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1025
1406
|
}
|
|
1407
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1026
1408
|
}
|
|
1027
1409
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1028
|
-
return maybeIndices.map((index
|
|
1410
|
+
return maybeIndices.map((index)=>{
|
|
1029
1411
|
if (index === undefined) {
|
|
1030
1412
|
return undefined;
|
|
1031
1413
|
}
|
|
1032
|
-
const blockNumber =
|
|
1414
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1033
1415
|
if (blockNumber === undefined) {
|
|
1034
|
-
|
|
1416
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1035
1417
|
}
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
return undefined;
|
|
1418
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1419
|
+
if (l2BlockHash === undefined) {
|
|
1420
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1040
1421
|
}
|
|
1041
1422
|
return {
|
|
1042
|
-
l2BlockNumber:
|
|
1043
|
-
l2BlockHash
|
|
1423
|
+
l2BlockNumber: blockNumber,
|
|
1424
|
+
l2BlockHash,
|
|
1044
1425
|
data: index
|
|
1045
1426
|
};
|
|
1046
1427
|
});
|
|
1047
1428
|
}
|
|
1048
1429
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1049
|
-
|
|
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));
|
|
1050
1439
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1051
1440
|
blockHash
|
|
1052
1441
|
]);
|
|
1053
1442
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1054
1443
|
}
|
|
1055
1444
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1056
|
-
const committedDb = await this
|
|
1445
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1057
1446
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1058
1447
|
noteHash
|
|
1059
1448
|
]);
|
|
1060
1449
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1061
1450
|
}
|
|
1062
1451
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1063
|
-
const db = await this
|
|
1452
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1064
1453
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1065
1454
|
l1ToL2Message
|
|
1066
1455
|
]);
|
|
@@ -1073,9 +1462,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1073
1462
|
witness.path
|
|
1074
1463
|
];
|
|
1075
1464
|
}
|
|
1076
|
-
async
|
|
1465
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1077
1466
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1078
|
-
return messageIndex ?
|
|
1467
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1079
1468
|
}
|
|
1080
1469
|
/**
|
|
1081
1470
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1092,23 +1481,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1092
1481
|
*/ async getL2ToL1Messages(epoch) {
|
|
1093
1482
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1094
1483
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1095
|
-
const blocksInCheckpoints =
|
|
1096
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1097
|
-
let checkpointIndex = -1;
|
|
1098
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1099
|
-
const block = checkpointedBlock.block;
|
|
1100
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1101
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1102
|
-
checkpointIndex++;
|
|
1103
|
-
blocksInCheckpoints.push([]);
|
|
1104
|
-
previousSlotNumber = slotNumber;
|
|
1105
|
-
}
|
|
1106
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1107
|
-
}
|
|
1484
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1108
1485
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1109
1486
|
}
|
|
1110
1487
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1111
|
-
const db = await this
|
|
1488
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1112
1489
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1113
1490
|
nullifier.toBuffer()
|
|
1114
1491
|
]);
|
|
@@ -1122,36 +1499,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1122
1499
|
}
|
|
1123
1500
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1124
1501
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1128
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1129
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1130
|
-
* @returns The low nullifier membership witness (if found).
|
|
1131
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1132
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1133
|
-
* we are trying to prove non-inclusion for.
|
|
1134
|
-
*
|
|
1135
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1136
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1137
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1138
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1139
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1140
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1502
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1503
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1141
1504
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1142
1505
|
if (!findResult) {
|
|
1143
1506
|
return undefined;
|
|
1144
1507
|
}
|
|
1145
1508
|
const { index, alreadyPresent } = findResult;
|
|
1146
1509
|
if (alreadyPresent) {
|
|
1147
|
-
|
|
1510
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1148
1511
|
}
|
|
1149
1512
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1150
1513
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1151
1514
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1152
1515
|
}
|
|
1153
1516
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1154
|
-
const committedDb = await this
|
|
1517
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1155
1518
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1156
1519
|
if (!lowLeafResult) {
|
|
1157
1520
|
return undefined;
|
|
@@ -1162,7 +1525,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1162
1525
|
}
|
|
1163
1526
|
}
|
|
1164
1527
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1165
|
-
const committedDb = await this
|
|
1528
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1166
1529
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1167
1530
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1168
1531
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1171,30 +1534,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1171
1534
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1172
1535
|
return preimage.leaf.value;
|
|
1173
1536
|
}
|
|
1174
|
-
async getBlockHeader(block = 'latest') {
|
|
1175
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1176
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1177
|
-
if (block.equals(initialBlockHash)) {
|
|
1178
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1179
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1180
|
-
}
|
|
1181
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1182
|
-
} else {
|
|
1183
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1184
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1185
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1186
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1187
|
-
}
|
|
1188
|
-
return this.blockSource.getBlockHeader(block);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Get a block header specified by its archive root.
|
|
1193
|
-
* @param archive - The archive root being requested.
|
|
1194
|
-
* @returns The requested block header.
|
|
1195
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
1196
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1197
|
-
}
|
|
1198
1537
|
/**
|
|
1199
1538
|
* Simulates the public part of a transaction with the current state.
|
|
1200
1539
|
* @param tx - The transaction to simulate.
|
|
@@ -1207,7 +1546,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1207
1546
|
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1208
1547
|
}
|
|
1209
1548
|
const txHash = tx.getTxHash();
|
|
1210
|
-
const
|
|
1549
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1550
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1211
1551
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1212
1552
|
const coinbase = EthAddress.ZERO;
|
|
1213
1553
|
const feeRecipient = AztecAddress.ZERO;
|
|
@@ -1218,6 +1558,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1218
1558
|
txHash,
|
|
1219
1559
|
blockNumber
|
|
1220
1560
|
});
|
|
1561
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1562
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1221
1563
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1222
1564
|
try {
|
|
1223
1565
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1232,7 +1574,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1232
1574
|
});
|
|
1233
1575
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1234
1576
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1235
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1577
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1236
1578
|
tx
|
|
1237
1579
|
]);
|
|
1238
1580
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1243,26 +1585,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1243
1585
|
throw failedTxs[0].error;
|
|
1244
1586
|
}
|
|
1245
1587
|
const [processedTx] = processedTxs;
|
|
1246
|
-
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);
|
|
1247
1589
|
} finally{
|
|
1248
1590
|
await merkleTreeFork.close();
|
|
1249
1591
|
}
|
|
1250
1592
|
}
|
|
1251
1593
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1252
1594
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1253
|
-
const verifier = isSimulation ? undefined : this.
|
|
1254
|
-
// 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)
|
|
1255
1597
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1256
1598
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1257
|
-
const
|
|
1599
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1600
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1258
1601
|
timestamp: nextSlotTimestamp,
|
|
1259
1602
|
blockNumber,
|
|
1260
1603
|
l1ChainId: this.l1ChainId,
|
|
1261
1604
|
rollupVersion: this.version,
|
|
1262
|
-
setupAllowList:
|
|
1605
|
+
setupAllowList: [
|
|
1606
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1607
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1608
|
+
],
|
|
1263
1609
|
gasFees: await this.getCurrentMinFees(),
|
|
1264
1610
|
skipFeeEnforcement,
|
|
1265
|
-
txsPermitted: !this.config.disableTransactions
|
|
1611
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1612
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1613
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1614
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1266
1615
|
}, this.log.getBindings());
|
|
1267
1616
|
return await validator.validateTx(tx);
|
|
1268
1617
|
}
|
|
@@ -1285,7 +1634,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1285
1634
|
archiver.updateConfig(config);
|
|
1286
1635
|
}
|
|
1287
1636
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1288
|
-
|
|
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
|
+
}
|
|
1289
1649
|
}
|
|
1290
1650
|
this.config = newConfig;
|
|
1291
1651
|
}
|
|
@@ -1345,7 +1705,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1345
1705
|
});
|
|
1346
1706
|
return Promise.resolve();
|
|
1347
1707
|
}
|
|
1348
|
-
async rollbackTo(targetBlock, force) {
|
|
1708
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1349
1709
|
const archiver = this.blockSource;
|
|
1350
1710
|
if (!('rollbackTo' in archiver)) {
|
|
1351
1711
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1373,9 +1733,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1373
1733
|
this.log.error(`Error during rollback`, err);
|
|
1374
1734
|
throw err;
|
|
1375
1735
|
} finally{
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
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
|
+
}
|
|
1379
1743
|
}
|
|
1380
1744
|
}
|
|
1381
1745
|
async pauseSync() {
|
|
@@ -1389,22 +1753,110 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1389
1753
|
this.blockSource.resume();
|
|
1390
1754
|
return Promise.resolve();
|
|
1391
1755
|
}
|
|
1392
|
-
getSlashPayloads() {
|
|
1393
|
-
if (!this.slasherClient) {
|
|
1394
|
-
throw new Error(`Slasher client not enabled`);
|
|
1395
|
-
}
|
|
1396
|
-
return this.slasherClient.getSlashPayloads();
|
|
1397
|
-
}
|
|
1398
1756
|
getSlashOffenses(round) {
|
|
1399
1757
|
if (!this.slasherClient) {
|
|
1400
1758
|
throw new Error(`Slasher client not enabled`);
|
|
1401
1759
|
}
|
|
1402
1760
|
if (round === 'all') {
|
|
1403
|
-
return this.slasherClient.
|
|
1761
|
+
return this.slasherClient.getOffenses();
|
|
1404
1762
|
} else {
|
|
1405
1763
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1406
1764
|
}
|
|
1407
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
|
+
}
|
|
1408
1860
|
#getInitialHeaderHash() {
|
|
1409
1861
|
if (!this.initialHeaderHashPromise) {
|
|
1410
1862
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1415,7 +1867,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1415
1867
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1416
1868
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1417
1869
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1418
|
-
*/ async
|
|
1870
|
+
*/ async getWorldState(block) {
|
|
1419
1871
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1420
1872
|
try {
|
|
1421
1873
|
// Attempt to sync the world state if necessary
|
|
@@ -1427,29 +1879,65 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1427
1879
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1428
1880
|
return this.worldStateSynchronizer.getCommitted();
|
|
1429
1881
|
}
|
|
1882
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1883
|
+
let blockNumber;
|
|
1430
1884
|
if (BlockHash.isBlockHash(block)) {
|
|
1431
1885
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1432
1886
|
if (block.equals(initialBlockHash)) {
|
|
1433
|
-
// Block
|
|
1434
|
-
|
|
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.`);
|
|
1435
1913
|
}
|
|
1436
|
-
|
|
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);
|
|
1437
1928
|
if (!header) {
|
|
1438
|
-
throw new Error(`Block hash ${
|
|
1929
|
+
throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
|
|
1439
1930
|
}
|
|
1440
|
-
|
|
1441
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1442
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1931
|
+
return header.getBlockNumber();
|
|
1443
1932
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
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.`);
|
|
1449
1937
|
}
|
|
1450
|
-
|
|
1451
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1938
|
+
return header.getBlockNumber();
|
|
1452
1939
|
}
|
|
1940
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
|
|
1453
1941
|
}
|
|
1454
1942
|
/**
|
|
1455
1943
|
* Ensure we fully sync the world state
|