@aztec/aztec-node 0.0.1-commit.5de5ca79e → 0.0.1-commit.6201a7b05
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/server.d.ts +36 -66
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +634 -332
- package/dest/sentinel/factory.d.ts +3 -2
- 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 +9 -3
- package/package.json +26 -26
- package/src/aztec-node/block_response_helpers.ts +131 -0
- package/src/aztec-node/server.ts +747 -442
- package/src/sentinel/factory.ts +2 -1
- package/src/sentinel/sentinel.ts +19 -7
|
@@ -372,7 +372,8 @@ 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';
|
|
377
378
|
import { Blob } from '@aztec/blob-lib';
|
|
378
379
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
@@ -385,6 +386,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
385
386
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
387
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
387
388
|
import { createLogger } from '@aztec/foundation/log';
|
|
389
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
388
390
|
import { count } from '@aztec/foundation/string';
|
|
389
391
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
390
392
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
@@ -395,12 +397,12 @@ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAll
|
|
|
395
397
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
398
|
import { createProverNode } from '@aztec/prover-node';
|
|
397
399
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
398
|
-
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
400
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
399
401
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
400
402
|
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
401
403
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
402
404
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
403
|
-
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
405
|
+
import { BlockHash, L2Block, inspectBlockParameter } from '@aztec/stdlib/block';
|
|
404
406
|
import { GasFees } from '@aztec/stdlib/gas';
|
|
405
407
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
406
408
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
@@ -411,10 +413,11 @@ import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@az
|
|
|
411
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
412
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
413
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
415
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
416
418
|
import { createPublicClient } from 'viem';
|
|
417
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
420
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint } from './block_response_helpers.js';
|
|
418
421
|
import { createKeyStoreForValidator } from './config.js';
|
|
419
422
|
import { NodeMetrics } from './node_metrics.js';
|
|
420
423
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
@@ -435,12 +438,15 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
435
438
|
slasherClient;
|
|
436
439
|
validatorsSentinel;
|
|
437
440
|
epochPruneWatcher;
|
|
441
|
+
attestationsBlockWatcher;
|
|
438
442
|
l1ChainId;
|
|
439
443
|
version;
|
|
440
444
|
globalVariableBuilder;
|
|
445
|
+
feeProvider;
|
|
441
446
|
epochCache;
|
|
442
447
|
packageVersion;
|
|
443
|
-
|
|
448
|
+
peerProofVerifier;
|
|
449
|
+
rpcProofVerifier;
|
|
444
450
|
telemetry;
|
|
445
451
|
log;
|
|
446
452
|
blobClient;
|
|
@@ -461,7 +467,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
461
467
|
// Prevent two snapshot operations to happen simultaneously
|
|
462
468
|
isUploadingSnapshot;
|
|
463
469
|
tracer;
|
|
464
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, 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()){
|
|
465
471
|
this.config = config;
|
|
466
472
|
this.p2pClient = p2pClient;
|
|
467
473
|
this.blockSource = blockSource;
|
|
@@ -474,12 +480,15 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
474
480
|
this.slasherClient = slasherClient;
|
|
475
481
|
this.validatorsSentinel = validatorsSentinel;
|
|
476
482
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
483
|
+
this.attestationsBlockWatcher = attestationsBlockWatcher;
|
|
477
484
|
this.l1ChainId = l1ChainId;
|
|
478
485
|
this.version = version;
|
|
479
486
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
487
|
+
this.feeProvider = feeProvider;
|
|
480
488
|
this.epochCache = epochCache;
|
|
481
489
|
this.packageVersion = packageVersion;
|
|
482
|
-
this.
|
|
490
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
491
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
483
492
|
this.telemetry = telemetry;
|
|
484
493
|
this.log = log;
|
|
485
494
|
this.blobClient = blobClient;
|
|
@@ -499,13 +508,280 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
499
508
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
500
509
|
}
|
|
501
510
|
}
|
|
511
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
512
|
+
return this.rpcProofVerifier;
|
|
513
|
+
}
|
|
502
514
|
async getWorldStateSyncStatus() {
|
|
503
515
|
const status = await this.worldStateSynchronizer.status();
|
|
504
516
|
return status.syncSummary;
|
|
505
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
|
+
}
|
|
506
527
|
getL2Tips() {
|
|
507
528
|
return this.blockSource.getL2Tips();
|
|
508
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
|
+
}
|
|
509
785
|
/**
|
|
510
786
|
* initializes the Aztec Node, wait for component to sync.
|
|
511
787
|
* @param config - The configuration to be used by the aztec node.
|
|
@@ -587,201 +863,261 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
587
863
|
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
588
864
|
dateProvider
|
|
589
865
|
});
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
dateProvider
|
|
595
|
-
}, {
|
|
596
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
597
|
-
});
|
|
598
|
-
// now create the merkle trees and the world state synchronizer
|
|
599
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
600
|
-
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
601
|
-
let debugLogStore;
|
|
602
|
-
if (!config.realProofs) {
|
|
603
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
604
|
-
debugLogStore = new InMemoryDebugLogStore();
|
|
605
|
-
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
606
|
-
} else {
|
|
607
|
-
debugLogStore = new NullDebugLogStore();
|
|
608
|
-
}
|
|
609
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
610
|
-
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
611
|
-
if (proverOnly) {
|
|
612
|
-
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
613
|
-
}
|
|
614
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
615
|
-
const p2pClient = await createP2PClient(config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
616
|
-
// We'll accumulate sentinel watchers here
|
|
617
|
-
const watchers = [];
|
|
618
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
619
|
-
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
620
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
621
|
-
...config,
|
|
622
|
-
l1GenesisTime,
|
|
623
|
-
slotDuration: Number(slotDuration),
|
|
624
|
-
rollupManaLimit,
|
|
625
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
626
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
627
|
-
let validatorClient;
|
|
628
|
-
if (!proverOnly) {
|
|
629
|
-
// Create validator client if required
|
|
630
|
-
validatorClient = await createValidatorClient(config, {
|
|
631
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
632
|
-
worldState: worldStateSynchronizer,
|
|
633
|
-
p2pClient,
|
|
634
|
-
telemetry,
|
|
635
|
-
dateProvider,
|
|
636
|
-
epochCache,
|
|
637
|
-
blockSource: archiver,
|
|
638
|
-
l1ToL2MessageSource: archiver,
|
|
639
|
-
keyStoreManager,
|
|
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, {
|
|
640
870
|
blobClient,
|
|
641
|
-
slashingProtectionDb: deps.slashingProtectionDb
|
|
642
|
-
});
|
|
643
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
644
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
645
|
-
// like attestations or auths will fail.
|
|
646
|
-
if (validatorClient) {
|
|
647
|
-
watchers.push(validatorClient);
|
|
648
|
-
if (!options.dontStartSequencer) {
|
|
649
|
-
await validatorClient.registerHandlers();
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
654
|
-
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
655
|
-
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
656
|
-
if (!validatorClient) {
|
|
657
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
658
|
-
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
659
|
-
createBlockProposalHandler(config, {
|
|
660
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
661
|
-
worldState: worldStateSynchronizer,
|
|
662
871
|
epochCache,
|
|
663
|
-
blockSource: archiver,
|
|
664
|
-
l1ToL2MessageSource: archiver,
|
|
665
|
-
p2pClient,
|
|
666
|
-
dateProvider,
|
|
667
|
-
telemetry
|
|
668
|
-
}).register(p2pClient, reexecute);
|
|
669
|
-
}
|
|
670
|
-
// Start world state and wait for it to sync to the archiver.
|
|
671
|
-
await worldStateSynchronizer.start();
|
|
672
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
673
|
-
await p2pClient.start();
|
|
674
|
-
let validatorsSentinel;
|
|
675
|
-
let epochPruneWatcher;
|
|
676
|
-
let attestationsBlockWatcher;
|
|
677
|
-
if (!proverOnly) {
|
|
678
|
-
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
679
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
680
|
-
watchers.push(validatorsSentinel);
|
|
681
|
-
}
|
|
682
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
683
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
684
|
-
watchers.push(epochPruneWatcher);
|
|
685
|
-
}
|
|
686
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
687
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
688
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
689
|
-
watchers.push(attestationsBlockWatcher);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
// Start p2p-related services once the archiver has completed sync
|
|
693
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
694
|
-
await p2pClient.start();
|
|
695
|
-
await validatorsSentinel?.start();
|
|
696
|
-
await epochPruneWatcher?.start();
|
|
697
|
-
await attestationsBlockWatcher?.start();
|
|
698
|
-
log.info(`All p2p services started`);
|
|
699
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
700
|
-
// Validator enabled, create/start relevant service
|
|
701
|
-
let sequencer;
|
|
702
|
-
let slasherClient;
|
|
703
|
-
if (!config.disableValidator && validatorClient) {
|
|
704
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
705
|
-
// as they are executed when the node is selected as proposer.
|
|
706
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
707
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
708
|
-
await slasherClient.start();
|
|
709
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
710
|
-
...config,
|
|
711
|
-
scope: 'sequencer'
|
|
712
|
-
}, {
|
|
713
872
|
telemetry,
|
|
714
|
-
|
|
715
|
-
dateProvider,
|
|
716
|
-
kzg: Blob.getViemKzgInstance()
|
|
717
|
-
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
718
|
-
...config,
|
|
719
|
-
scope: 'sequencer'
|
|
873
|
+
dateProvider
|
|
720
874
|
}, {
|
|
721
|
-
|
|
722
|
-
logger: log.createChild('l1-tx-utils'),
|
|
723
|
-
dateProvider,
|
|
724
|
-
kzg: Blob.getViemKzgInstance()
|
|
875
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
725
876
|
});
|
|
726
|
-
|
|
727
|
-
|
|
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),
|
|
905
|
+
l1GenesisTime,
|
|
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({
|
|
728
922
|
...config,
|
|
729
923
|
l1GenesisTime,
|
|
730
924
|
slotDuration: Number(slotDuration),
|
|
731
|
-
rollupManaLimit
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
validatorClient,
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
925
|
+
rollupManaLimit,
|
|
926
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
927
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
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`);
|
|
775
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;
|
|
776
1120
|
}
|
|
777
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
778
|
-
...config,
|
|
779
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
780
|
-
l1GenesisTime,
|
|
781
|
-
slotDuration: Number(slotDuration)
|
|
782
|
-
});
|
|
783
|
-
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore);
|
|
784
|
-
return node;
|
|
785
1121
|
}
|
|
786
1122
|
/**
|
|
787
1123
|
* Returns the sequencer client instance.
|
|
@@ -842,64 +1178,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
842
1178
|
};
|
|
843
1179
|
return nodeInfo;
|
|
844
1180
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
848
|
-
* @returns The requested block.
|
|
849
|
-
*/ async getBlock(block) {
|
|
850
|
-
if (BlockHash.isBlockHash(block)) {
|
|
851
|
-
return this.getBlockByHash(block);
|
|
852
|
-
}
|
|
853
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
854
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
855
|
-
return this.buildInitialBlock();
|
|
856
|
-
}
|
|
857
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
1181
|
+
async getCurrentMinFees() {
|
|
1182
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
858
1183
|
}
|
|
859
|
-
/**
|
|
860
|
-
|
|
861
|
-
* @param blockHash - The block hash being requested.
|
|
862
|
-
* @returns The requested block.
|
|
863
|
-
*/ async getBlockByHash(blockHash) {
|
|
864
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
865
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
866
|
-
return this.buildInitialBlock();
|
|
867
|
-
}
|
|
868
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
869
|
-
}
|
|
870
|
-
buildInitialBlock() {
|
|
871
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
872
|
-
return L2Block.empty(initialHeader);
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Get a block specified by its archive root.
|
|
876
|
-
* @param archive - The archive root being requested.
|
|
877
|
-
* @returns The requested block.
|
|
878
|
-
*/ async getBlockByArchive(archive) {
|
|
879
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
883
|
-
* @param from - The start of the range of blocks to return.
|
|
884
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
885
|
-
* @returns The blocks requested.
|
|
886
|
-
*/ async getBlocks(from, limit) {
|
|
887
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
888
|
-
}
|
|
889
|
-
async getCheckpoints(from, limit) {
|
|
890
|
-
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
891
|
-
}
|
|
892
|
-
async getCheckpointedBlocks(from, limit) {
|
|
893
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
894
|
-
}
|
|
895
|
-
getCheckpointsDataForEpoch(epochNumber) {
|
|
896
|
-
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* Method to fetch the current min L2 fees.
|
|
900
|
-
* @returns The current min L2 fees.
|
|
901
|
-
*/ async getCurrentMinFees() {
|
|
902
|
-
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);
|
|
903
1186
|
}
|
|
904
1187
|
async getMaxPriorityFees() {
|
|
905
1188
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -911,21 +1194,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
911
1194
|
});
|
|
912
1195
|
}
|
|
913
1196
|
/**
|
|
914
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
915
|
-
* @returns The block number.
|
|
916
|
-
*/ async getBlockNumber() {
|
|
917
|
-
return await this.blockSource.getBlockNumber();
|
|
918
|
-
}
|
|
919
|
-
async getProvenBlockNumber() {
|
|
920
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
921
|
-
}
|
|
922
|
-
async getCheckpointedBlockNumber() {
|
|
923
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
924
|
-
}
|
|
925
|
-
getCheckpointNumber() {
|
|
926
|
-
return this.blockSource.getCheckpointNumber();
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
1197
|
* Method to fetch the version of the package.
|
|
930
1198
|
* @returns The node package version
|
|
931
1199
|
*/ getNodeVersion() {
|
|
@@ -1013,7 +1281,15 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1013
1281
|
});
|
|
1014
1282
|
throw new Error(`Invalid tx: ${reason}`);
|
|
1015
1283
|
}
|
|
1016
|
-
|
|
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
|
+
}
|
|
1017
1293
|
const duration = timer.ms();
|
|
1018
1294
|
this.metrics.receivedTx(duration, true);
|
|
1019
1295
|
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
@@ -1034,10 +1310,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1034
1310
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1035
1311
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
1036
1312
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1037
|
-
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
1313
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
1038
1314
|
} else {
|
|
1039
1315
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1040
|
-
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
1316
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, /*executionResult=*/ undefined, /*error=*/ 'Tx dropped by P2P node');
|
|
1041
1317
|
}
|
|
1042
1318
|
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1043
1319
|
return receipt;
|
|
@@ -1049,10 +1325,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1049
1325
|
* Method to stop the aztec node.
|
|
1050
1326
|
*/ async stop() {
|
|
1051
1327
|
this.log.info(`Stopping Aztec Node`);
|
|
1328
|
+
await tryStop(this.attestationsBlockWatcher);
|
|
1052
1329
|
await tryStop(this.validatorsSentinel);
|
|
1053
1330
|
await tryStop(this.epochPruneWatcher);
|
|
1054
1331
|
await tryStop(this.slasherClient);
|
|
1055
|
-
await
|
|
1332
|
+
await Promise.all([
|
|
1333
|
+
tryStop(this.peerProofVerifier),
|
|
1334
|
+
tryStop(this.rpcProofVerifier)
|
|
1335
|
+
]);
|
|
1056
1336
|
await tryStop(this.sequencer);
|
|
1057
1337
|
await tryStop(this.proverNode);
|
|
1058
1338
|
await tryStop(this.p2pClient);
|
|
@@ -1135,13 +1415,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1135
1415
|
if (blockNumber === undefined) {
|
|
1136
1416
|
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1137
1417
|
}
|
|
1138
|
-
const
|
|
1139
|
-
if (
|
|
1418
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1419
|
+
if (l2BlockHash === undefined) {
|
|
1140
1420
|
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1141
1421
|
}
|
|
1142
1422
|
return {
|
|
1143
1423
|
l2BlockNumber: blockNumber,
|
|
1144
|
-
l2BlockHash
|
|
1424
|
+
l2BlockHash,
|
|
1145
1425
|
data: index
|
|
1146
1426
|
};
|
|
1147
1427
|
});
|
|
@@ -1151,6 +1431,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1151
1431
|
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1152
1432
|
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1153
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
|
+
}
|
|
1154
1438
|
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1155
1439
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1156
1440
|
blockHash
|
|
@@ -1250,36 +1534,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1250
1534
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1251
1535
|
return preimage.leaf.value;
|
|
1252
1536
|
}
|
|
1253
|
-
async getBlockHeader(block = 'latest') {
|
|
1254
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1255
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1256
|
-
if (block.equals(initialBlockHash)) {
|
|
1257
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1258
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1259
|
-
}
|
|
1260
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1261
|
-
} else {
|
|
1262
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1263
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1264
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1265
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1266
|
-
}
|
|
1267
|
-
return this.blockSource.getBlockHeader(block);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
/**
|
|
1271
|
-
* Get a block header specified by its archive root.
|
|
1272
|
-
* @param archive - The archive root being requested.
|
|
1273
|
-
* @returns The requested block header.
|
|
1274
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
1275
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1276
|
-
}
|
|
1277
|
-
getBlockData(number) {
|
|
1278
|
-
return this.blockSource.getBlockData(number);
|
|
1279
|
-
}
|
|
1280
|
-
getBlockDataByArchive(archive) {
|
|
1281
|
-
return this.blockSource.getBlockDataByArchive(archive);
|
|
1282
|
-
}
|
|
1283
1537
|
/**
|
|
1284
1538
|
* Simulates the public part of a transaction with the current state.
|
|
1285
1539
|
* @param tx - The transaction to simulate.
|
|
@@ -1338,7 +1592,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1338
1592
|
}
|
|
1339
1593
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1340
1594
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1341
|
-
const verifier = isSimulation ? undefined : this.
|
|
1595
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1342
1596
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1343
1597
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1344
1598
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
@@ -1380,7 +1634,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1380
1634
|
archiver.updateConfig(config);
|
|
1381
1635
|
}
|
|
1382
1636
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1383
|
-
|
|
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
|
+
}
|
|
1384
1649
|
}
|
|
1385
1650
|
this.config = newConfig;
|
|
1386
1651
|
}
|
|
@@ -1440,7 +1705,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1440
1705
|
});
|
|
1441
1706
|
return Promise.resolve();
|
|
1442
1707
|
}
|
|
1443
|
-
async rollbackTo(targetBlock, force) {
|
|
1708
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1444
1709
|
const archiver = this.blockSource;
|
|
1445
1710
|
if (!('rollbackTo' in archiver)) {
|
|
1446
1711
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1468,9 +1733,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1468
1733
|
this.log.error(`Error during rollback`, err);
|
|
1469
1734
|
throw err;
|
|
1470
1735
|
} finally{
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
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
|
+
}
|
|
1474
1743
|
}
|
|
1475
1744
|
}
|
|
1476
1745
|
async pauseSync() {
|
|
@@ -1484,18 +1753,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1484
1753
|
this.blockSource.resume();
|
|
1485
1754
|
return Promise.resolve();
|
|
1486
1755
|
}
|
|
1487
|
-
getSlashPayloads() {
|
|
1488
|
-
if (!this.slasherClient) {
|
|
1489
|
-
throw new Error(`Slasher client not enabled`);
|
|
1490
|
-
}
|
|
1491
|
-
return this.slasherClient.getSlashPayloads();
|
|
1492
|
-
}
|
|
1493
1756
|
getSlashOffenses(round) {
|
|
1494
1757
|
if (!this.slasherClient) {
|
|
1495
1758
|
throw new Error(`Slasher client not enabled`);
|
|
1496
1759
|
}
|
|
1497
1760
|
if (round === 'all') {
|
|
1498
|
-
return this.slasherClient.
|
|
1761
|
+
return this.slasherClient.getOffenses();
|
|
1499
1762
|
} else {
|
|
1500
1763
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1501
1764
|
}
|
|
@@ -1567,6 +1830,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1567
1830
|
this.keyStoreManager = newManager;
|
|
1568
1831
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1569
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
|
+
}
|
|
1570
1860
|
#getInitialHeaderHash() {
|
|
1571
1861
|
if (!this.initialHeaderHashPromise) {
|
|
1572
1862
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1594,48 +1884,60 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1594
1884
|
if (BlockHash.isBlockHash(block)) {
|
|
1595
1885
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1596
1886
|
if (block.equals(initialBlockHash)) {
|
|
1597
|
-
// Block
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
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();
|
|
1603
1897
|
}
|
|
1604
|
-
blockNumber = header.getBlockNumber();
|
|
1605
1898
|
} else {
|
|
1606
1899
|
blockNumber = block;
|
|
1607
1900
|
}
|
|
1608
1901
|
// Check it's within world state sync range
|
|
1609
1902
|
if (blockNumber > blockSyncedTo) {
|
|
1610
|
-
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1903
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1611
1904
|
}
|
|
1612
1905
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1613
1906
|
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1614
1907
|
// Double-check world-state synced to the same block hash as was requested
|
|
1615
1908
|
if (BlockHash.isBlockHash(block)) {
|
|
1616
1909
|
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1617
|
-
if (!blockHash || !
|
|
1618
|
-
|
|
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.`);
|
|
1619
1913
|
}
|
|
1620
1914
|
}
|
|
1621
1915
|
return snapshot;
|
|
1622
1916
|
}
|
|
1623
|
-
/** Resolves
|
|
1624
|
-
|
|
1625
|
-
|
|
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;
|
|
1626
1921
|
}
|
|
1627
|
-
if (
|
|
1922
|
+
if (resolved.hash !== undefined) {
|
|
1628
1923
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1629
|
-
if (
|
|
1924
|
+
if (resolved.hash.equals(initialBlockHash)) {
|
|
1630
1925
|
return BlockNumber.ZERO;
|
|
1631
1926
|
}
|
|
1632
|
-
const header = await this.blockSource.getBlockHeaderByHash(
|
|
1927
|
+
const header = await this.blockSource.getBlockHeaderByHash(resolved.hash);
|
|
1928
|
+
if (!header) {
|
|
1929
|
+
throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
|
|
1930
|
+
}
|
|
1931
|
+
return header.getBlockNumber();
|
|
1932
|
+
}
|
|
1933
|
+
if (resolved.archive !== undefined) {
|
|
1934
|
+
const header = await this.blockSource.getBlockHeaderByArchive(resolved.archive);
|
|
1633
1935
|
if (!header) {
|
|
1634
|
-
throw new Error(`Block
|
|
1936
|
+
throw new Error(`Block with archive ${resolved.archive.toString()} not found.`);
|
|
1635
1937
|
}
|
|
1636
1938
|
return header.getBlockNumber();
|
|
1637
1939
|
}
|
|
1638
|
-
|
|
1940
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
|
|
1639
1941
|
}
|
|
1640
1942
|
/**
|
|
1641
1943
|
* Ensure we fully sync the world state
|