@aztec/aztec-node 0.0.1-commit.a072138 → 0.0.1-commit.a4600f49
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 +23 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +26 -8
- package/dest/aztec-node/node_public_calls_simulator.d.ts +97 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
- package/dest/aztec-node/node_public_calls_simulator.js +351 -0
- 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 +143 -135
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +497 -730
- 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 +523 -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/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 +6 -4
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +12 -5
- package/dest/sentinel/sentinel.d.ts +146 -22
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +266 -118
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +33 -21
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -25
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +55 -16
- package/src/aztec-node/node_public_calls_simulator.ts +394 -0
- 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 +644 -939
- package/src/bin/index.ts +19 -12
- package/src/factory.ts +688 -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 +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +22 -7
- package/src/sentinel/sentinel.ts +316 -136
- package/src/sentinel/store.ts +35 -27
- package/src/test/index.ts +2 -2
|
@@ -371,55 +371,59 @@ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
|
371
371
|
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
372
372
|
}
|
|
373
373
|
var _dec, _initProto;
|
|
374
|
-
import {
|
|
375
|
-
import {
|
|
376
|
-
import {
|
|
377
|
-
import {
|
|
378
|
-
import {
|
|
379
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
380
|
-
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
381
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
382
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
383
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
374
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
375
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
376
|
+
import { pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
377
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
378
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
384
379
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
385
380
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
386
381
|
import { createLogger } from '@aztec/foundation/log';
|
|
382
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
387
383
|
import { count } from '@aztec/foundation/string';
|
|
388
|
-
import {
|
|
389
|
-
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
384
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
390
385
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
391
|
-
import {
|
|
392
|
-
import {
|
|
393
|
-
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
386
|
+
import { uploadSnapshot } from '@aztec/node-lib/actions';
|
|
387
|
+
import { createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
394
388
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
395
|
-
import {
|
|
396
|
-
import {
|
|
397
|
-
import {
|
|
398
|
-
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
399
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
400
|
-
import { BlockHash, L2Block } from '@aztec/stdlib/block';
|
|
401
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
402
|
-
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
389
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
390
|
+
import { inspectBlockParameter } from '@aztec/stdlib/block';
|
|
391
|
+
import { GasFees, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
403
392
|
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
404
393
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
405
|
-
import {
|
|
406
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
407
|
-
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
408
|
-
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
409
|
-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
394
|
+
import { NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
410
395
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
411
|
-
import {
|
|
412
|
-
import {
|
|
413
|
-
import {
|
|
414
|
-
import {
|
|
415
|
-
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';
|
|
416
400
|
import { NodeMetrics } from './node_metrics.js';
|
|
401
|
+
import { NodePublicCallsSimulator } from './node_public_calls_simulator.js';
|
|
417
402
|
_dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
418
403
|
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
419
404
|
}));
|
|
420
405
|
/**
|
|
421
406
|
* The aztec node.
|
|
422
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;
|
|
423
427
|
config;
|
|
424
428
|
p2pClient;
|
|
425
429
|
blockSource;
|
|
@@ -428,287 +432,158 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
428
432
|
l1ToL2MessageSource;
|
|
429
433
|
worldStateSynchronizer;
|
|
430
434
|
sequencer;
|
|
435
|
+
proverNode;
|
|
431
436
|
slasherClient;
|
|
432
437
|
validatorsSentinel;
|
|
433
|
-
|
|
438
|
+
stopStartedWatchers;
|
|
434
439
|
l1ChainId;
|
|
435
440
|
version;
|
|
436
441
|
globalVariableBuilder;
|
|
442
|
+
rollupContract;
|
|
443
|
+
feeProvider;
|
|
437
444
|
epochCache;
|
|
438
445
|
packageVersion;
|
|
439
|
-
|
|
446
|
+
peerProofVerifier;
|
|
447
|
+
rpcProofVerifier;
|
|
440
448
|
telemetry;
|
|
441
449
|
log;
|
|
442
450
|
blobClient;
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
this.
|
|
459
|
-
this.
|
|
460
|
-
this.
|
|
461
|
-
this.
|
|
462
|
-
this.
|
|
463
|
-
this.
|
|
464
|
-
this.
|
|
465
|
-
this.
|
|
466
|
-
this.
|
|
467
|
-
this.
|
|
468
|
-
this.
|
|
469
|
-
this.
|
|
470
|
-
this.
|
|
471
|
-
this.
|
|
472
|
-
this.
|
|
473
|
-
this.
|
|
474
|
-
this.
|
|
475
|
-
this.
|
|
476
|
-
this.
|
|
477
|
-
this.
|
|
478
|
-
this.
|
|
479
|
-
this.
|
|
480
|
-
|
|
481
|
-
|
|
451
|
+
validatorClient;
|
|
452
|
+
keyStoreManager;
|
|
453
|
+
debugLogStore;
|
|
454
|
+
automineSequencer;
|
|
455
|
+
avmSimulator;
|
|
456
|
+
constructor(deps){
|
|
457
|
+
this.config = deps.config;
|
|
458
|
+
this.p2pClient = deps.p2pClient;
|
|
459
|
+
this.blockSource = deps.blockSource;
|
|
460
|
+
this.logsSource = deps.logsSource;
|
|
461
|
+
this.contractDataSource = deps.contractDataSource;
|
|
462
|
+
this.l1ToL2MessageSource = deps.l1ToL2MessageSource;
|
|
463
|
+
this.worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
464
|
+
this.sequencer = deps.sequencer;
|
|
465
|
+
this.proverNode = deps.proverNode;
|
|
466
|
+
this.slasherClient = deps.slasherClient;
|
|
467
|
+
this.validatorsSentinel = deps.validatorsSentinel;
|
|
468
|
+
this.stopStartedWatchers = deps.stopStartedWatchers;
|
|
469
|
+
this.l1ChainId = deps.l1ChainId;
|
|
470
|
+
this.version = deps.version;
|
|
471
|
+
this.globalVariableBuilder = deps.globalVariableBuilder;
|
|
472
|
+
this.rollupContract = deps.rollupContract;
|
|
473
|
+
this.feeProvider = deps.feeProvider;
|
|
474
|
+
this.epochCache = deps.epochCache;
|
|
475
|
+
this.packageVersion = deps.packageVersion;
|
|
476
|
+
this.peerProofVerifier = deps.peerProofVerifier;
|
|
477
|
+
this.rpcProofVerifier = deps.rpcProofVerifier;
|
|
478
|
+
this.telemetry = deps.telemetry ?? getTelemetryClient();
|
|
479
|
+
this.log = deps.log ?? createLogger('node');
|
|
480
|
+
this.blobClient = deps.blobClient;
|
|
481
|
+
this.validatorClient = deps.validatorClient;
|
|
482
|
+
this.keyStoreManager = deps.keyStoreManager;
|
|
483
|
+
this.debugLogStore = deps.debugLogStore ?? new NullDebugLogStore();
|
|
484
|
+
this.automineSequencer = deps.automineSequencer;
|
|
485
|
+
this.avmSimulator = deps.avmSimulator;
|
|
486
|
+
this.metrics = new NodeMetrics(this.telemetry, 'AztecNodeService');
|
|
487
|
+
this.tracer = this.telemetry.getTracer('AztecNodeService');
|
|
488
|
+
// The node never represents a proposer's payout addresses, so the simulator zeroes coinbase and
|
|
489
|
+
// fee recipient. The signature context only needs chain id + rollup address (see signature_utils).
|
|
490
|
+
this.nodePublicCallsSimulator = new NodePublicCallsSimulator({
|
|
491
|
+
blockSource: this.blockSource,
|
|
492
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
493
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
494
|
+
contractDataSource: this.contractDataSource,
|
|
495
|
+
globalVariableBuilder: this.globalVariableBuilder,
|
|
496
|
+
rollupContract: this.rollupContract,
|
|
497
|
+
epochCache: this.epochCache,
|
|
498
|
+
signatureContext: {
|
|
499
|
+
chainId: this.l1ChainId,
|
|
500
|
+
rollupAddress: this.config.rollupAddress
|
|
501
|
+
},
|
|
502
|
+
config: this.config,
|
|
503
|
+
avmSimulator: this.avmSimulator,
|
|
504
|
+
telemetry: this.telemetry,
|
|
505
|
+
log: this.log.createChild('public-calls-simulator')
|
|
506
|
+
});
|
|
507
|
+
this.worldStateQueries = new NodeWorldStateQueries({
|
|
508
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
509
|
+
blockSource: this.blockSource,
|
|
510
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
511
|
+
log: this.log.createChild('world-state-queries')
|
|
512
|
+
});
|
|
513
|
+
this.blockProvider = new NodeBlockProvider(this.blockSource);
|
|
514
|
+
this.txReceiptBuilder = new NodeTxReceiptBuilder({
|
|
515
|
+
p2pClient: this.p2pClient,
|
|
516
|
+
blockSource: this.blockSource,
|
|
517
|
+
debugLogStore: this.debugLogStore
|
|
518
|
+
});
|
|
482
519
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
483
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
520
|
+
this.log.info(`Aztec Node started on chain 0x${this.l1ChainId.toString(16)}`, pickL1ContractAddresses(this.config));
|
|
521
|
+
// A defensive check that protects us against introducing a bug in the complex node creation flow. We must
|
|
522
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
523
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
524
|
+
if (this.debugLogStore.isEnabled && this.config.realProofs) {
|
|
525
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */ getProofVerifier() {
|
|
529
|
+
return this.rpcProofVerifier;
|
|
484
530
|
}
|
|
485
531
|
async getWorldStateSyncStatus() {
|
|
486
532
|
const status = await this.worldStateSynchronizer.status();
|
|
487
533
|
return status.syncSummary;
|
|
488
534
|
}
|
|
489
|
-
|
|
535
|
+
getChainTips() {
|
|
490
536
|
return this.blockSource.getL2Tips();
|
|
491
537
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
510
|
-
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
511
|
-
} else {
|
|
512
|
-
const keyStore = createKeyStoreForValidator(config);
|
|
513
|
-
if (keyStore) {
|
|
514
|
-
keyStoreManager = new KeystoreManager(keyStore);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
await keyStoreManager?.validateSigners();
|
|
518
|
-
// If we are a validator, verify our configuration before doing too much more.
|
|
519
|
-
if (!config.disableValidator) {
|
|
520
|
-
if (keyStoreManager === undefined) {
|
|
521
|
-
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
522
|
-
}
|
|
523
|
-
if (!keyStoreProvided) {
|
|
524
|
-
log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
|
|
525
|
-
}
|
|
526
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
527
|
-
}
|
|
528
|
-
// validate that the actual chain id matches that specified in configuration
|
|
529
|
-
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
530
|
-
throw new Error(`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`);
|
|
531
|
-
}
|
|
532
|
-
const publicClient = createPublicClient({
|
|
533
|
-
chain: ethereumChain.chainInfo,
|
|
534
|
-
transport: fallback(config.l1RpcUrls.map((url)=>http(url, {
|
|
535
|
-
batch: false
|
|
536
|
-
}))),
|
|
537
|
-
pollingInterval: config.viemPollingIntervalMS
|
|
538
|
-
});
|
|
539
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
540
|
-
// Overwrite the passed in vars.
|
|
541
|
-
config.l1Contracts = {
|
|
542
|
-
...config.l1Contracts,
|
|
543
|
-
...l1ContractsAddresses
|
|
544
|
-
};
|
|
545
|
-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
546
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
547
|
-
rollupContract.getL1GenesisTime(),
|
|
548
|
-
rollupContract.getSlotDuration(),
|
|
549
|
-
rollupContract.getVersion()
|
|
550
|
-
]);
|
|
551
|
-
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
552
|
-
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
553
|
-
log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
|
|
554
|
-
}
|
|
555
|
-
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
556
|
-
// attempt snapshot sync if possible
|
|
557
|
-
await trySnapshotSync(config, log);
|
|
558
|
-
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
559
|
-
dateProvider
|
|
560
|
-
});
|
|
561
|
-
const archiver = await createArchiver(config, {
|
|
562
|
-
blobClient,
|
|
563
|
-
epochCache,
|
|
564
|
-
telemetry,
|
|
565
|
-
dateProvider
|
|
566
|
-
}, {
|
|
567
|
-
blockUntilSync: !config.skipArchiverInitialSync
|
|
568
|
-
});
|
|
569
|
-
// now create the merkle trees and the world state synchronizer
|
|
570
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
571
|
-
const circuitVerifier = config.realProofs || config.debugForceTxProofVerification ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
572
|
-
if (!config.realProofs) {
|
|
573
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
574
|
-
}
|
|
575
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
576
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
577
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
578
|
-
// We should really not be modifying the config object
|
|
579
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
580
|
-
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
581
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder({
|
|
582
|
-
...config,
|
|
583
|
-
l1GenesisTime,
|
|
584
|
-
slotDuration: Number(slotDuration)
|
|
585
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
586
|
-
// We'll accumulate sentinel watchers here
|
|
587
|
-
const watchers = [];
|
|
588
|
-
// Create validator client if required
|
|
589
|
-
const validatorClient = await createValidatorClient(config, {
|
|
590
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
591
|
-
worldState: worldStateSynchronizer,
|
|
592
|
-
p2pClient,
|
|
593
|
-
telemetry,
|
|
594
|
-
dateProvider,
|
|
595
|
-
epochCache,
|
|
596
|
-
blockSource: archiver,
|
|
597
|
-
l1ToL2MessageSource: archiver,
|
|
598
|
-
keyStoreManager,
|
|
599
|
-
blobClient
|
|
600
|
-
});
|
|
601
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
602
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
603
|
-
// like attestations or auths will fail.
|
|
604
|
-
if (validatorClient) {
|
|
605
|
-
watchers.push(validatorClient);
|
|
606
|
-
if (!options.dontStartSequencer) {
|
|
607
|
-
await validatorClient.registerHandlers();
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
611
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
612
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
613
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
614
|
-
createBlockProposalHandler(config, {
|
|
615
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
616
|
-
worldState: worldStateSynchronizer,
|
|
617
|
-
epochCache,
|
|
618
|
-
blockSource: archiver,
|
|
619
|
-
l1ToL2MessageSource: archiver,
|
|
620
|
-
p2pClient,
|
|
621
|
-
dateProvider,
|
|
622
|
-
telemetry
|
|
623
|
-
}).registerForReexecution(p2pClient);
|
|
624
|
-
}
|
|
625
|
-
// Start world state and wait for it to sync to the archiver.
|
|
626
|
-
await worldStateSynchronizer.start();
|
|
627
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
628
|
-
await p2pClient.start();
|
|
629
|
-
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
630
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
631
|
-
watchers.push(validatorsSentinel);
|
|
632
|
-
}
|
|
633
|
-
let epochPruneWatcher;
|
|
634
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
635
|
-
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), validatorCheckpointsBuilder, config);
|
|
636
|
-
watchers.push(epochPruneWatcher);
|
|
637
|
-
}
|
|
638
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
639
|
-
let attestationsBlockWatcher;
|
|
640
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
641
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
642
|
-
watchers.push(attestationsBlockWatcher);
|
|
643
|
-
}
|
|
644
|
-
// Start p2p-related services once the archiver has completed sync
|
|
645
|
-
void archiver.waitForInitialSync().then(async ()=>{
|
|
646
|
-
await p2pClient.start();
|
|
647
|
-
await validatorsSentinel?.start();
|
|
648
|
-
await epochPruneWatcher?.start();
|
|
649
|
-
await attestationsBlockWatcher?.start();
|
|
650
|
-
log.info(`All p2p services started`);
|
|
651
|
-
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
652
|
-
// Validator enabled, create/start relevant service
|
|
653
|
-
let sequencer;
|
|
654
|
-
let slasherClient;
|
|
655
|
-
if (!config.disableValidator && validatorClient) {
|
|
656
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
657
|
-
// as they are executed when the node is selected as proposer.
|
|
658
|
-
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
659
|
-
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
660
|
-
await slasherClient.start();
|
|
661
|
-
const l1TxUtils = config.publisherForwarderAddress ? await createForwarderL1TxUtilsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), config.publisherForwarderAddress, {
|
|
662
|
-
...config,
|
|
663
|
-
scope: 'sequencer'
|
|
664
|
-
}, {
|
|
665
|
-
telemetry,
|
|
666
|
-
logger: log.createChild('l1-tx-utils'),
|
|
667
|
-
dateProvider
|
|
668
|
-
}) : await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
669
|
-
...config,
|
|
670
|
-
scope: 'sequencer'
|
|
671
|
-
}, {
|
|
672
|
-
telemetry,
|
|
673
|
-
logger: log.createChild('l1-tx-utils'),
|
|
674
|
-
dateProvider
|
|
675
|
-
});
|
|
676
|
-
// Create and start the sequencer client
|
|
677
|
-
const checkpointsBuilder = new CheckpointsBuilder({
|
|
678
|
-
...config,
|
|
679
|
-
l1GenesisTime,
|
|
680
|
-
slotDuration: Number(slotDuration)
|
|
681
|
-
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
682
|
-
sequencer = await SequencerClient.new(config, {
|
|
683
|
-
...deps,
|
|
684
|
-
epochCache,
|
|
685
|
-
l1TxUtils,
|
|
686
|
-
validatorClient,
|
|
687
|
-
p2pClient,
|
|
688
|
-
worldStateSynchronizer,
|
|
689
|
-
slasherClient,
|
|
690
|
-
checkpointsBuilder,
|
|
691
|
-
l2BlockSource: archiver,
|
|
692
|
-
l1ToL2MessageSource: archiver,
|
|
693
|
-
telemetry,
|
|
694
|
-
dateProvider,
|
|
695
|
-
blobClient,
|
|
696
|
-
nodeKeyStore: keyStoreManager
|
|
697
|
-
});
|
|
538
|
+
getL1Constants() {
|
|
539
|
+
return this.blockSource.getL1Constants();
|
|
540
|
+
}
|
|
541
|
+
getSyncedL2SlotNumber() {
|
|
542
|
+
return this.blockSource.getSyncedL2SlotNumber();
|
|
543
|
+
}
|
|
544
|
+
getSyncedL2EpochNumber() {
|
|
545
|
+
return this.blockSource.getSyncedL2EpochNumber();
|
|
546
|
+
}
|
|
547
|
+
getSyncedL1Timestamp() {
|
|
548
|
+
return this.blockSource.getL1Timestamp();
|
|
549
|
+
}
|
|
550
|
+
getCheckpointsData(query) {
|
|
551
|
+
return this.blockSource.getCheckpointsData(query);
|
|
552
|
+
}
|
|
553
|
+
async getBlockNumber(tip) {
|
|
554
|
+
if (tip === undefined || tip === 'proposed') {
|
|
555
|
+
return this.blockSource.getBlockNumber();
|
|
698
556
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
557
|
+
return await this.blockSource.getBlockNumber({
|
|
558
|
+
tag: tip
|
|
559
|
+
}) ?? BlockNumber.ZERO;
|
|
560
|
+
}
|
|
561
|
+
async getCheckpointNumber(tip) {
|
|
562
|
+
const tips = await this.blockSource.getL2Tips();
|
|
563
|
+
switch(tip){
|
|
564
|
+
case undefined:
|
|
565
|
+
case 'checkpointed':
|
|
566
|
+
return tips.checkpointed.checkpoint.number;
|
|
567
|
+
case 'proven':
|
|
568
|
+
return tips.proven.checkpoint.number;
|
|
569
|
+
case 'finalized':
|
|
570
|
+
return tips.finalized.checkpoint.number;
|
|
704
571
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
572
|
+
}
|
|
573
|
+
getBlock(param, options = {}) {
|
|
574
|
+
return this.blockProvider.getBlock(param, options);
|
|
575
|
+
}
|
|
576
|
+
getBlockData(param) {
|
|
577
|
+
return this.blockProvider.getBlockData(param);
|
|
578
|
+
}
|
|
579
|
+
getBlocks(from, limit, options = {}) {
|
|
580
|
+
return this.blockProvider.getBlocks(from, limit, options);
|
|
581
|
+
}
|
|
582
|
+
getCheckpoint(param, options = {}) {
|
|
583
|
+
return this.blockProvider.getCheckpoint(param, options);
|
|
584
|
+
}
|
|
585
|
+
getCheckpoints(from, limit, options = {}) {
|
|
586
|
+
return this.blockProvider.getCheckpoints(from, limit, options);
|
|
712
587
|
}
|
|
713
588
|
/**
|
|
714
589
|
* Returns the sequencer client instance.
|
|
@@ -716,6 +591,12 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
716
591
|
*/ getSequencer() {
|
|
717
592
|
return this.sequencer;
|
|
718
593
|
}
|
|
594
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */ getAutomineSequencer() {
|
|
595
|
+
return this.automineSequencer;
|
|
596
|
+
}
|
|
597
|
+
/** Returns the prover node subsystem, if enabled. */ getProverNode() {
|
|
598
|
+
return this.proverNode;
|
|
599
|
+
}
|
|
719
600
|
getBlockSource() {
|
|
720
601
|
return this.blockSource;
|
|
721
602
|
}
|
|
@@ -729,13 +610,16 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
729
610
|
* Method to return the currently deployed L1 contract addresses.
|
|
730
611
|
* @returns - The currently deployed L1 contract addresses.
|
|
731
612
|
*/ getL1ContractAddresses() {
|
|
732
|
-
return Promise.resolve(this.config
|
|
613
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
733
614
|
}
|
|
734
615
|
getEncodedEnr() {
|
|
735
616
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
736
617
|
}
|
|
737
618
|
async getAllowedPublicSetup() {
|
|
738
|
-
return
|
|
619
|
+
return [
|
|
620
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
621
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
622
|
+
];
|
|
739
623
|
}
|
|
740
624
|
/**
|
|
741
625
|
* Method to determine if the node is ready to accept transactions.
|
|
@@ -744,82 +628,47 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
744
628
|
return Promise.resolve(this.p2pClient.isReady() ?? false);
|
|
745
629
|
}
|
|
746
630
|
async getNodeInfo() {
|
|
747
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
631
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses, l1Constants] = await Promise.all([
|
|
748
632
|
this.getNodeVersion(),
|
|
749
633
|
this.getVersion(),
|
|
750
634
|
this.getChainId(),
|
|
751
635
|
this.getEncodedEnr(),
|
|
752
636
|
this.getL1ContractAddresses(),
|
|
753
|
-
this.getProtocolContractAddresses()
|
|
637
|
+
this.getProtocolContractAddresses(),
|
|
638
|
+
this.blockSource.getL1Constants()
|
|
754
639
|
]);
|
|
640
|
+
// Gas limits a single tx may declare on this network, derived from network-wide constants only (the
|
|
641
|
+
// timetable's blocks-per-checkpoint and the network-minimum per-block multipliers) — never this node's
|
|
642
|
+
// local caps or configured multipliers, which can make the node stricter at block-building time but
|
|
643
|
+
// cannot define what the network accepts for relay. Clients read txsLimits to set fallback gas limits.
|
|
644
|
+
const maxTxGas = getNetworkTxGasLimits(this.config, l1Constants);
|
|
755
645
|
const nodeInfo = {
|
|
756
646
|
nodeVersion,
|
|
757
647
|
l1ChainId: chainId,
|
|
758
648
|
rollupVersion,
|
|
759
649
|
enr,
|
|
760
650
|
l1ContractAddresses: contractAddresses,
|
|
761
|
-
protocolContractAddresses: protocolContractAddresses
|
|
651
|
+
protocolContractAddresses: protocolContractAddresses,
|
|
652
|
+
realProofs: !!this.config.realProofs,
|
|
653
|
+
txsLimits: {
|
|
654
|
+
gas: {
|
|
655
|
+
daGas: maxTxGas.daGas,
|
|
656
|
+
l2Gas: maxTxGas.l2Gas
|
|
657
|
+
}
|
|
658
|
+
}
|
|
762
659
|
};
|
|
763
660
|
return nodeInfo;
|
|
764
661
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
768
|
-
* @returns The requested block.
|
|
769
|
-
*/ async getBlock(block) {
|
|
770
|
-
if (BlockHash.isBlockHash(block)) {
|
|
771
|
-
return this.getBlockByHash(block);
|
|
772
|
-
}
|
|
773
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
774
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
775
|
-
return this.buildInitialBlock();
|
|
776
|
-
}
|
|
777
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
778
|
-
}
|
|
779
|
-
/**
|
|
780
|
-
* Get a block specified by its hash.
|
|
781
|
-
* @param blockHash - The block hash being requested.
|
|
782
|
-
* @returns The requested block.
|
|
783
|
-
*/ async getBlockByHash(blockHash) {
|
|
784
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
785
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
786
|
-
return this.buildInitialBlock();
|
|
787
|
-
}
|
|
788
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
789
|
-
}
|
|
790
|
-
buildInitialBlock() {
|
|
791
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
792
|
-
return L2Block.empty(initialHeader);
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Get a block specified by its archive root.
|
|
796
|
-
* @param archive - The archive root being requested.
|
|
797
|
-
* @returns The requested block.
|
|
798
|
-
*/ async getBlockByArchive(archive) {
|
|
799
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
803
|
-
* @param from - The start of the range of blocks to return.
|
|
804
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
805
|
-
* @returns The blocks requested.
|
|
806
|
-
*/ async getBlocks(from, limit) {
|
|
807
|
-
return await this.blockSource.getBlocks(from, BlockNumber(limit)) ?? [];
|
|
662
|
+
async getCurrentMinFees() {
|
|
663
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
808
664
|
}
|
|
809
|
-
async
|
|
810
|
-
return await this.
|
|
811
|
-
}
|
|
812
|
-
async getCheckpointedBlocks(from, limit) {
|
|
813
|
-
return await this.blockSource.getCheckpointedBlocks(from, limit) ?? [];
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Method to fetch the current min L2 fees.
|
|
817
|
-
* @returns The current min L2 fees.
|
|
818
|
-
*/ async getCurrentMinFees() {
|
|
819
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
665
|
+
/** Returns predicted min fees for the current slot and next N slots. */ async getPredictedMinFees(manaUsage) {
|
|
666
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
820
667
|
}
|
|
821
668
|
async getMaxPriorityFees() {
|
|
822
|
-
for await (const tx of this.p2pClient.iteratePendingTxs(
|
|
669
|
+
for await (const tx of this.p2pClient.iteratePendingTxs({
|
|
670
|
+
includeProof: false
|
|
671
|
+
})){
|
|
823
672
|
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
824
673
|
}
|
|
825
674
|
return GasFees.from({
|
|
@@ -828,18 +677,6 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
828
677
|
});
|
|
829
678
|
}
|
|
830
679
|
/**
|
|
831
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
832
|
-
* @returns The block number.
|
|
833
|
-
*/ async getBlockNumber() {
|
|
834
|
-
return await this.blockSource.getBlockNumber();
|
|
835
|
-
}
|
|
836
|
-
async getProvenBlockNumber() {
|
|
837
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
838
|
-
}
|
|
839
|
-
async getCheckpointedBlockNumber() {
|
|
840
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
680
|
* Method to fetch the version of the package.
|
|
844
681
|
* @returns The node package version
|
|
845
682
|
*/ getNodeVersion() {
|
|
@@ -860,46 +697,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
860
697
|
getContractClass(id) {
|
|
861
698
|
return this.contractDataSource.getContractClass(id);
|
|
862
699
|
}
|
|
863
|
-
getContract(address) {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
if (referenceBlock) {
|
|
868
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
869
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
870
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
871
|
-
if (!header) {
|
|
872
|
-
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
877
|
-
}
|
|
878
|
-
async getPublicLogsByTagsFromContract(contractAddress, tags, page, referenceBlock) {
|
|
879
|
-
if (referenceBlock) {
|
|
880
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
881
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
882
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
883
|
-
if (!header) {
|
|
884
|
-
throw new Error(`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
700
|
+
async getContract(address, referenceBlock = 'latest') {
|
|
701
|
+
const blockData = await this.getBlockData(referenceBlock);
|
|
702
|
+
if (!blockData) {
|
|
703
|
+
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.`);
|
|
887
704
|
}
|
|
888
|
-
return this.
|
|
705
|
+
return this.contractDataSource.getContract(address, blockData.header.globalVariables.timestamp);
|
|
889
706
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
* @param filter - The filter to apply to the logs.
|
|
893
|
-
* @returns The requested logs.
|
|
894
|
-
*/ getPublicLogs(filter) {
|
|
895
|
-
return this.logsSource.getPublicLogs(filter);
|
|
707
|
+
getPrivateLogsByTags(query) {
|
|
708
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
896
709
|
}
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
* @param filter - The filter to apply to the logs.
|
|
900
|
-
* @returns The requested logs.
|
|
901
|
-
*/ getContractClassLogs(filter) {
|
|
902
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
710
|
+
getPublicLogsByTags(query) {
|
|
711
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
903
712
|
}
|
|
904
713
|
/**
|
|
905
714
|
* Method to submit a transaction to the p2p pool.
|
|
@@ -919,31 +728,23 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
919
728
|
});
|
|
920
729
|
throw new Error(`Invalid tx: ${reason}`);
|
|
921
730
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
731
|
+
try {
|
|
732
|
+
await this.p2pClient.sendTx(tx);
|
|
733
|
+
} catch (err) {
|
|
734
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
735
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${err.message}`, {
|
|
736
|
+
txHash
|
|
737
|
+
});
|
|
738
|
+
throw err;
|
|
739
|
+
}
|
|
740
|
+
const duration = timer.ms();
|
|
741
|
+
this.metrics.receivedTx(duration, true);
|
|
742
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, {
|
|
925
743
|
txHash
|
|
926
744
|
});
|
|
927
745
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
// as a fallback if we don't find a settled receipt in the archiver.
|
|
931
|
-
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
932
|
-
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
933
|
-
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
934
|
-
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
935
|
-
if (settledTxReceipt) {
|
|
936
|
-
// If the archiver has the receipt then return it.
|
|
937
|
-
return settledTxReceipt;
|
|
938
|
-
} else if (isKnownToPool) {
|
|
939
|
-
// If the tx is in the pool but not in the archiver, it's pending.
|
|
940
|
-
// This handles race conditions between archiver and p2p, where the archiver
|
|
941
|
-
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
942
|
-
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
943
|
-
} else {
|
|
944
|
-
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
945
|
-
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
946
|
-
}
|
|
746
|
+
getTxReceipt(txHash, options) {
|
|
747
|
+
return this.txReceiptBuilder.getTxReceipt(txHash, options);
|
|
947
748
|
}
|
|
948
749
|
getTxEffect(txHash) {
|
|
949
750
|
return this.blockSource.getTxEffect(txHash);
|
|
@@ -952,12 +753,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
952
753
|
* Method to stop the aztec node.
|
|
953
754
|
*/ async stop() {
|
|
954
755
|
this.log.info(`Stopping Aztec Node`);
|
|
955
|
-
await
|
|
956
|
-
await tryStop(this.epochPruneWatcher);
|
|
756
|
+
await this.stopStartedWatchers();
|
|
957
757
|
await tryStop(this.slasherClient);
|
|
958
|
-
await
|
|
758
|
+
await Promise.all([
|
|
759
|
+
tryStop(this.peerProofVerifier),
|
|
760
|
+
tryStop(this.rpcProofVerifier)
|
|
761
|
+
]);
|
|
959
762
|
await tryStop(this.sequencer);
|
|
763
|
+
await tryStop(this.automineSequencer);
|
|
764
|
+
await tryStop(this.proverNode);
|
|
960
765
|
await tryStop(this.p2pClient);
|
|
766
|
+
// Dispose the AVM backend before world state: it kills the bb-avm-sim processes and closes the CDB IPC
|
|
767
|
+
// server, releasing their connections to the WSDB so it shuts down cleanly (and freeing the
|
|
768
|
+
// Server/Socket/ChildProcess handles that would otherwise keep the process alive after teardown).
|
|
769
|
+
await this.avmSimulator?.[Symbol.asyncDispose]();
|
|
961
770
|
await tryStop(this.worldStateSynchronizer);
|
|
962
771
|
await tryStop(this.blockSource);
|
|
963
772
|
await tryStop(this.blobClient);
|
|
@@ -975,293 +784,120 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
975
784
|
* @param limit - The number of items to returns
|
|
976
785
|
* @param after - The last known pending tx. Used for pagination
|
|
977
786
|
* @returns - The pending txs.
|
|
978
|
-
*/ getPendingTxs(limit, after) {
|
|
979
|
-
return this.p2pClient.getPendingTxs(limit, after);
|
|
787
|
+
*/ getPendingTxs(limit, after, options) {
|
|
788
|
+
return this.p2pClient.getPendingTxs(limit, after, options);
|
|
980
789
|
}
|
|
981
790
|
getPendingTxCount() {
|
|
982
791
|
return this.p2pClient.getPendingTxCount();
|
|
983
792
|
}
|
|
793
|
+
getPeers(includePending) {
|
|
794
|
+
return this.p2pClient.getPeers(includePending);
|
|
795
|
+
}
|
|
796
|
+
getCheckpointAttestationsForSlot(slot, proposalPayloadHash) {
|
|
797
|
+
return this.p2pClient.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
798
|
+
}
|
|
799
|
+
getProposalsForSlot(slot) {
|
|
800
|
+
return this.p2pClient.getProposalsForSlot(slot);
|
|
801
|
+
}
|
|
984
802
|
/**
|
|
985
|
-
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
803
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain. The tx's proof is only loaded and returned
|
|
804
|
+
* when `includeProof` is set.
|
|
986
805
|
* @param txHash - The transaction hash to return.
|
|
806
|
+
* @param options - Options for the returned tx (eg whether to include its proof).
|
|
987
807
|
* @returns - The tx if it exists.
|
|
988
|
-
*/ getTxByHash(txHash) {
|
|
989
|
-
return
|
|
808
|
+
*/ getTxByHash(txHash, options) {
|
|
809
|
+
return this.p2pClient.getTxByHashFromPool(txHash, {
|
|
810
|
+
includeProof: !!options?.includeProof
|
|
811
|
+
});
|
|
990
812
|
}
|
|
991
813
|
/**
|
|
992
|
-
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
814
|
+
* Method to retrieve txs from the mempool or unfinalized chain. The txs' proofs are only loaded and returned when
|
|
815
|
+
* `includeProof` is set.
|
|
993
816
|
* @param txHash - The transaction hash to return.
|
|
817
|
+
* @param options - Options for the returned txs (eg whether to include their proofs).
|
|
994
818
|
* @returns - The txs if it exists.
|
|
995
|
-
*/ async getTxsByHash(txHashes) {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
async findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
999
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1000
|
-
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
1001
|
-
// We filter out undefined values
|
|
1002
|
-
const indices = maybeIndices.filter((x)=>x !== undefined);
|
|
1003
|
-
// Now we find the block numbers for the indices
|
|
1004
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
|
|
1005
|
-
// If any of the block numbers are undefined, we throw an error.
|
|
1006
|
-
for(let i = 0; i < indices.length; i++){
|
|
1007
|
-
if (blockNumbers[i] === undefined) {
|
|
1008
|
-
throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1012
|
-
const uniqueBlockNumbers = [
|
|
1013
|
-
...new Set(blockNumbers.filter((x)=>x !== undefined))
|
|
1014
|
-
];
|
|
1015
|
-
// Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
|
|
1016
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1017
|
-
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
1018
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1019
|
-
}));
|
|
1020
|
-
// If any of the block hashes are undefined, we throw an error.
|
|
1021
|
-
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
1022
|
-
if (blockHashes[i] === undefined) {
|
|
1023
|
-
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1027
|
-
return maybeIndices.map((index, i)=>{
|
|
1028
|
-
if (index === undefined) {
|
|
1029
|
-
return undefined;
|
|
1030
|
-
}
|
|
1031
|
-
const blockNumber = blockNumbers[i];
|
|
1032
|
-
if (blockNumber === undefined) {
|
|
1033
|
-
return undefined;
|
|
1034
|
-
}
|
|
1035
|
-
const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
|
|
1036
|
-
const blockHash = blockHashes[blockHashIndex];
|
|
1037
|
-
if (!blockHash) {
|
|
1038
|
-
return undefined;
|
|
1039
|
-
}
|
|
1040
|
-
return {
|
|
1041
|
-
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
1042
|
-
l2BlockHash: new BlockHash(blockHash),
|
|
1043
|
-
data: index
|
|
1044
|
-
};
|
|
819
|
+
*/ async getTxsByHash(txHashes, options) {
|
|
820
|
+
const txs = await this.p2pClient.getTxsByHashFromPool(txHashes, {
|
|
821
|
+
includeProof: !!options?.includeProof
|
|
1045
822
|
});
|
|
823
|
+
return compactArray(txs);
|
|
1046
824
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
1050
|
-
blockHash
|
|
1051
|
-
]);
|
|
1052
|
-
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
825
|
+
findLeavesIndexes(referenceBlock, treeId, leafValues) {
|
|
826
|
+
return this.worldStateQueries.findLeavesIndexes(referenceBlock, treeId, leafValues);
|
|
1053
827
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
1057
|
-
noteHash
|
|
1058
|
-
]);
|
|
1059
|
-
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
828
|
+
getBlockHashMembershipWitness(referenceBlock, blockHash) {
|
|
829
|
+
return this.worldStateQueries.getBlockHashMembershipWitness(referenceBlock, blockHash);
|
|
1060
830
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
1064
|
-
l1ToL2Message
|
|
1065
|
-
]);
|
|
1066
|
-
if (!witness) {
|
|
1067
|
-
return undefined;
|
|
1068
|
-
}
|
|
1069
|
-
// REFACTOR: Return a MembershipWitness object
|
|
1070
|
-
return [
|
|
1071
|
-
witness.index,
|
|
1072
|
-
witness.path
|
|
1073
|
-
];
|
|
831
|
+
getNoteHashMembershipWitness(referenceBlock, noteHash) {
|
|
832
|
+
return this.worldStateQueries.getNoteHashMembershipWitness(referenceBlock, noteHash);
|
|
1074
833
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
return messageIndex ? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex)) : undefined;
|
|
834
|
+
getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message) {
|
|
835
|
+
return this.worldStateQueries.getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message);
|
|
1078
836
|
}
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
1082
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
1083
|
-
*/ async isL1ToL2MessageSynced(l1ToL2Message) {
|
|
1084
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1085
|
-
return messageIndex !== undefined;
|
|
837
|
+
getL1ToL2MessageCheckpoint(l1ToL2Message) {
|
|
838
|
+
return this.worldStateQueries.getL1ToL2MessageCheckpoint(l1ToL2Message);
|
|
1086
839
|
}
|
|
1087
840
|
/**
|
|
1088
841
|
* Returns all the L2 to L1 messages in an epoch.
|
|
842
|
+
*
|
|
843
|
+
* @deprecated Use {@link getL2ToL1MembershipWitness} to get an L2-to-L1 message witness directly.
|
|
844
|
+
*
|
|
1089
845
|
* @param epoch - The epoch at which to get the data.
|
|
1090
846
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1091
|
-
*/
|
|
1092
|
-
|
|
1093
|
-
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1094
|
-
const blocksInCheckpoints = [];
|
|
1095
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1096
|
-
let checkpointIndex = -1;
|
|
1097
|
-
for (const checkpointedBlock of checkpointedBlocks){
|
|
1098
|
-
const block = checkpointedBlock.block;
|
|
1099
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1100
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1101
|
-
checkpointIndex++;
|
|
1102
|
-
blocksInCheckpoints.push([]);
|
|
1103
|
-
previousSlotNumber = slotNumber;
|
|
1104
|
-
}
|
|
1105
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1106
|
-
}
|
|
1107
|
-
return blocksInCheckpoints.map((blocks)=>blocks.map((block)=>block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs)));
|
|
1108
|
-
}
|
|
1109
|
-
async getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1110
|
-
const db = await this.#getWorldState(referenceBlock);
|
|
1111
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
1112
|
-
nullifier.toBuffer()
|
|
1113
|
-
]);
|
|
1114
|
-
if (!witness) {
|
|
1115
|
-
return undefined;
|
|
1116
|
-
}
|
|
1117
|
-
const { index, path } = witness;
|
|
1118
|
-
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1119
|
-
if (!leafPreimage) {
|
|
1120
|
-
return undefined;
|
|
1121
|
-
}
|
|
1122
|
-
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
847
|
+
*/ getL2ToL1Messages(epoch) {
|
|
848
|
+
return this.worldStateQueries.getL2ToL1Messages(epoch);
|
|
1123
849
|
}
|
|
1124
850
|
/**
|
|
1125
|
-
* Returns
|
|
1126
|
-
*
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
* @returns The low nullifier membership witness (if found).
|
|
1130
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1131
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1132
|
-
* we are trying to prove non-inclusion for.
|
|
1133
|
-
*
|
|
1134
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1135
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1136
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1137
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1138
|
-
*/ async getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
1139
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1140
|
-
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1141
|
-
if (!findResult) {
|
|
1142
|
-
return undefined;
|
|
1143
|
-
}
|
|
1144
|
-
const { index, alreadyPresent } = findResult;
|
|
1145
|
-
if (alreadyPresent) {
|
|
1146
|
-
this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1147
|
-
}
|
|
1148
|
-
const preimageData = await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1149
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1150
|
-
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
1151
|
-
}
|
|
1152
|
-
async getPublicDataWitness(referenceBlock, leafSlot) {
|
|
1153
|
-
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1154
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1155
|
-
if (!lowLeafResult) {
|
|
1156
|
-
return undefined;
|
|
1157
|
-
} else {
|
|
1158
|
-
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1159
|
-
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1160
|
-
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1161
|
-
}
|
|
851
|
+
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
852
|
+
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
853
|
+
*/ getL2ToL1MembershipWitness(txHash, message, messageIndexInTx) {
|
|
854
|
+
return this.worldStateQueries.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1162
855
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1166
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1167
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
1168
|
-
return Fr.ZERO;
|
|
1169
|
-
}
|
|
1170
|
-
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1171
|
-
return preimage.leaf.value;
|
|
1172
|
-
}
|
|
1173
|
-
async getBlockHeader(block = 'latest') {
|
|
1174
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1175
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1176
|
-
if (block.equals(initialBlockHash)) {
|
|
1177
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1178
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1179
|
-
}
|
|
1180
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1181
|
-
} else {
|
|
1182
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1183
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : block;
|
|
1184
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1185
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1186
|
-
}
|
|
1187
|
-
return this.blockSource.getBlockHeader(block);
|
|
1188
|
-
}
|
|
856
|
+
getNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
857
|
+
return this.worldStateQueries.getNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1189
858
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
859
|
+
getLowNullifierMembershipWitness(referenceBlock, nullifier) {
|
|
860
|
+
return this.worldStateQueries.getLowNullifierMembershipWitness(referenceBlock, nullifier);
|
|
861
|
+
}
|
|
862
|
+
getPublicDataWitness(referenceBlock, leafSlot) {
|
|
863
|
+
return this.worldStateQueries.getPublicDataWitness(referenceBlock, leafSlot);
|
|
864
|
+
}
|
|
865
|
+
getPublicStorageAt(referenceBlock, contract, slot) {
|
|
866
|
+
return this.worldStateQueries.getPublicStorageAt(referenceBlock, contract, slot);
|
|
1196
867
|
}
|
|
1197
868
|
/**
|
|
1198
869
|
* Simulates the public part of a transaction with the current state.
|
|
1199
870
|
* @param tx - The transaction to simulate.
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1205
|
-
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1206
|
-
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
1207
|
-
}
|
|
1208
|
-
const txHash = tx.getTxHash();
|
|
1209
|
-
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1210
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1211
|
-
const coinbase = EthAddress.ZERO;
|
|
1212
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1213
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
1214
|
-
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry, this.log.getBindings());
|
|
1215
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1216
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1217
|
-
txHash,
|
|
1218
|
-
blockNumber
|
|
1219
|
-
});
|
|
1220
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1221
|
-
try {
|
|
1222
|
-
const config = PublicSimulatorConfig.from({
|
|
1223
|
-
skipFeeEnforcement,
|
|
1224
|
-
collectDebugLogs: true,
|
|
1225
|
-
collectHints: false,
|
|
1226
|
-
collectCallMetadata: true,
|
|
1227
|
-
collectStatistics: false,
|
|
1228
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1229
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads
|
|
1230
|
-
})
|
|
1231
|
-
});
|
|
1232
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1233
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1234
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
1235
|
-
tx
|
|
1236
|
-
]);
|
|
1237
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1238
|
-
if (failedTxs.length) {
|
|
1239
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, {
|
|
1240
|
-
txHash
|
|
1241
|
-
});
|
|
1242
|
-
throw failedTxs[0].error;
|
|
1243
|
-
}
|
|
1244
|
-
const [processedTx] = processedTxs;
|
|
1245
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
1246
|
-
} finally{
|
|
1247
|
-
await merkleTreeFork.close();
|
|
1248
|
-
}
|
|
871
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
872
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
873
|
+
**/ simulatePublicCalls(tx, skipFeeEnforcement = false, overrides) {
|
|
874
|
+
return this.nodePublicCallsSimulator.simulate(tx, skipFeeEnforcement, overrides);
|
|
1249
875
|
}
|
|
1250
876
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
1251
877
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1252
|
-
const verifier = isSimulation ? undefined : this.
|
|
1253
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
878
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
879
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1254
880
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1255
881
|
const blockNumber = BlockNumber(await this.blockSource.getBlockNumber() + 1);
|
|
1256
|
-
const
|
|
882
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
883
|
+
// Enforce the same network admission limit the node advertises in getNodeInfo (network-wide, not this
|
|
884
|
+
// node's local caps), so a tx the wallet sized against txsLimits is not rejected here.
|
|
885
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
886
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(db, this.contractDataSource, verifier, {
|
|
1257
887
|
timestamp: nextSlotTimestamp,
|
|
1258
888
|
blockNumber,
|
|
1259
889
|
l1ChainId: this.l1ChainId,
|
|
1260
890
|
rollupVersion: this.version,
|
|
1261
|
-
setupAllowList:
|
|
891
|
+
setupAllowList: [
|
|
892
|
+
...await getDefaultAllowedSetupFunctions(),
|
|
893
|
+
...this.config.txPublicSetupAllowListExtend ?? []
|
|
894
|
+
],
|
|
1262
895
|
gasFees: await this.getCurrentMinFees(),
|
|
1263
896
|
skipFeeEnforcement,
|
|
1264
|
-
|
|
897
|
+
isSimulation,
|
|
898
|
+
txsPermitted: !this.config.disableTransactions,
|
|
899
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
900
|
+
maxTxDAGas: networkTxGasLimits.daGas
|
|
1265
901
|
}, this.log.getBindings());
|
|
1266
902
|
return await validator.validateTx(tx);
|
|
1267
903
|
}
|
|
@@ -1275,7 +911,20 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1275
911
|
...this.config,
|
|
1276
912
|
...config
|
|
1277
913
|
};
|
|
1278
|
-
|
|
914
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
915
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
916
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
917
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
918
|
+
// pauseSequencer() still considers it paused.
|
|
919
|
+
const sequencerUpdate = {
|
|
920
|
+
...config
|
|
921
|
+
};
|
|
922
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
923
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
924
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
925
|
+
}
|
|
926
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
927
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
1279
928
|
this.slasherClient?.updateConfig(config);
|
|
1280
929
|
this.validatorsSentinel?.updateConfig(config);
|
|
1281
930
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1284,7 +933,18 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1284
933
|
archiver.updateConfig(config);
|
|
1285
934
|
}
|
|
1286
935
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1287
|
-
|
|
936
|
+
await Promise.all([
|
|
937
|
+
tryStop(this.peerProofVerifier),
|
|
938
|
+
tryStop(this.rpcProofVerifier)
|
|
939
|
+
]);
|
|
940
|
+
if (newConfig.realProofs) {
|
|
941
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
942
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
943
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
944
|
+
} else {
|
|
945
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
946
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
947
|
+
}
|
|
1288
948
|
}
|
|
1289
949
|
this.config = newConfig;
|
|
1290
950
|
}
|
|
@@ -1293,7 +953,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1293
953
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1294
954
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1295
955
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1296
|
-
multiCallEntrypoint:
|
|
956
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS
|
|
1297
957
|
});
|
|
1298
958
|
}
|
|
1299
959
|
registerContractFunctionSignatures(signatures) {
|
|
@@ -1344,7 +1004,7 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1344
1004
|
});
|
|
1345
1005
|
return Promise.resolve();
|
|
1346
1006
|
}
|
|
1347
|
-
async rollbackTo(targetBlock, force) {
|
|
1007
|
+
async rollbackTo(targetBlock, force, resumeSync = true) {
|
|
1348
1008
|
const archiver = this.blockSource;
|
|
1349
1009
|
if (!('rollbackTo' in archiver)) {
|
|
1350
1010
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1372,9 +1032,13 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1372
1032
|
this.log.error(`Error during rollback`, err);
|
|
1373
1033
|
throw err;
|
|
1374
1034
|
} finally{
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1035
|
+
if (resumeSync) {
|
|
1036
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1037
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1038
|
+
archiver.resume();
|
|
1039
|
+
} else {
|
|
1040
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1041
|
+
}
|
|
1378
1042
|
}
|
|
1379
1043
|
}
|
|
1380
1044
|
async pauseSync() {
|
|
@@ -1388,73 +1052,176 @@ _dec = trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
|
1388
1052
|
this.blockSource.resume();
|
|
1389
1053
|
return Promise.resolve();
|
|
1390
1054
|
}
|
|
1391
|
-
|
|
1392
|
-
if (
|
|
1393
|
-
|
|
1055
|
+
pauseSequencer() {
|
|
1056
|
+
if (this.automineSequencer) {
|
|
1057
|
+
this.automineSequencer.pause();
|
|
1058
|
+
return Promise.resolve();
|
|
1059
|
+
}
|
|
1060
|
+
if (this.sequencer) {
|
|
1061
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
1062
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
1063
|
+
this.sequencer.updateConfig({
|
|
1064
|
+
minTxsPerBlock: Number.MAX_SAFE_INTEGER
|
|
1065
|
+
});
|
|
1066
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
1067
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
return Promise.resolve();
|
|
1071
|
+
}
|
|
1072
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
1073
|
+
}
|
|
1074
|
+
resumeSequencer() {
|
|
1075
|
+
if (this.automineSequencer) {
|
|
1076
|
+
this.automineSequencer.resume();
|
|
1077
|
+
return Promise.resolve();
|
|
1078
|
+
}
|
|
1079
|
+
if (this.sequencer) {
|
|
1080
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
1081
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
1082
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
1083
|
+
this.sequencer.updateConfig({
|
|
1084
|
+
minTxsPerBlock: restored
|
|
1085
|
+
});
|
|
1086
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, {
|
|
1087
|
+
minTxsPerBlock: restored
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
return Promise.resolve();
|
|
1394
1091
|
}
|
|
1395
|
-
|
|
1092
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1396
1093
|
}
|
|
1397
1094
|
getSlashOffenses(round) {
|
|
1398
1095
|
if (!this.slasherClient) {
|
|
1399
1096
|
throw new Error(`Slasher client not enabled`);
|
|
1400
1097
|
}
|
|
1401
1098
|
if (round === 'all') {
|
|
1402
|
-
return this.slasherClient.
|
|
1099
|
+
return this.slasherClient.getOffenses();
|
|
1403
1100
|
} else {
|
|
1404
1101
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1405
1102
|
}
|
|
1406
1103
|
}
|
|
1407
|
-
|
|
1408
|
-
if (!this.
|
|
1409
|
-
|
|
1104
|
+
async reloadKeystore() {
|
|
1105
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1106
|
+
throw new BadRequestError('Cannot reload keystore: node is not using a file-based keystore. ' + 'Set KEY_STORE_DIRECTORY to use file-based keystores.');
|
|
1107
|
+
}
|
|
1108
|
+
if (!this.validatorClient) {
|
|
1109
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1110
|
+
}
|
|
1111
|
+
this.log.info('Reloading keystore from disk');
|
|
1112
|
+
// Re-read and validate keystore files
|
|
1113
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1114
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1115
|
+
await newManager.validateSigners();
|
|
1116
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1117
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1118
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1119
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1120
|
+
// would silently fail on every proposer slot.
|
|
1121
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1122
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1123
|
+
const availablePublishers = new Set(oldAdapter.getAttesterAddresses().flatMap((a)=>oldAdapter.getPublisherAddresses(a).map((p)=>p.toString().toLowerCase())));
|
|
1124
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1125
|
+
for (const attester of newAdapter.getAttesterAddresses()){
|
|
1126
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1127
|
+
if (pubs.length > 0 && !pubs.some((p)=>availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1128
|
+
throw new BadRequestError(`Cannot reload keystore: validator ${attester} has publisher keys ` + `[${pubs.map((p)=>p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` + `[${[
|
|
1129
|
+
...availablePublishers
|
|
1130
|
+
].join(', ')}]. Publishers cannot be hot-reloaded — ` + `use an existing publisher key or restart the node.`);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1410
1133
|
}
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1134
|
+
// Build adapters for old and new keystores to compute diff
|
|
1135
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1136
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1137
|
+
const oldAddresses = this.keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses() : [];
|
|
1138
|
+
const oldSet = new Set(oldAddresses.map((a)=>a.toString()));
|
|
1139
|
+
const newSet = new Set(newAddresses.map((a)=>a.toString()));
|
|
1140
|
+
const added = newAddresses.filter((a)=>!oldSet.has(a.toString()));
|
|
1141
|
+
const removed = oldAddresses.filter((a)=>!newSet.has(a.toString()));
|
|
1142
|
+
if (added.length > 0) {
|
|
1143
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map((a)=>a.toString()).join(', ')}`);
|
|
1144
|
+
}
|
|
1145
|
+
if (removed.length > 0) {
|
|
1146
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map((a)=>a.toString()).join(', ')}`);
|
|
1147
|
+
}
|
|
1148
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1149
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1150
|
+
}
|
|
1151
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1152
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1153
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1154
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1155
|
+
if (this.sequencer) {
|
|
1156
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1157
|
+
}
|
|
1158
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1159
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1160
|
+
const slashValidatorsNever = unique([
|
|
1161
|
+
...this.config.slashValidatorsNever ?? [],
|
|
1162
|
+
...newAddresses
|
|
1163
|
+
].map((a)=>a.toString())).map(EthAddress.fromString);
|
|
1164
|
+
this.slasherClient.updateConfig({
|
|
1165
|
+
slashValidatorsNever
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
this.keyStoreManager = newManager;
|
|
1169
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1170
|
+
}
|
|
1171
|
+
async mineBlock() {
|
|
1172
|
+
if (this.automineSequencer) {
|
|
1173
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
if (!this.sequencer) {
|
|
1177
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1178
|
+
}
|
|
1179
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1180
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1181
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1182
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1183
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1184
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1185
|
+
this.sequencer.updateConfig({
|
|
1186
|
+
minTxsPerBlock: 0
|
|
1187
|
+
});
|
|
1419
1188
|
try {
|
|
1420
|
-
//
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1189
|
+
// Trigger the sequencer to produce a block immediately
|
|
1190
|
+
void this.sequencer.trigger();
|
|
1191
|
+
// Wait for the new L2 block to appear
|
|
1192
|
+
await retryUntil(async ()=>{
|
|
1193
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1194
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1195
|
+
}, 'mineBlock', timeoutSeconds, 0.1);
|
|
1196
|
+
} finally{
|
|
1197
|
+
this.sequencer.updateConfig({
|
|
1198
|
+
minTxsPerBlock: originalMinTxsPerBlock
|
|
1199
|
+
});
|
|
1424
1200
|
}
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1201
|
+
}
|
|
1202
|
+
async prove(upToCheckpoint) {
|
|
1203
|
+
if (!this.automineSequencer) {
|
|
1204
|
+
throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
|
|
1428
1205
|
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1436
|
-
if (!header) {
|
|
1437
|
-
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.`);
|
|
1438
|
-
}
|
|
1439
|
-
const blockNumber = header.getBlockNumber();
|
|
1440
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1441
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1206
|
+
return await this.automineSequencer.prove(upToCheckpoint);
|
|
1207
|
+
}
|
|
1208
|
+
async warpL2TimeAtLeastTo(targetTimestamp) {
|
|
1209
|
+
if (!this.automineSequencer) {
|
|
1210
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
1442
1211
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1450
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1212
|
+
await this.automineSequencer.warpTo(targetTimestamp);
|
|
1213
|
+
}
|
|
1214
|
+
async warpL2TimeAtLeastBy(duration) {
|
|
1215
|
+
if (!this.automineSequencer) {
|
|
1216
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
1451
1217
|
}
|
|
1218
|
+
await this.automineSequencer.warpBy(duration);
|
|
1452
1219
|
}
|
|
1453
1220
|
/**
|
|
1454
|
-
*
|
|
1455
|
-
* @
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
return
|
|
1221
|
+
* Returns a committed world-state view at `block`, driving sync first. Delegates to
|
|
1222
|
+
* {@link NodeWorldStateQueries.getWorldState}; kept as a protected method so subclasses and tests can
|
|
1223
|
+
* exercise the node's block-resolution and reorg-aware sync behavior.
|
|
1224
|
+
*/ getWorldState(block) {
|
|
1225
|
+
return this.worldStateQueries.getWorldState(block);
|
|
1459
1226
|
}
|
|
1460
1227
|
}
|