@aztec/aztec-node 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
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 +11 -5
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +17 -3
- package/dest/aztec-node/node_metrics.d.ts +5 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +20 -6
- package/dest/aztec-node/server.d.ts +68 -124
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +789 -225
- package/dest/bin/index.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/sentinel/config.d.ts +1 -1
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/index.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts +22 -20
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +101 -63
- package/dest/sentinel/store.d.ts +6 -5
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +14 -9
- package/dest/test/index.d.ts +1 -1
- package/package.json +31 -28
- package/src/aztec-node/config.ts +34 -14
- package/src/aztec-node/node_metrics.ts +23 -6
- package/src/aztec-node/server.ts +512 -304
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +136 -82
- package/src/sentinel/store.ts +22 -21
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
3
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
+
import { Blob } from '@aztec/blob-lib';
|
|
5
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from '@aztec/
|
|
20
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
7
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
+
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
11
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
21
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
22
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
23
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
24
16
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
25
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
26
17
|
import { count } from '@aztec/foundation/string';
|
|
27
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
28
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
21
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
31
|
-
import {
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
32
23
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
24
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
SequencerClient,
|
|
38
|
-
type SequencerPublisher,
|
|
39
|
-
createValidatorForAcceptingTxs,
|
|
40
|
-
} from '@aztec/sequencer-client';
|
|
25
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
26
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
27
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
41
28
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
42
29
|
import {
|
|
43
30
|
AttestationsBlockWatcher,
|
|
@@ -46,15 +33,17 @@ import {
|
|
|
46
33
|
type Watcher,
|
|
47
34
|
createSlasher,
|
|
48
35
|
} from '@aztec/slasher';
|
|
36
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
49
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
50
38
|
import {
|
|
51
|
-
type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type
|
|
39
|
+
type BlockData,
|
|
40
|
+
BlockHash,
|
|
41
|
+
type BlockParameter,
|
|
42
|
+
type DataInBlock,
|
|
43
|
+
L2Block,
|
|
55
44
|
type L2BlockSource,
|
|
56
|
-
type PublishedL2Block,
|
|
57
45
|
} from '@aztec/stdlib/block';
|
|
46
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
58
47
|
import type {
|
|
59
48
|
ContractClassPublic,
|
|
60
49
|
ContractDataSource,
|
|
@@ -62,7 +51,7 @@ import type {
|
|
|
62
51
|
NodeInfo,
|
|
63
52
|
ProtocolContractAddresses,
|
|
64
53
|
} from '@aztec/stdlib/contract';
|
|
65
|
-
import
|
|
54
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
66
55
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
67
56
|
import {
|
|
68
57
|
type AztecNode,
|
|
@@ -73,6 +62,7 @@ import {
|
|
|
73
62
|
type GetPublicLogsResponse,
|
|
74
63
|
} from '@aztec/stdlib/interfaces/client';
|
|
75
64
|
import {
|
|
65
|
+
type AllowedElement,
|
|
76
66
|
type ClientProtocolCircuitVerifier,
|
|
77
67
|
type L2LogsSource,
|
|
78
68
|
type Service,
|
|
@@ -80,7 +70,7 @@ import {
|
|
|
80
70
|
type WorldStateSynchronizer,
|
|
81
71
|
tryStop,
|
|
82
72
|
} from '@aztec/stdlib/interfaces/server';
|
|
83
|
-
import type { LogFilter,
|
|
73
|
+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
84
74
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
85
75
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
86
76
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -108,10 +98,13 @@ import {
|
|
|
108
98
|
trackSpan,
|
|
109
99
|
} from '@aztec/telemetry-client';
|
|
110
100
|
import {
|
|
101
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
102
|
+
FullNodeCheckpointsBuilder,
|
|
111
103
|
NodeKeystoreAdapter,
|
|
112
104
|
ValidatorClient,
|
|
113
105
|
createBlockProposalHandler,
|
|
114
106
|
createValidatorClient,
|
|
107
|
+
createValidatorForAcceptingTxs,
|
|
115
108
|
} from '@aztec/validator-client';
|
|
116
109
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
117
110
|
|
|
@@ -127,13 +120,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
127
120
|
*/
|
|
128
121
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
129
122
|
private metrics: NodeMetrics;
|
|
123
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
130
124
|
|
|
131
125
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
126
|
private isUploadingSnapshot = false;
|
|
133
127
|
|
|
134
|
-
// Serial queue to ensure that we only send one tx at a time
|
|
135
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
136
|
-
|
|
137
128
|
public readonly tracer: Tracer;
|
|
138
129
|
|
|
139
130
|
constructor(
|
|
@@ -145,6 +136,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
145
136
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
146
137
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
147
138
|
protected readonly sequencer: SequencerClient | undefined,
|
|
139
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
148
140
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
149
141
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
150
142
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -156,10 +148,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
156
148
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
157
149
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
158
150
|
private log = createLogger('node'),
|
|
151
|
+
private blobClient?: BlobClientInterface,
|
|
152
|
+
private validatorClient?: ValidatorClient,
|
|
153
|
+
private keyStoreManager?: KeystoreManager,
|
|
159
154
|
) {
|
|
160
155
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
161
156
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
162
|
-
this.txQueue.start();
|
|
163
157
|
|
|
164
158
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
165
159
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
@@ -186,12 +180,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
186
180
|
logger?: Logger;
|
|
187
181
|
publisher?: SequencerPublisher;
|
|
188
182
|
dateProvider?: DateProvider;
|
|
189
|
-
blobSinkClient?: BlobSinkClientInterface;
|
|
190
183
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
184
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
191
185
|
} = {},
|
|
192
186
|
options: {
|
|
193
187
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
194
188
|
dontStartSequencer?: boolean;
|
|
189
|
+
dontStartProverNode?: boolean;
|
|
195
190
|
} = {},
|
|
196
191
|
): Promise<AztecNodeService> {
|
|
197
192
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -199,20 +194,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
199
194
|
const packageVersion = getPackageVersion() ?? '';
|
|
200
195
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
201
196
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
202
|
-
const blobSinkClient =
|
|
203
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
204
197
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
205
198
|
|
|
206
|
-
// Build a key store from file if given or from environment otherwise
|
|
199
|
+
// Build a key store from file if given or from environment otherwise.
|
|
200
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
207
201
|
let keyStoreManager: KeystoreManager | undefined;
|
|
208
202
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
209
203
|
if (keyStoreProvided) {
|
|
210
204
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
211
205
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
212
206
|
} else {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
207
|
+
const rawKeyStores: KeyStore[] = [];
|
|
208
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
209
|
+
if (validatorKeyStore) {
|
|
210
|
+
rawKeyStores.push(validatorKeyStore);
|
|
211
|
+
}
|
|
212
|
+
if (config.enableProverNode) {
|
|
213
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
214
|
+
if (proverKeyStore) {
|
|
215
|
+
rawKeyStores.push(proverKeyStore);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (rawKeyStores.length > 0) {
|
|
219
|
+
keyStoreManager = new KeystoreManager(
|
|
220
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
221
|
+
);
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
|
|
@@ -223,12 +229,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
223
229
|
if (keyStoreManager === undefined) {
|
|
224
230
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
225
231
|
}
|
|
226
|
-
if (!keyStoreProvided) {
|
|
227
|
-
log.warn(
|
|
228
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
229
|
-
);
|
|
232
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
233
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
230
234
|
}
|
|
231
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager);
|
|
235
|
+
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
// validate that the actual chain id matches that specified in configuration
|
|
@@ -240,7 +244,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
240
244
|
|
|
241
245
|
const publicClient = createPublicClient({
|
|
242
246
|
chain: ethereumChain.chainInfo,
|
|
243
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
247
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
244
248
|
pollingInterval: config.viemPollingIntervalMS,
|
|
245
249
|
});
|
|
246
250
|
|
|
@@ -268,6 +272,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
268
272
|
);
|
|
269
273
|
}
|
|
270
274
|
|
|
275
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
276
|
+
|
|
271
277
|
// attempt snapshot sync if possible
|
|
272
278
|
await trySnapshotSync(config, log);
|
|
273
279
|
|
|
@@ -275,7 +281,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
275
281
|
|
|
276
282
|
const archiver = await createArchiver(
|
|
277
283
|
config,
|
|
278
|
-
{
|
|
284
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
279
285
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
280
286
|
);
|
|
281
287
|
|
|
@@ -286,7 +292,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
286
292
|
options.prefilledPublicData,
|
|
287
293
|
telemetry,
|
|
288
294
|
);
|
|
289
|
-
const circuitVerifier =
|
|
295
|
+
const circuitVerifier =
|
|
296
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
297
|
+
? await BBCircuitVerifier.new(config)
|
|
298
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
290
299
|
if (!config.realProofs) {
|
|
291
300
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
292
301
|
}
|
|
@@ -306,12 +315,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
315
|
deps.p2pClientDeps,
|
|
307
316
|
);
|
|
308
317
|
|
|
309
|
-
//
|
|
310
|
-
await worldStateSynchronizer.start();
|
|
311
|
-
|
|
318
|
+
// We should really not be modifying the config object
|
|
312
319
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
313
320
|
|
|
314
|
-
|
|
321
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
322
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
315
323
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
316
324
|
worldStateSynchronizer,
|
|
317
325
|
archiver,
|
|
@@ -323,15 +331,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
323
331
|
const watchers: Watcher[] = [];
|
|
324
332
|
|
|
325
333
|
// Create validator client if required
|
|
326
|
-
const validatorClient = createValidatorClient(config, {
|
|
334
|
+
const validatorClient = await createValidatorClient(config, {
|
|
335
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
336
|
+
worldState: worldStateSynchronizer,
|
|
327
337
|
p2pClient,
|
|
328
338
|
telemetry,
|
|
329
339
|
dateProvider,
|
|
330
340
|
epochCache,
|
|
331
|
-
blockBuilder,
|
|
332
341
|
blockSource: archiver,
|
|
333
342
|
l1ToL2MessageSource: archiver,
|
|
334
343
|
keyStoreManager,
|
|
344
|
+
blobClient,
|
|
335
345
|
});
|
|
336
346
|
|
|
337
347
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -349,7 +359,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
349
359
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
350
360
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
351
361
|
createBlockProposalHandler(config, {
|
|
352
|
-
|
|
362
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
363
|
+
worldState: worldStateSynchronizer,
|
|
353
364
|
epochCache,
|
|
354
365
|
blockSource: archiver,
|
|
355
366
|
l1ToL2MessageSource: archiver,
|
|
@@ -377,7 +388,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
377
388
|
archiver,
|
|
378
389
|
epochCache,
|
|
379
390
|
p2pClient.getTxProvider(),
|
|
380
|
-
|
|
391
|
+
validatorCheckpointsBuilder,
|
|
381
392
|
config,
|
|
382
393
|
);
|
|
383
394
|
watchers.push(epochPruneWatcher);
|
|
@@ -402,13 +413,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
402
413
|
})
|
|
403
414
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
404
415
|
|
|
405
|
-
log.verbose(`All Aztec Node subsystems synced`);
|
|
406
|
-
|
|
407
416
|
// Validator enabled, create/start relevant service
|
|
408
417
|
let sequencer: SequencerClient | undefined;
|
|
409
418
|
let slasherClient: SlasherClientInterface | undefined;
|
|
410
|
-
|
|
411
|
-
if (!config.disableValidator) {
|
|
419
|
+
if (!config.disableValidator && validatorClient) {
|
|
412
420
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
413
421
|
// as they are executed when the node is selected as proposer.
|
|
414
422
|
const validatorAddresses = keyStoreManager
|
|
@@ -427,14 +435,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
427
435
|
);
|
|
428
436
|
await slasherClient.start();
|
|
429
437
|
|
|
430
|
-
const l1TxUtils =
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
438
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
439
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
440
|
+
publicClient,
|
|
441
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
442
|
+
config.sequencerPublisherForwarderAddress,
|
|
443
|
+
{ ...config, scope: 'sequencer' },
|
|
444
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
445
|
+
)
|
|
446
|
+
: await createL1TxUtilsFromSigners(
|
|
447
|
+
publicClient,
|
|
448
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
449
|
+
{ ...config, scope: 'sequencer' },
|
|
450
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
451
|
+
);
|
|
436
452
|
|
|
437
453
|
// Create and start the sequencer client
|
|
454
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
455
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
456
|
+
worldStateSynchronizer,
|
|
457
|
+
archiver,
|
|
458
|
+
dateProvider,
|
|
459
|
+
telemetry,
|
|
460
|
+
);
|
|
461
|
+
|
|
438
462
|
sequencer = await SequencerClient.new(config, {
|
|
439
463
|
...deps,
|
|
440
464
|
epochCache,
|
|
@@ -443,12 +467,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
443
467
|
p2pClient,
|
|
444
468
|
worldStateSynchronizer,
|
|
445
469
|
slasherClient,
|
|
446
|
-
|
|
470
|
+
checkpointsBuilder,
|
|
447
471
|
l2BlockSource: archiver,
|
|
448
472
|
l1ToL2MessageSource: archiver,
|
|
449
473
|
telemetry,
|
|
450
474
|
dateProvider,
|
|
451
|
-
|
|
475
|
+
blobClient,
|
|
452
476
|
nodeKeyStore: keyStoreManager!,
|
|
453
477
|
});
|
|
454
478
|
}
|
|
@@ -460,7 +484,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
460
484
|
log.warn(`Sequencer created but not started`);
|
|
461
485
|
}
|
|
462
486
|
|
|
463
|
-
|
|
487
|
+
// Create prover node subsystem if enabled
|
|
488
|
+
let proverNode: ProverNode | undefined;
|
|
489
|
+
if (config.enableProverNode) {
|
|
490
|
+
proverNode = await createProverNode(config, {
|
|
491
|
+
...deps.proverNodeDeps,
|
|
492
|
+
telemetry,
|
|
493
|
+
dateProvider,
|
|
494
|
+
archiver,
|
|
495
|
+
worldStateSynchronizer,
|
|
496
|
+
p2pClient,
|
|
497
|
+
epochCache,
|
|
498
|
+
blobClient,
|
|
499
|
+
keyStoreManager,
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
if (!options.dontStartProverNode) {
|
|
503
|
+
await proverNode.start();
|
|
504
|
+
log.info(`Prover node subsystem started`);
|
|
505
|
+
} else {
|
|
506
|
+
log.info(`Prover node subsystem created but not started`);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
511
|
+
...config,
|
|
512
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
513
|
+
l1GenesisTime,
|
|
514
|
+
slotDuration: Number(slotDuration),
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const node = new AztecNodeService(
|
|
464
518
|
config,
|
|
465
519
|
p2pClient,
|
|
466
520
|
archiver,
|
|
@@ -469,18 +523,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
469
523
|
archiver,
|
|
470
524
|
worldStateSynchronizer,
|
|
471
525
|
sequencer,
|
|
526
|
+
proverNode,
|
|
472
527
|
slasherClient,
|
|
473
528
|
validatorsSentinel,
|
|
474
529
|
epochPruneWatcher,
|
|
475
530
|
ethereumChain.chainInfo.id,
|
|
476
531
|
config.rollupVersion,
|
|
477
|
-
|
|
532
|
+
globalVariableBuilder,
|
|
478
533
|
epochCache,
|
|
479
534
|
packageVersion,
|
|
480
535
|
proofVerifier,
|
|
481
536
|
telemetry,
|
|
482
537
|
log,
|
|
538
|
+
blobClient,
|
|
539
|
+
validatorClient,
|
|
540
|
+
keyStoreManager,
|
|
483
541
|
);
|
|
542
|
+
|
|
543
|
+
return node;
|
|
484
544
|
}
|
|
485
545
|
|
|
486
546
|
/**
|
|
@@ -491,6 +551,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
491
551
|
return this.sequencer;
|
|
492
552
|
}
|
|
493
553
|
|
|
554
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
555
|
+
public getProverNode(): ProverNode | undefined {
|
|
556
|
+
return this.proverNode;
|
|
557
|
+
}
|
|
558
|
+
|
|
494
559
|
public getBlockSource(): L2BlockSource {
|
|
495
560
|
return this.blockSource;
|
|
496
561
|
}
|
|
@@ -515,6 +580,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
515
580
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
516
581
|
}
|
|
517
582
|
|
|
583
|
+
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
584
|
+
return this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
585
|
+
}
|
|
586
|
+
|
|
518
587
|
/**
|
|
519
588
|
* Method to determine if the node is ready to accept transactions.
|
|
520
589
|
* @returns - Flag indicating the readiness for tx submission.
|
|
@@ -540,19 +609,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
609
|
enr,
|
|
541
610
|
l1ContractAddresses: contractAddresses,
|
|
542
611
|
protocolContractAddresses: protocolContractAddresses,
|
|
612
|
+
realProofs: !!this.config.realProofs,
|
|
543
613
|
};
|
|
544
614
|
|
|
545
615
|
return nodeInfo;
|
|
546
616
|
}
|
|
547
617
|
|
|
548
618
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
619
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
620
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
621
|
* @returns The requested block.
|
|
552
622
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
623
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
624
|
+
if (BlockHash.isBlockHash(block)) {
|
|
625
|
+
return this.getBlockByHash(block);
|
|
626
|
+
}
|
|
627
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
628
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
629
|
+
return this.buildInitialBlock();
|
|
630
|
+
}
|
|
631
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
556
632
|
}
|
|
557
633
|
|
|
558
634
|
/**
|
|
@@ -560,9 +636,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
636
|
* @param blockHash - The block hash being requested.
|
|
561
637
|
* @returns The requested block.
|
|
562
638
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash:
|
|
564
|
-
const
|
|
565
|
-
|
|
639
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
640
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
641
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
642
|
+
return this.buildInitialBlock();
|
|
643
|
+
}
|
|
644
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
private buildInitialBlock(): L2Block {
|
|
648
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
649
|
+
return L2Block.empty(initialHeader);
|
|
566
650
|
}
|
|
567
651
|
|
|
568
652
|
/**
|
|
@@ -571,8 +655,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
571
655
|
* @returns The requested block.
|
|
572
656
|
*/
|
|
573
657
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
658
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
576
659
|
}
|
|
577
660
|
|
|
578
661
|
/**
|
|
@@ -581,34 +664,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
664
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
665
|
* @returns The blocks requested.
|
|
583
666
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
667
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
668
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
586
669
|
}
|
|
587
670
|
|
|
588
|
-
public async
|
|
589
|
-
return (await this.blockSource.
|
|
671
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
672
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
676
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
590
677
|
}
|
|
591
678
|
|
|
592
679
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
680
|
+
* Method to fetch the current min L2 fees.
|
|
681
|
+
* @returns The current min L2 fees.
|
|
595
682
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
683
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
684
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
688
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
689
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
693
|
}
|
|
599
694
|
|
|
600
695
|
/**
|
|
601
696
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
697
|
* @returns The block number.
|
|
603
698
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
699
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
700
|
return await this.blockSource.getBlockNumber();
|
|
606
701
|
}
|
|
607
702
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
703
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
704
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
705
|
}
|
|
611
706
|
|
|
707
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
708
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
709
|
+
}
|
|
710
|
+
|
|
612
711
|
/**
|
|
613
712
|
* Method to fetch the version of the package.
|
|
614
713
|
* @returns The node package version
|
|
@@ -641,25 +740,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
740
|
return this.contractDataSource.getContract(address);
|
|
642
741
|
}
|
|
643
742
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
743
|
+
public async getPrivateLogsByTags(
|
|
744
|
+
tags: SiloedTag[],
|
|
745
|
+
page?: number,
|
|
746
|
+
referenceBlock?: BlockHash,
|
|
747
|
+
): Promise<TxScopedL2Log[][]> {
|
|
748
|
+
if (referenceBlock) {
|
|
749
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
750
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
751
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
752
|
+
if (!header) {
|
|
753
|
+
throw new Error(
|
|
754
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
public async getPublicLogsByTagsFromContract(
|
|
763
|
+
contractAddress: AztecAddress,
|
|
764
|
+
tags: Tag[],
|
|
765
|
+
page?: number,
|
|
766
|
+
referenceBlock?: BlockHash,
|
|
767
|
+
): Promise<TxScopedL2Log[][]> {
|
|
768
|
+
if (referenceBlock) {
|
|
769
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
770
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
771
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
772
|
+
if (!header) {
|
|
773
|
+
throw new Error(
|
|
774
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
663
780
|
}
|
|
664
781
|
|
|
665
782
|
/**
|
|
@@ -685,7 +802,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
802
|
* @param tx - The transaction to be submitted.
|
|
686
803
|
*/
|
|
687
804
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
805
|
+
await this.#sendTx(tx);
|
|
689
806
|
}
|
|
690
807
|
|
|
691
808
|
async #sendTx(tx: Tx) {
|
|
@@ -706,21 +823,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
706
823
|
}
|
|
707
824
|
|
|
708
825
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
714
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
715
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
716
|
-
}
|
|
826
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
827
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
828
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
829
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
830
|
|
|
831
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
832
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
833
|
+
|
|
719
834
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
835
|
+
// If the archiver has the receipt then return it.
|
|
836
|
+
return settledTxReceipt;
|
|
837
|
+
} else if (isKnownToPool) {
|
|
838
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
839
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
840
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
841
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
842
|
+
} else {
|
|
843
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
844
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
721
845
|
}
|
|
722
|
-
|
|
723
|
-
return txReceipt;
|
|
724
846
|
}
|
|
725
847
|
|
|
726
848
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,19 +854,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
854
|
*/
|
|
733
855
|
public async stop() {
|
|
734
856
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
857
|
await tryStop(this.validatorsSentinel);
|
|
737
858
|
await tryStop(this.epochPruneWatcher);
|
|
738
859
|
await tryStop(this.slasherClient);
|
|
739
860
|
await tryStop(this.proofVerifier);
|
|
740
861
|
await tryStop(this.sequencer);
|
|
862
|
+
await tryStop(this.proverNode);
|
|
741
863
|
await tryStop(this.p2pClient);
|
|
742
864
|
await tryStop(this.worldStateSynchronizer);
|
|
743
865
|
await tryStop(this.blockSource);
|
|
866
|
+
await tryStop(this.blobClient);
|
|
744
867
|
await tryStop(this.telemetry);
|
|
745
868
|
this.log.info(`Stopped Aztec Node`);
|
|
746
869
|
}
|
|
747
870
|
|
|
871
|
+
/**
|
|
872
|
+
* Returns the blob client used by this node.
|
|
873
|
+
* @internal - Exposed for testing purposes only.
|
|
874
|
+
*/
|
|
875
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
876
|
+
return this.blobClient;
|
|
877
|
+
}
|
|
878
|
+
|
|
748
879
|
/**
|
|
749
880
|
* Method to retrieve pending txs.
|
|
750
881
|
* @param limit - The number of items to returns
|
|
@@ -777,20 +908,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
908
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
909
|
}
|
|
779
910
|
|
|
780
|
-
/**
|
|
781
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
782
|
-
* the leaves were inserted.
|
|
783
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
784
|
-
* @param treeId - The tree to search in.
|
|
785
|
-
* @param leafValues - The values to search for.
|
|
786
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
787
|
-
*/
|
|
788
911
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
912
|
+
referenceBlock: BlockParameter,
|
|
790
913
|
treeId: MerkleTreeId,
|
|
791
914
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this.#getWorldState(
|
|
915
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
916
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
794
917
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
918
|
treeId,
|
|
796
919
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -815,7 +938,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
815
938
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
816
939
|
const blockHashes = await Promise.all(
|
|
817
940
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
941
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
942
|
}),
|
|
820
943
|
);
|
|
821
944
|
|
|
@@ -826,7 +949,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
949
|
}
|
|
827
950
|
}
|
|
828
951
|
|
|
829
|
-
// Create
|
|
952
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
830
953
|
return maybeIndices.map((index, i) => {
|
|
831
954
|
if (index === undefined) {
|
|
832
955
|
return undefined;
|
|
@@ -841,57 +964,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
841
964
|
return undefined;
|
|
842
965
|
}
|
|
843
966
|
return {
|
|
844
|
-
l2BlockNumber: Number(blockNumber),
|
|
845
|
-
l2BlockHash:
|
|
967
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
968
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
846
969
|
data: index,
|
|
847
970
|
};
|
|
848
971
|
});
|
|
849
972
|
}
|
|
850
973
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
855
|
-
* @returns The sibling path for the leaf index.
|
|
856
|
-
*/
|
|
857
|
-
public async getNullifierSiblingPath(
|
|
858
|
-
blockNumber: L2BlockNumber,
|
|
859
|
-
leafIndex: bigint,
|
|
860
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
861
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
862
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Returns a sibling path for the given index in the data tree.
|
|
867
|
-
* @param blockNumber - The block number at which to get the data.
|
|
868
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
869
|
-
* @returns The sibling path for the leaf index.
|
|
870
|
-
*/
|
|
871
|
-
public async getNoteHashSiblingPath(
|
|
872
|
-
blockNumber: L2BlockNumber,
|
|
873
|
-
leafIndex: bigint,
|
|
874
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
875
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
876
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
public async getArchiveMembershipWitness(
|
|
880
|
-
blockNumber: L2BlockNumber,
|
|
881
|
-
archive: Fr,
|
|
974
|
+
public async getBlockHashMembershipWitness(
|
|
975
|
+
referenceBlock: BlockParameter,
|
|
976
|
+
blockHash: BlockHash,
|
|
882
977
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
const committedDb = await this.#getWorldState(
|
|
884
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
978
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
979
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
885
980
|
return pathAndIndex === undefined
|
|
886
981
|
? undefined
|
|
887
982
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
888
983
|
}
|
|
889
984
|
|
|
890
985
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
986
|
+
referenceBlock: BlockParameter,
|
|
892
987
|
noteHash: Fr,
|
|
893
988
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this.#getWorldState(
|
|
989
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
895
990
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
991
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
992
|
[noteHash],
|
|
@@ -901,17 +996,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
996
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
997
|
}
|
|
903
998
|
|
|
904
|
-
/**
|
|
905
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
906
|
-
* @param blockNumber - The block number at which to get the data.
|
|
907
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
908
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
909
|
-
*/
|
|
910
999
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
1000
|
+
referenceBlock: BlockParameter,
|
|
912
1001
|
l1ToL2Message: Fr,
|
|
913
1002
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this.#getWorldState(
|
|
1003
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
915
1004
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
1005
|
if (!witness) {
|
|
917
1006
|
return undefined;
|
|
@@ -921,9 +1010,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
1010
|
return [witness.index, witness.path];
|
|
922
1011
|
}
|
|
923
1012
|
|
|
924
|
-
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<
|
|
1013
|
+
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
925
1014
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex
|
|
1015
|
+
return messageIndex
|
|
1016
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
1017
|
+
: undefined;
|
|
927
1018
|
}
|
|
928
1019
|
|
|
929
1020
|
/**
|
|
@@ -937,54 +1028,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
1028
|
}
|
|
938
1029
|
|
|
939
1030
|
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in
|
|
941
|
-
* @param
|
|
942
|
-
* @returns The L2 to L1 messages (
|
|
943
|
-
*/
|
|
944
|
-
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
945
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
946
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
951
|
-
* @param blockNumber - The block number at which to get the data.
|
|
952
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
953
|
-
* @returns The sibling path.
|
|
1031
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1032
|
+
* @param epoch - The epoch at which to get the data.
|
|
1033
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
954
1034
|
*/
|
|
955
|
-
public async
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1035
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1036
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1037
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1038
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
1039
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1040
|
+
let checkpointIndex = -1;
|
|
1041
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1042
|
+
const block = checkpointedBlock.block;
|
|
1043
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1044
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1045
|
+
checkpointIndex++;
|
|
1046
|
+
blocksInCheckpoints.push([]);
|
|
1047
|
+
previousSlotNumber = slotNumber;
|
|
1048
|
+
}
|
|
1049
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1050
|
+
}
|
|
1051
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1052
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1053
|
+
);
|
|
975
1054
|
}
|
|
976
1055
|
|
|
977
|
-
/**
|
|
978
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
979
|
-
* @param blockNumber - The block number at which to get the index.
|
|
980
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
981
|
-
* @returns The nullifier membership witness (if found).
|
|
982
|
-
*/
|
|
983
1056
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1057
|
+
referenceBlock: BlockParameter,
|
|
985
1058
|
nullifier: Fr,
|
|
986
1059
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this.#getWorldState(
|
|
1060
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
988
1061
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1062
|
if (!witness) {
|
|
990
1063
|
return undefined;
|
|
@@ -1001,7 +1074,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1074
|
|
|
1002
1075
|
/**
|
|
1003
1076
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param
|
|
1077
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1078
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1005
1079
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
1080
|
* @returns The low nullifier membership witness (if found).
|
|
1007
1081
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1014,10 +1088,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1088
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
1089
|
*/
|
|
1016
1090
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1091
|
+
referenceBlock: BlockParameter,
|
|
1018
1092
|
nullifier: Fr,
|
|
1019
1093
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(
|
|
1094
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1021
1095
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1096
|
if (!findResult) {
|
|
1023
1097
|
return undefined;
|
|
@@ -1032,8 +1106,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1106
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1107
|
}
|
|
1034
1108
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this.#getWorldState(
|
|
1109
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1110
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1037
1111
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1112
|
if (!lowLeafResult) {
|
|
1039
1113
|
return undefined;
|
|
@@ -1047,19 +1121,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1121
|
}
|
|
1048
1122
|
}
|
|
1049
1123
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
*
|
|
1053
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1054
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1055
|
-
*
|
|
1056
|
-
* @param contract - Address of the contract to query.
|
|
1057
|
-
* @param slot - Slot to query.
|
|
1058
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1059
|
-
* @returns Storage value at the given contract slot.
|
|
1060
|
-
*/
|
|
1061
|
-
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1062
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1124
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1125
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1063
1126
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1127
|
|
|
1065
1128
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1136,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1136
|
return preimage.leaf.value;
|
|
1074
1137
|
}
|
|
1075
1138
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1139
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1140
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1141
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1142
|
+
if (block.equals(initialBlockHash)) {
|
|
1143
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1144
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1145
|
+
}
|
|
1146
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1147
|
+
} else {
|
|
1148
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1149
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1150
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1151
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1152
|
+
}
|
|
1153
|
+
return this.blockSource.getBlockHeader(block);
|
|
1154
|
+
}
|
|
1093
1155
|
}
|
|
1094
1156
|
|
|
1095
1157
|
/**
|
|
@@ -1101,6 +1163,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1101
1163
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1102
1164
|
}
|
|
1103
1165
|
|
|
1166
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1167
|
+
return this.blockSource.getBlockData(number);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1171
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1104
1174
|
/**
|
|
1105
1175
|
* Simulates the public part of a transaction with the current state.
|
|
1106
1176
|
* @param tx - The transaction to simulate.
|
|
@@ -1124,7 +1194,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1194
|
}
|
|
1125
1195
|
|
|
1126
1196
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const
|
|
1197
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1198
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1128
1199
|
|
|
1129
1200
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1201
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1139,6 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1210
|
this.contractDataSource,
|
|
1140
1211
|
new DateProvider(),
|
|
1141
1212
|
this.telemetry,
|
|
1213
|
+
this.log.getBindings(),
|
|
1142
1214
|
);
|
|
1143
1215
|
|
|
1144
1216
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1147,17 +1219,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1147
1219
|
blockNumber,
|
|
1148
1220
|
});
|
|
1149
1221
|
|
|
1222
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1223
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1150
1224
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1225
|
try {
|
|
1152
|
-
const
|
|
1153
|
-
merkleTreeFork,
|
|
1154
|
-
newGlobalVariables,
|
|
1226
|
+
const config = PublicSimulatorConfig.from({
|
|
1155
1227
|
skipFeeEnforcement,
|
|
1156
|
-
|
|
1157
|
-
|
|
1228
|
+
collectDebugLogs: true,
|
|
1229
|
+
collectHints: false,
|
|
1230
|
+
collectCallMetadata: true,
|
|
1231
|
+
collectStatistics: false,
|
|
1232
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1233
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1234
|
+
}),
|
|
1235
|
+
});
|
|
1236
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1158
1237
|
|
|
1159
1238
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1160
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1239
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
|
|
1161
1240
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1162
1241
|
if (failedTxs.length) {
|
|
1163
1242
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1171,6 +1250,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1171
1250
|
processedTx.txEffect,
|
|
1172
1251
|
returns,
|
|
1173
1252
|
processedTx.gasUsed,
|
|
1253
|
+
debugLogs,
|
|
1174
1254
|
);
|
|
1175
1255
|
} finally {
|
|
1176
1256
|
await merkleTreeFork.close();
|
|
@@ -1184,19 +1264,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1184
1264
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1185
1265
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1186
1266
|
|
|
1187
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1267
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1188
1268
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1189
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1190
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1269
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1270
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1271
|
+
db,
|
|
1272
|
+
this.contractDataSource,
|
|
1273
|
+
verifier,
|
|
1274
|
+
{
|
|
1275
|
+
timestamp: nextSlotTimestamp,
|
|
1276
|
+
blockNumber,
|
|
1277
|
+
l1ChainId: this.l1ChainId,
|
|
1278
|
+
rollupVersion: this.version,
|
|
1279
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1280
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1281
|
+
skipFeeEnforcement,
|
|
1282
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1283
|
+
},
|
|
1284
|
+
this.log.getBindings(),
|
|
1285
|
+
);
|
|
1200
1286
|
|
|
1201
1287
|
return await validator.validateTx(tx);
|
|
1202
1288
|
}
|
|
@@ -1243,8 +1329,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1329
|
|
|
1244
1330
|
public getValidatorStats(
|
|
1245
1331
|
validatorAddress: EthAddress,
|
|
1246
|
-
fromSlot?:
|
|
1247
|
-
toSlot?:
|
|
1332
|
+
fromSlot?: SlotNumber,
|
|
1333
|
+
toSlot?: SlotNumber,
|
|
1248
1334
|
): Promise<SingleValidatorStats | undefined> {
|
|
1249
1335
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1250
1336
|
}
|
|
@@ -1254,45 +1340,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1254
1340
|
// We break support for archiver running remotely to the node
|
|
1255
1341
|
const archiver = this.blockSource as Archiver;
|
|
1256
1342
|
if (!('backupTo' in archiver)) {
|
|
1343
|
+
this.metrics.recordSnapshotError();
|
|
1257
1344
|
throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
|
|
1258
1345
|
}
|
|
1259
1346
|
|
|
1260
1347
|
// Test that the archiver has done an initial sync.
|
|
1261
1348
|
if (!archiver.isInitialSyncComplete()) {
|
|
1349
|
+
this.metrics.recordSnapshotError();
|
|
1262
1350
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
1263
1351
|
}
|
|
1264
1352
|
|
|
1265
1353
|
// And it has an L2 block hash
|
|
1266
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1354
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1267
1355
|
if (!l2BlockHash) {
|
|
1356
|
+
this.metrics.recordSnapshotError();
|
|
1268
1357
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
1269
1358
|
}
|
|
1270
1359
|
|
|
1271
1360
|
if (this.isUploadingSnapshot) {
|
|
1361
|
+
this.metrics.recordSnapshotError();
|
|
1272
1362
|
throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
|
|
1273
1363
|
}
|
|
1274
1364
|
|
|
1275
1365
|
// Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
|
|
1276
1366
|
this.isUploadingSnapshot = true;
|
|
1367
|
+
const timer = new Timer();
|
|
1277
1368
|
void uploadSnapshot(location, this.blockSource as Archiver, this.worldStateSynchronizer, this.config, this.log)
|
|
1278
1369
|
.then(() => {
|
|
1279
1370
|
this.isUploadingSnapshot = false;
|
|
1371
|
+
this.metrics.recordSnapshot(timer.ms());
|
|
1280
1372
|
})
|
|
1281
1373
|
.catch(err => {
|
|
1282
1374
|
this.isUploadingSnapshot = false;
|
|
1375
|
+
this.metrics.recordSnapshotError();
|
|
1283
1376
|
this.log.error(`Error uploading snapshot: ${err}`);
|
|
1284
1377
|
});
|
|
1285
1378
|
|
|
1286
1379
|
return Promise.resolve();
|
|
1287
1380
|
}
|
|
1288
1381
|
|
|
1289
|
-
public async rollbackTo(targetBlock:
|
|
1382
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1290
1383
|
const archiver = this.blockSource as Archiver;
|
|
1291
1384
|
if (!('rollbackTo' in archiver)) {
|
|
1292
1385
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1293
1386
|
}
|
|
1294
1387
|
|
|
1295
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1388
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1296
1389
|
if (targetBlock < finalizedBlock) {
|
|
1297
1390
|
if (force) {
|
|
1298
1391
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1353,17 +1446,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1353
1446
|
}
|
|
1354
1447
|
}
|
|
1355
1448
|
|
|
1449
|
+
public async reloadKeystore(): Promise<void> {
|
|
1450
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1451
|
+
throw new BadRequestError(
|
|
1452
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1453
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1454
|
+
);
|
|
1455
|
+
}
|
|
1456
|
+
if (!this.validatorClient) {
|
|
1457
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
this.log.info('Reloading keystore from disk');
|
|
1461
|
+
|
|
1462
|
+
// Re-read and validate keystore files
|
|
1463
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1464
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1465
|
+
await newManager.validateSigners();
|
|
1466
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1467
|
+
|
|
1468
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1469
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1470
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1471
|
+
// would silently fail on every proposer slot.
|
|
1472
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1473
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1474
|
+
const availablePublishers = new Set(
|
|
1475
|
+
oldAdapter
|
|
1476
|
+
.getAttesterAddresses()
|
|
1477
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1478
|
+
);
|
|
1479
|
+
|
|
1480
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1481
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1482
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1483
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1484
|
+
throw new BadRequestError(
|
|
1485
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1486
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1487
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1488
|
+
`use an existing publisher key or restart the node.`,
|
|
1489
|
+
);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
// Build adapters for old and new keystores to compute diff
|
|
1495
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1496
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1497
|
+
const oldAddresses = this.keyStoreManager
|
|
1498
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1499
|
+
: [];
|
|
1500
|
+
|
|
1501
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1502
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1503
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1504
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1505
|
+
|
|
1506
|
+
if (added.length > 0) {
|
|
1507
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1508
|
+
}
|
|
1509
|
+
if (removed.length > 0) {
|
|
1510
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1511
|
+
}
|
|
1512
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1513
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1517
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1518
|
+
|
|
1519
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1520
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1521
|
+
if (this.sequencer) {
|
|
1522
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1526
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1527
|
+
const slashValidatorsNever = unique(
|
|
1528
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1529
|
+
).map(EthAddress.fromString);
|
|
1530
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1531
|
+
}
|
|
1532
|
+
|
|
1533
|
+
this.keyStoreManager = newManager;
|
|
1534
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1538
|
+
if (!this.initialHeaderHashPromise) {
|
|
1539
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1540
|
+
}
|
|
1541
|
+
return this.initialHeaderHashPromise;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1356
1544
|
/**
|
|
1357
1545
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1358
|
-
* @param
|
|
1546
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1359
1547
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1360
1548
|
*/
|
|
1361
|
-
async #getWorldState(
|
|
1362
|
-
|
|
1363
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
let blockSyncedTo: number = 0;
|
|
1549
|
+
async #getWorldState(block: BlockParameter) {
|
|
1550
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1367
1551
|
try {
|
|
1368
1552
|
// Attempt to sync the world state if necessary
|
|
1369
1553
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1371,15 +1555,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1371
1555
|
this.log.error(`Error getting world state: ${err}`);
|
|
1372
1556
|
}
|
|
1373
1557
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1558
|
+
if (block === 'latest') {
|
|
1559
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1377
1560
|
return this.worldStateSynchronizer.getCommitted();
|
|
1378
|
-
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1564
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1565
|
+
if (block.equals(initialBlockHash)) {
|
|
1566
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1567
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1571
|
+
if (!header) {
|
|
1572
|
+
throw new Error(
|
|
1573
|
+
`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.`,
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
const blockNumber = header.getBlockNumber();
|
|
1577
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1578
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
// Block number provided
|
|
1582
|
+
{
|
|
1583
|
+
const blockNumber = block as BlockNumber;
|
|
1584
|
+
|
|
1585
|
+
if (blockNumber > blockSyncedTo) {
|
|
1586
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1379
1589
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1380
1590
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1381
|
-
} else {
|
|
1382
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1383
1591
|
}
|
|
1384
1592
|
}
|
|
1385
1593
|
|
|
@@ -1387,8 +1595,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1387
1595
|
* Ensure we fully sync the world state
|
|
1388
1596
|
* @returns A promise that fulfils once the world state is synced
|
|
1389
1597
|
*/
|
|
1390
|
-
async #syncWorldState(): Promise<
|
|
1598
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1391
1599
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1392
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1600
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1393
1601
|
}
|
|
1394
1602
|
}
|