@aztec/aztec-node 0.0.1-commit.6d3c34e → 0.0.1-commit.7ac86ea28
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 +7 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -2
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +8 -4
- package/dest/aztec-node/server.d.ts +39 -93
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +294 -178
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +53 -27
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +28 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +370 -241
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +56 -23
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
3
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
4
|
+
import { Blob } from '@aztec/blob-lib';
|
|
5
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
14
8
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
15
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
16
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
17
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
18
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
19
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
20
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
21
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -23,15 +17,14 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
23
17
|
import { count } from '@aztec/foundation/string';
|
|
24
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
25
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
26
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
27
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
28
|
-
import {
|
|
29
|
-
createForwarderL1TxUtilsFromEthSigner,
|
|
30
|
-
createL1TxUtilsWithBlobsFromEthSigner,
|
|
31
|
-
} from '@aztec/node-lib/factories';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
32
23
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
24
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
25
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
26
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
27
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
35
28
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
29
|
import {
|
|
37
30
|
AttestationsBlockWatcher,
|
|
@@ -43,13 +36,12 @@ import {
|
|
|
43
36
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
38
|
import {
|
|
39
|
+
type BlockData,
|
|
40
|
+
BlockHash,
|
|
46
41
|
type BlockParameter,
|
|
47
42
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockHash,
|
|
50
|
-
L2BlockNew,
|
|
43
|
+
L2Block,
|
|
51
44
|
type L2BlockSource,
|
|
52
|
-
type PublishedL2Block,
|
|
53
45
|
} from '@aztec/stdlib/block';
|
|
54
46
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
55
47
|
import type {
|
|
@@ -128,6 +120,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
120
|
*/
|
|
129
121
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
122
|
private metrics: NodeMetrics;
|
|
123
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
124
|
|
|
132
125
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
126
|
private isUploadingSnapshot = false;
|
|
@@ -143,6 +136,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
143
136
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
144
137
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
145
138
|
protected readonly sequencer: SequencerClient | undefined,
|
|
139
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
146
140
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
147
141
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
148
142
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -155,6 +149,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
155
149
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
156
150
|
private log = createLogger('node'),
|
|
157
151
|
private blobClient?: BlobClientInterface,
|
|
152
|
+
private validatorClient?: ValidatorClient,
|
|
153
|
+
private keyStoreManager?: KeystoreManager,
|
|
158
154
|
) {
|
|
159
155
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
156
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
@@ -185,10 +181,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
185
181
|
publisher?: SequencerPublisher;
|
|
186
182
|
dateProvider?: DateProvider;
|
|
187
183
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
184
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
188
185
|
} = {},
|
|
189
186
|
options: {
|
|
190
187
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
191
188
|
dontStartSequencer?: boolean;
|
|
189
|
+
dontStartProverNode?: boolean;
|
|
192
190
|
} = {},
|
|
193
191
|
): Promise<AztecNodeService> {
|
|
194
192
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -198,16 +196,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
198
196
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
199
197
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
200
198
|
|
|
201
|
-
// Build a key store from file if given or from environment otherwise
|
|
199
|
+
// Build a key store from file if given or from environment otherwise.
|
|
200
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
202
201
|
let keyStoreManager: KeystoreManager | undefined;
|
|
203
202
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
204
203
|
if (keyStoreProvided) {
|
|
205
204
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
206
205
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
207
206
|
} else {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
const rawKeyStores: KeyStore[] = [];
|
|
208
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
209
|
+
if (validatorKeyStore) {
|
|
210
|
+
rawKeyStores.push(validatorKeyStore);
|
|
211
|
+
}
|
|
212
|
+
if (config.enableProverNode) {
|
|
213
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
214
|
+
if (proverKeyStore) {
|
|
215
|
+
rawKeyStores.push(proverKeyStore);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (rawKeyStores.length > 0) {
|
|
219
|
+
keyStoreManager = new KeystoreManager(
|
|
220
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
221
|
+
);
|
|
211
222
|
}
|
|
212
223
|
}
|
|
213
224
|
|
|
@@ -218,10 +229,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
218
229
|
if (keyStoreManager === undefined) {
|
|
219
230
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
220
231
|
}
|
|
221
|
-
if (!keyStoreProvided) {
|
|
222
|
-
log.warn(
|
|
223
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
224
|
-
);
|
|
232
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
233
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
225
234
|
}
|
|
226
235
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
227
236
|
}
|
|
@@ -263,7 +272,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
263
272
|
);
|
|
264
273
|
}
|
|
265
274
|
|
|
266
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
275
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
267
276
|
|
|
268
277
|
// attempt snapshot sync if possible
|
|
269
278
|
await trySnapshotSync(config, log);
|
|
@@ -309,18 +318,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
309
318
|
// We should really not be modifying the config object
|
|
310
319
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
311
320
|
|
|
312
|
-
// Create BlockBuilder for EpochPruneWatcher (slasher functionality)
|
|
313
|
-
const blockBuilder = new BlockBuilder(
|
|
314
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
|
-
worldStateSynchronizer,
|
|
316
|
-
archiver,
|
|
317
|
-
dateProvider,
|
|
318
|
-
telemetry,
|
|
319
|
-
);
|
|
320
|
-
|
|
321
321
|
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
322
322
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
323
323
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
324
|
+
worldStateSynchronizer,
|
|
324
325
|
archiver,
|
|
325
326
|
dateProvider,
|
|
326
327
|
telemetry,
|
|
@@ -330,7 +331,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
330
331
|
const watchers: Watcher[] = [];
|
|
331
332
|
|
|
332
333
|
// Create validator client if required
|
|
333
|
-
const validatorClient = createValidatorClient(config, {
|
|
334
|
+
const validatorClient = await createValidatorClient(config, {
|
|
334
335
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
335
336
|
worldState: worldStateSynchronizer,
|
|
336
337
|
p2pClient,
|
|
@@ -387,7 +388,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
387
388
|
archiver,
|
|
388
389
|
epochCache,
|
|
389
390
|
p2pClient.getTxProvider(),
|
|
390
|
-
|
|
391
|
+
validatorCheckpointsBuilder,
|
|
391
392
|
config,
|
|
392
393
|
);
|
|
393
394
|
watchers.push(epochPruneWatcher);
|
|
@@ -434,24 +435,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
434
435
|
);
|
|
435
436
|
await slasherClient.start();
|
|
436
437
|
|
|
437
|
-
const l1TxUtils = config.
|
|
438
|
-
? await
|
|
438
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
439
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
439
440
|
publicClient,
|
|
440
441
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
441
|
-
config.
|
|
442
|
+
config.sequencerPublisherForwarderAddress,
|
|
442
443
|
{ ...config, scope: 'sequencer' },
|
|
443
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
444
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
444
445
|
)
|
|
445
|
-
: await
|
|
446
|
+
: await createL1TxUtilsFromSigners(
|
|
446
447
|
publicClient,
|
|
447
448
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
448
449
|
{ ...config, scope: 'sequencer' },
|
|
449
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
450
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
450
451
|
);
|
|
451
452
|
|
|
452
453
|
// Create and start the sequencer client
|
|
453
454
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
454
455
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
456
|
+
worldStateSynchronizer,
|
|
455
457
|
archiver,
|
|
456
458
|
dateProvider,
|
|
457
459
|
telemetry,
|
|
@@ -482,6 +484,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
482
484
|
log.warn(`Sequencer created but not started`);
|
|
483
485
|
}
|
|
484
486
|
|
|
487
|
+
// Create prover node subsystem if enabled
|
|
488
|
+
let proverNode: ProverNode | undefined;
|
|
489
|
+
if (config.enableProverNode) {
|
|
490
|
+
proverNode = await createProverNode(config, {
|
|
491
|
+
...deps.proverNodeDeps,
|
|
492
|
+
telemetry,
|
|
493
|
+
dateProvider,
|
|
494
|
+
archiver,
|
|
495
|
+
worldStateSynchronizer,
|
|
496
|
+
p2pClient,
|
|
497
|
+
epochCache,
|
|
498
|
+
blobClient,
|
|
499
|
+
keyStoreManager,
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
if (!options.dontStartProverNode) {
|
|
503
|
+
await proverNode.start();
|
|
504
|
+
log.info(`Prover node subsystem started`);
|
|
505
|
+
} else {
|
|
506
|
+
log.info(`Prover node subsystem created but not started`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
485
510
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
486
511
|
...config,
|
|
487
512
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -489,7 +514,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
489
514
|
slotDuration: Number(slotDuration),
|
|
490
515
|
});
|
|
491
516
|
|
|
492
|
-
|
|
517
|
+
const node = new AztecNodeService(
|
|
493
518
|
config,
|
|
494
519
|
p2pClient,
|
|
495
520
|
archiver,
|
|
@@ -498,6 +523,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
498
523
|
archiver,
|
|
499
524
|
worldStateSynchronizer,
|
|
500
525
|
sequencer,
|
|
526
|
+
proverNode,
|
|
501
527
|
slasherClient,
|
|
502
528
|
validatorsSentinel,
|
|
503
529
|
epochPruneWatcher,
|
|
@@ -510,7 +536,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
510
536
|
telemetry,
|
|
511
537
|
log,
|
|
512
538
|
blobClient,
|
|
539
|
+
validatorClient,
|
|
540
|
+
keyStoreManager,
|
|
513
541
|
);
|
|
542
|
+
|
|
543
|
+
return node;
|
|
514
544
|
}
|
|
515
545
|
|
|
516
546
|
/**
|
|
@@ -521,6 +551,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
521
551
|
return this.sequencer;
|
|
522
552
|
}
|
|
523
553
|
|
|
554
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
555
|
+
public getProverNode(): ProverNode | undefined {
|
|
556
|
+
return this.proverNode;
|
|
557
|
+
}
|
|
558
|
+
|
|
524
559
|
public getBlockSource(): L2BlockSource {
|
|
525
560
|
return this.blockSource;
|
|
526
561
|
}
|
|
@@ -574,19 +609,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
574
609
|
enr,
|
|
575
610
|
l1ContractAddresses: contractAddresses,
|
|
576
611
|
protocolContractAddresses: protocolContractAddresses,
|
|
612
|
+
realProofs: !!this.config.realProofs,
|
|
577
613
|
};
|
|
578
614
|
|
|
579
615
|
return nodeInfo;
|
|
580
616
|
}
|
|
581
617
|
|
|
582
618
|
/**
|
|
583
|
-
* Get a block specified by its number.
|
|
584
|
-
* @param
|
|
619
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
620
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
585
621
|
* @returns The requested block.
|
|
586
622
|
*/
|
|
587
|
-
public async getBlock(
|
|
588
|
-
|
|
589
|
-
|
|
623
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
624
|
+
if (BlockHash.isBlockHash(block)) {
|
|
625
|
+
return this.getBlockByHash(block);
|
|
626
|
+
}
|
|
627
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
628
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
629
|
+
return this.buildInitialBlock();
|
|
630
|
+
}
|
|
631
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
590
632
|
}
|
|
591
633
|
|
|
592
634
|
/**
|
|
@@ -594,9 +636,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
594
636
|
* @param blockHash - The block hash being requested.
|
|
595
637
|
* @returns The requested block.
|
|
596
638
|
*/
|
|
597
|
-
public async getBlockByHash(blockHash:
|
|
598
|
-
const
|
|
599
|
-
|
|
639
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
640
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
641
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
642
|
+
return this.buildInitialBlock();
|
|
643
|
+
}
|
|
644
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
private buildInitialBlock(): L2Block {
|
|
648
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
649
|
+
return L2Block.empty(initialHeader);
|
|
600
650
|
}
|
|
601
651
|
|
|
602
652
|
/**
|
|
@@ -605,8 +655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
605
655
|
* @returns The requested block.
|
|
606
656
|
*/
|
|
607
657
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
608
|
-
|
|
609
|
-
return publishedBlock?.block;
|
|
658
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
610
659
|
}
|
|
611
660
|
|
|
612
661
|
/**
|
|
@@ -616,23 +665,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
665
|
* @returns The blocks requested.
|
|
617
666
|
*/
|
|
618
667
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
619
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
668
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
620
669
|
}
|
|
621
670
|
|
|
622
|
-
public async
|
|
623
|
-
return (await this.blockSource.
|
|
671
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
672
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
624
673
|
}
|
|
625
674
|
|
|
626
|
-
public async
|
|
627
|
-
return (await this.blockSource.
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
public async getL2BlocksNew(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
|
|
631
|
-
return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
|
|
635
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
|
|
675
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
676
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
636
677
|
}
|
|
637
678
|
|
|
638
679
|
/**
|
|
@@ -663,6 +704,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
704
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
705
|
}
|
|
665
706
|
|
|
707
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
708
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
709
|
+
}
|
|
710
|
+
|
|
666
711
|
/**
|
|
667
712
|
* Method to fetch the version of the package.
|
|
668
713
|
* @returns The node package version
|
|
@@ -695,12 +740,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
740
|
return this.contractDataSource.getContract(address);
|
|
696
741
|
}
|
|
697
742
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
743
|
+
public async getPrivateLogsByTags(
|
|
744
|
+
tags: SiloedTag[],
|
|
745
|
+
page?: number,
|
|
746
|
+
referenceBlock?: BlockHash,
|
|
747
|
+
): Promise<TxScopedL2Log[][]> {
|
|
748
|
+
if (referenceBlock) {
|
|
749
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
750
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
751
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
752
|
+
if (!header) {
|
|
753
|
+
throw new Error(
|
|
754
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
public async getPublicLogsByTagsFromContract(
|
|
763
|
+
contractAddress: AztecAddress,
|
|
764
|
+
tags: Tag[],
|
|
765
|
+
page?: number,
|
|
766
|
+
referenceBlock?: BlockHash,
|
|
767
|
+
): Promise<TxScopedL2Log[][]> {
|
|
768
|
+
if (referenceBlock) {
|
|
769
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
770
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
771
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
772
|
+
if (!header) {
|
|
773
|
+
throw new Error(
|
|
774
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
704
780
|
}
|
|
705
781
|
|
|
706
782
|
/**
|
|
@@ -747,21 +823,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
747
823
|
}
|
|
748
824
|
|
|
749
825
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
755
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
756
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
757
|
-
}
|
|
826
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
827
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
828
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
829
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
830
|
|
|
831
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
832
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
833
|
+
|
|
760
834
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
835
|
+
// If the archiver has the receipt then return it.
|
|
836
|
+
return settledTxReceipt;
|
|
837
|
+
} else if (isKnownToPool) {
|
|
838
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
839
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
840
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
841
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
842
|
+
} else {
|
|
843
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
844
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
845
|
}
|
|
763
|
-
|
|
764
|
-
return txReceipt;
|
|
765
846
|
}
|
|
766
847
|
|
|
767
848
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -778,6 +859,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
778
859
|
await tryStop(this.slasherClient);
|
|
779
860
|
await tryStop(this.proofVerifier);
|
|
780
861
|
await tryStop(this.sequencer);
|
|
862
|
+
await tryStop(this.proverNode);
|
|
781
863
|
await tryStop(this.p2pClient);
|
|
782
864
|
await tryStop(this.worldStateSynchronizer);
|
|
783
865
|
await tryStop(this.blockSource);
|
|
@@ -826,20 +908,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
908
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
827
909
|
}
|
|
828
910
|
|
|
829
|
-
/**
|
|
830
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
831
|
-
* the leaves were inserted.
|
|
832
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
833
|
-
* @param treeId - The tree to search in.
|
|
834
|
-
* @param leafValues - The values to search for.
|
|
835
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
836
|
-
*/
|
|
837
911
|
public async findLeavesIndexes(
|
|
838
|
-
|
|
912
|
+
referenceBlock: BlockParameter,
|
|
839
913
|
treeId: MerkleTreeId,
|
|
840
914
|
leafValues: Fr[],
|
|
841
915
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
842
|
-
const committedDb = await this.#getWorldState(
|
|
916
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
843
917
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
844
918
|
treeId,
|
|
845
919
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -891,56 +965,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
891
965
|
}
|
|
892
966
|
return {
|
|
893
967
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
894
|
-
l2BlockHash:
|
|
968
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
895
969
|
data: index,
|
|
896
970
|
};
|
|
897
971
|
});
|
|
898
972
|
}
|
|
899
973
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
904
|
-
* @returns The sibling path for the leaf index.
|
|
905
|
-
*/
|
|
906
|
-
public async getNullifierSiblingPath(
|
|
907
|
-
blockNumber: BlockParameter,
|
|
908
|
-
leafIndex: bigint,
|
|
909
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
910
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
911
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Returns a sibling path for the given index in the data tree.
|
|
916
|
-
* @param blockNumber - The block number at which to get the data.
|
|
917
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
918
|
-
* @returns The sibling path for the leaf index.
|
|
919
|
-
*/
|
|
920
|
-
public async getNoteHashSiblingPath(
|
|
921
|
-
blockNumber: BlockParameter,
|
|
922
|
-
leafIndex: bigint,
|
|
923
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
924
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
925
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
public async getArchiveMembershipWitness(
|
|
929
|
-
blockNumber: BlockParameter,
|
|
930
|
-
archive: Fr,
|
|
974
|
+
public async getBlockHashMembershipWitness(
|
|
975
|
+
referenceBlock: BlockParameter,
|
|
976
|
+
blockHash: BlockHash,
|
|
931
977
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
933
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
978
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
979
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
934
980
|
return pathAndIndex === undefined
|
|
935
981
|
? undefined
|
|
936
982
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
937
983
|
}
|
|
938
984
|
|
|
939
985
|
public async getNoteHashMembershipWitness(
|
|
940
|
-
|
|
986
|
+
referenceBlock: BlockParameter,
|
|
941
987
|
noteHash: Fr,
|
|
942
988
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
943
|
-
const committedDb = await this.#getWorldState(
|
|
989
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
944
990
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
945
991
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
946
992
|
[noteHash],
|
|
@@ -950,17 +996,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
996
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
951
997
|
}
|
|
952
998
|
|
|
953
|
-
/**
|
|
954
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
955
|
-
* @param blockNumber - The block number at which to get the data.
|
|
956
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
957
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
958
|
-
*/
|
|
959
999
|
public async getL1ToL2MessageMembershipWitness(
|
|
960
|
-
|
|
1000
|
+
referenceBlock: BlockParameter,
|
|
961
1001
|
l1ToL2Message: Fr,
|
|
962
1002
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
963
|
-
const db = await this.#getWorldState(
|
|
1003
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
964
1004
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
965
1005
|
if (!witness) {
|
|
966
1006
|
return undefined;
|
|
@@ -993,12 +1033,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
993
1033
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
994
1034
|
*/
|
|
995
1035
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
996
|
-
// Assumes `
|
|
997
|
-
const
|
|
1036
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1037
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
998
1038
|
const blocksInCheckpoints: L2Block[][] = [];
|
|
999
1039
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
1000
1040
|
let checkpointIndex = -1;
|
|
1001
|
-
for (const
|
|
1041
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1042
|
+
const block = checkpointedBlock.block;
|
|
1002
1043
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1003
1044
|
if (slotNumber !== previousSlotNumber) {
|
|
1004
1045
|
checkpointIndex++;
|
|
@@ -1012,45 +1053,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1012
1053
|
);
|
|
1013
1054
|
}
|
|
1014
1055
|
|
|
1015
|
-
/**
|
|
1016
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
1017
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1018
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1019
|
-
* @returns The sibling path.
|
|
1020
|
-
*/
|
|
1021
|
-
public async getArchiveSiblingPath(
|
|
1022
|
-
blockNumber: BlockParameter,
|
|
1023
|
-
leafIndex: bigint,
|
|
1024
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1025
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1026
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1031
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1032
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1033
|
-
* @returns The sibling path.
|
|
1034
|
-
*/
|
|
1035
|
-
public async getPublicDataSiblingPath(
|
|
1036
|
-
blockNumber: BlockParameter,
|
|
1037
|
-
leafIndex: bigint,
|
|
1038
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1039
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1040
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1045
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1046
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1047
|
-
* @returns The nullifier membership witness (if found).
|
|
1048
|
-
*/
|
|
1049
1056
|
public async getNullifierMembershipWitness(
|
|
1050
|
-
|
|
1057
|
+
referenceBlock: BlockParameter,
|
|
1051
1058
|
nullifier: Fr,
|
|
1052
1059
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1053
|
-
const db = await this.#getWorldState(
|
|
1060
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1054
1061
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1055
1062
|
if (!witness) {
|
|
1056
1063
|
return undefined;
|
|
@@ -1067,7 +1074,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1067
1074
|
|
|
1068
1075
|
/**
|
|
1069
1076
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1070
|
-
* @param
|
|
1077
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1078
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1071
1079
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1072
1080
|
* @returns The low nullifier membership witness (if found).
|
|
1073
1081
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1080,10 +1088,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1080
1088
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1081
1089
|
*/
|
|
1082
1090
|
public async getLowNullifierMembershipWitness(
|
|
1083
|
-
|
|
1091
|
+
referenceBlock: BlockParameter,
|
|
1084
1092
|
nullifier: Fr,
|
|
1085
1093
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1086
|
-
const committedDb = await this.#getWorldState(
|
|
1094
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1087
1095
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1088
1096
|
if (!findResult) {
|
|
1089
1097
|
return undefined;
|
|
@@ -1098,8 +1106,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1098
1106
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1099
1107
|
}
|
|
1100
1108
|
|
|
1101
|
-
async getPublicDataWitness(
|
|
1102
|
-
const committedDb = await this.#getWorldState(
|
|
1109
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1110
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1103
1111
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1104
1112
|
if (!lowLeafResult) {
|
|
1105
1113
|
return undefined;
|
|
@@ -1113,19 +1121,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1113
1121
|
}
|
|
1114
1122
|
}
|
|
1115
1123
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
*
|
|
1119
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1120
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1121
|
-
*
|
|
1122
|
-
* @param contract - Address of the contract to query.
|
|
1123
|
-
* @param slot - Slot to query.
|
|
1124
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1125
|
-
* @returns Storage value at the given contract slot.
|
|
1126
|
-
*/
|
|
1127
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1128
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1124
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1125
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1129
1126
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1130
1127
|
|
|
1131
1128
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1139,24 +1136,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1136
|
return preimage.leaf.value;
|
|
1140
1137
|
}
|
|
1141
1138
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1159
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1139
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1140
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1141
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1142
|
+
if (block.equals(initialBlockHash)) {
|
|
1143
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1144
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1145
|
+
}
|
|
1146
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1147
|
+
} else {
|
|
1148
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1149
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1150
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1151
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1152
|
+
}
|
|
1153
|
+
return this.blockSource.getBlockHeader(block);
|
|
1154
|
+
}
|
|
1160
1155
|
}
|
|
1161
1156
|
|
|
1162
1157
|
/**
|
|
@@ -1168,6 +1163,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1163
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1169
1164
|
}
|
|
1170
1165
|
|
|
1166
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1167
|
+
return this.blockSource.getBlockData(number);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1171
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1171
1174
|
/**
|
|
1172
1175
|
* Simulates the public part of a transaction with the current state.
|
|
1173
1176
|
* @param tx - The transaction to simulate.
|
|
@@ -1191,7 +1194,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1191
1194
|
}
|
|
1192
1195
|
|
|
1193
1196
|
const txHash = tx.getTxHash();
|
|
1194
|
-
const
|
|
1197
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1198
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1195
1199
|
|
|
1196
1200
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1197
1201
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1206,6 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1210
|
this.contractDataSource,
|
|
1207
1211
|
new DateProvider(),
|
|
1208
1212
|
this.telemetry,
|
|
1213
|
+
this.log.getBindings(),
|
|
1209
1214
|
);
|
|
1210
1215
|
|
|
1211
1216
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1214,6 +1219,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1214
1219
|
blockNumber,
|
|
1215
1220
|
});
|
|
1216
1221
|
|
|
1222
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1223
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1217
1224
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1218
1225
|
try {
|
|
1219
1226
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1229,7 +1236,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1229
1236
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1230
1237
|
|
|
1231
1238
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1232
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1239
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
|
|
1233
1240
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1234
1241
|
if (failedTxs.length) {
|
|
1235
1242
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1243,6 +1250,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1250
|
processedTx.txEffect,
|
|
1244
1251
|
returns,
|
|
1245
1252
|
processedTx.gasUsed,
|
|
1253
|
+
debugLogs,
|
|
1246
1254
|
);
|
|
1247
1255
|
} finally {
|
|
1248
1256
|
await merkleTreeFork.close();
|
|
@@ -1256,19 +1264,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1256
1264
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1257
1265
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1258
1266
|
|
|
1259
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1267
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1260
1268
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1261
1269
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1262
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1270
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1271
|
+
db,
|
|
1272
|
+
this.contractDataSource,
|
|
1273
|
+
verifier,
|
|
1274
|
+
{
|
|
1275
|
+
timestamp: nextSlotTimestamp,
|
|
1276
|
+
blockNumber,
|
|
1277
|
+
l1ChainId: this.l1ChainId,
|
|
1278
|
+
rollupVersion: this.version,
|
|
1279
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1280
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1281
|
+
skipFeeEnforcement,
|
|
1282
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1283
|
+
},
|
|
1284
|
+
this.log.getBindings(),
|
|
1285
|
+
);
|
|
1272
1286
|
|
|
1273
1287
|
return await validator.validateTx(tx);
|
|
1274
1288
|
}
|
|
@@ -1432,16 +1446,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1432
1446
|
}
|
|
1433
1447
|
}
|
|
1434
1448
|
|
|
1449
|
+
public async reloadKeystore(): Promise<void> {
|
|
1450
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1451
|
+
throw new BadRequestError(
|
|
1452
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1453
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
if (!this.validatorClient) {
|
|
1457
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
this.log.info('Reloading keystore from disk');
|
|
1461
|
+
|
|
1462
|
+
// Re-read and validate keystore files
|
|
1463
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1464
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1465
|
+
await newManager.validateSigners();
|
|
1466
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1467
|
+
|
|
1468
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1469
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1470
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1471
|
+
// would silently fail on every proposer slot.
|
|
1472
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1473
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1474
|
+
const availablePublishers = new Set(
|
|
1475
|
+
oldAdapter
|
|
1476
|
+
.getAttesterAddresses()
|
|
1477
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1478
|
+
);
|
|
1479
|
+
|
|
1480
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1481
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1482
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1483
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1484
|
+
throw new BadRequestError(
|
|
1485
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1486
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1487
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1488
|
+
`use an existing publisher key or restart the node.`,
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// Build adapters for old and new keystores to compute diff
|
|
1495
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1496
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1497
|
+
const oldAddresses = this.keyStoreManager
|
|
1498
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1499
|
+
: [];
|
|
1500
|
+
|
|
1501
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1502
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1503
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1504
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1505
|
+
|
|
1506
|
+
if (added.length > 0) {
|
|
1507
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1508
|
+
}
|
|
1509
|
+
if (removed.length > 0) {
|
|
1510
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1511
|
+
}
|
|
1512
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1513
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1517
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1518
|
+
|
|
1519
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1520
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1521
|
+
if (this.sequencer) {
|
|
1522
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1526
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1527
|
+
const slashValidatorsNever = unique(
|
|
1528
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1529
|
+
).map(EthAddress.fromString);
|
|
1530
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
this.keyStoreManager = newManager;
|
|
1534
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1538
|
+
if (!this.initialHeaderHashPromise) {
|
|
1539
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1540
|
+
}
|
|
1541
|
+
return this.initialHeaderHashPromise;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1435
1544
|
/**
|
|
1436
1545
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1437
|
-
* @param
|
|
1546
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1438
1547
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1439
1548
|
*/
|
|
1440
|
-
async #getWorldState(
|
|
1441
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1442
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1549
|
+
async #getWorldState(block: BlockParameter) {
|
|
1445
1550
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1446
1551
|
try {
|
|
1447
1552
|
// Attempt to sync the world state if necessary
|
|
@@ -1450,15 +1555,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1450
1555
|
this.log.error(`Error getting world state: ${err}`);
|
|
1451
1556
|
}
|
|
1452
1557
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1558
|
+
if (block === 'latest') {
|
|
1559
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1456
1560
|
return this.worldStateSynchronizer.getCommitted();
|
|
1457
|
-
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1564
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1565
|
+
if (block.equals(initialBlockHash)) {
|
|
1566
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1567
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1571
|
+
if (!header) {
|
|
1572
|
+
throw new Error(
|
|
1573
|
+
`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.`,
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
const blockNumber = header.getBlockNumber();
|
|
1458
1577
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1459
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1578
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Block number provided
|
|
1582
|
+
{
|
|
1583
|
+
const blockNumber = block as BlockNumber;
|
|
1584
|
+
|
|
1585
|
+
if (blockNumber > blockSyncedTo) {
|
|
1586
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1590
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1462
1591
|
}
|
|
1463
1592
|
}
|
|
1464
1593
|
|