@aztec/aztec-node 0.0.1-commit.3469e52 → 0.0.1-commit.358457c
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 +38 -28
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +247 -101
- 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 +27 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +328 -154
- 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,20 +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
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
7
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
8
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
9
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
10
|
-
} 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';
|
|
11
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
12
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
13
8
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
14
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
15
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
16
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
17
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
18
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
19
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
20
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -22,14 +17,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
22
17
|
import { count } from '@aztec/foundation/string';
|
|
23
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
24
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
25
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
26
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
27
23
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
type P2P,
|
|
25
|
+
type P2PClientDeps,
|
|
26
|
+
createP2PClient,
|
|
27
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
+
getDefaultAllowedSetupFunctions,
|
|
29
|
+
} from '@aztec/p2p';
|
|
32
30
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
31
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
32
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
33
|
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
34
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
35
35
|
import {
|
|
@@ -42,11 +42,11 @@ import {
|
|
|
42
42
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
43
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
44
|
import {
|
|
45
|
+
type BlockData,
|
|
46
|
+
BlockHash,
|
|
45
47
|
type BlockParameter,
|
|
46
|
-
type CheckpointedL2Block,
|
|
47
48
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockNew,
|
|
49
|
+
L2Block,
|
|
50
50
|
type L2BlockSource,
|
|
51
51
|
} from '@aztec/stdlib/block';
|
|
52
52
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -76,7 +76,8 @@ import {
|
|
|
76
76
|
type WorldStateSynchronizer,
|
|
77
77
|
tryStop,
|
|
78
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
79
|
-
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';
|
|
80
81
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
81
82
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
82
83
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -110,7 +111,6 @@ import {
|
|
|
110
111
|
ValidatorClient,
|
|
111
112
|
createBlockProposalHandler,
|
|
112
113
|
createValidatorClient,
|
|
113
|
-
createValidatorForAcceptingTxs,
|
|
114
114
|
} from '@aztec/validator-client';
|
|
115
115
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
116
116
|
|
|
@@ -126,7 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
126
126
|
*/
|
|
127
127
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
128
128
|
private metrics: NodeMetrics;
|
|
129
|
-
private initialHeaderHashPromise: Promise<
|
|
129
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
130
130
|
|
|
131
131
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
132
|
private isUploadingSnapshot = false;
|
|
@@ -142,6 +142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
142
142
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
143
143
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
144
144
|
protected readonly sequencer: SequencerClient | undefined,
|
|
145
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
145
146
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
146
147
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
147
148
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -154,12 +155,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
154
155
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
156
|
private log = createLogger('node'),
|
|
156
157
|
private blobClient?: BlobClientInterface,
|
|
158
|
+
private validatorClient?: ValidatorClient,
|
|
159
|
+
private keyStoreManager?: KeystoreManager,
|
|
160
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
157
161
|
) {
|
|
158
162
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
159
163
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
160
164
|
|
|
161
165
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
162
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
|
+
}
|
|
163
174
|
}
|
|
164
175
|
|
|
165
176
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -184,10 +195,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
195
|
publisher?: SequencerPublisher;
|
|
185
196
|
dateProvider?: DateProvider;
|
|
186
197
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
198
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
187
199
|
} = {},
|
|
188
200
|
options: {
|
|
189
201
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
190
202
|
dontStartSequencer?: boolean;
|
|
203
|
+
dontStartProverNode?: boolean;
|
|
191
204
|
} = {},
|
|
192
205
|
): Promise<AztecNodeService> {
|
|
193
206
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -197,16 +210,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
197
210
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
198
211
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
199
212
|
|
|
200
|
-
// 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.
|
|
201
215
|
let keyStoreManager: KeystoreManager | undefined;
|
|
202
216
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
203
217
|
if (keyStoreProvided) {
|
|
204
218
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
205
219
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
206
220
|
} else {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
);
|
|
210
236
|
}
|
|
211
237
|
}
|
|
212
238
|
|
|
@@ -217,10 +243,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
217
243
|
if (keyStoreManager === undefined) {
|
|
218
244
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
219
245
|
}
|
|
220
|
-
if (!keyStoreProvided) {
|
|
221
|
-
log.warn(
|
|
222
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
223
|
-
);
|
|
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");
|
|
224
248
|
}
|
|
225
249
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
226
250
|
}
|
|
@@ -262,7 +286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
262
286
|
);
|
|
263
287
|
}
|
|
264
288
|
|
|
265
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
289
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
266
290
|
|
|
267
291
|
// attempt snapshot sync if possible
|
|
268
292
|
await trySnapshotSync(config, log);
|
|
@@ -286,9 +310,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
286
310
|
config.realProofs || config.debugForceTxProofVerification
|
|
287
311
|
? await BBCircuitVerifier.new(config)
|
|
288
312
|
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
313
|
+
|
|
314
|
+
let debugLogStore: DebugLogStore;
|
|
289
315
|
if (!config.realProofs) {
|
|
290
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();
|
|
291
324
|
}
|
|
325
|
+
|
|
292
326
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
293
327
|
|
|
294
328
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
@@ -425,19 +459,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
425
459
|
);
|
|
426
460
|
await slasherClient.start();
|
|
427
461
|
|
|
428
|
-
const l1TxUtils = config.
|
|
429
|
-
? await
|
|
462
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
463
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
430
464
|
publicClient,
|
|
431
465
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
-
config.
|
|
466
|
+
config.sequencerPublisherForwarderAddress,
|
|
433
467
|
{ ...config, scope: 'sequencer' },
|
|
434
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
468
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
435
469
|
)
|
|
436
|
-
: await
|
|
470
|
+
: await createL1TxUtilsFromSigners(
|
|
437
471
|
publicClient,
|
|
438
472
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
439
473
|
{ ...config, scope: 'sequencer' },
|
|
440
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
474
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
441
475
|
);
|
|
442
476
|
|
|
443
477
|
// Create and start the sequencer client
|
|
@@ -447,6 +481,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
447
481
|
archiver,
|
|
448
482
|
dateProvider,
|
|
449
483
|
telemetry,
|
|
484
|
+
debugLogStore,
|
|
450
485
|
);
|
|
451
486
|
|
|
452
487
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -474,6 +509,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
474
509
|
log.warn(`Sequencer created but not started`);
|
|
475
510
|
}
|
|
476
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
|
+
|
|
477
535
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
478
536
|
...config,
|
|
479
537
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -481,7 +539,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
481
539
|
slotDuration: Number(slotDuration),
|
|
482
540
|
});
|
|
483
541
|
|
|
484
|
-
|
|
542
|
+
const node = new AztecNodeService(
|
|
485
543
|
config,
|
|
486
544
|
p2pClient,
|
|
487
545
|
archiver,
|
|
@@ -490,6 +548,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
490
548
|
archiver,
|
|
491
549
|
worldStateSynchronizer,
|
|
492
550
|
sequencer,
|
|
551
|
+
proverNode,
|
|
493
552
|
slasherClient,
|
|
494
553
|
validatorsSentinel,
|
|
495
554
|
epochPruneWatcher,
|
|
@@ -502,7 +561,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
502
561
|
telemetry,
|
|
503
562
|
log,
|
|
504
563
|
blobClient,
|
|
564
|
+
validatorClient,
|
|
565
|
+
keyStoreManager,
|
|
566
|
+
debugLogStore,
|
|
505
567
|
);
|
|
568
|
+
|
|
569
|
+
return node;
|
|
506
570
|
}
|
|
507
571
|
|
|
508
572
|
/**
|
|
@@ -513,6 +577,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
513
577
|
return this.sequencer;
|
|
514
578
|
}
|
|
515
579
|
|
|
580
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
581
|
+
public getProverNode(): ProverNode | undefined {
|
|
582
|
+
return this.proverNode;
|
|
583
|
+
}
|
|
584
|
+
|
|
516
585
|
public getBlockSource(): L2BlockSource {
|
|
517
586
|
return this.blockSource;
|
|
518
587
|
}
|
|
@@ -566,6 +635,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
566
635
|
enr,
|
|
567
636
|
l1ContractAddresses: contractAddresses,
|
|
568
637
|
protocolContractAddresses: protocolContractAddresses,
|
|
638
|
+
realProofs: !!this.config.realProofs,
|
|
569
639
|
};
|
|
570
640
|
|
|
571
641
|
return nodeInfo;
|
|
@@ -576,15 +646,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
576
646
|
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
577
647
|
* @returns The requested block.
|
|
578
648
|
*/
|
|
579
|
-
public async getBlock(block: BlockParameter): Promise<
|
|
580
|
-
if (
|
|
581
|
-
return this.getBlockByHash(
|
|
649
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
650
|
+
if (BlockHash.isBlockHash(block)) {
|
|
651
|
+
return this.getBlockByHash(block);
|
|
582
652
|
}
|
|
583
653
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
584
654
|
if (blockNumber === BlockNumber.ZERO) {
|
|
585
655
|
return this.buildInitialBlock();
|
|
586
656
|
}
|
|
587
|
-
return await this.blockSource.
|
|
657
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
588
658
|
}
|
|
589
659
|
|
|
590
660
|
/**
|
|
@@ -592,17 +662,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
592
662
|
* @param blockHash - The block hash being requested.
|
|
593
663
|
* @returns The requested block.
|
|
594
664
|
*/
|
|
595
|
-
public async getBlockByHash(blockHash:
|
|
665
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
596
666
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
597
|
-
if (blockHash.equals(
|
|
667
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
598
668
|
return this.buildInitialBlock();
|
|
599
669
|
}
|
|
600
|
-
return await this.blockSource.
|
|
670
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
601
671
|
}
|
|
602
672
|
|
|
603
|
-
private buildInitialBlock():
|
|
673
|
+
private buildInitialBlock(): L2Block {
|
|
604
674
|
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
605
|
-
return
|
|
675
|
+
return L2Block.empty(initialHeader);
|
|
606
676
|
}
|
|
607
677
|
|
|
608
678
|
/**
|
|
@@ -610,8 +680,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
610
680
|
* @param archive - The archive root being requested.
|
|
611
681
|
* @returns The requested block.
|
|
612
682
|
*/
|
|
613
|
-
public async getBlockByArchive(archive: Fr): Promise<
|
|
614
|
-
return await this.blockSource.
|
|
683
|
+
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
684
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
615
685
|
}
|
|
616
686
|
|
|
617
687
|
/**
|
|
@@ -620,24 +690,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
620
690
|
* @param limit - The maximum number of blocks to obtain.
|
|
621
691
|
* @returns The blocks requested.
|
|
622
692
|
*/
|
|
623
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<
|
|
624
|
-
return (await this.blockSource.
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
628
|
-
return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
632
|
-
return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
|
|
693
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
694
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
633
695
|
}
|
|
634
696
|
|
|
635
|
-
public async
|
|
636
|
-
return (await this.blockSource.
|
|
697
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
698
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
637
699
|
}
|
|
638
700
|
|
|
639
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number
|
|
640
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit
|
|
701
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
702
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
641
703
|
}
|
|
642
704
|
|
|
643
705
|
/**
|
|
@@ -668,6 +730,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
668
730
|
return await this.blockSource.getProvenBlockNumber();
|
|
669
731
|
}
|
|
670
732
|
|
|
733
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
734
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
735
|
+
}
|
|
736
|
+
|
|
671
737
|
/**
|
|
672
738
|
* Method to fetch the version of the package.
|
|
673
739
|
* @returns The node package version
|
|
@@ -700,15 +766,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
700
766
|
return this.contractDataSource.getContract(address);
|
|
701
767
|
}
|
|
702
768
|
|
|
703
|
-
public getPrivateLogsByTags(
|
|
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
|
+
}
|
|
704
785
|
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
705
786
|
}
|
|
706
787
|
|
|
707
|
-
public getPublicLogsByTagsFromContract(
|
|
788
|
+
public async getPublicLogsByTagsFromContract(
|
|
708
789
|
contractAddress: AztecAddress,
|
|
709
790
|
tags: Tag[],
|
|
710
791
|
page?: number,
|
|
792
|
+
referenceBlock?: BlockHash,
|
|
711
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
|
+
}
|
|
712
805
|
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
713
806
|
}
|
|
714
807
|
|
|
@@ -756,21 +849,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
756
849
|
}
|
|
757
850
|
|
|
758
851
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
764
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
765
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
766
|
-
}
|
|
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';
|
|
767
856
|
|
|
857
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
768
858
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
859
|
+
|
|
860
|
+
let receipt: TxReceipt;
|
|
769
861
|
if (settledTxReceipt) {
|
|
770
|
-
|
|
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');
|
|
771
871
|
}
|
|
772
872
|
|
|
773
|
-
|
|
873
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
874
|
+
|
|
875
|
+
return receipt;
|
|
774
876
|
}
|
|
775
877
|
|
|
776
878
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -787,6 +889,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
787
889
|
await tryStop(this.slasherClient);
|
|
788
890
|
await tryStop(this.proofVerifier);
|
|
789
891
|
await tryStop(this.sequencer);
|
|
892
|
+
await tryStop(this.proverNode);
|
|
790
893
|
await tryStop(this.p2pClient);
|
|
791
894
|
await tryStop(this.worldStateSynchronizer);
|
|
792
895
|
await tryStop(this.blockSource);
|
|
@@ -836,11 +939,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
836
939
|
}
|
|
837
940
|
|
|
838
941
|
public async findLeavesIndexes(
|
|
839
|
-
|
|
942
|
+
referenceBlock: BlockParameter,
|
|
840
943
|
treeId: MerkleTreeId,
|
|
841
944
|
leafValues: Fr[],
|
|
842
945
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
843
|
-
const committedDb = await this.#getWorldState(
|
|
946
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
844
947
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
845
948
|
treeId,
|
|
846
949
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -892,44 +995,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
892
995
|
}
|
|
893
996
|
return {
|
|
894
997
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
895
|
-
l2BlockHash:
|
|
998
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
896
999
|
data: index,
|
|
897
1000
|
};
|
|
898
1001
|
});
|
|
899
1002
|
}
|
|
900
1003
|
|
|
901
|
-
public async
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
905
|
-
const committedDb = await this.#getWorldState(block);
|
|
906
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
public async getNoteHashSiblingPath(
|
|
910
|
-
block: BlockParameter,
|
|
911
|
-
leafIndex: bigint,
|
|
912
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
913
|
-
const committedDb = await this.#getWorldState(block);
|
|
914
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
public async getArchiveMembershipWitness(
|
|
918
|
-
block: BlockParameter,
|
|
919
|
-
archive: Fr,
|
|
1004
|
+
public async getBlockHashMembershipWitness(
|
|
1005
|
+
referenceBlock: BlockParameter,
|
|
1006
|
+
blockHash: BlockHash,
|
|
920
1007
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
921
|
-
const committedDb = await this.#getWorldState(
|
|
922
|
-
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]);
|
|
923
1010
|
return pathAndIndex === undefined
|
|
924
1011
|
? undefined
|
|
925
1012
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
926
1013
|
}
|
|
927
1014
|
|
|
928
1015
|
public async getNoteHashMembershipWitness(
|
|
929
|
-
|
|
1016
|
+
referenceBlock: BlockParameter,
|
|
930
1017
|
noteHash: Fr,
|
|
931
1018
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
1019
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
933
1020
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
934
1021
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
935
1022
|
[noteHash],
|
|
@@ -940,10 +1027,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
940
1027
|
}
|
|
941
1028
|
|
|
942
1029
|
public async getL1ToL2MessageMembershipWitness(
|
|
943
|
-
|
|
1030
|
+
referenceBlock: BlockParameter,
|
|
944
1031
|
l1ToL2Message: Fr,
|
|
945
1032
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
946
|
-
const db = await this.#getWorldState(
|
|
1033
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
947
1034
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
948
1035
|
if (!witness) {
|
|
949
1036
|
return undefined;
|
|
@@ -976,12 +1063,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
976
1063
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
977
1064
|
*/
|
|
978
1065
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
-
// Assumes `
|
|
980
|
-
const
|
|
981
|
-
const blocksInCheckpoints:
|
|
1066
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1067
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1068
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
982
1069
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
983
1070
|
let checkpointIndex = -1;
|
|
984
|
-
for (const
|
|
1071
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1072
|
+
const block = checkpointedBlock.block;
|
|
985
1073
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
1074
|
if (slotNumber !== previousSlotNumber) {
|
|
987
1075
|
checkpointIndex++;
|
|
@@ -995,27 +1083,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
995
1083
|
);
|
|
996
1084
|
}
|
|
997
1085
|
|
|
998
|
-
public async getArchiveSiblingPath(
|
|
999
|
-
block: BlockParameter,
|
|
1000
|
-
leafIndex: bigint,
|
|
1001
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1002
|
-
const committedDb = await this.#getWorldState(block);
|
|
1003
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
public async getPublicDataSiblingPath(
|
|
1007
|
-
block: BlockParameter,
|
|
1008
|
-
leafIndex: bigint,
|
|
1009
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1010
|
-
const committedDb = await this.#getWorldState(block);
|
|
1011
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
1086
|
public async getNullifierMembershipWitness(
|
|
1015
|
-
|
|
1087
|
+
referenceBlock: BlockParameter,
|
|
1016
1088
|
nullifier: Fr,
|
|
1017
1089
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1018
|
-
const db = await this.#getWorldState(
|
|
1090
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1019
1091
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1020
1092
|
if (!witness) {
|
|
1021
1093
|
return undefined;
|
|
@@ -1032,7 +1104,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1104
|
|
|
1033
1105
|
/**
|
|
1034
1106
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1035
|
-
* @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).
|
|
1036
1109
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1037
1110
|
* @returns The low nullifier membership witness (if found).
|
|
1038
1111
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1045,10 +1118,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1045
1118
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1046
1119
|
*/
|
|
1047
1120
|
public async getLowNullifierMembershipWitness(
|
|
1048
|
-
|
|
1121
|
+
referenceBlock: BlockParameter,
|
|
1049
1122
|
nullifier: Fr,
|
|
1050
1123
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1051
|
-
const committedDb = await this.#getWorldState(
|
|
1124
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1052
1125
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1053
1126
|
if (!findResult) {
|
|
1054
1127
|
return undefined;
|
|
@@ -1063,8 +1136,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1063
1136
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1064
1137
|
}
|
|
1065
1138
|
|
|
1066
|
-
async getPublicDataWitness(
|
|
1067
|
-
const committedDb = await this.#getWorldState(
|
|
1139
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1140
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1068
1141
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1069
1142
|
if (!lowLeafResult) {
|
|
1070
1143
|
return undefined;
|
|
@@ -1078,8 +1151,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1078
1151
|
}
|
|
1079
1152
|
}
|
|
1080
1153
|
|
|
1081
|
-
public async getPublicStorageAt(
|
|
1082
|
-
const committedDb = await this.#getWorldState(
|
|
1154
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1155
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1083
1156
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1084
1157
|
|
|
1085
1158
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1094,14 +1167,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1094
1167
|
}
|
|
1095
1168
|
|
|
1096
1169
|
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1097
|
-
if (
|
|
1170
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1098
1171
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1099
1172
|
if (block.equals(initialBlockHash)) {
|
|
1100
1173
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1101
1174
|
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1102
1175
|
}
|
|
1103
|
-
|
|
1104
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1176
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1105
1177
|
} else {
|
|
1106
1178
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1107
1179
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
@@ -1121,6 +1193,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1121
1193
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1122
1194
|
}
|
|
1123
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
|
+
|
|
1124
1204
|
/**
|
|
1125
1205
|
* Simulates the public part of a transaction with the current state.
|
|
1126
1206
|
* @param tx - The transaction to simulate.
|
|
@@ -1144,7 +1224,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1144
1224
|
}
|
|
1145
1225
|
|
|
1146
1226
|
const txHash = tx.getTxHash();
|
|
1147
|
-
const
|
|
1227
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1228
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1148
1229
|
|
|
1149
1230
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1150
1231
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1159,6 +1240,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1159
1240
|
this.contractDataSource,
|
|
1160
1241
|
new DateProvider(),
|
|
1161
1242
|
this.telemetry,
|
|
1243
|
+
this.log.getBindings(),
|
|
1162
1244
|
);
|
|
1163
1245
|
|
|
1164
1246
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1167,6 +1249,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1167
1249
|
blockNumber,
|
|
1168
1250
|
});
|
|
1169
1251
|
|
|
1252
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1253
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1170
1254
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1171
1255
|
try {
|
|
1172
1256
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1182,7 +1266,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1182
1266
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1183
1267
|
|
|
1184
1268
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1185
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1269
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
|
|
1186
1270
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1187
1271
|
if (failedTxs.length) {
|
|
1188
1272
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1196,6 +1280,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1196
1280
|
processedTx.txEffect,
|
|
1197
1281
|
returns,
|
|
1198
1282
|
processedTx.gasUsed,
|
|
1283
|
+
debugLogs,
|
|
1199
1284
|
);
|
|
1200
1285
|
} finally {
|
|
1201
1286
|
await merkleTreeFork.close();
|
|
@@ -1209,19 +1294,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1209
1294
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1210
1295
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1211
1296
|
|
|
1212
|
-
// 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)
|
|
1213
1298
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1214
1299
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1215
|
-
const validator =
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
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
|
+
);
|
|
1225
1316
|
|
|
1226
1317
|
return await validator.validateTx(tx);
|
|
1227
1318
|
}
|
|
@@ -1385,13 +1476,97 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1385
1476
|
}
|
|
1386
1477
|
}
|
|
1387
1478
|
|
|
1388
|
-
|
|
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> {
|
|
1389
1568
|
if (!this.initialHeaderHashPromise) {
|
|
1390
|
-
this.initialHeaderHashPromise = this.worldStateSynchronizer
|
|
1391
|
-
.getCommitted()
|
|
1392
|
-
.getInitialHeader()
|
|
1393
|
-
.hash()
|
|
1394
|
-
.then(hash => L2BlockHash.fromField(hash));
|
|
1569
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1395
1570
|
}
|
|
1396
1571
|
return this.initialHeaderHashPromise;
|
|
1397
1572
|
}
|
|
@@ -1415,15 +1590,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1415
1590
|
return this.worldStateSynchronizer.getCommitted();
|
|
1416
1591
|
}
|
|
1417
1592
|
|
|
1418
|
-
if (
|
|
1593
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1419
1594
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1420
1595
|
if (block.equals(initialBlockHash)) {
|
|
1421
1596
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1422
1597
|
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1423
1598
|
}
|
|
1424
1599
|
|
|
1425
|
-
const
|
|
1426
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1600
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1427
1601
|
if (!header) {
|
|
1428
1602
|
throw new Error(
|
|
1429
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.`,
|