@aztec/aztec-node 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d
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 +41 -94
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +313 -181
- 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 +401 -242
- 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,20 @@ 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';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
28
23
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
type P2P,
|
|
25
|
+
type P2PClientDeps,
|
|
26
|
+
createP2PClient,
|
|
27
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
+
getDefaultAllowedSetupFunctions,
|
|
29
|
+
} from '@aztec/p2p';
|
|
33
30
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
31
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
32
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
35
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
35
|
import {
|
|
37
36
|
AttestationsBlockWatcher,
|
|
@@ -43,13 +42,12 @@ import {
|
|
|
43
42
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
44
|
import {
|
|
45
|
+
type BlockData,
|
|
46
|
+
BlockHash,
|
|
46
47
|
type BlockParameter,
|
|
47
48
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockHash,
|
|
50
|
-
L2BlockNew,
|
|
49
|
+
L2Block,
|
|
51
50
|
type L2BlockSource,
|
|
52
|
-
type PublishedL2Block,
|
|
53
51
|
} from '@aztec/stdlib/block';
|
|
54
52
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
55
53
|
import type {
|
|
@@ -78,7 +76,8 @@ import {
|
|
|
78
76
|
type WorldStateSynchronizer,
|
|
79
77
|
tryStop,
|
|
80
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
81
|
-
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
79
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
80
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
82
81
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
83
82
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
84
83
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -112,7 +111,6 @@ import {
|
|
|
112
111
|
ValidatorClient,
|
|
113
112
|
createBlockProposalHandler,
|
|
114
113
|
createValidatorClient,
|
|
115
|
-
createValidatorForAcceptingTxs,
|
|
116
114
|
} from '@aztec/validator-client';
|
|
117
115
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
116
|
|
|
@@ -128,6 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
126
|
*/
|
|
129
127
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
128
|
private metrics: NodeMetrics;
|
|
129
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
130
|
|
|
132
131
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
132
|
private isUploadingSnapshot = false;
|
|
@@ -143,6 +142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
143
142
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
144
143
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
145
144
|
protected readonly sequencer: SequencerClient | undefined,
|
|
145
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
146
146
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
147
147
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
148
148
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -155,12 +155,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
155
155
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
156
156
|
private log = createLogger('node'),
|
|
157
157
|
private blobClient?: BlobClientInterface,
|
|
158
|
+
private validatorClient?: ValidatorClient,
|
|
159
|
+
private keyStoreManager?: KeystoreManager,
|
|
160
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
158
161
|
) {
|
|
159
162
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
163
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
161
164
|
|
|
162
165
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
163
166
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
167
|
+
|
|
168
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
169
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
170
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
171
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
172
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
173
|
+
}
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -185,10 +195,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
185
195
|
publisher?: SequencerPublisher;
|
|
186
196
|
dateProvider?: DateProvider;
|
|
187
197
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
198
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
188
199
|
} = {},
|
|
189
200
|
options: {
|
|
190
201
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
191
202
|
dontStartSequencer?: boolean;
|
|
203
|
+
dontStartProverNode?: boolean;
|
|
192
204
|
} = {},
|
|
193
205
|
): Promise<AztecNodeService> {
|
|
194
206
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -198,16 +210,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
198
210
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
199
211
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
200
212
|
|
|
201
|
-
// Build a key store from file if given or from environment otherwise
|
|
213
|
+
// Build a key store from file if given or from environment otherwise.
|
|
214
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
202
215
|
let keyStoreManager: KeystoreManager | undefined;
|
|
203
216
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
204
217
|
if (keyStoreProvided) {
|
|
205
218
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
206
219
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
207
220
|
} else {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
221
|
+
const rawKeyStores: KeyStore[] = [];
|
|
222
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
223
|
+
if (validatorKeyStore) {
|
|
224
|
+
rawKeyStores.push(validatorKeyStore);
|
|
225
|
+
}
|
|
226
|
+
if (config.enableProverNode) {
|
|
227
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
228
|
+
if (proverKeyStore) {
|
|
229
|
+
rawKeyStores.push(proverKeyStore);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (rawKeyStores.length > 0) {
|
|
233
|
+
keyStoreManager = new KeystoreManager(
|
|
234
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
235
|
+
);
|
|
211
236
|
}
|
|
212
237
|
}
|
|
213
238
|
|
|
@@ -218,10 +243,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
218
243
|
if (keyStoreManager === undefined) {
|
|
219
244
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
220
245
|
}
|
|
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
|
-
);
|
|
246
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
247
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
225
248
|
}
|
|
226
249
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
227
250
|
}
|
|
@@ -263,7 +286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
263
286
|
);
|
|
264
287
|
}
|
|
265
288
|
|
|
266
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
289
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
267
290
|
|
|
268
291
|
// attempt snapshot sync if possible
|
|
269
292
|
await trySnapshotSync(config, log);
|
|
@@ -287,9 +310,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
310
|
config.realProofs || config.debugForceTxProofVerification
|
|
288
311
|
? await BBCircuitVerifier.new(config)
|
|
289
312
|
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
313
|
+
|
|
314
|
+
let debugLogStore: DebugLogStore;
|
|
290
315
|
if (!config.realProofs) {
|
|
291
316
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
317
|
+
|
|
318
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
319
|
+
log.info(
|
|
320
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
321
|
+
);
|
|
322
|
+
} else {
|
|
323
|
+
debugLogStore = new NullDebugLogStore();
|
|
292
324
|
}
|
|
325
|
+
|
|
293
326
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
294
327
|
|
|
295
328
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
@@ -309,18 +342,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
309
342
|
// We should really not be modifying the config object
|
|
310
343
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
311
344
|
|
|
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
345
|
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
322
346
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
323
347
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
348
|
+
worldStateSynchronizer,
|
|
324
349
|
archiver,
|
|
325
350
|
dateProvider,
|
|
326
351
|
telemetry,
|
|
@@ -330,7 +355,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
330
355
|
const watchers: Watcher[] = [];
|
|
331
356
|
|
|
332
357
|
// Create validator client if required
|
|
333
|
-
const validatorClient = createValidatorClient(config, {
|
|
358
|
+
const validatorClient = await createValidatorClient(config, {
|
|
334
359
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
335
360
|
worldState: worldStateSynchronizer,
|
|
336
361
|
p2pClient,
|
|
@@ -387,7 +412,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
387
412
|
archiver,
|
|
388
413
|
epochCache,
|
|
389
414
|
p2pClient.getTxProvider(),
|
|
390
|
-
|
|
415
|
+
validatorCheckpointsBuilder,
|
|
391
416
|
config,
|
|
392
417
|
);
|
|
393
418
|
watchers.push(epochPruneWatcher);
|
|
@@ -434,27 +459,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
434
459
|
);
|
|
435
460
|
await slasherClient.start();
|
|
436
461
|
|
|
437
|
-
const l1TxUtils = config.
|
|
438
|
-
? await
|
|
462
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
463
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
439
464
|
publicClient,
|
|
440
465
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
441
|
-
config.
|
|
466
|
+
config.sequencerPublisherForwarderAddress,
|
|
442
467
|
{ ...config, scope: 'sequencer' },
|
|
443
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
468
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
444
469
|
)
|
|
445
|
-
: await
|
|
470
|
+
: await createL1TxUtilsFromSigners(
|
|
446
471
|
publicClient,
|
|
447
472
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
448
473
|
{ ...config, scope: 'sequencer' },
|
|
449
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
474
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
450
475
|
);
|
|
451
476
|
|
|
452
477
|
// Create and start the sequencer client
|
|
453
478
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
454
479
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
480
|
+
worldStateSynchronizer,
|
|
455
481
|
archiver,
|
|
456
482
|
dateProvider,
|
|
457
483
|
telemetry,
|
|
484
|
+
debugLogStore,
|
|
458
485
|
);
|
|
459
486
|
|
|
460
487
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -482,6 +509,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
482
509
|
log.warn(`Sequencer created but not started`);
|
|
483
510
|
}
|
|
484
511
|
|
|
512
|
+
// Create prover node subsystem if enabled
|
|
513
|
+
let proverNode: ProverNode | undefined;
|
|
514
|
+
if (config.enableProverNode) {
|
|
515
|
+
proverNode = await createProverNode(config, {
|
|
516
|
+
...deps.proverNodeDeps,
|
|
517
|
+
telemetry,
|
|
518
|
+
dateProvider,
|
|
519
|
+
archiver,
|
|
520
|
+
worldStateSynchronizer,
|
|
521
|
+
p2pClient,
|
|
522
|
+
epochCache,
|
|
523
|
+
blobClient,
|
|
524
|
+
keyStoreManager,
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
if (!options.dontStartProverNode) {
|
|
528
|
+
await proverNode.start();
|
|
529
|
+
log.info(`Prover node subsystem started`);
|
|
530
|
+
} else {
|
|
531
|
+
log.info(`Prover node subsystem created but not started`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
485
535
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
486
536
|
...config,
|
|
487
537
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -489,7 +539,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
489
539
|
slotDuration: Number(slotDuration),
|
|
490
540
|
});
|
|
491
541
|
|
|
492
|
-
|
|
542
|
+
const node = new AztecNodeService(
|
|
493
543
|
config,
|
|
494
544
|
p2pClient,
|
|
495
545
|
archiver,
|
|
@@ -498,6 +548,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
498
548
|
archiver,
|
|
499
549
|
worldStateSynchronizer,
|
|
500
550
|
sequencer,
|
|
551
|
+
proverNode,
|
|
501
552
|
slasherClient,
|
|
502
553
|
validatorsSentinel,
|
|
503
554
|
epochPruneWatcher,
|
|
@@ -510,7 +561,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
510
561
|
telemetry,
|
|
511
562
|
log,
|
|
512
563
|
blobClient,
|
|
564
|
+
validatorClient,
|
|
565
|
+
keyStoreManager,
|
|
566
|
+
debugLogStore,
|
|
513
567
|
);
|
|
568
|
+
|
|
569
|
+
return node;
|
|
514
570
|
}
|
|
515
571
|
|
|
516
572
|
/**
|
|
@@ -521,6 +577,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
521
577
|
return this.sequencer;
|
|
522
578
|
}
|
|
523
579
|
|
|
580
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
581
|
+
public getProverNode(): ProverNode | undefined {
|
|
582
|
+
return this.proverNode;
|
|
583
|
+
}
|
|
584
|
+
|
|
524
585
|
public getBlockSource(): L2BlockSource {
|
|
525
586
|
return this.blockSource;
|
|
526
587
|
}
|
|
@@ -574,19 +635,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
574
635
|
enr,
|
|
575
636
|
l1ContractAddresses: contractAddresses,
|
|
576
637
|
protocolContractAddresses: protocolContractAddresses,
|
|
638
|
+
realProofs: !!this.config.realProofs,
|
|
577
639
|
};
|
|
578
640
|
|
|
579
641
|
return nodeInfo;
|
|
580
642
|
}
|
|
581
643
|
|
|
582
644
|
/**
|
|
583
|
-
* Get a block specified by its number.
|
|
584
|
-
* @param
|
|
645
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
646
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
585
647
|
* @returns The requested block.
|
|
586
648
|
*/
|
|
587
|
-
public async getBlock(
|
|
588
|
-
|
|
589
|
-
|
|
649
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
650
|
+
if (BlockHash.isBlockHash(block)) {
|
|
651
|
+
return this.getBlockByHash(block);
|
|
652
|
+
}
|
|
653
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
654
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
655
|
+
return this.buildInitialBlock();
|
|
656
|
+
}
|
|
657
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
590
658
|
}
|
|
591
659
|
|
|
592
660
|
/**
|
|
@@ -594,9 +662,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
594
662
|
* @param blockHash - The block hash being requested.
|
|
595
663
|
* @returns The requested block.
|
|
596
664
|
*/
|
|
597
|
-
public async getBlockByHash(blockHash:
|
|
598
|
-
const
|
|
599
|
-
|
|
665
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
666
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
667
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
668
|
+
return this.buildInitialBlock();
|
|
669
|
+
}
|
|
670
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
private buildInitialBlock(): L2Block {
|
|
674
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
675
|
+
return L2Block.empty(initialHeader);
|
|
600
676
|
}
|
|
601
677
|
|
|
602
678
|
/**
|
|
@@ -605,8 +681,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
605
681
|
* @returns The requested block.
|
|
606
682
|
*/
|
|
607
683
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
608
|
-
|
|
609
|
-
return publishedBlock?.block;
|
|
684
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
610
685
|
}
|
|
611
686
|
|
|
612
687
|
/**
|
|
@@ -616,23 +691,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
691
|
* @returns The blocks requested.
|
|
617
692
|
*/
|
|
618
693
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
619
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
694
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
620
695
|
}
|
|
621
696
|
|
|
622
|
-
public async
|
|
623
|
-
return (await this.blockSource.
|
|
697
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
698
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
624
699
|
}
|
|
625
700
|
|
|
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)) ?? [];
|
|
701
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
702
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
636
703
|
}
|
|
637
704
|
|
|
638
705
|
/**
|
|
@@ -663,6 +730,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
730
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
731
|
}
|
|
665
732
|
|
|
733
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
734
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
735
|
+
}
|
|
736
|
+
|
|
666
737
|
/**
|
|
667
738
|
* Method to fetch the version of the package.
|
|
668
739
|
* @returns The node package version
|
|
@@ -695,12 +766,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
766
|
return this.contractDataSource.getContract(address);
|
|
696
767
|
}
|
|
697
768
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
769
|
+
public async getPrivateLogsByTags(
|
|
770
|
+
tags: SiloedTag[],
|
|
771
|
+
page?: number,
|
|
772
|
+
referenceBlock?: BlockHash,
|
|
773
|
+
): Promise<TxScopedL2Log[][]> {
|
|
774
|
+
if (referenceBlock) {
|
|
775
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
776
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
777
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
778
|
+
if (!header) {
|
|
779
|
+
throw new Error(
|
|
780
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
public async getPublicLogsByTagsFromContract(
|
|
789
|
+
contractAddress: AztecAddress,
|
|
790
|
+
tags: Tag[],
|
|
791
|
+
page?: number,
|
|
792
|
+
referenceBlock?: BlockHash,
|
|
793
|
+
): Promise<TxScopedL2Log[][]> {
|
|
794
|
+
if (referenceBlock) {
|
|
795
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
796
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
797
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
798
|
+
if (!header) {
|
|
799
|
+
throw new Error(
|
|
800
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
704
806
|
}
|
|
705
807
|
|
|
706
808
|
/**
|
|
@@ -747,21 +849,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
747
849
|
}
|
|
748
850
|
|
|
749
851
|
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
|
-
}
|
|
852
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
853
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
854
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
855
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
856
|
|
|
857
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
858
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
859
|
+
|
|
860
|
+
let receipt: TxReceipt;
|
|
760
861
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
862
|
+
receipt = settledTxReceipt;
|
|
863
|
+
} else if (isKnownToPool) {
|
|
864
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
865
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
866
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
867
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
868
|
+
} else {
|
|
869
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
870
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
871
|
}
|
|
763
872
|
|
|
764
|
-
|
|
873
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
874
|
+
|
|
875
|
+
return receipt;
|
|
765
876
|
}
|
|
766
877
|
|
|
767
878
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -778,6 +889,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
778
889
|
await tryStop(this.slasherClient);
|
|
779
890
|
await tryStop(this.proofVerifier);
|
|
780
891
|
await tryStop(this.sequencer);
|
|
892
|
+
await tryStop(this.proverNode);
|
|
781
893
|
await tryStop(this.p2pClient);
|
|
782
894
|
await tryStop(this.worldStateSynchronizer);
|
|
783
895
|
await tryStop(this.blockSource);
|
|
@@ -826,20 +938,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
938
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
827
939
|
}
|
|
828
940
|
|
|
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
941
|
public async findLeavesIndexes(
|
|
838
|
-
|
|
942
|
+
referenceBlock: BlockParameter,
|
|
839
943
|
treeId: MerkleTreeId,
|
|
840
944
|
leafValues: Fr[],
|
|
841
945
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
842
|
-
const committedDb = await this.#getWorldState(
|
|
946
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
843
947
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
844
948
|
treeId,
|
|
845
949
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -891,56 +995,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
891
995
|
}
|
|
892
996
|
return {
|
|
893
997
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
894
|
-
l2BlockHash:
|
|
998
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
895
999
|
data: index,
|
|
896
1000
|
};
|
|
897
1001
|
});
|
|
898
1002
|
}
|
|
899
1003
|
|
|
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,
|
|
1004
|
+
public async getBlockHashMembershipWitness(
|
|
1005
|
+
referenceBlock: BlockParameter,
|
|
1006
|
+
blockHash: BlockHash,
|
|
931
1007
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
933
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
1008
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1009
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
934
1010
|
return pathAndIndex === undefined
|
|
935
1011
|
? undefined
|
|
936
1012
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
937
1013
|
}
|
|
938
1014
|
|
|
939
1015
|
public async getNoteHashMembershipWitness(
|
|
940
|
-
|
|
1016
|
+
referenceBlock: BlockParameter,
|
|
941
1017
|
noteHash: Fr,
|
|
942
1018
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
943
|
-
const committedDb = await this.#getWorldState(
|
|
1019
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
944
1020
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
945
1021
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
946
1022
|
[noteHash],
|
|
@@ -950,17 +1026,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
1026
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
951
1027
|
}
|
|
952
1028
|
|
|
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
1029
|
public async getL1ToL2MessageMembershipWitness(
|
|
960
|
-
|
|
1030
|
+
referenceBlock: BlockParameter,
|
|
961
1031
|
l1ToL2Message: Fr,
|
|
962
1032
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
963
|
-
const db = await this.#getWorldState(
|
|
1033
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
964
1034
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
965
1035
|
if (!witness) {
|
|
966
1036
|
return undefined;
|
|
@@ -993,12 +1063,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
993
1063
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
994
1064
|
*/
|
|
995
1065
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
996
|
-
// Assumes `
|
|
997
|
-
const
|
|
1066
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1067
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
998
1068
|
const blocksInCheckpoints: L2Block[][] = [];
|
|
999
1069
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
1000
1070
|
let checkpointIndex = -1;
|
|
1001
|
-
for (const
|
|
1071
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1072
|
+
const block = checkpointedBlock.block;
|
|
1002
1073
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1003
1074
|
if (slotNumber !== previousSlotNumber) {
|
|
1004
1075
|
checkpointIndex++;
|
|
@@ -1012,45 +1083,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1012
1083
|
);
|
|
1013
1084
|
}
|
|
1014
1085
|
|
|
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
1086
|
public async getNullifierMembershipWitness(
|
|
1050
|
-
|
|
1087
|
+
referenceBlock: BlockParameter,
|
|
1051
1088
|
nullifier: Fr,
|
|
1052
1089
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1053
|
-
const db = await this.#getWorldState(
|
|
1090
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1054
1091
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1055
1092
|
if (!witness) {
|
|
1056
1093
|
return undefined;
|
|
@@ -1067,7 +1104,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1067
1104
|
|
|
1068
1105
|
/**
|
|
1069
1106
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1070
|
-
* @param
|
|
1107
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1108
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1071
1109
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1072
1110
|
* @returns The low nullifier membership witness (if found).
|
|
1073
1111
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1080,10 +1118,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1080
1118
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1081
1119
|
*/
|
|
1082
1120
|
public async getLowNullifierMembershipWitness(
|
|
1083
|
-
|
|
1121
|
+
referenceBlock: BlockParameter,
|
|
1084
1122
|
nullifier: Fr,
|
|
1085
1123
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1086
|
-
const committedDb = await this.#getWorldState(
|
|
1124
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1087
1125
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1088
1126
|
if (!findResult) {
|
|
1089
1127
|
return undefined;
|
|
@@ -1098,8 +1136,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1098
1136
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1099
1137
|
}
|
|
1100
1138
|
|
|
1101
|
-
async getPublicDataWitness(
|
|
1102
|
-
const committedDb = await this.#getWorldState(
|
|
1139
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1140
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1103
1141
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1104
1142
|
if (!lowLeafResult) {
|
|
1105
1143
|
return undefined;
|
|
@@ -1113,19 +1151,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1113
1151
|
}
|
|
1114
1152
|
}
|
|
1115
1153
|
|
|
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);
|
|
1154
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1155
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1129
1156
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1130
1157
|
|
|
1131
1158
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1139,24 +1166,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1166
|
return preimage.leaf.value;
|
|
1140
1167
|
}
|
|
1141
1168
|
|
|
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);
|
|
1169
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1170
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1171
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1172
|
+
if (block.equals(initialBlockHash)) {
|
|
1173
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1174
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1175
|
+
}
|
|
1176
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1177
|
+
} else {
|
|
1178
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1179
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1180
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1181
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1182
|
+
}
|
|
1183
|
+
return this.blockSource.getBlockHeader(block);
|
|
1184
|
+
}
|
|
1160
1185
|
}
|
|
1161
1186
|
|
|
1162
1187
|
/**
|
|
@@ -1168,6 +1193,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1193
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1169
1194
|
}
|
|
1170
1195
|
|
|
1196
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1197
|
+
return this.blockSource.getBlockData(number);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1201
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1171
1204
|
/**
|
|
1172
1205
|
* Simulates the public part of a transaction with the current state.
|
|
1173
1206
|
* @param tx - The transaction to simulate.
|
|
@@ -1191,7 +1224,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1191
1224
|
}
|
|
1192
1225
|
|
|
1193
1226
|
const txHash = tx.getTxHash();
|
|
1194
|
-
const
|
|
1227
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1228
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1195
1229
|
|
|
1196
1230
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1197
1231
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1206,6 +1240,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1240
|
this.contractDataSource,
|
|
1207
1241
|
new DateProvider(),
|
|
1208
1242
|
this.telemetry,
|
|
1243
|
+
this.log.getBindings(),
|
|
1209
1244
|
);
|
|
1210
1245
|
|
|
1211
1246
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1214,6 +1249,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1214
1249
|
blockNumber,
|
|
1215
1250
|
});
|
|
1216
1251
|
|
|
1252
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1253
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1217
1254
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1218
1255
|
try {
|
|
1219
1256
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1229,7 +1266,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1229
1266
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1230
1267
|
|
|
1231
1268
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1232
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1269
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
|
|
1233
1270
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1234
1271
|
if (failedTxs.length) {
|
|
1235
1272
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1243,6 +1280,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1280
|
processedTx.txEffect,
|
|
1244
1281
|
returns,
|
|
1245
1282
|
processedTx.gasUsed,
|
|
1283
|
+
debugLogs,
|
|
1246
1284
|
);
|
|
1247
1285
|
} finally {
|
|
1248
1286
|
await merkleTreeFork.close();
|
|
@@ -1256,19 +1294,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1256
1294
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1257
1295
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1258
1296
|
|
|
1259
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1297
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1260
1298
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1261
1299
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1262
|
-
const validator =
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1300
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1301
|
+
db,
|
|
1302
|
+
this.contractDataSource,
|
|
1303
|
+
verifier,
|
|
1304
|
+
{
|
|
1305
|
+
timestamp: nextSlotTimestamp,
|
|
1306
|
+
blockNumber,
|
|
1307
|
+
l1ChainId: this.l1ChainId,
|
|
1308
|
+
rollupVersion: this.version,
|
|
1309
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1310
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1311
|
+
skipFeeEnforcement,
|
|
1312
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1313
|
+
},
|
|
1314
|
+
this.log.getBindings(),
|
|
1315
|
+
);
|
|
1272
1316
|
|
|
1273
1317
|
return await validator.validateTx(tx);
|
|
1274
1318
|
}
|
|
@@ -1432,16 +1476,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1432
1476
|
}
|
|
1433
1477
|
}
|
|
1434
1478
|
|
|
1479
|
+
public async reloadKeystore(): Promise<void> {
|
|
1480
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1481
|
+
throw new BadRequestError(
|
|
1482
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1483
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1484
|
+
);
|
|
1485
|
+
}
|
|
1486
|
+
if (!this.validatorClient) {
|
|
1487
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
this.log.info('Reloading keystore from disk');
|
|
1491
|
+
|
|
1492
|
+
// Re-read and validate keystore files
|
|
1493
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1494
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1495
|
+
await newManager.validateSigners();
|
|
1496
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1497
|
+
|
|
1498
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1499
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1500
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1501
|
+
// would silently fail on every proposer slot.
|
|
1502
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1503
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1504
|
+
const availablePublishers = new Set(
|
|
1505
|
+
oldAdapter
|
|
1506
|
+
.getAttesterAddresses()
|
|
1507
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1508
|
+
);
|
|
1509
|
+
|
|
1510
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1511
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1512
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1513
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1514
|
+
throw new BadRequestError(
|
|
1515
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1516
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1517
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1518
|
+
`use an existing publisher key or restart the node.`,
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// Build adapters for old and new keystores to compute diff
|
|
1525
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1526
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1527
|
+
const oldAddresses = this.keyStoreManager
|
|
1528
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1529
|
+
: [];
|
|
1530
|
+
|
|
1531
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1532
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1533
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1534
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1535
|
+
|
|
1536
|
+
if (added.length > 0) {
|
|
1537
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1538
|
+
}
|
|
1539
|
+
if (removed.length > 0) {
|
|
1540
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1541
|
+
}
|
|
1542
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1543
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1547
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1548
|
+
|
|
1549
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1550
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1551
|
+
if (this.sequencer) {
|
|
1552
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1556
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1557
|
+
const slashValidatorsNever = unique(
|
|
1558
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1559
|
+
).map(EthAddress.fromString);
|
|
1560
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
this.keyStoreManager = newManager;
|
|
1564
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1568
|
+
if (!this.initialHeaderHashPromise) {
|
|
1569
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1570
|
+
}
|
|
1571
|
+
return this.initialHeaderHashPromise;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1435
1574
|
/**
|
|
1436
1575
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1437
|
-
* @param
|
|
1576
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1438
1577
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1439
1578
|
*/
|
|
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
|
-
|
|
1579
|
+
async #getWorldState(block: BlockParameter) {
|
|
1445
1580
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1446
1581
|
try {
|
|
1447
1582
|
// Attempt to sync the world state if necessary
|
|
@@ -1450,15 +1585,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1450
1585
|
this.log.error(`Error getting world state: ${err}`);
|
|
1451
1586
|
}
|
|
1452
1587
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1588
|
+
if (block === 'latest') {
|
|
1589
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1456
1590
|
return this.worldStateSynchronizer.getCommitted();
|
|
1457
|
-
}
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1594
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1595
|
+
if (block.equals(initialBlockHash)) {
|
|
1596
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1597
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1601
|
+
if (!header) {
|
|
1602
|
+
throw new Error(
|
|
1603
|
+
`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.`,
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
const blockNumber = header.getBlockNumber();
|
|
1458
1607
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1459
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1608
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// Block number provided
|
|
1612
|
+
{
|
|
1613
|
+
const blockNumber = block as BlockNumber;
|
|
1614
|
+
|
|
1615
|
+
if (blockNumber > blockSyncedTo) {
|
|
1616
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1620
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1462
1621
|
}
|
|
1463
1622
|
}
|
|
1464
1623
|
|