@aztec/aztec-node 0.0.1-commit.2f68f620 → 0.0.1-commit.3100065
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/config.d.ts +10 -1
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts +90 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
- package/dest/aztec-node/node_public_calls_simulator.js +346 -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 +89 -64
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +222 -1131
- package/dest/bin/index.js +15 -10
- package/dest/factory.d.ts +33 -0
- package/dest/factory.d.ts.map +1 -0
- package/dest/factory.js +509 -0
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -0
- package/dest/modules/block_parameter.d.ts +25 -0
- package/dest/modules/block_parameter.d.ts.map +1 -0
- package/dest/modules/block_parameter.js +100 -0
- package/dest/modules/node_block_provider.d.ts +19 -0
- package/dest/modules/node_block_provider.d.ts.map +1 -0
- package/dest/modules/node_block_provider.js +112 -0
- package/dest/modules/node_tx_receipt.d.ts +24 -0
- package/dest/modules/node_tx_receipt.d.ts.map +1 -0
- package/dest/modules/node_tx_receipt.js +70 -0
- package/dest/modules/node_world_state_queries.d.ts +65 -0
- package/dest/modules/node_world_state_queries.d.ts.map +1 -0
- package/dest/modules/node_world_state_queries.js +272 -0
- package/dest/sentinel/factory.d.ts +3 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +8 -1
- package/dest/sentinel/sentinel.d.ts +21 -21
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +27 -47
- package/package.json +28 -27
- package/src/aztec-node/config.ts +19 -0
- package/src/aztec-node/node_public_calls_simulator.ts +383 -0
- package/src/aztec-node/register_node_rpc_handlers.ts +29 -0
- package/src/aztec-node/server.ts +307 -1315
- package/src/bin/index.ts +19 -12
- package/src/factory.ts +673 -0
- package/src/index.ts +2 -0
- package/src/modules/block_parameter.ts +93 -0
- package/src/modules/node_block_provider.ts +149 -0
- package/src/modules/node_tx_receipt.ts +115 -0
- package/src/modules/node_world_state_queries.ts +374 -0
- package/src/sentinel/README.md +3 -3
- package/src/sentinel/factory.ts +15 -3
- package/src/sentinel/sentinel.ts +34 -72
|
@@ -1,68 +1,3 @@
|
|
|
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
|
-
}
|
|
66
1
|
function applyDecs2203RFactory() {
|
|
67
2
|
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
68
3
|
return function addInitializer(initializer) {
|
|
@@ -436,68 +371,59 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
436
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
437
372
|
}
|
|
438
373
|
var _dec, _initProto;
|
|
439
|
-
import { L1ToL2MessagesNotReadyError, createArchiver } from '@aztec/archiver';
|
|
440
374
|
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
441
375
|
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
442
|
-
import { createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
443
|
-
import { Blob } from '@aztec/blob-lib';
|
|
444
|
-
import { EpochCache } from '@aztec/epoch-cache';
|
|
445
|
-
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
446
|
-
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
447
|
-
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
448
376
|
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
449
|
-
import { BlockNumber
|
|
450
|
-
import {
|
|
451
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
377
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
378
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
452
379
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
453
380
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
454
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
455
382
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
456
383
|
import { count } from '@aztec/foundation/string';
|
|
457
|
-
import {
|
|
458
|
-
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
459
|
-
import { isErrorClass } from '@aztec/foundation/types';
|
|
384
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
460
385
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
461
|
-
import {
|
|
462
|
-
import {
|
|
463
|
-
import { createP2PClient, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
386
|
+
import { uploadSnapshot } from '@aztec/node-lib/actions';
|
|
387
|
+
import { createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
464
388
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
465
|
-
import { createProverNode } from '@aztec/prover-node';
|
|
466
|
-
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
467
|
-
import { FeeProviderImpl, GlobalVariableBuilder, SequencerClient, createAutomineSequencer } from '@aztec/sequencer-client';
|
|
468
|
-
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
469
|
-
import { AttestationsBlockWatcher, AttestedInvalidProposalWatcher, BroadcastedInvalidCheckpointProposalWatcher, CheckpointEquivocationWatcher, DataWithholdingWatcher, createSlasher } from '@aztec/slasher';
|
|
470
389
|
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
471
|
-
import {
|
|
472
|
-
import {
|
|
473
|
-
import { BlockHash, BlockTag, inspectBlockParameter } from '@aztec/stdlib/block';
|
|
474
|
-
import { CheckpointReexecutionTracker } from '@aztec/stdlib/checkpoint';
|
|
475
|
-
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
476
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
477
|
-
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
390
|
+
import { inspectBlockParameter } from '@aztec/stdlib/block';
|
|
391
|
+
import { GasFees, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
478
392
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
479
393
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
480
|
-
import {
|
|
481
|
-
import { InboxLeaf, appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
482
|
-
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
483
|
-
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
484
|
-
import { DroppedTxReceipt, MinedTxReceipt, PendingTxReceipt, PublicSimulationOutput, TxStatus } from '@aztec/stdlib/tx';
|
|
485
|
-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
394
|
+
import { NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
486
395
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
487
|
-
import {
|
|
488
|
-
import {
|
|
489
|
-
import {
|
|
490
|
-
import {
|
|
491
|
-
import { blockResponseFromBlockData, blockResponseFromL2Block, checkpointResponseFromCheckpointData, checkpointResponseFromPublishedCheckpoint, projectProposedToCheckpointResponse } from './block_response_helpers.js';
|
|
492
|
-
import { createKeyStoreForValidator } from './config.js';
|
|
396
|
+
import { NodeKeystoreAdapter, ValidatorClient } from '@aztec/validator-client';
|
|
397
|
+
import { NodeBlockProvider } from '../modules/node_block_provider.js';
|
|
398
|
+
import { NodeTxReceiptBuilder } from '../modules/node_tx_receipt.js';
|
|
399
|
+
import { NodeWorldStateQueries } from '../modules/node_world_state_queries.js';
|
|
493
400
|
import { NodeMetrics } from './node_metrics.js';
|
|
494
|
-
import {
|
|
401
|
+
import { NodePublicCallsSimulator } from './node_public_calls_simulator.js';
|
|
495
402
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
496
403
|
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
497
404
|
}));
|
|
498
405
|
/**
|
|
499
406
|
* The aztec node.
|
|
500
407
|
*/ export class AztecNodeService {
|
|
408
|
+
static{
|
|
409
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
410
|
+
[
|
|
411
|
+
_dec,
|
|
412
|
+
2,
|
|
413
|
+
"simulatePublicCalls"
|
|
414
|
+
]
|
|
415
|
+
], []));
|
|
416
|
+
}
|
|
417
|
+
metrics;
|
|
418
|
+
// Prevent two snapshot operations to happen simultaneously
|
|
419
|
+
isUploadingSnapshot = (_initProto(this), false);
|
|
420
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
421
|
+
sequencerPausedMinTxsPerBlock;
|
|
422
|
+
nodePublicCallsSimulator;
|
|
423
|
+
worldStateQueries;
|
|
424
|
+
blockProvider;
|
|
425
|
+
txReceiptBuilder;
|
|
426
|
+
tracer;
|
|
501
427
|
config;
|
|
502
428
|
p2pClient;
|
|
503
429
|
blockSource;
|
|
@@ -513,6 +439,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
513
439
|
l1ChainId;
|
|
514
440
|
version;
|
|
515
441
|
globalVariableBuilder;
|
|
442
|
+
rollupContract;
|
|
516
443
|
feeProvider;
|
|
517
444
|
epochCache;
|
|
518
445
|
packageVersion;
|
|
@@ -525,58 +452,73 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
525
452
|
keyStoreManager;
|
|
526
453
|
debugLogStore;
|
|
527
454
|
automineSequencer;
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
this.
|
|
545
|
-
this.
|
|
546
|
-
this.
|
|
547
|
-
this.
|
|
548
|
-
this.
|
|
549
|
-
this.
|
|
550
|
-
this.
|
|
551
|
-
this.
|
|
552
|
-
this.
|
|
553
|
-
this.
|
|
554
|
-
this.
|
|
555
|
-
this.
|
|
556
|
-
this.
|
|
557
|
-
this.
|
|
558
|
-
this.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
this.
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
455
|
+
constructor(deps){
|
|
456
|
+
this.config = deps.config;
|
|
457
|
+
this.p2pClient = deps.p2pClient;
|
|
458
|
+
this.blockSource = deps.blockSource;
|
|
459
|
+
this.logsSource = deps.logsSource;
|
|
460
|
+
this.contractDataSource = deps.contractDataSource;
|
|
461
|
+
this.l1ToL2MessageSource = deps.l1ToL2MessageSource;
|
|
462
|
+
this.worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
463
|
+
this.sequencer = deps.sequencer;
|
|
464
|
+
this.proverNode = deps.proverNode;
|
|
465
|
+
this.slasherClient = deps.slasherClient;
|
|
466
|
+
this.validatorsSentinel = deps.validatorsSentinel;
|
|
467
|
+
this.stopStartedWatchers = deps.stopStartedWatchers;
|
|
468
|
+
this.l1ChainId = deps.l1ChainId;
|
|
469
|
+
this.version = deps.version;
|
|
470
|
+
this.globalVariableBuilder = deps.globalVariableBuilder;
|
|
471
|
+
this.rollupContract = deps.rollupContract;
|
|
472
|
+
this.feeProvider = deps.feeProvider;
|
|
473
|
+
this.epochCache = deps.epochCache;
|
|
474
|
+
this.packageVersion = deps.packageVersion;
|
|
475
|
+
this.peerProofVerifier = deps.peerProofVerifier;
|
|
476
|
+
this.rpcProofVerifier = deps.rpcProofVerifier;
|
|
477
|
+
this.telemetry = deps.telemetry ?? getTelemetryClient();
|
|
478
|
+
this.log = deps.log ?? createLogger('node');
|
|
479
|
+
this.blobClient = deps.blobClient;
|
|
480
|
+
this.validatorClient = deps.validatorClient;
|
|
481
|
+
this.keyStoreManager = deps.keyStoreManager;
|
|
482
|
+
this.debugLogStore = deps.debugLogStore ?? new NullDebugLogStore();
|
|
483
|
+
this.automineSequencer = deps.automineSequencer;
|
|
484
|
+
this.metrics = new NodeMetrics(this.telemetry, 'AztecNodeService');
|
|
485
|
+
this.tracer = this.telemetry.getTracer('AztecNodeService');
|
|
486
|
+
// The node never represents a proposer's payout addresses, so the simulator zeroes coinbase and
|
|
487
|
+
// fee recipient. The signature context only needs chain id + rollup address (see signature_utils).
|
|
488
|
+
this.nodePublicCallsSimulator = new NodePublicCallsSimulator({
|
|
489
|
+
blockSource: this.blockSource,
|
|
490
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
491
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
492
|
+
contractDataSource: this.contractDataSource,
|
|
493
|
+
globalVariableBuilder: this.globalVariableBuilder,
|
|
494
|
+
rollupContract: this.rollupContract,
|
|
495
|
+
epochCache: this.epochCache,
|
|
496
|
+
signatureContext: {
|
|
497
|
+
chainId: this.l1ChainId,
|
|
498
|
+
rollupAddress: this.config.rollupAddress
|
|
499
|
+
},
|
|
500
|
+
config: this.config,
|
|
501
|
+
telemetry: this.telemetry,
|
|
502
|
+
log: this.log.createChild('public-calls-simulator')
|
|
503
|
+
});
|
|
504
|
+
this.worldStateQueries = new NodeWorldStateQueries({
|
|
505
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
506
|
+
blockSource: this.blockSource,
|
|
507
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
508
|
+
log: this.log.createChild('world-state-queries')
|
|
509
|
+
});
|
|
510
|
+
this.blockProvider = new NodeBlockProvider(this.blockSource);
|
|
511
|
+
this.txReceiptBuilder = new NodeTxReceiptBuilder({
|
|
512
|
+
p2pClient: this.p2pClient,
|
|
513
|
+
blockSource: this.blockSource,
|
|
514
|
+
debugLogStore: this.debugLogStore
|
|
515
|
+
});
|
|
574
516
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
575
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
576
|
-
// A defensive check that protects us against introducing a bug in the complex
|
|
517
|
+
this.log.info(`Aztec Node started on chain 0x${this.l1ChainId.toString(16)}`, pickL1ContractAddresses(this.config));
|
|
518
|
+
// A defensive check that protects us against introducing a bug in the complex node creation flow. We must
|
|
577
519
|
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
578
520
|
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
579
|
-
if (debugLogStore.isEnabled && config.realProofs) {
|
|
521
|
+
if (this.debugLogStore.isEnabled && this.config.realProofs) {
|
|
580
522
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
581
523
|
}
|
|
582
524
|
}
|
|
@@ -587,14 +529,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
587
529
|
const status = await this.worldStateSynchronizer.status();
|
|
588
530
|
return status.syncSummary;
|
|
589
531
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
532
|
+
getChainTips() {
|
|
533
|
+
return this.blockSource.getL2Tips();
|
|
534
|
+
}
|
|
535
|
+
getL1Constants() {
|
|
536
|
+
return this.blockSource.getL1Constants();
|
|
537
|
+
}
|
|
538
|
+
getSyncedL2SlotNumber() {
|
|
539
|
+
return this.blockSource.getSyncedL2SlotNumber();
|
|
540
|
+
}
|
|
541
|
+
getSyncedL2EpochNumber() {
|
|
542
|
+
return this.blockSource.getSyncedL2EpochNumber();
|
|
543
|
+
}
|
|
544
|
+
getSyncedL1Timestamp() {
|
|
545
|
+
return this.blockSource.getL1Timestamp();
|
|
598
546
|
}
|
|
599
547
|
getCheckpointsData(query) {
|
|
600
548
|
return this.blockSource.getCheckpointsData(query);
|
|
@@ -613,623 +561,26 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
613
561
|
case undefined:
|
|
614
562
|
case 'checkpointed':
|
|
615
563
|
return tips.checkpointed.checkpoint.number;
|
|
616
|
-
case 'proposed':
|
|
617
|
-
return tips.proposedCheckpoint.checkpoint.number;
|
|
618
564
|
case 'proven':
|
|
619
565
|
return tips.proven.checkpoint.number;
|
|
620
566
|
case 'finalized':
|
|
621
567
|
return tips.finalized.checkpoint.number;
|
|
622
568
|
}
|
|
623
569
|
}
|
|
624
|
-
|
|
625
|
-
return
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
629
|
-
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
630
|
-
* lookups are deferred to the underlying block source.
|
|
631
|
-
*/ normalizeBlockParameter(param) {
|
|
632
|
-
if (BlockHash.isBlockHash(param)) {
|
|
633
|
-
return {
|
|
634
|
-
hash: param
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
if (typeof param === 'number') {
|
|
638
|
-
return {
|
|
639
|
-
number: param
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
if (typeof param === 'string') {
|
|
643
|
-
if (this.isBlockTag(param)) {
|
|
644
|
-
return {
|
|
645
|
-
tag: param === 'latest' ? 'proposed' : param
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
649
|
-
}
|
|
650
|
-
if (typeof param === 'object' && param !== null) {
|
|
651
|
-
if ('number' in param) {
|
|
652
|
-
return {
|
|
653
|
-
number: param.number
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
if ('hash' in param) {
|
|
657
|
-
return {
|
|
658
|
-
hash: param.hash
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
if ('archive' in param) {
|
|
662
|
-
return {
|
|
663
|
-
archive: param.archive
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
if ('tag' in param) {
|
|
667
|
-
if (this.isBlockTag(param.tag)) {
|
|
668
|
-
return {
|
|
669
|
-
tag: param.tag
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
676
|
-
}
|
|
677
|
-
isBlockTag(value) {
|
|
678
|
-
return BlockTag.includes(value);
|
|
679
|
-
}
|
|
680
|
-
/**
|
|
681
|
-
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
682
|
-
*
|
|
683
|
-
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
684
|
-
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
685
|
-
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
686
|
-
* confirmed→proposed lookup against either store.
|
|
687
|
-
*/ async resolveCheckpointParameter(param) {
|
|
688
|
-
if (typeof param === 'number') {
|
|
689
|
-
return {
|
|
690
|
-
number: param
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
if (this.isChainTip(param)) {
|
|
694
|
-
const tips = await this.blockSource.getL2Tips();
|
|
695
|
-
switch(param){
|
|
696
|
-
case 'proposed':
|
|
697
|
-
return {
|
|
698
|
-
number: tips.proposedCheckpoint.checkpoint.number
|
|
699
|
-
};
|
|
700
|
-
case 'checkpointed':
|
|
701
|
-
return {
|
|
702
|
-
number: tips.checkpointed.checkpoint.number
|
|
703
|
-
};
|
|
704
|
-
case 'proven':
|
|
705
|
-
return {
|
|
706
|
-
number: tips.proven.checkpoint.number
|
|
707
|
-
};
|
|
708
|
-
case 'finalized':
|
|
709
|
-
return {
|
|
710
|
-
number: tips.finalized.checkpoint.number
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
if (typeof param === 'object' && param !== null) {
|
|
715
|
-
if ('number' in param) {
|
|
716
|
-
return {
|
|
717
|
-
number: param.number
|
|
718
|
-
};
|
|
719
|
-
}
|
|
720
|
-
if ('slot' in param) {
|
|
721
|
-
return {
|
|
722
|
-
slot: param.slot
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
727
|
-
}
|
|
728
|
-
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */ async #getCheckpointContext(checkpointNumber) {
|
|
729
|
-
const checkpoint = await this.blockSource.getCheckpointData({
|
|
730
|
-
number: checkpointNumber
|
|
731
|
-
});
|
|
732
|
-
if (!checkpoint) {
|
|
733
|
-
return undefined;
|
|
734
|
-
}
|
|
735
|
-
return {
|
|
736
|
-
l1: checkpoint.l1,
|
|
737
|
-
attestations: checkpoint.attestations
|
|
738
|
-
};
|
|
739
|
-
}
|
|
740
|
-
async getBlock(param, options = {}) {
|
|
741
|
-
const query = this.normalizeBlockParameter(param);
|
|
742
|
-
const wantTxs = !!options.includeTransactions;
|
|
743
|
-
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
744
|
-
if (wantTxs) {
|
|
745
|
-
const block = await this.blockSource.getBlock(query);
|
|
746
|
-
if (!block) {
|
|
747
|
-
return undefined;
|
|
748
|
-
}
|
|
749
|
-
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
750
|
-
return await blockResponseFromL2Block(block, options, ctx);
|
|
751
|
-
}
|
|
752
|
-
const data = await this.blockSource.getBlockData(query);
|
|
753
|
-
if (!data) {
|
|
754
|
-
return undefined;
|
|
755
|
-
}
|
|
756
|
-
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
757
|
-
return blockResponseFromBlockData(data, options, ctx);
|
|
570
|
+
getBlock(param, options = {}) {
|
|
571
|
+
return this.blockProvider.getBlock(param, options);
|
|
758
572
|
}
|
|
759
573
|
getBlockData(param) {
|
|
760
|
-
|
|
761
|
-
return this.blockSource.getBlockData(query);
|
|
762
|
-
}
|
|
763
|
-
async getBlocks(from, limit, options = {}) {
|
|
764
|
-
const wantTxs = !!options.includeTransactions;
|
|
765
|
-
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
766
|
-
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
767
|
-
if (wantTxs) {
|
|
768
|
-
const blocks = await this.blockSource.getBlocks({
|
|
769
|
-
from,
|
|
770
|
-
limit,
|
|
771
|
-
onlyCheckpointed
|
|
772
|
-
});
|
|
773
|
-
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
774
|
-
return await Promise.all(blocks.map((block)=>blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))));
|
|
775
|
-
}
|
|
776
|
-
const dataItems = await this.blockSource.getBlocksData({
|
|
777
|
-
from,
|
|
778
|
-
limit,
|
|
779
|
-
onlyCheckpointed
|
|
780
|
-
});
|
|
781
|
-
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
782
|
-
return await Promise.all(dataItems.map((data)=>blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))));
|
|
783
|
-
}
|
|
784
|
-
/** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */ async #getCheckpointContextsForBlocks(blocks) {
|
|
785
|
-
const unique = Array.from(new Set(blocks.map((b)=>b.checkpointNumber)));
|
|
786
|
-
const entries = await Promise.all(unique.map(async (n)=>[
|
|
787
|
-
n,
|
|
788
|
-
await this.#getCheckpointContext(n)
|
|
789
|
-
]));
|
|
790
|
-
return new Map(entries);
|
|
791
|
-
}
|
|
792
|
-
async getCheckpoint(param, options = {}) {
|
|
793
|
-
const query = await this.resolveCheckpointParameter(param);
|
|
794
|
-
// Try the confirmed store first.
|
|
795
|
-
const confirmed = options.includeBlocks ? await this.blockSource.getCheckpoint(query) : await this.blockSource.getCheckpointData(query);
|
|
796
|
-
if (confirmed) {
|
|
797
|
-
return await (options.includeBlocks ? checkpointResponseFromPublishedCheckpoint(confirmed, options) : checkpointResponseFromCheckpointData(confirmed, options));
|
|
798
|
-
}
|
|
799
|
-
// Fall back to the proposed store.
|
|
800
|
-
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
801
|
-
if (proposed) {
|
|
802
|
-
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
803
|
-
throw new BadRequestError(`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`);
|
|
804
|
-
}
|
|
805
|
-
const blocks = options.includeBlocks ? await this.blockSource.getBlocks({
|
|
806
|
-
from: proposed.startBlock,
|
|
807
|
-
limit: proposed.blockCount
|
|
808
|
-
}) : undefined;
|
|
809
|
-
return await projectProposedToCheckpointResponse(proposed, options, blocks);
|
|
810
|
-
}
|
|
811
|
-
return undefined;
|
|
574
|
+
return this.blockProvider.getBlockData(param);
|
|
812
575
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const checkpoints = await this.blockSource.getCheckpoints({
|
|
816
|
-
from,
|
|
817
|
-
limit
|
|
818
|
-
});
|
|
819
|
-
return await Promise.all(checkpoints.map((cp)=>checkpointResponseFromPublishedCheckpoint(cp, options)));
|
|
820
|
-
}
|
|
821
|
-
const datas = await this.blockSource.getCheckpointsData({
|
|
822
|
-
from,
|
|
823
|
-
limit
|
|
824
|
-
});
|
|
825
|
-
return datas.map((d)=>checkpointResponseFromCheckpointData(d, options));
|
|
576
|
+
getBlocks(from, limit, options = {}) {
|
|
577
|
+
return this.blockProvider.getBlocks(from, limit, options);
|
|
826
578
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
const config = {
|
|
833
|
-
...inputConfig
|
|
834
|
-
}; // Copy the config so we dont mutate the input object
|
|
835
|
-
const log = deps.logger ?? createLogger('node');
|
|
836
|
-
const packageVersion = getPackageVersion();
|
|
837
|
-
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
838
|
-
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
839
|
-
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
840
|
-
// Build a key store from file if given or from environment otherwise.
|
|
841
|
-
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
842
|
-
let keyStoreManager;
|
|
843
|
-
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
844
|
-
if (keyStoreProvided) {
|
|
845
|
-
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
846
|
-
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
847
|
-
} else {
|
|
848
|
-
const rawKeyStores = [];
|
|
849
|
-
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
850
|
-
if (validatorKeyStore) {
|
|
851
|
-
rawKeyStores.push(validatorKeyStore);
|
|
852
|
-
}
|
|
853
|
-
if (config.enableProverNode) {
|
|
854
|
-
const proverKeyStore = createKeyStoreForProver(config);
|
|
855
|
-
if (proverKeyStore) {
|
|
856
|
-
rawKeyStores.push(proverKeyStore);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (rawKeyStores.length > 0) {
|
|
860
|
-
keyStoreManager = new KeystoreManager(rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores));
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
await keyStoreManager?.validateSigners();
|
|
864
|
-
// If we are a validator, verify our configuration before doing too much more.
|
|
865
|
-
if (!config.disableValidator) {
|
|
866
|
-
if (keyStoreManager === undefined) {
|
|
867
|
-
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
868
|
-
}
|
|
869
|
-
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
870
|
-
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
871
|
-
}
|
|
872
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
873
|
-
}
|
|
874
|
-
// validate that the actual chain id matches that specified in configuration
|
|
875
|
-
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
876
|
-
throw new Error(`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`);
|
|
877
|
-
}
|
|
878
|
-
const publicClient = createPublicClient({
|
|
879
|
-
chain: ethereumChain.chainInfo,
|
|
880
|
-
transport: makeL1HttpTransport(config.l1RpcUrls, {
|
|
881
|
-
timeout: config.l1HttpTimeoutMS
|
|
882
|
-
}),
|
|
883
|
-
pollingInterval: config.viemPollingIntervalMS
|
|
884
|
-
});
|
|
885
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.registryAddress, config.rollupVersion ?? 'canonical');
|
|
886
|
-
Object.assign(config, l1ContractsAddresses);
|
|
887
|
-
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
888
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
889
|
-
rollupContract.getL1GenesisTime(),
|
|
890
|
-
rollupContract.getSlotDuration(),
|
|
891
|
-
rollupContract.getVersion(),
|
|
892
|
-
rollupContract.getManaLimit().then(Number)
|
|
893
|
-
]);
|
|
894
|
-
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
895
|
-
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
896
|
-
log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
|
|
897
|
-
}
|
|
898
|
-
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
899
|
-
// attempt snapshot sync if possible
|
|
900
|
-
await trySnapshotSync(config, log);
|
|
901
|
-
const epochCache = await EpochCache.create(config.rollupAddress, config, {
|
|
902
|
-
dateProvider
|
|
903
|
-
});
|
|
904
|
-
// Track started resources so we can clean up on partial failure during node creation.
|
|
905
|
-
const started = [];
|
|
906
|
-
try {
|
|
907
|
-
// Default the orphan-prune grace window from the block build duration when unset, so the archiver
|
|
908
|
-
// waits roughly one build slot for a proposed checkpoint to arrive before pruning a block-only tip.
|
|
909
|
-
config.orphanProposedBlockPruneGraceSeconds ??= config.blockDurationMs !== undefined ? Math.ceil(config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
910
|
-
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
911
|
-
const nativeWs = await createWorldState(config, options.genesis);
|
|
912
|
-
const initialHeader = nativeWs.getInitialHeader();
|
|
913
|
-
const initialBlockHash = await initialHeader.hash();
|
|
914
|
-
const archiver = await createArchiver(config, {
|
|
915
|
-
blobClient,
|
|
916
|
-
epochCache,
|
|
917
|
-
telemetry,
|
|
918
|
-
dateProvider
|
|
919
|
-
}, {
|
|
920
|
-
blockUntilSync: !config.skipArchiverInitialSync,
|
|
921
|
-
// The non-pipelined automine sequencer publishes each checkpoint in-slot, so it never
|
|
922
|
-
// leaves orphan proposed blocks; pruning would race its local push. See pruneOrphanProposedBlocks.
|
|
923
|
-
enableOrphanProposedBlockPruning: !config.useAutomineSequencer
|
|
924
|
-
}, initialHeader, initialBlockHash);
|
|
925
|
-
started.push(archiver);
|
|
926
|
-
// The synchronizer takes ownership of the native world-state from here
|
|
927
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
928
|
-
started.push(worldStateSynchronizer);
|
|
929
|
-
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
930
|
-
let peerProofVerifier;
|
|
931
|
-
let rpcProofVerifier;
|
|
932
|
-
if (useRealVerifiers) {
|
|
933
|
-
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
934
|
-
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
935
|
-
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
936
|
-
} else {
|
|
937
|
-
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
938
|
-
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
939
|
-
}
|
|
940
|
-
started.push(peerProofVerifier, rpcProofVerifier);
|
|
941
|
-
let debugLogStore;
|
|
942
|
-
if (!config.realProofs) {
|
|
943
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
944
|
-
debugLogStore = new InMemoryDebugLogStore();
|
|
945
|
-
log.info('Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served');
|
|
946
|
-
} else {
|
|
947
|
-
debugLogStore = new NullDebugLogStore();
|
|
948
|
-
}
|
|
949
|
-
const globalVariableBuilderConfig = {
|
|
950
|
-
rollupAddress: config.rollupAddress,
|
|
951
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
952
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
953
|
-
l1GenesisTime,
|
|
954
|
-
slotDuration: Number(slotDuration)
|
|
955
|
-
};
|
|
956
|
-
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
957
|
-
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
958
|
-
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
959
|
-
if (proverOnly) {
|
|
960
|
-
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
961
|
-
}
|
|
962
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
963
|
-
const p2pClient = await createP2PClient(config, archiver, peerProofVerifier, worldStateSynchronizer, epochCache, feeProvider, packageVersion, dateProvider, telemetry, deps.p2pClientDeps, initialBlockHash);
|
|
964
|
-
started.push(p2pClient);
|
|
965
|
-
// We'll accumulate sentinel watchers here
|
|
966
|
-
const watchers = [];
|
|
967
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
968
|
-
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
969
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
970
|
-
...config,
|
|
971
|
-
l1GenesisTime,
|
|
972
|
-
slotDuration: Number(slotDuration),
|
|
973
|
-
rollupManaLimit,
|
|
974
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint
|
|
975
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
976
|
-
let validatorClient;
|
|
977
|
-
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
978
|
-
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
979
|
-
if (!config.disableValidator) {
|
|
980
|
-
// Create validator client if required
|
|
981
|
-
validatorClient = await createValidatorClient(config, {
|
|
982
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
983
|
-
worldState: worldStateSynchronizer,
|
|
984
|
-
p2pClient,
|
|
985
|
-
telemetry,
|
|
986
|
-
dateProvider,
|
|
987
|
-
epochCache,
|
|
988
|
-
blockSource: archiver,
|
|
989
|
-
l1ToL2MessageSource: archiver,
|
|
990
|
-
keyStoreManager,
|
|
991
|
-
blobClient,
|
|
992
|
-
reexecutionTracker,
|
|
993
|
-
slashingProtectionDb: deps.slashingProtectionDb
|
|
994
|
-
});
|
|
995
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
996
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
997
|
-
// like attestations or auths will fail.
|
|
998
|
-
if (validatorClient) {
|
|
999
|
-
watchers.push(validatorClient);
|
|
1000
|
-
const vc = validatorClient;
|
|
1001
|
-
const getValidatorAddresses = ()=>vc.getValidatorAddresses().map((a)=>a.toString());
|
|
1002
|
-
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
1003
|
-
if (!options.dontStartSequencer) {
|
|
1004
|
-
await validatorClient.registerHandlers();
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
1009
|
-
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
1010
|
-
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
1011
|
-
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
1012
|
-
if (!validatorClient) {
|
|
1013
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
1014
|
-
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
1015
|
-
createProposalHandler(config, {
|
|
1016
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
1017
|
-
worldState: worldStateSynchronizer,
|
|
1018
|
-
epochCache,
|
|
1019
|
-
blockSource: archiver,
|
|
1020
|
-
l1ToL2MessageSource: archiver,
|
|
1021
|
-
p2pClient,
|
|
1022
|
-
blobClient,
|
|
1023
|
-
dateProvider,
|
|
1024
|
-
telemetry,
|
|
1025
|
-
reexecutionTracker
|
|
1026
|
-
}).register(p2pClient, reexecute, archiver);
|
|
1027
|
-
}
|
|
1028
|
-
// Start world state and wait for it to sync to the archiver.
|
|
1029
|
-
await worldStateSynchronizer.start();
|
|
1030
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
1031
|
-
await p2pClient.start();
|
|
1032
|
-
let validatorsSentinel;
|
|
1033
|
-
let dataWithholdingWatcher;
|
|
1034
|
-
let attestationsBlockWatcher;
|
|
1035
|
-
let attestedInvalidProposalWatcher;
|
|
1036
|
-
let broadcastedInvalidCheckpointProposalWatcher;
|
|
1037
|
-
let checkpointEquivocationWatcher;
|
|
1038
|
-
if (!proverOnly) {
|
|
1039
|
-
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
1040
|
-
if (validatorsSentinel) {
|
|
1041
|
-
watchers.push(validatorsSentinel);
|
|
1042
|
-
}
|
|
1043
|
-
dataWithholdingWatcher = new DataWithholdingWatcher(epochCache, archiver, p2pClient.getTxProvider(), p2pClient, reexecutionTracker, {
|
|
1044
|
-
chainId: config.l1ChainId,
|
|
1045
|
-
rollupAddress: config.rollupAddress
|
|
1046
|
-
}, config);
|
|
1047
|
-
watchers.push(dataWithholdingWatcher);
|
|
1048
|
-
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(p2pClient, archiver, epochCache, config);
|
|
1049
|
-
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
1050
|
-
if (validatorClient) {
|
|
1051
|
-
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(p2pClient, validatorClient, archiver, epochCache, config, {
|
|
1052
|
-
log: log.createChild('attested-invalid-proposal-watcher')
|
|
1053
|
-
});
|
|
1054
|
-
watchers.push(attestedInvalidProposalWatcher);
|
|
1055
|
-
}
|
|
1056
|
-
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
1057
|
-
watchers.push(checkpointEquivocationWatcher);
|
|
1058
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
1059
|
-
watchers.push(attestationsBlockWatcher);
|
|
1060
|
-
}
|
|
1061
|
-
const watchersToStart = compactArray([
|
|
1062
|
-
validatorsSentinel,
|
|
1063
|
-
dataWithholdingWatcher,
|
|
1064
|
-
attestationsBlockWatcher,
|
|
1065
|
-
broadcastedInvalidCheckpointProposalWatcher,
|
|
1066
|
-
attestedInvalidProposalWatcher,
|
|
1067
|
-
checkpointEquivocationWatcher
|
|
1068
|
-
]);
|
|
1069
|
-
const startedWatchers = [];
|
|
1070
|
-
const stopStartedWatchers = async ()=>{
|
|
1071
|
-
for (const watcher of startedWatchers){
|
|
1072
|
-
await tryStop(watcher);
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
// Start p2p-related services once the archiver has completed sync
|
|
1076
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
1077
|
-
for (const watcher of watchersToStart){
|
|
1078
|
-
await watcher.start();
|
|
1079
|
-
startedWatchers.push(watcher);
|
|
1080
|
-
}
|
|
1081
|
-
log.info(`All p2p services started`);
|
|
1082
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
1083
|
-
started.push({
|
|
1084
|
-
stop: stopStartedWatchers
|
|
1085
|
-
});
|
|
1086
|
-
// Validator enabled, create/start relevant service
|
|
1087
|
-
let sequencer;
|
|
1088
|
-
let automineSequencer;
|
|
1089
|
-
let slasherClient;
|
|
1090
|
-
if (!config.disableValidator && validatorClient) {
|
|
1091
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
1092
|
-
// as they are executed when the node is selected as proposer.
|
|
1093
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
1094
|
-
slasherClient = await createSlasher(config, pickL1ContractAddresses(config), getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
1095
|
-
await slasherClient.start();
|
|
1096
|
-
started.push(slasherClient);
|
|
1097
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress ? await createForwarderL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.sequencerPublisherForwarderAddress, {
|
|
1098
|
-
...config,
|
|
1099
|
-
scope: 'sequencer'
|
|
1100
|
-
}, {
|
|
1101
|
-
telemetry,
|
|
1102
|
-
logger: log.createChild('l1-tx-utils'),
|
|
1103
|
-
dateProvider,
|
|
1104
|
-
kzg: Blob.getViemKzgInstance()
|
|
1105
|
-
}) : await createL1TxUtilsFromSigners(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
1106
|
-
...config,
|
|
1107
|
-
scope: 'sequencer'
|
|
1108
|
-
}, {
|
|
1109
|
-
telemetry,
|
|
1110
|
-
logger: log.createChild('l1-tx-utils'),
|
|
1111
|
-
dateProvider,
|
|
1112
|
-
kzg: Blob.getViemKzgInstance()
|
|
1113
|
-
});
|
|
1114
|
-
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
1115
|
-
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
1116
|
-
let funderL1TxUtils;
|
|
1117
|
-
if (fundingSigner) {
|
|
1118
|
-
const [funder] = await createL1TxUtilsFromSigners(publicClient, [
|
|
1119
|
-
fundingSigner
|
|
1120
|
-
], {
|
|
1121
|
-
...config,
|
|
1122
|
-
scope: 'sequencer'
|
|
1123
|
-
}, {
|
|
1124
|
-
telemetry,
|
|
1125
|
-
logger: log.createChild('l1-tx-utils:funder'),
|
|
1126
|
-
dateProvider
|
|
1127
|
-
});
|
|
1128
|
-
funderL1TxUtils = funder;
|
|
1129
|
-
}
|
|
1130
|
-
// Create and start the sequencer client
|
|
1131
|
-
const checkpointsBuilder = new CheckpointsBuilder({
|
|
1132
|
-
...config,
|
|
1133
|
-
l1GenesisTime,
|
|
1134
|
-
slotDuration: Number(slotDuration),
|
|
1135
|
-
rollupManaLimit
|
|
1136
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry, debugLogStore);
|
|
1137
|
-
if (config.useAutomineSequencer) {
|
|
1138
|
-
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
1139
|
-
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
1140
|
-
automineSequencer = await createAutomineSequencer({
|
|
1141
|
-
config,
|
|
1142
|
-
l1TxUtils,
|
|
1143
|
-
funderL1TxUtils,
|
|
1144
|
-
publicClient,
|
|
1145
|
-
rollupContract,
|
|
1146
|
-
epochCache,
|
|
1147
|
-
blobClient,
|
|
1148
|
-
telemetry,
|
|
1149
|
-
dateProvider,
|
|
1150
|
-
keyStoreManager: keyStoreManager,
|
|
1151
|
-
validatorClient,
|
|
1152
|
-
checkpointsBuilder,
|
|
1153
|
-
globalVariableBuilder,
|
|
1154
|
-
worldStateSynchronizer,
|
|
1155
|
-
archiver,
|
|
1156
|
-
p2pClient,
|
|
1157
|
-
l1Constants: {
|
|
1158
|
-
l1GenesisTime,
|
|
1159
|
-
slotDuration: Number(slotDuration),
|
|
1160
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
1161
|
-
rollupManaLimit
|
|
1162
|
-
},
|
|
1163
|
-
log
|
|
1164
|
-
});
|
|
1165
|
-
} else {
|
|
1166
|
-
sequencer = await SequencerClient.new(config, {
|
|
1167
|
-
...deps,
|
|
1168
|
-
epochCache,
|
|
1169
|
-
l1TxUtils,
|
|
1170
|
-
funderL1TxUtils,
|
|
1171
|
-
validatorClient,
|
|
1172
|
-
p2pClient,
|
|
1173
|
-
worldStateSynchronizer,
|
|
1174
|
-
slasherClient,
|
|
1175
|
-
checkpointsBuilder,
|
|
1176
|
-
l2BlockSource: archiver,
|
|
1177
|
-
l1ToL2MessageSource: archiver,
|
|
1178
|
-
telemetry,
|
|
1179
|
-
dateProvider,
|
|
1180
|
-
blobClient,
|
|
1181
|
-
nodeKeyStore: keyStoreManager,
|
|
1182
|
-
globalVariableBuilder
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
1187
|
-
await sequencer.start();
|
|
1188
|
-
started.push(sequencer);
|
|
1189
|
-
log.verbose(`Sequencer started`);
|
|
1190
|
-
} else if (sequencer) {
|
|
1191
|
-
log.warn(`Sequencer created but not started`);
|
|
1192
|
-
}
|
|
1193
|
-
if (!options.dontStartSequencer && automineSequencer) {
|
|
1194
|
-
await automineSequencer.start();
|
|
1195
|
-
started.push({
|
|
1196
|
-
stop: ()=>automineSequencer.stop()
|
|
1197
|
-
});
|
|
1198
|
-
log.verbose(`AutomineSequencer started`);
|
|
1199
|
-
} else if (automineSequencer) {
|
|
1200
|
-
log.warn(`AutomineSequencer created but not started`);
|
|
1201
|
-
}
|
|
1202
|
-
// Create prover node subsystem if enabled
|
|
1203
|
-
let proverNode;
|
|
1204
|
-
if (config.enableProverNode) {
|
|
1205
|
-
proverNode = await createProverNode(config, {
|
|
1206
|
-
...deps.proverNodeDeps,
|
|
1207
|
-
telemetry,
|
|
1208
|
-
dateProvider,
|
|
1209
|
-
archiver,
|
|
1210
|
-
worldStateSynchronizer,
|
|
1211
|
-
p2pClient,
|
|
1212
|
-
epochCache,
|
|
1213
|
-
blobClient,
|
|
1214
|
-
keyStoreManager
|
|
1215
|
-
});
|
|
1216
|
-
if (!options.dontStartProverNode) {
|
|
1217
|
-
await proverNode.start();
|
|
1218
|
-
started.push(proverNode);
|
|
1219
|
-
log.info(`Prover node subsystem started`);
|
|
1220
|
-
} else {
|
|
1221
|
-
log.info(`Prover node subsystem created but not started`);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
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);
|
|
1225
|
-
return node;
|
|
1226
|
-
} catch (err) {
|
|
1227
|
-
log.error('Failed during node creation, stopping started resources', err);
|
|
1228
|
-
for (const resource of started.reverse()){
|
|
1229
|
-
await tryStop(resource);
|
|
1230
|
-
}
|
|
1231
|
-
throw err;
|
|
1232
|
-
}
|
|
579
|
+
getCheckpoint(param, options = {}) {
|
|
580
|
+
return this.blockProvider.getCheckpoint(param, options);
|
|
581
|
+
}
|
|
582
|
+
getCheckpoints(from, limit, options = {}) {
|
|
583
|
+
return this.blockProvider.getCheckpoints(from, limit, options);
|
|
1233
584
|
}
|
|
1234
585
|
/**
|
|
1235
586
|
* Returns the sequencer client instance.
|
|
@@ -1274,14 +625,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1274
625
|
return Promise.resolve(this.p2pClient.isReady() ?? false);
|
|
1275
626
|
}
|
|
1276
627
|
async getNodeInfo() {
|
|
1277
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
628
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses, l1Constants] = await Promise.all([
|
|
1278
629
|
this.getNodeVersion(),
|
|
1279
630
|
this.getVersion(),
|
|
1280
631
|
this.getChainId(),
|
|
1281
632
|
this.getEncodedEnr(),
|
|
1282
633
|
this.getL1ContractAddresses(),
|
|
1283
|
-
this.getProtocolContractAddresses()
|
|
634
|
+
this.getProtocolContractAddresses(),
|
|
635
|
+
this.blockSource.getL1Constants()
|
|
1284
636
|
]);
|
|
637
|
+
// Gas limits a single tx may declare on this network, derived from network-wide constants only (the
|
|
638
|
+
// timetable's blocks-per-checkpoint and the network-minimum per-block multipliers) — never this node's
|
|
639
|
+
// local caps or configured multipliers, which can make the node stricter at block-building time but
|
|
640
|
+
// cannot define what the network accepts for relay. Clients read txsLimits to set fallback gas limits.
|
|
641
|
+
const maxTxGas = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1285
642
|
const nodeInfo = {
|
|
1286
643
|
nodeVersion,
|
|
1287
644
|
l1ChainId: chainId,
|
|
@@ -1289,7 +646,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1289
646
|
enr,
|
|
1290
647
|
l1ContractAddresses: contractAddresses,
|
|
1291
648
|
protocolContractAddresses: protocolContractAddresses,
|
|
1292
|
-
realProofs: !!this.config.realProofs
|
|
649
|
+
realProofs: !!this.config.realProofs,
|
|
650
|
+
txsLimits: {
|
|
651
|
+
gas: {
|
|
652
|
+
daGas: maxTxGas.daGas,
|
|
653
|
+
l2Gas: maxTxGas.l2Gas
|
|
654
|
+
}
|
|
655
|
+
}
|
|
1293
656
|
};
|
|
1294
657
|
return nodeInfo;
|
|
1295
658
|
}
|
|
@@ -1300,7 +663,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1300
663
|
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
1301
664
|
}
|
|
1302
665
|
async getMaxPriorityFees() {
|
|
1303
|
-
for await (const tx of this.p2pClient.iteratePendingTxs(
|
|
666
|
+
for await (const tx of this.p2pClient.iteratePendingTxs({
|
|
667
|
+
includeProof: false
|
|
668
|
+
})){
|
|
1304
669
|
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
1305
670
|
}
|
|
1306
671
|
return GasFees.from({
|
|
@@ -1329,8 +694,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1329
694
|
getContractClass(id) {
|
|
1330
695
|
return this.contractDataSource.getContractClass(id);
|
|
1331
696
|
}
|
|
1332
|
-
getContract(address) {
|
|
1333
|
-
|
|
697
|
+
async getContract(address, referenceBlock = 'latest') {
|
|
698
|
+
const blockData = await this.getBlockData(referenceBlock);
|
|
699
|
+
if (!blockData) {
|
|
700
|
+
throw new Error(`Reference block ${inspectBlockParameter(referenceBlock)} not found when querying contract ${address}. If the node API has been queried with an anchor block hash, possibly a reorg has occurred.`);
|
|
701
|
+
}
|
|
702
|
+
return this.contractDataSource.getContract(address, blockData.header.globalVariables.timestamp);
|
|
1334
703
|
}
|
|
1335
704
|
getPrivateLogsByTags(query) {
|
|
1336
705
|
return this.logsSource.getPrivateLogsByTags(query);
|
|
@@ -1371,58 +740,8 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1371
740
|
txHash
|
|
1372
741
|
});
|
|
1373
742
|
}
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
// as a fallback if we don't find a mined tx effect in the archiver.
|
|
1377
|
-
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1378
|
-
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1379
|
-
// Then get the raw tx effect from the archiver, which tracks every tx in a mined block.
|
|
1380
|
-
const indexed = await this.blockSource.getTxEffect(txHash);
|
|
1381
|
-
let receipt;
|
|
1382
|
-
if (indexed) {
|
|
1383
|
-
receipt = await this.#assembleMinedReceipt(indexed, options);
|
|
1384
|
-
} else if (isKnownToPool) {
|
|
1385
|
-
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1386
|
-
// This handles race conditions between archiver and p2p, where the archiver
|
|
1387
|
-
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1388
|
-
let tx;
|
|
1389
|
-
if (options?.includePendingTx) {
|
|
1390
|
-
// The tx may have left the pool since we checked its status (mined or dropped); in that case we
|
|
1391
|
-
// leave `tx` unset and still return a pending receipt.
|
|
1392
|
-
const pendingTx = await this.p2pClient.getTxByHashFromPool(txHash);
|
|
1393
|
-
tx = pendingTx && !options.includeProof ? pendingTx.withoutProof() : pendingTx;
|
|
1394
|
-
}
|
|
1395
|
-
receipt = new PendingTxReceipt(txHash, tx);
|
|
1396
|
-
} else {
|
|
1397
|
-
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1398
|
-
receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
|
|
1399
|
-
}
|
|
1400
|
-
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1401
|
-
return receipt;
|
|
1402
|
-
}
|
|
1403
|
-
/**
|
|
1404
|
-
* Assembles a {@link MinedTxReceipt} from a raw {@link IndexedTxEffect}, deriving the finalization status from the
|
|
1405
|
-
* cached L2 tips and the epoch from the block's slot number.
|
|
1406
|
-
*/ async #assembleMinedReceipt(indexed, options) {
|
|
1407
|
-
const blockNumber = indexed.l2BlockNumber;
|
|
1408
|
-
const [tips, l1Constants] = await Promise.all([
|
|
1409
|
-
this.blockSource.getL2Tips(),
|
|
1410
|
-
this.blockSource.getL1Constants()
|
|
1411
|
-
]);
|
|
1412
|
-
const status = this.#deriveMinedStatus(blockNumber, tips);
|
|
1413
|
-
const epochNumber = getEpochAtSlot(indexed.slotNumber, l1Constants);
|
|
1414
|
-
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);
|
|
1415
|
-
}
|
|
1416
|
-
#deriveMinedStatus(blockNumber, tips) {
|
|
1417
|
-
if (blockNumber <= tips.finalized.block.number) {
|
|
1418
|
-
return TxStatus.FINALIZED;
|
|
1419
|
-
} else if (blockNumber <= tips.proven.block.number) {
|
|
1420
|
-
return TxStatus.PROVEN;
|
|
1421
|
-
} else if (blockNumber <= tips.checkpointed.block.number) {
|
|
1422
|
-
return TxStatus.CHECKPOINTED;
|
|
1423
|
-
} else {
|
|
1424
|
-
return TxStatus.PROPOSED;
|
|
1425
|
-
}
|
|
743
|
+
getTxReceipt(txHash, options) {
|
|
744
|
+
return this.txReceiptBuilder.getTxReceipt(txHash, options);
|
|
1426
745
|
}
|
|
1427
746
|
getTxEffect(txHash) {
|
|
1428
747
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -1458,118 +777,58 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1458
777
|
* @param limit - The number of items to returns
|
|
1459
778
|
* @param after - The last known pending tx. Used for pagination
|
|
1460
779
|
* @returns - The pending txs.
|
|
1461
|
-
*/ getPendingTxs(limit, after) {
|
|
1462
|
-
return this.p2pClient.getPendingTxs(limit, after);
|
|
780
|
+
*/ getPendingTxs(limit, after, options) {
|
|
781
|
+
return this.p2pClient.getPendingTxs(limit, after, options);
|
|
1463
782
|
}
|
|
1464
783
|
getPendingTxCount() {
|
|
1465
784
|
return this.p2pClient.getPendingTxCount();
|
|
1466
785
|
}
|
|
786
|
+
getPeers(includePending) {
|
|
787
|
+
return this.p2pClient.getPeers(includePending);
|
|
788
|
+
}
|
|
789
|
+
getCheckpointAttestationsForSlot(slot, proposalPayloadHash) {
|
|
790
|
+
return this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
791
|
+
}
|
|
792
|
+
getProposalsForSlot(slot) {
|
|
793
|
+
return this.p2pClient.getProposalsForSlot(slot);
|
|
794
|
+
}
|
|
1467
795
|
/**
|
|
1468
|
-
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
796
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain. The tx's proof is only loaded and returned
|
|
797
|
+
* when `includeProof` is set.
|
|
1469
798
|
* @param txHash - The transaction hash to return.
|
|
799
|
+
* @param options - Options for the returned tx (eg whether to include its proof).
|
|
1470
800
|
* @returns - The tx if it exists.
|
|
1471
|
-
*/ getTxByHash(txHash) {
|
|
1472
|
-
return
|
|
801
|
+
*/ getTxByHash(txHash, options) {
|
|
802
|
+
return this.p2pClient.getTxByHashFromPool(txHash, {
|
|
803
|
+
includeProof: !!options?.includeProof
|
|
804
|
+
});
|
|
1473
805
|
}
|
|
1474
806
|
/**
|
|
1475
|
-
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
807
|
+
* Method to retrieve txs from the mempool or unfinalized chain. The txs' proofs are only loaded and returned when
|
|
808
|
+
* `includeProof` is set.
|
|
1476
809
|
* @param txHash - The transaction hash to return.
|
|
810
|
+
* @param options - Options for the returned txs (eg whether to include their proofs).
|
|
1477
811
|
* @returns - The txs if it exists.
|
|
1478
|
-
*/ async getTxsByHash(txHashes) {
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
1482
|
-
const committedDb = await this.getWorldState(referenceBlock);
|
|
1483
|
-
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1484
|
-
// Filter out undefined values to query block numbers only for found leaves
|
|
1485
|
-
const definedIndices = maybeIndices.filter((x)=>x !== undefined);
|
|
1486
|
-
// Now we find the block numbers for the defined indices
|
|
1487
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1488
|
-
// Build a map from leaf index to block number
|
|
1489
|
-
const indexToBlockNumber = new Map();
|
|
1490
|
-
for(let i = 0; i < definedIndices.length; i++){
|
|
1491
|
-
const blockNumber = blockNumbers[i];
|
|
1492
|
-
if (blockNumber === undefined) {
|
|
1493
|
-
throw new Error(`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1494
|
-
}
|
|
1495
|
-
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1496
|
-
}
|
|
1497
|
-
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1498
|
-
const uniqueBlockNumbers = [
|
|
1499
|
-
...new Set(indexToBlockNumber.values())
|
|
1500
|
-
];
|
|
1501
|
-
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1502
|
-
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1503
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1504
|
-
}));
|
|
1505
|
-
// Build a map from block number to block hash
|
|
1506
|
-
const blockNumberToHash = new Map();
|
|
1507
|
-
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1508
|
-
const blockHash = blockHashes[i];
|
|
1509
|
-
if (blockHash === undefined) {
|
|
1510
|
-
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1511
|
-
}
|
|
1512
|
-
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1513
|
-
}
|
|
1514
|
-
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1515
|
-
return maybeIndices.map((index)=>{
|
|
1516
|
-
if (index === undefined) {
|
|
1517
|
-
return undefined;
|
|
1518
|
-
}
|
|
1519
|
-
const blockNumber = indexToBlockNumber.get(index);
|
|
1520
|
-
if (blockNumber === undefined) {
|
|
1521
|
-
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1522
|
-
}
|
|
1523
|
-
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1524
|
-
if (l2BlockHash === undefined) {
|
|
1525
|
-
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1526
|
-
}
|
|
1527
|
-
return {
|
|
1528
|
-
l2BlockNumber: blockNumber,
|
|
1529
|
-
l2BlockHash,
|
|
1530
|
-
data: index
|
|
1531
|
-
};
|
|
812
|
+
*/ async getTxsByHash(txHashes, options) {
|
|
813
|
+
const txs = await this.p2pClient.getTxsByHashFromPool(txHashes, {
|
|
814
|
+
includeProof: !!options?.includeProof
|
|
1532
815
|
});
|
|
816
|
+
return compactArray(txs);
|
|
1533
817
|
}
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1537
|
-
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1538
|
-
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1539
|
-
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1540
|
-
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1541
|
-
return undefined;
|
|
1542
|
-
}
|
|
1543
|
-
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1544
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1545
|
-
blockHash
|
|
1546
|
-
]);
|
|
1547
|
-
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
818
|
+
findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
819
|
+
return this.worldStateQueries.findLeavesIndexes(referenceBlock, treeId, leafValues);
|
|
1548
820
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1552
|
-
noteHash
|
|
1553
|
-
]);
|
|
1554
|
-
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
821
|
+
getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
822
|
+
return this.worldStateQueries.getBlockHashMembershipWitness(referenceBlock, blockHash);
|
|
1555
823
|
}
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
if (!witness) {
|
|
1562
|
-
return undefined;
|
|
1563
|
-
}
|
|
1564
|
-
// REFACTOR: Return a MembershipWitness object
|
|
1565
|
-
return [
|
|
1566
|
-
witness.index,
|
|
1567
|
-
witness.path
|
|
1568
|
-
];
|
|
824
|
+
getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
825
|
+
return this.worldStateQueries.getNoteHashMembershipWitness(referenceBlock, noteHash);
|
|
826
|
+
}
|
|
827
|
+
getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
828
|
+
return this.worldStateQueries.getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message);
|
|
1569
829
|
}
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
830
|
+
getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
831
|
+
return this.worldStateQueries.getL1ToL2MessageCheckpoint(l1ToL2Message);
|
|
1573
832
|
}
|
|
1574
833
|
/**
|
|
1575
834
|
* Returns all the L2 to L1 messages in an epoch.
|
|
@@ -1578,161 +837,34 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1578
837
|
*
|
|
1579
838
|
* @param epoch - The epoch at which to get the data.
|
|
1580
839
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1581
|
-
*/
|
|
1582
|
-
|
|
1583
|
-
epoch,
|
|
1584
|
-
onlyCheckpointed: true
|
|
1585
|
-
});
|
|
1586
|
-
const blocksInCheckpoints = chunkBy(blocks, (block)=>block.header.globalVariables.slotNumber);
|
|
1587
|
-
return blocksInCheckpoints.map((slotBlocks)=>slotBlocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
840
|
+
*/ getL2ToL1Messages(epoch) {
|
|
841
|
+
return this.worldStateQueries.getL2ToL1Messages(epoch);
|
|
1588
842
|
}
|
|
1589
843
|
/**
|
|
1590
844
|
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
1591
845
|
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
1592
846
|
*/ getL2ToL1MembershipWitness(txHash, message, messageIndexInTx) {
|
|
1593
|
-
return this.
|
|
847
|
+
return this.worldStateQueries.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1594
848
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1598
|
-
nullifier.toBuffer()
|
|
1599
|
-
]);
|
|
1600
|
-
if (!witness) {
|
|
1601
|
-
return undefined;
|
|
1602
|
-
}
|
|
1603
|
-
const { index, path } = witness;
|
|
1604
|
-
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1605
|
-
if (!leafPreimage) {
|
|
1606
|
-
return undefined;
|
|
1607
|
-
}
|
|
1608
|
-
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
849
|
+
getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
850
|
+
return this.worldStateQueries.getNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1609
851
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1613
|
-
if (!findResult) {
|
|
1614
|
-
return undefined;
|
|
1615
|
-
}
|
|
1616
|
-
const { index, alreadyPresent } = findResult;
|
|
1617
|
-
if (alreadyPresent) {
|
|
1618
|
-
throw new Error(`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1619
|
-
}
|
|
1620
|
-
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1621
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1622
|
-
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1623
|
-
}
|
|
1624
|
-
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1625
|
-
const committedDb = await this.getWorldState(referenceBlock);
|
|
1626
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1627
|
-
if (!lowLeafResult) {
|
|
1628
|
-
return undefined;
|
|
1629
|
-
} else {
|
|
1630
|
-
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1631
|
-
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1632
|
-
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1633
|
-
}
|
|
852
|
+
getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
853
|
+
return this.worldStateQueries.getLowNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1634
854
|
}
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
return Fr.ZERO;
|
|
1641
|
-
}
|
|
1642
|
-
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1643
|
-
return preimage.leaf.value;
|
|
855
|
+
getPublicDataWitness(referenceBlock, leafSlot) {
|
|
856
|
+
return this.worldStateQueries.getPublicDataWitness(referenceBlock, leafSlot);
|
|
857
|
+
}
|
|
858
|
+
getPublicStorageAt(referenceBlock, contract, slot) {
|
|
859
|
+
return this.worldStateQueries.getPublicStorageAt(referenceBlock, contract, slot);
|
|
1644
860
|
}
|
|
1645
861
|
/**
|
|
1646
862
|
* Simulates the public part of a transaction with the current state.
|
|
1647
863
|
* @param tx - The transaction to simulate.
|
|
1648
864
|
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
1649
865
|
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1650
|
-
**/
|
|
1651
|
-
|
|
1652
|
-
stack: [],
|
|
1653
|
-
error: void 0,
|
|
1654
|
-
hasError: false
|
|
1655
|
-
};
|
|
1656
|
-
try {
|
|
1657
|
-
// Check total gas limit for simulation
|
|
1658
|
-
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1659
|
-
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
1660
|
-
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1661
|
-
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1662
|
-
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1663
|
-
}
|
|
1664
|
-
const txHash = tx.getTxHash();
|
|
1665
|
-
const l2Tips = await this.blockSource.getL2Tips();
|
|
1666
|
-
const latestBlockNumber = l2Tips.proposed.number;
|
|
1667
|
-
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1668
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1669
|
-
const coinbase = EthAddress.ZERO;
|
|
1670
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1671
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1672
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1673
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1674
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1675
|
-
txHash,
|
|
1676
|
-
blockNumber
|
|
1677
|
-
});
|
|
1678
|
-
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1679
|
-
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1680
|
-
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1681
|
-
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1682
|
-
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1683
|
-
// which means the next block would be the first block of the next checkpoint.
|
|
1684
|
-
const targetCheckpoint = CheckpointNumber((l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1);
|
|
1685
|
-
const nextCheckpointMessages = l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number ? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch((err)=>{
|
|
1686
|
-
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1687
|
-
this.log.warn(`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`);
|
|
1688
|
-
} else {
|
|
1689
|
-
this.log.error(`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`, err);
|
|
1690
|
-
}
|
|
1691
|
-
return undefined;
|
|
1692
|
-
}) : undefined;
|
|
1693
|
-
const merkleTreeFork = _ts_add_disposable_resource(env, await this.worldStateSynchronizer.fork(latestBlockNumber), true);
|
|
1694
|
-
if (nextCheckpointMessages !== undefined) {
|
|
1695
|
-
this.log.debug(`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`, {
|
|
1696
|
-
checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1
|
|
1697
|
-
});
|
|
1698
|
-
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1699
|
-
}
|
|
1700
|
-
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
1701
|
-
const config = PublicSimulatorConfig.from({
|
|
1702
|
-
skipFeeEnforcement,
|
|
1703
|
-
collectDebugLogs: true,
|
|
1704
|
-
collectHints: false,
|
|
1705
|
-
collectCallMetadata: true,
|
|
1706
|
-
collectStatistics: false,
|
|
1707
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1708
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1709
|
-
})
|
|
1710
|
-
});
|
|
1711
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1712
|
-
if (overrides?.contracts) {
|
|
1713
|
-
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance })=>instance));
|
|
1714
|
-
}
|
|
1715
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
1716
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1717
|
-
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([
|
|
1718
|
-
tx
|
|
1719
|
-
]);
|
|
1720
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1721
|
-
if (failedTxs.length) {
|
|
1722
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, {
|
|
1723
|
-
txHash
|
|
1724
|
-
});
|
|
1725
|
-
throw failedTxs[0].error;
|
|
1726
|
-
}
|
|
1727
|
-
const [processedTx] = processedTxs;
|
|
1728
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed, debugLogs);
|
|
1729
|
-
} catch (e) {
|
|
1730
|
-
env.error = e;
|
|
1731
|
-
env.hasError = true;
|
|
1732
|
-
} finally{
|
|
1733
|
-
const result = _ts_dispose_resources(env);
|
|
1734
|
-
if (result) await result;
|
|
1735
|
-
}
|
|
866
|
+
**/ simulatePublicCalls(tx, skipFeeEnforcement = false, overrides) {
|
|
867
|
+
return this.nodePublicCallsSimulator.simulate(tx, skipFeeEnforcement, overrides);
|
|
1736
868
|
}
|
|
1737
869
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1738
870
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
@@ -1741,6 +873,9 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1741
873
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1742
874
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1743
875
|
const l1Constants = await this.blockSource.getL1Constants();
|
|
876
|
+
// Enforce the same network admission limit the node advertises in getNodeInfo (network-wide, not this
|
|
877
|
+
// node's local caps), so a tx the wallet sized against txsLimits is not rejected here.
|
|
878
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1744
879
|
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1745
880
|
timestamp: nextSlotTimestamp,
|
|
1746
881
|
blockNumber,
|
|
@@ -1752,10 +887,10 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1752
887
|
],
|
|
1753
888
|
gasFees: await this.getCurrentMinFees(),
|
|
1754
889
|
skipFeeEnforcement,
|
|
890
|
+
isSimulation,
|
|
1755
891
|
txsPermitted: !this.config.disableTransactions,
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
maxBlockDAGas: this.config.validateMaxDABlockGas
|
|
892
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
893
|
+
maxTxDAGas: networkTxGasLimits.daGas
|
|
1759
894
|
}, this.log.getBindings());
|
|
1760
895
|
return await validator.validateTx(tx);
|
|
1761
896
|
}
|
|
@@ -2057,73 +1192,29 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
2057
1192
|
});
|
|
2058
1193
|
}
|
|
2059
1194
|
}
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
* @returns An instance of a committed MerkleTreeOperations
|
|
2064
|
-
*/ async getWorldState(block) {
|
|
2065
|
-
const query = this.normalizeBlockParameter(block);
|
|
2066
|
-
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
2067
|
-
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
2068
|
-
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
2069
|
-
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
2070
|
-
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
2071
|
-
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
2072
|
-
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
2073
|
-
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
2074
|
-
let blockSyncedTo = BlockNumber.ZERO;
|
|
2075
|
-
try {
|
|
2076
|
-
// Attempt to sync the world state if necessary
|
|
2077
|
-
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
2078
|
-
} catch (err) {
|
|
2079
|
-
this.log.error(`Error getting world state: ${err}`);
|
|
1195
|
+
async prove(upToCheckpoint) {
|
|
1196
|
+
if (!this.automineSequencer) {
|
|
1197
|
+
throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
|
|
2080
1198
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
// Check it's within world state sync range
|
|
2087
|
-
if (blockNumber > blockSyncedTo) {
|
|
2088
|
-
throw new Error(`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
2089
|
-
}
|
|
2090
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2091
|
-
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
2092
|
-
// Double-check world-state synced to the same block hash as was requested.
|
|
2093
|
-
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2094
|
-
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2095
|
-
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2096
|
-
// the archiver when it resolves the hash query to block number 0.
|
|
2097
|
-
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
2098
|
-
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
2099
|
-
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
2100
|
-
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.`);
|
|
2101
|
-
}
|
|
1199
|
+
return await this.automineSequencer.prove(upToCheckpoint);
|
|
1200
|
+
}
|
|
1201
|
+
async warpL2TimeAtLeastTo(targetTimestamp) {
|
|
1202
|
+
if (!this.automineSequencer) {
|
|
1203
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
2102
1204
|
}
|
|
2103
|
-
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
if (blockNumber === undefined) {
|
|
2109
|
-
if ('hash' in query) {
|
|
2110
|
-
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.`);
|
|
2111
|
-
}
|
|
2112
|
-
if ('archive' in query) {
|
|
2113
|
-
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
2114
|
-
}
|
|
2115
|
-
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
1205
|
+
await this.automineSequencer.warpTo(targetTimestamp);
|
|
1206
|
+
}
|
|
1207
|
+
async warpL2TimeAtLeastBy(duration) {
|
|
1208
|
+
if (!this.automineSequencer) {
|
|
1209
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
2116
1210
|
}
|
|
2117
|
-
|
|
1211
|
+
await this.automineSequencer.warpBy(duration);
|
|
2118
1212
|
}
|
|
2119
1213
|
/**
|
|
2120
|
-
*
|
|
2121
|
-
* @
|
|
2122
|
-
*
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
*/ async #syncWorldState(targetBlockNumber, blockHash) {
|
|
2126
|
-
const target = targetBlockNumber ?? await this.blockSource.getBlockNumber();
|
|
2127
|
-
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1214
|
+
* Returns a committed world-state view at `block`, driving sync first. Delegates to
|
|
1215
|
+
* {@link NodeWorldStateQueries.getWorldState}; kept as a protected method so subclasses and tests can
|
|
1216
|
+
* exercise the node's block-resolution and reorg-aware sync behavior.
|
|
1217
|
+
*/ getWorldState(block) {
|
|
1218
|
+
return this.worldStateQueries.getWorldState(block);
|
|
2128
1219
|
}
|
|
2129
1220
|
}
|