@aztec/aztec-node 0.0.1-commit.21caa21 → 0.0.1-commit.21ecf947b
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 +5 -2
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +7 -1
- 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 +9 -16
- package/dest/aztec-node/server.d.ts +52 -122
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +639 -206
- 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/sentinel.d.ts +6 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +68 -44
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +28 -28
- package/src/aztec-node/config.ts +12 -8
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +326 -279
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +80 -47
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
ARCHIVE_HEIGHT,
|
|
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 { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
5
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getPublicClient,
|
|
19
|
-
} from '@aztec/ethereum';
|
|
20
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
7
|
+
import { getPublicClient } from '@aztec/ethereum/client';
|
|
8
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
9
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
10
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
21
11
|
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
22
13
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
23
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
24
14
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
25
15
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
26
16
|
import { count } from '@aztec/foundation/string';
|
|
@@ -28,16 +18,13 @@ import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
|
28
18
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
19
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
20
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
31
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
createForwarderL1TxUtilsFromEthSigner,
|
|
23
|
+
createL1TxUtilsWithBlobsFromEthSigner,
|
|
24
|
+
} from '@aztec/node-lib/factories';
|
|
32
25
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
26
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
35
|
-
BlockBuilder,
|
|
36
|
-
GlobalVariableBuilder,
|
|
37
|
-
SequencerClient,
|
|
38
|
-
type SequencerPublisher,
|
|
39
|
-
createValidatorForAcceptingTxs,
|
|
40
|
-
} from '@aztec/sequencer-client';
|
|
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,16 +33,10 @@ import {
|
|
|
46
33
|
type Watcher,
|
|
47
34
|
createSlasher,
|
|
48
35
|
} from '@aztec/slasher';
|
|
49
|
-
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
36
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
50
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
type L2Block,
|
|
54
|
-
L2BlockHash,
|
|
55
|
-
type L2BlockNumber,
|
|
56
|
-
type L2BlockSource,
|
|
57
|
-
type PublishedL2Block,
|
|
58
|
-
} from '@aztec/stdlib/block';
|
|
38
|
+
import { BlockHash, type BlockParameter, type DataInBlock, L2Block, type L2BlockSource } from '@aztec/stdlib/block';
|
|
39
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
59
40
|
import type {
|
|
60
41
|
ContractClassPublic,
|
|
61
42
|
ContractDataSource,
|
|
@@ -63,7 +44,7 @@ import type {
|
|
|
63
44
|
NodeInfo,
|
|
64
45
|
ProtocolContractAddresses,
|
|
65
46
|
} from '@aztec/stdlib/contract';
|
|
66
|
-
import
|
|
47
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
67
48
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
68
49
|
import {
|
|
69
50
|
type AztecNode,
|
|
@@ -82,7 +63,7 @@ import {
|
|
|
82
63
|
type WorldStateSynchronizer,
|
|
83
64
|
tryStop,
|
|
84
65
|
} from '@aztec/stdlib/interfaces/server';
|
|
85
|
-
import type { LogFilter,
|
|
66
|
+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
86
67
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
87
68
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
88
69
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -110,10 +91,13 @@ import {
|
|
|
110
91
|
trackSpan,
|
|
111
92
|
} from '@aztec/telemetry-client';
|
|
112
93
|
import {
|
|
94
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
95
|
+
FullNodeCheckpointsBuilder,
|
|
113
96
|
NodeKeystoreAdapter,
|
|
114
97
|
ValidatorClient,
|
|
115
98
|
createBlockProposalHandler,
|
|
116
99
|
createValidatorClient,
|
|
100
|
+
createValidatorForAcceptingTxs,
|
|
117
101
|
} from '@aztec/validator-client';
|
|
118
102
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
119
103
|
|
|
@@ -129,6 +113,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
129
113
|
*/
|
|
130
114
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
131
115
|
private metrics: NodeMetrics;
|
|
116
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
132
117
|
|
|
133
118
|
// Prevent two snapshot operations to happen simultaneously
|
|
134
119
|
private isUploadingSnapshot = false;
|
|
@@ -155,6 +140,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
155
140
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
156
141
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
157
142
|
private log = createLogger('node'),
|
|
143
|
+
private blobClient?: BlobClientInterface,
|
|
158
144
|
) {
|
|
159
145
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
146
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
@@ -184,7 +170,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
170
|
logger?: Logger;
|
|
185
171
|
publisher?: SequencerPublisher;
|
|
186
172
|
dateProvider?: DateProvider;
|
|
187
|
-
blobSinkClient?: BlobSinkClientInterface;
|
|
188
173
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
189
174
|
} = {},
|
|
190
175
|
options: {
|
|
@@ -197,8 +182,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
197
182
|
const packageVersion = getPackageVersion() ?? '';
|
|
198
183
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
199
184
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
200
|
-
const blobSinkClient =
|
|
201
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
202
185
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
203
186
|
|
|
204
187
|
// Build a key store from file if given or from environment otherwise
|
|
@@ -238,7 +221,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
238
221
|
|
|
239
222
|
const publicClient = createPublicClient({
|
|
240
223
|
chain: ethereumChain.chainInfo,
|
|
241
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
224
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
242
225
|
pollingInterval: config.viemPollingIntervalMS,
|
|
243
226
|
});
|
|
244
227
|
|
|
@@ -266,6 +249,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
266
249
|
);
|
|
267
250
|
}
|
|
268
251
|
|
|
252
|
+
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
253
|
+
|
|
269
254
|
// attempt snapshot sync if possible
|
|
270
255
|
await trySnapshotSync(config, log);
|
|
271
256
|
|
|
@@ -273,7 +258,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
273
258
|
|
|
274
259
|
const archiver = await createArchiver(
|
|
275
260
|
config,
|
|
276
|
-
{
|
|
261
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
277
262
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
278
263
|
);
|
|
279
264
|
|
|
@@ -284,9 +269,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
284
269
|
options.prefilledPublicData,
|
|
285
270
|
telemetry,
|
|
286
271
|
);
|
|
287
|
-
const circuitVerifier =
|
|
288
|
-
|
|
289
|
-
|
|
272
|
+
const circuitVerifier =
|
|
273
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
274
|
+
? await BBCircuitVerifier.new(config)
|
|
275
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
290
276
|
if (!config.realProofs) {
|
|
291
277
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
292
278
|
}
|
|
@@ -309,7 +295,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
309
295
|
// We should really not be modifying the config object
|
|
310
296
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
311
297
|
|
|
312
|
-
|
|
298
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
299
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
313
300
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
314
301
|
worldStateSynchronizer,
|
|
315
302
|
archiver,
|
|
@@ -321,15 +308,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
321
308
|
const watchers: Watcher[] = [];
|
|
322
309
|
|
|
323
310
|
// Create validator client if required
|
|
324
|
-
const validatorClient = createValidatorClient(config, {
|
|
311
|
+
const validatorClient = await createValidatorClient(config, {
|
|
312
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
313
|
+
worldState: worldStateSynchronizer,
|
|
325
314
|
p2pClient,
|
|
326
315
|
telemetry,
|
|
327
316
|
dateProvider,
|
|
328
317
|
epochCache,
|
|
329
|
-
blockBuilder,
|
|
330
318
|
blockSource: archiver,
|
|
331
319
|
l1ToL2MessageSource: archiver,
|
|
332
320
|
keyStoreManager,
|
|
321
|
+
blobClient,
|
|
333
322
|
});
|
|
334
323
|
|
|
335
324
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -347,7 +336,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
347
336
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
348
337
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
349
338
|
createBlockProposalHandler(config, {
|
|
350
|
-
|
|
339
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
340
|
+
worldState: worldStateSynchronizer,
|
|
351
341
|
epochCache,
|
|
352
342
|
blockSource: archiver,
|
|
353
343
|
l1ToL2MessageSource: archiver,
|
|
@@ -375,7 +365,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
375
365
|
archiver,
|
|
376
366
|
epochCache,
|
|
377
367
|
p2pClient.getTxProvider(),
|
|
378
|
-
|
|
368
|
+
validatorCheckpointsBuilder,
|
|
379
369
|
config,
|
|
380
370
|
);
|
|
381
371
|
watchers.push(epochPruneWatcher);
|
|
@@ -403,7 +393,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
403
393
|
// Validator enabled, create/start relevant service
|
|
404
394
|
let sequencer: SequencerClient | undefined;
|
|
405
395
|
let slasherClient: SlasherClientInterface | undefined;
|
|
406
|
-
if (!config.disableValidator) {
|
|
396
|
+
if (!config.disableValidator && validatorClient) {
|
|
407
397
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
408
398
|
// as they are executed when the node is selected as proposer.
|
|
409
399
|
const validatorAddresses = keyStoreManager
|
|
@@ -422,14 +412,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
422
412
|
);
|
|
423
413
|
await slasherClient.start();
|
|
424
414
|
|
|
425
|
-
const l1TxUtils =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
415
|
+
const l1TxUtils = config.publisherForwarderAddress
|
|
416
|
+
? await createForwarderL1TxUtilsFromEthSigner(
|
|
417
|
+
publicClient,
|
|
418
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
419
|
+
config.publisherForwarderAddress,
|
|
420
|
+
{ ...config, scope: 'sequencer' },
|
|
421
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
422
|
+
)
|
|
423
|
+
: await createL1TxUtilsWithBlobsFromEthSigner(
|
|
424
|
+
publicClient,
|
|
425
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
426
|
+
{ ...config, scope: 'sequencer' },
|
|
427
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
428
|
+
);
|
|
431
429
|
|
|
432
430
|
// Create and start the sequencer client
|
|
431
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
432
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
433
|
+
worldStateSynchronizer,
|
|
434
|
+
archiver,
|
|
435
|
+
dateProvider,
|
|
436
|
+
telemetry,
|
|
437
|
+
);
|
|
438
|
+
|
|
433
439
|
sequencer = await SequencerClient.new(config, {
|
|
434
440
|
...deps,
|
|
435
441
|
epochCache,
|
|
@@ -438,12 +444,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
438
444
|
p2pClient,
|
|
439
445
|
worldStateSynchronizer,
|
|
440
446
|
slasherClient,
|
|
441
|
-
|
|
447
|
+
checkpointsBuilder,
|
|
442
448
|
l2BlockSource: archiver,
|
|
443
449
|
l1ToL2MessageSource: archiver,
|
|
444
450
|
telemetry,
|
|
445
451
|
dateProvider,
|
|
446
|
-
|
|
452
|
+
blobClient,
|
|
447
453
|
nodeKeyStore: keyStoreManager!,
|
|
448
454
|
});
|
|
449
455
|
}
|
|
@@ -455,6 +461,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
461
|
log.warn(`Sequencer created but not started`);
|
|
456
462
|
}
|
|
457
463
|
|
|
464
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
465
|
+
...config,
|
|
466
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
467
|
+
l1GenesisTime,
|
|
468
|
+
slotDuration: Number(slotDuration),
|
|
469
|
+
});
|
|
470
|
+
|
|
458
471
|
return new AztecNodeService(
|
|
459
472
|
config,
|
|
460
473
|
p2pClient,
|
|
@@ -469,12 +482,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
469
482
|
epochPruneWatcher,
|
|
470
483
|
ethereumChain.chainInfo.id,
|
|
471
484
|
config.rollupVersion,
|
|
472
|
-
|
|
485
|
+
globalVariableBuilder,
|
|
473
486
|
epochCache,
|
|
474
487
|
packageVersion,
|
|
475
488
|
proofVerifier,
|
|
476
489
|
telemetry,
|
|
477
490
|
log,
|
|
491
|
+
blobClient,
|
|
478
492
|
);
|
|
479
493
|
}
|
|
480
494
|
|
|
@@ -539,19 +553,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
539
553
|
enr,
|
|
540
554
|
l1ContractAddresses: contractAddresses,
|
|
541
555
|
protocolContractAddresses: protocolContractAddresses,
|
|
556
|
+
realProofs: !!this.config.realProofs,
|
|
542
557
|
};
|
|
543
558
|
|
|
544
559
|
return nodeInfo;
|
|
545
560
|
}
|
|
546
561
|
|
|
547
562
|
/**
|
|
548
|
-
* Get a block specified by its number.
|
|
549
|
-
* @param
|
|
563
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
564
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
550
565
|
* @returns The requested block.
|
|
551
566
|
*/
|
|
552
|
-
public async getBlock(
|
|
553
|
-
|
|
554
|
-
|
|
567
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
568
|
+
if (BlockHash.isBlockHash(block)) {
|
|
569
|
+
return this.getBlockByHash(block);
|
|
570
|
+
}
|
|
571
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
572
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
573
|
+
return this.buildInitialBlock();
|
|
574
|
+
}
|
|
575
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
555
576
|
}
|
|
556
577
|
|
|
557
578
|
/**
|
|
@@ -559,9 +580,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
559
580
|
* @param blockHash - The block hash being requested.
|
|
560
581
|
* @returns The requested block.
|
|
561
582
|
*/
|
|
562
|
-
public async getBlockByHash(blockHash:
|
|
563
|
-
const
|
|
564
|
-
|
|
583
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
584
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
585
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
586
|
+
return this.buildInitialBlock();
|
|
587
|
+
}
|
|
588
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
private buildInitialBlock(): L2Block {
|
|
592
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
593
|
+
return L2Block.empty(initialHeader);
|
|
565
594
|
}
|
|
566
595
|
|
|
567
596
|
/**
|
|
@@ -570,8 +599,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
570
599
|
* @returns The requested block.
|
|
571
600
|
*/
|
|
572
601
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
573
|
-
|
|
574
|
-
return publishedBlock?.block;
|
|
602
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
575
603
|
}
|
|
576
604
|
|
|
577
605
|
/**
|
|
@@ -580,34 +608,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
580
608
|
* @param limit - The maximum number of blocks to obtain.
|
|
581
609
|
* @returns The blocks requested.
|
|
582
610
|
*/
|
|
583
|
-
public async getBlocks(from:
|
|
584
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
611
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
612
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
616
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
585
617
|
}
|
|
586
618
|
|
|
587
|
-
public async
|
|
588
|
-
return (await this.blockSource.
|
|
619
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
620
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
589
621
|
}
|
|
590
622
|
|
|
591
623
|
/**
|
|
592
|
-
* Method to fetch the current
|
|
593
|
-
* @returns The current
|
|
624
|
+
* Method to fetch the current min L2 fees.
|
|
625
|
+
* @returns The current min L2 fees.
|
|
594
626
|
*/
|
|
595
|
-
public async
|
|
596
|
-
return await this.globalVariableBuilder.
|
|
627
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
628
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
632
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
633
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
597
637
|
}
|
|
598
638
|
|
|
599
639
|
/**
|
|
600
640
|
* Method to fetch the latest block number synchronized by the node.
|
|
601
641
|
* @returns The block number.
|
|
602
642
|
*/
|
|
603
|
-
public async getBlockNumber(): Promise<
|
|
643
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
604
644
|
return await this.blockSource.getBlockNumber();
|
|
605
645
|
}
|
|
606
646
|
|
|
607
|
-
public async getProvenBlockNumber(): Promise<
|
|
647
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
608
648
|
return await this.blockSource.getProvenBlockNumber();
|
|
609
649
|
}
|
|
610
650
|
|
|
651
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
652
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
653
|
+
}
|
|
654
|
+
|
|
611
655
|
/**
|
|
612
656
|
* Method to fetch the version of the package.
|
|
613
657
|
* @returns The node package version
|
|
@@ -640,25 +684,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
640
684
|
return this.contractDataSource.getContract(address);
|
|
641
685
|
}
|
|
642
686
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
687
|
+
public async getPrivateLogsByTags(
|
|
688
|
+
tags: SiloedTag[],
|
|
689
|
+
page?: number,
|
|
690
|
+
referenceBlock?: BlockHash,
|
|
691
|
+
): Promise<TxScopedL2Log[][]> {
|
|
692
|
+
if (referenceBlock) {
|
|
693
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
694
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
695
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
696
|
+
if (!header) {
|
|
697
|
+
throw new Error(
|
|
698
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
public async getPublicLogsByTagsFromContract(
|
|
707
|
+
contractAddress: AztecAddress,
|
|
708
|
+
tags: Tag[],
|
|
709
|
+
page?: number,
|
|
710
|
+
referenceBlock?: BlockHash,
|
|
711
|
+
): Promise<TxScopedL2Log[][]> {
|
|
712
|
+
if (referenceBlock) {
|
|
713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
714
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
715
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
716
|
+
if (!header) {
|
|
717
|
+
throw new Error(
|
|
718
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
662
724
|
}
|
|
663
725
|
|
|
664
726
|
/**
|
|
@@ -705,21 +767,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
705
767
|
}
|
|
706
768
|
|
|
707
769
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
713
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
714
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
715
|
-
}
|
|
770
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
771
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
772
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
773
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
716
774
|
|
|
775
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
717
776
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
777
|
+
|
|
718
778
|
if (settledTxReceipt) {
|
|
719
|
-
|
|
779
|
+
// If the archiver has the receipt then return it.
|
|
780
|
+
return settledTxReceipt;
|
|
781
|
+
} else if (isKnownToPool) {
|
|
782
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
783
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
784
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
785
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
786
|
+
} else {
|
|
787
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
788
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
720
789
|
}
|
|
721
|
-
|
|
722
|
-
return txReceipt;
|
|
723
790
|
}
|
|
724
791
|
|
|
725
792
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -739,10 +806,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
739
806
|
await tryStop(this.p2pClient);
|
|
740
807
|
await tryStop(this.worldStateSynchronizer);
|
|
741
808
|
await tryStop(this.blockSource);
|
|
809
|
+
await tryStop(this.blobClient);
|
|
742
810
|
await tryStop(this.telemetry);
|
|
743
811
|
this.log.info(`Stopped Aztec Node`);
|
|
744
812
|
}
|
|
745
813
|
|
|
814
|
+
/**
|
|
815
|
+
* Returns the blob client used by this node.
|
|
816
|
+
* @internal - Exposed for testing purposes only.
|
|
817
|
+
*/
|
|
818
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
819
|
+
return this.blobClient;
|
|
820
|
+
}
|
|
821
|
+
|
|
746
822
|
/**
|
|
747
823
|
* Method to retrieve pending txs.
|
|
748
824
|
* @param limit - The number of items to returns
|
|
@@ -775,20 +851,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
775
851
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
776
852
|
}
|
|
777
853
|
|
|
778
|
-
/**
|
|
779
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
780
|
-
* the leaves were inserted.
|
|
781
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
782
|
-
* @param treeId - The tree to search in.
|
|
783
|
-
* @param leafValues - The values to search for.
|
|
784
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
785
|
-
*/
|
|
786
854
|
public async findLeavesIndexes(
|
|
787
|
-
|
|
855
|
+
referenceBlock: BlockParameter,
|
|
788
856
|
treeId: MerkleTreeId,
|
|
789
857
|
leafValues: Fr[],
|
|
790
|
-
): Promise<(
|
|
791
|
-
const committedDb = await this.#getWorldState(
|
|
858
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
859
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
792
860
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
793
861
|
treeId,
|
|
794
862
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -813,7 +881,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
813
881
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
814
882
|
const blockHashes = await Promise.all(
|
|
815
883
|
uniqueBlockNumbers.map(blockNumber => {
|
|
816
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
884
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
817
885
|
}),
|
|
818
886
|
);
|
|
819
887
|
|
|
@@ -824,7 +892,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
824
892
|
}
|
|
825
893
|
}
|
|
826
894
|
|
|
827
|
-
// Create
|
|
895
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
828
896
|
return maybeIndices.map((index, i) => {
|
|
829
897
|
if (index === undefined) {
|
|
830
898
|
return undefined;
|
|
@@ -839,57 +907,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
839
907
|
return undefined;
|
|
840
908
|
}
|
|
841
909
|
return {
|
|
842
|
-
l2BlockNumber: Number(blockNumber),
|
|
843
|
-
l2BlockHash:
|
|
910
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
911
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
844
912
|
data: index,
|
|
845
913
|
};
|
|
846
914
|
});
|
|
847
915
|
}
|
|
848
916
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
853
|
-
* @returns The sibling path for the leaf index.
|
|
854
|
-
*/
|
|
855
|
-
public async getNullifierSiblingPath(
|
|
856
|
-
blockNumber: L2BlockNumber,
|
|
857
|
-
leafIndex: bigint,
|
|
858
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
859
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
860
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Returns a sibling path for the given index in the data tree.
|
|
865
|
-
* @param blockNumber - The block number at which to get the data.
|
|
866
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
867
|
-
* @returns The sibling path for the leaf index.
|
|
868
|
-
*/
|
|
869
|
-
public async getNoteHashSiblingPath(
|
|
870
|
-
blockNumber: L2BlockNumber,
|
|
871
|
-
leafIndex: bigint,
|
|
872
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
873
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
874
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
public async getArchiveMembershipWitness(
|
|
878
|
-
blockNumber: L2BlockNumber,
|
|
879
|
-
archive: Fr,
|
|
917
|
+
public async getBlockHashMembershipWitness(
|
|
918
|
+
referenceBlock: BlockParameter,
|
|
919
|
+
blockHash: BlockHash,
|
|
880
920
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
881
|
-
const committedDb = await this.#getWorldState(
|
|
882
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
921
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
922
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
883
923
|
return pathAndIndex === undefined
|
|
884
924
|
? undefined
|
|
885
925
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
886
926
|
}
|
|
887
927
|
|
|
888
928
|
public async getNoteHashMembershipWitness(
|
|
889
|
-
|
|
929
|
+
referenceBlock: BlockParameter,
|
|
890
930
|
noteHash: Fr,
|
|
891
931
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
892
|
-
const committedDb = await this.#getWorldState(
|
|
932
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
893
933
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
894
934
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
895
935
|
[noteHash],
|
|
@@ -899,17 +939,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
899
939
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
900
940
|
}
|
|
901
941
|
|
|
902
|
-
/**
|
|
903
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
904
|
-
* @param blockNumber - The block number at which to get the data.
|
|
905
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
906
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
907
|
-
*/
|
|
908
942
|
public async getL1ToL2MessageMembershipWitness(
|
|
909
|
-
|
|
943
|
+
referenceBlock: BlockParameter,
|
|
910
944
|
l1ToL2Message: Fr,
|
|
911
945
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
912
|
-
const db = await this.#getWorldState(
|
|
946
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
913
947
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
914
948
|
if (!witness) {
|
|
915
949
|
return undefined;
|
|
@@ -919,9 +953,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
919
953
|
return [witness.index, witness.path];
|
|
920
954
|
}
|
|
921
955
|
|
|
922
|
-
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<
|
|
956
|
+
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
923
957
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
924
|
-
return messageIndex
|
|
958
|
+
return messageIndex
|
|
959
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
960
|
+
: undefined;
|
|
925
961
|
}
|
|
926
962
|
|
|
927
963
|
/**
|
|
@@ -935,54 +971,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
935
971
|
}
|
|
936
972
|
|
|
937
973
|
/**
|
|
938
|
-
* Returns all the L2 to L1 messages in
|
|
939
|
-
* @param
|
|
940
|
-
* @returns The L2 to L1 messages (
|
|
941
|
-
*/
|
|
942
|
-
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
943
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
944
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
949
|
-
* @param blockNumber - The block number at which to get the data.
|
|
950
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
951
|
-
* @returns The sibling path.
|
|
974
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
975
|
+
* @param epoch - The epoch at which to get the data.
|
|
976
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
952
977
|
*/
|
|
953
|
-
public async
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
978
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
980
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
981
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
982
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
983
|
+
let checkpointIndex = -1;
|
|
984
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
985
|
+
const block = checkpointedBlock.block;
|
|
986
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
987
|
+
if (slotNumber !== previousSlotNumber) {
|
|
988
|
+
checkpointIndex++;
|
|
989
|
+
blocksInCheckpoints.push([]);
|
|
990
|
+
previousSlotNumber = slotNumber;
|
|
991
|
+
}
|
|
992
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
993
|
+
}
|
|
994
|
+
return blocksInCheckpoints.map(blocks =>
|
|
995
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
996
|
+
);
|
|
973
997
|
}
|
|
974
998
|
|
|
975
|
-
/**
|
|
976
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
977
|
-
* @param blockNumber - The block number at which to get the index.
|
|
978
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
979
|
-
* @returns The nullifier membership witness (if found).
|
|
980
|
-
*/
|
|
981
999
|
public async getNullifierMembershipWitness(
|
|
982
|
-
|
|
1000
|
+
referenceBlock: BlockParameter,
|
|
983
1001
|
nullifier: Fr,
|
|
984
1002
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
985
|
-
const db = await this.#getWorldState(
|
|
1003
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
986
1004
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
987
1005
|
if (!witness) {
|
|
988
1006
|
return undefined;
|
|
@@ -999,7 +1017,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
999
1017
|
|
|
1000
1018
|
/**
|
|
1001
1019
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1002
|
-
* @param
|
|
1020
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1021
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1003
1022
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1004
1023
|
* @returns The low nullifier membership witness (if found).
|
|
1005
1024
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1012,10 +1031,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1012
1031
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1013
1032
|
*/
|
|
1014
1033
|
public async getLowNullifierMembershipWitness(
|
|
1015
|
-
|
|
1034
|
+
referenceBlock: BlockParameter,
|
|
1016
1035
|
nullifier: Fr,
|
|
1017
1036
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1018
|
-
const committedDb = await this.#getWorldState(
|
|
1037
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1019
1038
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1020
1039
|
if (!findResult) {
|
|
1021
1040
|
return undefined;
|
|
@@ -1030,8 +1049,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1030
1049
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1031
1050
|
}
|
|
1032
1051
|
|
|
1033
|
-
async getPublicDataWitness(
|
|
1034
|
-
const committedDb = await this.#getWorldState(
|
|
1052
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1053
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1035
1054
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1036
1055
|
if (!lowLeafResult) {
|
|
1037
1056
|
return undefined;
|
|
@@ -1045,19 +1064,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1045
1064
|
}
|
|
1046
1065
|
}
|
|
1047
1066
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
*
|
|
1051
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1052
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1053
|
-
*
|
|
1054
|
-
* @param contract - Address of the contract to query.
|
|
1055
|
-
* @param slot - Slot to query.
|
|
1056
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1057
|
-
* @returns Storage value at the given contract slot.
|
|
1058
|
-
*/
|
|
1059
|
-
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1060
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1067
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1068
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1061
1069
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1062
1070
|
|
|
1063
1071
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1071,23 +1079,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1071
1079
|
return preimage.leaf.value;
|
|
1072
1080
|
}
|
|
1073
1081
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1082
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1083
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1084
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1085
|
+
if (block.equals(initialBlockHash)) {
|
|
1086
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1087
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1088
|
+
}
|
|
1089
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1090
|
+
} else {
|
|
1091
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1092
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1093
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1094
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1095
|
+
}
|
|
1096
|
+
return this.blockSource.getBlockHeader(block);
|
|
1097
|
+
}
|
|
1091
1098
|
}
|
|
1092
1099
|
|
|
1093
1100
|
/**
|
|
@@ -1122,7 +1129,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1122
1129
|
}
|
|
1123
1130
|
|
|
1124
1131
|
const txHash = tx.getTxHash();
|
|
1125
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1132
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1126
1133
|
|
|
1127
1134
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1128
1135
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1137,6 +1144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1137
1144
|
this.contractDataSource,
|
|
1138
1145
|
new DateProvider(),
|
|
1139
1146
|
this.telemetry,
|
|
1147
|
+
this.log.getBindings(),
|
|
1140
1148
|
);
|
|
1141
1149
|
|
|
1142
1150
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1145,6 +1153,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1145
1153
|
blockNumber,
|
|
1146
1154
|
});
|
|
1147
1155
|
|
|
1156
|
+
// Ensure world state is synced to the latest block before forking.
|
|
1157
|
+
// Without this, the fork may be behind the archiver, causing lookups
|
|
1158
|
+
// (e.g. L1-to-L2 message existence checks) to fail against stale state.
|
|
1159
|
+
await this.#syncWorldState();
|
|
1148
1160
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1149
1161
|
try {
|
|
1150
1162
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1152,8 +1164,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1152
1164
|
collectDebugLogs: true,
|
|
1153
1165
|
collectHints: false,
|
|
1154
1166
|
collectCallMetadata: true,
|
|
1155
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1156
1167
|
collectStatistics: false,
|
|
1168
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1169
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1170
|
+
}),
|
|
1157
1171
|
});
|
|
1158
1172
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1159
1173
|
|
|
@@ -1185,19 +1199,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1185
1199
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1186
1200
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1187
1201
|
|
|
1188
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1202
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1189
1203
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1190
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1191
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1204
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1205
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1206
|
+
db,
|
|
1207
|
+
this.contractDataSource,
|
|
1208
|
+
verifier,
|
|
1209
|
+
{
|
|
1210
|
+
timestamp: nextSlotTimestamp,
|
|
1211
|
+
blockNumber,
|
|
1212
|
+
l1ChainId: this.l1ChainId,
|
|
1213
|
+
rollupVersion: this.version,
|
|
1214
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1215
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1216
|
+
skipFeeEnforcement,
|
|
1217
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1218
|
+
},
|
|
1219
|
+
this.log.getBindings(),
|
|
1220
|
+
);
|
|
1201
1221
|
|
|
1202
1222
|
return await validator.validateTx(tx);
|
|
1203
1223
|
}
|
|
@@ -1266,7 +1286,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1266
1286
|
}
|
|
1267
1287
|
|
|
1268
1288
|
// And it has an L2 block hash
|
|
1269
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1289
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1270
1290
|
if (!l2BlockHash) {
|
|
1271
1291
|
this.metrics.recordSnapshotError();
|
|
1272
1292
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1294,13 +1314,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1294
1314
|
return Promise.resolve();
|
|
1295
1315
|
}
|
|
1296
1316
|
|
|
1297
|
-
public async rollbackTo(targetBlock:
|
|
1317
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1298
1318
|
const archiver = this.blockSource as Archiver;
|
|
1299
1319
|
if (!('rollbackTo' in archiver)) {
|
|
1300
1320
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1301
1321
|
}
|
|
1302
1322
|
|
|
1303
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1323
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1304
1324
|
if (targetBlock < finalizedBlock) {
|
|
1305
1325
|
if (force) {
|
|
1306
1326
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1361,17 +1381,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1361
1381
|
}
|
|
1362
1382
|
}
|
|
1363
1383
|
|
|
1384
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1385
|
+
if (!this.initialHeaderHashPromise) {
|
|
1386
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1387
|
+
}
|
|
1388
|
+
return this.initialHeaderHashPromise;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1364
1391
|
/**
|
|
1365
1392
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1366
|
-
* @param
|
|
1393
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1367
1394
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1368
1395
|
*/
|
|
1369
|
-
async #getWorldState(
|
|
1370
|
-
|
|
1371
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
let blockSyncedTo: number = 0;
|
|
1396
|
+
async #getWorldState(block: BlockParameter) {
|
|
1397
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1375
1398
|
try {
|
|
1376
1399
|
// Attempt to sync the world state if necessary
|
|
1377
1400
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1379,15 +1402,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1379
1402
|
this.log.error(`Error getting world state: ${err}`);
|
|
1380
1403
|
}
|
|
1381
1404
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1405
|
+
if (block === 'latest') {
|
|
1406
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1385
1407
|
return this.worldStateSynchronizer.getCommitted();
|
|
1386
|
-
}
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1411
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1412
|
+
if (block.equals(initialBlockHash)) {
|
|
1413
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1414
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1418
|
+
if (!header) {
|
|
1419
|
+
throw new Error(
|
|
1420
|
+
`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.`,
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
const blockNumber = header.getBlockNumber();
|
|
1424
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1425
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
// Block number provided
|
|
1429
|
+
{
|
|
1430
|
+
const blockNumber = block as BlockNumber;
|
|
1431
|
+
|
|
1432
|
+
if (blockNumber > blockSyncedTo) {
|
|
1433
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1387
1436
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1388
1437
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1389
|
-
} else {
|
|
1390
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1391
1438
|
}
|
|
1392
1439
|
}
|
|
1393
1440
|
|
|
@@ -1395,8 +1442,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1395
1442
|
* Ensure we fully sync the world state
|
|
1396
1443
|
* @returns A promise that fulfils once the world state is synced
|
|
1397
1444
|
*/
|
|
1398
|
-
async #syncWorldState(): Promise<
|
|
1445
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1399
1446
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1400
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1447
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1401
1448
|
}
|
|
1402
1449
|
}
|