@aztec/aztec-node 0.0.1-commit.29c6b1a3 → 0.0.1-commit.2d9cb6034
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 +46 -36
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +443 -218
- 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 +61 -35
- 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/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +529 -266
- package/src/sentinel/factory.ts +2 -7
- package/src/sentinel/sentinel.ts +64 -31
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
7
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
8
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
9
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
10
|
-
} from '@aztec/constants';
|
|
5
|
+
import { Blob } from '@aztec/blob-lib';
|
|
6
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
11
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
12
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
13
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
14
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
15
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
16
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
17
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
18
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
19
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
20
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
@@ -22,14 +19,19 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
|
22
19
|
import { count } from '@aztec/foundation/string';
|
|
23
20
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
24
21
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
25
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
22
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
26
23
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
24
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
27
25
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
type P2P,
|
|
27
|
+
type P2PClientDeps,
|
|
28
|
+
createP2PClient,
|
|
29
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
30
|
+
getDefaultAllowedSetupFunctions,
|
|
31
|
+
} from '@aztec/p2p';
|
|
32
32
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
33
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
34
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
35
|
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
34
36
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
35
37
|
import {
|
|
@@ -41,7 +43,14 @@ import {
|
|
|
41
43
|
} from '@aztec/slasher';
|
|
42
44
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
43
45
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
type BlockData,
|
|
48
|
+
BlockHash,
|
|
49
|
+
type BlockParameter,
|
|
50
|
+
type DataInBlock,
|
|
51
|
+
L2Block,
|
|
52
|
+
type L2BlockSource,
|
|
53
|
+
} from '@aztec/stdlib/block';
|
|
45
54
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
46
55
|
import type {
|
|
47
56
|
ContractClassPublic,
|
|
@@ -69,9 +78,9 @@ import {
|
|
|
69
78
|
type WorldStateSynchronizer,
|
|
70
79
|
tryStop,
|
|
71
80
|
} from '@aztec/stdlib/interfaces/server';
|
|
72
|
-
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
81
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
82
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
73
83
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
74
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
75
84
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
76
85
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
77
86
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -101,13 +110,13 @@ import {
|
|
|
101
110
|
FullNodeCheckpointsBuilder,
|
|
102
111
|
NodeKeystoreAdapter,
|
|
103
112
|
ValidatorClient,
|
|
104
|
-
|
|
113
|
+
createProposalHandler,
|
|
105
114
|
createValidatorClient,
|
|
106
|
-
createValidatorForAcceptingTxs,
|
|
107
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
108
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
109
118
|
|
|
110
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
111
120
|
|
|
112
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
113
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -135,6 +144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
135
144
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
136
145
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
137
146
|
protected readonly sequencer: SequencerClient | undefined,
|
|
147
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
138
148
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
139
149
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
140
150
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -143,16 +153,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
143
153
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
144
154
|
protected readonly epochCache: EpochCacheInterface,
|
|
145
155
|
protected readonly packageVersion: string,
|
|
146
|
-
private
|
|
156
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
147
158
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
148
159
|
private log = createLogger('node'),
|
|
149
160
|
private blobClient?: BlobClientInterface,
|
|
161
|
+
private validatorClient?: ValidatorClient,
|
|
162
|
+
private keyStoreManager?: KeystoreManager,
|
|
163
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
150
164
|
) {
|
|
151
165
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
152
166
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
153
167
|
|
|
154
168
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
155
169
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
170
|
+
|
|
171
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
172
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
173
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
174
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
175
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
180
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
181
|
+
return this.rpcProofVerifier;
|
|
156
182
|
}
|
|
157
183
|
|
|
158
184
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -176,11 +202,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
176
202
|
logger?: Logger;
|
|
177
203
|
publisher?: SequencerPublisher;
|
|
178
204
|
dateProvider?: DateProvider;
|
|
179
|
-
p2pClientDeps?: P2PClientDeps
|
|
205
|
+
p2pClientDeps?: P2PClientDeps;
|
|
206
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
207
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
180
208
|
} = {},
|
|
181
209
|
options: {
|
|
182
210
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
183
211
|
dontStartSequencer?: boolean;
|
|
212
|
+
dontStartProverNode?: boolean;
|
|
184
213
|
} = {},
|
|
185
214
|
): Promise<AztecNodeService> {
|
|
186
215
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -190,16 +219,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
190
219
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
191
220
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
192
221
|
|
|
193
|
-
// Build a key store from file if given or from environment otherwise
|
|
222
|
+
// Build a key store from file if given or from environment otherwise.
|
|
223
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
194
224
|
let keyStoreManager: KeystoreManager | undefined;
|
|
195
225
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
196
226
|
if (keyStoreProvided) {
|
|
197
227
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
198
228
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
199
229
|
} else {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
230
|
+
const rawKeyStores: KeyStore[] = [];
|
|
231
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
232
|
+
if (validatorKeyStore) {
|
|
233
|
+
rawKeyStores.push(validatorKeyStore);
|
|
234
|
+
}
|
|
235
|
+
if (config.enableProverNode) {
|
|
236
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
237
|
+
if (proverKeyStore) {
|
|
238
|
+
rawKeyStores.push(proverKeyStore);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (rawKeyStores.length > 0) {
|
|
242
|
+
keyStoreManager = new KeystoreManager(
|
|
243
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
244
|
+
);
|
|
203
245
|
}
|
|
204
246
|
}
|
|
205
247
|
|
|
@@ -210,10 +252,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
210
252
|
if (keyStoreManager === undefined) {
|
|
211
253
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
212
254
|
}
|
|
213
|
-
if (!keyStoreProvided) {
|
|
214
|
-
log.warn(
|
|
215
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
216
|
-
);
|
|
255
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
256
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
217
257
|
}
|
|
218
258
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
219
259
|
}
|
|
@@ -227,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
227
267
|
|
|
228
268
|
const publicClient = createPublicClient({
|
|
229
269
|
chain: ethereumChain.chainInfo,
|
|
230
|
-
transport:
|
|
270
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
231
271
|
pollingInterval: config.viemPollingIntervalMS,
|
|
232
272
|
});
|
|
233
273
|
|
|
@@ -241,10 +281,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
241
281
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
242
282
|
|
|
243
283
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
244
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
284
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
245
285
|
rollupContract.getL1GenesisTime(),
|
|
246
286
|
rollupContract.getSlotDuration(),
|
|
247
287
|
rollupContract.getVersion(),
|
|
288
|
+
rollupContract.getManaLimit().then(Number),
|
|
248
289
|
] as const);
|
|
249
290
|
|
|
250
291
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -255,7 +296,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
255
296
|
);
|
|
256
297
|
}
|
|
257
298
|
|
|
258
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
299
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
259
300
|
|
|
260
301
|
// attempt snapshot sync if possible
|
|
261
302
|
await trySnapshotSync(config, log);
|
|
@@ -275,21 +316,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
275
316
|
options.prefilledPublicData,
|
|
276
317
|
telemetry,
|
|
277
318
|
);
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
319
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
320
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
321
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
322
|
+
if (useRealVerifiers) {
|
|
323
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
324
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
325
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
326
|
+
} else {
|
|
327
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
328
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let debugLogStore: DebugLogStore;
|
|
282
332
|
if (!config.realProofs) {
|
|
283
333
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
334
|
+
|
|
335
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
336
|
+
log.info(
|
|
337
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
338
|
+
);
|
|
339
|
+
} else {
|
|
340
|
+
debugLogStore = new NullDebugLogStore();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
344
|
+
if (proverOnly) {
|
|
345
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
284
346
|
}
|
|
285
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
286
347
|
|
|
287
348
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
288
349
|
const p2pClient = await createP2PClient(
|
|
289
|
-
P2PClientType.Full,
|
|
290
350
|
config,
|
|
291
351
|
archiver,
|
|
292
|
-
|
|
352
|
+
peerProofVerifier,
|
|
293
353
|
worldStateSynchronizer,
|
|
294
354
|
epochCache,
|
|
295
355
|
packageVersion,
|
|
@@ -298,59 +358,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
298
358
|
deps.p2pClientDeps,
|
|
299
359
|
);
|
|
300
360
|
|
|
301
|
-
// We
|
|
302
|
-
|
|
361
|
+
// We'll accumulate sentinel watchers here
|
|
362
|
+
const watchers: Watcher[] = [];
|
|
303
363
|
|
|
304
|
-
// Create FullNodeCheckpointsBuilder for
|
|
364
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
365
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
305
366
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
306
|
-
{
|
|
367
|
+
{
|
|
368
|
+
...config,
|
|
369
|
+
l1GenesisTime,
|
|
370
|
+
slotDuration: Number(slotDuration),
|
|
371
|
+
rollupManaLimit,
|
|
372
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
373
|
+
},
|
|
307
374
|
worldStateSynchronizer,
|
|
308
375
|
archiver,
|
|
309
376
|
dateProvider,
|
|
310
377
|
telemetry,
|
|
311
378
|
);
|
|
312
379
|
|
|
313
|
-
|
|
314
|
-
const watchers: Watcher[] = [];
|
|
380
|
+
let validatorClient: ValidatorClient | undefined;
|
|
315
381
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
382
|
+
if (!proverOnly) {
|
|
383
|
+
// Create validator client if required
|
|
384
|
+
validatorClient = await createValidatorClient(config, {
|
|
385
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
386
|
+
worldState: worldStateSynchronizer,
|
|
387
|
+
p2pClient,
|
|
388
|
+
telemetry,
|
|
389
|
+
dateProvider,
|
|
390
|
+
epochCache,
|
|
391
|
+
blockSource: archiver,
|
|
392
|
+
l1ToL2MessageSource: archiver,
|
|
393
|
+
keyStoreManager,
|
|
394
|
+
blobClient,
|
|
395
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
399
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
400
|
+
// like attestations or auths will fail.
|
|
401
|
+
if (validatorClient) {
|
|
402
|
+
watchers.push(validatorClient);
|
|
403
|
+
|
|
404
|
+
const vc = validatorClient;
|
|
405
|
+
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
406
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
329
407
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
if (validatorClient) {
|
|
334
|
-
watchers.push(validatorClient);
|
|
335
|
-
if (!options.dontStartSequencer) {
|
|
336
|
-
await validatorClient.registerHandlers();
|
|
408
|
+
if (!options.dontStartSequencer) {
|
|
409
|
+
await validatorClient.registerHandlers();
|
|
410
|
+
}
|
|
337
411
|
}
|
|
338
412
|
}
|
|
339
413
|
|
|
340
|
-
// If there's no validator client
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
414
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
415
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
416
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
417
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
418
|
+
if (!validatorClient) {
|
|
419
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
420
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
421
|
+
createProposalHandler(config, {
|
|
345
422
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
346
423
|
worldState: worldStateSynchronizer,
|
|
347
424
|
epochCache,
|
|
348
425
|
blockSource: archiver,
|
|
349
426
|
l1ToL2MessageSource: archiver,
|
|
350
427
|
p2pClient,
|
|
428
|
+
blobClient,
|
|
351
429
|
dateProvider,
|
|
352
430
|
telemetry,
|
|
353
|
-
}).
|
|
431
|
+
}).register(p2pClient, reexecute, archiver);
|
|
354
432
|
}
|
|
355
433
|
|
|
356
434
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -359,29 +437,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
359
437
|
// Start p2p. Note that it depends on world state to be running.
|
|
360
438
|
await p2pClient.start();
|
|
361
439
|
|
|
362
|
-
|
|
363
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
364
|
-
watchers.push(validatorsSentinel);
|
|
365
|
-
}
|
|
366
|
-
|
|
440
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
367
441
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
368
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
369
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
370
|
-
archiver,
|
|
371
|
-
archiver,
|
|
372
|
-
epochCache,
|
|
373
|
-
p2pClient.getTxProvider(),
|
|
374
|
-
validatorCheckpointsBuilder,
|
|
375
|
-
config,
|
|
376
|
-
);
|
|
377
|
-
watchers.push(epochPruneWatcher);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
381
442
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
443
|
+
|
|
444
|
+
if (!proverOnly) {
|
|
445
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
446
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
447
|
+
watchers.push(validatorsSentinel);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
451
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
452
|
+
archiver,
|
|
453
|
+
archiver,
|
|
454
|
+
epochCache,
|
|
455
|
+
p2pClient.getTxProvider(),
|
|
456
|
+
validatorCheckpointsBuilder,
|
|
457
|
+
config,
|
|
458
|
+
);
|
|
459
|
+
watchers.push(epochPruneWatcher);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
463
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
464
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
465
|
+
watchers.push(attestationsBlockWatcher);
|
|
466
|
+
}
|
|
385
467
|
}
|
|
386
468
|
|
|
387
469
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -396,6 +478,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
396
478
|
})
|
|
397
479
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
398
480
|
|
|
481
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
482
|
+
l1Contracts: config.l1Contracts,
|
|
483
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
484
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
485
|
+
l1GenesisTime,
|
|
486
|
+
slotDuration: Number(slotDuration),
|
|
487
|
+
});
|
|
488
|
+
|
|
399
489
|
// Validator enabled, create/start relevant service
|
|
400
490
|
let sequencer: SequencerClient | undefined;
|
|
401
491
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -418,34 +508,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
418
508
|
);
|
|
419
509
|
await slasherClient.start();
|
|
420
510
|
|
|
421
|
-
const l1TxUtils = config.
|
|
422
|
-
? await
|
|
511
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
512
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
423
513
|
publicClient,
|
|
424
514
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
425
|
-
config.
|
|
515
|
+
config.sequencerPublisherForwarderAddress,
|
|
426
516
|
{ ...config, scope: 'sequencer' },
|
|
427
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
517
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
428
518
|
)
|
|
429
|
-
: await
|
|
519
|
+
: await createL1TxUtilsFromSigners(
|
|
430
520
|
publicClient,
|
|
431
521
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
522
|
{ ...config, scope: 'sequencer' },
|
|
433
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
523
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
434
524
|
);
|
|
435
525
|
|
|
526
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
527
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
528
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
529
|
+
if (fundingSigner) {
|
|
530
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
531
|
+
publicClient,
|
|
532
|
+
[fundingSigner],
|
|
533
|
+
{ ...config, scope: 'sequencer' },
|
|
534
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
535
|
+
);
|
|
536
|
+
funderL1TxUtils = funder;
|
|
537
|
+
}
|
|
538
|
+
|
|
436
539
|
// Create and start the sequencer client
|
|
437
540
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
438
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
541
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
439
542
|
worldStateSynchronizer,
|
|
440
543
|
archiver,
|
|
441
544
|
dateProvider,
|
|
442
545
|
telemetry,
|
|
546
|
+
debugLogStore,
|
|
443
547
|
);
|
|
444
548
|
|
|
445
549
|
sequencer = await SequencerClient.new(config, {
|
|
446
550
|
...deps,
|
|
447
551
|
epochCache,
|
|
448
552
|
l1TxUtils,
|
|
553
|
+
funderL1TxUtils,
|
|
449
554
|
validatorClient,
|
|
450
555
|
p2pClient,
|
|
451
556
|
worldStateSynchronizer,
|
|
@@ -457,6 +562,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
457
562
|
dateProvider,
|
|
458
563
|
blobClient,
|
|
459
564
|
nodeKeyStore: keyStoreManager!,
|
|
565
|
+
globalVariableBuilder,
|
|
460
566
|
});
|
|
461
567
|
}
|
|
462
568
|
|
|
@@ -467,14 +573,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
467
573
|
log.warn(`Sequencer created but not started`);
|
|
468
574
|
}
|
|
469
575
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
576
|
+
// Create prover node subsystem if enabled
|
|
577
|
+
let proverNode: ProverNode | undefined;
|
|
578
|
+
if (config.enableProverNode) {
|
|
579
|
+
proverNode = await createProverNode(config, {
|
|
580
|
+
...deps.proverNodeDeps,
|
|
581
|
+
telemetry,
|
|
582
|
+
dateProvider,
|
|
583
|
+
archiver,
|
|
584
|
+
worldStateSynchronizer,
|
|
585
|
+
p2pClient,
|
|
586
|
+
epochCache,
|
|
587
|
+
blobClient,
|
|
588
|
+
keyStoreManager,
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
if (!options.dontStartProverNode) {
|
|
592
|
+
await proverNode.start();
|
|
593
|
+
log.info(`Prover node subsystem started`);
|
|
594
|
+
} else {
|
|
595
|
+
log.info(`Prover node subsystem created but not started`);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
476
598
|
|
|
477
|
-
|
|
599
|
+
const node = new AztecNodeService(
|
|
478
600
|
config,
|
|
479
601
|
p2pClient,
|
|
480
602
|
archiver,
|
|
@@ -483,6 +605,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
483
605
|
archiver,
|
|
484
606
|
worldStateSynchronizer,
|
|
485
607
|
sequencer,
|
|
608
|
+
proverNode,
|
|
486
609
|
slasherClient,
|
|
487
610
|
validatorsSentinel,
|
|
488
611
|
epochPruneWatcher,
|
|
@@ -491,11 +614,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
491
614
|
globalVariableBuilder,
|
|
492
615
|
epochCache,
|
|
493
616
|
packageVersion,
|
|
494
|
-
|
|
617
|
+
peerProofVerifier,
|
|
618
|
+
rpcProofVerifier,
|
|
495
619
|
telemetry,
|
|
496
620
|
log,
|
|
497
621
|
blobClient,
|
|
622
|
+
validatorClient,
|
|
623
|
+
keyStoreManager,
|
|
624
|
+
debugLogStore,
|
|
498
625
|
);
|
|
626
|
+
|
|
627
|
+
return node;
|
|
499
628
|
}
|
|
500
629
|
|
|
501
630
|
/**
|
|
@@ -506,6 +635,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
506
635
|
return this.sequencer;
|
|
507
636
|
}
|
|
508
637
|
|
|
638
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
639
|
+
public getProverNode(): ProverNode | undefined {
|
|
640
|
+
return this.proverNode;
|
|
641
|
+
}
|
|
642
|
+
|
|
509
643
|
public getBlockSource(): L2BlockSource {
|
|
510
644
|
return this.blockSource;
|
|
511
645
|
}
|
|
@@ -531,7 +665,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
531
665
|
}
|
|
532
666
|
|
|
533
667
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
534
|
-
return this.config.
|
|
668
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
535
669
|
}
|
|
536
670
|
|
|
537
671
|
/**
|
|
@@ -559,6 +693,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
559
693
|
enr,
|
|
560
694
|
l1ContractAddresses: contractAddresses,
|
|
561
695
|
protocolContractAddresses: protocolContractAddresses,
|
|
696
|
+
realProofs: !!this.config.realProofs,
|
|
562
697
|
};
|
|
563
698
|
|
|
564
699
|
return nodeInfo;
|
|
@@ -570,8 +705,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
570
705
|
* @returns The requested block.
|
|
571
706
|
*/
|
|
572
707
|
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
573
|
-
if (BlockHash.
|
|
574
|
-
return this.getBlockByHash(
|
|
708
|
+
if (BlockHash.isBlockHash(block)) {
|
|
709
|
+
return this.getBlockByHash(block);
|
|
575
710
|
}
|
|
576
711
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
577
712
|
if (blockNumber === BlockNumber.ZERO) {
|
|
@@ -585,9 +720,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
585
720
|
* @param blockHash - The block hash being requested.
|
|
586
721
|
* @returns The requested block.
|
|
587
722
|
*/
|
|
588
|
-
public async getBlockByHash(blockHash:
|
|
723
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
589
724
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
590
|
-
if (blockHash.equals(
|
|
725
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
591
726
|
return this.buildInitialBlock();
|
|
592
727
|
}
|
|
593
728
|
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
@@ -625,6 +760,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
625
760
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
626
761
|
}
|
|
627
762
|
|
|
763
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
764
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
765
|
+
}
|
|
766
|
+
|
|
628
767
|
/**
|
|
629
768
|
* Method to fetch the current min L2 fees.
|
|
630
769
|
* @returns The current min L2 fees.
|
|
@@ -657,6 +796,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
657
796
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
658
797
|
}
|
|
659
798
|
|
|
799
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
800
|
+
return this.blockSource.getCheckpointNumber();
|
|
801
|
+
}
|
|
802
|
+
|
|
660
803
|
/**
|
|
661
804
|
* Method to fetch the version of the package.
|
|
662
805
|
* @returns The node package version
|
|
@@ -694,19 +837,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
694
837
|
page?: number,
|
|
695
838
|
referenceBlock?: BlockHash,
|
|
696
839
|
): Promise<TxScopedL2Log[][]> {
|
|
840
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
697
841
|
if (referenceBlock) {
|
|
698
842
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
699
|
-
if (
|
|
700
|
-
|
|
701
|
-
|
|
843
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
844
|
+
upToBlockNumber = BlockNumber(0);
|
|
845
|
+
} else {
|
|
846
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
702
847
|
if (!header) {
|
|
703
848
|
throw new Error(
|
|
704
849
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
705
850
|
);
|
|
706
851
|
}
|
|
852
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
707
853
|
}
|
|
708
854
|
}
|
|
709
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
855
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
710
856
|
}
|
|
711
857
|
|
|
712
858
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -715,19 +861,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
715
861
|
page?: number,
|
|
716
862
|
referenceBlock?: BlockHash,
|
|
717
863
|
): Promise<TxScopedL2Log[][]> {
|
|
864
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
718
865
|
if (referenceBlock) {
|
|
719
866
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
720
|
-
if (
|
|
721
|
-
|
|
722
|
-
|
|
867
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
868
|
+
upToBlockNumber = BlockNumber(0);
|
|
869
|
+
} else {
|
|
870
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
723
871
|
if (!header) {
|
|
724
872
|
throw new Error(
|
|
725
873
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
726
874
|
);
|
|
727
875
|
}
|
|
876
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
728
877
|
}
|
|
729
878
|
}
|
|
730
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
879
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
731
880
|
}
|
|
732
881
|
|
|
733
882
|
/**
|
|
@@ -769,8 +918,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
769
918
|
}
|
|
770
919
|
|
|
771
920
|
await this.p2pClient!.sendTx(tx);
|
|
772
|
-
|
|
773
|
-
this.
|
|
921
|
+
const duration = timer.ms();
|
|
922
|
+
this.metrics.receivedTx(duration, true);
|
|
923
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
774
924
|
}
|
|
775
925
|
|
|
776
926
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
@@ -782,18 +932,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
782
932
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
783
933
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
784
934
|
|
|
935
|
+
let receipt: TxReceipt;
|
|
785
936
|
if (settledTxReceipt) {
|
|
786
|
-
|
|
787
|
-
return settledTxReceipt;
|
|
937
|
+
receipt = settledTxReceipt;
|
|
788
938
|
} else if (isKnownToPool) {
|
|
789
939
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
790
940
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
791
941
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
792
|
-
|
|
942
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
793
943
|
} else {
|
|
794
944
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
795
|
-
|
|
945
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
796
946
|
}
|
|
947
|
+
|
|
948
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
949
|
+
|
|
950
|
+
return receipt;
|
|
797
951
|
}
|
|
798
952
|
|
|
799
953
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -808,8 +962,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
808
962
|
await tryStop(this.validatorsSentinel);
|
|
809
963
|
await tryStop(this.epochPruneWatcher);
|
|
810
964
|
await tryStop(this.slasherClient);
|
|
811
|
-
await tryStop(this.
|
|
965
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
812
966
|
await tryStop(this.sequencer);
|
|
967
|
+
await tryStop(this.proverNode);
|
|
813
968
|
await tryStop(this.p2pClient);
|
|
814
969
|
await tryStop(this.worldStateSynchronizer);
|
|
815
970
|
await tryStop(this.blockSource);
|
|
@@ -859,100 +1014,98 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
859
1014
|
}
|
|
860
1015
|
|
|
861
1016
|
public async findLeavesIndexes(
|
|
862
|
-
|
|
1017
|
+
referenceBlock: BlockParameter,
|
|
863
1018
|
treeId: MerkleTreeId,
|
|
864
1019
|
leafValues: Fr[],
|
|
865
1020
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
866
|
-
const committedDb = await this
|
|
1021
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
867
1022
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
868
1023
|
treeId,
|
|
869
1024
|
leafValues.map(x => x.toBuffer()),
|
|
870
1025
|
);
|
|
871
|
-
//
|
|
872
|
-
const
|
|
1026
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1027
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
873
1028
|
|
|
874
|
-
// Now we find the block numbers for the indices
|
|
875
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1029
|
+
// Now we find the block numbers for the defined indices
|
|
1030
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
876
1031
|
|
|
877
|
-
//
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1032
|
+
// Build a map from leaf index to block number
|
|
1033
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1034
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1035
|
+
const blockNumber = blockNumbers[i];
|
|
1036
|
+
if (blockNumber === undefined) {
|
|
1037
|
+
throw new Error(
|
|
1038
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1039
|
+
);
|
|
881
1040
|
}
|
|
1041
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
882
1042
|
}
|
|
883
1043
|
|
|
884
1044
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
885
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1045
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
886
1046
|
|
|
887
|
-
// Now we obtain the block hashes from the archive tree
|
|
888
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1047
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
889
1048
|
const blockHashes = await Promise.all(
|
|
890
1049
|
uniqueBlockNumbers.map(blockNumber => {
|
|
891
1050
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
892
1051
|
}),
|
|
893
1052
|
);
|
|
894
1053
|
|
|
895
|
-
//
|
|
1054
|
+
// Build a map from block number to block hash
|
|
1055
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
896
1056
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
897
|
-
|
|
1057
|
+
const blockHash = blockHashes[i];
|
|
1058
|
+
if (blockHash === undefined) {
|
|
898
1059
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
899
1060
|
}
|
|
1061
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
900
1062
|
}
|
|
901
1063
|
|
|
902
1064
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
903
|
-
return maybeIndices.map(
|
|
1065
|
+
return maybeIndices.map(index => {
|
|
904
1066
|
if (index === undefined) {
|
|
905
1067
|
return undefined;
|
|
906
1068
|
}
|
|
907
|
-
const blockNumber =
|
|
1069
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
908
1070
|
if (blockNumber === undefined) {
|
|
909
|
-
|
|
1071
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
910
1072
|
}
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
return undefined;
|
|
1073
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1074
|
+
if (blockHash === undefined) {
|
|
1075
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
915
1076
|
}
|
|
916
1077
|
return {
|
|
917
|
-
l2BlockNumber:
|
|
918
|
-
l2BlockHash: BlockHash
|
|
1078
|
+
l2BlockNumber: blockNumber,
|
|
1079
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
919
1080
|
data: index,
|
|
920
1081
|
};
|
|
921
1082
|
});
|
|
922
1083
|
}
|
|
923
1084
|
|
|
924
|
-
public async
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
928
|
-
const committedDb = await this.#getWorldState(block);
|
|
929
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
public async getNoteHashSiblingPath(
|
|
933
|
-
block: BlockParameter,
|
|
934
|
-
leafIndex: bigint,
|
|
935
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
936
|
-
const committedDb = await this.#getWorldState(block);
|
|
937
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
public async getArchiveMembershipWitness(
|
|
941
|
-
block: BlockParameter,
|
|
942
|
-
archive: Fr,
|
|
1085
|
+
public async getBlockHashMembershipWitness(
|
|
1086
|
+
referenceBlock: BlockParameter,
|
|
1087
|
+
blockHash: BlockHash,
|
|
943
1088
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
944
|
-
|
|
945
|
-
|
|
1089
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1090
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1091
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1092
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1093
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1094
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1095
|
+
return undefined;
|
|
1096
|
+
}
|
|
1097
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1098
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
946
1099
|
return pathAndIndex === undefined
|
|
947
1100
|
? undefined
|
|
948
1101
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
949
1102
|
}
|
|
950
1103
|
|
|
951
1104
|
public async getNoteHashMembershipWitness(
|
|
952
|
-
|
|
1105
|
+
referenceBlock: BlockParameter,
|
|
953
1106
|
noteHash: Fr,
|
|
954
1107
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
955
|
-
const committedDb = await this
|
|
1108
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
956
1109
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
957
1110
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
958
1111
|
[noteHash],
|
|
@@ -963,10 +1116,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
963
1116
|
}
|
|
964
1117
|
|
|
965
1118
|
public async getL1ToL2MessageMembershipWitness(
|
|
966
|
-
|
|
1119
|
+
referenceBlock: BlockParameter,
|
|
967
1120
|
l1ToL2Message: Fr,
|
|
968
1121
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
969
|
-
const db = await this
|
|
1122
|
+
const db = await this.getWorldState(referenceBlock);
|
|
970
1123
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
971
1124
|
if (!witness) {
|
|
972
1125
|
return undefined;
|
|
@@ -976,11 +1129,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
976
1129
|
return [witness.index, witness.path];
|
|
977
1130
|
}
|
|
978
1131
|
|
|
979
|
-
public async
|
|
1132
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
980
1133
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
981
|
-
return messageIndex
|
|
982
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
983
|
-
: undefined;
|
|
1134
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
984
1135
|
}
|
|
985
1136
|
|
|
986
1137
|
/**
|
|
@@ -1001,45 +1152,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1152
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1002
1153
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1003
1154
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1004
|
-
const blocksInCheckpoints
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1008
|
-
const block = checkpointedBlock.block;
|
|
1009
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1010
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1011
|
-
checkpointIndex++;
|
|
1012
|
-
blocksInCheckpoints.push([]);
|
|
1013
|
-
previousSlotNumber = slotNumber;
|
|
1014
|
-
}
|
|
1015
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1016
|
-
}
|
|
1155
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1156
|
+
group => group.map(cb => cb.block),
|
|
1157
|
+
);
|
|
1017
1158
|
return blocksInCheckpoints.map(blocks =>
|
|
1018
1159
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1019
1160
|
);
|
|
1020
1161
|
}
|
|
1021
1162
|
|
|
1022
|
-
public async getArchiveSiblingPath(
|
|
1023
|
-
block: BlockParameter,
|
|
1024
|
-
leafIndex: bigint,
|
|
1025
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1026
|
-
const committedDb = await this.#getWorldState(block);
|
|
1027
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
public async getPublicDataSiblingPath(
|
|
1031
|
-
block: BlockParameter,
|
|
1032
|
-
leafIndex: bigint,
|
|
1033
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1034
|
-
const committedDb = await this.#getWorldState(block);
|
|
1035
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
1163
|
public async getNullifierMembershipWitness(
|
|
1039
|
-
|
|
1164
|
+
referenceBlock: BlockParameter,
|
|
1040
1165
|
nullifier: Fr,
|
|
1041
1166
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1042
|
-
const db = await this
|
|
1167
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1043
1168
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1044
1169
|
if (!witness) {
|
|
1045
1170
|
return undefined;
|
|
@@ -1054,32 +1179,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1054
1179
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1055
1180
|
}
|
|
1056
1181
|
|
|
1057
|
-
/**
|
|
1058
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1059
|
-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1060
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1061
|
-
* @returns The low nullifier membership witness (if found).
|
|
1062
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1063
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1064
|
-
* we are trying to prove non-inclusion for.
|
|
1065
|
-
*
|
|
1066
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1067
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1068
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1069
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1070
|
-
*/
|
|
1071
1182
|
public async getLowNullifierMembershipWitness(
|
|
1072
|
-
|
|
1183
|
+
referenceBlock: BlockParameter,
|
|
1073
1184
|
nullifier: Fr,
|
|
1074
1185
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1075
|
-
const committedDb = await this
|
|
1186
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1076
1187
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1077
1188
|
if (!findResult) {
|
|
1078
1189
|
return undefined;
|
|
1079
1190
|
}
|
|
1080
1191
|
const { index, alreadyPresent } = findResult;
|
|
1081
1192
|
if (alreadyPresent) {
|
|
1082
|
-
|
|
1193
|
+
throw new Error(
|
|
1194
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1195
|
+
);
|
|
1083
1196
|
}
|
|
1084
1197
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1085
1198
|
|
|
@@ -1087,8 +1200,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1087
1200
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1088
1201
|
}
|
|
1089
1202
|
|
|
1090
|
-
async getPublicDataWitness(
|
|
1091
|
-
const committedDb = await this
|
|
1203
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1204
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1092
1205
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1093
1206
|
if (!lowLeafResult) {
|
|
1094
1207
|
return undefined;
|
|
@@ -1102,8 +1215,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1102
1215
|
}
|
|
1103
1216
|
}
|
|
1104
1217
|
|
|
1105
|
-
public async getPublicStorageAt(
|
|
1106
|
-
const committedDb = await this
|
|
1218
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1219
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1107
1220
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1108
1221
|
|
|
1109
1222
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1118,14 +1231,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1118
1231
|
}
|
|
1119
1232
|
|
|
1120
1233
|
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1121
|
-
if (BlockHash.
|
|
1234
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1122
1235
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1123
1236
|
if (block.equals(initialBlockHash)) {
|
|
1124
1237
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1125
1238
|
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1126
1239
|
}
|
|
1127
|
-
|
|
1128
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1240
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1129
1241
|
} else {
|
|
1130
1242
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1131
1243
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
@@ -1145,6 +1257,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1145
1257
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1146
1258
|
}
|
|
1147
1259
|
|
|
1260
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1261
|
+
return this.blockSource.getBlockData(number);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1265
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1148
1268
|
/**
|
|
1149
1269
|
* Simulates the public part of a transaction with the current state.
|
|
1150
1270
|
* @param tx - The transaction to simulate.
|
|
@@ -1168,7 +1288,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1288
|
}
|
|
1169
1289
|
|
|
1170
1290
|
const txHash = tx.getTxHash();
|
|
1171
|
-
const
|
|
1291
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1292
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1172
1293
|
|
|
1173
1294
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1174
1295
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1183,6 +1304,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1183
1304
|
this.contractDataSource,
|
|
1184
1305
|
new DateProvider(),
|
|
1185
1306
|
this.telemetry,
|
|
1307
|
+
this.log.getBindings(),
|
|
1186
1308
|
);
|
|
1187
1309
|
|
|
1188
1310
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1191,6 +1313,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1191
1313
|
blockNumber,
|
|
1192
1314
|
});
|
|
1193
1315
|
|
|
1316
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1317
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1194
1318
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1195
1319
|
try {
|
|
1196
1320
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1206,7 +1330,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1330
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1207
1331
|
|
|
1208
1332
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1209
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1333
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1210
1334
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1211
1335
|
if (failedTxs.length) {
|
|
1212
1336
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1220,6 +1344,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1220
1344
|
processedTx.txEffect,
|
|
1221
1345
|
returns,
|
|
1222
1346
|
processedTx.gasUsed,
|
|
1347
|
+
debugLogs,
|
|
1223
1348
|
);
|
|
1224
1349
|
} finally {
|
|
1225
1350
|
await merkleTreeFork.close();
|
|
@@ -1231,21 +1356,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1231
1356
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1232
1357
|
): Promise<TxValidationResult> {
|
|
1233
1358
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1234
|
-
const verifier = isSimulation ? undefined : this.
|
|
1359
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1235
1360
|
|
|
1236
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1361
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1237
1362
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1238
1363
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1364
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1365
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1366
|
+
db,
|
|
1367
|
+
this.contractDataSource,
|
|
1368
|
+
verifier,
|
|
1369
|
+
{
|
|
1370
|
+
timestamp: nextSlotTimestamp,
|
|
1371
|
+
blockNumber,
|
|
1372
|
+
l1ChainId: this.l1ChainId,
|
|
1373
|
+
rollupVersion: this.version,
|
|
1374
|
+
setupAllowList: [
|
|
1375
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1376
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1377
|
+
],
|
|
1378
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1379
|
+
skipFeeEnforcement,
|
|
1380
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1381
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1382
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1383
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1384
|
+
},
|
|
1385
|
+
this.log.getBindings(),
|
|
1386
|
+
);
|
|
1249
1387
|
|
|
1250
1388
|
return await validator.validateTx(tx);
|
|
1251
1389
|
}
|
|
@@ -1267,7 +1405,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1267
1405
|
archiver.updateConfig(config);
|
|
1268
1406
|
}
|
|
1269
1407
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1270
|
-
|
|
1408
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1409
|
+
if (newConfig.realProofs) {
|
|
1410
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1411
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1412
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1413
|
+
} else {
|
|
1414
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1415
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1416
|
+
}
|
|
1271
1417
|
}
|
|
1272
1418
|
|
|
1273
1419
|
this.config = newConfig;
|
|
@@ -1409,6 +1555,94 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1409
1555
|
}
|
|
1410
1556
|
}
|
|
1411
1557
|
|
|
1558
|
+
public async reloadKeystore(): Promise<void> {
|
|
1559
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1560
|
+
throw new BadRequestError(
|
|
1561
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1562
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
1565
|
+
if (!this.validatorClient) {
|
|
1566
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
this.log.info('Reloading keystore from disk');
|
|
1570
|
+
|
|
1571
|
+
// Re-read and validate keystore files
|
|
1572
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1573
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1574
|
+
await newManager.validateSigners();
|
|
1575
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1576
|
+
|
|
1577
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1578
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1579
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1580
|
+
// would silently fail on every proposer slot.
|
|
1581
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1582
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1583
|
+
const availablePublishers = new Set(
|
|
1584
|
+
oldAdapter
|
|
1585
|
+
.getAttesterAddresses()
|
|
1586
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1587
|
+
);
|
|
1588
|
+
|
|
1589
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1590
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1591
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1592
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1593
|
+
throw new BadRequestError(
|
|
1594
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1595
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1596
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1597
|
+
`use an existing publisher key or restart the node.`,
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
// Build adapters for old and new keystores to compute diff
|
|
1604
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1605
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1606
|
+
const oldAddresses = this.keyStoreManager
|
|
1607
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1608
|
+
: [];
|
|
1609
|
+
|
|
1610
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1611
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1612
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1613
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1614
|
+
|
|
1615
|
+
if (added.length > 0) {
|
|
1616
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1617
|
+
}
|
|
1618
|
+
if (removed.length > 0) {
|
|
1619
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1620
|
+
}
|
|
1621
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1622
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1626
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1627
|
+
|
|
1628
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1629
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1630
|
+
if (this.sequencer) {
|
|
1631
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1635
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1636
|
+
const slashValidatorsNever = unique(
|
|
1637
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1638
|
+
).map(EthAddress.fromString);
|
|
1639
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
this.keyStoreManager = newManager;
|
|
1643
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1412
1646
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1413
1647
|
if (!this.initialHeaderHashPromise) {
|
|
1414
1648
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1421,7 +1655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1421
1655
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1422
1656
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1423
1657
|
*/
|
|
1424
|
-
async
|
|
1658
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1425
1659
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1426
1660
|
try {
|
|
1427
1661
|
// Attempt to sync the world state if necessary
|
|
@@ -1435,36 +1669,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1435
1669
|
return this.worldStateSynchronizer.getCommitted();
|
|
1436
1670
|
}
|
|
1437
1671
|
|
|
1438
|
-
|
|
1672
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1673
|
+
let blockNumber: BlockNumber;
|
|
1674
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1439
1675
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1440
1676
|
if (block.equals(initialBlockHash)) {
|
|
1441
1677
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1442
1678
|
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1443
1679
|
}
|
|
1444
1680
|
|
|
1445
|
-
const
|
|
1446
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1681
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1447
1682
|
if (!header) {
|
|
1448
1683
|
throw new Error(
|
|
1449
1684
|
`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.`,
|
|
1450
1685
|
);
|
|
1451
1686
|
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1687
|
+
|
|
1688
|
+
blockNumber = header.getBlockNumber();
|
|
1689
|
+
} else {
|
|
1690
|
+
blockNumber = block as BlockNumber;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
// Check it's within world state sync range
|
|
1694
|
+
if (blockNumber > blockSyncedTo) {
|
|
1695
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1455
1696
|
}
|
|
1697
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1456
1698
|
|
|
1457
|
-
|
|
1458
|
-
{
|
|
1459
|
-
const blockNumber = block as BlockNumber;
|
|
1699
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1460
1700
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1701
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1702
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1703
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1704
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1705
|
+
throw new Error(
|
|
1706
|
+
`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.`,
|
|
1707
|
+
);
|
|
1463
1708
|
}
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
return snapshot;
|
|
1712
|
+
}
|
|
1464
1713
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1714
|
+
/** Resolves a block parameter to a block number. */
|
|
1715
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1716
|
+
if (block === 'latest') {
|
|
1717
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1718
|
+
}
|
|
1719
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1720
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1721
|
+
if (block.equals(initialBlockHash)) {
|
|
1722
|
+
return BlockNumber.ZERO;
|
|
1723
|
+
}
|
|
1724
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1725
|
+
if (!header) {
|
|
1726
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1727
|
+
}
|
|
1728
|
+
return header.getBlockNumber();
|
|
1467
1729
|
}
|
|
1730
|
+
return block as BlockNumber;
|
|
1468
1731
|
}
|
|
1469
1732
|
|
|
1470
1733
|
/**
|