@aztec/aztec-node 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
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 +54 -45
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +479 -235
- 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 +571 -295
- 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 {
|
|
@@ -42,11 +44,11 @@ import {
|
|
|
42
44
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
43
45
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
46
|
import {
|
|
47
|
+
type BlockData,
|
|
48
|
+
BlockHash,
|
|
45
49
|
type BlockParameter,
|
|
46
|
-
type CheckpointedL2Block,
|
|
47
50
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockNew,
|
|
51
|
+
L2Block,
|
|
50
52
|
type L2BlockSource,
|
|
51
53
|
} from '@aztec/stdlib/block';
|
|
52
54
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
@@ -76,9 +78,9 @@ import {
|
|
|
76
78
|
type WorldStateSynchronizer,
|
|
77
79
|
tryStop,
|
|
78
80
|
} from '@aztec/stdlib/interfaces/server';
|
|
79
|
-
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';
|
|
80
83
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
81
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
82
84
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
83
85
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
84
86
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -110,11 +112,11 @@ import {
|
|
|
110
112
|
ValidatorClient,
|
|
111
113
|
createBlockProposalHandler,
|
|
112
114
|
createValidatorClient,
|
|
113
|
-
createValidatorForAcceptingTxs,
|
|
114
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
115
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
116
118
|
|
|
117
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
118
120
|
|
|
119
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
120
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -126,7 +128,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
126
128
|
*/
|
|
127
129
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
128
130
|
private metrics: NodeMetrics;
|
|
129
|
-
private initialHeaderHashPromise: Promise<
|
|
131
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
130
132
|
|
|
131
133
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
134
|
private isUploadingSnapshot = false;
|
|
@@ -142,6 +144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
142
144
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
143
145
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
144
146
|
protected readonly sequencer: SequencerClient | undefined,
|
|
147
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
145
148
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
146
149
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
147
150
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -150,16 +153,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
150
153
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
151
154
|
protected readonly epochCache: EpochCacheInterface,
|
|
152
155
|
protected readonly packageVersion: string,
|
|
153
|
-
private
|
|
156
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
154
158
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
159
|
private log = createLogger('node'),
|
|
156
160
|
private blobClient?: BlobClientInterface,
|
|
161
|
+
private validatorClient?: ValidatorClient,
|
|
162
|
+
private keyStoreManager?: KeystoreManager,
|
|
163
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
157
164
|
) {
|
|
158
165
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
159
166
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
160
167
|
|
|
161
168
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
162
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;
|
|
163
182
|
}
|
|
164
183
|
|
|
165
184
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -183,11 +202,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
183
202
|
logger?: Logger;
|
|
184
203
|
publisher?: SequencerPublisher;
|
|
185
204
|
dateProvider?: DateProvider;
|
|
186
|
-
p2pClientDeps?: P2PClientDeps
|
|
205
|
+
p2pClientDeps?: P2PClientDeps;
|
|
206
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
207
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
187
208
|
} = {},
|
|
188
209
|
options: {
|
|
189
210
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
190
211
|
dontStartSequencer?: boolean;
|
|
212
|
+
dontStartProverNode?: boolean;
|
|
191
213
|
} = {},
|
|
192
214
|
): Promise<AztecNodeService> {
|
|
193
215
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -197,16 +219,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
197
219
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
198
220
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
199
221
|
|
|
200
|
-
// 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.
|
|
201
224
|
let keyStoreManager: KeystoreManager | undefined;
|
|
202
225
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
203
226
|
if (keyStoreProvided) {
|
|
204
227
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
205
228
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
206
229
|
} else {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
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
|
+
);
|
|
210
245
|
}
|
|
211
246
|
}
|
|
212
247
|
|
|
@@ -217,10 +252,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
217
252
|
if (keyStoreManager === undefined) {
|
|
218
253
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
219
254
|
}
|
|
220
|
-
if (!keyStoreProvided) {
|
|
221
|
-
log.warn(
|
|
222
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
223
|
-
);
|
|
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");
|
|
224
257
|
}
|
|
225
258
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
226
259
|
}
|
|
@@ -234,7 +267,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
234
267
|
|
|
235
268
|
const publicClient = createPublicClient({
|
|
236
269
|
chain: ethereumChain.chainInfo,
|
|
237
|
-
transport:
|
|
270
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
238
271
|
pollingInterval: config.viemPollingIntervalMS,
|
|
239
272
|
});
|
|
240
273
|
|
|
@@ -248,10 +281,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
248
281
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
249
282
|
|
|
250
283
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
251
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
284
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
252
285
|
rollupContract.getL1GenesisTime(),
|
|
253
286
|
rollupContract.getSlotDuration(),
|
|
254
287
|
rollupContract.getVersion(),
|
|
288
|
+
rollupContract.getManaLimit().then(Number),
|
|
255
289
|
] as const);
|
|
256
290
|
|
|
257
291
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -262,7 +296,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
262
296
|
);
|
|
263
297
|
}
|
|
264
298
|
|
|
265
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
299
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
266
300
|
|
|
267
301
|
// attempt snapshot sync if possible
|
|
268
302
|
await trySnapshotSync(config, log);
|
|
@@ -282,21 +316,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
282
316
|
options.prefilledPublicData,
|
|
283
317
|
telemetry,
|
|
284
318
|
);
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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;
|
|
289
332
|
if (!config.realProofs) {
|
|
290
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');
|
|
291
346
|
}
|
|
292
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
293
347
|
|
|
294
348
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
295
349
|
const p2pClient = await createP2PClient(
|
|
296
|
-
P2PClientType.Full,
|
|
297
350
|
config,
|
|
298
351
|
archiver,
|
|
299
|
-
|
|
352
|
+
peerProofVerifier,
|
|
300
353
|
worldStateSynchronizer,
|
|
301
354
|
epochCache,
|
|
302
355
|
packageVersion,
|
|
@@ -305,49 +358,60 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
305
358
|
deps.p2pClientDeps,
|
|
306
359
|
);
|
|
307
360
|
|
|
308
|
-
// We
|
|
309
|
-
|
|
361
|
+
// We'll accumulate sentinel watchers here
|
|
362
|
+
const watchers: Watcher[] = [];
|
|
310
363
|
|
|
311
|
-
// Create FullNodeCheckpointsBuilder for
|
|
364
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
365
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
312
366
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
313
|
-
{
|
|
367
|
+
{
|
|
368
|
+
...config,
|
|
369
|
+
l1GenesisTime,
|
|
370
|
+
slotDuration: Number(slotDuration),
|
|
371
|
+
rollupManaLimit,
|
|
372
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
373
|
+
},
|
|
314
374
|
worldStateSynchronizer,
|
|
315
375
|
archiver,
|
|
316
376
|
dateProvider,
|
|
317
377
|
telemetry,
|
|
318
378
|
);
|
|
319
379
|
|
|
320
|
-
|
|
321
|
-
const watchers: Watcher[] = [];
|
|
380
|
+
let validatorClient: ValidatorClient | undefined;
|
|
322
381
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
+
});
|
|
336
397
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
+
if (!options.dontStartSequencer) {
|
|
404
|
+
await validatorClient.registerHandlers();
|
|
405
|
+
}
|
|
344
406
|
}
|
|
345
407
|
}
|
|
346
408
|
|
|
347
|
-
// If there's no validator client
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
409
|
+
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
410
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
411
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
412
|
+
if (!validatorClient) {
|
|
413
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
414
|
+
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
351
415
|
createBlockProposalHandler(config, {
|
|
352
416
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
353
417
|
worldState: worldStateSynchronizer,
|
|
@@ -357,7 +421,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
357
421
|
p2pClient,
|
|
358
422
|
dateProvider,
|
|
359
423
|
telemetry,
|
|
360
|
-
}).
|
|
424
|
+
}).register(p2pClient, reexecute);
|
|
361
425
|
}
|
|
362
426
|
|
|
363
427
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -366,29 +430,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
366
430
|
// Start p2p. Note that it depends on world state to be running.
|
|
367
431
|
await p2pClient.start();
|
|
368
432
|
|
|
369
|
-
|
|
370
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
371
|
-
watchers.push(validatorsSentinel);
|
|
372
|
-
}
|
|
373
|
-
|
|
433
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
374
434
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
375
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
376
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
377
|
-
archiver,
|
|
378
|
-
archiver,
|
|
379
|
-
epochCache,
|
|
380
|
-
p2pClient.getTxProvider(),
|
|
381
|
-
validatorCheckpointsBuilder,
|
|
382
|
-
config,
|
|
383
|
-
);
|
|
384
|
-
watchers.push(epochPruneWatcher);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
388
435
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
436
|
+
|
|
437
|
+
if (!proverOnly) {
|
|
438
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
439
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
440
|
+
watchers.push(validatorsSentinel);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
444
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
445
|
+
archiver,
|
|
446
|
+
archiver,
|
|
447
|
+
epochCache,
|
|
448
|
+
p2pClient.getTxProvider(),
|
|
449
|
+
validatorCheckpointsBuilder,
|
|
450
|
+
config,
|
|
451
|
+
);
|
|
452
|
+
watchers.push(epochPruneWatcher);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
456
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
457
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
458
|
+
watchers.push(attestationsBlockWatcher);
|
|
459
|
+
}
|
|
392
460
|
}
|
|
393
461
|
|
|
394
462
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -403,6 +471,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
403
471
|
})
|
|
404
472
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
405
473
|
|
|
474
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
475
|
+
l1Contracts: config.l1Contracts,
|
|
476
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
477
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
478
|
+
l1GenesisTime,
|
|
479
|
+
slotDuration: Number(slotDuration),
|
|
480
|
+
});
|
|
481
|
+
|
|
406
482
|
// Validator enabled, create/start relevant service
|
|
407
483
|
let sequencer: SequencerClient | undefined;
|
|
408
484
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -425,34 +501,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
425
501
|
);
|
|
426
502
|
await slasherClient.start();
|
|
427
503
|
|
|
428
|
-
const l1TxUtils = config.
|
|
429
|
-
? await
|
|
504
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
505
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
430
506
|
publicClient,
|
|
431
507
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
-
config.
|
|
508
|
+
config.sequencerPublisherForwarderAddress,
|
|
433
509
|
{ ...config, scope: 'sequencer' },
|
|
434
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
510
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
435
511
|
)
|
|
436
|
-
: await
|
|
512
|
+
: await createL1TxUtilsFromSigners(
|
|
437
513
|
publicClient,
|
|
438
514
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
439
515
|
{ ...config, scope: 'sequencer' },
|
|
440
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
516
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
441
517
|
);
|
|
442
518
|
|
|
519
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
520
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
521
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
522
|
+
if (fundingSigner) {
|
|
523
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
524
|
+
publicClient,
|
|
525
|
+
[fundingSigner],
|
|
526
|
+
{ ...config, scope: 'sequencer' },
|
|
527
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
528
|
+
);
|
|
529
|
+
funderL1TxUtils = funder;
|
|
530
|
+
}
|
|
531
|
+
|
|
443
532
|
// Create and start the sequencer client
|
|
444
533
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
445
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
534
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
446
535
|
worldStateSynchronizer,
|
|
447
536
|
archiver,
|
|
448
537
|
dateProvider,
|
|
449
538
|
telemetry,
|
|
539
|
+
debugLogStore,
|
|
450
540
|
);
|
|
451
541
|
|
|
452
542
|
sequencer = await SequencerClient.new(config, {
|
|
453
543
|
...deps,
|
|
454
544
|
epochCache,
|
|
455
545
|
l1TxUtils,
|
|
546
|
+
funderL1TxUtils,
|
|
456
547
|
validatorClient,
|
|
457
548
|
p2pClient,
|
|
458
549
|
worldStateSynchronizer,
|
|
@@ -464,6 +555,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
464
555
|
dateProvider,
|
|
465
556
|
blobClient,
|
|
466
557
|
nodeKeyStore: keyStoreManager!,
|
|
558
|
+
globalVariableBuilder,
|
|
467
559
|
});
|
|
468
560
|
}
|
|
469
561
|
|
|
@@ -474,14 +566,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
474
566
|
log.warn(`Sequencer created but not started`);
|
|
475
567
|
}
|
|
476
568
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
569
|
+
// Create prover node subsystem if enabled
|
|
570
|
+
let proverNode: ProverNode | undefined;
|
|
571
|
+
if (config.enableProverNode) {
|
|
572
|
+
proverNode = await createProverNode(config, {
|
|
573
|
+
...deps.proverNodeDeps,
|
|
574
|
+
telemetry,
|
|
575
|
+
dateProvider,
|
|
576
|
+
archiver,
|
|
577
|
+
worldStateSynchronizer,
|
|
578
|
+
p2pClient,
|
|
579
|
+
epochCache,
|
|
580
|
+
blobClient,
|
|
581
|
+
keyStoreManager,
|
|
582
|
+
});
|
|
483
583
|
|
|
484
|
-
|
|
584
|
+
if (!options.dontStartProverNode) {
|
|
585
|
+
await proverNode.start();
|
|
586
|
+
log.info(`Prover node subsystem started`);
|
|
587
|
+
} else {
|
|
588
|
+
log.info(`Prover node subsystem created but not started`);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const node = new AztecNodeService(
|
|
485
593
|
config,
|
|
486
594
|
p2pClient,
|
|
487
595
|
archiver,
|
|
@@ -490,6 +598,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
490
598
|
archiver,
|
|
491
599
|
worldStateSynchronizer,
|
|
492
600
|
sequencer,
|
|
601
|
+
proverNode,
|
|
493
602
|
slasherClient,
|
|
494
603
|
validatorsSentinel,
|
|
495
604
|
epochPruneWatcher,
|
|
@@ -498,11 +607,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
498
607
|
globalVariableBuilder,
|
|
499
608
|
epochCache,
|
|
500
609
|
packageVersion,
|
|
501
|
-
|
|
610
|
+
peerProofVerifier,
|
|
611
|
+
rpcProofVerifier,
|
|
502
612
|
telemetry,
|
|
503
613
|
log,
|
|
504
614
|
blobClient,
|
|
615
|
+
validatorClient,
|
|
616
|
+
keyStoreManager,
|
|
617
|
+
debugLogStore,
|
|
505
618
|
);
|
|
619
|
+
|
|
620
|
+
return node;
|
|
506
621
|
}
|
|
507
622
|
|
|
508
623
|
/**
|
|
@@ -513,6 +628,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
513
628
|
return this.sequencer;
|
|
514
629
|
}
|
|
515
630
|
|
|
631
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
632
|
+
public getProverNode(): ProverNode | undefined {
|
|
633
|
+
return this.proverNode;
|
|
634
|
+
}
|
|
635
|
+
|
|
516
636
|
public getBlockSource(): L2BlockSource {
|
|
517
637
|
return this.blockSource;
|
|
518
638
|
}
|
|
@@ -538,7 +658,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
538
658
|
}
|
|
539
659
|
|
|
540
660
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
541
|
-
return this.config.
|
|
661
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
542
662
|
}
|
|
543
663
|
|
|
544
664
|
/**
|
|
@@ -566,6 +686,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
566
686
|
enr,
|
|
567
687
|
l1ContractAddresses: contractAddresses,
|
|
568
688
|
protocolContractAddresses: protocolContractAddresses,
|
|
689
|
+
realProofs: !!this.config.realProofs,
|
|
569
690
|
};
|
|
570
691
|
|
|
571
692
|
return nodeInfo;
|
|
@@ -576,15 +697,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
576
697
|
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
577
698
|
* @returns The requested block.
|
|
578
699
|
*/
|
|
579
|
-
public async getBlock(block: BlockParameter): Promise<
|
|
580
|
-
if (
|
|
581
|
-
return this.getBlockByHash(
|
|
700
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
701
|
+
if (BlockHash.isBlockHash(block)) {
|
|
702
|
+
return this.getBlockByHash(block);
|
|
582
703
|
}
|
|
583
704
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
584
705
|
if (blockNumber === BlockNumber.ZERO) {
|
|
585
706
|
return this.buildInitialBlock();
|
|
586
707
|
}
|
|
587
|
-
return await this.blockSource.
|
|
708
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
588
709
|
}
|
|
589
710
|
|
|
590
711
|
/**
|
|
@@ -592,17 +713,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
592
713
|
* @param blockHash - The block hash being requested.
|
|
593
714
|
* @returns The requested block.
|
|
594
715
|
*/
|
|
595
|
-
public async getBlockByHash(blockHash:
|
|
716
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
596
717
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
597
|
-
if (blockHash.equals(
|
|
718
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
598
719
|
return this.buildInitialBlock();
|
|
599
720
|
}
|
|
600
|
-
return await this.blockSource.
|
|
721
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
601
722
|
}
|
|
602
723
|
|
|
603
|
-
private buildInitialBlock():
|
|
724
|
+
private buildInitialBlock(): L2Block {
|
|
604
725
|
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
605
|
-
return
|
|
726
|
+
return L2Block.empty(initialHeader);
|
|
606
727
|
}
|
|
607
728
|
|
|
608
729
|
/**
|
|
@@ -610,8 +731,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
610
731
|
* @param archive - The archive root being requested.
|
|
611
732
|
* @returns The requested block.
|
|
612
733
|
*/
|
|
613
|
-
public async getBlockByArchive(archive: Fr): Promise<
|
|
614
|
-
return await this.blockSource.
|
|
734
|
+
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
735
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
615
736
|
}
|
|
616
737
|
|
|
617
738
|
/**
|
|
@@ -620,24 +741,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
620
741
|
* @param limit - The maximum number of blocks to obtain.
|
|
621
742
|
* @returns The blocks requested.
|
|
622
743
|
*/
|
|
623
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<
|
|
624
|
-
return (await this.blockSource.
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
628
|
-
return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
|
|
744
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
745
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
629
746
|
}
|
|
630
747
|
|
|
631
|
-
public async
|
|
632
|
-
return (await this.blockSource.
|
|
748
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
749
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
633
750
|
}
|
|
634
751
|
|
|
635
|
-
public async
|
|
636
|
-
return (await this.blockSource.
|
|
752
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
753
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
637
754
|
}
|
|
638
755
|
|
|
639
|
-
public
|
|
640
|
-
return
|
|
756
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
757
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
641
758
|
}
|
|
642
759
|
|
|
643
760
|
/**
|
|
@@ -668,6 +785,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
668
785
|
return await this.blockSource.getProvenBlockNumber();
|
|
669
786
|
}
|
|
670
787
|
|
|
788
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
789
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
793
|
+
return this.blockSource.getCheckpointNumber();
|
|
794
|
+
}
|
|
795
|
+
|
|
671
796
|
/**
|
|
672
797
|
* Method to fetch the version of the package.
|
|
673
798
|
* @returns The node package version
|
|
@@ -700,16 +825,51 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
700
825
|
return this.contractDataSource.getContract(address);
|
|
701
826
|
}
|
|
702
827
|
|
|
703
|
-
public getPrivateLogsByTags(
|
|
704
|
-
|
|
828
|
+
public async getPrivateLogsByTags(
|
|
829
|
+
tags: SiloedTag[],
|
|
830
|
+
page?: number,
|
|
831
|
+
referenceBlock?: BlockHash,
|
|
832
|
+
): Promise<TxScopedL2Log[][]> {
|
|
833
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
834
|
+
if (referenceBlock) {
|
|
835
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
836
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
837
|
+
upToBlockNumber = BlockNumber(0);
|
|
838
|
+
} else {
|
|
839
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
840
|
+
if (!header) {
|
|
841
|
+
throw new Error(
|
|
842
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
705
849
|
}
|
|
706
850
|
|
|
707
|
-
public getPublicLogsByTagsFromContract(
|
|
851
|
+
public async getPublicLogsByTagsFromContract(
|
|
708
852
|
contractAddress: AztecAddress,
|
|
709
853
|
tags: Tag[],
|
|
710
854
|
page?: number,
|
|
855
|
+
referenceBlock?: BlockHash,
|
|
711
856
|
): Promise<TxScopedL2Log[][]> {
|
|
712
|
-
|
|
857
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
858
|
+
if (referenceBlock) {
|
|
859
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
860
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
861
|
+
upToBlockNumber = BlockNumber(0);
|
|
862
|
+
} else {
|
|
863
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
864
|
+
if (!header) {
|
|
865
|
+
throw new Error(
|
|
866
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
713
873
|
}
|
|
714
874
|
|
|
715
875
|
/**
|
|
@@ -751,26 +911,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
751
911
|
}
|
|
752
912
|
|
|
753
913
|
await this.p2pClient!.sendTx(tx);
|
|
754
|
-
|
|
755
|
-
this.
|
|
914
|
+
const duration = timer.ms();
|
|
915
|
+
this.metrics.receivedTx(duration, true);
|
|
916
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
756
917
|
}
|
|
757
918
|
|
|
758
919
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
764
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
765
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
766
|
-
}
|
|
920
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
921
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
922
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
923
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
767
924
|
|
|
925
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
768
926
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
927
|
+
|
|
928
|
+
let receipt: TxReceipt;
|
|
769
929
|
if (settledTxReceipt) {
|
|
770
|
-
|
|
930
|
+
receipt = settledTxReceipt;
|
|
931
|
+
} else if (isKnownToPool) {
|
|
932
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
933
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
934
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
935
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
936
|
+
} else {
|
|
937
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
938
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
771
939
|
}
|
|
772
940
|
|
|
773
|
-
|
|
941
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
942
|
+
|
|
943
|
+
return receipt;
|
|
774
944
|
}
|
|
775
945
|
|
|
776
946
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -785,8 +955,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
785
955
|
await tryStop(this.validatorsSentinel);
|
|
786
956
|
await tryStop(this.epochPruneWatcher);
|
|
787
957
|
await tryStop(this.slasherClient);
|
|
788
|
-
await tryStop(this.
|
|
958
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
789
959
|
await tryStop(this.sequencer);
|
|
960
|
+
await tryStop(this.proverNode);
|
|
790
961
|
await tryStop(this.p2pClient);
|
|
791
962
|
await tryStop(this.worldStateSynchronizer);
|
|
792
963
|
await tryStop(this.blockSource);
|
|
@@ -836,100 +1007,98 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
836
1007
|
}
|
|
837
1008
|
|
|
838
1009
|
public async findLeavesIndexes(
|
|
839
|
-
|
|
1010
|
+
referenceBlock: BlockParameter,
|
|
840
1011
|
treeId: MerkleTreeId,
|
|
841
1012
|
leafValues: Fr[],
|
|
842
1013
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
843
|
-
const committedDb = await this
|
|
1014
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
844
1015
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
845
1016
|
treeId,
|
|
846
1017
|
leafValues.map(x => x.toBuffer()),
|
|
847
1018
|
);
|
|
848
|
-
//
|
|
849
|
-
const
|
|
1019
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1020
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
850
1021
|
|
|
851
|
-
// Now we find the block numbers for the indices
|
|
852
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1022
|
+
// Now we find the block numbers for the defined indices
|
|
1023
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
853
1024
|
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1025
|
+
// Build a map from leaf index to block number
|
|
1026
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1027
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1028
|
+
const blockNumber = blockNumbers[i];
|
|
1029
|
+
if (blockNumber === undefined) {
|
|
1030
|
+
throw new Error(
|
|
1031
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1032
|
+
);
|
|
858
1033
|
}
|
|
1034
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
859
1035
|
}
|
|
860
1036
|
|
|
861
1037
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
862
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1038
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
863
1039
|
|
|
864
|
-
// Now we obtain the block hashes from the archive tree
|
|
865
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1040
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
866
1041
|
const blockHashes = await Promise.all(
|
|
867
1042
|
uniqueBlockNumbers.map(blockNumber => {
|
|
868
1043
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
869
1044
|
}),
|
|
870
1045
|
);
|
|
871
1046
|
|
|
872
|
-
//
|
|
1047
|
+
// Build a map from block number to block hash
|
|
1048
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
873
1049
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
874
|
-
|
|
1050
|
+
const blockHash = blockHashes[i];
|
|
1051
|
+
if (blockHash === undefined) {
|
|
875
1052
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
876
1053
|
}
|
|
1054
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
877
1055
|
}
|
|
878
1056
|
|
|
879
1057
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
880
|
-
return maybeIndices.map(
|
|
1058
|
+
return maybeIndices.map(index => {
|
|
881
1059
|
if (index === undefined) {
|
|
882
1060
|
return undefined;
|
|
883
1061
|
}
|
|
884
|
-
const blockNumber =
|
|
1062
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
885
1063
|
if (blockNumber === undefined) {
|
|
886
|
-
|
|
1064
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
887
1065
|
}
|
|
888
|
-
const
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
return undefined;
|
|
1066
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1067
|
+
if (blockHash === undefined) {
|
|
1068
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
892
1069
|
}
|
|
893
1070
|
return {
|
|
894
|
-
l2BlockNumber:
|
|
895
|
-
l2BlockHash:
|
|
1071
|
+
l2BlockNumber: blockNumber,
|
|
1072
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
896
1073
|
data: index,
|
|
897
1074
|
};
|
|
898
1075
|
});
|
|
899
1076
|
}
|
|
900
1077
|
|
|
901
|
-
public async
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
905
|
-
const committedDb = await this.#getWorldState(block);
|
|
906
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
public async getNoteHashSiblingPath(
|
|
910
|
-
block: BlockParameter,
|
|
911
|
-
leafIndex: bigint,
|
|
912
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
913
|
-
const committedDb = await this.#getWorldState(block);
|
|
914
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
public async getArchiveMembershipWitness(
|
|
918
|
-
block: BlockParameter,
|
|
919
|
-
archive: Fr,
|
|
1078
|
+
public async getBlockHashMembershipWitness(
|
|
1079
|
+
referenceBlock: BlockParameter,
|
|
1080
|
+
blockHash: BlockHash,
|
|
920
1081
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
921
|
-
|
|
922
|
-
|
|
1082
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1083
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1084
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1085
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1086
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1087
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1088
|
+
return undefined;
|
|
1089
|
+
}
|
|
1090
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1091
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
923
1092
|
return pathAndIndex === undefined
|
|
924
1093
|
? undefined
|
|
925
1094
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
926
1095
|
}
|
|
927
1096
|
|
|
928
1097
|
public async getNoteHashMembershipWitness(
|
|
929
|
-
|
|
1098
|
+
referenceBlock: BlockParameter,
|
|
930
1099
|
noteHash: Fr,
|
|
931
1100
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this
|
|
1101
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
933
1102
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
934
1103
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
935
1104
|
[noteHash],
|
|
@@ -940,10 +1109,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
940
1109
|
}
|
|
941
1110
|
|
|
942
1111
|
public async getL1ToL2MessageMembershipWitness(
|
|
943
|
-
|
|
1112
|
+
referenceBlock: BlockParameter,
|
|
944
1113
|
l1ToL2Message: Fr,
|
|
945
1114
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
946
|
-
const db = await this
|
|
1115
|
+
const db = await this.getWorldState(referenceBlock);
|
|
947
1116
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
948
1117
|
if (!witness) {
|
|
949
1118
|
return undefined;
|
|
@@ -953,11 +1122,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
953
1122
|
return [witness.index, witness.path];
|
|
954
1123
|
}
|
|
955
1124
|
|
|
956
|
-
public async
|
|
1125
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
957
1126
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
958
|
-
return messageIndex
|
|
959
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
960
|
-
: undefined;
|
|
1127
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
961
1128
|
}
|
|
962
1129
|
|
|
963
1130
|
/**
|
|
@@ -976,46 +1143,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
976
1143
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
977
1144
|
*/
|
|
978
1145
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
-
// Assumes `
|
|
980
|
-
const
|
|
981
|
-
const blocksInCheckpoints
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
for (const block of blocks) {
|
|
985
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
|
-
if (slotNumber !== previousSlotNumber) {
|
|
987
|
-
checkpointIndex++;
|
|
988
|
-
blocksInCheckpoints.push([]);
|
|
989
|
-
previousSlotNumber = slotNumber;
|
|
990
|
-
}
|
|
991
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
992
|
-
}
|
|
1146
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1147
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1148
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1149
|
+
group => group.map(cb => cb.block),
|
|
1150
|
+
);
|
|
993
1151
|
return blocksInCheckpoints.map(blocks =>
|
|
994
1152
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
995
1153
|
);
|
|
996
1154
|
}
|
|
997
1155
|
|
|
998
|
-
public async getArchiveSiblingPath(
|
|
999
|
-
block: BlockParameter,
|
|
1000
|
-
leafIndex: bigint,
|
|
1001
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1002
|
-
const committedDb = await this.#getWorldState(block);
|
|
1003
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
public async getPublicDataSiblingPath(
|
|
1007
|
-
block: BlockParameter,
|
|
1008
|
-
leafIndex: bigint,
|
|
1009
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1010
|
-
const committedDb = await this.#getWorldState(block);
|
|
1011
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
1156
|
public async getNullifierMembershipWitness(
|
|
1015
|
-
|
|
1157
|
+
referenceBlock: BlockParameter,
|
|
1016
1158
|
nullifier: Fr,
|
|
1017
1159
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1018
|
-
const db = await this
|
|
1160
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1019
1161
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1020
1162
|
if (!witness) {
|
|
1021
1163
|
return undefined;
|
|
@@ -1030,32 +1172,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1030
1172
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1031
1173
|
}
|
|
1032
1174
|
|
|
1033
|
-
/**
|
|
1034
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1035
|
-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1036
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1037
|
-
* @returns The low nullifier membership witness (if found).
|
|
1038
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1039
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1040
|
-
* we are trying to prove non-inclusion for.
|
|
1041
|
-
*
|
|
1042
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1043
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1044
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1045
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1046
|
-
*/
|
|
1047
1175
|
public async getLowNullifierMembershipWitness(
|
|
1048
|
-
|
|
1176
|
+
referenceBlock: BlockParameter,
|
|
1049
1177
|
nullifier: Fr,
|
|
1050
1178
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1051
|
-
const committedDb = await this
|
|
1179
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1052
1180
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1053
1181
|
if (!findResult) {
|
|
1054
1182
|
return undefined;
|
|
1055
1183
|
}
|
|
1056
1184
|
const { index, alreadyPresent } = findResult;
|
|
1057
1185
|
if (alreadyPresent) {
|
|
1058
|
-
|
|
1186
|
+
throw new Error(
|
|
1187
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1188
|
+
);
|
|
1059
1189
|
}
|
|
1060
1190
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1061
1191
|
|
|
@@ -1063,8 +1193,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1063
1193
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1064
1194
|
}
|
|
1065
1195
|
|
|
1066
|
-
async getPublicDataWitness(
|
|
1067
|
-
const committedDb = await this
|
|
1196
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1197
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1068
1198
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1069
1199
|
if (!lowLeafResult) {
|
|
1070
1200
|
return undefined;
|
|
@@ -1078,8 +1208,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1078
1208
|
}
|
|
1079
1209
|
}
|
|
1080
1210
|
|
|
1081
|
-
public async getPublicStorageAt(
|
|
1082
|
-
const committedDb = await this
|
|
1211
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1212
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1083
1213
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1084
1214
|
|
|
1085
1215
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1094,14 +1224,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1094
1224
|
}
|
|
1095
1225
|
|
|
1096
1226
|
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1097
|
-
if (
|
|
1227
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1098
1228
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1099
1229
|
if (block.equals(initialBlockHash)) {
|
|
1100
1230
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1101
1231
|
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1102
1232
|
}
|
|
1103
|
-
|
|
1104
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1233
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1105
1234
|
} else {
|
|
1106
1235
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1107
1236
|
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
@@ -1121,6 +1250,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1121
1250
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1122
1251
|
}
|
|
1123
1252
|
|
|
1253
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1254
|
+
return this.blockSource.getBlockData(number);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1258
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1124
1261
|
/**
|
|
1125
1262
|
* Simulates the public part of a transaction with the current state.
|
|
1126
1263
|
* @param tx - The transaction to simulate.
|
|
@@ -1144,7 +1281,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1144
1281
|
}
|
|
1145
1282
|
|
|
1146
1283
|
const txHash = tx.getTxHash();
|
|
1147
|
-
const
|
|
1284
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1285
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1148
1286
|
|
|
1149
1287
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1150
1288
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1159,6 +1297,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1159
1297
|
this.contractDataSource,
|
|
1160
1298
|
new DateProvider(),
|
|
1161
1299
|
this.telemetry,
|
|
1300
|
+
this.log.getBindings(),
|
|
1162
1301
|
);
|
|
1163
1302
|
|
|
1164
1303
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1167,6 +1306,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1167
1306
|
blockNumber,
|
|
1168
1307
|
});
|
|
1169
1308
|
|
|
1309
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1310
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1170
1311
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1171
1312
|
try {
|
|
1172
1313
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1182,7 +1323,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1182
1323
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1183
1324
|
|
|
1184
1325
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1185
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1326
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1186
1327
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1187
1328
|
if (failedTxs.length) {
|
|
1188
1329
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1196,6 +1337,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1196
1337
|
processedTx.txEffect,
|
|
1197
1338
|
returns,
|
|
1198
1339
|
processedTx.gasUsed,
|
|
1340
|
+
debugLogs,
|
|
1199
1341
|
);
|
|
1200
1342
|
} finally {
|
|
1201
1343
|
await merkleTreeFork.close();
|
|
@@ -1207,21 +1349,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1207
1349
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1208
1350
|
): Promise<TxValidationResult> {
|
|
1209
1351
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1210
|
-
const verifier = isSimulation ? undefined : this.
|
|
1352
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1211
1353
|
|
|
1212
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1354
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1213
1355
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1214
1356
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1357
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1358
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1359
|
+
db,
|
|
1360
|
+
this.contractDataSource,
|
|
1361
|
+
verifier,
|
|
1362
|
+
{
|
|
1363
|
+
timestamp: nextSlotTimestamp,
|
|
1364
|
+
blockNumber,
|
|
1365
|
+
l1ChainId: this.l1ChainId,
|
|
1366
|
+
rollupVersion: this.version,
|
|
1367
|
+
setupAllowList: [
|
|
1368
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1369
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1370
|
+
],
|
|
1371
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1372
|
+
skipFeeEnforcement,
|
|
1373
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1374
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1375
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1376
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1377
|
+
},
|
|
1378
|
+
this.log.getBindings(),
|
|
1379
|
+
);
|
|
1225
1380
|
|
|
1226
1381
|
return await validator.validateTx(tx);
|
|
1227
1382
|
}
|
|
@@ -1243,7 +1398,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1398
|
archiver.updateConfig(config);
|
|
1244
1399
|
}
|
|
1245
1400
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1246
|
-
|
|
1401
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1402
|
+
if (newConfig.realProofs) {
|
|
1403
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1404
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1405
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1406
|
+
} else {
|
|
1407
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1408
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1409
|
+
}
|
|
1247
1410
|
}
|
|
1248
1411
|
|
|
1249
1412
|
this.config = newConfig;
|
|
@@ -1385,13 +1548,97 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1385
1548
|
}
|
|
1386
1549
|
}
|
|
1387
1550
|
|
|
1388
|
-
|
|
1551
|
+
public async reloadKeystore(): Promise<void> {
|
|
1552
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1553
|
+
throw new BadRequestError(
|
|
1554
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1555
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1556
|
+
);
|
|
1557
|
+
}
|
|
1558
|
+
if (!this.validatorClient) {
|
|
1559
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
this.log.info('Reloading keystore from disk');
|
|
1563
|
+
|
|
1564
|
+
// Re-read and validate keystore files
|
|
1565
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1566
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1567
|
+
await newManager.validateSigners();
|
|
1568
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1569
|
+
|
|
1570
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1571
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1572
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1573
|
+
// would silently fail on every proposer slot.
|
|
1574
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1575
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1576
|
+
const availablePublishers = new Set(
|
|
1577
|
+
oldAdapter
|
|
1578
|
+
.getAttesterAddresses()
|
|
1579
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1580
|
+
);
|
|
1581
|
+
|
|
1582
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1583
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1584
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1585
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1586
|
+
throw new BadRequestError(
|
|
1587
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1588
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1589
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1590
|
+
`use an existing publisher key or restart the node.`,
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// Build adapters for old and new keystores to compute diff
|
|
1597
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1598
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1599
|
+
const oldAddresses = this.keyStoreManager
|
|
1600
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1601
|
+
: [];
|
|
1602
|
+
|
|
1603
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1604
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1605
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1606
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1607
|
+
|
|
1608
|
+
if (added.length > 0) {
|
|
1609
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1610
|
+
}
|
|
1611
|
+
if (removed.length > 0) {
|
|
1612
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1613
|
+
}
|
|
1614
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1615
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1619
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1620
|
+
|
|
1621
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1622
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1623
|
+
if (this.sequencer) {
|
|
1624
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1628
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1629
|
+
const slashValidatorsNever = unique(
|
|
1630
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1631
|
+
).map(EthAddress.fromString);
|
|
1632
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
this.keyStoreManager = newManager;
|
|
1636
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1389
1640
|
if (!this.initialHeaderHashPromise) {
|
|
1390
|
-
this.initialHeaderHashPromise = this.worldStateSynchronizer
|
|
1391
|
-
.getCommitted()
|
|
1392
|
-
.getInitialHeader()
|
|
1393
|
-
.hash()
|
|
1394
|
-
.then(hash => L2BlockHash.fromField(hash));
|
|
1641
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1395
1642
|
}
|
|
1396
1643
|
return this.initialHeaderHashPromise;
|
|
1397
1644
|
}
|
|
@@ -1401,7 +1648,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1401
1648
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1402
1649
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1403
1650
|
*/
|
|
1404
|
-
async
|
|
1651
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1405
1652
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1406
1653
|
try {
|
|
1407
1654
|
// Attempt to sync the world state if necessary
|
|
@@ -1415,36 +1662,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1415
1662
|
return this.worldStateSynchronizer.getCommitted();
|
|
1416
1663
|
}
|
|
1417
1664
|
|
|
1418
|
-
|
|
1665
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1666
|
+
let blockNumber: BlockNumber;
|
|
1667
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1419
1668
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1420
1669
|
if (block.equals(initialBlockHash)) {
|
|
1421
1670
|
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1422
1671
|
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1423
1672
|
}
|
|
1424
1673
|
|
|
1425
|
-
const
|
|
1426
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1674
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1427
1675
|
if (!header) {
|
|
1428
1676
|
throw new Error(
|
|
1429
1677
|
`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.`,
|
|
1430
1678
|
);
|
|
1431
1679
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1680
|
+
|
|
1681
|
+
blockNumber = header.getBlockNumber();
|
|
1682
|
+
} else {
|
|
1683
|
+
blockNumber = block as BlockNumber;
|
|
1435
1684
|
}
|
|
1436
1685
|
|
|
1437
|
-
//
|
|
1438
|
-
{
|
|
1439
|
-
|
|
1686
|
+
// Check it's within world state sync range
|
|
1687
|
+
if (blockNumber > blockSyncedTo) {
|
|
1688
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1689
|
+
}
|
|
1690
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1440
1691
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1692
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1693
|
+
|
|
1694
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1695
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1696
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1697
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`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.`,
|
|
1700
|
+
);
|
|
1443
1701
|
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
return snapshot;
|
|
1705
|
+
}
|
|
1444
1706
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1707
|
+
/** Resolves a block parameter to a block number. */
|
|
1708
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1709
|
+
if (block === 'latest') {
|
|
1710
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1711
|
+
}
|
|
1712
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1714
|
+
if (block.equals(initialBlockHash)) {
|
|
1715
|
+
return BlockNumber.ZERO;
|
|
1716
|
+
}
|
|
1717
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1718
|
+
if (!header) {
|
|
1719
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1720
|
+
}
|
|
1721
|
+
return header.getBlockNumber();
|
|
1447
1722
|
}
|
|
1723
|
+
return block as BlockNumber;
|
|
1448
1724
|
}
|
|
1449
1725
|
|
|
1450
1726
|
/**
|