@aztec/aztec-node 0.0.1-commit.934299a21 → 0.0.1-commit.949a33fd8
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 +2 -2
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +1 -1
- package/dest/aztec-node/server.d.ts +47 -81
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +736 -388
- 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 +16 -10
- package/package.json +26 -27
- package/src/aztec-node/block_response_helpers.ts +131 -0
- package/src/aztec-node/config.ts +1 -1
- package/src/aztec-node/server.ts +855 -490
- package/src/sentinel/factory.ts +3 -2
- package/src/sentinel/sentinel.ts +26 -14
|
@@ -372,19 +372,21 @@ 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';
|
|
379
380
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
381
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
382
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
-
import { BlockNumber
|
|
383
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
383
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
384
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
385
|
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,27 +397,27 @@ 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';
|
|
407
409
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
408
410
|
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
409
411
|
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
410
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
411
412
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
412
413
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
413
414
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
414
415
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
415
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
416
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
416
417
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
417
|
-
import { createPublicClient
|
|
418
|
+
import { createPublicClient } from 'viem';
|
|
418
419
|
import { createSentinel } from '../sentinel/factory.js';
|
|
420
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint } from './block_response_helpers.js';
|
|
419
421
|
import { createKeyStoreForValidator } from './config.js';
|
|
420
422
|
import { NodeMetrics } from './node_metrics.js';
|
|
421
423
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
@@ -436,12 +438,15 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
436
438
|
slasherClient;
|
|
437
439
|
validatorsSentinel;
|
|
438
440
|
epochPruneWatcher;
|
|
441
|
+
attestationsBlockWatcher;
|
|
439
442
|
l1ChainId;
|
|
440
443
|
version;
|
|
441
444
|
globalVariableBuilder;
|
|
445
|
+
feeProvider;
|
|
442
446
|
epochCache;
|
|
443
447
|
packageVersion;
|
|
444
|
-
|
|
448
|
+
peerProofVerifier;
|
|
449
|
+
rpcProofVerifier;
|
|
445
450
|
telemetry;
|
|
446
451
|
log;
|
|
447
452
|
blobClient;
|
|
@@ -462,7 +467,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
462
467
|
// Prevent two snapshot operations to happen simultaneously
|
|
463
468
|
isUploadingSnapshot;
|
|
464
469
|
tracer;
|
|
465
|
-
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()){
|
|
466
471
|
this.config = config;
|
|
467
472
|
this.p2pClient = p2pClient;
|
|
468
473
|
this.blockSource = blockSource;
|
|
@@ -475,12 +480,15 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
475
480
|
this.slasherClient = slasherClient;
|
|
476
481
|
this.validatorsSentinel = validatorsSentinel;
|
|
477
482
|
this.epochPruneWatcher = epochPruneWatcher;
|
|
483
|
+
this.attestationsBlockWatcher = attestationsBlockWatcher;
|
|
478
484
|
this.l1ChainId = l1ChainId;
|
|
479
485
|
this.version = version;
|
|
480
486
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
487
|
+
this.feeProvider = feeProvider;
|
|
481
488
|
this.epochCache = epochCache;
|
|
482
489
|
this.packageVersion = packageVersion;
|
|
483
|
-
this.
|
|
490
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
491
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
484
492
|
this.telemetry = telemetry;
|
|
485
493
|
this.log = log;
|
|
486
494
|
this.blobClient = blobClient;
|
|
@@ -500,13 +508,280 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
500
508
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
501
509
|
}
|
|
502
510
|
}
|
|
511
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
512
|
+
return this.rpcProofVerifier;
|
|
513
|
+
}
|
|
503
514
|
async getWorldStateSyncStatus() {
|
|
504
515
|
const status = await this.worldStateSynchronizer.status();
|
|
505
516
|
return status.syncSummary;
|
|
506
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
|
+
}
|
|
507
527
|
getL2Tips() {
|
|
508
528
|
return this.blockSource.getL2Tips();
|
|
509
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
|
+
}
|
|
510
785
|
/**
|
|
511
786
|
* initializes the Aztec Node, wait for component to sync.
|
|
512
787
|
* @param config - The configuration to be used by the aztec node.
|
|
@@ -560,9 +835,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
560
835
|
}
|
|
561
836
|
const publicClient = createPublicClient({
|
|
562
837
|
chain: ethereumChain.chainInfo,
|
|
563
|
-
transport:
|
|
564
|
-
|
|
565
|
-
|
|
838
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
839
|
+
timeout: config.l1HttpTimeoutMS
|
|
840
|
+
}),
|
|
566
841
|
pollingInterval: config.viemPollingIntervalMS
|
|
567
842
|
});
|
|
568
843
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
@@ -572,10 +847,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
572
847
|
...l1ContractsAddresses
|
|
573
848
|
};
|
|
574
849
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
575
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
850
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
576
851
|
rollupContract.getL1GenesisTime(),
|
|
577
852
|
rollupContract.getSlotDuration(),
|
|
578
|
-
rollupContract.getVersion()
|
|
853
|
+
rollupContract.getVersion(),
|
|
854
|
+
rollupContract.getManaLimit().then(Number)
|
|
579
855
|
]);
|
|
580
856
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
581
857
|
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
@@ -587,186 +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
|
-
|
|
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
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
611
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
612
|
-
// We should really not be modifying the config object
|
|
613
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
614
|
-
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
615
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
616
|
-
...config,
|
|
617
|
-
l1GenesisTime,
|
|
618
|
-
slotDuration: Number(slotDuration)
|
|
619
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
620
|
-
// We'll accumulate sentinel watchers here
|
|
621
|
-
const watchers = [];
|
|
622
|
-
// Create validator client if required
|
|
623
|
-
const validatorClient = await createValidatorClient(config, {
|
|
624
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
625
|
-
worldState: worldStateSynchronizer,
|
|
626
|
-
p2pClient,
|
|
627
|
-
telemetry,
|
|
628
|
-
dateProvider,
|
|
629
|
-
epochCache,
|
|
630
|
-
blockSource: archiver,
|
|
631
|
-
l1ToL2MessageSource: archiver,
|
|
632
|
-
keyStoreManager,
|
|
633
|
-
blobClient
|
|
634
|
-
});
|
|
635
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
636
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
637
|
-
// like attestations or auths will fail.
|
|
638
|
-
if (validatorClient) {
|
|
639
|
-
watchers.push(validatorClient);
|
|
640
|
-
if (!options.dontStartSequencer) {
|
|
641
|
-
await validatorClient.registerHandlers();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
645
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
646
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
647
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
648
|
-
createBlockProposalHandler(config, {
|
|
649
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
650
|
-
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,
|
|
651
871
|
epochCache,
|
|
652
|
-
blockSource: archiver,
|
|
653
|
-
l1ToL2MessageSource: archiver,
|
|
654
|
-
p2pClient,
|
|
655
|
-
dateProvider,
|
|
656
|
-
telemetry
|
|
657
|
-
}).registerForReexecution(p2pClient);
|
|
658
|
-
}
|
|
659
|
-
// Start world state and wait for it to sync to the archiver.
|
|
660
|
-
await worldStateSynchronizer.start();
|
|
661
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
662
|
-
await p2pClient.start();
|
|
663
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
664
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
665
|
-
watchers.push(validatorsSentinel);
|
|
666
|
-
}
|
|
667
|
-
let epochPruneWatcher;
|
|
668
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
669
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
670
|
-
watchers.push(epochPruneWatcher);
|
|
671
|
-
}
|
|
672
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
673
|
-
let attestationsBlockWatcher;
|
|
674
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
675
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
676
|
-
watchers.push(attestationsBlockWatcher);
|
|
677
|
-
}
|
|
678
|
-
// Start p2p-related services once the archiver has completed sync
|
|
679
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
680
|
-
await p2pClient.start();
|
|
681
|
-
await validatorsSentinel?.start();
|
|
682
|
-
await epochPruneWatcher?.start();
|
|
683
|
-
await attestationsBlockWatcher?.start();
|
|
684
|
-
log.info(`All p2p services started`);
|
|
685
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
686
|
-
// Validator enabled, create/start relevant service
|
|
687
|
-
let sequencer;
|
|
688
|
-
let slasherClient;
|
|
689
|
-
if (!config.disableValidator && validatorClient) {
|
|
690
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
691
|
-
// as they are executed when the node is selected as proposer.
|
|
692
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
693
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
694
|
-
await slasherClient.start();
|
|
695
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
696
|
-
...config,
|
|
697
|
-
scope: 'sequencer'
|
|
698
|
-
}, {
|
|
699
872
|
telemetry,
|
|
700
|
-
|
|
701
|
-
dateProvider,
|
|
702
|
-
kzg: Blob.getViemKzgInstance()
|
|
703
|
-
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
704
|
-
...config,
|
|
705
|
-
scope: 'sequencer'
|
|
873
|
+
dateProvider
|
|
706
874
|
}, {
|
|
707
|
-
|
|
708
|
-
logger: log.createChild('l1-tx-utils'),
|
|
709
|
-
dateProvider,
|
|
710
|
-
kzg: Blob.getViemKzgInstance()
|
|
875
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
711
876
|
});
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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),
|
|
715
905
|
l1GenesisTime,
|
|
716
906
|
slotDuration: Number(slotDuration)
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
p2pClient,
|
|
724
|
-
worldStateSynchronizer,
|
|
725
|
-
slasherClient,
|
|
726
|
-
checkpointsBuilder,
|
|
727
|
-
l2BlockSource: archiver,
|
|
728
|
-
l1ToL2MessageSource: archiver,
|
|
729
|
-
telemetry,
|
|
730
|
-
dateProvider,
|
|
731
|
-
blobClient,
|
|
732
|
-
nodeKeyStore: keyStoreManager
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
736
|
-
await sequencer.start();
|
|
737
|
-
log.verbose(`Sequencer started`);
|
|
738
|
-
} else if (sequencer) {
|
|
739
|
-
log.warn(`Sequencer created but not started`);
|
|
740
|
-
}
|
|
741
|
-
// Create prover node subsystem if enabled
|
|
742
|
-
let proverNode;
|
|
743
|
-
if (config.enableProverNode) {
|
|
744
|
-
proverNode = await createProverNode(config, {
|
|
745
|
-
...deps.proverNodeDeps,
|
|
746
|
-
telemetry,
|
|
747
|
-
dateProvider,
|
|
748
|
-
archiver,
|
|
749
|
-
worldStateSynchronizer,
|
|
750
|
-
p2pClient,
|
|
751
|
-
epochCache,
|
|
752
|
-
blobClient,
|
|
753
|
-
keyStoreManager
|
|
754
|
-
});
|
|
755
|
-
if (!options.dontStartProverNode) {
|
|
756
|
-
await proverNode.start();
|
|
757
|
-
log.info(`Prover node subsystem started`);
|
|
758
|
-
} else {
|
|
759
|
-
log.info(`Prover node subsystem created but not started`);
|
|
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');
|
|
760
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
|
|
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`);
|
|
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;
|
|
761
1120
|
}
|
|
762
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
763
|
-
...config,
|
|
764
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
765
|
-
l1GenesisTime,
|
|
766
|
-
slotDuration: Number(slotDuration)
|
|
767
|
-
});
|
|
768
|
-
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);
|
|
769
|
-
return node;
|
|
770
1121
|
}
|
|
771
1122
|
/**
|
|
772
1123
|
* Returns the sequencer client instance.
|
|
@@ -796,7 +1147,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
796
1147
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
797
1148
|
}
|
|
798
1149
|
async getAllowedPublicSetup() {
|
|
799
|
-
return
|
|
1150
|
+
return [
|
|
1151
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1152
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1153
|
+
];
|
|
800
1154
|
}
|
|
801
1155
|
/**
|
|
802
1156
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -824,61 +1178,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
824
1178
|
};
|
|
825
1179
|
return nodeInfo;
|
|
826
1180
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
830
|
-
* @returns The requested block.
|
|
831
|
-
*/ async getBlock(block) {
|
|
832
|
-
if (BlockHash.isBlockHash(block)) {
|
|
833
|
-
return this.getBlockByHash(block);
|
|
834
|
-
}
|
|
835
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
836
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
837
|
-
return this.buildInitialBlock();
|
|
838
|
-
}
|
|
839
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Get a block specified by its hash.
|
|
843
|
-
* @param blockHash - The block hash being requested.
|
|
844
|
-
* @returns The requested block.
|
|
845
|
-
*/ async getBlockByHash(blockHash) {
|
|
846
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
847
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
848
|
-
return this.buildInitialBlock();
|
|
849
|
-
}
|
|
850
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
851
|
-
}
|
|
852
|
-
buildInitialBlock() {
|
|
853
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
854
|
-
return L2Block.empty(initialHeader);
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Get a block specified by its archive root.
|
|
858
|
-
* @param archive - The archive root being requested.
|
|
859
|
-
* @returns The requested block.
|
|
860
|
-
*/ async getBlockByArchive(archive) {
|
|
861
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
865
|
-
* @param from - The start of the range of blocks to return.
|
|
866
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
867
|
-
* @returns The blocks requested.
|
|
868
|
-
*/ async getBlocks(from, limit) {
|
|
869
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
870
|
-
}
|
|
871
|
-
async getCheckpoints(from, limit) {
|
|
872
|
-
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
1181
|
+
async getCurrentMinFees() {
|
|
1182
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
873
1183
|
}
|
|
874
|
-
async
|
|
875
|
-
return await this.
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Method to fetch the current min L2 fees.
|
|
879
|
-
* @returns The current min L2 fees.
|
|
880
|
-
*/ async getCurrentMinFees() {
|
|
881
|
-
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);
|
|
882
1186
|
}
|
|
883
1187
|
async getMaxPriorityFees() {
|
|
884
1188
|
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
@@ -890,18 +1194,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
890
1194
|
});
|
|
891
1195
|
}
|
|
892
1196
|
/**
|
|
893
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
894
|
-
* @returns The block number.
|
|
895
|
-
*/ async getBlockNumber() {
|
|
896
|
-
return await this.blockSource.getBlockNumber();
|
|
897
|
-
}
|
|
898
|
-
async getProvenBlockNumber() {
|
|
899
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
900
|
-
}
|
|
901
|
-
async getCheckpointedBlockNumber() {
|
|
902
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
903
|
-
}
|
|
904
|
-
/**
|
|
905
1197
|
* Method to fetch the version of the package.
|
|
906
1198
|
* @returns The node package version
|
|
907
1199
|
*/ getNodeVersion() {
|
|
@@ -926,28 +1218,36 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
926
1218
|
return this.contractDataSource.getContract(address);
|
|
927
1219
|
}
|
|
928
1220
|
async getPrivateLogsByTags(tags, page, referenceBlock) {
|
|
1221
|
+
let upToBlockNumber;
|
|
929
1222
|
if (referenceBlock) {
|
|
930
1223
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
931
|
-
if (
|
|
1224
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1225
|
+
upToBlockNumber = BlockNumber(0);
|
|
1226
|
+
} else {
|
|
932
1227
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
933
1228
|
if (!header) {
|
|
934
1229
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
935
1230
|
}
|
|
1231
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
936
1232
|
}
|
|
937
1233
|
}
|
|
938
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
1234
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
939
1235
|
}
|
|
940
1236
|
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
1237
|
+
let upToBlockNumber;
|
|
941
1238
|
if (referenceBlock) {
|
|
942
1239
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
943
|
-
if (
|
|
1240
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1241
|
+
upToBlockNumber = BlockNumber(0);
|
|
1242
|
+
} else {
|
|
944
1243
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
945
1244
|
if (!header) {
|
|
946
1245
|
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
947
1246
|
}
|
|
1247
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
948
1248
|
}
|
|
949
1249
|
}
|
|
950
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1250
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
951
1251
|
}
|
|
952
1252
|
/**
|
|
953
1253
|
* Gets public logs based on the provided filter.
|
|
@@ -981,9 +1281,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
981
1281
|
});
|
|
982
1282
|
throw new Error(`Invalid tx: ${reason}`);
|
|
983
1283
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
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`, {
|
|
987
1296
|
txHash
|
|
988
1297
|
});
|
|
989
1298
|
}
|
|
@@ -1001,10 +1310,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1001
1310
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1002
1311
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
1003
1312
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1004
|
-
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
1313
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
1005
1314
|
} else {
|
|
1006
1315
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1007
|
-
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');
|
|
1008
1317
|
}
|
|
1009
1318
|
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1010
1319
|
return receipt;
|
|
@@ -1016,10 +1325,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1016
1325
|
* Method to stop the aztec node.
|
|
1017
1326
|
*/ async stop() {
|
|
1018
1327
|
this.log.info(`Stopping Aztec Node`);
|
|
1328
|
+
await tryStop(this.attestationsBlockWatcher);
|
|
1019
1329
|
await tryStop(this.validatorsSentinel);
|
|
1020
1330
|
await tryStop(this.epochPruneWatcher);
|
|
1021
1331
|
await tryStop(this.slasherClient);
|
|
1022
|
-
await
|
|
1332
|
+
await Promise.all([
|
|
1333
|
+
tryStop(this.peerProofVerifier),
|
|
1334
|
+
tryStop(this.rpcProofVerifier)
|
|
1335
|
+
]);
|
|
1023
1336
|
await tryStop(this.sequencer);
|
|
1024
1337
|
await tryStop(this.proverNode);
|
|
1025
1338
|
await tryStop(this.p2pClient);
|
|
@@ -1061,70 +1374,82 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1061
1374
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
1062
1375
|
}
|
|
1063
1376
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1064
|
-
const committedDb = await this
|
|
1377
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1065
1378
|
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1066
|
-
//
|
|
1067
|
-
const
|
|
1068
|
-
// Now we find the block numbers for the indices
|
|
1069
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1070
|
-
//
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
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]}`);
|
|
1074
1389
|
}
|
|
1390
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1075
1391
|
}
|
|
1076
1392
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1077
1393
|
const uniqueBlockNumbers = [
|
|
1078
|
-
...new Set(
|
|
1394
|
+
...new Set(indexToBlockNumber.values())
|
|
1079
1395
|
];
|
|
1080
|
-
// Now we obtain the block hashes from the archive tree
|
|
1081
|
-
// (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).
|
|
1082
1397
|
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1083
1398
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1084
1399
|
}));
|
|
1085
|
-
//
|
|
1400
|
+
// Build a map from block number to block hash
|
|
1401
|
+
const blockNumberToHash = new Map();
|
|
1086
1402
|
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1087
|
-
|
|
1403
|
+
const blockHash = blockHashes[i];
|
|
1404
|
+
if (blockHash === undefined) {
|
|
1088
1405
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1089
1406
|
}
|
|
1407
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1090
1408
|
}
|
|
1091
1409
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1092
|
-
return maybeIndices.map((index
|
|
1410
|
+
return maybeIndices.map((index)=>{
|
|
1093
1411
|
if (index === undefined) {
|
|
1094
1412
|
return undefined;
|
|
1095
1413
|
}
|
|
1096
|
-
const blockNumber =
|
|
1414
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
1097
1415
|
if (blockNumber === undefined) {
|
|
1098
|
-
|
|
1416
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1099
1417
|
}
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
return undefined;
|
|
1418
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1419
|
+
if (l2BlockHash === undefined) {
|
|
1420
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1104
1421
|
}
|
|
1105
1422
|
return {
|
|
1106
|
-
l2BlockNumber:
|
|
1107
|
-
l2BlockHash
|
|
1423
|
+
l2BlockNumber: blockNumber,
|
|
1424
|
+
l2BlockHash,
|
|
1108
1425
|
data: index
|
|
1109
1426
|
};
|
|
1110
1427
|
});
|
|
1111
1428
|
}
|
|
1112
1429
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1113
|
-
|
|
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));
|
|
1114
1439
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1115
1440
|
blockHash
|
|
1116
1441
|
]);
|
|
1117
1442
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1118
1443
|
}
|
|
1119
1444
|
async getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
1120
|
-
const committedDb = await this
|
|
1445
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1121
1446
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1122
1447
|
noteHash
|
|
1123
1448
|
]);
|
|
1124
1449
|
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1125
1450
|
}
|
|
1126
1451
|
async getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
1127
|
-
const db = await this
|
|
1452
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1128
1453
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1129
1454
|
l1ToL2Message
|
|
1130
1455
|
]);
|
|
@@ -1137,9 +1462,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1137
1462
|
witness.path
|
|
1138
1463
|
];
|
|
1139
1464
|
}
|
|
1140
|
-
async
|
|
1465
|
+
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1141
1466
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1142
|
-
return messageIndex ?
|
|
1467
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1143
1468
|
}
|
|
1144
1469
|
/**
|
|
1145
1470
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
@@ -1156,23 +1481,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1156
1481
|
*/ async getL2ToL1Messages(epoch) {
|
|
1157
1482
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1158
1483
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1159
|
-
const blocksInCheckpoints =
|
|
1160
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1161
|
-
let checkpointIndex = -1;
|
|
1162
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1163
|
-
const block = checkpointedBlock.block;
|
|
1164
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1165
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1166
|
-
checkpointIndex++;
|
|
1167
|
-
blocksInCheckpoints.push([]);
|
|
1168
|
-
previousSlotNumber = slotNumber;
|
|
1169
|
-
}
|
|
1170
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1171
|
-
}
|
|
1484
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, (cb)=>cb.block.header.globalVariables.slotNumber).map((group)=>group.map((cb)=>cb.block));
|
|
1172
1485
|
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1173
1486
|
}
|
|
1174
1487
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1175
|
-
const db = await this
|
|
1488
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1176
1489
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1177
1490
|
nullifier.toBuffer()
|
|
1178
1491
|
]);
|
|
@@ -1186,36 +1499,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1186
1499
|
}
|
|
1187
1500
|
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
1188
1501
|
}
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1192
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1193
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1194
|
-
* @returns The low nullifier membership witness (if found).
|
|
1195
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1196
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1197
|
-
* we are trying to prove non-inclusion for.
|
|
1198
|
-
*
|
|
1199
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1200
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1201
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1202
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1203
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1204
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1502
|
+
async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1503
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1205
1504
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1206
1505
|
if (!findResult) {
|
|
1207
1506
|
return undefined;
|
|
1208
1507
|
}
|
|
1209
1508
|
const { index, alreadyPresent } = findResult;
|
|
1210
1509
|
if (alreadyPresent) {
|
|
1211
|
-
|
|
1510
|
+
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1212
1511
|
}
|
|
1213
1512
|
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1214
1513
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1215
1514
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1216
1515
|
}
|
|
1217
1516
|
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1218
|
-
const committedDb = await this
|
|
1517
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1219
1518
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1220
1519
|
if (!lowLeafResult) {
|
|
1221
1520
|
return undefined;
|
|
@@ -1226,7 +1525,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1226
1525
|
}
|
|
1227
1526
|
}
|
|
1228
1527
|
async getPublicStorageAt(referenceBlock, contract, slot) {
|
|
1229
|
-
const committedDb = await this
|
|
1528
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1230
1529
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1231
1530
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1232
1531
|
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
@@ -1235,36 +1534,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1235
1534
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1236
1535
|
return preimage.leaf.value;
|
|
1237
1536
|
}
|
|
1238
|
-
async getBlockHeader(block = 'latest') {
|
|
1239
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1240
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1241
|
-
if (block.equals(initialBlockHash)) {
|
|
1242
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1243
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1244
|
-
}
|
|
1245
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1246
|
-
} else {
|
|
1247
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1248
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1249
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1250
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1251
|
-
}
|
|
1252
|
-
return this.blockSource.getBlockHeader(block);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
/**
|
|
1256
|
-
* Get a block header specified by its archive root.
|
|
1257
|
-
* @param archive - The archive root being requested.
|
|
1258
|
-
* @returns The requested block header.
|
|
1259
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
1260
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1261
|
-
}
|
|
1262
|
-
getBlockData(number) {
|
|
1263
|
-
return this.blockSource.getBlockData(number);
|
|
1264
|
-
}
|
|
1265
|
-
getBlockDataByArchive(archive) {
|
|
1266
|
-
return this.blockSource.getBlockDataByArchive(archive);
|
|
1267
|
-
}
|
|
1268
1537
|
/**
|
|
1269
1538
|
* Simulates the public part of a transaction with the current state.
|
|
1270
1539
|
* @param tx - The transaction to simulate.
|
|
@@ -1305,7 +1574,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1305
1574
|
});
|
|
1306
1575
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1307
1576
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1308
|
-
const [processedTxs, failedTxs, _usedTxs, returns,
|
|
1577
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1309
1578
|
tx
|
|
1310
1579
|
]);
|
|
1311
1580
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -1323,19 +1592,26 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1323
1592
|
}
|
|
1324
1593
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1325
1594
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1326
|
-
const verifier = isSimulation ? undefined : this.
|
|
1595
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1327
1596
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1328
1597
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1329
1598
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1599
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1330
1600
|
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1331
1601
|
timestamp: nextSlotTimestamp,
|
|
1332
1602
|
blockNumber,
|
|
1333
1603
|
l1ChainId: this.l1ChainId,
|
|
1334
1604
|
rollupVersion: this.version,
|
|
1335
|
-
setupAllowList:
|
|
1605
|
+
setupAllowList: [
|
|
1606
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
1607
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
1608
|
+
],
|
|
1336
1609
|
gasFees: await this.getCurrentMinFees(),
|
|
1337
1610
|
skipFeeEnforcement,
|
|
1338
|
-
txsPermitted: !this.config.disableTransactions
|
|
1611
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1612
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1613
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1614
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1339
1615
|
}, this.log.getBindings());
|
|
1340
1616
|
return await validator.validateTx(tx);
|
|
1341
1617
|
}
|
|
@@ -1358,7 +1634,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1358
1634
|
archiver.updateConfig(config);
|
|
1359
1635
|
}
|
|
1360
1636
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1361
|
-
|
|
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
|
+
}
|
|
1362
1649
|
}
|
|
1363
1650
|
this.config = newConfig;
|
|
1364
1651
|
}
|
|
@@ -1418,7 +1705,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1418
1705
|
});
|
|
1419
1706
|
return Promise.resolve();
|
|
1420
1707
|
}
|
|
1421
|
-
async rollbackTo(targetBlock, force) {
|
|
1708
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1422
1709
|
const archiver = this.blockSource;
|
|
1423
1710
|
if (!('rollbackTo' in archiver)) {
|
|
1424
1711
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1446,9 +1733,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1446
1733
|
this.log.error(`Error during rollback`, err);
|
|
1447
1734
|
throw err;
|
|
1448
1735
|
} finally{
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
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
|
+
}
|
|
1452
1743
|
}
|
|
1453
1744
|
}
|
|
1454
1745
|
async pauseSync() {
|
|
@@ -1462,18 +1753,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1462
1753
|
this.blockSource.resume();
|
|
1463
1754
|
return Promise.resolve();
|
|
1464
1755
|
}
|
|
1465
|
-
getSlashPayloads() {
|
|
1466
|
-
if (!this.slasherClient) {
|
|
1467
|
-
throw new Error(`Slasher client not enabled`);
|
|
1468
|
-
}
|
|
1469
|
-
return this.slasherClient.getSlashPayloads();
|
|
1470
|
-
}
|
|
1471
1756
|
getSlashOffenses(round) {
|
|
1472
1757
|
if (!this.slasherClient) {
|
|
1473
1758
|
throw new Error(`Slasher client not enabled`);
|
|
1474
1759
|
}
|
|
1475
1760
|
if (round === 'all') {
|
|
1476
|
-
return this.slasherClient.
|
|
1761
|
+
return this.slasherClient.getOffenses();
|
|
1477
1762
|
} else {
|
|
1478
1763
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1479
1764
|
}
|
|
@@ -1545,6 +1830,33 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1545
1830
|
this.keyStoreManager = newManager;
|
|
1546
1831
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1547
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
|
+
}
|
|
1548
1860
|
#getInitialHeaderHash() {
|
|
1549
1861
|
if (!this.initialHeaderHashPromise) {
|
|
1550
1862
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1555,7 +1867,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1555
1867
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1556
1868
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1557
1869
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1558
|
-
*/ async
|
|
1870
|
+
*/ async getWorldState(block) {
|
|
1559
1871
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1560
1872
|
try {
|
|
1561
1873
|
// Attempt to sync the world state if necessary
|
|
@@ -1567,29 +1879,65 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1567
1879
|
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1568
1880
|
return this.worldStateSynchronizer.getCommitted();
|
|
1569
1881
|
}
|
|
1882
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1883
|
+
let blockNumber;
|
|
1570
1884
|
if (BlockHash.isBlockHash(block)) {
|
|
1571
1885
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1572
1886
|
if (block.equals(initialBlockHash)) {
|
|
1573
|
-
// Block
|
|
1574
|
-
|
|
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.`);
|
|
1575
1913
|
}
|
|
1576
|
-
|
|
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);
|
|
1577
1928
|
if (!header) {
|
|
1578
|
-
throw new Error(`Block hash ${
|
|
1929
|
+
throw new Error(`Block hash ${resolved.hash.toString()} not found.`);
|
|
1579
1930
|
}
|
|
1580
|
-
|
|
1581
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1582
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1931
|
+
return header.getBlockNumber();
|
|
1583
1932
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
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.`);
|
|
1589
1937
|
}
|
|
1590
|
-
|
|
1591
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1938
|
+
return header.getBlockNumber();
|
|
1592
1939
|
}
|
|
1940
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(block)}`);
|
|
1593
1941
|
}
|
|
1594
1942
|
/**
|
|
1595
1943
|
* Ensure we fully sync the world state
|