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