@aztec/aztec-node 0.0.1-commit.3469e52 → 0.0.1-commit.381b1a9
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 +44 -31
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +378 -176
- 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 +56 -30
- 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 +472 -237
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +59 -26
- 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,9 +76,9 @@ 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
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
82
82
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
83
83
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
84
84
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -110,7 +110,6 @@ import {
|
|
|
110
110
|
ValidatorClient,
|
|
111
111
|
createBlockProposalHandler,
|
|
112
112
|
createValidatorClient,
|
|
113
|
-
createValidatorForAcceptingTxs,
|
|
114
113
|
} from '@aztec/validator-client';
|
|
115
114
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
116
115
|
|
|
@@ -126,7 +125,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
126
125
|
*/
|
|
127
126
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
128
127
|
private metrics: NodeMetrics;
|
|
129
|
-
private initialHeaderHashPromise: Promise<
|
|
128
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
130
129
|
|
|
131
130
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
131
|
private isUploadingSnapshot = false;
|
|
@@ -142,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
142
141
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
143
142
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
144
143
|
protected readonly sequencer: SequencerClient | undefined,
|
|
144
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
145
145
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
146
146
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
147
147
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -154,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
154
154
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
155
|
private log = createLogger('node'),
|
|
156
156
|
private blobClient?: BlobClientInterface,
|
|
157
|
+
private validatorClient?: ValidatorClient,
|
|
158
|
+
private keyStoreManager?: KeystoreManager,
|
|
159
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
157
160
|
) {
|
|
158
161
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
159
162
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
160
163
|
|
|
161
164
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
162
165
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
166
|
+
|
|
167
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
168
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
169
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
170
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
171
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
172
|
+
}
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -183,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
183
193
|
logger?: Logger;
|
|
184
194
|
publisher?: SequencerPublisher;
|
|
185
195
|
dateProvider?: DateProvider;
|
|
186
|
-
p2pClientDeps?: P2PClientDeps
|
|
196
|
+
p2pClientDeps?: P2PClientDeps;
|
|
197
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
187
198
|
} = {},
|
|
188
199
|
options: {
|
|
189
200
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
190
201
|
dontStartSequencer?: boolean;
|
|
202
|
+
dontStartProverNode?: boolean;
|
|
191
203
|
} = {},
|
|
192
204
|
): Promise<AztecNodeService> {
|
|
193
205
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -197,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
197
209
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
198
210
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
199
211
|
|
|
200
|
-
// Build a key store from file if given or from environment otherwise
|
|
212
|
+
// Build a key store from file if given or from environment otherwise.
|
|
213
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
201
214
|
let keyStoreManager: KeystoreManager | undefined;
|
|
202
215
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
203
216
|
if (keyStoreProvided) {
|
|
204
217
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
205
218
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
206
219
|
} else {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
220
|
+
const rawKeyStores: KeyStore[] = [];
|
|
221
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
222
|
+
if (validatorKeyStore) {
|
|
223
|
+
rawKeyStores.push(validatorKeyStore);
|
|
224
|
+
}
|
|
225
|
+
if (config.enableProverNode) {
|
|
226
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
227
|
+
if (proverKeyStore) {
|
|
228
|
+
rawKeyStores.push(proverKeyStore);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (rawKeyStores.length > 0) {
|
|
232
|
+
keyStoreManager = new KeystoreManager(
|
|
233
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
234
|
+
);
|
|
210
235
|
}
|
|
211
236
|
}
|
|
212
237
|
|
|
@@ -217,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
217
242
|
if (keyStoreManager === undefined) {
|
|
218
243
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
219
244
|
}
|
|
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
|
-
);
|
|
245
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
246
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
224
247
|
}
|
|
225
248
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
226
249
|
}
|
|
@@ -248,10 +271,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
248
271
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
249
272
|
|
|
250
273
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
251
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
274
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
252
275
|
rollupContract.getL1GenesisTime(),
|
|
253
276
|
rollupContract.getSlotDuration(),
|
|
254
277
|
rollupContract.getVersion(),
|
|
278
|
+
rollupContract.getManaLimit().then(Number),
|
|
255
279
|
] as const);
|
|
256
280
|
|
|
257
281
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -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,14 +310,28 @@ 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
|
|
|
328
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
329
|
+
if (proverOnly) {
|
|
330
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
331
|
+
}
|
|
332
|
+
|
|
294
333
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
295
334
|
const p2pClient = await createP2PClient(
|
|
296
|
-
P2PClientType.Full,
|
|
297
335
|
config,
|
|
298
336
|
archiver,
|
|
299
337
|
proofVerifier,
|
|
@@ -305,49 +343,59 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
305
343
|
deps.p2pClientDeps,
|
|
306
344
|
);
|
|
307
345
|
|
|
308
|
-
// We
|
|
309
|
-
|
|
346
|
+
// We'll accumulate sentinel watchers here
|
|
347
|
+
const watchers: Watcher[] = [];
|
|
310
348
|
|
|
311
|
-
// Create FullNodeCheckpointsBuilder for
|
|
349
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
350
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
312
351
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
313
|
-
{
|
|
352
|
+
{
|
|
353
|
+
...config,
|
|
354
|
+
l1GenesisTime,
|
|
355
|
+
slotDuration: Number(slotDuration),
|
|
356
|
+
rollupManaLimit,
|
|
357
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
358
|
+
},
|
|
314
359
|
worldStateSynchronizer,
|
|
315
360
|
archiver,
|
|
316
361
|
dateProvider,
|
|
317
362
|
telemetry,
|
|
318
363
|
);
|
|
319
364
|
|
|
320
|
-
|
|
321
|
-
const watchers: Watcher[] = [];
|
|
365
|
+
let validatorClient: ValidatorClient | undefined;
|
|
322
366
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
367
|
+
if (!proverOnly) {
|
|
368
|
+
// Create validator client if required
|
|
369
|
+
validatorClient = await createValidatorClient(config, {
|
|
370
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
371
|
+
worldState: worldStateSynchronizer,
|
|
372
|
+
p2pClient,
|
|
373
|
+
telemetry,
|
|
374
|
+
dateProvider,
|
|
375
|
+
epochCache,
|
|
376
|
+
blockSource: archiver,
|
|
377
|
+
l1ToL2MessageSource: archiver,
|
|
378
|
+
keyStoreManager,
|
|
379
|
+
blobClient,
|
|
380
|
+
});
|
|
336
381
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
382
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
383
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
384
|
+
// like attestations or auths will fail.
|
|
385
|
+
if (validatorClient) {
|
|
386
|
+
watchers.push(validatorClient);
|
|
387
|
+
if (!options.dontStartSequencer) {
|
|
388
|
+
await validatorClient.registerHandlers();
|
|
389
|
+
}
|
|
344
390
|
}
|
|
345
391
|
}
|
|
346
392
|
|
|
347
|
-
// If there's no validator client
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
393
|
+
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
394
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
395
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
396
|
+
if (!validatorClient) {
|
|
397
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
398
|
+
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
351
399
|
createBlockProposalHandler(config, {
|
|
352
400
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
353
401
|
worldState: worldStateSynchronizer,
|
|
@@ -357,7 +405,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
357
405
|
p2pClient,
|
|
358
406
|
dateProvider,
|
|
359
407
|
telemetry,
|
|
360
|
-
}).
|
|
408
|
+
}).register(p2pClient, reexecute);
|
|
361
409
|
}
|
|
362
410
|
|
|
363
411
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -366,29 +414,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
366
414
|
// Start p2p. Note that it depends on world state to be running.
|
|
367
415
|
await p2pClient.start();
|
|
368
416
|
|
|
369
|
-
|
|
370
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
371
|
-
watchers.push(validatorsSentinel);
|
|
372
|
-
}
|
|
373
|
-
|
|
417
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
374
418
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
375
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
376
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
377
|
-
archiver,
|
|
378
|
-
archiver,
|
|
379
|
-
epochCache,
|
|
380
|
-
p2pClient.getTxProvider(),
|
|
381
|
-
validatorCheckpointsBuilder,
|
|
382
|
-
config,
|
|
383
|
-
);
|
|
384
|
-
watchers.push(epochPruneWatcher);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
388
419
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
420
|
+
|
|
421
|
+
if (!proverOnly) {
|
|
422
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
423
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
424
|
+
watchers.push(validatorsSentinel);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
428
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
429
|
+
archiver,
|
|
430
|
+
archiver,
|
|
431
|
+
epochCache,
|
|
432
|
+
p2pClient.getTxProvider(),
|
|
433
|
+
validatorCheckpointsBuilder,
|
|
434
|
+
config,
|
|
435
|
+
);
|
|
436
|
+
watchers.push(epochPruneWatcher);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
440
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
441
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
442
|
+
watchers.push(attestationsBlockWatcher);
|
|
443
|
+
}
|
|
392
444
|
}
|
|
393
445
|
|
|
394
446
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -425,28 +477,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
425
477
|
);
|
|
426
478
|
await slasherClient.start();
|
|
427
479
|
|
|
428
|
-
const l1TxUtils = config.
|
|
429
|
-
? await
|
|
480
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
481
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
430
482
|
publicClient,
|
|
431
483
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
-
config.
|
|
484
|
+
config.sequencerPublisherForwarderAddress,
|
|
433
485
|
{ ...config, scope: 'sequencer' },
|
|
434
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
486
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
435
487
|
)
|
|
436
|
-
: await
|
|
488
|
+
: await createL1TxUtilsFromSigners(
|
|
437
489
|
publicClient,
|
|
438
490
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
439
491
|
{ ...config, scope: 'sequencer' },
|
|
440
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
492
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
441
493
|
);
|
|
442
494
|
|
|
443
495
|
// Create and start the sequencer client
|
|
444
496
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
445
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
497
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
446
498
|
worldStateSynchronizer,
|
|
447
499
|
archiver,
|
|
448
500
|
dateProvider,
|
|
449
501
|
telemetry,
|
|
502
|
+
debugLogStore,
|
|
450
503
|
);
|
|
451
504
|
|
|
452
505
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -474,6 +527,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
474
527
|
log.warn(`Sequencer created but not started`);
|
|
475
528
|
}
|
|
476
529
|
|
|
530
|
+
// Create prover node subsystem if enabled
|
|
531
|
+
let proverNode: ProverNode | undefined;
|
|
532
|
+
if (config.enableProverNode) {
|
|
533
|
+
proverNode = await createProverNode(config, {
|
|
534
|
+
...deps.proverNodeDeps,
|
|
535
|
+
telemetry,
|
|
536
|
+
dateProvider,
|
|
537
|
+
archiver,
|
|
538
|
+
worldStateSynchronizer,
|
|
539
|
+
p2pClient,
|
|
540
|
+
epochCache,
|
|
541
|
+
blobClient,
|
|
542
|
+
keyStoreManager,
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
if (!options.dontStartProverNode) {
|
|
546
|
+
await proverNode.start();
|
|
547
|
+
log.info(`Prover node subsystem started`);
|
|
548
|
+
} else {
|
|
549
|
+
log.info(`Prover node subsystem created but not started`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
477
553
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
478
554
|
...config,
|
|
479
555
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -481,7 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
481
557
|
slotDuration: Number(slotDuration),
|
|
482
558
|
});
|
|
483
559
|
|
|
484
|
-
|
|
560
|
+
const node = new AztecNodeService(
|
|
485
561
|
config,
|
|
486
562
|
p2pClient,
|
|
487
563
|
archiver,
|
|
@@ -490,6 +566,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
490
566
|
archiver,
|
|
491
567
|
worldStateSynchronizer,
|
|
492
568
|
sequencer,
|
|
569
|
+
proverNode,
|
|
493
570
|
slasherClient,
|
|
494
571
|
validatorsSentinel,
|
|
495
572
|
epochPruneWatcher,
|
|
@@ -502,7 +579,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
502
579
|
telemetry,
|
|
503
580
|
log,
|
|
504
581
|
blobClient,
|
|
582
|
+
validatorClient,
|
|
583
|
+
keyStoreManager,
|
|
584
|
+
debugLogStore,
|
|
505
585
|
);
|
|
586
|
+
|
|
587
|
+
return node;
|
|
506
588
|
}
|
|
507
589
|
|
|
508
590
|
/**
|
|
@@ -513,6 +595,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
513
595
|
return this.sequencer;
|
|
514
596
|
}
|
|
515
597
|
|
|
598
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
599
|
+
public getProverNode(): ProverNode | undefined {
|
|
600
|
+
return this.proverNode;
|
|
601
|
+
}
|
|
602
|
+
|
|
516
603
|
public getBlockSource(): L2BlockSource {
|
|
517
604
|
return this.blockSource;
|
|
518
605
|
}
|
|
@@ -538,7 +625,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
538
625
|
}
|
|
539
626
|
|
|
540
627
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
541
|
-
return this.config.
|
|
628
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
542
629
|
}
|
|
543
630
|
|
|
544
631
|
/**
|
|
@@ -566,6 +653,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
566
653
|
enr,
|
|
567
654
|
l1ContractAddresses: contractAddresses,
|
|
568
655
|
protocolContractAddresses: protocolContractAddresses,
|
|
656
|
+
realProofs: !!this.config.realProofs,
|
|
569
657
|
};
|
|
570
658
|
|
|
571
659
|
return nodeInfo;
|
|
@@ -576,15 +664,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
576
664
|
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
577
665
|
* @returns The requested block.
|
|
578
666
|
*/
|
|
579
|
-
public async getBlock(block: BlockParameter): Promise<
|
|
580
|
-
if (
|
|
581
|
-
return this.getBlockByHash(
|
|
667
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
668
|
+
if (BlockHash.isBlockHash(block)) {
|
|
669
|
+
return this.getBlockByHash(block);
|
|
582
670
|
}
|
|
583
671
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
584
672
|
if (blockNumber === BlockNumber.ZERO) {
|
|
585
673
|
return this.buildInitialBlock();
|
|
586
674
|
}
|
|
587
|
-
return await this.blockSource.
|
|
675
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
588
676
|
}
|
|
589
677
|
|
|
590
678
|
/**
|
|
@@ -592,17 +680,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
592
680
|
* @param blockHash - The block hash being requested.
|
|
593
681
|
* @returns The requested block.
|
|
594
682
|
*/
|
|
595
|
-
public async getBlockByHash(blockHash:
|
|
683
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
596
684
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
597
|
-
if (blockHash.equals(
|
|
685
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
598
686
|
return this.buildInitialBlock();
|
|
599
687
|
}
|
|
600
|
-
return await this.blockSource.
|
|
688
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
601
689
|
}
|
|
602
690
|
|
|
603
|
-
private buildInitialBlock():
|
|
691
|
+
private buildInitialBlock(): L2Block {
|
|
604
692
|
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
605
|
-
return
|
|
693
|
+
return L2Block.empty(initialHeader);
|
|
606
694
|
}
|
|
607
695
|
|
|
608
696
|
/**
|
|
@@ -610,8 +698,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
610
698
|
* @param archive - The archive root being requested.
|
|
611
699
|
* @returns The requested block.
|
|
612
700
|
*/
|
|
613
|
-
public async getBlockByArchive(archive: Fr): Promise<
|
|
614
|
-
return await this.blockSource.
|
|
701
|
+
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
702
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
615
703
|
}
|
|
616
704
|
|
|
617
705
|
/**
|
|
@@ -620,24 +708,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
620
708
|
* @param limit - The maximum number of blocks to obtain.
|
|
621
709
|
* @returns The blocks requested.
|
|
622
710
|
*/
|
|
623
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<
|
|
624
|
-
return (await this.blockSource.
|
|
711
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
712
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
625
713
|
}
|
|
626
714
|
|
|
627
|
-
public async
|
|
628
|
-
return (await this.blockSource.
|
|
715
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
716
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
629
717
|
}
|
|
630
718
|
|
|
631
|
-
public async
|
|
632
|
-
return (await this.blockSource.
|
|
719
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
720
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
633
721
|
}
|
|
634
722
|
|
|
635
|
-
public
|
|
636
|
-
return
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
|
|
640
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
|
|
723
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
724
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
641
725
|
}
|
|
642
726
|
|
|
643
727
|
/**
|
|
@@ -668,6 +752,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
668
752
|
return await this.blockSource.getProvenBlockNumber();
|
|
669
753
|
}
|
|
670
754
|
|
|
755
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
756
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
760
|
+
return this.blockSource.getCheckpointNumber();
|
|
761
|
+
}
|
|
762
|
+
|
|
671
763
|
/**
|
|
672
764
|
* Method to fetch the version of the package.
|
|
673
765
|
* @returns The node package version
|
|
@@ -700,15 +792,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
700
792
|
return this.contractDataSource.getContract(address);
|
|
701
793
|
}
|
|
702
794
|
|
|
703
|
-
public getPrivateLogsByTags(
|
|
795
|
+
public async getPrivateLogsByTags(
|
|
796
|
+
tags: SiloedTag[],
|
|
797
|
+
page?: number,
|
|
798
|
+
referenceBlock?: BlockHash,
|
|
799
|
+
): Promise<TxScopedL2Log[][]> {
|
|
800
|
+
if (referenceBlock) {
|
|
801
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
802
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
803
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
804
|
+
if (!header) {
|
|
805
|
+
throw new Error(
|
|
806
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
704
811
|
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
705
812
|
}
|
|
706
813
|
|
|
707
|
-
public getPublicLogsByTagsFromContract(
|
|
814
|
+
public async getPublicLogsByTagsFromContract(
|
|
708
815
|
contractAddress: AztecAddress,
|
|
709
816
|
tags: Tag[],
|
|
710
817
|
page?: number,
|
|
818
|
+
referenceBlock?: BlockHash,
|
|
711
819
|
): Promise<TxScopedL2Log[][]> {
|
|
820
|
+
if (referenceBlock) {
|
|
821
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
822
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
823
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
824
|
+
if (!header) {
|
|
825
|
+
throw new Error(
|
|
826
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
712
831
|
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
713
832
|
}
|
|
714
833
|
|
|
@@ -751,26 +870,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
751
870
|
}
|
|
752
871
|
|
|
753
872
|
await this.p2pClient!.sendTx(tx);
|
|
754
|
-
|
|
755
|
-
this.
|
|
873
|
+
const duration = timer.ms();
|
|
874
|
+
this.metrics.receivedTx(duration, true);
|
|
875
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
756
876
|
}
|
|
757
877
|
|
|
758
878
|
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
|
-
}
|
|
879
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
880
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
881
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
882
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
767
883
|
|
|
884
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
768
885
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
886
|
+
|
|
887
|
+
let receipt: TxReceipt;
|
|
769
888
|
if (settledTxReceipt) {
|
|
770
|
-
|
|
889
|
+
receipt = settledTxReceipt;
|
|
890
|
+
} else if (isKnownToPool) {
|
|
891
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
892
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
893
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
894
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
895
|
+
} else {
|
|
896
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
897
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
771
898
|
}
|
|
772
899
|
|
|
773
|
-
|
|
900
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
901
|
+
|
|
902
|
+
return receipt;
|
|
774
903
|
}
|
|
775
904
|
|
|
776
905
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -787,6 +916,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
787
916
|
await tryStop(this.slasherClient);
|
|
788
917
|
await tryStop(this.proofVerifier);
|
|
789
918
|
await tryStop(this.sequencer);
|
|
919
|
+
await tryStop(this.proverNode);
|
|
790
920
|
await tryStop(this.p2pClient);
|
|
791
921
|
await tryStop(this.worldStateSynchronizer);
|
|
792
922
|
await tryStop(this.blockSource);
|
|
@@ -836,100 +966,94 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
836
966
|
}
|
|
837
967
|
|
|
838
968
|
public async findLeavesIndexes(
|
|
839
|
-
|
|
969
|
+
referenceBlock: BlockParameter,
|
|
840
970
|
treeId: MerkleTreeId,
|
|
841
971
|
leafValues: Fr[],
|
|
842
972
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
843
|
-
const committedDb = await this.#getWorldState(
|
|
973
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
844
974
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
845
975
|
treeId,
|
|
846
976
|
leafValues.map(x => x.toBuffer()),
|
|
847
977
|
);
|
|
848
|
-
//
|
|
849
|
-
const
|
|
978
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
979
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
850
980
|
|
|
851
|
-
// Now we find the block numbers for the indices
|
|
852
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
981
|
+
// Now we find the block numbers for the defined indices
|
|
982
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
853
983
|
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
984
|
+
// Build a map from leaf index to block number
|
|
985
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
986
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
987
|
+
const blockNumber = blockNumbers[i];
|
|
988
|
+
if (blockNumber === undefined) {
|
|
989
|
+
throw new Error(
|
|
990
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
991
|
+
);
|
|
858
992
|
}
|
|
993
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
859
994
|
}
|
|
860
995
|
|
|
861
996
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
862
|
-
const uniqueBlockNumbers = [...new Set(
|
|
997
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
863
998
|
|
|
864
|
-
// Now we obtain the block hashes from the archive tree
|
|
865
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
999
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
866
1000
|
const blockHashes = await Promise.all(
|
|
867
1001
|
uniqueBlockNumbers.map(blockNumber => {
|
|
868
1002
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
869
1003
|
}),
|
|
870
1004
|
);
|
|
871
1005
|
|
|
872
|
-
//
|
|
1006
|
+
// Build a map from block number to block hash
|
|
1007
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
873
1008
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
874
|
-
|
|
1009
|
+
const blockHash = blockHashes[i];
|
|
1010
|
+
if (blockHash === undefined) {
|
|
875
1011
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
876
1012
|
}
|
|
1013
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
877
1014
|
}
|
|
878
1015
|
|
|
879
1016
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
880
|
-
return maybeIndices.map(
|
|
1017
|
+
return maybeIndices.map(index => {
|
|
881
1018
|
if (index === undefined) {
|
|
882
1019
|
return undefined;
|
|
883
1020
|
}
|
|
884
|
-
const blockNumber =
|
|
1021
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
885
1022
|
if (blockNumber === undefined) {
|
|
886
|
-
|
|
1023
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
887
1024
|
}
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
return undefined;
|
|
1025
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1026
|
+
if (blockHash === undefined) {
|
|
1027
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
892
1028
|
}
|
|
893
1029
|
return {
|
|
894
|
-
l2BlockNumber:
|
|
895
|
-
l2BlockHash:
|
|
1030
|
+
l2BlockNumber: blockNumber,
|
|
1031
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
896
1032
|
data: index,
|
|
897
1033
|
};
|
|
898
1034
|
});
|
|
899
1035
|
}
|
|
900
1036
|
|
|
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,
|
|
1037
|
+
public async getBlockHashMembershipWitness(
|
|
1038
|
+
referenceBlock: BlockParameter,
|
|
1039
|
+
blockHash: BlockHash,
|
|
920
1040
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
921
|
-
|
|
922
|
-
|
|
1041
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1042
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1043
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1044
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1045
|
+
const committedDb = await this.#getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1046
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
923
1047
|
return pathAndIndex === undefined
|
|
924
1048
|
? undefined
|
|
925
1049
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
926
1050
|
}
|
|
927
1051
|
|
|
928
1052
|
public async getNoteHashMembershipWitness(
|
|
929
|
-
|
|
1053
|
+
referenceBlock: BlockParameter,
|
|
930
1054
|
noteHash: Fr,
|
|
931
1055
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
1056
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
933
1057
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
934
1058
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
935
1059
|
[noteHash],
|
|
@@ -940,10 +1064,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
940
1064
|
}
|
|
941
1065
|
|
|
942
1066
|
public async getL1ToL2MessageMembershipWitness(
|
|
943
|
-
|
|
1067
|
+
referenceBlock: BlockParameter,
|
|
944
1068
|
l1ToL2Message: Fr,
|
|
945
1069
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
946
|
-
const db = await this.#getWorldState(
|
|
1070
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
947
1071
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
948
1072
|
if (!witness) {
|
|
949
1073
|
return undefined;
|
|
@@ -953,11 +1077,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
953
1077
|
return [witness.index, witness.path];
|
|
954
1078
|
}
|
|
955
1079
|
|
|
956
|
-
public async
|
|
1080
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
957
1081
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
958
|
-
return messageIndex
|
|
959
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
960
|
-
: undefined;
|
|
1082
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
961
1083
|
}
|
|
962
1084
|
|
|
963
1085
|
/**
|
|
@@ -976,12 +1098,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
976
1098
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
977
1099
|
*/
|
|
978
1100
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
-
// Assumes `
|
|
980
|
-
const
|
|
981
|
-
const blocksInCheckpoints:
|
|
1101
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1102
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1103
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
982
1104
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
983
1105
|
let checkpointIndex = -1;
|
|
984
|
-
for (const
|
|
1106
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1107
|
+
const block = checkpointedBlock.block;
|
|
985
1108
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
1109
|
if (slotNumber !== previousSlotNumber) {
|
|
987
1110
|
checkpointIndex++;
|
|
@@ -995,27 +1118,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
995
1118
|
);
|
|
996
1119
|
}
|
|
997
1120
|
|
|
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
1121
|
public async getNullifierMembershipWitness(
|
|
1015
|
-
|
|
1122
|
+
referenceBlock: BlockParameter,
|
|
1016
1123
|
nullifier: Fr,
|
|
1017
1124
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1018
|
-
const db = await this.#getWorldState(
|
|
1125
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1019
1126
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1020
1127
|
if (!witness) {
|
|
1021
1128
|
return undefined;
|
|
@@ -1032,7 +1139,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1139
|
|
|
1033
1140
|
/**
|
|
1034
1141
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1035
|
-
* @param
|
|
1142
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1143
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1036
1144
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1037
1145
|
* @returns The low nullifier membership witness (if found).
|
|
1038
1146
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1045,10 +1153,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1045
1153
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1046
1154
|
*/
|
|
1047
1155
|
public async getLowNullifierMembershipWitness(
|
|
1048
|
-
|
|
1156
|
+
referenceBlock: BlockParameter,
|
|
1049
1157
|
nullifier: Fr,
|
|
1050
1158
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1051
|
-
const committedDb = await this.#getWorldState(
|
|
1159
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1052
1160
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1053
1161
|
if (!findResult) {
|
|
1054
1162
|
return undefined;
|
|
@@ -1063,8 +1171,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1063
1171
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1064
1172
|
}
|
|
1065
1173
|
|
|
1066
|
-
async getPublicDataWitness(
|
|
1067
|
-
const committedDb = await this.#getWorldState(
|
|
1174
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1175
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1068
1176
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1069
1177
|
if (!lowLeafResult) {
|
|
1070
1178
|
return undefined;
|
|
@@ -1078,8 +1186,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1078
1186
|
}
|
|
1079
1187
|
}
|
|
1080
1188
|
|
|
1081
|
-
public async getPublicStorageAt(
|
|
1082
|
-
const committedDb = await this.#getWorldState(
|
|
1189
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1190
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1083
1191
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1084
1192
|
|
|
1085
1193
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1094,14 +1202,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1094
1202
|
}
|
|
1095
1203
|
|
|
1096
1204
|
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1097
|
-
if (
|
|
1205
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1098
1206
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1099
1207
|
if (block.equals(initialBlockHash)) {
|
|
1100
1208
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1101
1209
|
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1102
1210
|
}
|
|
1103
|
-
|
|
1104
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1211
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1105
1212
|
} else {
|
|
1106
1213
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1107
1214
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
@@ -1121,6 +1228,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1121
1228
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1122
1229
|
}
|
|
1123
1230
|
|
|
1231
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1232
|
+
return this.blockSource.getBlockData(number);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1236
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1124
1239
|
/**
|
|
1125
1240
|
* Simulates the public part of a transaction with the current state.
|
|
1126
1241
|
* @param tx - The transaction to simulate.
|
|
@@ -1144,7 +1259,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1144
1259
|
}
|
|
1145
1260
|
|
|
1146
1261
|
const txHash = tx.getTxHash();
|
|
1147
|
-
const
|
|
1262
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1263
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1148
1264
|
|
|
1149
1265
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1150
1266
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1159,6 +1275,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1159
1275
|
this.contractDataSource,
|
|
1160
1276
|
new DateProvider(),
|
|
1161
1277
|
this.telemetry,
|
|
1278
|
+
this.log.getBindings(),
|
|
1162
1279
|
);
|
|
1163
1280
|
|
|
1164
1281
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1167,6 +1284,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1167
1284
|
blockNumber,
|
|
1168
1285
|
});
|
|
1169
1286
|
|
|
1287
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1288
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1170
1289
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1171
1290
|
try {
|
|
1172
1291
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1182,7 +1301,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1182
1301
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1183
1302
|
|
|
1184
1303
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1185
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1304
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1186
1305
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1187
1306
|
if (failedTxs.length) {
|
|
1188
1307
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1196,6 +1315,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1196
1315
|
processedTx.txEffect,
|
|
1197
1316
|
returns,
|
|
1198
1317
|
processedTx.gasUsed,
|
|
1318
|
+
debugLogs,
|
|
1199
1319
|
);
|
|
1200
1320
|
} finally {
|
|
1201
1321
|
await merkleTreeFork.close();
|
|
@@ -1209,19 +1329,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1209
1329
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1210
1330
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1211
1331
|
|
|
1212
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1332
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1213
1333
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1214
1334
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1335
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1336
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1337
|
+
db,
|
|
1338
|
+
this.contractDataSource,
|
|
1339
|
+
verifier,
|
|
1340
|
+
{
|
|
1341
|
+
timestamp: nextSlotTimestamp,
|
|
1342
|
+
blockNumber,
|
|
1343
|
+
l1ChainId: this.l1ChainId,
|
|
1344
|
+
rollupVersion: this.version,
|
|
1345
|
+
setupAllowList: [
|
|
1346
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1347
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1348
|
+
],
|
|
1349
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1350
|
+
skipFeeEnforcement,
|
|
1351
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1352
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1353
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1354
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1355
|
+
},
|
|
1356
|
+
this.log.getBindings(),
|
|
1357
|
+
);
|
|
1225
1358
|
|
|
1226
1359
|
return await validator.validateTx(tx);
|
|
1227
1360
|
}
|
|
@@ -1385,13 +1518,97 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1385
1518
|
}
|
|
1386
1519
|
}
|
|
1387
1520
|
|
|
1388
|
-
|
|
1521
|
+
public async reloadKeystore(): Promise<void> {
|
|
1522
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1523
|
+
throw new BadRequestError(
|
|
1524
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1525
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1526
|
+
);
|
|
1527
|
+
}
|
|
1528
|
+
if (!this.validatorClient) {
|
|
1529
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
this.log.info('Reloading keystore from disk');
|
|
1533
|
+
|
|
1534
|
+
// Re-read and validate keystore files
|
|
1535
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1536
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1537
|
+
await newManager.validateSigners();
|
|
1538
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1539
|
+
|
|
1540
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1541
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1542
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1543
|
+
// would silently fail on every proposer slot.
|
|
1544
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1545
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1546
|
+
const availablePublishers = new Set(
|
|
1547
|
+
oldAdapter
|
|
1548
|
+
.getAttesterAddresses()
|
|
1549
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1550
|
+
);
|
|
1551
|
+
|
|
1552
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1553
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1554
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1555
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1556
|
+
throw new BadRequestError(
|
|
1557
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1558
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1559
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1560
|
+
`use an existing publisher key or restart the node.`,
|
|
1561
|
+
);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// Build adapters for old and new keystores to compute diff
|
|
1567
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1568
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1569
|
+
const oldAddresses = this.keyStoreManager
|
|
1570
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1571
|
+
: [];
|
|
1572
|
+
|
|
1573
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1574
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1575
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1576
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1577
|
+
|
|
1578
|
+
if (added.length > 0) {
|
|
1579
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1580
|
+
}
|
|
1581
|
+
if (removed.length > 0) {
|
|
1582
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1583
|
+
}
|
|
1584
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1585
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1589
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1590
|
+
|
|
1591
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1592
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1593
|
+
if (this.sequencer) {
|
|
1594
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1598
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1599
|
+
const slashValidatorsNever = unique(
|
|
1600
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1601
|
+
).map(EthAddress.fromString);
|
|
1602
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
this.keyStoreManager = newManager;
|
|
1606
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1389
1610
|
if (!this.initialHeaderHashPromise) {
|
|
1390
|
-
this.initialHeaderHashPromise = this.worldStateSynchronizer
|
|
1391
|
-
.getCommitted()
|
|
1392
|
-
.getInitialHeader()
|
|
1393
|
-
.hash()
|
|
1394
|
-
.then(hash => L2BlockHash.fromField(hash));
|
|
1611
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1395
1612
|
}
|
|
1396
1613
|
return this.initialHeaderHashPromise;
|
|
1397
1614
|
}
|
|
@@ -1415,15 +1632,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1415
1632
|
return this.worldStateSynchronizer.getCommitted();
|
|
1416
1633
|
}
|
|
1417
1634
|
|
|
1418
|
-
if (
|
|
1635
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1419
1636
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1420
1637
|
if (block.equals(initialBlockHash)) {
|
|
1421
1638
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1422
1639
|
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1423
1640
|
}
|
|
1424
1641
|
|
|
1425
|
-
const
|
|
1426
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1642
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1427
1643
|
if (!header) {
|
|
1428
1644
|
throw new Error(
|
|
1429
1645
|
`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.`,
|
|
@@ -1447,6 +1663,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1447
1663
|
}
|
|
1448
1664
|
}
|
|
1449
1665
|
|
|
1666
|
+
/** Resolves a block parameter to a block number. */
|
|
1667
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1668
|
+
if (block === 'latest') {
|
|
1669
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1670
|
+
}
|
|
1671
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1672
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1673
|
+
if (block.equals(initialBlockHash)) {
|
|
1674
|
+
return BlockNumber.ZERO;
|
|
1675
|
+
}
|
|
1676
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1677
|
+
if (!header) {
|
|
1678
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1679
|
+
}
|
|
1680
|
+
return header.getBlockNumber();
|
|
1681
|
+
}
|
|
1682
|
+
return block as BlockNumber;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1450
1685
|
/**
|
|
1451
1686
|
* Ensure we fully sync the world state
|
|
1452
1687
|
* @returns A promise that fulfils once the world state is synced
|