@aztec/aztec-node 0.0.1-commit.b655e406 → 0.0.1-commit.c2595eba
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 +55 -122
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +644 -202
- 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 +332 -251
- 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,36 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type
|
|
3
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
4
|
import {
|
|
5
5
|
ARCHIVE_HEIGHT,
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
6
|
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
7
|
type NOTE_HASH_TREE_HEIGHT,
|
|
9
8
|
type NULLIFIER_TREE_HEIGHT,
|
|
10
9
|
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
10
|
} from '@aztec/constants';
|
|
12
11
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
getPublicClient,
|
|
19
|
-
} from '@aztec/ethereum';
|
|
12
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
13
|
+
import { getPublicClient } from '@aztec/ethereum/client';
|
|
14
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
15
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
16
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
20
17
|
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
18
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
21
19
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
22
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
23
20
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
24
21
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
25
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
26
22
|
import { count } from '@aztec/foundation/string';
|
|
27
23
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
28
24
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
25
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
26
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
31
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
createForwarderL1TxUtilsFromEthSigner,
|
|
29
|
+
createL1TxUtilsWithBlobsFromEthSigner,
|
|
30
|
+
} from '@aztec/node-lib/factories';
|
|
32
31
|
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
32
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
import {
|
|
35
|
-
BlockBuilder,
|
|
36
|
-
GlobalVariableBuilder,
|
|
37
|
-
SequencerClient,
|
|
38
|
-
type SequencerPublisher,
|
|
39
|
-
createValidatorForAcceptingTxs,
|
|
40
|
-
} from '@aztec/sequencer-client';
|
|
33
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
41
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
42
35
|
import {
|
|
43
36
|
AttestationsBlockWatcher,
|
|
@@ -46,15 +39,10 @@ import {
|
|
|
46
39
|
type Watcher,
|
|
47
40
|
createSlasher,
|
|
48
41
|
} from '@aztec/slasher';
|
|
42
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
49
43
|
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';
|
|
44
|
+
import { BlockHash, type BlockParameter, type DataInBlock, L2Block, type L2BlockSource } from '@aztec/stdlib/block';
|
|
45
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
58
46
|
import type {
|
|
59
47
|
ContractClassPublic,
|
|
60
48
|
ContractDataSource,
|
|
@@ -62,7 +50,7 @@ import type {
|
|
|
62
50
|
NodeInfo,
|
|
63
51
|
ProtocolContractAddresses,
|
|
64
52
|
} from '@aztec/stdlib/contract';
|
|
65
|
-
import
|
|
53
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
66
54
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
67
55
|
import {
|
|
68
56
|
type AztecNode,
|
|
@@ -81,7 +69,7 @@ import {
|
|
|
81
69
|
type WorldStateSynchronizer,
|
|
82
70
|
tryStop,
|
|
83
71
|
} from '@aztec/stdlib/interfaces/server';
|
|
84
|
-
import type { LogFilter,
|
|
72
|
+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
85
73
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
86
74
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
87
75
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -109,10 +97,13 @@ import {
|
|
|
109
97
|
trackSpan,
|
|
110
98
|
} from '@aztec/telemetry-client';
|
|
111
99
|
import {
|
|
100
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
101
|
+
FullNodeCheckpointsBuilder,
|
|
112
102
|
NodeKeystoreAdapter,
|
|
113
103
|
ValidatorClient,
|
|
114
104
|
createBlockProposalHandler,
|
|
115
105
|
createValidatorClient,
|
|
106
|
+
createValidatorForAcceptingTxs,
|
|
116
107
|
} from '@aztec/validator-client';
|
|
117
108
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
109
|
|
|
@@ -128,13 +119,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
119
|
*/
|
|
129
120
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
121
|
private metrics: NodeMetrics;
|
|
122
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
123
|
|
|
132
124
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
125
|
private isUploadingSnapshot = false;
|
|
134
126
|
|
|
135
|
-
// Serial queue to ensure that we only send one tx at a time
|
|
136
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
137
|
-
|
|
138
127
|
public readonly tracer: Tracer;
|
|
139
128
|
|
|
140
129
|
constructor(
|
|
@@ -157,10 +146,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
157
146
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
158
147
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
159
148
|
private log = createLogger('node'),
|
|
149
|
+
private blobClient?: BlobClientInterface,
|
|
160
150
|
) {
|
|
161
151
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
162
152
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
163
|
-
this.txQueue.start();
|
|
164
153
|
|
|
165
154
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
166
155
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
@@ -187,7 +176,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
187
176
|
logger?: Logger;
|
|
188
177
|
publisher?: SequencerPublisher;
|
|
189
178
|
dateProvider?: DateProvider;
|
|
190
|
-
blobSinkClient?: BlobSinkClientInterface;
|
|
191
179
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
192
180
|
} = {},
|
|
193
181
|
options: {
|
|
@@ -200,8 +188,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
200
188
|
const packageVersion = getPackageVersion() ?? '';
|
|
201
189
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
202
190
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
203
|
-
const blobSinkClient =
|
|
204
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
205
191
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
206
192
|
|
|
207
193
|
// Build a key store from file if given or from environment otherwise
|
|
@@ -241,7 +227,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
241
227
|
|
|
242
228
|
const publicClient = createPublicClient({
|
|
243
229
|
chain: ethereumChain.chainInfo,
|
|
244
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
230
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
245
231
|
pollingInterval: config.viemPollingIntervalMS,
|
|
246
232
|
});
|
|
247
233
|
|
|
@@ -269,6 +255,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
269
255
|
);
|
|
270
256
|
}
|
|
271
257
|
|
|
258
|
+
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
259
|
+
|
|
272
260
|
// attempt snapshot sync if possible
|
|
273
261
|
await trySnapshotSync(config, log);
|
|
274
262
|
|
|
@@ -276,7 +264,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
276
264
|
|
|
277
265
|
const archiver = await createArchiver(
|
|
278
266
|
config,
|
|
279
|
-
{
|
|
267
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
280
268
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
281
269
|
);
|
|
282
270
|
|
|
@@ -287,7 +275,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
275
|
options.prefilledPublicData,
|
|
288
276
|
telemetry,
|
|
289
277
|
);
|
|
290
|
-
const circuitVerifier =
|
|
278
|
+
const circuitVerifier =
|
|
279
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
280
|
+
? await BBCircuitVerifier.new(config)
|
|
281
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
291
282
|
if (!config.realProofs) {
|
|
292
283
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
293
284
|
}
|
|
@@ -310,7 +301,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
310
301
|
// We should really not be modifying the config object
|
|
311
302
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
312
303
|
|
|
313
|
-
|
|
304
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
305
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
314
306
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
307
|
worldStateSynchronizer,
|
|
316
308
|
archiver,
|
|
@@ -322,15 +314,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
322
314
|
const watchers: Watcher[] = [];
|
|
323
315
|
|
|
324
316
|
// Create validator client if required
|
|
325
|
-
const validatorClient = createValidatorClient(config, {
|
|
317
|
+
const validatorClient = await createValidatorClient(config, {
|
|
318
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
319
|
+
worldState: worldStateSynchronizer,
|
|
326
320
|
p2pClient,
|
|
327
321
|
telemetry,
|
|
328
322
|
dateProvider,
|
|
329
323
|
epochCache,
|
|
330
|
-
blockBuilder,
|
|
331
324
|
blockSource: archiver,
|
|
332
325
|
l1ToL2MessageSource: archiver,
|
|
333
326
|
keyStoreManager,
|
|
327
|
+
blobClient,
|
|
334
328
|
});
|
|
335
329
|
|
|
336
330
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -348,7 +342,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
348
342
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
349
343
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
350
344
|
createBlockProposalHandler(config, {
|
|
351
|
-
|
|
345
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
346
|
+
worldState: worldStateSynchronizer,
|
|
352
347
|
epochCache,
|
|
353
348
|
blockSource: archiver,
|
|
354
349
|
l1ToL2MessageSource: archiver,
|
|
@@ -376,7 +371,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
376
371
|
archiver,
|
|
377
372
|
epochCache,
|
|
378
373
|
p2pClient.getTxProvider(),
|
|
379
|
-
|
|
374
|
+
validatorCheckpointsBuilder,
|
|
380
375
|
config,
|
|
381
376
|
);
|
|
382
377
|
watchers.push(epochPruneWatcher);
|
|
@@ -404,7 +399,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
404
399
|
// Validator enabled, create/start relevant service
|
|
405
400
|
let sequencer: SequencerClient | undefined;
|
|
406
401
|
let slasherClient: SlasherClientInterface | undefined;
|
|
407
|
-
if (!config.disableValidator) {
|
|
402
|
+
if (!config.disableValidator && validatorClient) {
|
|
408
403
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
409
404
|
// as they are executed when the node is selected as proposer.
|
|
410
405
|
const validatorAddresses = keyStoreManager
|
|
@@ -423,14 +418,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
423
418
|
);
|
|
424
419
|
await slasherClient.start();
|
|
425
420
|
|
|
426
|
-
const l1TxUtils =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
421
|
+
const l1TxUtils = config.publisherForwarderAddress
|
|
422
|
+
? await createForwarderL1TxUtilsFromEthSigner(
|
|
423
|
+
publicClient,
|
|
424
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
425
|
+
config.publisherForwarderAddress,
|
|
426
|
+
{ ...config, scope: 'sequencer' },
|
|
427
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
428
|
+
)
|
|
429
|
+
: await createL1TxUtilsWithBlobsFromEthSigner(
|
|
430
|
+
publicClient,
|
|
431
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
+
{ ...config, scope: 'sequencer' },
|
|
433
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
434
|
+
);
|
|
432
435
|
|
|
433
436
|
// Create and start the sequencer client
|
|
437
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
438
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
439
|
+
worldStateSynchronizer,
|
|
440
|
+
archiver,
|
|
441
|
+
dateProvider,
|
|
442
|
+
telemetry,
|
|
443
|
+
);
|
|
444
|
+
|
|
434
445
|
sequencer = await SequencerClient.new(config, {
|
|
435
446
|
...deps,
|
|
436
447
|
epochCache,
|
|
@@ -439,12 +450,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
439
450
|
p2pClient,
|
|
440
451
|
worldStateSynchronizer,
|
|
441
452
|
slasherClient,
|
|
442
|
-
|
|
453
|
+
checkpointsBuilder,
|
|
443
454
|
l2BlockSource: archiver,
|
|
444
455
|
l1ToL2MessageSource: archiver,
|
|
445
456
|
telemetry,
|
|
446
457
|
dateProvider,
|
|
447
|
-
|
|
458
|
+
blobClient,
|
|
448
459
|
nodeKeyStore: keyStoreManager!,
|
|
449
460
|
});
|
|
450
461
|
}
|
|
@@ -456,6 +467,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
456
467
|
log.warn(`Sequencer created but not started`);
|
|
457
468
|
}
|
|
458
469
|
|
|
470
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
471
|
+
...config,
|
|
472
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
473
|
+
l1GenesisTime,
|
|
474
|
+
slotDuration: Number(slotDuration),
|
|
475
|
+
});
|
|
476
|
+
|
|
459
477
|
return new AztecNodeService(
|
|
460
478
|
config,
|
|
461
479
|
p2pClient,
|
|
@@ -470,12 +488,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
470
488
|
epochPruneWatcher,
|
|
471
489
|
ethereumChain.chainInfo.id,
|
|
472
490
|
config.rollupVersion,
|
|
473
|
-
|
|
491
|
+
globalVariableBuilder,
|
|
474
492
|
epochCache,
|
|
475
493
|
packageVersion,
|
|
476
494
|
proofVerifier,
|
|
477
495
|
telemetry,
|
|
478
496
|
log,
|
|
497
|
+
blobClient,
|
|
479
498
|
);
|
|
480
499
|
}
|
|
481
500
|
|
|
@@ -546,13 +565,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
546
565
|
}
|
|
547
566
|
|
|
548
567
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
568
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
569
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
570
|
* @returns The requested block.
|
|
552
571
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
572
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
573
|
+
if (BlockHash.isBlockHash(block)) {
|
|
574
|
+
return this.getBlockByHash(block);
|
|
575
|
+
}
|
|
576
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
577
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
578
|
+
return this.buildInitialBlock();
|
|
579
|
+
}
|
|
580
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
556
581
|
}
|
|
557
582
|
|
|
558
583
|
/**
|
|
@@ -560,9 +585,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
585
|
* @param blockHash - The block hash being requested.
|
|
561
586
|
* @returns The requested block.
|
|
562
587
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash:
|
|
564
|
-
const
|
|
565
|
-
|
|
588
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
589
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
590
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
591
|
+
return this.buildInitialBlock();
|
|
592
|
+
}
|
|
593
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
private buildInitialBlock(): L2Block {
|
|
597
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
598
|
+
return L2Block.empty(initialHeader);
|
|
566
599
|
}
|
|
567
600
|
|
|
568
601
|
/**
|
|
@@ -571,8 +604,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
571
604
|
* @returns The requested block.
|
|
572
605
|
*/
|
|
573
606
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
607
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
576
608
|
}
|
|
577
609
|
|
|
578
610
|
/**
|
|
@@ -581,34 +613,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
613
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
614
|
* @returns The blocks requested.
|
|
583
615
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
616
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
617
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
621
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
586
622
|
}
|
|
587
623
|
|
|
588
|
-
public async
|
|
589
|
-
return (await this.blockSource.
|
|
624
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
625
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
590
626
|
}
|
|
591
627
|
|
|
592
628
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
629
|
+
* Method to fetch the current min L2 fees.
|
|
630
|
+
* @returns The current min L2 fees.
|
|
595
631
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
632
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
633
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
637
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
638
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
642
|
}
|
|
599
643
|
|
|
600
644
|
/**
|
|
601
645
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
646
|
* @returns The block number.
|
|
603
647
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
648
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
649
|
return await this.blockSource.getBlockNumber();
|
|
606
650
|
}
|
|
607
651
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
652
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
653
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
654
|
}
|
|
611
655
|
|
|
656
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
657
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
658
|
+
}
|
|
659
|
+
|
|
612
660
|
/**
|
|
613
661
|
* Method to fetch the version of the package.
|
|
614
662
|
* @returns The node package version
|
|
@@ -641,25 +689,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
689
|
return this.contractDataSource.getContract(address);
|
|
642
690
|
}
|
|
643
691
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
692
|
+
public async getPrivateLogsByTags(
|
|
693
|
+
tags: SiloedTag[],
|
|
694
|
+
page?: number,
|
|
695
|
+
referenceBlock?: BlockHash,
|
|
696
|
+
): Promise<TxScopedL2Log[][]> {
|
|
697
|
+
if (referenceBlock) {
|
|
698
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
699
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
700
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
701
|
+
if (!header) {
|
|
702
|
+
throw new Error(
|
|
703
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
public async getPublicLogsByTagsFromContract(
|
|
712
|
+
contractAddress: AztecAddress,
|
|
713
|
+
tags: Tag[],
|
|
714
|
+
page?: number,
|
|
715
|
+
referenceBlock?: BlockHash,
|
|
716
|
+
): Promise<TxScopedL2Log[][]> {
|
|
717
|
+
if (referenceBlock) {
|
|
718
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
719
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
720
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
721
|
+
if (!header) {
|
|
722
|
+
throw new Error(
|
|
723
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
663
729
|
}
|
|
664
730
|
|
|
665
731
|
/**
|
|
@@ -685,7 +751,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
751
|
* @param tx - The transaction to be submitted.
|
|
686
752
|
*/
|
|
687
753
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
754
|
+
await this.#sendTx(tx);
|
|
689
755
|
}
|
|
690
756
|
|
|
691
757
|
async #sendTx(tx: Tx) {
|
|
@@ -706,21 +772,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
706
772
|
}
|
|
707
773
|
|
|
708
774
|
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
|
-
}
|
|
775
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
776
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
777
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
778
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
779
|
|
|
780
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
781
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
782
|
+
|
|
719
783
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
784
|
+
// If the archiver has the receipt then return it.
|
|
785
|
+
return settledTxReceipt;
|
|
786
|
+
} else if (isKnownToPool) {
|
|
787
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
788
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
789
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
790
|
+
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
791
|
+
} else {
|
|
792
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
793
|
+
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
721
794
|
}
|
|
722
|
-
|
|
723
|
-
return txReceipt;
|
|
724
795
|
}
|
|
725
796
|
|
|
726
797
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,7 +803,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
803
|
*/
|
|
733
804
|
public async stop() {
|
|
734
805
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
806
|
await tryStop(this.validatorsSentinel);
|
|
737
807
|
await tryStop(this.epochPruneWatcher);
|
|
738
808
|
await tryStop(this.slasherClient);
|
|
@@ -741,10 +811,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
741
811
|
await tryStop(this.p2pClient);
|
|
742
812
|
await tryStop(this.worldStateSynchronizer);
|
|
743
813
|
await tryStop(this.blockSource);
|
|
814
|
+
await tryStop(this.blobClient);
|
|
744
815
|
await tryStop(this.telemetry);
|
|
745
816
|
this.log.info(`Stopped Aztec Node`);
|
|
746
817
|
}
|
|
747
818
|
|
|
819
|
+
/**
|
|
820
|
+
* Returns the blob client used by this node.
|
|
821
|
+
* @internal - Exposed for testing purposes only.
|
|
822
|
+
*/
|
|
823
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
824
|
+
return this.blobClient;
|
|
825
|
+
}
|
|
826
|
+
|
|
748
827
|
/**
|
|
749
828
|
* Method to retrieve pending txs.
|
|
750
829
|
* @param limit - The number of items to returns
|
|
@@ -777,20 +856,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
856
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
857
|
}
|
|
779
858
|
|
|
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
859
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
860
|
+
block: BlockParameter,
|
|
790
861
|
treeId: MerkleTreeId,
|
|
791
862
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this.#getWorldState(
|
|
863
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
864
|
+
const committedDb = await this.#getWorldState(block);
|
|
794
865
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
866
|
treeId,
|
|
796
867
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -815,7 +886,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
815
886
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
816
887
|
const blockHashes = await Promise.all(
|
|
817
888
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
889
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
890
|
}),
|
|
820
891
|
);
|
|
821
892
|
|
|
@@ -826,7 +897,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
897
|
}
|
|
827
898
|
}
|
|
828
899
|
|
|
829
|
-
// Create
|
|
900
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
830
901
|
return maybeIndices.map((index, i) => {
|
|
831
902
|
if (index === undefined) {
|
|
832
903
|
return undefined;
|
|
@@ -841,46 +912,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
841
912
|
return undefined;
|
|
842
913
|
}
|
|
843
914
|
return {
|
|
844
|
-
l2BlockNumber: Number(blockNumber),
|
|
845
|
-
l2BlockHash:
|
|
915
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
916
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
846
917
|
data: index,
|
|
847
918
|
};
|
|
848
919
|
});
|
|
849
920
|
}
|
|
850
921
|
|
|
851
|
-
/**
|
|
852
|
-
* Returns a sibling path for the given index in the nullifier tree.
|
|
853
|
-
* @param blockNumber - The block number at which to get the data.
|
|
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
922
|
public async getNullifierSiblingPath(
|
|
858
|
-
|
|
923
|
+
block: BlockParameter,
|
|
859
924
|
leafIndex: bigint,
|
|
860
925
|
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
861
|
-
const committedDb = await this.#getWorldState(
|
|
926
|
+
const committedDb = await this.#getWorldState(block);
|
|
862
927
|
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
863
928
|
}
|
|
864
929
|
|
|
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
930
|
public async getNoteHashSiblingPath(
|
|
872
|
-
|
|
931
|
+
block: BlockParameter,
|
|
873
932
|
leafIndex: bigint,
|
|
874
933
|
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
875
|
-
const committedDb = await this.#getWorldState(
|
|
934
|
+
const committedDb = await this.#getWorldState(block);
|
|
876
935
|
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
877
936
|
}
|
|
878
937
|
|
|
879
938
|
public async getArchiveMembershipWitness(
|
|
880
|
-
|
|
939
|
+
block: BlockParameter,
|
|
881
940
|
archive: Fr,
|
|
882
941
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
const committedDb = await this.#getWorldState(
|
|
942
|
+
const committedDb = await this.#getWorldState(block);
|
|
884
943
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
|
|
885
944
|
return pathAndIndex === undefined
|
|
886
945
|
? undefined
|
|
@@ -888,10 +947,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
888
947
|
}
|
|
889
948
|
|
|
890
949
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
950
|
+
block: BlockParameter,
|
|
892
951
|
noteHash: Fr,
|
|
893
952
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this.#getWorldState(
|
|
953
|
+
const committedDb = await this.#getWorldState(block);
|
|
895
954
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
955
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
956
|
[noteHash],
|
|
@@ -901,17 +960,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
960
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
961
|
}
|
|
903
962
|
|
|
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
963
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
964
|
+
block: BlockParameter,
|
|
912
965
|
l1ToL2Message: Fr,
|
|
913
966
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this.#getWorldState(
|
|
967
|
+
const db = await this.#getWorldState(block);
|
|
915
968
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
969
|
if (!witness) {
|
|
917
970
|
return undefined;
|
|
@@ -921,9 +974,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
974
|
return [witness.index, witness.path];
|
|
922
975
|
}
|
|
923
976
|
|
|
924
|
-
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<
|
|
977
|
+
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
925
978
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex
|
|
979
|
+
return messageIndex
|
|
980
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
981
|
+
: undefined;
|
|
927
982
|
}
|
|
928
983
|
|
|
929
984
|
/**
|
|
@@ -937,54 +992,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
992
|
}
|
|
938
993
|
|
|
939
994
|
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in
|
|
941
|
-
* @param
|
|
942
|
-
* @returns The L2 to L1 messages (
|
|
995
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
996
|
+
* @param epoch - The epoch at which to get the data.
|
|
997
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
943
998
|
*/
|
|
944
|
-
public async getL2ToL1Messages(
|
|
945
|
-
|
|
946
|
-
|
|
999
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1000
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1001
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1002
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
1003
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1004
|
+
let checkpointIndex = -1;
|
|
1005
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1006
|
+
const block = checkpointedBlock.block;
|
|
1007
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1008
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1009
|
+
checkpointIndex++;
|
|
1010
|
+
blocksInCheckpoints.push([]);
|
|
1011
|
+
previousSlotNumber = slotNumber;
|
|
1012
|
+
}
|
|
1013
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1014
|
+
}
|
|
1015
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1016
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1017
|
+
);
|
|
947
1018
|
}
|
|
948
1019
|
|
|
949
|
-
/**
|
|
950
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
951
|
-
* @param blockNumber - The block number at which to get the data.
|
|
952
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
953
|
-
* @returns The sibling path.
|
|
954
|
-
*/
|
|
955
1020
|
public async getArchiveSiblingPath(
|
|
956
|
-
|
|
1021
|
+
block: BlockParameter,
|
|
957
1022
|
leafIndex: bigint,
|
|
958
1023
|
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
959
|
-
const committedDb = await this.#getWorldState(
|
|
1024
|
+
const committedDb = await this.#getWorldState(block);
|
|
960
1025
|
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
961
1026
|
}
|
|
962
1027
|
|
|
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
1028
|
public async getPublicDataSiblingPath(
|
|
970
|
-
|
|
1029
|
+
block: BlockParameter,
|
|
971
1030
|
leafIndex: bigint,
|
|
972
1031
|
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
973
|
-
const committedDb = await this.#getWorldState(
|
|
1032
|
+
const committedDb = await this.#getWorldState(block);
|
|
974
1033
|
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
975
1034
|
}
|
|
976
1035
|
|
|
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
1036
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1037
|
+
block: BlockParameter,
|
|
985
1038
|
nullifier: Fr,
|
|
986
1039
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this.#getWorldState(
|
|
1040
|
+
const db = await this.#getWorldState(block);
|
|
988
1041
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1042
|
if (!witness) {
|
|
990
1043
|
return undefined;
|
|
@@ -1001,7 +1054,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1054
|
|
|
1002
1055
|
/**
|
|
1003
1056
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param
|
|
1057
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1005
1058
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
1059
|
* @returns The low nullifier membership witness (if found).
|
|
1007
1060
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1014,10 +1067,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1067
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
1068
|
*/
|
|
1016
1069
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1070
|
+
block: BlockParameter,
|
|
1018
1071
|
nullifier: Fr,
|
|
1019
1072
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(
|
|
1073
|
+
const committedDb = await this.#getWorldState(block);
|
|
1021
1074
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1075
|
if (!findResult) {
|
|
1023
1076
|
return undefined;
|
|
@@ -1032,8 +1085,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1085
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1086
|
}
|
|
1034
1087
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this.#getWorldState(
|
|
1088
|
+
async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1089
|
+
const committedDb = await this.#getWorldState(block);
|
|
1037
1090
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1091
|
if (!lowLeafResult) {
|
|
1039
1092
|
return undefined;
|
|
@@ -1047,19 +1100,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1100
|
}
|
|
1048
1101
|
}
|
|
1049
1102
|
|
|
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);
|
|
1103
|
+
public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1104
|
+
const committedDb = await this.#getWorldState(block);
|
|
1063
1105
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1106
|
|
|
1065
1107
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1115,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1115
|
return preimage.leaf.value;
|
|
1074
1116
|
}
|
|
1075
1117
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1118
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1119
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1120
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1121
|
+
if (block.equals(initialBlockHash)) {
|
|
1122
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1123
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1124
|
+
}
|
|
1125
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1126
|
+
} else {
|
|
1127
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1128
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1129
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1130
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1131
|
+
}
|
|
1132
|
+
return this.blockSource.getBlockHeader(block);
|
|
1133
|
+
}
|
|
1093
1134
|
}
|
|
1094
1135
|
|
|
1095
1136
|
/**
|
|
@@ -1124,7 +1165,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1165
|
}
|
|
1125
1166
|
|
|
1126
1167
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1168
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1128
1169
|
|
|
1129
1170
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1171
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1139,6 +1180,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1180
|
this.contractDataSource,
|
|
1140
1181
|
new DateProvider(),
|
|
1141
1182
|
this.telemetry,
|
|
1183
|
+
this.log.getBindings(),
|
|
1142
1184
|
);
|
|
1143
1185
|
|
|
1144
1186
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1149,11 +1191,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1149
1191
|
|
|
1150
1192
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1193
|
try {
|
|
1152
|
-
const
|
|
1194
|
+
const config = PublicSimulatorConfig.from({
|
|
1153
1195
|
skipFeeEnforcement,
|
|
1154
|
-
|
|
1155
|
-
|
|
1196
|
+
collectDebugLogs: true,
|
|
1197
|
+
collectHints: false,
|
|
1198
|
+
collectCallMetadata: true,
|
|
1199
|
+
collectStatistics: false,
|
|
1200
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1201
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1202
|
+
}),
|
|
1156
1203
|
});
|
|
1204
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1157
1205
|
|
|
1158
1206
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1159
1207
|
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
@@ -1185,17 +1233,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1185
1233
|
|
|
1186
1234
|
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1187
1235
|
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
|
-
|
|
1236
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1237
|
+
const validator = createValidatorForAcceptingTxs(
|
|
1238
|
+
db,
|
|
1239
|
+
this.contractDataSource,
|
|
1240
|
+
verifier,
|
|
1241
|
+
{
|
|
1242
|
+
timestamp: nextSlotTimestamp,
|
|
1243
|
+
blockNumber,
|
|
1244
|
+
l1ChainId: this.l1ChainId,
|
|
1245
|
+
rollupVersion: this.version,
|
|
1246
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1247
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1248
|
+
skipFeeEnforcement,
|
|
1249
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1250
|
+
},
|
|
1251
|
+
this.log.getBindings(),
|
|
1252
|
+
);
|
|
1199
1253
|
|
|
1200
1254
|
return await validator.validateTx(tx);
|
|
1201
1255
|
}
|
|
@@ -1242,8 +1296,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1242
1296
|
|
|
1243
1297
|
public getValidatorStats(
|
|
1244
1298
|
validatorAddress: EthAddress,
|
|
1245
|
-
fromSlot?:
|
|
1246
|
-
toSlot?:
|
|
1299
|
+
fromSlot?: SlotNumber,
|
|
1300
|
+
toSlot?: SlotNumber,
|
|
1247
1301
|
): Promise<SingleValidatorStats | undefined> {
|
|
1248
1302
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1249
1303
|
}
|
|
@@ -1264,7 +1318,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1264
1318
|
}
|
|
1265
1319
|
|
|
1266
1320
|
// And it has an L2 block hash
|
|
1267
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1321
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1268
1322
|
if (!l2BlockHash) {
|
|
1269
1323
|
this.metrics.recordSnapshotError();
|
|
1270
1324
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1292,13 +1346,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1292
1346
|
return Promise.resolve();
|
|
1293
1347
|
}
|
|
1294
1348
|
|
|
1295
|
-
public async rollbackTo(targetBlock:
|
|
1349
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1296
1350
|
const archiver = this.blockSource as Archiver;
|
|
1297
1351
|
if (!('rollbackTo' in archiver)) {
|
|
1298
1352
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1299
1353
|
}
|
|
1300
1354
|
|
|
1301
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1355
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1302
1356
|
if (targetBlock < finalizedBlock) {
|
|
1303
1357
|
if (force) {
|
|
1304
1358
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1359,17 +1413,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1359
1413
|
}
|
|
1360
1414
|
}
|
|
1361
1415
|
|
|
1416
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1417
|
+
if (!this.initialHeaderHashPromise) {
|
|
1418
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1419
|
+
}
|
|
1420
|
+
return this.initialHeaderHashPromise;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1362
1423
|
/**
|
|
1363
1424
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1364
|
-
* @param
|
|
1425
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1365
1426
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1366
1427
|
*/
|
|
1367
|
-
async #getWorldState(
|
|
1368
|
-
|
|
1369
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
let blockSyncedTo: number = 0;
|
|
1428
|
+
async #getWorldState(block: BlockParameter) {
|
|
1429
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1373
1430
|
try {
|
|
1374
1431
|
// Attempt to sync the world state if necessary
|
|
1375
1432
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1377,15 +1434,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1377
1434
|
this.log.error(`Error getting world state: ${err}`);
|
|
1378
1435
|
}
|
|
1379
1436
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1437
|
+
if (block === 'latest') {
|
|
1438
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1383
1439
|
return this.worldStateSynchronizer.getCommitted();
|
|
1384
|
-
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1443
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1444
|
+
if (block.equals(initialBlockHash)) {
|
|
1445
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1446
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1450
|
+
if (!header) {
|
|
1451
|
+
throw new Error(
|
|
1452
|
+
`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.`,
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
const blockNumber = header.getBlockNumber();
|
|
1456
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1457
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
// Block number provided
|
|
1461
|
+
{
|
|
1462
|
+
const blockNumber = block as BlockNumber;
|
|
1463
|
+
|
|
1464
|
+
if (blockNumber > blockSyncedTo) {
|
|
1465
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1385
1468
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1386
1469
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1387
|
-
} else {
|
|
1388
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1389
1470
|
}
|
|
1390
1471
|
}
|
|
1391
1472
|
|
|
@@ -1393,8 +1474,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1393
1474
|
* Ensure we fully sync the world state
|
|
1394
1475
|
* @returns A promise that fulfils once the world state is synced
|
|
1395
1476
|
*/
|
|
1396
|
-
async #syncWorldState(): Promise<
|
|
1477
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1397
1478
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1398
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1479
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1399
1480
|
}
|
|
1400
1481
|
}
|