@aztec/aztec-node 5.0.0-private.20260318 → 5.0.0-rc.1
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 +25 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +112 -0
- package/dest/aztec-node/config.d.ts +14 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -5
- package/dest/aztec-node/public_data_overrides.d.ts +13 -0
- package/dest/aztec-node/public_data_overrides.d.ts.map +1 -0
- package/dest/aztec-node/public_data_overrides.js +21 -0
- package/dest/aztec-node/register_node_rpc_handlers.d.ts +10 -0
- package/dest/aztec-node/register_node_rpc_handlers.d.ts.map +1 -0
- package/dest/aztec-node/register_node_rpc_handlers.js +31 -0
- package/dest/aztec-node/server.d.ts +94 -99
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1082 -479
- package/dest/bin/index.js +14 -9
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/sentinel/config.d.ts +3 -2
- package/dest/sentinel/config.d.ts.map +1 -1
- package/dest/sentinel/config.js +15 -5
- package/dest/sentinel/factory.d.ts +4 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +4 -4
- package/dest/sentinel/sentinel.d.ts +133 -9
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +212 -70
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +25 -17
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +27 -26
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +23 -7
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/register_node_rpc_handlers.ts +29 -0
- package/src/aztec-node/server.ts +1203 -612
- package/src/bin/index.ts +13 -11
- package/src/index.ts +1 -0
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +7 -4
- package/src/sentinel/sentinel.ts +267 -82
- package/src/sentinel/store.ts +26 -18
- package/src/test/index.ts +2 -2
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
function _ts_add_disposable_resource(env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() {
|
|
16
|
+
try {
|
|
17
|
+
inner.call(this);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
return Promise.reject(e);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
env.stack.push({
|
|
23
|
+
value: value,
|
|
24
|
+
dispose: dispose,
|
|
25
|
+
async: async
|
|
26
|
+
});
|
|
27
|
+
} else if (async) {
|
|
28
|
+
env.stack.push({
|
|
29
|
+
async: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function _ts_dispose_resources(env) {
|
|
35
|
+
var _SuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
36
|
+
var e = new Error(message);
|
|
37
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
38
|
+
};
|
|
39
|
+
return (_ts_dispose_resources = function _ts_dispose_resources(env) {
|
|
40
|
+
function fail(e) {
|
|
41
|
+
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
42
|
+
env.hasError = true;
|
|
43
|
+
}
|
|
44
|
+
var r, s = 0;
|
|
45
|
+
function next() {
|
|
46
|
+
while(r = env.stack.pop()){
|
|
47
|
+
try {
|
|
48
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
49
|
+
if (r.dispose) {
|
|
50
|
+
var result = r.dispose.call(r.value);
|
|
51
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
52
|
+
fail(e);
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
} else s |= 1;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
})(env);
|
|
65
|
+
}
|
|
1
66
|
function applyDecs2203RFactory() {
|
|
2
67
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
3
68
|
return function addInitializer(initializer) {
|
|
@@ -371,23 +436,27 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
371
436
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
437
|
}
|
|
373
438
|
var _dec, _initProto;
|
|
374
|
-
import { createArchiver } from '@aztec/archiver';
|
|
375
|
-
import { BBCircuitVerifier,
|
|
439
|
+
import { L1ToL2MessagesNotReadyError, createArchiver } from '@aztec/archiver';
|
|
440
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
441
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
376
442
|
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
377
443
|
import { Blob } from '@aztec/blob-lib';
|
|
378
444
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
379
445
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
380
446
|
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
381
447
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
382
|
-
import {
|
|
448
|
+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
449
|
+
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
383
450
|
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
451
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
385
452
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
386
453
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
387
454
|
import { createLogger } from '@aztec/foundation/log';
|
|
455
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
388
456
|
import { count } from '@aztec/foundation/string';
|
|
389
457
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
390
458
|
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
459
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
391
460
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
392
461
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
393
462
|
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
@@ -395,28 +464,34 @@ import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAll
|
|
|
395
464
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
396
465
|
import { createProverNode } from '@aztec/prover-node';
|
|
397
466
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
398
|
-
import { GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
399
|
-
import {
|
|
400
|
-
import {
|
|
467
|
+
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient } from '@aztec/sequencer-client';
|
|
468
|
+
import { createAutomineSequencer } from '@aztec/sequencer-client/automine';
|
|
469
|
+
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
470
|
+
import { AttestationsBlockWatcher, AttestedInvalidProposalWatcher, BroadcastedInvalidCheckpointProposalWatcher, CheckpointEquivocationWatcher, DataWithholdingWatcher, createSlasher } from '@aztec/slasher';
|
|
471
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
401
472
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
402
473
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
403
|
-
import { BlockHash,
|
|
404
|
-
import {
|
|
474
|
+
import { BlockHash, BlockTag, inspectBlockParameter } from '@aztec/stdlib/block';
|
|
475
|
+
import { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
476
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
477
|
+
import { GasFees, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
405
478
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
406
479
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
407
480
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
408
481
|
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
409
|
-
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
482
|
+
import { InboxLeaf, appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
410
483
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
411
|
-
import {
|
|
484
|
+
import { DroppedTxReceipt, GlobalVariables, MinedTxReceipt, PendingTxReceipt, PublicSimulationOutput, TxStatus } from '@aztec/stdlib/tx';
|
|
412
485
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
413
486
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
414
|
-
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient,
|
|
415
|
-
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
487
|
+
import { FullNodeCheckpointsBuilder as CheckpointsBuilder, FullNodeCheckpointsBuilder, NodeKeystoreAdapter, ValidatorClient, createProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
488
|
+
import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
|
|
416
489
|
import { createPublicClient } from 'viem';
|
|
417
490
|
import { createSentinel } from '../sentinel/factory.js';
|
|
491
|
+
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint, projectProposedToCheckpointResponse } from './block_response_helpers.js';
|
|
418
492
|
import { createKeyStoreForValidator } from './config.js';
|
|
419
493
|
import { NodeMetrics } from './node_metrics.js';
|
|
494
|
+
import { applyPublicDataOverrides } from './public_data_overrides.js';
|
|
420
495
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
421
496
|
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
422
497
|
}));
|
|
@@ -434,19 +509,22 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
434
509
|
proverNode;
|
|
435
510
|
slasherClient;
|
|
436
511
|
validatorsSentinel;
|
|
437
|
-
|
|
512
|
+
stopStartedWatchers;
|
|
438
513
|
l1ChainId;
|
|
439
514
|
version;
|
|
440
515
|
globalVariableBuilder;
|
|
516
|
+
feeProvider;
|
|
441
517
|
epochCache;
|
|
442
518
|
packageVersion;
|
|
443
|
-
|
|
519
|
+
peerProofVerifier;
|
|
520
|
+
rpcProofVerifier;
|
|
444
521
|
telemetry;
|
|
445
522
|
log;
|
|
446
523
|
blobClient;
|
|
447
524
|
validatorClient;
|
|
448
525
|
keyStoreManager;
|
|
449
526
|
debugLogStore;
|
|
527
|
+
automineSequencer;
|
|
450
528
|
static{
|
|
451
529
|
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
452
530
|
[
|
|
@@ -457,11 +535,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
457
535
|
], []));
|
|
458
536
|
}
|
|
459
537
|
metrics;
|
|
460
|
-
initialHeaderHashPromise;
|
|
461
538
|
// Prevent two snapshot operations to happen simultaneously
|
|
462
539
|
isUploadingSnapshot;
|
|
540
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
541
|
+
sequencerPausedMinTxsPerBlock;
|
|
463
542
|
tracer;
|
|
464
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel,
|
|
543
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, stopStartedWatchers, l1ChainId, version, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry = getTelemetryClient(), log = createLogger('node'), blobClient, validatorClient, keyStoreManager, debugLogStore = new NullDebugLogStore(), automineSequencer){
|
|
465
544
|
this.config = config;
|
|
466
545
|
this.p2pClient = p2pClient;
|
|
467
546
|
this.blockSource = blockSource;
|
|
@@ -473,25 +552,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
473
552
|
this.proverNode = proverNode;
|
|
474
553
|
this.slasherClient = slasherClient;
|
|
475
554
|
this.validatorsSentinel = validatorsSentinel;
|
|
476
|
-
this.
|
|
555
|
+
this.stopStartedWatchers = stopStartedWatchers;
|
|
477
556
|
this.l1ChainId = l1ChainId;
|
|
478
557
|
this.version = version;
|
|
479
558
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
559
|
+
this.feeProvider = feeProvider;
|
|
480
560
|
this.epochCache = epochCache;
|
|
481
561
|
this.packageVersion = packageVersion;
|
|
482
|
-
this.
|
|
562
|
+
this.peerProofVerifier = peerProofVerifier;
|
|
563
|
+
this.rpcProofVerifier = rpcProofVerifier;
|
|
483
564
|
this.telemetry = telemetry;
|
|
484
565
|
this.log = log;
|
|
485
566
|
this.blobClient = blobClient;
|
|
486
567
|
this.validatorClient = validatorClient;
|
|
487
568
|
this.keyStoreManager = keyStoreManager;
|
|
488
569
|
this.debugLogStore = debugLogStore;
|
|
489
|
-
this.
|
|
490
|
-
this.isUploadingSnapshot = false;
|
|
570
|
+
this.automineSequencer = automineSequencer;
|
|
571
|
+
this.isUploadingSnapshot = (_initProto(this), false);
|
|
491
572
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
492
573
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
493
574
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
494
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
575
|
+
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
495
576
|
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
496
577
|
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
497
578
|
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
@@ -499,12 +580,261 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
499
580
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
500
581
|
}
|
|
501
582
|
}
|
|
583
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
584
|
+
return this.rpcProofVerifier;
|
|
585
|
+
}
|
|
502
586
|
async getWorldStateSyncStatus() {
|
|
503
587
|
const status = await this.worldStateSynchronizer.status();
|
|
504
588
|
return status.syncSummary;
|
|
505
589
|
}
|
|
506
|
-
|
|
507
|
-
|
|
590
|
+
async getChainTips() {
|
|
591
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
592
|
+
return {
|
|
593
|
+
proposed,
|
|
594
|
+
checkpointed,
|
|
595
|
+
proven,
|
|
596
|
+
finalized
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
getL1Constants() {
|
|
600
|
+
return this.blockSource.getL1Constants();
|
|
601
|
+
}
|
|
602
|
+
getSyncedL2SlotNumber() {
|
|
603
|
+
return this.blockSource.getSyncedL2SlotNumber();
|
|
604
|
+
}
|
|
605
|
+
getSyncedL2EpochNumber() {
|
|
606
|
+
return this.blockSource.getSyncedL2EpochNumber();
|
|
607
|
+
}
|
|
608
|
+
getSyncedL1Timestamp() {
|
|
609
|
+
return this.blockSource.getL1Timestamp();
|
|
610
|
+
}
|
|
611
|
+
getCheckpointsData(query) {
|
|
612
|
+
return this.blockSource.getCheckpointsData(query);
|
|
613
|
+
}
|
|
614
|
+
async getBlockNumber(tip) {
|
|
615
|
+
if (tip === undefined || tip === 'proposed') {
|
|
616
|
+
return this.blockSource.getBlockNumber();
|
|
617
|
+
}
|
|
618
|
+
return await this.blockSource.getBlockNumber({
|
|
619
|
+
tag: tip
|
|
620
|
+
}) ?? BlockNumber.ZERO;
|
|
621
|
+
}
|
|
622
|
+
async getCheckpointNumber(tip) {
|
|
623
|
+
const tips = await this.blockSource.getL2Tips();
|
|
624
|
+
switch(tip){
|
|
625
|
+
case undefined:
|
|
626
|
+
case 'checkpointed':
|
|
627
|
+
return tips.checkpointed.checkpoint.number;
|
|
628
|
+
case 'proposed':
|
|
629
|
+
return tips.proposedCheckpoint.checkpoint.number;
|
|
630
|
+
case 'proven':
|
|
631
|
+
return tips.proven.checkpoint.number;
|
|
632
|
+
case 'finalized':
|
|
633
|
+
return tips.finalized.checkpoint.number;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
isChainTip(value) {
|
|
637
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
641
|
+
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
642
|
+
* lookups are deferred to the underlying block source.
|
|
643
|
+
*/ normalizeBlockParameter(param) {
|
|
644
|
+
if (BlockHash.isBlockHash(param)) {
|
|
645
|
+
return {
|
|
646
|
+
hash: param
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
if (typeof param === 'number') {
|
|
650
|
+
return {
|
|
651
|
+
number: param
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
if (typeof param === 'string') {
|
|
655
|
+
if (this.isBlockTag(param)) {
|
|
656
|
+
return {
|
|
657
|
+
tag: param === 'latest' ? 'proposed' : param
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
661
|
+
}
|
|
662
|
+
if (typeof param === 'object' && param !== null) {
|
|
663
|
+
if ('number' in param) {
|
|
664
|
+
return {
|
|
665
|
+
number: param.number
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
if ('hash' in param) {
|
|
669
|
+
return {
|
|
670
|
+
hash: param.hash
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
if ('archive' in param) {
|
|
674
|
+
return {
|
|
675
|
+
archive: param.archive
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
if ('tag' in param) {
|
|
679
|
+
if (this.isBlockTag(param.tag)) {
|
|
680
|
+
return {
|
|
681
|
+
tag: param.tag
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
688
|
+
}
|
|
689
|
+
isBlockTag(value) {
|
|
690
|
+
return BlockTag.includes(value);
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
694
|
+
*
|
|
695
|
+
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
696
|
+
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
697
|
+
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
698
|
+
* confirmed→proposed lookup against either store.
|
|
699
|
+
*/ async resolveCheckpointParameter(param) {
|
|
700
|
+
if (typeof param === 'number') {
|
|
701
|
+
return {
|
|
702
|
+
number: param
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
if (this.isChainTip(param)) {
|
|
706
|
+
const tips = await this.blockSource.getL2Tips();
|
|
707
|
+
switch(param){
|
|
708
|
+
case 'proposed':
|
|
709
|
+
return {
|
|
710
|
+
number: tips.proposedCheckpoint.checkpoint.number
|
|
711
|
+
};
|
|
712
|
+
case 'checkpointed':
|
|
713
|
+
return {
|
|
714
|
+
number: tips.checkpointed.checkpoint.number
|
|
715
|
+
};
|
|
716
|
+
case 'proven':
|
|
717
|
+
return {
|
|
718
|
+
number: tips.proven.checkpoint.number
|
|
719
|
+
};
|
|
720
|
+
case 'finalized':
|
|
721
|
+
return {
|
|
722
|
+
number: tips.finalized.checkpoint.number
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
if (typeof param === 'object' && param !== null) {
|
|
727
|
+
if ('number' in param) {
|
|
728
|
+
return {
|
|
729
|
+
number: param.number
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
if ('slot' in param) {
|
|
733
|
+
return {
|
|
734
|
+
slot: param.slot
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
739
|
+
}
|
|
740
|
+
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */ async #getCheckpointContext(checkpointNumber) {
|
|
741
|
+
const checkpoint = await this.blockSource.getCheckpointData({
|
|
742
|
+
number: checkpointNumber
|
|
743
|
+
});
|
|
744
|
+
if (!checkpoint) {
|
|
745
|
+
return undefined;
|
|
746
|
+
}
|
|
747
|
+
return {
|
|
748
|
+
l1: checkpoint.l1,
|
|
749
|
+
attestations: checkpoint.attestations
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
async getBlock(param, options = {}) {
|
|
753
|
+
const query = this.normalizeBlockParameter(param);
|
|
754
|
+
const wantTxs = !!options.includeTransactions;
|
|
755
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
756
|
+
if (wantTxs) {
|
|
757
|
+
const block = await this.blockSource.getBlock(query);
|
|
758
|
+
if (!block) {
|
|
759
|
+
return undefined;
|
|
760
|
+
}
|
|
761
|
+
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
762
|
+
return await blockResponseFromL2Block(block, options, ctx);
|
|
763
|
+
}
|
|
764
|
+
const data = await this.blockSource.getBlockData(query);
|
|
765
|
+
if (!data) {
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
769
|
+
return blockResponseFromBlockData(data, options, ctx);
|
|
770
|
+
}
|
|
771
|
+
getBlockData(param) {
|
|
772
|
+
const query = this.normalizeBlockParameter(param);
|
|
773
|
+
return this.blockSource.getBlockData(query);
|
|
774
|
+
}
|
|
775
|
+
async getBlocks(from, limit, options = {}) {
|
|
776
|
+
const wantTxs = !!options.includeTransactions;
|
|
777
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
778
|
+
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
779
|
+
if (wantTxs) {
|
|
780
|
+
const blocks = await this.blockSource.getBlocks({
|
|
781
|
+
from,
|
|
782
|
+
limit,
|
|
783
|
+
onlyCheckpointed
|
|
784
|
+
});
|
|
785
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
786
|
+
return await Promise.all(blocks.map((block)=>blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))));
|
|
787
|
+
}
|
|
788
|
+
const dataItems = await this.blockSource.getBlocksData({
|
|
789
|
+
from,
|
|
790
|
+
limit,
|
|
791
|
+
onlyCheckpointed
|
|
792
|
+
});
|
|
793
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
794
|
+
return await Promise.all(dataItems.map((data)=>blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))));
|
|
795
|
+
}
|
|
796
|
+
/** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */ async #getCheckpointContextsForBlocks(blocks) {
|
|
797
|
+
const unique = Array.from(new Set(blocks.map((b)=>b.checkpointNumber)));
|
|
798
|
+
const entries = await Promise.all(unique.map(async (n)=>[
|
|
799
|
+
n,
|
|
800
|
+
await this.#getCheckpointContext(n)
|
|
801
|
+
]));
|
|
802
|
+
return new Map(entries);
|
|
803
|
+
}
|
|
804
|
+
async getCheckpoint(param, options = {}) {
|
|
805
|
+
const query = await this.resolveCheckpointParameter(param);
|
|
806
|
+
// Try the confirmed store first.
|
|
807
|
+
const confirmed = options.includeBlocks ? await this.blockSource.getCheckpoint(query) : await this.blockSource.getCheckpointData(query);
|
|
808
|
+
if (confirmed) {
|
|
809
|
+
return await (options.includeBlocks ? checkpointResponseFromPublishedCheckpoint(confirmed, options) : checkpointResponseFromCheckpointData(confirmed, options));
|
|
810
|
+
}
|
|
811
|
+
// Fall back to the proposed store.
|
|
812
|
+
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
813
|
+
if (proposed) {
|
|
814
|
+
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
815
|
+
throw new BadRequestError(`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`);
|
|
816
|
+
}
|
|
817
|
+
const blocks = options.includeBlocks ? await this.blockSource.getBlocks({
|
|
818
|
+
from: proposed.startBlock,
|
|
819
|
+
limit: proposed.blockCount
|
|
820
|
+
}) : undefined;
|
|
821
|
+
return await projectProposedToCheckpointResponse(proposed, options, blocks);
|
|
822
|
+
}
|
|
823
|
+
return undefined;
|
|
824
|
+
}
|
|
825
|
+
async getCheckpoints(from, limit, options = {}) {
|
|
826
|
+
if (options.includeBlocks) {
|
|
827
|
+
const checkpoints = await this.blockSource.getCheckpoints({
|
|
828
|
+
from,
|
|
829
|
+
limit
|
|
830
|
+
});
|
|
831
|
+
return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
|
|
832
|
+
}
|
|
833
|
+
const datas = await this.blockSource.getCheckpointsData({
|
|
834
|
+
from,
|
|
835
|
+
limit
|
|
836
|
+
});
|
|
837
|
+
return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
|
|
508
838
|
}
|
|
509
839
|
/**
|
|
510
840
|
* initializes the Aztec Node, wait for component to sync.
|
|
@@ -515,7 +845,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
515
845
|
...inputConfig
|
|
516
846
|
}; // Copy the config so we dont mutate the input object
|
|
517
847
|
const log = deps.logger ?? createLogger('node');
|
|
518
|
-
const packageVersion = getPackageVersion()
|
|
848
|
+
const packageVersion = getPackageVersion();
|
|
519
849
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
520
850
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
521
851
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
@@ -564,16 +894,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
564
894
|
}),
|
|
565
895
|
pollingInterval: config.viemPollingIntervalMS
|
|
566
896
|
});
|
|
567
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
...l1ContractsAddresses
|
|
572
|
-
};
|
|
573
|
-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
574
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
897
|
+
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.registryAddress, config.rollupVersion ?? 'canonical');
|
|
898
|
+
Object.assign(config, l1ContractsAddresses);
|
|
899
|
+
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
900
|
+
const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
575
901
|
rollupContract.getL1GenesisTime(),
|
|
576
902
|
rollupContract.getSlotDuration(),
|
|
903
|
+
rollupContract.getEpochDuration(),
|
|
577
904
|
rollupContract.getVersion(),
|
|
578
905
|
rollupContract.getManaLimit().then(Number)
|
|
579
906
|
]);
|
|
@@ -584,203 +911,356 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
584
911
|
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
585
912
|
// attempt snapshot sync if possible
|
|
586
913
|
await trySnapshotSync(config, log);
|
|
587
|
-
const epochCache = await EpochCache.create(config.
|
|
588
|
-
dateProvider
|
|
589
|
-
});
|
|
590
|
-
const archiver = await createArchiver(config, {
|
|
591
|
-
blobClient,
|
|
592
|
-
epochCache,
|
|
593
|
-
telemetry,
|
|
914
|
+
const epochCache = await EpochCache.create(config.rollupAddress, config, {
|
|
594
915
|
dateProvider
|
|
595
|
-
}, {
|
|
596
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
597
916
|
});
|
|
598
|
-
//
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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,
|
|
640
|
-
blobClient
|
|
917
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
918
|
+
const started = [];
|
|
919
|
+
try {
|
|
920
|
+
config.skipOrphanProposedBlockPruning ||= !!config.useAutomineSequencer;
|
|
921
|
+
AztecNodeService.checkConfigMatchesRollup(config, {
|
|
922
|
+
slotDuration: Number(slotDuration),
|
|
923
|
+
epochDuration: Number(epochDuration)
|
|
641
924
|
});
|
|
642
|
-
//
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
await validatorClient.registerHandlers();
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
653
|
-
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
654
|
-
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
655
|
-
if (!validatorClient) {
|
|
656
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
657
|
-
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
658
|
-
createBlockProposalHandler(config, {
|
|
659
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
660
|
-
worldState: worldStateSynchronizer,
|
|
925
|
+
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
926
|
+
const nativeWs = await createWorldState(config, options.genesis);
|
|
927
|
+
const initialHeader = nativeWs.getInitialHeader();
|
|
928
|
+
const initialBlockHash = await initialHeader.hash();
|
|
929
|
+
const archiver = await createArchiver(config, {
|
|
930
|
+
blobClient,
|
|
661
931
|
epochCache,
|
|
662
|
-
blockSource: archiver,
|
|
663
|
-
l1ToL2MessageSource: archiver,
|
|
664
|
-
p2pClient,
|
|
665
|
-
dateProvider,
|
|
666
|
-
telemetry
|
|
667
|
-
}).register(p2pClient, reexecute);
|
|
668
|
-
}
|
|
669
|
-
// Start world state and wait for it to sync to the archiver.
|
|
670
|
-
await worldStateSynchronizer.start();
|
|
671
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
672
|
-
await p2pClient.start();
|
|
673
|
-
let validatorsSentinel;
|
|
674
|
-
let epochPruneWatcher;
|
|
675
|
-
let attestationsBlockWatcher;
|
|
676
|
-
if (!proverOnly) {
|
|
677
|
-
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
678
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
679
|
-
watchers.push(validatorsSentinel);
|
|
680
|
-
}
|
|
681
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
682
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
683
|
-
watchers.push(epochPruneWatcher);
|
|
684
|
-
}
|
|
685
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
686
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
687
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
688
|
-
watchers.push(attestationsBlockWatcher);
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
// Start p2p-related services once the archiver has completed sync
|
|
692
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
693
|
-
await p2pClient.start();
|
|
694
|
-
await validatorsSentinel?.start();
|
|
695
|
-
await epochPruneWatcher?.start();
|
|
696
|
-
await attestationsBlockWatcher?.start();
|
|
697
|
-
log.info(`All p2p services started`);
|
|
698
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
699
|
-
// Validator enabled, create/start relevant service
|
|
700
|
-
let sequencer;
|
|
701
|
-
let slasherClient;
|
|
702
|
-
if (!config.disableValidator && validatorClient) {
|
|
703
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
704
|
-
// as they are executed when the node is selected as proposer.
|
|
705
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
706
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
707
|
-
await slasherClient.start();
|
|
708
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
709
|
-
...config,
|
|
710
|
-
scope: 'sequencer'
|
|
711
|
-
}, {
|
|
712
932
|
telemetry,
|
|
713
|
-
|
|
714
|
-
dateProvider,
|
|
715
|
-
kzg: Blob.getViemKzgInstance()
|
|
716
|
-
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
717
|
-
...config,
|
|
718
|
-
scope: 'sequencer'
|
|
933
|
+
dateProvider
|
|
719
934
|
}, {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
const
|
|
935
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
936
|
+
}, initialHeader, initialBlockHash);
|
|
937
|
+
started.push(archiver);
|
|
938
|
+
// The synchronizer takes ownership of the native world-state from here
|
|
939
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
940
|
+
started.push(worldStateSynchronizer);
|
|
941
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
942
|
+
let peerProofVerifier;
|
|
943
|
+
let rpcProofVerifier;
|
|
944
|
+
if (useRealVerifiers) {
|
|
945
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
946
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
947
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
948
|
+
} else {
|
|
949
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
950
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
951
|
+
}
|
|
952
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
953
|
+
let debugLogStore;
|
|
954
|
+
if (!config.realProofs) {
|
|
955
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
956
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
957
|
+
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
958
|
+
} else {
|
|
959
|
+
debugLogStore = new NullDebugLogStore();
|
|
960
|
+
}
|
|
961
|
+
const globalVariableBuilderConfig = {
|
|
962
|
+
rollupAddress: config.rollupAddress,
|
|
963
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
964
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
965
|
+
l1GenesisTime,
|
|
966
|
+
slotDuration: Number(slotDuration)
|
|
967
|
+
};
|
|
968
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
969
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
970
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
971
|
+
if (proverOnly) {
|
|
972
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
973
|
+
}
|
|
974
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
975
|
+
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps, initialBlockHash);
|
|
976
|
+
started.push(p2pClient);
|
|
977
|
+
archiver.setCheckpointProposalPresence(p2pClient);
|
|
978
|
+
// We'll accumulate sentinel watchers here
|
|
979
|
+
const watchers = [];
|
|
980
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
981
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
982
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
727
983
|
...config,
|
|
728
984
|
l1GenesisTime,
|
|
729
985
|
slotDuration: Number(slotDuration),
|
|
730
|
-
rollupManaLimit
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
-
|
|
986
|
+
rollupManaLimit,
|
|
987
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
988
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
989
|
+
let validatorClient;
|
|
990
|
+
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
991
|
+
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
992
|
+
if (!config.disableValidator) {
|
|
993
|
+
// Create validator client if required
|
|
994
|
+
validatorClient = await createValidatorClient(config, {
|
|
995
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
996
|
+
worldState: worldStateSynchronizer,
|
|
997
|
+
p2pClient,
|
|
998
|
+
telemetry,
|
|
999
|
+
dateProvider,
|
|
1000
|
+
epochCache,
|
|
1001
|
+
blockSource: archiver,
|
|
1002
|
+
l1ToL2MessageSource: archiver,
|
|
1003
|
+
keyStoreManager,
|
|
1004
|
+
blobClient,
|
|
1005
|
+
reexecutionTracker,
|
|
1006
|
+
slashingProtectionDb: deps.slashingProtectionDb
|
|
1007
|
+
});
|
|
1008
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
1009
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
1010
|
+
// like attestations or auths will fail.
|
|
1011
|
+
if (validatorClient) {
|
|
1012
|
+
watchers.push(validatorClient);
|
|
1013
|
+
const vc = validatorClient;
|
|
1014
|
+
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
1015
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
1016
|
+
if (!options.dontStartSequencer) {
|
|
1017
|
+
await validatorClient.registerHandlers();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
1022
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
1023
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
1024
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
1025
|
+
if (!validatorClient) {
|
|
1026
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
1027
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
1028
|
+
createProposalHandler(config, {
|
|
1029
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
1030
|
+
worldState: worldStateSynchronizer,
|
|
1031
|
+
epochCache,
|
|
1032
|
+
blockSource: archiver,
|
|
1033
|
+
l1ToL2MessageSource: archiver,
|
|
1034
|
+
p2pClient,
|
|
1035
|
+
blobClient,
|
|
1036
|
+
dateProvider,
|
|
1037
|
+
telemetry,
|
|
1038
|
+
reexecutionTracker
|
|
1039
|
+
}).register(p2pClient, reexecute, archiver);
|
|
1040
|
+
}
|
|
1041
|
+
// Start world state and wait for it to sync to the archiver.
|
|
1042
|
+
await worldStateSynchronizer.start();
|
|
1043
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
1044
|
+
await p2pClient.start();
|
|
1045
|
+
let validatorsSentinel;
|
|
1046
|
+
let dataWithholdingWatcher;
|
|
1047
|
+
let attestationsBlockWatcher;
|
|
1048
|
+
let attestedInvalidProposalWatcher;
|
|
1049
|
+
let broadcastedInvalidCheckpointProposalWatcher;
|
|
1050
|
+
let checkpointEquivocationWatcher;
|
|
1051
|
+
if (!proverOnly) {
|
|
1052
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
1053
|
+
if (validatorsSentinel) {
|
|
1054
|
+
watchers.push(validatorsSentinel);
|
|
1055
|
+
}
|
|
1056
|
+
dataWithholdingWatcher = new DataWithholdingWatcher(epochCache, archiver, p2pClient.getTxProvider(), p2pClient, reexecutionTracker, {
|
|
1057
|
+
chainId: config.l1ChainId,
|
|
1058
|
+
rollupAddress: config.rollupAddress
|
|
1059
|
+
}, config);
|
|
1060
|
+
watchers.push(dataWithholdingWatcher);
|
|
1061
|
+
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(p2pClient, archiver, epochCache, config);
|
|
1062
|
+
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
1063
|
+
if (validatorClient) {
|
|
1064
|
+
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(p2pClient, validatorClient, archiver, epochCache, config, {
|
|
1065
|
+
log: log.createChild('attested-invalid-proposal-watcher')
|
|
1066
|
+
});
|
|
1067
|
+
watchers.push(attestedInvalidProposalWatcher);
|
|
1068
|
+
}
|
|
1069
|
+
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
1070
|
+
watchers.push(checkpointEquivocationWatcher);
|
|
1071
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
1072
|
+
watchers.push(attestationsBlockWatcher);
|
|
1073
|
+
}
|
|
1074
|
+
const watchersToStart = compactArray([
|
|
1075
|
+
validatorsSentinel,
|
|
1076
|
+
dataWithholdingWatcher,
|
|
1077
|
+
attestationsBlockWatcher,
|
|
1078
|
+
broadcastedInvalidCheckpointProposalWatcher,
|
|
1079
|
+
attestedInvalidProposalWatcher,
|
|
1080
|
+
checkpointEquivocationWatcher
|
|
1081
|
+
]);
|
|
1082
|
+
const startedWatchers = [];
|
|
1083
|
+
const stopStartedWatchers = async ()=>{
|
|
1084
|
+
for (const watcher of startedWatchers){
|
|
1085
|
+
await tryStop(watcher);
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
// Start p2p-related services once the archiver has completed sync
|
|
1089
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
1090
|
+
for (const watcher of watchersToStart){
|
|
1091
|
+
await watcher.start();
|
|
1092
|
+
startedWatchers.push(watcher);
|
|
1093
|
+
}
|
|
1094
|
+
log.info(`All p2p services started`);
|
|
1095
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
1096
|
+
started.push({
|
|
1097
|
+
stop: stopStartedWatchers
|
|
768
1098
|
});
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1099
|
+
// Validator enabled, create/start relevant service
|
|
1100
|
+
let sequencer;
|
|
1101
|
+
let automineSequencer;
|
|
1102
|
+
let slasherClient;
|
|
1103
|
+
if (!config.disableValidator && validatorClient) {
|
|
1104
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
1105
|
+
// as they are executed when the node is selected as proposer.
|
|
1106
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
1107
|
+
slasherClient = await createSlasher(config, pickL1ContractAddresses(config), getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
1108
|
+
await slasherClient.start();
|
|
1109
|
+
started.push(slasherClient);
|
|
1110
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
1111
|
+
...config,
|
|
1112
|
+
scope: 'sequencer'
|
|
1113
|
+
}, {
|
|
1114
|
+
telemetry,
|
|
1115
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1116
|
+
dateProvider,
|
|
1117
|
+
kzg: Blob.getViemKzgInstance()
|
|
1118
|
+
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
1119
|
+
...config,
|
|
1120
|
+
scope: 'sequencer'
|
|
1121
|
+
}, {
|
|
1122
|
+
telemetry,
|
|
1123
|
+
logger: log.createChild('l1-tx-utils'),
|
|
1124
|
+
dateProvider,
|
|
1125
|
+
kzg: Blob.getViemKzgInstance()
|
|
1126
|
+
});
|
|
1127
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
1128
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
1129
|
+
let funderL1TxUtils;
|
|
1130
|
+
if (fundingSigner) {
|
|
1131
|
+
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
1132
|
+
fundingSigner
|
|
1133
|
+
], {
|
|
1134
|
+
...config,
|
|
1135
|
+
scope: 'sequencer'
|
|
1136
|
+
}, {
|
|
1137
|
+
telemetry,
|
|
1138
|
+
logger: log.createChild('l1-tx-utils:funder'),
|
|
1139
|
+
dateProvider
|
|
1140
|
+
});
|
|
1141
|
+
funderL1TxUtils = funder;
|
|
1142
|
+
}
|
|
1143
|
+
// Create and start the sequencer client
|
|
1144
|
+
const checkpointsBuilder = new CheckpointsBuilder({
|
|
1145
|
+
...config,
|
|
1146
|
+
l1GenesisTime,
|
|
1147
|
+
slotDuration: Number(slotDuration),
|
|
1148
|
+
rollupManaLimit
|
|
1149
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
1150
|
+
if (config.useAutomineSequencer) {
|
|
1151
|
+
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
1152
|
+
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
1153
|
+
automineSequencer = await createAutomineSequencer({
|
|
1154
|
+
config,
|
|
1155
|
+
l1TxUtils,
|
|
1156
|
+
funderL1TxUtils,
|
|
1157
|
+
publicClient,
|
|
1158
|
+
rollupContract,
|
|
1159
|
+
epochCache,
|
|
1160
|
+
blobClient,
|
|
1161
|
+
telemetry,
|
|
1162
|
+
dateProvider,
|
|
1163
|
+
keyStoreManager: keyStoreManager,
|
|
1164
|
+
validatorClient,
|
|
1165
|
+
checkpointsBuilder,
|
|
1166
|
+
globalVariableBuilder,
|
|
1167
|
+
worldStateSynchronizer,
|
|
1168
|
+
archiver,
|
|
1169
|
+
p2pClient,
|
|
1170
|
+
l1Constants: {
|
|
1171
|
+
l1GenesisTime,
|
|
1172
|
+
slotDuration: Number(slotDuration),
|
|
1173
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
1174
|
+
rollupManaLimit
|
|
1175
|
+
},
|
|
1176
|
+
autoSettle: config.automineEnableProveEpoch,
|
|
1177
|
+
log
|
|
1178
|
+
});
|
|
1179
|
+
} else {
|
|
1180
|
+
sequencer = await SequencerClient.new(config, {
|
|
1181
|
+
...deps,
|
|
1182
|
+
epochCache,
|
|
1183
|
+
l1TxUtils,
|
|
1184
|
+
funderL1TxUtils,
|
|
1185
|
+
validatorClient,
|
|
1186
|
+
p2pClient,
|
|
1187
|
+
worldStateSynchronizer,
|
|
1188
|
+
slasherClient,
|
|
1189
|
+
checkpointsBuilder,
|
|
1190
|
+
l2BlockSource: archiver,
|
|
1191
|
+
l1ToL2MessageSource: archiver,
|
|
1192
|
+
telemetry,
|
|
1193
|
+
dateProvider,
|
|
1194
|
+
blobClient,
|
|
1195
|
+
nodeKeyStore: keyStoreManager,
|
|
1196
|
+
globalVariableBuilder
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
774
1199
|
}
|
|
1200
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
1201
|
+
await sequencer.start();
|
|
1202
|
+
started.push(sequencer);
|
|
1203
|
+
log.verbose(`Sequencer started`);
|
|
1204
|
+
} else if (sequencer) {
|
|
1205
|
+
log.warn(`Sequencer created but not started`);
|
|
1206
|
+
}
|
|
1207
|
+
if (!options.dontStartSequencer && automineSequencer) {
|
|
1208
|
+
await automineSequencer.start();
|
|
1209
|
+
started.push({
|
|
1210
|
+
stop: ()=>automineSequencer.stop()
|
|
1211
|
+
});
|
|
1212
|
+
log.verbose(`AutomineSequencer started`);
|
|
1213
|
+
} else if (automineSequencer) {
|
|
1214
|
+
log.warn(`AutomineSequencer created but not started`);
|
|
1215
|
+
}
|
|
1216
|
+
// Create prover node subsystem if enabled
|
|
1217
|
+
let proverNode;
|
|
1218
|
+
if (config.enableProverNode) {
|
|
1219
|
+
proverNode = await createProverNode(config, {
|
|
1220
|
+
...deps.proverNodeDeps,
|
|
1221
|
+
telemetry,
|
|
1222
|
+
dateProvider,
|
|
1223
|
+
archiver,
|
|
1224
|
+
worldStateSynchronizer,
|
|
1225
|
+
p2pClient,
|
|
1226
|
+
epochCache,
|
|
1227
|
+
blobClient,
|
|
1228
|
+
keyStoreManager
|
|
1229
|
+
});
|
|
1230
|
+
if (!options.dontStartProverNode) {
|
|
1231
|
+
await proverNode.start();
|
|
1232
|
+
started.push(proverNode);
|
|
1233
|
+
log.info(`Prover node subsystem started`);
|
|
1234
|
+
} else {
|
|
1235
|
+
log.info(`Prover node subsystem created but not started`);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
const node = new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, proverNode, slasherClient, validatorsSentinel, stopStartedWatchers, ethereumChain.chainInfo.id, config.rollupVersion, globalVariableBuilder, feeProvider, epochCache, packageVersion, peerProofVerifier, rpcProofVerifier, telemetry, log, blobClient, validatorClient, keyStoreManager, debugLogStore, automineSequencer);
|
|
1239
|
+
return node;
|
|
1240
|
+
} catch (err) {
|
|
1241
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1242
|
+
for (const resource of started.reverse()){
|
|
1243
|
+
await tryStop(resource);
|
|
1244
|
+
}
|
|
1245
|
+
throw err;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Verifies the node's configured L1 timing matches the rollup contract it is pointed at, for the fields the
|
|
1250
|
+
* node's own config carries. Each comparison is guarded against an undefined config value, so a config that
|
|
1251
|
+
* does not carry a field is not checked. Throws a single error listing every mismatch. Runs in the shared
|
|
1252
|
+
* startup path for every node role.
|
|
1253
|
+
*/ static checkConfigMatchesRollup(config, rollup) {
|
|
1254
|
+
const mismatches = [];
|
|
1255
|
+
if (config.aztecSlotDuration !== undefined && config.aztecSlotDuration !== rollup.slotDuration) {
|
|
1256
|
+
mismatches.push(`aztecSlotDuration is ${config.aztecSlotDuration} but the rollup reports ${rollup.slotDuration}`);
|
|
1257
|
+
}
|
|
1258
|
+
if (config.aztecEpochDuration !== undefined && config.aztecEpochDuration !== rollup.epochDuration) {
|
|
1259
|
+
mismatches.push(`aztecEpochDuration is ${config.aztecEpochDuration} but the rollup reports ${rollup.epochDuration}`);
|
|
1260
|
+
}
|
|
1261
|
+
if (mismatches.length > 0) {
|
|
1262
|
+
throw new Error(`The node's configured L1 timing does not match the rollup contract it is pointed at: ${mismatches.join('; ')}`);
|
|
775
1263
|
}
|
|
776
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
777
|
-
...config,
|
|
778
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
779
|
-
l1GenesisTime,
|
|
780
|
-
slotDuration: Number(slotDuration)
|
|
781
|
-
});
|
|
782
|
-
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);
|
|
783
|
-
return node;
|
|
784
1264
|
}
|
|
785
1265
|
/**
|
|
786
1266
|
* Returns the sequencer client instance.
|
|
@@ -788,6 +1268,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
788
1268
|
*/ getSequencer() {
|
|
789
1269
|
return this.sequencer;
|
|
790
1270
|
}
|
|
1271
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */ getAutomineSequencer() {
|
|
1272
|
+
return this.automineSequencer;
|
|
1273
|
+
}
|
|
791
1274
|
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
792
1275
|
return this.proverNode;
|
|
793
1276
|
}
|
|
@@ -804,7 +1287,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
804
1287
|
* Method to return the currently deployed L1 contract addresses.
|
|
805
1288
|
* @returns - The currently deployed L1 contract addresses.
|
|
806
1289
|
*/ getL1ContractAddresses() {
|
|
807
|
-
return Promise.resolve(this.config
|
|
1290
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
808
1291
|
}
|
|
809
1292
|
getEncodedEnr() {
|
|
810
1293
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
@@ -822,14 +1305,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
822
1305
|
return Promise.resolve(this.p2pClient.isReady() ?? false);
|
|
823
1306
|
}
|
|
824
1307
|
async getNodeInfo() {
|
|
825
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
1308
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses, l1Constants] = await Promise.all([
|
|
826
1309
|
this.getNodeVersion(),
|
|
827
1310
|
this.getVersion(),
|
|
828
1311
|
this.getChainId(),
|
|
829
1312
|
this.getEncodedEnr(),
|
|
830
1313
|
this.getL1ContractAddresses(),
|
|
831
|
-
this.getProtocolContractAddresses()
|
|
1314
|
+
this.getProtocolContractAddresses(),
|
|
1315
|
+
this.blockSource.getL1Constants()
|
|
832
1316
|
]);
|
|
1317
|
+
// Gas limits a single tx may declare on this network, derived from network-wide constants only (the
|
|
1318
|
+
// timetable's blocks-per-checkpoint and the network-minimum per-block multipliers) — never this node's
|
|
1319
|
+
// local caps or configured multipliers, which can make the node stricter at block-building time but
|
|
1320
|
+
// cannot define what the network accepts for relay. Clients read txsLimits to set fallback gas limits.
|
|
1321
|
+
const maxTxGas = getNetworkTxGasLimits(this.config, l1Constants);
|
|
833
1322
|
const nodeInfo = {
|
|
834
1323
|
nodeVersion,
|
|
835
1324
|
l1ChainId: chainId,
|
|
@@ -837,71 +1326,26 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
837
1326
|
enr,
|
|
838
1327
|
l1ContractAddresses: contractAddresses,
|
|
839
1328
|
protocolContractAddresses: protocolContractAddresses,
|
|
840
|
-
realProofs: !!this.config.realProofs
|
|
1329
|
+
realProofs: !!this.config.realProofs,
|
|
1330
|
+
txsLimits: {
|
|
1331
|
+
gas: {
|
|
1332
|
+
daGas: maxTxGas.daGas,
|
|
1333
|
+
l2Gas: maxTxGas.l2Gas
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
841
1336
|
};
|
|
842
1337
|
return nodeInfo;
|
|
843
1338
|
}
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
847
|
-
* @returns The requested block.
|
|
848
|
-
*/ async getBlock(block) {
|
|
849
|
-
if (BlockHash.isBlockHash(block)) {
|
|
850
|
-
return this.getBlockByHash(block);
|
|
851
|
-
}
|
|
852
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
853
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
854
|
-
return this.buildInitialBlock();
|
|
855
|
-
}
|
|
856
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Get a block specified by its hash.
|
|
860
|
-
* @param blockHash - The block hash being requested.
|
|
861
|
-
* @returns The requested block.
|
|
862
|
-
*/ async getBlockByHash(blockHash) {
|
|
863
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
864
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
865
|
-
return this.buildInitialBlock();
|
|
866
|
-
}
|
|
867
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
868
|
-
}
|
|
869
|
-
buildInitialBlock() {
|
|
870
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
871
|
-
return L2Block.empty(initialHeader);
|
|
1339
|
+
async getCurrentMinFees() {
|
|
1340
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
872
1341
|
}
|
|
873
|
-
/**
|
|
874
|
-
|
|
875
|
-
* @param archive - The archive root being requested.
|
|
876
|
-
* @returns The requested block.
|
|
877
|
-
*/ async getBlockByArchive(archive) {
|
|
878
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
879
|
-
}
|
|
880
|
-
/**
|
|
881
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
882
|
-
* @param from - The start of the range of blocks to return.
|
|
883
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
884
|
-
* @returns The blocks requested.
|
|
885
|
-
*/ async getBlocks(from, limit) {
|
|
886
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
887
|
-
}
|
|
888
|
-
async getCheckpoints(from, limit) {
|
|
889
|
-
return await this.blockSource.getCheckpoints(from, limit) ?? [];
|
|
890
|
-
}
|
|
891
|
-
async getCheckpointedBlocks(from, limit) {
|
|
892
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
893
|
-
}
|
|
894
|
-
getCheckpointsDataForEpoch(epochNumber) {
|
|
895
|
-
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
896
|
-
}
|
|
897
|
-
/**
|
|
898
|
-
* Method to fetch the current min L2 fees.
|
|
899
|
-
* @returns The current min L2 fees.
|
|
900
|
-
*/ async getCurrentMinFees() {
|
|
901
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
1342
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
1343
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
902
1344
|
}
|
|
903
1345
|
async getMaxPriorityFees() {
|
|
904
|
-
for await (const tx of this.p2pClient.iteratePendingTxs(
|
|
1346
|
+
for await (const tx of this.p2pClient.iteratePendingTxs({
|
|
1347
|
+
includeProof: false
|
|
1348
|
+
})){
|
|
905
1349
|
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
906
1350
|
}
|
|
907
1351
|
return GasFees.from({
|
|
@@ -910,21 +1354,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
910
1354
|
});
|
|
911
1355
|
}
|
|
912
1356
|
/**
|
|
913
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
914
|
-
* @returns The block number.
|
|
915
|
-
*/ async getBlockNumber() {
|
|
916
|
-
return await this.blockSource.getBlockNumber();
|
|
917
|
-
}
|
|
918
|
-
async getProvenBlockNumber() {
|
|
919
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
920
|
-
}
|
|
921
|
-
async getCheckpointedBlockNumber() {
|
|
922
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
923
|
-
}
|
|
924
|
-
getCheckpointNumber() {
|
|
925
|
-
return this.blockSource.getCheckpointNumber();
|
|
926
|
-
}
|
|
927
|
-
/**
|
|
928
1357
|
* Method to fetch the version of the package.
|
|
929
1358
|
* @returns The node package version
|
|
930
1359
|
*/ getNodeVersion() {
|
|
@@ -948,51 +1377,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
948
1377
|
getContract(address) {
|
|
949
1378
|
return this.contractDataSource.getContract(address);
|
|
950
1379
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
if (referenceBlock) {
|
|
954
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
955
|
-
if (referenceBlock.equals(initialBlockHash)) {
|
|
956
|
-
upToBlockNumber = BlockNumber(0);
|
|
957
|
-
} else {
|
|
958
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
959
|
-
if (!header) {
|
|
960
|
-
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
961
|
-
}
|
|
962
|
-
upToBlockNumber = header.globalVariables.blockNumber;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
966
|
-
}
|
|
967
|
-
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
968
|
-
let upToBlockNumber;
|
|
969
|
-
if (referenceBlock) {
|
|
970
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
971
|
-
if (referenceBlock.equals(initialBlockHash)) {
|
|
972
|
-
upToBlockNumber = BlockNumber(0);
|
|
973
|
-
} else {
|
|
974
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
975
|
-
if (!header) {
|
|
976
|
-
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
977
|
-
}
|
|
978
|
-
upToBlockNumber = header.globalVariables.blockNumber;
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
1380
|
+
getPrivateLogsByTags(query) {
|
|
1381
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
982
1382
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
* @param filter - The filter to apply to the logs.
|
|
986
|
-
* @returns The requested logs.
|
|
987
|
-
*/ getPublicLogs(filter) {
|
|
988
|
-
return this.logsSource.getPublicLogs(filter);
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Gets contract class logs based on the provided filter.
|
|
992
|
-
* @param filter - The filter to apply to the logs.
|
|
993
|
-
* @returns The requested logs.
|
|
994
|
-
*/ getContractClassLogs(filter) {
|
|
995
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
1383
|
+
getPublicLogsByTags(query) {
|
|
1384
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
996
1385
|
}
|
|
997
1386
|
/**
|
|
998
1387
|
* Method to submit a transaction to the p2p pool.
|
|
@@ -1012,35 +1401,75 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1012
1401
|
});
|
|
1013
1402
|
throw new Error(`Invalid tx: ${reason}`);
|
|
1014
1403
|
}
|
|
1015
|
-
|
|
1404
|
+
try {
|
|
1405
|
+
await this.p2pClient.sendTx(tx);
|
|
1406
|
+
} catch (err) {
|
|
1407
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1408
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
|
|
1409
|
+
txHash
|
|
1410
|
+
});
|
|
1411
|
+
throw err;
|
|
1412
|
+
}
|
|
1016
1413
|
const duration = timer.ms();
|
|
1017
1414
|
this.metrics.receivedTx(duration, true);
|
|
1018
1415
|
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
1019
1416
|
txHash
|
|
1020
1417
|
});
|
|
1021
1418
|
}
|
|
1022
|
-
async getTxReceipt(txHash) {
|
|
1419
|
+
async getTxReceipt(txHash, options) {
|
|
1023
1420
|
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1024
|
-
// as a fallback if we don't find a
|
|
1421
|
+
// as a fallback if we don't find a mined tx effect in the archiver.
|
|
1025
1422
|
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1026
1423
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1027
|
-
// Then get the
|
|
1028
|
-
const
|
|
1424
|
+
// Then get the raw tx effect from the archiver, which tracks every tx in a mined block.
|
|
1425
|
+
const indexed = await this.blockSource.getTxEffect(txHash);
|
|
1029
1426
|
let receipt;
|
|
1030
|
-
if (
|
|
1031
|
-
receipt =
|
|
1427
|
+
if (indexed) {
|
|
1428
|
+
receipt = await this.#assembleMinedReceipt(indexed, options);
|
|
1032
1429
|
} else if (isKnownToPool) {
|
|
1033
1430
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1034
1431
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
1035
1432
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1036
|
-
|
|
1433
|
+
let tx;
|
|
1434
|
+
if (options?.includePendingTx) {
|
|
1435
|
+
// The tx may have left the pool since we checked its status (mined or dropped); in that case we
|
|
1436
|
+
// leave `tx` unset and still return a pending receipt.
|
|
1437
|
+
tx = await this.p2pClient.getTxByHashFromPool(txHash, {
|
|
1438
|
+
includeProof: !!options.includeProof
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
receipt = new PendingTxReceipt(txHash, tx);
|
|
1037
1442
|
} else {
|
|
1038
1443
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1039
|
-
receipt = new
|
|
1444
|
+
receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
|
|
1040
1445
|
}
|
|
1041
1446
|
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1042
1447
|
return receipt;
|
|
1043
1448
|
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Assembles a {@link MinedTxReceipt} from a raw {@link IndexedTxEffect}, deriving the finalization status from the
|
|
1451
|
+
* cached L2 tips and the epoch from the block's slot number.
|
|
1452
|
+
*/ async #assembleMinedReceipt(indexed, options) {
|
|
1453
|
+
const blockNumber = indexed.l2BlockNumber;
|
|
1454
|
+
const [tips, l1Constants] = await Promise.all([
|
|
1455
|
+
this.blockSource.getL2Tips(),
|
|
1456
|
+
this.blockSource.getL1Constants()
|
|
1457
|
+
]);
|
|
1458
|
+
const status = this.#deriveMinedStatus(blockNumber, tips);
|
|
1459
|
+
const epochNumber = getEpochAtSlot(indexed.slotNumber, l1Constants);
|
|
1460
|
+
return new MinedTxReceipt(indexed.data.txHash, status, MinedTxReceipt.executionResultFromRevertCode(indexed.data.revertCode), indexed.data.transactionFee.toBigInt(), indexed.l2BlockHash, blockNumber, indexed.slotNumber, indexed.txIndexInBlock, epochNumber, options?.includeTxEffect ? indexed.data : undefined, /*debugLogs=*/ undefined);
|
|
1461
|
+
}
|
|
1462
|
+
#deriveMinedStatus(blockNumber, tips) {
|
|
1463
|
+
if (blockNumber <= tips.finalized.block.number) {
|
|
1464
|
+
return TxStatus.FINALIZED;
|
|
1465
|
+
} else if (blockNumber <= tips.proven.block.number) {
|
|
1466
|
+
return TxStatus.PROVEN;
|
|
1467
|
+
} else if (blockNumber <= tips.checkpointed.block.number) {
|
|
1468
|
+
return TxStatus.CHECKPOINTED;
|
|
1469
|
+
} else {
|
|
1470
|
+
return TxStatus.PROPOSED;
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1044
1473
|
getTxEffect(txHash) {
|
|
1045
1474
|
return this.blockSource.getTxEffect(txHash);
|
|
1046
1475
|
}
|
|
@@ -1048,11 +1477,14 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1048
1477
|
* Method to stop the aztec node.
|
|
1049
1478
|
*/ async stop() {
|
|
1050
1479
|
this.log.info(`Stopping Aztec Node`);
|
|
1051
|
-
await
|
|
1052
|
-
await tryStop(this.epochPruneWatcher);
|
|
1480
|
+
await this.stopStartedWatchers();
|
|
1053
1481
|
await tryStop(this.slasherClient);
|
|
1054
|
-
await
|
|
1482
|
+
await Promise.all([
|
|
1483
|
+
tryStop(this.peerProofVerifier),
|
|
1484
|
+
tryStop(this.rpcProofVerifier)
|
|
1485
|
+
]);
|
|
1055
1486
|
await tryStop(this.sequencer);
|
|
1487
|
+
await tryStop(this.automineSequencer);
|
|
1056
1488
|
await tryStop(this.proverNode);
|
|
1057
1489
|
await tryStop(this.p2pClient);
|
|
1058
1490
|
await tryStop(this.worldStateSynchronizer);
|
|
@@ -1072,25 +1504,43 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1072
1504
|
* @param limit - The number of items to returns
|
|
1073
1505
|
* @param after - The last known pending tx. Used for pagination
|
|
1074
1506
|
* @returns - The pending txs.
|
|
1075
|
-
*/ getPendingTxs(limit, after) {
|
|
1076
|
-
return this.p2pClient.getPendingTxs(limit, after);
|
|
1507
|
+
*/ getPendingTxs(limit, after, options) {
|
|
1508
|
+
return this.p2pClient.getPendingTxs(limit, after, options);
|
|
1077
1509
|
}
|
|
1078
1510
|
getPendingTxCount() {
|
|
1079
1511
|
return this.p2pClient.getPendingTxCount();
|
|
1080
1512
|
}
|
|
1513
|
+
getPeers(includePending) {
|
|
1514
|
+
return this.p2pClient.getPeers(includePending);
|
|
1515
|
+
}
|
|
1516
|
+
getCheckpointAttestationsForSlot(slot, proposalPayloadHash) {
|
|
1517
|
+
return this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
1518
|
+
}
|
|
1519
|
+
getProposalsForSlot(slot) {
|
|
1520
|
+
return this.p2pClient.getProposalsForSlot(slot);
|
|
1521
|
+
}
|
|
1081
1522
|
/**
|
|
1082
|
-
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
1523
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain. The tx's proof is only loaded and returned
|
|
1524
|
+
* when `includeProof` is set.
|
|
1083
1525
|
* @param txHash - The transaction hash to return.
|
|
1526
|
+
* @param options - Options for the returned tx (eg whether to include its proof).
|
|
1084
1527
|
* @returns - The tx if it exists.
|
|
1085
|
-
*/ getTxByHash(txHash) {
|
|
1086
|
-
return
|
|
1528
|
+
*/ getTxByHash(txHash, options) {
|
|
1529
|
+
return this.p2pClient.getTxByHashFromPool(txHash, {
|
|
1530
|
+
includeProof: !!options?.includeProof
|
|
1531
|
+
});
|
|
1087
1532
|
}
|
|
1088
1533
|
/**
|
|
1089
|
-
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
1534
|
+
* Method to retrieve txs from the mempool or unfinalized chain. The txs' proofs are only loaded and returned when
|
|
1535
|
+
* `includeProof` is set.
|
|
1090
1536
|
* @param txHash - The transaction hash to return.
|
|
1537
|
+
* @param options - Options for the returned txs (eg whether to include their proofs).
|
|
1091
1538
|
* @returns - The txs if it exists.
|
|
1092
|
-
*/ async getTxsByHash(txHashes) {
|
|
1093
|
-
|
|
1539
|
+
*/ async getTxsByHash(txHashes, options) {
|
|
1540
|
+
const txs = await this.p2pClient.getTxsByHashFromPool(txHashes, {
|
|
1541
|
+
includeProof: !!options?.includeProof
|
|
1542
|
+
});
|
|
1543
|
+
return compactArray(txs);
|
|
1094
1544
|
}
|
|
1095
1545
|
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1096
1546
|
const committedDb = await this.getWorldState(referenceBlock);
|
|
@@ -1134,19 +1584,27 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1134
1584
|
if (blockNumber === undefined) {
|
|
1135
1585
|
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1136
1586
|
}
|
|
1137
|
-
const
|
|
1138
|
-
if (
|
|
1587
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1588
|
+
if (l2BlockHash === undefined) {
|
|
1139
1589
|
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1140
1590
|
}
|
|
1141
1591
|
return {
|
|
1142
1592
|
l2BlockNumber: blockNumber,
|
|
1143
|
-
l2BlockHash
|
|
1593
|
+
l2BlockHash,
|
|
1144
1594
|
data: index
|
|
1145
1595
|
};
|
|
1146
1596
|
});
|
|
1147
1597
|
}
|
|
1148
1598
|
async getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
1149
|
-
|
|
1599
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1600
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1601
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1602
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1603
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1604
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1605
|
+
return undefined;
|
|
1606
|
+
}
|
|
1607
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1150
1608
|
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1151
1609
|
blockHash
|
|
1152
1610
|
]);
|
|
@@ -1175,25 +1633,28 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1175
1633
|
}
|
|
1176
1634
|
async getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
1177
1635
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1178
|
-
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
1182
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
1183
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
1184
|
-
*/ async isL1ToL2MessageSynced(l1ToL2Message) {
|
|
1185
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1186
|
-
return messageIndex !== undefined;
|
|
1636
|
+
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1187
1637
|
}
|
|
1188
1638
|
/**
|
|
1189
1639
|
* Returns all the L2 to L1 messages in an epoch.
|
|
1640
|
+
*
|
|
1641
|
+
* @deprecated Use {@link getL2ToL1MembershipWitness} to get an L2-to-L1 message witness directly.
|
|
1642
|
+
*
|
|
1190
1643
|
* @param epoch - The epoch at which to get the data.
|
|
1191
1644
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1192
1645
|
*/ async getL2ToL1Messages(epoch) {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1646
|
+
const blocks = await this.blockSource.getBlocks({
|
|
1647
|
+
epoch,
|
|
1648
|
+
onlyCheckpointed: true
|
|
1649
|
+
});
|
|
1650
|
+
const blocksInCheckpoints = chunkBy(blocks, (block)=>block.header.globalVariables.slotNumber);
|
|
1651
|
+
return blocksInCheckpoints.map((slotBlocks)=>slotBlocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1652
|
+
}
|
|
1653
|
+
/**
|
|
1654
|
+
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
1655
|
+
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
1656
|
+
*/ getL2ToL1MembershipWitness(txHash, message, messageIndexInTx) {
|
|
1657
|
+
return this.blockSource.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1197
1658
|
}
|
|
1198
1659
|
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1199
1660
|
const db = await this.getWorldState(referenceBlock);
|
|
@@ -1245,64 +1706,88 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1245
1706
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1246
1707
|
return preimage.leaf.value;
|
|
1247
1708
|
}
|
|
1248
|
-
async getBlockHeader(block = 'latest') {
|
|
1249
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1250
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1251
|
-
if (block.equals(initialBlockHash)) {
|
|
1252
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1253
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1254
|
-
}
|
|
1255
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1256
|
-
} else {
|
|
1257
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1258
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1259
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1260
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1261
|
-
}
|
|
1262
|
-
return this.blockSource.getBlockHeader(block);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* Get a block header specified by its archive root.
|
|
1267
|
-
* @param archive - The archive root being requested.
|
|
1268
|
-
* @returns The requested block header.
|
|
1269
|
-
*/ async getBlockHeaderByArchive(archive) {
|
|
1270
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1271
|
-
}
|
|
1272
|
-
getBlockData(number) {
|
|
1273
|
-
return this.blockSource.getBlockData(number);
|
|
1274
|
-
}
|
|
1275
|
-
getBlockDataByArchive(archive) {
|
|
1276
|
-
return this.blockSource.getBlockDataByArchive(archive);
|
|
1277
|
-
}
|
|
1278
1709
|
/**
|
|
1279
1710
|
* Simulates the public part of a transaction with the current state.
|
|
1280
1711
|
* @param tx - The transaction to simulate.
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
const
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
}
|
|
1289
|
-
const txHash = tx.getTxHash();
|
|
1290
|
-
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1291
|
-
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1292
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1293
|
-
const coinbase = EthAddress.ZERO;
|
|
1294
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1295
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1296
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1297
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1298
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1299
|
-
txHash,
|
|
1300
|
-
blockNumber
|
|
1301
|
-
});
|
|
1302
|
-
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1303
|
-
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1304
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1712
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
1713
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1714
|
+
**/ async simulatePublicCalls(tx, skipFeeEnforcement = false, overrides) {
|
|
1715
|
+
const env = {
|
|
1716
|
+
stack: [],
|
|
1717
|
+
error: void 0,
|
|
1718
|
+
hasError: false
|
|
1719
|
+
};
|
|
1305
1720
|
try {
|
|
1721
|
+
// Check total gas limit for simulation
|
|
1722
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1723
|
+
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
1724
|
+
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1725
|
+
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1726
|
+
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1727
|
+
}
|
|
1728
|
+
const txHash = tx.getTxHash();
|
|
1729
|
+
const l2Tips = await this.blockSource.getL2Tips();
|
|
1730
|
+
const latestBlockNumber = l2Tips.proposed.number;
|
|
1731
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1732
|
+
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1733
|
+
const coinbase = EthAddress.ZERO;
|
|
1734
|
+
const feeRecipient = AztecAddress.ZERO;
|
|
1735
|
+
// Define the slot for simulation as the max of the next L1 timestamp slot, the slot after the proposed
|
|
1736
|
+
// checkpoint, and the latest proposed block's slot.
|
|
1737
|
+
const proposedCheckpointBlockData = await this.blockSource.getBlockData({
|
|
1738
|
+
number: l2Tips.proposedCheckpoint.block.number
|
|
1739
|
+
});
|
|
1740
|
+
const proposedCheckpointSlot = proposedCheckpointBlockData?.header.getSlot();
|
|
1741
|
+
let slotAfterProposedCheckpoint;
|
|
1742
|
+
if (proposedCheckpointSlot !== undefined) {
|
|
1743
|
+
slotAfterProposedCheckpoint = SlotNumber.fromBigInt(BigInt(proposedCheckpointSlot) + 1n);
|
|
1744
|
+
}
|
|
1745
|
+
let latestProposedBlockSlot;
|
|
1746
|
+
if (l2Tips.proposed.number > l2Tips.proposedCheckpoint.block.number) {
|
|
1747
|
+
latestProposedBlockSlot = (await this.blockSource.getBlockData({
|
|
1748
|
+
number: l2Tips.proposed.number
|
|
1749
|
+
}))?.header.getSlot();
|
|
1750
|
+
}
|
|
1751
|
+
const slotFromNextL1Timestamp = this.epochCache.getEpochAndSlotInNextL1Slot().slot;
|
|
1752
|
+
const targetSlot = SlotNumber(Math.max(...compactArray([
|
|
1753
|
+
slotFromNextL1Timestamp,
|
|
1754
|
+
slotAfterProposedCheckpoint,
|
|
1755
|
+
latestProposedBlockSlot
|
|
1756
|
+
])));
|
|
1757
|
+
const checkpointGlobalVariables = await this.globalVariableBuilder.buildCheckpointGlobalVariables(coinbase, feeRecipient, targetSlot);
|
|
1758
|
+
const newGlobalVariables = GlobalVariables.from({
|
|
1759
|
+
blockNumber,
|
|
1760
|
+
...checkpointGlobalVariables
|
|
1761
|
+
});
|
|
1762
|
+
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1763
|
+
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1764
|
+
globalVariables: newGlobalVariables.toInspect(),
|
|
1765
|
+
txHash,
|
|
1766
|
+
blockNumber
|
|
1767
|
+
});
|
|
1768
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1769
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1770
|
+
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1771
|
+
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1772
|
+
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1773
|
+
// which means the next block would be the first block of the next checkpoint.
|
|
1774
|
+
const targetCheckpoint = CheckpointNumber((l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1);
|
|
1775
|
+
const nextCheckpointMessages = l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number ? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch((err)=>{
|
|
1776
|
+
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1777
|
+
this.log.warn(`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`);
|
|
1778
|
+
} else {
|
|
1779
|
+
this.log.error(`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`, err);
|
|
1780
|
+
}
|
|
1781
|
+
return undefined;
|
|
1782
|
+
}) : undefined;
|
|
1783
|
+
const merkleTreeFork = _ts_add_disposable_resource(env, await this.worldStateSynchronizer.fork(latestBlockNumber), true);
|
|
1784
|
+
if (nextCheckpointMessages !== undefined) {
|
|
1785
|
+
this.log.debug(`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`, {
|
|
1786
|
+
checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1
|
|
1787
|
+
});
|
|
1788
|
+
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1789
|
+
}
|
|
1790
|
+
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
1306
1791
|
const config = PublicSimulatorConfig.from({
|
|
1307
1792
|
skipFeeEnforcement,
|
|
1308
1793
|
collectDebugLogs: true,
|
|
@@ -1313,7 +1798,11 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1313
1798
|
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1314
1799
|
})
|
|
1315
1800
|
});
|
|
1316
|
-
const
|
|
1801
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1802
|
+
if (overrides?.contracts) {
|
|
1803
|
+
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance })=>instance));
|
|
1804
|
+
}
|
|
1805
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
1317
1806
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1318
1807
|
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1319
1808
|
tx
|
|
@@ -1327,17 +1816,24 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1327
1816
|
}
|
|
1328
1817
|
const [processedTx] = processedTxs;
|
|
1329
1818
|
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1819
|
+
} catch (e) {
|
|
1820
|
+
env.error = e;
|
|
1821
|
+
env.hasError = true;
|
|
1330
1822
|
} finally{
|
|
1331
|
-
|
|
1823
|
+
const result = _ts_dispose_resources(env);
|
|
1824
|
+
if (result) await result;
|
|
1332
1825
|
}
|
|
1333
1826
|
}
|
|
1334
1827
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1335
1828
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1336
|
-
const verifier = isSimulation ? undefined : this.
|
|
1829
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1337
1830
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1338
1831
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1339
1832
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1340
1833
|
const l1Constants = await this.blockSource.getL1Constants();
|
|
1834
|
+
// Enforce the same network admission limit the node advertises in getNodeInfo (network-wide, not this
|
|
1835
|
+
// node's local caps), so a tx the wallet sized against txsLimits is not rejected here.
|
|
1836
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1341
1837
|
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1342
1838
|
timestamp: nextSlotTimestamp,
|
|
1343
1839
|
blockNumber,
|
|
@@ -1349,10 +1845,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1349
1845
|
],
|
|
1350
1846
|
gasFees: await this.getCurrentMinFees(),
|
|
1351
1847
|
skipFeeEnforcement,
|
|
1848
|
+
isSimulation,
|
|
1352
1849
|
txsPermitted: !this.config.disableTransactions,
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
1850
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
1851
|
+
maxTxDAGas: networkTxGasLimits.daGas
|
|
1356
1852
|
}, this.log.getBindings());
|
|
1357
1853
|
return await validator.validateTx(tx);
|
|
1358
1854
|
}
|
|
@@ -1366,7 +1862,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1366
1862
|
...this.config,
|
|
1367
1863
|
...config
|
|
1368
1864
|
};
|
|
1369
|
-
|
|
1865
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
1866
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
1867
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
1868
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
1869
|
+
// pauseSequencer() still considers it paused.
|
|
1870
|
+
const sequencerUpdate = {
|
|
1871
|
+
...config
|
|
1872
|
+
};
|
|
1873
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
1874
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
1875
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
1876
|
+
}
|
|
1877
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
1878
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
1370
1879
|
this.slasherClient?.updateConfig(config);
|
|
1371
1880
|
this.validatorsSentinel?.updateConfig(config);
|
|
1372
1881
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1375,7 +1884,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1375
1884
|
archiver.updateConfig(config);
|
|
1376
1885
|
}
|
|
1377
1886
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1378
|
-
|
|
1887
|
+
await Promise.all([
|
|
1888
|
+
tryStop(this.peerProofVerifier),
|
|
1889
|
+
tryStop(this.rpcProofVerifier)
|
|
1890
|
+
]);
|
|
1891
|
+
if (newConfig.realProofs) {
|
|
1892
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1893
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1894
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1895
|
+
} else {
|
|
1896
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1897
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1898
|
+
}
|
|
1379
1899
|
}
|
|
1380
1900
|
this.config = newConfig;
|
|
1381
1901
|
}
|
|
@@ -1384,7 +1904,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1384
1904
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1385
1905
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1386
1906
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1387
|
-
multiCallEntrypoint:
|
|
1907
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS
|
|
1388
1908
|
});
|
|
1389
1909
|
}
|
|
1390
1910
|
registerContractFunctionSignatures(signatures) {
|
|
@@ -1435,7 +1955,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1435
1955
|
});
|
|
1436
1956
|
return Promise.resolve();
|
|
1437
1957
|
}
|
|
1438
|
-
async rollbackTo(targetBlock, force) {
|
|
1958
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1439
1959
|
const archiver = this.blockSource;
|
|
1440
1960
|
if (!('rollbackTo' in archiver)) {
|
|
1441
1961
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1463,9 +1983,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1463
1983
|
this.log.error(`Error during rollback`, err);
|
|
1464
1984
|
throw err;
|
|
1465
1985
|
} finally{
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1986
|
+
if (resumeSync) {
|
|
1987
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1988
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1989
|
+
archiver.resume();
|
|
1990
|
+
} else {
|
|
1991
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1992
|
+
}
|
|
1469
1993
|
}
|
|
1470
1994
|
}
|
|
1471
1995
|
async pauseSync() {
|
|
@@ -1479,18 +2003,51 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1479
2003
|
this.blockSource.resume();
|
|
1480
2004
|
return Promise.resolve();
|
|
1481
2005
|
}
|
|
1482
|
-
|
|
1483
|
-
if (
|
|
1484
|
-
|
|
2006
|
+
pauseSequencer() {
|
|
2007
|
+
if (this.automineSequencer) {
|
|
2008
|
+
this.automineSequencer.pause();
|
|
2009
|
+
return Promise.resolve();
|
|
1485
2010
|
}
|
|
1486
|
-
|
|
2011
|
+
if (this.sequencer) {
|
|
2012
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
2013
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
2014
|
+
this.sequencer.updateConfig({
|
|
2015
|
+
minTxsPerBlock: Number.MAX_SAFE_INTEGER
|
|
2016
|
+
});
|
|
2017
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
2018
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
return Promise.resolve();
|
|
2022
|
+
}
|
|
2023
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
2024
|
+
}
|
|
2025
|
+
resumeSequencer() {
|
|
2026
|
+
if (this.automineSequencer) {
|
|
2027
|
+
this.automineSequencer.resume();
|
|
2028
|
+
return Promise.resolve();
|
|
2029
|
+
}
|
|
2030
|
+
if (this.sequencer) {
|
|
2031
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
2032
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
2033
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
2034
|
+
this.sequencer.updateConfig({
|
|
2035
|
+
minTxsPerBlock: restored
|
|
2036
|
+
});
|
|
2037
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, {
|
|
2038
|
+
minTxsPerBlock: restored
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
return Promise.resolve();
|
|
2042
|
+
}
|
|
2043
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1487
2044
|
}
|
|
1488
2045
|
getSlashOffenses(round) {
|
|
1489
2046
|
if (!this.slasherClient) {
|
|
1490
2047
|
throw new Error(`Slasher client not enabled`);
|
|
1491
2048
|
}
|
|
1492
2049
|
if (round === 'all') {
|
|
1493
|
-
return this.slasherClient.
|
|
2050
|
+
return this.slasherClient.getOffenses();
|
|
1494
2051
|
} else {
|
|
1495
2052
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1496
2053
|
}
|
|
@@ -1562,64 +2119,110 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1562
2119
|
this.keyStoreManager = newManager;
|
|
1563
2120
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1564
2121
|
}
|
|
1565
|
-
|
|
1566
|
-
if (
|
|
1567
|
-
|
|
2122
|
+
async mineBlock() {
|
|
2123
|
+
if (this.automineSequencer) {
|
|
2124
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
if (!this.sequencer) {
|
|
2128
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
2129
|
+
}
|
|
2130
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
2131
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
2132
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
2133
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
2134
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
2135
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
2136
|
+
this.sequencer.updateConfig({
|
|
2137
|
+
minTxsPerBlock: 0
|
|
2138
|
+
});
|
|
2139
|
+
try {
|
|
2140
|
+
// Trigger the sequencer to produce a block immediately
|
|
2141
|
+
void this.sequencer.trigger();
|
|
2142
|
+
// Wait for the new L2 block to appear
|
|
2143
|
+
await retryUntil(async ()=>{
|
|
2144
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
2145
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
2146
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
2147
|
+
} finally{
|
|
2148
|
+
this.sequencer.updateConfig({
|
|
2149
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
async prove(upToCheckpoint) {
|
|
2154
|
+
if (!this.automineSequencer) {
|
|
2155
|
+
throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
|
|
1568
2156
|
}
|
|
1569
|
-
return this.
|
|
2157
|
+
return await this.automineSequencer.prove(upToCheckpoint);
|
|
1570
2158
|
}
|
|
1571
2159
|
/**
|
|
1572
2160
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1573
2161
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1574
2162
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1575
2163
|
*/ async getWorldState(block) {
|
|
2164
|
+
const query = this.normalizeBlockParameter(block);
|
|
2165
|
+
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
2166
|
+
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
2167
|
+
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
2168
|
+
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
2169
|
+
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
2170
|
+
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
2171
|
+
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
2172
|
+
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
1576
2173
|
let blockSyncedTo = BlockNumber.ZERO;
|
|
1577
2174
|
try {
|
|
1578
2175
|
// Attempt to sync the world state if necessary
|
|
1579
|
-
blockSyncedTo = await this.#syncWorldState();
|
|
2176
|
+
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
1580
2177
|
} catch (err) {
|
|
1581
2178
|
this.log.error(`Error getting world state: ${err}`);
|
|
1582
2179
|
}
|
|
1583
|
-
if (
|
|
1584
|
-
this.log.debug(`Using committed db for block
|
|
2180
|
+
if ('tag' in query && query.tag === 'proposed') {
|
|
2181
|
+
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
1585
2182
|
return this.worldStateSynchronizer.getCommitted();
|
|
1586
2183
|
}
|
|
1587
|
-
|
|
1588
|
-
let blockNumber;
|
|
1589
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1590
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1591
|
-
if (block.equals(initialBlockHash)) {
|
|
1592
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1593
|
-
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1594
|
-
}
|
|
1595
|
-
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1596
|
-
if (!header) {
|
|
1597
|
-
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.`);
|
|
1598
|
-
}
|
|
1599
|
-
blockNumber = header.getBlockNumber();
|
|
1600
|
-
} else {
|
|
1601
|
-
blockNumber = block;
|
|
1602
|
-
}
|
|
2184
|
+
const blockNumber = anchorBlockNumber ?? await this.resolveBlockNumber(query);
|
|
1603
2185
|
// Check it's within world state sync range
|
|
1604
2186
|
if (blockNumber > blockSyncedTo) {
|
|
1605
|
-
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
2187
|
+
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1606
2188
|
}
|
|
1607
2189
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1608
2190
|
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1609
|
-
// Double-check world-state synced to the same block hash as was requested
|
|
1610
|
-
|
|
2191
|
+
// Double-check world-state synced to the same block hash as was requested.
|
|
2192
|
+
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2193
|
+
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2194
|
+
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2195
|
+
// the archiver when it resolves the hash query to block number 0.
|
|
2196
|
+
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
1611
2197
|
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1612
|
-
if (!blockHash || !
|
|
1613
|
-
throw new Error(`Block hash ${
|
|
2198
|
+
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
2199
|
+
throw new Error(`Block hash ${requestedHash.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${this.blockSource.getGenesisBlockHash().toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
1614
2200
|
}
|
|
1615
2201
|
}
|
|
1616
2202
|
return snapshot;
|
|
1617
2203
|
}
|
|
2204
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */ async resolveBlockNumber(block) {
|
|
2205
|
+
const query = this.normalizeBlockParameter(block);
|
|
2206
|
+
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
2207
|
+
if (blockNumber === undefined) {
|
|
2208
|
+
if ('hash' in query) {
|
|
2209
|
+
throw new Error(`Block hash ${query.hash.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`);
|
|
2210
|
+
}
|
|
2211
|
+
if ('archive' in query) {
|
|
2212
|
+
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
2213
|
+
}
|
|
2214
|
+
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
2215
|
+
}
|
|
2216
|
+
return blockNumber;
|
|
2217
|
+
}
|
|
1618
2218
|
/**
|
|
1619
|
-
* Ensure
|
|
2219
|
+
* Ensure the world state is synced.
|
|
2220
|
+
* @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
|
|
2221
|
+
* @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
|
|
2222
|
+
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
1620
2223
|
* @returns A promise that fulfils once the world state is synced
|
|
1621
|
-
*/ async #syncWorldState() {
|
|
1622
|
-
const
|
|
1623
|
-
return await this.worldStateSynchronizer.syncImmediate(
|
|
2224
|
+
*/ async #syncWorldState(targetBlockNumber, blockHash) {
|
|
2225
|
+
const target = targetBlockNumber ?? await this.blockSource.getBlockNumber();
|
|
2226
|
+
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1624
2227
|
}
|
|
1625
2228
|
}
|