@aztec/aztec-node 0.0.1-commit.c7c42ec → 0.0.1-commit.cf93bcc56
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 +9 -16
- package/dest/aztec-node/server.d.ts +53 -99
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +714 -202
- 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 +6 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +81 -50
- 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 -26
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +413 -266
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +94 -52
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type BlobClientInterface,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
createReadOnlyFileStoreBlobClients,
|
|
7
|
-
createWritableFileStoreBlobClient,
|
|
8
|
-
} from '@aztec/blob-client/filestore';
|
|
9
|
-
import {
|
|
10
|
-
ARCHIVE_HEIGHT,
|
|
11
|
-
INITIAL_L2_BLOCK_NUM,
|
|
12
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
13
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
14
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
15
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
16
|
-
} from '@aztec/constants';
|
|
3
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
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';
|
|
17
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
18
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
19
8
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
20
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
21
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
22
|
-
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
23
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
11
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
24
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
25
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
26
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -28,22 +17,14 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
28
17
|
import { count } from '@aztec/foundation/string';
|
|
29
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
30
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
31
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
32
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
33
|
-
import {
|
|
34
|
-
createForwarderL1TxUtilsFromEthSigner,
|
|
35
|
-
createL1TxUtilsWithBlobsFromEthSigner,
|
|
36
|
-
} from '@aztec/node-lib/factories';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
37
23
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
38
24
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
SequencerClient,
|
|
43
|
-
type SequencerPublisher,
|
|
44
|
-
createValidatorForAcceptingTxs,
|
|
45
|
-
} from '@aztec/sequencer-client';
|
|
46
|
-
import { CheckpointsBuilder } from '@aztec/sequencer-client';
|
|
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';
|
|
47
28
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
48
29
|
import {
|
|
49
30
|
AttestationsBlockWatcher,
|
|
@@ -55,13 +36,14 @@ import {
|
|
|
55
36
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
56
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
57
38
|
import {
|
|
39
|
+
type BlockData,
|
|
40
|
+
BlockHash,
|
|
58
41
|
type BlockParameter,
|
|
59
42
|
type DataInBlock,
|
|
60
|
-
|
|
61
|
-
L2BlockHash,
|
|
43
|
+
L2Block,
|
|
62
44
|
type L2BlockSource,
|
|
63
|
-
type PublishedL2Block,
|
|
64
45
|
} from '@aztec/stdlib/block';
|
|
46
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
65
47
|
import type {
|
|
66
48
|
ContractClassPublic,
|
|
67
49
|
ContractDataSource,
|
|
@@ -116,10 +98,13 @@ import {
|
|
|
116
98
|
trackSpan,
|
|
117
99
|
} from '@aztec/telemetry-client';
|
|
118
100
|
import {
|
|
101
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
102
|
+
FullNodeCheckpointsBuilder,
|
|
119
103
|
NodeKeystoreAdapter,
|
|
120
104
|
ValidatorClient,
|
|
121
105
|
createBlockProposalHandler,
|
|
122
106
|
createValidatorClient,
|
|
107
|
+
createValidatorForAcceptingTxs,
|
|
123
108
|
} from '@aztec/validator-client';
|
|
124
109
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
125
110
|
|
|
@@ -135,6 +120,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
135
120
|
*/
|
|
136
121
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
137
122
|
private metrics: NodeMetrics;
|
|
123
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
138
124
|
|
|
139
125
|
// Prevent two snapshot operations to happen simultaneously
|
|
140
126
|
private isUploadingSnapshot = false;
|
|
@@ -150,6 +136,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
150
136
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
151
137
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
152
138
|
protected readonly sequencer: SequencerClient | undefined,
|
|
139
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
153
140
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
154
141
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
155
142
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -162,6 +149,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
162
149
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
163
150
|
private log = createLogger('node'),
|
|
164
151
|
private blobClient?: BlobClientInterface,
|
|
152
|
+
private validatorClient?: ValidatorClient,
|
|
153
|
+
private keyStoreManager?: KeystoreManager,
|
|
165
154
|
) {
|
|
166
155
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
167
156
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
@@ -191,12 +180,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
191
180
|
logger?: Logger;
|
|
192
181
|
publisher?: SequencerPublisher;
|
|
193
182
|
dateProvider?: DateProvider;
|
|
194
|
-
blobClient?: BlobClientInterface;
|
|
195
183
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
184
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
196
185
|
} = {},
|
|
197
186
|
options: {
|
|
198
187
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
199
188
|
dontStartSequencer?: boolean;
|
|
189
|
+
dontStartProverNode?: boolean;
|
|
200
190
|
} = {},
|
|
201
191
|
): Promise<AztecNodeService> {
|
|
202
192
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -206,16 +196,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
206
196
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
207
197
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
208
198
|
|
|
209
|
-
// 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.
|
|
210
201
|
let keyStoreManager: KeystoreManager | undefined;
|
|
211
202
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
212
203
|
if (keyStoreProvided) {
|
|
213
204
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
214
205
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
215
206
|
} else {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
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
|
+
);
|
|
219
222
|
}
|
|
220
223
|
}
|
|
221
224
|
|
|
@@ -226,10 +229,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
226
229
|
if (keyStoreManager === undefined) {
|
|
227
230
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
228
231
|
}
|
|
229
|
-
if (!keyStoreProvided) {
|
|
230
|
-
log.warn(
|
|
231
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
232
|
-
);
|
|
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");
|
|
233
234
|
}
|
|
234
235
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
235
236
|
}
|
|
@@ -271,24 +272,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
271
272
|
);
|
|
272
273
|
}
|
|
273
274
|
|
|
274
|
-
const
|
|
275
|
-
l1ChainId: config.l1ChainId,
|
|
276
|
-
rollupVersion: config.rollupVersion,
|
|
277
|
-
rollupAddress: config.l1Contracts.rollupAddress.toString(),
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const [fileStoreClients, fileStoreUploadClient] = await Promise.all([
|
|
281
|
-
createReadOnlyFileStoreBlobClients(config.blobFileStoreUrls, blobFileStoreMetadata, log),
|
|
282
|
-
createWritableFileStoreBlobClient(config.blobFileStoreUploadUrl, blobFileStoreMetadata, log),
|
|
283
|
-
]);
|
|
284
|
-
|
|
285
|
-
const blobClient =
|
|
286
|
-
deps.blobClient ??
|
|
287
|
-
createBlobClient(config, {
|
|
288
|
-
logger: createLogger('node:blob-client:client'),
|
|
289
|
-
fileStoreClients,
|
|
290
|
-
fileStoreUploadClient,
|
|
291
|
-
});
|
|
275
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
292
276
|
|
|
293
277
|
// attempt snapshot sync if possible
|
|
294
278
|
await trySnapshotSync(config, log);
|
|
@@ -334,7 +318,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
334
318
|
// We should really not be modifying the config object
|
|
335
319
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
336
320
|
|
|
337
|
-
|
|
321
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
322
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
338
323
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
339
324
|
worldStateSynchronizer,
|
|
340
325
|
archiver,
|
|
@@ -346,16 +331,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
346
331
|
const watchers: Watcher[] = [];
|
|
347
332
|
|
|
348
333
|
// Create validator client if required
|
|
349
|
-
const validatorClient = createValidatorClient(config, {
|
|
334
|
+
const validatorClient = await createValidatorClient(config, {
|
|
335
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
336
|
+
worldState: worldStateSynchronizer,
|
|
350
337
|
p2pClient,
|
|
351
338
|
telemetry,
|
|
352
339
|
dateProvider,
|
|
353
340
|
epochCache,
|
|
354
|
-
blockBuilder,
|
|
355
341
|
blockSource: archiver,
|
|
356
342
|
l1ToL2MessageSource: archiver,
|
|
357
343
|
keyStoreManager,
|
|
358
|
-
|
|
344
|
+
blobClient,
|
|
359
345
|
});
|
|
360
346
|
|
|
361
347
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -373,7 +359,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
373
359
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
374
360
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
375
361
|
createBlockProposalHandler(config, {
|
|
376
|
-
|
|
362
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
363
|
+
worldState: worldStateSynchronizer,
|
|
377
364
|
epochCache,
|
|
378
365
|
blockSource: archiver,
|
|
379
366
|
l1ToL2MessageSource: archiver,
|
|
@@ -401,7 +388,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
401
388
|
archiver,
|
|
402
389
|
epochCache,
|
|
403
390
|
p2pClient.getTxProvider(),
|
|
404
|
-
|
|
391
|
+
validatorCheckpointsBuilder,
|
|
405
392
|
config,
|
|
406
393
|
);
|
|
407
394
|
watchers.push(epochPruneWatcher);
|
|
@@ -448,24 +435,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
448
435
|
);
|
|
449
436
|
await slasherClient.start();
|
|
450
437
|
|
|
451
|
-
const l1TxUtils = config.
|
|
452
|
-
? await
|
|
438
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
439
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
453
440
|
publicClient,
|
|
454
441
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
455
|
-
config.
|
|
442
|
+
config.sequencerPublisherForwarderAddress,
|
|
456
443
|
{ ...config, scope: 'sequencer' },
|
|
457
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
444
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
458
445
|
)
|
|
459
|
-
: await
|
|
446
|
+
: await createL1TxUtilsFromSigners(
|
|
460
447
|
publicClient,
|
|
461
448
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
462
449
|
{ ...config, scope: 'sequencer' },
|
|
463
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
450
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
464
451
|
);
|
|
465
452
|
|
|
466
453
|
// Create and start the sequencer client
|
|
467
454
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
468
455
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
456
|
+
worldStateSynchronizer,
|
|
469
457
|
archiver,
|
|
470
458
|
dateProvider,
|
|
471
459
|
telemetry,
|
|
@@ -496,6 +484,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
496
484
|
log.warn(`Sequencer created but not started`);
|
|
497
485
|
}
|
|
498
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
|
+
|
|
499
510
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
500
511
|
...config,
|
|
501
512
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -503,7 +514,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
503
514
|
slotDuration: Number(slotDuration),
|
|
504
515
|
});
|
|
505
516
|
|
|
506
|
-
|
|
517
|
+
const node = new AztecNodeService(
|
|
507
518
|
config,
|
|
508
519
|
p2pClient,
|
|
509
520
|
archiver,
|
|
@@ -512,6 +523,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
512
523
|
archiver,
|
|
513
524
|
worldStateSynchronizer,
|
|
514
525
|
sequencer,
|
|
526
|
+
proverNode,
|
|
515
527
|
slasherClient,
|
|
516
528
|
validatorsSentinel,
|
|
517
529
|
epochPruneWatcher,
|
|
@@ -524,7 +536,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
524
536
|
telemetry,
|
|
525
537
|
log,
|
|
526
538
|
blobClient,
|
|
539
|
+
validatorClient,
|
|
540
|
+
keyStoreManager,
|
|
527
541
|
);
|
|
542
|
+
|
|
543
|
+
return node;
|
|
528
544
|
}
|
|
529
545
|
|
|
530
546
|
/**
|
|
@@ -535,6 +551,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
535
551
|
return this.sequencer;
|
|
536
552
|
}
|
|
537
553
|
|
|
554
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
555
|
+
public getProverNode(): ProverNode | undefined {
|
|
556
|
+
return this.proverNode;
|
|
557
|
+
}
|
|
558
|
+
|
|
538
559
|
public getBlockSource(): L2BlockSource {
|
|
539
560
|
return this.blockSource;
|
|
540
561
|
}
|
|
@@ -588,19 +609,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
588
609
|
enr,
|
|
589
610
|
l1ContractAddresses: contractAddresses,
|
|
590
611
|
protocolContractAddresses: protocolContractAddresses,
|
|
612
|
+
realProofs: !!this.config.realProofs,
|
|
591
613
|
};
|
|
592
614
|
|
|
593
615
|
return nodeInfo;
|
|
594
616
|
}
|
|
595
617
|
|
|
596
618
|
/**
|
|
597
|
-
* Get a block specified by its number.
|
|
598
|
-
* @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').
|
|
599
621
|
* @returns The requested block.
|
|
600
622
|
*/
|
|
601
|
-
public async getBlock(
|
|
602
|
-
|
|
603
|
-
|
|
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);
|
|
604
632
|
}
|
|
605
633
|
|
|
606
634
|
/**
|
|
@@ -608,9 +636,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
608
636
|
* @param blockHash - The block hash being requested.
|
|
609
637
|
* @returns The requested block.
|
|
610
638
|
*/
|
|
611
|
-
public async getBlockByHash(blockHash:
|
|
612
|
-
const
|
|
613
|
-
|
|
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);
|
|
614
650
|
}
|
|
615
651
|
|
|
616
652
|
/**
|
|
@@ -619,8 +655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
619
655
|
* @returns The requested block.
|
|
620
656
|
*/
|
|
621
657
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
622
|
-
|
|
623
|
-
return publishedBlock?.block;
|
|
658
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
624
659
|
}
|
|
625
660
|
|
|
626
661
|
/**
|
|
@@ -630,19 +665,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
630
665
|
* @returns The blocks requested.
|
|
631
666
|
*/
|
|
632
667
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
633
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
668
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
672
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
634
673
|
}
|
|
635
674
|
|
|
636
|
-
public async
|
|
637
|
-
return (await this.blockSource.
|
|
675
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
676
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
638
677
|
}
|
|
639
678
|
|
|
640
679
|
/**
|
|
641
|
-
* Method to fetch the current
|
|
642
|
-
* @returns The current
|
|
680
|
+
* Method to fetch the current min L2 fees.
|
|
681
|
+
* @returns The current min L2 fees.
|
|
643
682
|
*/
|
|
644
|
-
public async
|
|
645
|
-
return await this.globalVariableBuilder.
|
|
683
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
684
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
646
685
|
}
|
|
647
686
|
|
|
648
687
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -665,6 +704,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
665
704
|
return await this.blockSource.getProvenBlockNumber();
|
|
666
705
|
}
|
|
667
706
|
|
|
707
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
708
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
709
|
+
}
|
|
710
|
+
|
|
668
711
|
/**
|
|
669
712
|
* Method to fetch the version of the package.
|
|
670
713
|
* @returns The node package version
|
|
@@ -697,12 +740,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
697
740
|
return this.contractDataSource.getContract(address);
|
|
698
741
|
}
|
|
699
742
|
|
|
700
|
-
public getPrivateLogsByTags(
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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);
|
|
706
780
|
}
|
|
707
781
|
|
|
708
782
|
/**
|
|
@@ -749,21 +823,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
749
823
|
}
|
|
750
824
|
|
|
751
825
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
757
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
758
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
759
|
-
}
|
|
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';
|
|
760
830
|
|
|
831
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
761
832
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
833
|
+
|
|
762
834
|
if (settledTxReceipt) {
|
|
763
|
-
|
|
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');
|
|
764
845
|
}
|
|
765
|
-
|
|
766
|
-
return txReceipt;
|
|
767
846
|
}
|
|
768
847
|
|
|
769
848
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -780,6 +859,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
780
859
|
await tryStop(this.slasherClient);
|
|
781
860
|
await tryStop(this.proofVerifier);
|
|
782
861
|
await tryStop(this.sequencer);
|
|
862
|
+
await tryStop(this.proverNode);
|
|
783
863
|
await tryStop(this.p2pClient);
|
|
784
864
|
await tryStop(this.worldStateSynchronizer);
|
|
785
865
|
await tryStop(this.blockSource);
|
|
@@ -788,6 +868,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
788
868
|
this.log.info(`Stopped Aztec Node`);
|
|
789
869
|
}
|
|
790
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Returns the blob client used by this node.
|
|
873
|
+
* @internal - Exposed for testing purposes only.
|
|
874
|
+
*/
|
|
875
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
876
|
+
return this.blobClient;
|
|
877
|
+
}
|
|
878
|
+
|
|
791
879
|
/**
|
|
792
880
|
* Method to retrieve pending txs.
|
|
793
881
|
* @param limit - The number of items to returns
|
|
@@ -820,20 +908,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
820
908
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
821
909
|
}
|
|
822
910
|
|
|
823
|
-
/**
|
|
824
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
825
|
-
* the leaves were inserted.
|
|
826
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
827
|
-
* @param treeId - The tree to search in.
|
|
828
|
-
* @param leafValues - The values to search for.
|
|
829
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
830
|
-
*/
|
|
831
911
|
public async findLeavesIndexes(
|
|
832
|
-
|
|
912
|
+
referenceBlock: BlockParameter,
|
|
833
913
|
treeId: MerkleTreeId,
|
|
834
914
|
leafValues: Fr[],
|
|
835
915
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
836
|
-
const committedDb = await this.#getWorldState(
|
|
916
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
837
917
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
838
918
|
treeId,
|
|
839
919
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -885,56 +965,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
885
965
|
}
|
|
886
966
|
return {
|
|
887
967
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
888
|
-
l2BlockHash:
|
|
968
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
889
969
|
data: index,
|
|
890
970
|
};
|
|
891
971
|
});
|
|
892
972
|
}
|
|
893
973
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
898
|
-
* @returns The sibling path for the leaf index.
|
|
899
|
-
*/
|
|
900
|
-
public async getNullifierSiblingPath(
|
|
901
|
-
blockNumber: BlockParameter,
|
|
902
|
-
leafIndex: bigint,
|
|
903
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
904
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
905
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
/**
|
|
909
|
-
* Returns a sibling path for the given index in the data tree.
|
|
910
|
-
* @param blockNumber - The block number at which to get the data.
|
|
911
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
912
|
-
* @returns The sibling path for the leaf index.
|
|
913
|
-
*/
|
|
914
|
-
public async getNoteHashSiblingPath(
|
|
915
|
-
blockNumber: BlockParameter,
|
|
916
|
-
leafIndex: bigint,
|
|
917
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
918
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
919
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
920
|
-
}
|
|
921
|
-
|
|
922
|
-
public async getArchiveMembershipWitness(
|
|
923
|
-
blockNumber: BlockParameter,
|
|
924
|
-
archive: Fr,
|
|
974
|
+
public async getBlockHashMembershipWitness(
|
|
975
|
+
referenceBlock: BlockParameter,
|
|
976
|
+
blockHash: BlockHash,
|
|
925
977
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
926
|
-
const committedDb = await this.#getWorldState(
|
|
927
|
-
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]);
|
|
928
980
|
return pathAndIndex === undefined
|
|
929
981
|
? undefined
|
|
930
982
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
931
983
|
}
|
|
932
984
|
|
|
933
985
|
public async getNoteHashMembershipWitness(
|
|
934
|
-
|
|
986
|
+
referenceBlock: BlockParameter,
|
|
935
987
|
noteHash: Fr,
|
|
936
988
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
937
|
-
const committedDb = await this.#getWorldState(
|
|
989
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
938
990
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
939
991
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
940
992
|
[noteHash],
|
|
@@ -944,17 +996,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
944
996
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
945
997
|
}
|
|
946
998
|
|
|
947
|
-
/**
|
|
948
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
949
|
-
* @param blockNumber - The block number at which to get the data.
|
|
950
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
951
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
952
|
-
*/
|
|
953
999
|
public async getL1ToL2MessageMembershipWitness(
|
|
954
|
-
|
|
1000
|
+
referenceBlock: BlockParameter,
|
|
955
1001
|
l1ToL2Message: Fr,
|
|
956
1002
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
957
|
-
const db = await this.#getWorldState(
|
|
1003
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
958
1004
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
959
1005
|
if (!witness) {
|
|
960
1006
|
return undefined;
|
|
@@ -982,56 +1028,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
982
1028
|
}
|
|
983
1029
|
|
|
984
1030
|
/**
|
|
985
|
-
* Returns all the L2 to L1 messages in
|
|
986
|
-
* @param
|
|
987
|
-
* @returns The L2 to L1 messages (
|
|
1031
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1032
|
+
* @param epoch - The epoch at which to get the data.
|
|
1033
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
988
1034
|
*/
|
|
989
|
-
public async getL2ToL1Messages(
|
|
990
|
-
|
|
991
|
-
|
|
1035
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1036
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1037
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1038
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
1039
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1040
|
+
let checkpointIndex = -1;
|
|
1041
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1042
|
+
const block = checkpointedBlock.block;
|
|
1043
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1044
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1045
|
+
checkpointIndex++;
|
|
1046
|
+
blocksInCheckpoints.push([]);
|
|
1047
|
+
previousSlotNumber = slotNumber;
|
|
1048
|
+
}
|
|
1049
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1050
|
+
}
|
|
1051
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1052
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
992
1053
|
);
|
|
993
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
/**
|
|
997
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
998
|
-
* @param blockNumber - The block number at which to get the data.
|
|
999
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1000
|
-
* @returns The sibling path.
|
|
1001
|
-
*/
|
|
1002
|
-
public async getArchiveSiblingPath(
|
|
1003
|
-
blockNumber: BlockParameter,
|
|
1004
|
-
leafIndex: bigint,
|
|
1005
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1006
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1007
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
/**
|
|
1011
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1012
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1013
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1014
|
-
* @returns The sibling path.
|
|
1015
|
-
*/
|
|
1016
|
-
public async getPublicDataSiblingPath(
|
|
1017
|
-
blockNumber: BlockParameter,
|
|
1018
|
-
leafIndex: bigint,
|
|
1019
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1021
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1022
1054
|
}
|
|
1023
1055
|
|
|
1024
|
-
/**
|
|
1025
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1026
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1027
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1028
|
-
* @returns The nullifier membership witness (if found).
|
|
1029
|
-
*/
|
|
1030
1056
|
public async getNullifierMembershipWitness(
|
|
1031
|
-
|
|
1057
|
+
referenceBlock: BlockParameter,
|
|
1032
1058
|
nullifier: Fr,
|
|
1033
1059
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1034
|
-
const db = await this.#getWorldState(
|
|
1060
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1035
1061
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1036
1062
|
if (!witness) {
|
|
1037
1063
|
return undefined;
|
|
@@ -1048,7 +1074,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1048
1074
|
|
|
1049
1075
|
/**
|
|
1050
1076
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1051
|
-
* @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).
|
|
1052
1079
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1053
1080
|
* @returns The low nullifier membership witness (if found).
|
|
1054
1081
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1061,10 +1088,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1061
1088
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1062
1089
|
*/
|
|
1063
1090
|
public async getLowNullifierMembershipWitness(
|
|
1064
|
-
|
|
1091
|
+
referenceBlock: BlockParameter,
|
|
1065
1092
|
nullifier: Fr,
|
|
1066
1093
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1067
|
-
const committedDb = await this.#getWorldState(
|
|
1094
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1068
1095
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1069
1096
|
if (!findResult) {
|
|
1070
1097
|
return undefined;
|
|
@@ -1079,8 +1106,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1079
1106
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1080
1107
|
}
|
|
1081
1108
|
|
|
1082
|
-
async getPublicDataWitness(
|
|
1083
|
-
const committedDb = await this.#getWorldState(
|
|
1109
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1110
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1084
1111
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1085
1112
|
if (!lowLeafResult) {
|
|
1086
1113
|
return undefined;
|
|
@@ -1094,19 +1121,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1094
1121
|
}
|
|
1095
1122
|
}
|
|
1096
1123
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
*
|
|
1100
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1101
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1102
|
-
*
|
|
1103
|
-
* @param contract - Address of the contract to query.
|
|
1104
|
-
* @param slot - Slot to query.
|
|
1105
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1106
|
-
* @returns Storage value at the given contract slot.
|
|
1107
|
-
*/
|
|
1108
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1109
|
-
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);
|
|
1110
1126
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1111
1127
|
|
|
1112
1128
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1120,24 +1136,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1120
1136
|
return preimage.leaf.value;
|
|
1121
1137
|
}
|
|
1122
1138
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1140
|
-
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
|
+
}
|
|
1141
1155
|
}
|
|
1142
1156
|
|
|
1143
1157
|
/**
|
|
@@ -1149,6 +1163,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1149
1163
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1150
1164
|
}
|
|
1151
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
|
+
|
|
1152
1174
|
/**
|
|
1153
1175
|
* Simulates the public part of a transaction with the current state.
|
|
1154
1176
|
* @param tx - The transaction to simulate.
|
|
@@ -1172,7 +1194,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1172
1194
|
}
|
|
1173
1195
|
|
|
1174
1196
|
const txHash = tx.getTxHash();
|
|
1175
|
-
const
|
|
1197
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1198
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1176
1199
|
|
|
1177
1200
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1178
1201
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1187,6 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1187
1210
|
this.contractDataSource,
|
|
1188
1211
|
new DateProvider(),
|
|
1189
1212
|
this.telemetry,
|
|
1213
|
+
this.log.getBindings(),
|
|
1190
1214
|
);
|
|
1191
1215
|
|
|
1192
1216
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1195,6 +1219,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1195
1219
|
blockNumber,
|
|
1196
1220
|
});
|
|
1197
1221
|
|
|
1222
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1223
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1198
1224
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1199
1225
|
try {
|
|
1200
1226
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1237,19 +1263,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1237
1263
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1238
1264
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1239
1265
|
|
|
1240
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1266
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1241
1267
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1242
1268
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1243
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1269
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1270
|
+
db,
|
|
1271
|
+
this.contractDataSource,
|
|
1272
|
+
verifier,
|
|
1273
|
+
{
|
|
1274
|
+
timestamp: nextSlotTimestamp,
|
|
1275
|
+
blockNumber,
|
|
1276
|
+
l1ChainId: this.l1ChainId,
|
|
1277
|
+
rollupVersion: this.version,
|
|
1278
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1279
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1280
|
+
skipFeeEnforcement,
|
|
1281
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1282
|
+
},
|
|
1283
|
+
this.log.getBindings(),
|
|
1284
|
+
);
|
|
1253
1285
|
|
|
1254
1286
|
return await validator.validateTx(tx);
|
|
1255
1287
|
}
|
|
@@ -1318,7 +1350,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1318
1350
|
}
|
|
1319
1351
|
|
|
1320
1352
|
// And it has an L2 block hash
|
|
1321
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1353
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1322
1354
|
if (!l2BlockHash) {
|
|
1323
1355
|
this.metrics.recordSnapshotError();
|
|
1324
1356
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1352,7 +1384,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1352
1384
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1353
1385
|
}
|
|
1354
1386
|
|
|
1355
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1387
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1356
1388
|
if (targetBlock < finalizedBlock) {
|
|
1357
1389
|
if (force) {
|
|
1358
1390
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1413,16 +1445,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1413
1445
|
}
|
|
1414
1446
|
}
|
|
1415
1447
|
|
|
1448
|
+
public async reloadKeystore(): Promise<void> {
|
|
1449
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1450
|
+
throw new BadRequestError(
|
|
1451
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1452
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
if (!this.validatorClient) {
|
|
1456
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
this.log.info('Reloading keystore from disk');
|
|
1460
|
+
|
|
1461
|
+
// Re-read and validate keystore files
|
|
1462
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1463
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1464
|
+
await newManager.validateSigners();
|
|
1465
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1466
|
+
|
|
1467
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1468
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1469
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1470
|
+
// would silently fail on every proposer slot.
|
|
1471
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1472
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1473
|
+
const availablePublishers = new Set(
|
|
1474
|
+
oldAdapter
|
|
1475
|
+
.getAttesterAddresses()
|
|
1476
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1477
|
+
);
|
|
1478
|
+
|
|
1479
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1480
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1481
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1482
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1483
|
+
throw new BadRequestError(
|
|
1484
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1485
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1486
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1487
|
+
`use an existing publisher key or restart the node.`,
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// Build adapters for old and new keystores to compute diff
|
|
1494
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1495
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1496
|
+
const oldAddresses = this.keyStoreManager
|
|
1497
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1498
|
+
: [];
|
|
1499
|
+
|
|
1500
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1501
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1502
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1503
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1504
|
+
|
|
1505
|
+
if (added.length > 0) {
|
|
1506
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1507
|
+
}
|
|
1508
|
+
if (removed.length > 0) {
|
|
1509
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1510
|
+
}
|
|
1511
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1512
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1516
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1517
|
+
|
|
1518
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1519
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1520
|
+
if (this.sequencer) {
|
|
1521
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1525
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1526
|
+
const slashValidatorsNever = unique(
|
|
1527
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1528
|
+
).map(EthAddress.fromString);
|
|
1529
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
this.keyStoreManager = newManager;
|
|
1533
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1537
|
+
if (!this.initialHeaderHashPromise) {
|
|
1538
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1539
|
+
}
|
|
1540
|
+
return this.initialHeaderHashPromise;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1416
1543
|
/**
|
|
1417
1544
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1418
|
-
* @param
|
|
1545
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1419
1546
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1420
1547
|
*/
|
|
1421
|
-
async #getWorldState(
|
|
1422
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1423
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1548
|
+
async #getWorldState(block: BlockParameter) {
|
|
1426
1549
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1427
1550
|
try {
|
|
1428
1551
|
// Attempt to sync the world state if necessary
|
|
@@ -1431,15 +1554,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1431
1554
|
this.log.error(`Error getting world state: ${err}`);
|
|
1432
1555
|
}
|
|
1433
1556
|
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1557
|
+
if (block === 'latest') {
|
|
1558
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1437
1559
|
return this.worldStateSynchronizer.getCommitted();
|
|
1438
|
-
}
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1563
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1564
|
+
if (block.equals(initialBlockHash)) {
|
|
1565
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1566
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1570
|
+
if (!header) {
|
|
1571
|
+
throw new Error(
|
|
1572
|
+
`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.`,
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
const blockNumber = header.getBlockNumber();
|
|
1439
1576
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1440
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1577
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
// Block number provided
|
|
1581
|
+
{
|
|
1582
|
+
const blockNumber = block as BlockNumber;
|
|
1583
|
+
|
|
1584
|
+
if (blockNumber > blockSyncedTo) {
|
|
1585
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1589
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1443
1590
|
}
|
|
1444
1591
|
}
|
|
1445
1592
|
|