@aztec/aztec-node 0.0.1-commit.86469d5 → 0.0.1-commit.88c5703d4
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 +8 -5
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +11 -3
- package/dest/aztec-node/server.d.ts +28 -7
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +326 -147
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +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 +26 -25
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/server.ts +394 -159
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +59 -26
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,14 +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 { Blob } from '@aztec/blob-lib';
|
|
4
5
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
5
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
6
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
7
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
8
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
8
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
9
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
10
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
12
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -16,14 +17,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
16
17
|
import { count } from '@aztec/foundation/string';
|
|
17
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
18
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
19
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
21
23
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
type P2P,
|
|
25
|
+
type P2PClientDeps,
|
|
26
|
+
createP2PClient,
|
|
27
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
+
getDefaultAllowedSetupFunctions,
|
|
29
|
+
} from '@aztec/p2p';
|
|
26
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';
|
|
27
33
|
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
28
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
29
35
|
import {
|
|
@@ -35,7 +41,14 @@ import {
|
|
|
35
41
|
} from '@aztec/slasher';
|
|
36
42
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
37
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
38
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
type BlockData,
|
|
46
|
+
BlockHash,
|
|
47
|
+
type BlockParameter,
|
|
48
|
+
type DataInBlock,
|
|
49
|
+
L2Block,
|
|
50
|
+
type L2BlockSource,
|
|
51
|
+
} from '@aztec/stdlib/block';
|
|
39
52
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
40
53
|
import type {
|
|
41
54
|
ContractClassPublic,
|
|
@@ -63,9 +76,9 @@ import {
|
|
|
63
76
|
type WorldStateSynchronizer,
|
|
64
77
|
tryStop,
|
|
65
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
66
|
-
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';
|
|
67
81
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
68
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
69
82
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
70
83
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
71
84
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -97,11 +110,10 @@ import {
|
|
|
97
110
|
ValidatorClient,
|
|
98
111
|
createBlockProposalHandler,
|
|
99
112
|
createValidatorClient,
|
|
100
|
-
createValidatorForAcceptingTxs,
|
|
101
113
|
} from '@aztec/validator-client';
|
|
102
114
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
103
115
|
|
|
104
|
-
import { createPublicClient
|
|
116
|
+
import { createPublicClient } from 'viem';
|
|
105
117
|
|
|
106
118
|
import { createSentinel } from '../sentinel/factory.js';
|
|
107
119
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -129,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
129
141
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
130
142
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
131
143
|
protected readonly sequencer: SequencerClient | undefined,
|
|
144
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
132
145
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
133
146
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
134
147
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -141,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
141
154
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
142
155
|
private log = createLogger('node'),
|
|
143
156
|
private blobClient?: BlobClientInterface,
|
|
157
|
+
private validatorClient?: ValidatorClient,
|
|
158
|
+
private keyStoreManager?: KeystoreManager,
|
|
159
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
144
160
|
) {
|
|
145
161
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
146
162
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
147
163
|
|
|
148
164
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
149
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
|
+
}
|
|
150
173
|
}
|
|
151
174
|
|
|
152
175
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -170,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
170
193
|
logger?: Logger;
|
|
171
194
|
publisher?: SequencerPublisher;
|
|
172
195
|
dateProvider?: DateProvider;
|
|
173
|
-
p2pClientDeps?: P2PClientDeps
|
|
196
|
+
p2pClientDeps?: P2PClientDeps;
|
|
197
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
174
198
|
} = {},
|
|
175
199
|
options: {
|
|
176
200
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
177
201
|
dontStartSequencer?: boolean;
|
|
202
|
+
dontStartProverNode?: boolean;
|
|
178
203
|
} = {},
|
|
179
204
|
): Promise<AztecNodeService> {
|
|
180
205
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -184,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
209
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
185
210
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
186
211
|
|
|
187
|
-
// 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.
|
|
188
214
|
let keyStoreManager: KeystoreManager | undefined;
|
|
189
215
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
190
216
|
if (keyStoreProvided) {
|
|
191
217
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
192
218
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
193
219
|
} else {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
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
|
+
);
|
|
197
235
|
}
|
|
198
236
|
}
|
|
199
237
|
|
|
@@ -204,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
204
242
|
if (keyStoreManager === undefined) {
|
|
205
243
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
206
244
|
}
|
|
207
|
-
if (!keyStoreProvided) {
|
|
208
|
-
log.warn(
|
|
209
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
210
|
-
);
|
|
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");
|
|
211
247
|
}
|
|
212
248
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
213
249
|
}
|
|
@@ -221,7 +257,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
221
257
|
|
|
222
258
|
const publicClient = createPublicClient({
|
|
223
259
|
chain: ethereumChain.chainInfo,
|
|
224
|
-
transport:
|
|
260
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
225
261
|
pollingInterval: config.viemPollingIntervalMS,
|
|
226
262
|
});
|
|
227
263
|
|
|
@@ -235,10 +271,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
235
271
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
236
272
|
|
|
237
273
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
238
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
274
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
239
275
|
rollupContract.getL1GenesisTime(),
|
|
240
276
|
rollupContract.getSlotDuration(),
|
|
241
277
|
rollupContract.getVersion(),
|
|
278
|
+
rollupContract.getManaLimit().then(Number),
|
|
242
279
|
] as const);
|
|
243
280
|
|
|
244
281
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -249,7 +286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
249
286
|
);
|
|
250
287
|
}
|
|
251
288
|
|
|
252
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
289
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
253
290
|
|
|
254
291
|
// attempt snapshot sync if possible
|
|
255
292
|
await trySnapshotSync(config, log);
|
|
@@ -273,14 +310,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
273
310
|
config.realProofs || config.debugForceTxProofVerification
|
|
274
311
|
? await BBCircuitVerifier.new(config)
|
|
275
312
|
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
313
|
+
|
|
314
|
+
let debugLogStore: DebugLogStore;
|
|
276
315
|
if (!config.realProofs) {
|
|
277
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();
|
|
278
324
|
}
|
|
325
|
+
|
|
279
326
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
280
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
|
+
|
|
281
333
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
282
334
|
const p2pClient = await createP2PClient(
|
|
283
|
-
P2PClientType.Full,
|
|
284
335
|
config,
|
|
285
336
|
archiver,
|
|
286
337
|
proofVerifier,
|
|
@@ -292,49 +343,59 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
292
343
|
deps.p2pClientDeps,
|
|
293
344
|
);
|
|
294
345
|
|
|
295
|
-
// We
|
|
296
|
-
|
|
346
|
+
// We'll accumulate sentinel watchers here
|
|
347
|
+
const watchers: Watcher[] = [];
|
|
297
348
|
|
|
298
|
-
// Create FullNodeCheckpointsBuilder for
|
|
349
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
350
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
299
351
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
300
|
-
{
|
|
352
|
+
{
|
|
353
|
+
...config,
|
|
354
|
+
l1GenesisTime,
|
|
355
|
+
slotDuration: Number(slotDuration),
|
|
356
|
+
rollupManaLimit,
|
|
357
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
358
|
+
},
|
|
301
359
|
worldStateSynchronizer,
|
|
302
360
|
archiver,
|
|
303
361
|
dateProvider,
|
|
304
362
|
telemetry,
|
|
305
363
|
);
|
|
306
364
|
|
|
307
|
-
|
|
308
|
-
const watchers: Watcher[] = [];
|
|
365
|
+
let validatorClient: ValidatorClient | undefined;
|
|
309
366
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
+
});
|
|
323
381
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
+
}
|
|
331
390
|
}
|
|
332
391
|
}
|
|
333
392
|
|
|
334
|
-
// If there's no validator client
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
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' : ''));
|
|
338
399
|
createBlockProposalHandler(config, {
|
|
339
400
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
340
401
|
worldState: worldStateSynchronizer,
|
|
@@ -344,7 +405,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
344
405
|
p2pClient,
|
|
345
406
|
dateProvider,
|
|
346
407
|
telemetry,
|
|
347
|
-
}).
|
|
408
|
+
}).register(p2pClient, reexecute);
|
|
348
409
|
}
|
|
349
410
|
|
|
350
411
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -353,29 +414,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
353
414
|
// Start p2p. Note that it depends on world state to be running.
|
|
354
415
|
await p2pClient.start();
|
|
355
416
|
|
|
356
|
-
|
|
357
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
358
|
-
watchers.push(validatorsSentinel);
|
|
359
|
-
}
|
|
360
|
-
|
|
417
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
361
418
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
362
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
363
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
364
|
-
archiver,
|
|
365
|
-
archiver,
|
|
366
|
-
epochCache,
|
|
367
|
-
p2pClient.getTxProvider(),
|
|
368
|
-
validatorCheckpointsBuilder,
|
|
369
|
-
config,
|
|
370
|
-
);
|
|
371
|
-
watchers.push(epochPruneWatcher);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
375
419
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
+
}
|
|
379
444
|
}
|
|
380
445
|
|
|
381
446
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -412,28 +477,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
412
477
|
);
|
|
413
478
|
await slasherClient.start();
|
|
414
479
|
|
|
415
|
-
const l1TxUtils = config.
|
|
416
|
-
? await
|
|
480
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
481
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
417
482
|
publicClient,
|
|
418
483
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
419
|
-
config.
|
|
484
|
+
config.sequencerPublisherForwarderAddress,
|
|
420
485
|
{ ...config, scope: 'sequencer' },
|
|
421
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
486
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
422
487
|
)
|
|
423
|
-
: await
|
|
488
|
+
: await createL1TxUtilsFromSigners(
|
|
424
489
|
publicClient,
|
|
425
490
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
426
491
|
{ ...config, scope: 'sequencer' },
|
|
427
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
492
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
428
493
|
);
|
|
429
494
|
|
|
430
495
|
// Create and start the sequencer client
|
|
431
496
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
432
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
497
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
433
498
|
worldStateSynchronizer,
|
|
434
499
|
archiver,
|
|
435
500
|
dateProvider,
|
|
436
501
|
telemetry,
|
|
502
|
+
debugLogStore,
|
|
437
503
|
);
|
|
438
504
|
|
|
439
505
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -461,6 +527,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
461
527
|
log.warn(`Sequencer created but not started`);
|
|
462
528
|
}
|
|
463
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
|
+
|
|
464
553
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
465
554
|
...config,
|
|
466
555
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -468,7 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
468
557
|
slotDuration: Number(slotDuration),
|
|
469
558
|
});
|
|
470
559
|
|
|
471
|
-
|
|
560
|
+
const node = new AztecNodeService(
|
|
472
561
|
config,
|
|
473
562
|
p2pClient,
|
|
474
563
|
archiver,
|
|
@@ -477,6 +566,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
477
566
|
archiver,
|
|
478
567
|
worldStateSynchronizer,
|
|
479
568
|
sequencer,
|
|
569
|
+
proverNode,
|
|
480
570
|
slasherClient,
|
|
481
571
|
validatorsSentinel,
|
|
482
572
|
epochPruneWatcher,
|
|
@@ -489,7 +579,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
489
579
|
telemetry,
|
|
490
580
|
log,
|
|
491
581
|
blobClient,
|
|
582
|
+
validatorClient,
|
|
583
|
+
keyStoreManager,
|
|
584
|
+
debugLogStore,
|
|
492
585
|
);
|
|
586
|
+
|
|
587
|
+
return node;
|
|
493
588
|
}
|
|
494
589
|
|
|
495
590
|
/**
|
|
@@ -500,6 +595,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
500
595
|
return this.sequencer;
|
|
501
596
|
}
|
|
502
597
|
|
|
598
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
599
|
+
public getProverNode(): ProverNode | undefined {
|
|
600
|
+
return this.proverNode;
|
|
601
|
+
}
|
|
602
|
+
|
|
503
603
|
public getBlockSource(): L2BlockSource {
|
|
504
604
|
return this.blockSource;
|
|
505
605
|
}
|
|
@@ -525,7 +625,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
525
625
|
}
|
|
526
626
|
|
|
527
627
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
528
|
-
return this.config.
|
|
628
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
529
629
|
}
|
|
530
630
|
|
|
531
631
|
/**
|
|
@@ -553,6 +653,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
553
653
|
enr,
|
|
554
654
|
l1ContractAddresses: contractAddresses,
|
|
555
655
|
protocolContractAddresses: protocolContractAddresses,
|
|
656
|
+
realProofs: !!this.config.realProofs,
|
|
556
657
|
};
|
|
557
658
|
|
|
558
659
|
return nodeInfo;
|
|
@@ -619,6 +720,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
619
720
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
620
721
|
}
|
|
621
722
|
|
|
723
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
724
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
725
|
+
}
|
|
726
|
+
|
|
622
727
|
/**
|
|
623
728
|
* Method to fetch the current min L2 fees.
|
|
624
729
|
* @returns The current min L2 fees.
|
|
@@ -651,6 +756,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
651
756
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
652
757
|
}
|
|
653
758
|
|
|
759
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
760
|
+
return this.blockSource.getCheckpointNumber();
|
|
761
|
+
}
|
|
762
|
+
|
|
654
763
|
/**
|
|
655
764
|
* Method to fetch the version of the package.
|
|
656
765
|
* @returns The node package version
|
|
@@ -688,18 +797,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
688
797
|
page?: number,
|
|
689
798
|
referenceBlock?: BlockHash,
|
|
690
799
|
): Promise<TxScopedL2Log[][]> {
|
|
800
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
691
801
|
if (referenceBlock) {
|
|
692
802
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
693
|
-
if (
|
|
803
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
804
|
+
upToBlockNumber = BlockNumber(0);
|
|
805
|
+
} else {
|
|
694
806
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
695
807
|
if (!header) {
|
|
696
808
|
throw new Error(
|
|
697
809
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
698
810
|
);
|
|
699
811
|
}
|
|
812
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
700
813
|
}
|
|
701
814
|
}
|
|
702
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
815
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
703
816
|
}
|
|
704
817
|
|
|
705
818
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -708,18 +821,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
708
821
|
page?: number,
|
|
709
822
|
referenceBlock?: BlockHash,
|
|
710
823
|
): Promise<TxScopedL2Log[][]> {
|
|
824
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
711
825
|
if (referenceBlock) {
|
|
712
826
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
713
|
-
if (
|
|
827
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
828
|
+
upToBlockNumber = BlockNumber(0);
|
|
829
|
+
} else {
|
|
714
830
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
715
831
|
if (!header) {
|
|
716
832
|
throw new Error(
|
|
717
833
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
718
834
|
);
|
|
719
835
|
}
|
|
836
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
720
837
|
}
|
|
721
838
|
}
|
|
722
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
839
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
723
840
|
}
|
|
724
841
|
|
|
725
842
|
/**
|
|
@@ -761,8 +878,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
761
878
|
}
|
|
762
879
|
|
|
763
880
|
await this.p2pClient!.sendTx(tx);
|
|
764
|
-
|
|
765
|
-
this.
|
|
881
|
+
const duration = timer.ms();
|
|
882
|
+
this.metrics.receivedTx(duration, true);
|
|
883
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
766
884
|
}
|
|
767
885
|
|
|
768
886
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
@@ -774,18 +892,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
774
892
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
775
893
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
776
894
|
|
|
895
|
+
let receipt: TxReceipt;
|
|
777
896
|
if (settledTxReceipt) {
|
|
778
|
-
|
|
779
|
-
return settledTxReceipt;
|
|
897
|
+
receipt = settledTxReceipt;
|
|
780
898
|
} else if (isKnownToPool) {
|
|
781
899
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
782
900
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
783
901
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
784
|
-
|
|
902
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
785
903
|
} else {
|
|
786
904
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
787
|
-
|
|
905
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
788
906
|
}
|
|
907
|
+
|
|
908
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
909
|
+
|
|
910
|
+
return receipt;
|
|
789
911
|
}
|
|
790
912
|
|
|
791
913
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -802,6 +924,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
802
924
|
await tryStop(this.slasherClient);
|
|
803
925
|
await tryStop(this.proofVerifier);
|
|
804
926
|
await tryStop(this.sequencer);
|
|
927
|
+
await tryStop(this.proverNode);
|
|
805
928
|
await tryStop(this.p2pClient);
|
|
806
929
|
await tryStop(this.worldStateSynchronizer);
|
|
807
930
|
await tryStop(this.blockSource);
|
|
@@ -855,58 +978,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
855
978
|
treeId: MerkleTreeId,
|
|
856
979
|
leafValues: Fr[],
|
|
857
980
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
858
|
-
const committedDb = await this
|
|
981
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
859
982
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
860
983
|
treeId,
|
|
861
984
|
leafValues.map(x => x.toBuffer()),
|
|
862
985
|
);
|
|
863
|
-
//
|
|
864
|
-
const
|
|
986
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
987
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
865
988
|
|
|
866
|
-
// Now we find the block numbers for the indices
|
|
867
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
989
|
+
// Now we find the block numbers for the defined indices
|
|
990
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
868
991
|
|
|
869
|
-
//
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
992
|
+
// Build a map from leaf index to block number
|
|
993
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
994
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
995
|
+
const blockNumber = blockNumbers[i];
|
|
996
|
+
if (blockNumber === undefined) {
|
|
997
|
+
throw new Error(
|
|
998
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
999
|
+
);
|
|
873
1000
|
}
|
|
1001
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
874
1002
|
}
|
|
875
1003
|
|
|
876
1004
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
877
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1005
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
878
1006
|
|
|
879
|
-
// Now we obtain the block hashes from the archive tree
|
|
880
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1007
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
881
1008
|
const blockHashes = await Promise.all(
|
|
882
1009
|
uniqueBlockNumbers.map(blockNumber => {
|
|
883
1010
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
884
1011
|
}),
|
|
885
1012
|
);
|
|
886
1013
|
|
|
887
|
-
//
|
|
1014
|
+
// Build a map from block number to block hash
|
|
1015
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
888
1016
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
889
|
-
|
|
1017
|
+
const blockHash = blockHashes[i];
|
|
1018
|
+
if (blockHash === undefined) {
|
|
890
1019
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
891
1020
|
}
|
|
1021
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
892
1022
|
}
|
|
893
1023
|
|
|
894
1024
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
895
|
-
return maybeIndices.map(
|
|
1025
|
+
return maybeIndices.map(index => {
|
|
896
1026
|
if (index === undefined) {
|
|
897
1027
|
return undefined;
|
|
898
1028
|
}
|
|
899
|
-
const blockNumber =
|
|
1029
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
900
1030
|
if (blockNumber === undefined) {
|
|
901
|
-
|
|
1031
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
902
1032
|
}
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
return undefined;
|
|
1033
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1034
|
+
if (blockHash === undefined) {
|
|
1035
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
907
1036
|
}
|
|
908
1037
|
return {
|
|
909
|
-
l2BlockNumber:
|
|
1038
|
+
l2BlockNumber: blockNumber,
|
|
910
1039
|
l2BlockHash: new BlockHash(blockHash),
|
|
911
1040
|
data: index,
|
|
912
1041
|
};
|
|
@@ -917,7 +1046,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
917
1046
|
referenceBlock: BlockParameter,
|
|
918
1047
|
blockHash: BlockHash,
|
|
919
1048
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
920
|
-
const committedDb = await this
|
|
1049
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
921
1050
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
922
1051
|
return pathAndIndex === undefined
|
|
923
1052
|
? undefined
|
|
@@ -928,7 +1057,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
928
1057
|
referenceBlock: BlockParameter,
|
|
929
1058
|
noteHash: Fr,
|
|
930
1059
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
931
|
-
const committedDb = await this
|
|
1060
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
932
1061
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
933
1062
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
934
1063
|
[noteHash],
|
|
@@ -942,7 +1071,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
942
1071
|
referenceBlock: BlockParameter,
|
|
943
1072
|
l1ToL2Message: Fr,
|
|
944
1073
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
945
|
-
const db = await this
|
|
1074
|
+
const db = await this.getWorldState(referenceBlock);
|
|
946
1075
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
947
1076
|
if (!witness) {
|
|
948
1077
|
return undefined;
|
|
@@ -952,11 +1081,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
952
1081
|
return [witness.index, witness.path];
|
|
953
1082
|
}
|
|
954
1083
|
|
|
955
|
-
public async
|
|
1084
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
956
1085
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
957
|
-
return messageIndex
|
|
958
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
959
|
-
: undefined;
|
|
1086
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
960
1087
|
}
|
|
961
1088
|
|
|
962
1089
|
/**
|
|
@@ -977,19 +1104,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
977
1104
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
978
1105
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
979
1106
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
980
|
-
const blocksInCheckpoints
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
984
|
-
const block = checkpointedBlock.block;
|
|
985
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
|
-
if (slotNumber !== previousSlotNumber) {
|
|
987
|
-
checkpointIndex++;
|
|
988
|
-
blocksInCheckpoints.push([]);
|
|
989
|
-
previousSlotNumber = slotNumber;
|
|
990
|
-
}
|
|
991
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
992
|
-
}
|
|
1107
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1108
|
+
group => group.map(cb => cb.block),
|
|
1109
|
+
);
|
|
993
1110
|
return blocksInCheckpoints.map(blocks =>
|
|
994
1111
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
995
1112
|
);
|
|
@@ -999,7 +1116,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
999
1116
|
referenceBlock: BlockParameter,
|
|
1000
1117
|
nullifier: Fr,
|
|
1001
1118
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1002
|
-
const db = await this
|
|
1119
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1003
1120
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1004
1121
|
if (!witness) {
|
|
1005
1122
|
return undefined;
|
|
@@ -1033,7 +1150,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1033
1150
|
referenceBlock: BlockParameter,
|
|
1034
1151
|
nullifier: Fr,
|
|
1035
1152
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1036
|
-
const committedDb = await this
|
|
1153
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1037
1154
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1038
1155
|
if (!findResult) {
|
|
1039
1156
|
return undefined;
|
|
@@ -1049,7 +1166,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1049
1166
|
}
|
|
1050
1167
|
|
|
1051
1168
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1052
|
-
const committedDb = await this
|
|
1169
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1053
1170
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1054
1171
|
if (!lowLeafResult) {
|
|
1055
1172
|
return undefined;
|
|
@@ -1064,7 +1181,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1064
1181
|
}
|
|
1065
1182
|
|
|
1066
1183
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1067
|
-
const committedDb = await this
|
|
1184
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1068
1185
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1069
1186
|
|
|
1070
1187
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1105,6 +1222,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1105
1222
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1106
1223
|
}
|
|
1107
1224
|
|
|
1225
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1226
|
+
return this.blockSource.getBlockData(number);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1230
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1108
1233
|
/**
|
|
1109
1234
|
* Simulates the public part of a transaction with the current state.
|
|
1110
1235
|
* @param tx - The transaction to simulate.
|
|
@@ -1128,7 +1253,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1128
1253
|
}
|
|
1129
1254
|
|
|
1130
1255
|
const txHash = tx.getTxHash();
|
|
1131
|
-
const
|
|
1256
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1257
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1132
1258
|
|
|
1133
1259
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1134
1260
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1152,6 +1278,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1152
1278
|
blockNumber,
|
|
1153
1279
|
});
|
|
1154
1280
|
|
|
1281
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1282
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1155
1283
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1156
1284
|
try {
|
|
1157
1285
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1167,7 +1295,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1167
1295
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1168
1296
|
|
|
1169
1297
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1170
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1298
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1171
1299
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1172
1300
|
if (failedTxs.length) {
|
|
1173
1301
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1181,6 +1309,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1181
1309
|
processedTx.txEffect,
|
|
1182
1310
|
returns,
|
|
1183
1311
|
processedTx.gasUsed,
|
|
1312
|
+
debugLogs,
|
|
1184
1313
|
);
|
|
1185
1314
|
} finally {
|
|
1186
1315
|
await merkleTreeFork.close();
|
|
@@ -1194,10 +1323,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1194
1323
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1195
1324
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1196
1325
|
|
|
1197
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1326
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1198
1327
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1199
1328
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1200
|
-
const
|
|
1329
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1330
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1201
1331
|
db,
|
|
1202
1332
|
this.contractDataSource,
|
|
1203
1333
|
verifier,
|
|
@@ -1206,10 +1336,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1336
|
blockNumber,
|
|
1207
1337
|
l1ChainId: this.l1ChainId,
|
|
1208
1338
|
rollupVersion: this.version,
|
|
1209
|
-
setupAllowList:
|
|
1339
|
+
setupAllowList: [
|
|
1340
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1341
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1342
|
+
],
|
|
1210
1343
|
gasFees: await this.getCurrentMinFees(),
|
|
1211
1344
|
skipFeeEnforcement,
|
|
1212
1345
|
txsPermitted: !this.config.disableTransactions,
|
|
1346
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1347
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1348
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1213
1349
|
},
|
|
1214
1350
|
this.log.getBindings(),
|
|
1215
1351
|
);
|
|
@@ -1376,6 +1512,94 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1376
1512
|
}
|
|
1377
1513
|
}
|
|
1378
1514
|
|
|
1515
|
+
public async reloadKeystore(): Promise<void> {
|
|
1516
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1517
|
+
throw new BadRequestError(
|
|
1518
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1519
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1520
|
+
);
|
|
1521
|
+
}
|
|
1522
|
+
if (!this.validatorClient) {
|
|
1523
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
this.log.info('Reloading keystore from disk');
|
|
1527
|
+
|
|
1528
|
+
// Re-read and validate keystore files
|
|
1529
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1530
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1531
|
+
await newManager.validateSigners();
|
|
1532
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1533
|
+
|
|
1534
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1535
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1536
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1537
|
+
// would silently fail on every proposer slot.
|
|
1538
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1539
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1540
|
+
const availablePublishers = new Set(
|
|
1541
|
+
oldAdapter
|
|
1542
|
+
.getAttesterAddresses()
|
|
1543
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1544
|
+
);
|
|
1545
|
+
|
|
1546
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1547
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1548
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1549
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1550
|
+
throw new BadRequestError(
|
|
1551
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1552
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1553
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1554
|
+
`use an existing publisher key or restart the node.`,
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// Build adapters for old and new keystores to compute diff
|
|
1561
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1562
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1563
|
+
const oldAddresses = this.keyStoreManager
|
|
1564
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1565
|
+
: [];
|
|
1566
|
+
|
|
1567
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1568
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1569
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1570
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1571
|
+
|
|
1572
|
+
if (added.length > 0) {
|
|
1573
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1574
|
+
}
|
|
1575
|
+
if (removed.length > 0) {
|
|
1576
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1577
|
+
}
|
|
1578
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1579
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1583
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1584
|
+
|
|
1585
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1586
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1587
|
+
if (this.sequencer) {
|
|
1588
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1592
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1593
|
+
const slashValidatorsNever = unique(
|
|
1594
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1595
|
+
).map(EthAddress.fromString);
|
|
1596
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
this.keyStoreManager = newManager;
|
|
1600
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1379
1603
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1380
1604
|
if (!this.initialHeaderHashPromise) {
|
|
1381
1605
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1388,7 +1612,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1388
1612
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1389
1613
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1390
1614
|
*/
|
|
1391
|
-
async
|
|
1615
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1392
1616
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1393
1617
|
try {
|
|
1394
1618
|
// Attempt to sync the world state if necessary
|
|
@@ -1402,6 +1626,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1402
1626
|
return this.worldStateSynchronizer.getCommitted();
|
|
1403
1627
|
}
|
|
1404
1628
|
|
|
1629
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1630
|
+
let blockNumber: BlockNumber;
|
|
1405
1631
|
if (BlockHash.isBlockHash(block)) {
|
|
1406
1632
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1407
1633
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1415,22 +1641,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1415
1641
|
`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.`,
|
|
1416
1642
|
);
|
|
1417
1643
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1644
|
+
|
|
1645
|
+
blockNumber = header.getBlockNumber();
|
|
1646
|
+
} else {
|
|
1647
|
+
blockNumber = block as BlockNumber;
|
|
1421
1648
|
}
|
|
1422
1649
|
|
|
1423
|
-
//
|
|
1424
|
-
{
|
|
1425
|
-
|
|
1650
|
+
// Check it's within world state sync range
|
|
1651
|
+
if (blockNumber > blockSyncedTo) {
|
|
1652
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1653
|
+
}
|
|
1654
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1426
1655
|
|
|
1427
|
-
|
|
1428
|
-
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1429
|
-
}
|
|
1656
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1430
1657
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1658
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1659
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1660
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1661
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1662
|
+
throw new Error(
|
|
1663
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1433
1666
|
}
|
|
1667
|
+
|
|
1668
|
+
return snapshot;
|
|
1434
1669
|
}
|
|
1435
1670
|
|
|
1436
1671
|
/**
|