@aztec/aztec-node 0.0.1-commit.7d4e6cd → 0.0.1-commit.7ffbba4
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/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 -97
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +389 -233
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +53 -27
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +28 -25
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +487 -304
- package/src/sentinel/factory.ts +2 -7
- package/src/sentinel/sentinel.ts +56 -23
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
3
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
4
|
+
import { Blob } from '@aztec/blob-lib';
|
|
5
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
14
8
|
import { getPublicClient } from '@aztec/ethereum/client';
|
|
15
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
16
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
17
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
18
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
19
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
20
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
21
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -23,15 +17,20 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
23
17
|
import { count } from '@aztec/foundation/string';
|
|
24
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
25
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
26
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
27
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
28
23
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
type P2P,
|
|
25
|
+
type P2PClientDeps,
|
|
26
|
+
createP2PClient,
|
|
27
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
+
getDefaultAllowedSetupFunctions,
|
|
29
|
+
} from '@aztec/p2p';
|
|
33
30
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
31
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
32
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
35
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
35
|
import {
|
|
37
36
|
AttestationsBlockWatcher,
|
|
@@ -43,13 +42,12 @@ import {
|
|
|
43
42
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
44
|
import {
|
|
45
|
+
type BlockData,
|
|
46
|
+
BlockHash,
|
|
46
47
|
type BlockParameter,
|
|
47
48
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockHash,
|
|
50
|
-
L2BlockNew,
|
|
49
|
+
L2Block,
|
|
51
50
|
type L2BlockSource,
|
|
52
|
-
type PublishedL2Block,
|
|
53
51
|
} from '@aztec/stdlib/block';
|
|
54
52
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
55
53
|
import type {
|
|
@@ -78,9 +76,9 @@ import {
|
|
|
78
76
|
type WorldStateSynchronizer,
|
|
79
77
|
tryStop,
|
|
80
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
81
|
-
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
79
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
80
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
82
81
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
83
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
84
82
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
85
83
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
86
84
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -112,7 +110,6 @@ import {
|
|
|
112
110
|
ValidatorClient,
|
|
113
111
|
createBlockProposalHandler,
|
|
114
112
|
createValidatorClient,
|
|
115
|
-
createValidatorForAcceptingTxs,
|
|
116
113
|
} from '@aztec/validator-client';
|
|
117
114
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
115
|
|
|
@@ -128,6 +125,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
125
|
*/
|
|
129
126
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
127
|
private metrics: NodeMetrics;
|
|
128
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
129
|
|
|
132
130
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
131
|
private isUploadingSnapshot = false;
|
|
@@ -143,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
143
141
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
144
142
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
145
143
|
protected readonly sequencer: SequencerClient | undefined,
|
|
144
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
146
145
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
147
146
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
148
147
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -155,12 +154,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
155
154
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
156
155
|
private log = createLogger('node'),
|
|
157
156
|
private blobClient?: BlobClientInterface,
|
|
157
|
+
private validatorClient?: ValidatorClient,
|
|
158
|
+
private keyStoreManager?: KeystoreManager,
|
|
159
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
158
160
|
) {
|
|
159
161
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
162
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
161
163
|
|
|
162
164
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
163
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
|
+
}
|
|
164
173
|
}
|
|
165
174
|
|
|
166
175
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -184,11 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
193
|
logger?: Logger;
|
|
185
194
|
publisher?: SequencerPublisher;
|
|
186
195
|
dateProvider?: DateProvider;
|
|
187
|
-
p2pClientDeps?: P2PClientDeps
|
|
196
|
+
p2pClientDeps?: P2PClientDeps;
|
|
197
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
188
198
|
} = {},
|
|
189
199
|
options: {
|
|
190
200
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
191
201
|
dontStartSequencer?: boolean;
|
|
202
|
+
dontStartProverNode?: boolean;
|
|
192
203
|
} = {},
|
|
193
204
|
): Promise<AztecNodeService> {
|
|
194
205
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -198,16 +209,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
198
209
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
199
210
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
200
211
|
|
|
201
|
-
// 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.
|
|
202
214
|
let keyStoreManager: KeystoreManager | undefined;
|
|
203
215
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
204
216
|
if (keyStoreProvided) {
|
|
205
217
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
206
218
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
207
219
|
} else {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
);
|
|
211
235
|
}
|
|
212
236
|
}
|
|
213
237
|
|
|
@@ -218,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
218
242
|
if (keyStoreManager === undefined) {
|
|
219
243
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
220
244
|
}
|
|
221
|
-
if (!keyStoreProvided) {
|
|
222
|
-
log.warn(
|
|
223
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
224
|
-
);
|
|
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");
|
|
225
247
|
}
|
|
226
248
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
227
249
|
}
|
|
@@ -249,10 +271,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
249
271
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
250
272
|
|
|
251
273
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
252
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
274
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
253
275
|
rollupContract.getL1GenesisTime(),
|
|
254
276
|
rollupContract.getSlotDuration(),
|
|
255
277
|
rollupContract.getVersion(),
|
|
278
|
+
rollupContract.getManaLimit().then(Number),
|
|
256
279
|
] as const);
|
|
257
280
|
|
|
258
281
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -263,7 +286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
263
286
|
);
|
|
264
287
|
}
|
|
265
288
|
|
|
266
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
289
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
267
290
|
|
|
268
291
|
// attempt snapshot sync if possible
|
|
269
292
|
await trySnapshotSync(config, log);
|
|
@@ -287,14 +310,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
310
|
config.realProofs || config.debugForceTxProofVerification
|
|
288
311
|
? await BBCircuitVerifier.new(config)
|
|
289
312
|
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
313
|
+
|
|
314
|
+
let debugLogStore: DebugLogStore;
|
|
290
315
|
if (!config.realProofs) {
|
|
291
316
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
317
|
+
|
|
318
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
319
|
+
log.info(
|
|
320
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
321
|
+
);
|
|
322
|
+
} else {
|
|
323
|
+
debugLogStore = new NullDebugLogStore();
|
|
292
324
|
}
|
|
325
|
+
|
|
293
326
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
294
327
|
|
|
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
|
+
|
|
295
333
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
296
334
|
const p2pClient = await createP2PClient(
|
|
297
|
-
P2PClientType.Full,
|
|
298
335
|
config,
|
|
299
336
|
archiver,
|
|
300
337
|
proofVerifier,
|
|
@@ -306,57 +343,59 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
343
|
deps.p2pClientDeps,
|
|
307
344
|
);
|
|
308
345
|
|
|
309
|
-
// We
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// Create BlockBuilder for EpochPruneWatcher (slasher functionality)
|
|
313
|
-
const blockBuilder = new BlockBuilder(
|
|
314
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
|
-
worldStateSynchronizer,
|
|
316
|
-
archiver,
|
|
317
|
-
dateProvider,
|
|
318
|
-
telemetry,
|
|
319
|
-
);
|
|
346
|
+
// We'll accumulate sentinel watchers here
|
|
347
|
+
const watchers: Watcher[] = [];
|
|
320
348
|
|
|
321
|
-
// Create FullNodeCheckpointsBuilder for
|
|
349
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
350
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
322
351
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
323
|
-
{
|
|
352
|
+
{
|
|
353
|
+
...config,
|
|
354
|
+
l1GenesisTime,
|
|
355
|
+
slotDuration: Number(slotDuration),
|
|
356
|
+
rollupManaLimit,
|
|
357
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
358
|
+
},
|
|
359
|
+
worldStateSynchronizer,
|
|
324
360
|
archiver,
|
|
325
361
|
dateProvider,
|
|
326
362
|
telemetry,
|
|
327
363
|
);
|
|
328
364
|
|
|
329
|
-
|
|
330
|
-
const watchers: Watcher[] = [];
|
|
365
|
+
let validatorClient: ValidatorClient | undefined;
|
|
331
366
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
+
});
|
|
345
381
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
+
}
|
|
353
390
|
}
|
|
354
391
|
}
|
|
355
392
|
|
|
356
|
-
// If there's no validator client
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
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' : ''));
|
|
360
399
|
createBlockProposalHandler(config, {
|
|
361
400
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
362
401
|
worldState: worldStateSynchronizer,
|
|
@@ -366,7 +405,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
366
405
|
p2pClient,
|
|
367
406
|
dateProvider,
|
|
368
407
|
telemetry,
|
|
369
|
-
}).
|
|
408
|
+
}).register(p2pClient, reexecute);
|
|
370
409
|
}
|
|
371
410
|
|
|
372
411
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -375,29 +414,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
375
414
|
// Start p2p. Note that it depends on world state to be running.
|
|
376
415
|
await p2pClient.start();
|
|
377
416
|
|
|
378
|
-
|
|
379
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
380
|
-
watchers.push(validatorsSentinel);
|
|
381
|
-
}
|
|
382
|
-
|
|
417
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
383
418
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
384
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
385
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
386
|
-
archiver,
|
|
387
|
-
archiver,
|
|
388
|
-
epochCache,
|
|
389
|
-
p2pClient.getTxProvider(),
|
|
390
|
-
blockBuilder,
|
|
391
|
-
config,
|
|
392
|
-
);
|
|
393
|
-
watchers.push(epochPruneWatcher);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
397
419
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
}
|
|
401
444
|
}
|
|
402
445
|
|
|
403
446
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -434,27 +477,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
434
477
|
);
|
|
435
478
|
await slasherClient.start();
|
|
436
479
|
|
|
437
|
-
const l1TxUtils = config.
|
|
438
|
-
? await
|
|
480
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
481
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
439
482
|
publicClient,
|
|
440
483
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
441
|
-
config.
|
|
484
|
+
config.sequencerPublisherForwarderAddress,
|
|
442
485
|
{ ...config, scope: 'sequencer' },
|
|
443
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
486
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
444
487
|
)
|
|
445
|
-
: await
|
|
488
|
+
: await createL1TxUtilsFromSigners(
|
|
446
489
|
publicClient,
|
|
447
490
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
448
491
|
{ ...config, scope: 'sequencer' },
|
|
449
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
492
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
450
493
|
);
|
|
451
494
|
|
|
452
495
|
// Create and start the sequencer client
|
|
453
496
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
454
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
497
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
498
|
+
worldStateSynchronizer,
|
|
455
499
|
archiver,
|
|
456
500
|
dateProvider,
|
|
457
501
|
telemetry,
|
|
502
|
+
debugLogStore,
|
|
458
503
|
);
|
|
459
504
|
|
|
460
505
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -482,6 +527,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
482
527
|
log.warn(`Sequencer created but not started`);
|
|
483
528
|
}
|
|
484
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
|
+
|
|
485
553
|
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
486
554
|
...config,
|
|
487
555
|
rollupVersion: BigInt(config.rollupVersion),
|
|
@@ -489,7 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
489
557
|
slotDuration: Number(slotDuration),
|
|
490
558
|
});
|
|
491
559
|
|
|
492
|
-
|
|
560
|
+
const node = new AztecNodeService(
|
|
493
561
|
config,
|
|
494
562
|
p2pClient,
|
|
495
563
|
archiver,
|
|
@@ -498,6 +566,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
498
566
|
archiver,
|
|
499
567
|
worldStateSynchronizer,
|
|
500
568
|
sequencer,
|
|
569
|
+
proverNode,
|
|
501
570
|
slasherClient,
|
|
502
571
|
validatorsSentinel,
|
|
503
572
|
epochPruneWatcher,
|
|
@@ -510,7 +579,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
510
579
|
telemetry,
|
|
511
580
|
log,
|
|
512
581
|
blobClient,
|
|
582
|
+
validatorClient,
|
|
583
|
+
keyStoreManager,
|
|
584
|
+
debugLogStore,
|
|
513
585
|
);
|
|
586
|
+
|
|
587
|
+
return node;
|
|
514
588
|
}
|
|
515
589
|
|
|
516
590
|
/**
|
|
@@ -521,6 +595,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
521
595
|
return this.sequencer;
|
|
522
596
|
}
|
|
523
597
|
|
|
598
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
599
|
+
public getProverNode(): ProverNode | undefined {
|
|
600
|
+
return this.proverNode;
|
|
601
|
+
}
|
|
602
|
+
|
|
524
603
|
public getBlockSource(): L2BlockSource {
|
|
525
604
|
return this.blockSource;
|
|
526
605
|
}
|
|
@@ -546,7 +625,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
546
625
|
}
|
|
547
626
|
|
|
548
627
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
549
|
-
return this.config.
|
|
628
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
550
629
|
}
|
|
551
630
|
|
|
552
631
|
/**
|
|
@@ -574,19 +653,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
574
653
|
enr,
|
|
575
654
|
l1ContractAddresses: contractAddresses,
|
|
576
655
|
protocolContractAddresses: protocolContractAddresses,
|
|
656
|
+
realProofs: !!this.config.realProofs,
|
|
577
657
|
};
|
|
578
658
|
|
|
579
659
|
return nodeInfo;
|
|
580
660
|
}
|
|
581
661
|
|
|
582
662
|
/**
|
|
583
|
-
* Get a block specified by its number.
|
|
584
|
-
* @param
|
|
663
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
664
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
585
665
|
* @returns The requested block.
|
|
586
666
|
*/
|
|
587
|
-
public async getBlock(
|
|
588
|
-
|
|
589
|
-
|
|
667
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
668
|
+
if (BlockHash.isBlockHash(block)) {
|
|
669
|
+
return this.getBlockByHash(block);
|
|
670
|
+
}
|
|
671
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
672
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
673
|
+
return this.buildInitialBlock();
|
|
674
|
+
}
|
|
675
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
590
676
|
}
|
|
591
677
|
|
|
592
678
|
/**
|
|
@@ -594,9 +680,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
594
680
|
* @param blockHash - The block hash being requested.
|
|
595
681
|
* @returns The requested block.
|
|
596
682
|
*/
|
|
597
|
-
public async getBlockByHash(blockHash:
|
|
598
|
-
const
|
|
599
|
-
|
|
683
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
684
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
685
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
686
|
+
return this.buildInitialBlock();
|
|
687
|
+
}
|
|
688
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
private buildInitialBlock(): L2Block {
|
|
692
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
693
|
+
return L2Block.empty(initialHeader);
|
|
600
694
|
}
|
|
601
695
|
|
|
602
696
|
/**
|
|
@@ -605,8 +699,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
605
699
|
* @returns The requested block.
|
|
606
700
|
*/
|
|
607
701
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
608
|
-
|
|
609
|
-
return publishedBlock?.block;
|
|
702
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
610
703
|
}
|
|
611
704
|
|
|
612
705
|
/**
|
|
@@ -616,23 +709,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
709
|
* @returns The blocks requested.
|
|
617
710
|
*/
|
|
618
711
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
619
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<PublishedL2Block[]> {
|
|
623
|
-
return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
627
|
-
return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
|
|
712
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
628
713
|
}
|
|
629
714
|
|
|
630
|
-
public async
|
|
631
|
-
return (await this.blockSource.
|
|
715
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
716
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
632
717
|
}
|
|
633
718
|
|
|
634
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number
|
|
635
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit
|
|
719
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
720
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
636
721
|
}
|
|
637
722
|
|
|
638
723
|
/**
|
|
@@ -663,6 +748,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
748
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
749
|
}
|
|
665
750
|
|
|
751
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
752
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
756
|
+
return this.blockSource.getCheckpointNumber();
|
|
757
|
+
}
|
|
758
|
+
|
|
666
759
|
/**
|
|
667
760
|
* Method to fetch the version of the package.
|
|
668
761
|
* @returns The node package version
|
|
@@ -695,12 +788,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
788
|
return this.contractDataSource.getContract(address);
|
|
696
789
|
}
|
|
697
790
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
791
|
+
public async getPrivateLogsByTags(
|
|
792
|
+
tags: SiloedTag[],
|
|
793
|
+
page?: number,
|
|
794
|
+
referenceBlock?: BlockHash,
|
|
795
|
+
): Promise<TxScopedL2Log[][]> {
|
|
796
|
+
if (referenceBlock) {
|
|
797
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
798
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
799
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
800
|
+
if (!header) {
|
|
801
|
+
throw new Error(
|
|
802
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
public async getPublicLogsByTagsFromContract(
|
|
811
|
+
contractAddress: AztecAddress,
|
|
812
|
+
tags: Tag[],
|
|
813
|
+
page?: number,
|
|
814
|
+
referenceBlock?: BlockHash,
|
|
815
|
+
): Promise<TxScopedL2Log[][]> {
|
|
816
|
+
if (referenceBlock) {
|
|
817
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
818
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
819
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
820
|
+
if (!header) {
|
|
821
|
+
throw new Error(
|
|
822
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
704
828
|
}
|
|
705
829
|
|
|
706
830
|
/**
|
|
@@ -742,26 +866,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
742
866
|
}
|
|
743
867
|
|
|
744
868
|
await this.p2pClient!.sendTx(tx);
|
|
745
|
-
|
|
746
|
-
this.
|
|
869
|
+
const duration = timer.ms();
|
|
870
|
+
this.metrics.receivedTx(duration, true);
|
|
871
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
747
872
|
}
|
|
748
873
|
|
|
749
874
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
755
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
756
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
757
|
-
}
|
|
875
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
876
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
877
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
878
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
879
|
|
|
880
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
881
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
882
|
+
|
|
883
|
+
let receipt: TxReceipt;
|
|
760
884
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
885
|
+
receipt = settledTxReceipt;
|
|
886
|
+
} else if (isKnownToPool) {
|
|
887
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
888
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
889
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
890
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
891
|
+
} else {
|
|
892
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
893
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
894
|
}
|
|
763
895
|
|
|
764
|
-
|
|
896
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
897
|
+
|
|
898
|
+
return receipt;
|
|
765
899
|
}
|
|
766
900
|
|
|
767
901
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -778,6 +912,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
778
912
|
await tryStop(this.slasherClient);
|
|
779
913
|
await tryStop(this.proofVerifier);
|
|
780
914
|
await tryStop(this.sequencer);
|
|
915
|
+
await tryStop(this.proverNode);
|
|
781
916
|
await tryStop(this.p2pClient);
|
|
782
917
|
await tryStop(this.worldStateSynchronizer);
|
|
783
918
|
await tryStop(this.blockSource);
|
|
@@ -826,20 +961,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
961
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
827
962
|
}
|
|
828
963
|
|
|
829
|
-
/**
|
|
830
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
831
|
-
* the leaves were inserted.
|
|
832
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
833
|
-
* @param treeId - The tree to search in.
|
|
834
|
-
* @param leafValues - The values to search for.
|
|
835
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
836
|
-
*/
|
|
837
964
|
public async findLeavesIndexes(
|
|
838
|
-
|
|
965
|
+
referenceBlock: BlockParameter,
|
|
839
966
|
treeId: MerkleTreeId,
|
|
840
967
|
leafValues: Fr[],
|
|
841
968
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
842
|
-
const committedDb = await this.#getWorldState(
|
|
969
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
843
970
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
844
971
|
treeId,
|
|
845
972
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -891,56 +1018,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
891
1018
|
}
|
|
892
1019
|
return {
|
|
893
1020
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
894
|
-
l2BlockHash:
|
|
1021
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
895
1022
|
data: index,
|
|
896
1023
|
};
|
|
897
1024
|
});
|
|
898
1025
|
}
|
|
899
1026
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
904
|
-
* @returns The sibling path for the leaf index.
|
|
905
|
-
*/
|
|
906
|
-
public async getNullifierSiblingPath(
|
|
907
|
-
blockNumber: BlockParameter,
|
|
908
|
-
leafIndex: bigint,
|
|
909
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
910
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
911
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Returns a sibling path for the given index in the data tree.
|
|
916
|
-
* @param blockNumber - The block number at which to get the data.
|
|
917
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
918
|
-
* @returns The sibling path for the leaf index.
|
|
919
|
-
*/
|
|
920
|
-
public async getNoteHashSiblingPath(
|
|
921
|
-
blockNumber: BlockParameter,
|
|
922
|
-
leafIndex: bigint,
|
|
923
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
924
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
925
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
public async getArchiveMembershipWitness(
|
|
929
|
-
blockNumber: BlockParameter,
|
|
930
|
-
archive: Fr,
|
|
1027
|
+
public async getBlockHashMembershipWitness(
|
|
1028
|
+
referenceBlock: BlockParameter,
|
|
1029
|
+
blockHash: BlockHash,
|
|
931
1030
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this.#getWorldState(
|
|
933
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
1031
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1032
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
934
1033
|
return pathAndIndex === undefined
|
|
935
1034
|
? undefined
|
|
936
1035
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
937
1036
|
}
|
|
938
1037
|
|
|
939
1038
|
public async getNoteHashMembershipWitness(
|
|
940
|
-
|
|
1039
|
+
referenceBlock: BlockParameter,
|
|
941
1040
|
noteHash: Fr,
|
|
942
1041
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
943
|
-
const committedDb = await this.#getWorldState(
|
|
1042
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
944
1043
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
945
1044
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
946
1045
|
[noteHash],
|
|
@@ -950,17 +1049,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
1049
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
951
1050
|
}
|
|
952
1051
|
|
|
953
|
-
/**
|
|
954
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
955
|
-
* @param blockNumber - The block number at which to get the data.
|
|
956
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
957
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
958
|
-
*/
|
|
959
1052
|
public async getL1ToL2MessageMembershipWitness(
|
|
960
|
-
|
|
1053
|
+
referenceBlock: BlockParameter,
|
|
961
1054
|
l1ToL2Message: Fr,
|
|
962
1055
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
963
|
-
const db = await this.#getWorldState(
|
|
1056
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
964
1057
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
965
1058
|
if (!witness) {
|
|
966
1059
|
return undefined;
|
|
@@ -970,11 +1063,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
970
1063
|
return [witness.index, witness.path];
|
|
971
1064
|
}
|
|
972
1065
|
|
|
973
|
-
public async
|
|
1066
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
974
1067
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
975
|
-
return messageIndex
|
|
976
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
977
|
-
: undefined;
|
|
1068
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
978
1069
|
}
|
|
979
1070
|
|
|
980
1071
|
/**
|
|
@@ -993,12 +1084,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
993
1084
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
994
1085
|
*/
|
|
995
1086
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
996
|
-
// Assumes `
|
|
997
|
-
const
|
|
1087
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1088
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
998
1089
|
const blocksInCheckpoints: L2Block[][] = [];
|
|
999
1090
|
let previousSlotNumber = SlotNumber.ZERO;
|
|
1000
1091
|
let checkpointIndex = -1;
|
|
1001
|
-
for (const
|
|
1092
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1093
|
+
const block = checkpointedBlock.block;
|
|
1002
1094
|
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1003
1095
|
if (slotNumber !== previousSlotNumber) {
|
|
1004
1096
|
checkpointIndex++;
|
|
@@ -1012,45 +1104,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1012
1104
|
);
|
|
1013
1105
|
}
|
|
1014
1106
|
|
|
1015
|
-
/**
|
|
1016
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
1017
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1018
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1019
|
-
* @returns The sibling path.
|
|
1020
|
-
*/
|
|
1021
|
-
public async getArchiveSiblingPath(
|
|
1022
|
-
blockNumber: BlockParameter,
|
|
1023
|
-
leafIndex: bigint,
|
|
1024
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1025
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1026
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1031
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1032
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1033
|
-
* @returns The sibling path.
|
|
1034
|
-
*/
|
|
1035
|
-
public async getPublicDataSiblingPath(
|
|
1036
|
-
blockNumber: BlockParameter,
|
|
1037
|
-
leafIndex: bigint,
|
|
1038
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1039
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1040
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1045
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1046
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1047
|
-
* @returns The nullifier membership witness (if found).
|
|
1048
|
-
*/
|
|
1049
1107
|
public async getNullifierMembershipWitness(
|
|
1050
|
-
|
|
1108
|
+
referenceBlock: BlockParameter,
|
|
1051
1109
|
nullifier: Fr,
|
|
1052
1110
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1053
|
-
const db = await this.#getWorldState(
|
|
1111
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
1054
1112
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1055
1113
|
if (!witness) {
|
|
1056
1114
|
return undefined;
|
|
@@ -1067,7 +1125,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1067
1125
|
|
|
1068
1126
|
/**
|
|
1069
1127
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1070
|
-
* @param
|
|
1128
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1129
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1071
1130
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1072
1131
|
* @returns The low nullifier membership witness (if found).
|
|
1073
1132
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1080,10 +1139,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1080
1139
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1081
1140
|
*/
|
|
1082
1141
|
public async getLowNullifierMembershipWitness(
|
|
1083
|
-
|
|
1142
|
+
referenceBlock: BlockParameter,
|
|
1084
1143
|
nullifier: Fr,
|
|
1085
1144
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1086
|
-
const committedDb = await this.#getWorldState(
|
|
1145
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1087
1146
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1088
1147
|
if (!findResult) {
|
|
1089
1148
|
return undefined;
|
|
@@ -1098,8 +1157,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1098
1157
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1099
1158
|
}
|
|
1100
1159
|
|
|
1101
|
-
async getPublicDataWitness(
|
|
1102
|
-
const committedDb = await this.#getWorldState(
|
|
1160
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1161
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1103
1162
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1104
1163
|
if (!lowLeafResult) {
|
|
1105
1164
|
return undefined;
|
|
@@ -1113,19 +1172,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1113
1172
|
}
|
|
1114
1173
|
}
|
|
1115
1174
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
*
|
|
1119
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1120
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1121
|
-
*
|
|
1122
|
-
* @param contract - Address of the contract to query.
|
|
1123
|
-
* @param slot - Slot to query.
|
|
1124
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1125
|
-
* @returns Storage value at the given contract slot.
|
|
1126
|
-
*/
|
|
1127
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1128
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1175
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1176
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1129
1177
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1130
1178
|
|
|
1131
1179
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1139,24 +1187,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1187
|
return preimage.leaf.value;
|
|
1140
1188
|
}
|
|
1141
1189
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1159
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1190
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1191
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1192
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1193
|
+
if (block.equals(initialBlockHash)) {
|
|
1194
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1195
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1196
|
+
}
|
|
1197
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1198
|
+
} else {
|
|
1199
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1200
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1201
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1202
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1203
|
+
}
|
|
1204
|
+
return this.blockSource.getBlockHeader(block);
|
|
1205
|
+
}
|
|
1160
1206
|
}
|
|
1161
1207
|
|
|
1162
1208
|
/**
|
|
@@ -1168,6 +1214,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1214
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1169
1215
|
}
|
|
1170
1216
|
|
|
1217
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1218
|
+
return this.blockSource.getBlockData(number);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1222
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1171
1225
|
/**
|
|
1172
1226
|
* Simulates the public part of a transaction with the current state.
|
|
1173
1227
|
* @param tx - The transaction to simulate.
|
|
@@ -1191,7 +1245,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1191
1245
|
}
|
|
1192
1246
|
|
|
1193
1247
|
const txHash = tx.getTxHash();
|
|
1194
|
-
const
|
|
1248
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1249
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1195
1250
|
|
|
1196
1251
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1197
1252
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1206,6 +1261,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1261
|
this.contractDataSource,
|
|
1207
1262
|
new DateProvider(),
|
|
1208
1263
|
this.telemetry,
|
|
1264
|
+
this.log.getBindings(),
|
|
1209
1265
|
);
|
|
1210
1266
|
|
|
1211
1267
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1214,6 +1270,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1214
1270
|
blockNumber,
|
|
1215
1271
|
});
|
|
1216
1272
|
|
|
1273
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1274
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1217
1275
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1218
1276
|
try {
|
|
1219
1277
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1229,7 +1287,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1229
1287
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1230
1288
|
|
|
1231
1289
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1232
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1290
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1233
1291
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1234
1292
|
if (failedTxs.length) {
|
|
1235
1293
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1243,6 +1301,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1301
|
processedTx.txEffect,
|
|
1244
1302
|
returns,
|
|
1245
1303
|
processedTx.gasUsed,
|
|
1304
|
+
debugLogs,
|
|
1246
1305
|
);
|
|
1247
1306
|
} finally {
|
|
1248
1307
|
await merkleTreeFork.close();
|
|
@@ -1256,19 +1315,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1256
1315
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1257
1316
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1258
1317
|
|
|
1259
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1318
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1260
1319
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1261
1320
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1262
|
-
const validator =
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1321
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1322
|
+
db,
|
|
1323
|
+
this.contractDataSource,
|
|
1324
|
+
verifier,
|
|
1325
|
+
{
|
|
1326
|
+
timestamp: nextSlotTimestamp,
|
|
1327
|
+
blockNumber,
|
|
1328
|
+
l1ChainId: this.l1ChainId,
|
|
1329
|
+
rollupVersion: this.version,
|
|
1330
|
+
setupAllowList: [
|
|
1331
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1332
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1333
|
+
],
|
|
1334
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1335
|
+
skipFeeEnforcement,
|
|
1336
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1337
|
+
},
|
|
1338
|
+
this.log.getBindings(),
|
|
1339
|
+
);
|
|
1272
1340
|
|
|
1273
1341
|
return await validator.validateTx(tx);
|
|
1274
1342
|
}
|
|
@@ -1432,16 +1500,107 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1432
1500
|
}
|
|
1433
1501
|
}
|
|
1434
1502
|
|
|
1503
|
+
public async reloadKeystore(): Promise<void> {
|
|
1504
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1505
|
+
throw new BadRequestError(
|
|
1506
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1507
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
if (!this.validatorClient) {
|
|
1511
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
this.log.info('Reloading keystore from disk');
|
|
1515
|
+
|
|
1516
|
+
// Re-read and validate keystore files
|
|
1517
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1518
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1519
|
+
await newManager.validateSigners();
|
|
1520
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1521
|
+
|
|
1522
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1523
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1524
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1525
|
+
// would silently fail on every proposer slot.
|
|
1526
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1527
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1528
|
+
const availablePublishers = new Set(
|
|
1529
|
+
oldAdapter
|
|
1530
|
+
.getAttesterAddresses()
|
|
1531
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1532
|
+
);
|
|
1533
|
+
|
|
1534
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1535
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1536
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1537
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1538
|
+
throw new BadRequestError(
|
|
1539
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1540
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1541
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1542
|
+
`use an existing publisher key or restart the node.`,
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// Build adapters for old and new keystores to compute diff
|
|
1549
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1550
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1551
|
+
const oldAddresses = this.keyStoreManager
|
|
1552
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1553
|
+
: [];
|
|
1554
|
+
|
|
1555
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1556
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1557
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1558
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1559
|
+
|
|
1560
|
+
if (added.length > 0) {
|
|
1561
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1562
|
+
}
|
|
1563
|
+
if (removed.length > 0) {
|
|
1564
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1565
|
+
}
|
|
1566
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1567
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1571
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1572
|
+
|
|
1573
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1574
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1575
|
+
if (this.sequencer) {
|
|
1576
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1580
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1581
|
+
const slashValidatorsNever = unique(
|
|
1582
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1583
|
+
).map(EthAddress.fromString);
|
|
1584
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
this.keyStoreManager = newManager;
|
|
1588
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1592
|
+
if (!this.initialHeaderHashPromise) {
|
|
1593
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1594
|
+
}
|
|
1595
|
+
return this.initialHeaderHashPromise;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1435
1598
|
/**
|
|
1436
1599
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1437
|
-
* @param
|
|
1600
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1438
1601
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1439
1602
|
*/
|
|
1440
|
-
async #getWorldState(
|
|
1441
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1442
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1603
|
+
async #getWorldState(block: BlockParameter) {
|
|
1445
1604
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1446
1605
|
try {
|
|
1447
1606
|
// Attempt to sync the world state if necessary
|
|
@@ -1450,15 +1609,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1450
1609
|
this.log.error(`Error getting world state: ${err}`);
|
|
1451
1610
|
}
|
|
1452
1611
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1612
|
+
if (block === 'latest') {
|
|
1613
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1456
1614
|
return this.worldStateSynchronizer.getCommitted();
|
|
1457
|
-
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1618
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1619
|
+
if (block.equals(initialBlockHash)) {
|
|
1620
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1621
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1625
|
+
if (!header) {
|
|
1626
|
+
throw new Error(
|
|
1627
|
+
`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.`,
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
const blockNumber = header.getBlockNumber();
|
|
1458
1631
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1459
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1632
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// Block number provided
|
|
1636
|
+
{
|
|
1637
|
+
const blockNumber = block as BlockNumber;
|
|
1638
|
+
|
|
1639
|
+
if (blockNumber > blockSyncedTo) {
|
|
1640
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1644
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1462
1645
|
}
|
|
1463
1646
|
}
|
|
1464
1647
|
|