@aztec/aztec-node 0.0.1-commit.d3ec352c → 0.0.1-commit.e3c1de76
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 +44 -116
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +608 -194
- 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 +5 -4
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +31 -26
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/aztec-node/config.ts +12 -8
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +289 -261
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +41 -32
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 { BlockNumber, 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,
|
|
@@ -48,14 +35,8 @@ import {
|
|
|
48
35
|
} from '@aztec/slasher';
|
|
49
36
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
50
37
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
51
|
-
import {
|
|
52
|
-
|
|
53
|
-
type DataInBlock,
|
|
54
|
-
type L2Block,
|
|
55
|
-
L2BlockHash,
|
|
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,
|
|
@@ -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
|
|
|
@@ -545,13 +559,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
545
559
|
}
|
|
546
560
|
|
|
547
561
|
/**
|
|
548
|
-
* Get a block specified by its number.
|
|
549
|
-
* @param
|
|
562
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
563
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
550
564
|
* @returns The requested block.
|
|
551
565
|
*/
|
|
552
|
-
public async getBlock(
|
|
553
|
-
|
|
554
|
-
|
|
566
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
567
|
+
if (BlockHash.isBlockHash(block)) {
|
|
568
|
+
return this.getBlockByHash(block);
|
|
569
|
+
}
|
|
570
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
571
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
572
|
+
return this.buildInitialBlock();
|
|
573
|
+
}
|
|
574
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
555
575
|
}
|
|
556
576
|
|
|
557
577
|
/**
|
|
@@ -559,9 +579,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
559
579
|
* @param blockHash - The block hash being requested.
|
|
560
580
|
* @returns The requested block.
|
|
561
581
|
*/
|
|
562
|
-
public async getBlockByHash(blockHash:
|
|
563
|
-
const
|
|
564
|
-
|
|
582
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
583
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
584
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
585
|
+
return this.buildInitialBlock();
|
|
586
|
+
}
|
|
587
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
private buildInitialBlock(): L2Block {
|
|
591
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
592
|
+
return L2Block.empty(initialHeader);
|
|
565
593
|
}
|
|
566
594
|
|
|
567
595
|
/**
|
|
@@ -570,8 +598,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
570
598
|
* @returns The requested block.
|
|
571
599
|
*/
|
|
572
600
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
573
|
-
|
|
574
|
-
return publishedBlock?.block;
|
|
601
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
575
602
|
}
|
|
576
603
|
|
|
577
604
|
/**
|
|
@@ -581,19 +608,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
608
|
* @returns The blocks requested.
|
|
582
609
|
*/
|
|
583
610
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
584
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
611
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
615
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
585
616
|
}
|
|
586
617
|
|
|
587
|
-
public async
|
|
588
|
-
return (await this.blockSource.
|
|
618
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
619
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
589
620
|
}
|
|
590
621
|
|
|
591
622
|
/**
|
|
592
|
-
* Method to fetch the current
|
|
593
|
-
* @returns The current
|
|
623
|
+
* Method to fetch the current min L2 fees.
|
|
624
|
+
* @returns The current min L2 fees.
|
|
594
625
|
*/
|
|
595
|
-
public async
|
|
596
|
-
return await this.globalVariableBuilder.
|
|
626
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
627
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
597
628
|
}
|
|
598
629
|
|
|
599
630
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -616,6 +647,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
647
|
return await this.blockSource.getProvenBlockNumber();
|
|
617
648
|
}
|
|
618
649
|
|
|
650
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
651
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
652
|
+
}
|
|
653
|
+
|
|
619
654
|
/**
|
|
620
655
|
* Method to fetch the version of the package.
|
|
621
656
|
* @returns The node package version
|
|
@@ -648,25 +683,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
648
683
|
return this.contractDataSource.getContract(address);
|
|
649
684
|
}
|
|
650
685
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
686
|
+
public async getPrivateLogsByTags(
|
|
687
|
+
tags: SiloedTag[],
|
|
688
|
+
page?: number,
|
|
689
|
+
referenceBlock?: BlockHash,
|
|
690
|
+
): Promise<TxScopedL2Log[][]> {
|
|
691
|
+
if (referenceBlock) {
|
|
692
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
693
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
694
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
695
|
+
if (!header) {
|
|
696
|
+
throw new Error(
|
|
697
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
public async getPublicLogsByTagsFromContract(
|
|
706
|
+
contractAddress: AztecAddress,
|
|
707
|
+
tags: Tag[],
|
|
708
|
+
page?: number,
|
|
709
|
+
referenceBlock?: BlockHash,
|
|
710
|
+
): Promise<TxScopedL2Log[][]> {
|
|
711
|
+
if (referenceBlock) {
|
|
712
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
713
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
714
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
715
|
+
if (!header) {
|
|
716
|
+
throw new Error(
|
|
717
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
670
723
|
}
|
|
671
724
|
|
|
672
725
|
/**
|
|
@@ -713,21 +766,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
713
766
|
}
|
|
714
767
|
|
|
715
768
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
721
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
722
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
723
|
-
}
|
|
769
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
770
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
771
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
772
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
724
773
|
|
|
774
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
725
775
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
776
|
+
|
|
726
777
|
if (settledTxReceipt) {
|
|
727
|
-
|
|
778
|
+
// If the archiver has the receipt then return it.
|
|
779
|
+
return settledTxReceipt;
|
|
780
|
+
} else if (isKnownToPool) {
|
|
781
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
782
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
783
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
784
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
785
|
+
} else {
|
|
786
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
787
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
728
788
|
}
|
|
729
|
-
|
|
730
|
-
return txReceipt;
|
|
731
789
|
}
|
|
732
790
|
|
|
733
791
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -747,10 +805,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
747
805
|
await tryStop(this.p2pClient);
|
|
748
806
|
await tryStop(this.worldStateSynchronizer);
|
|
749
807
|
await tryStop(this.blockSource);
|
|
808
|
+
await tryStop(this.blobClient);
|
|
750
809
|
await tryStop(this.telemetry);
|
|
751
810
|
this.log.info(`Stopped Aztec Node`);
|
|
752
811
|
}
|
|
753
812
|
|
|
813
|
+
/**
|
|
814
|
+
* Returns the blob client used by this node.
|
|
815
|
+
* @internal - Exposed for testing purposes only.
|
|
816
|
+
*/
|
|
817
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
818
|
+
return this.blobClient;
|
|
819
|
+
}
|
|
820
|
+
|
|
754
821
|
/**
|
|
755
822
|
* Method to retrieve pending txs.
|
|
756
823
|
* @param limit - The number of items to returns
|
|
@@ -783,20 +850,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
783
850
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
784
851
|
}
|
|
785
852
|
|
|
786
|
-
/**
|
|
787
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
788
|
-
* the leaves were inserted.
|
|
789
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
790
|
-
* @param treeId - The tree to search in.
|
|
791
|
-
* @param leafValues - The values to search for.
|
|
792
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
793
|
-
*/
|
|
794
853
|
public async findLeavesIndexes(
|
|
795
|
-
|
|
854
|
+
block: BlockParameter,
|
|
796
855
|
treeId: MerkleTreeId,
|
|
797
856
|
leafValues: Fr[],
|
|
798
857
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
799
|
-
const committedDb = await this.#getWorldState(
|
|
858
|
+
const committedDb = await this.#getWorldState(block);
|
|
800
859
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
801
860
|
treeId,
|
|
802
861
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -848,45 +907,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
848
907
|
}
|
|
849
908
|
return {
|
|
850
909
|
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
851
|
-
l2BlockHash:
|
|
910
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
852
911
|
data: index,
|
|
853
912
|
};
|
|
854
913
|
});
|
|
855
914
|
}
|
|
856
915
|
|
|
857
|
-
/**
|
|
858
|
-
* Returns a sibling path for the given index in the nullifier tree.
|
|
859
|
-
* @param blockNumber - The block number at which to get the data.
|
|
860
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
861
|
-
* @returns The sibling path for the leaf index.
|
|
862
|
-
*/
|
|
863
|
-
public async getNullifierSiblingPath(
|
|
864
|
-
blockNumber: BlockParameter,
|
|
865
|
-
leafIndex: bigint,
|
|
866
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
867
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
868
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* Returns a sibling path for the given index in the data tree.
|
|
873
|
-
* @param blockNumber - The block number at which to get the data.
|
|
874
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
875
|
-
* @returns The sibling path for the leaf index.
|
|
876
|
-
*/
|
|
877
|
-
public async getNoteHashSiblingPath(
|
|
878
|
-
blockNumber: BlockParameter,
|
|
879
|
-
leafIndex: bigint,
|
|
880
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
881
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
882
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
883
|
-
}
|
|
884
|
-
|
|
885
916
|
public async getArchiveMembershipWitness(
|
|
886
|
-
|
|
917
|
+
block: BlockParameter,
|
|
887
918
|
archive: Fr,
|
|
888
919
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
889
|
-
const committedDb = await this.#getWorldState(
|
|
920
|
+
const committedDb = await this.#getWorldState(block);
|
|
890
921
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
|
|
891
922
|
return pathAndIndex === undefined
|
|
892
923
|
? undefined
|
|
@@ -894,10 +925,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
894
925
|
}
|
|
895
926
|
|
|
896
927
|
public async getNoteHashMembershipWitness(
|
|
897
|
-
|
|
928
|
+
block: BlockParameter,
|
|
898
929
|
noteHash: Fr,
|
|
899
930
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
900
|
-
const committedDb = await this.#getWorldState(
|
|
931
|
+
const committedDb = await this.#getWorldState(block);
|
|
901
932
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
902
933
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
903
934
|
[noteHash],
|
|
@@ -907,17 +938,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
907
938
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
908
939
|
}
|
|
909
940
|
|
|
910
|
-
/**
|
|
911
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
912
|
-
* @param blockNumber - The block number at which to get the data.
|
|
913
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
914
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
915
|
-
*/
|
|
916
941
|
public async getL1ToL2MessageMembershipWitness(
|
|
917
|
-
|
|
942
|
+
block: BlockParameter,
|
|
918
943
|
l1ToL2Message: Fr,
|
|
919
944
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
920
|
-
const db = await this.#getWorldState(
|
|
945
|
+
const db = await this.#getWorldState(block);
|
|
921
946
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
922
947
|
if (!witness) {
|
|
923
948
|
return undefined;
|
|
@@ -929,7 +954,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
929
954
|
|
|
930
955
|
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
931
956
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
932
|
-
return messageIndex
|
|
957
|
+
return messageIndex
|
|
958
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
959
|
+
: undefined;
|
|
933
960
|
}
|
|
934
961
|
|
|
935
962
|
/**
|
|
@@ -943,56 +970,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
943
970
|
}
|
|
944
971
|
|
|
945
972
|
/**
|
|
946
|
-
* Returns all the L2 to L1 messages in
|
|
947
|
-
* @param
|
|
948
|
-
* @returns The L2 to L1 messages (
|
|
973
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
974
|
+
* @param epoch - The epoch at which to get the data.
|
|
975
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
949
976
|
*/
|
|
950
|
-
public async getL2ToL1Messages(
|
|
951
|
-
|
|
952
|
-
|
|
977
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
978
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
979
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
980
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
981
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
982
|
+
let checkpointIndex = -1;
|
|
983
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
984
|
+
const block = checkpointedBlock.block;
|
|
985
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
|
+
if (slotNumber !== previousSlotNumber) {
|
|
987
|
+
checkpointIndex++;
|
|
988
|
+
blocksInCheckpoints.push([]);
|
|
989
|
+
previousSlotNumber = slotNumber;
|
|
990
|
+
}
|
|
991
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
992
|
+
}
|
|
993
|
+
return blocksInCheckpoints.map(blocks =>
|
|
994
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
953
995
|
);
|
|
954
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/**
|
|
958
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
959
|
-
* @param blockNumber - The block number at which to get the data.
|
|
960
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
961
|
-
* @returns The sibling path.
|
|
962
|
-
*/
|
|
963
|
-
public async getArchiveSiblingPath(
|
|
964
|
-
blockNumber: BlockParameter,
|
|
965
|
-
leafIndex: bigint,
|
|
966
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
967
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
968
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
969
996
|
}
|
|
970
997
|
|
|
971
|
-
/**
|
|
972
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
973
|
-
* @param blockNumber - The block number at which to get the data.
|
|
974
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
975
|
-
* @returns The sibling path.
|
|
976
|
-
*/
|
|
977
|
-
public async getPublicDataSiblingPath(
|
|
978
|
-
blockNumber: BlockParameter,
|
|
979
|
-
leafIndex: bigint,
|
|
980
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
981
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
982
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
/**
|
|
986
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
987
|
-
* @param blockNumber - The block number at which to get the index.
|
|
988
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
989
|
-
* @returns The nullifier membership witness (if found).
|
|
990
|
-
*/
|
|
991
998
|
public async getNullifierMembershipWitness(
|
|
992
|
-
|
|
999
|
+
block: BlockParameter,
|
|
993
1000
|
nullifier: Fr,
|
|
994
1001
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
995
|
-
const db = await this.#getWorldState(
|
|
1002
|
+
const db = await this.#getWorldState(block);
|
|
996
1003
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
997
1004
|
if (!witness) {
|
|
998
1005
|
return undefined;
|
|
@@ -1009,7 +1016,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1009
1016
|
|
|
1010
1017
|
/**
|
|
1011
1018
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1012
|
-
* @param
|
|
1019
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1013
1020
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1014
1021
|
* @returns The low nullifier membership witness (if found).
|
|
1015
1022
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1022,10 +1029,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1022
1029
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1023
1030
|
*/
|
|
1024
1031
|
public async getLowNullifierMembershipWitness(
|
|
1025
|
-
|
|
1032
|
+
block: BlockParameter,
|
|
1026
1033
|
nullifier: Fr,
|
|
1027
1034
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1028
|
-
const committedDb = await this.#getWorldState(
|
|
1035
|
+
const committedDb = await this.#getWorldState(block);
|
|
1029
1036
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1030
1037
|
if (!findResult) {
|
|
1031
1038
|
return undefined;
|
|
@@ -1040,8 +1047,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1040
1047
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1041
1048
|
}
|
|
1042
1049
|
|
|
1043
|
-
async getPublicDataWitness(
|
|
1044
|
-
const committedDb = await this.#getWorldState(
|
|
1050
|
+
async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1051
|
+
const committedDb = await this.#getWorldState(block);
|
|
1045
1052
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1046
1053
|
if (!lowLeafResult) {
|
|
1047
1054
|
return undefined;
|
|
@@ -1055,19 +1062,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1055
1062
|
}
|
|
1056
1063
|
}
|
|
1057
1064
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
*
|
|
1061
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1062
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1063
|
-
*
|
|
1064
|
-
* @param contract - Address of the contract to query.
|
|
1065
|
-
* @param slot - Slot to query.
|
|
1066
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1067
|
-
* @returns Storage value at the given contract slot.
|
|
1068
|
-
*/
|
|
1069
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1070
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1065
|
+
public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1066
|
+
const committedDb = await this.#getWorldState(block);
|
|
1071
1067
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1072
1068
|
|
|
1073
1069
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1081,24 +1077,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1081
1077
|
return preimage.leaf.value;
|
|
1082
1078
|
}
|
|
1083
1079
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1101
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1080
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1081
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1082
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1083
|
+
if (block.equals(initialBlockHash)) {
|
|
1084
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1085
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1086
|
+
}
|
|
1087
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1088
|
+
} else {
|
|
1089
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1090
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1091
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1092
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1093
|
+
}
|
|
1094
|
+
return this.blockSource.getBlockHeader(block);
|
|
1095
|
+
}
|
|
1102
1096
|
}
|
|
1103
1097
|
|
|
1104
1098
|
/**
|
|
@@ -1148,6 +1142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1148
1142
|
this.contractDataSource,
|
|
1149
1143
|
new DateProvider(),
|
|
1150
1144
|
this.telemetry,
|
|
1145
|
+
this.log.getBindings(),
|
|
1151
1146
|
);
|
|
1152
1147
|
|
|
1153
1148
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1201,16 +1196,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1201
1196
|
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1202
1197
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1203
1198
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1204
|
-
const validator = createValidatorForAcceptingTxs(
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1199
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1200
|
+
db,
|
|
1201
|
+
this.contractDataSource,
|
|
1202
|
+
verifier,
|
|
1203
|
+
{
|
|
1204
|
+
timestamp: nextSlotTimestamp,
|
|
1205
|
+
blockNumber,
|
|
1206
|
+
l1ChainId: this.l1ChainId,
|
|
1207
|
+
rollupVersion: this.version,
|
|
1208
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1209
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1210
|
+
skipFeeEnforcement,
|
|
1211
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1212
|
+
},
|
|
1213
|
+
this.log.getBindings(),
|
|
1214
|
+
);
|
|
1214
1215
|
|
|
1215
1216
|
return await validator.validateTx(tx);
|
|
1216
1217
|
}
|
|
@@ -1279,7 +1280,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1279
1280
|
}
|
|
1280
1281
|
|
|
1281
1282
|
// And it has an L2 block hash
|
|
1282
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1283
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1283
1284
|
if (!l2BlockHash) {
|
|
1284
1285
|
this.metrics.recordSnapshotError();
|
|
1285
1286
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1313,7 +1314,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1313
1314
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1314
1315
|
}
|
|
1315
1316
|
|
|
1316
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1317
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1317
1318
|
if (targetBlock < finalizedBlock) {
|
|
1318
1319
|
if (force) {
|
|
1319
1320
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1374,16 +1375,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1374
1375
|
}
|
|
1375
1376
|
}
|
|
1376
1377
|
|
|
1378
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1379
|
+
if (!this.initialHeaderHashPromise) {
|
|
1380
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1381
|
+
}
|
|
1382
|
+
return this.initialHeaderHashPromise;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1377
1385
|
/**
|
|
1378
1386
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1379
|
-
* @param
|
|
1387
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1380
1388
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1381
1389
|
*/
|
|
1382
|
-
async #getWorldState(
|
|
1383
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1384
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1390
|
+
async #getWorldState(block: BlockParameter) {
|
|
1387
1391
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1388
1392
|
try {
|
|
1389
1393
|
// Attempt to sync the world state if necessary
|
|
@@ -1392,15 +1396,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1392
1396
|
this.log.error(`Error getting world state: ${err}`);
|
|
1393
1397
|
}
|
|
1394
1398
|
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1399
|
+
if (block === 'latest') {
|
|
1400
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1398
1401
|
return this.worldStateSynchronizer.getCommitted();
|
|
1399
|
-
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1405
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1406
|
+
if (block.equals(initialBlockHash)) {
|
|
1407
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1408
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1412
|
+
if (!header) {
|
|
1413
|
+
throw new Error(
|
|
1414
|
+
`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.`,
|
|
1415
|
+
);
|
|
1416
|
+
}
|
|
1417
|
+
const blockNumber = header.getBlockNumber();
|
|
1400
1418
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1401
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1419
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// Block number provided
|
|
1423
|
+
{
|
|
1424
|
+
const blockNumber = block as BlockNumber;
|
|
1425
|
+
|
|
1426
|
+
if (blockNumber > blockSyncedTo) {
|
|
1427
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1431
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1404
1432
|
}
|
|
1405
1433
|
}
|
|
1406
1434
|
|