@aztec/aztec-node 0.0.1-commit.24de95ac → 0.0.1-commit.3469e52
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 +5 -16
- package/dest/aztec-node/server.d.ts +57 -123
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +609 -187
- 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/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 +5 -23
- package/src/aztec-node/server.ts +282 -224
- 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,17 @@ 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
44
|
import {
|
|
51
|
-
type
|
|
52
|
-
type
|
|
45
|
+
type BlockParameter,
|
|
46
|
+
type CheckpointedL2Block,
|
|
47
|
+
type DataInBlock,
|
|
53
48
|
L2BlockHash,
|
|
54
|
-
|
|
49
|
+
L2BlockNew,
|
|
55
50
|
type L2BlockSource,
|
|
56
|
-
type PublishedL2Block,
|
|
57
51
|
} from '@aztec/stdlib/block';
|
|
52
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
58
53
|
import type {
|
|
59
54
|
ContractClassPublic,
|
|
60
55
|
ContractDataSource,
|
|
@@ -62,7 +57,7 @@ import type {
|
|
|
62
57
|
NodeInfo,
|
|
63
58
|
ProtocolContractAddresses,
|
|
64
59
|
} from '@aztec/stdlib/contract';
|
|
65
|
-
import
|
|
60
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
66
61
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
67
62
|
import {
|
|
68
63
|
type AztecNode,
|
|
@@ -81,7 +76,7 @@ import {
|
|
|
81
76
|
type WorldStateSynchronizer,
|
|
82
77
|
tryStop,
|
|
83
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
84
|
-
import type { LogFilter,
|
|
79
|
+
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
85
80
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
86
81
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
87
82
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
@@ -109,10 +104,13 @@ import {
|
|
|
109
104
|
trackSpan,
|
|
110
105
|
} from '@aztec/telemetry-client';
|
|
111
106
|
import {
|
|
107
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
108
|
+
FullNodeCheckpointsBuilder,
|
|
112
109
|
NodeKeystoreAdapter,
|
|
113
110
|
ValidatorClient,
|
|
114
111
|
createBlockProposalHandler,
|
|
115
112
|
createValidatorClient,
|
|
113
|
+
createValidatorForAcceptingTxs,
|
|
116
114
|
} from '@aztec/validator-client';
|
|
117
115
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
116
|
|
|
@@ -128,13 +126,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
126
|
*/
|
|
129
127
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
128
|
private metrics: NodeMetrics;
|
|
129
|
+
private initialHeaderHashPromise: Promise<L2BlockHash> | undefined = undefined;
|
|
131
130
|
|
|
132
131
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
132
|
private isUploadingSnapshot = false;
|
|
134
133
|
|
|
135
|
-
// Serial queue to ensure that we only send one tx at a time
|
|
136
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
137
|
-
|
|
138
134
|
public readonly tracer: Tracer;
|
|
139
135
|
|
|
140
136
|
constructor(
|
|
@@ -157,10 +153,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
157
153
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
158
154
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
159
155
|
private log = createLogger('node'),
|
|
156
|
+
private blobClient?: BlobClientInterface,
|
|
160
157
|
) {
|
|
161
158
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
162
159
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
163
|
-
this.txQueue.start();
|
|
164
160
|
|
|
165
161
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
166
162
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
@@ -187,7 +183,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
187
183
|
logger?: Logger;
|
|
188
184
|
publisher?: SequencerPublisher;
|
|
189
185
|
dateProvider?: DateProvider;
|
|
190
|
-
blobSinkClient?: BlobSinkClientInterface;
|
|
191
186
|
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
192
187
|
} = {},
|
|
193
188
|
options: {
|
|
@@ -200,8 +195,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
200
195
|
const packageVersion = getPackageVersion() ?? '';
|
|
201
196
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
202
197
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
203
|
-
const blobSinkClient =
|
|
204
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
205
198
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
206
199
|
|
|
207
200
|
// Build a key store from file if given or from environment otherwise
|
|
@@ -241,7 +234,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
241
234
|
|
|
242
235
|
const publicClient = createPublicClient({
|
|
243
236
|
chain: ethereumChain.chainInfo,
|
|
244
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
237
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
245
238
|
pollingInterval: config.viemPollingIntervalMS,
|
|
246
239
|
});
|
|
247
240
|
|
|
@@ -269,6 +262,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
269
262
|
);
|
|
270
263
|
}
|
|
271
264
|
|
|
265
|
+
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
266
|
+
|
|
272
267
|
// attempt snapshot sync if possible
|
|
273
268
|
await trySnapshotSync(config, log);
|
|
274
269
|
|
|
@@ -276,7 +271,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
276
271
|
|
|
277
272
|
const archiver = await createArchiver(
|
|
278
273
|
config,
|
|
279
|
-
{
|
|
274
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
280
275
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
281
276
|
);
|
|
282
277
|
|
|
@@ -287,7 +282,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
282
|
options.prefilledPublicData,
|
|
288
283
|
telemetry,
|
|
289
284
|
);
|
|
290
|
-
const circuitVerifier =
|
|
285
|
+
const circuitVerifier =
|
|
286
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
287
|
+
? await BBCircuitVerifier.new(config)
|
|
288
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
291
289
|
if (!config.realProofs) {
|
|
292
290
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
293
291
|
}
|
|
@@ -310,7 +308,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
310
308
|
// We should really not be modifying the config object
|
|
311
309
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
312
310
|
|
|
313
|
-
|
|
311
|
+
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
312
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
314
313
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
314
|
worldStateSynchronizer,
|
|
316
315
|
archiver,
|
|
@@ -322,15 +321,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
322
321
|
const watchers: Watcher[] = [];
|
|
323
322
|
|
|
324
323
|
// Create validator client if required
|
|
325
|
-
const validatorClient = createValidatorClient(config, {
|
|
324
|
+
const validatorClient = await createValidatorClient(config, {
|
|
325
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
326
|
+
worldState: worldStateSynchronizer,
|
|
326
327
|
p2pClient,
|
|
327
328
|
telemetry,
|
|
328
329
|
dateProvider,
|
|
329
330
|
epochCache,
|
|
330
|
-
blockBuilder,
|
|
331
331
|
blockSource: archiver,
|
|
332
332
|
l1ToL2MessageSource: archiver,
|
|
333
333
|
keyStoreManager,
|
|
334
|
+
blobClient,
|
|
334
335
|
});
|
|
335
336
|
|
|
336
337
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -348,7 +349,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
348
349
|
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
349
350
|
log.info('Setting up block proposal reexecution for monitoring');
|
|
350
351
|
createBlockProposalHandler(config, {
|
|
351
|
-
|
|
352
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
353
|
+
worldState: worldStateSynchronizer,
|
|
352
354
|
epochCache,
|
|
353
355
|
blockSource: archiver,
|
|
354
356
|
l1ToL2MessageSource: archiver,
|
|
@@ -376,7 +378,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
376
378
|
archiver,
|
|
377
379
|
epochCache,
|
|
378
380
|
p2pClient.getTxProvider(),
|
|
379
|
-
|
|
381
|
+
validatorCheckpointsBuilder,
|
|
380
382
|
config,
|
|
381
383
|
);
|
|
382
384
|
watchers.push(epochPruneWatcher);
|
|
@@ -404,7 +406,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
404
406
|
// Validator enabled, create/start relevant service
|
|
405
407
|
let sequencer: SequencerClient | undefined;
|
|
406
408
|
let slasherClient: SlasherClientInterface | undefined;
|
|
407
|
-
if (!config.disableValidator) {
|
|
409
|
+
if (!config.disableValidator && validatorClient) {
|
|
408
410
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
409
411
|
// as they are executed when the node is selected as proposer.
|
|
410
412
|
const validatorAddresses = keyStoreManager
|
|
@@ -423,14 +425,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
423
425
|
);
|
|
424
426
|
await slasherClient.start();
|
|
425
427
|
|
|
426
|
-
const l1TxUtils =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
const l1TxUtils = config.publisherForwarderAddress
|
|
429
|
+
? await createForwarderL1TxUtilsFromEthSigner(
|
|
430
|
+
publicClient,
|
|
431
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
+
config.publisherForwarderAddress,
|
|
433
|
+
{ ...config, scope: 'sequencer' },
|
|
434
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
435
|
+
)
|
|
436
|
+
: await createL1TxUtilsWithBlobsFromEthSigner(
|
|
437
|
+
publicClient,
|
|
438
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
439
|
+
{ ...config, scope: 'sequencer' },
|
|
440
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
441
|
+
);
|
|
432
442
|
|
|
433
443
|
// Create and start the sequencer client
|
|
444
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
445
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
446
|
+
worldStateSynchronizer,
|
|
447
|
+
archiver,
|
|
448
|
+
dateProvider,
|
|
449
|
+
telemetry,
|
|
450
|
+
);
|
|
451
|
+
|
|
434
452
|
sequencer = await SequencerClient.new(config, {
|
|
435
453
|
...deps,
|
|
436
454
|
epochCache,
|
|
@@ -439,12 +457,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
439
457
|
p2pClient,
|
|
440
458
|
worldStateSynchronizer,
|
|
441
459
|
slasherClient,
|
|
442
|
-
|
|
460
|
+
checkpointsBuilder,
|
|
443
461
|
l2BlockSource: archiver,
|
|
444
462
|
l1ToL2MessageSource: archiver,
|
|
445
463
|
telemetry,
|
|
446
464
|
dateProvider,
|
|
447
|
-
|
|
465
|
+
blobClient,
|
|
448
466
|
nodeKeyStore: keyStoreManager!,
|
|
449
467
|
});
|
|
450
468
|
}
|
|
@@ -456,6 +474,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
456
474
|
log.warn(`Sequencer created but not started`);
|
|
457
475
|
}
|
|
458
476
|
|
|
477
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
478
|
+
...config,
|
|
479
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
480
|
+
l1GenesisTime,
|
|
481
|
+
slotDuration: Number(slotDuration),
|
|
482
|
+
});
|
|
483
|
+
|
|
459
484
|
return new AztecNodeService(
|
|
460
485
|
config,
|
|
461
486
|
p2pClient,
|
|
@@ -470,12 +495,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
470
495
|
epochPruneWatcher,
|
|
471
496
|
ethereumChain.chainInfo.id,
|
|
472
497
|
config.rollupVersion,
|
|
473
|
-
|
|
498
|
+
globalVariableBuilder,
|
|
474
499
|
epochCache,
|
|
475
500
|
packageVersion,
|
|
476
501
|
proofVerifier,
|
|
477
502
|
telemetry,
|
|
478
503
|
log,
|
|
504
|
+
blobClient,
|
|
479
505
|
);
|
|
480
506
|
}
|
|
481
507
|
|
|
@@ -546,13 +572,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
546
572
|
}
|
|
547
573
|
|
|
548
574
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
575
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
576
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
577
|
* @returns The requested block.
|
|
552
578
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
579
|
+
public async getBlock(block: BlockParameter): Promise<L2BlockNew | undefined> {
|
|
580
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
581
|
+
return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
|
|
582
|
+
}
|
|
583
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
584
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
585
|
+
return this.buildInitialBlock();
|
|
586
|
+
}
|
|
587
|
+
return await this.blockSource.getL2BlockNew(blockNumber);
|
|
556
588
|
}
|
|
557
589
|
|
|
558
590
|
/**
|
|
@@ -560,9 +592,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
592
|
* @param blockHash - The block hash being requested.
|
|
561
593
|
* @returns The requested block.
|
|
562
594
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash: Fr): Promise<
|
|
564
|
-
const
|
|
565
|
-
|
|
595
|
+
public async getBlockByHash(blockHash: Fr): Promise<L2BlockNew | undefined> {
|
|
596
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
597
|
+
if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
|
|
598
|
+
return this.buildInitialBlock();
|
|
599
|
+
}
|
|
600
|
+
return await this.blockSource.getL2BlockNewByHash(blockHash);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
private buildInitialBlock(): L2BlockNew {
|
|
604
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
605
|
+
return L2BlockNew.empty(initialHeader);
|
|
566
606
|
}
|
|
567
607
|
|
|
568
608
|
/**
|
|
@@ -570,9 +610,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
570
610
|
* @param archive - The archive root being requested.
|
|
571
611
|
* @returns The requested block.
|
|
572
612
|
*/
|
|
573
|
-
public async getBlockByArchive(archive: Fr): Promise<
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
613
|
+
public async getBlockByArchive(archive: Fr): Promise<L2BlockNew | undefined> {
|
|
614
|
+
return await this.blockSource.getL2BlockNewByArchive(archive);
|
|
576
615
|
}
|
|
577
616
|
|
|
578
617
|
/**
|
|
@@ -581,31 +620,51 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
620
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
621
|
* @returns The blocks requested.
|
|
583
622
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.
|
|
623
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
|
|
624
|
+
return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
|
|
586
625
|
}
|
|
587
626
|
|
|
588
|
-
public async getPublishedBlocks(from:
|
|
627
|
+
public async getPublishedBlocks(from: BlockNumber, limit: number): Promise<CheckpointedL2Block[]> {
|
|
589
628
|
return (await this.blockSource.getPublishedBlocks(from, limit)) ?? [];
|
|
590
629
|
}
|
|
591
630
|
|
|
631
|
+
public async getPublishedCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
632
|
+
return (await this.blockSource.getPublishedCheckpoints(from, limit)) ?? [];
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
public async getL2BlocksNew(from: BlockNumber, limit: number): Promise<L2BlockNew[]> {
|
|
636
|
+
return (await this.blockSource.getL2BlocksNew(from, limit)) ?? [];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number, proven?: boolean) {
|
|
640
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit, proven)) ?? [];
|
|
641
|
+
}
|
|
642
|
+
|
|
592
643
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
644
|
+
* Method to fetch the current min L2 fees.
|
|
645
|
+
* @returns The current min L2 fees.
|
|
595
646
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
647
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
648
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
652
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
653
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
657
|
}
|
|
599
658
|
|
|
600
659
|
/**
|
|
601
660
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
661
|
* @returns The block number.
|
|
603
662
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
663
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
664
|
return await this.blockSource.getBlockNumber();
|
|
606
665
|
}
|
|
607
666
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
667
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
668
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
669
|
}
|
|
611
670
|
|
|
@@ -641,25 +700,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
700
|
return this.contractDataSource.getContract(address);
|
|
642
701
|
}
|
|
643
702
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
* @param from - The block number from which to begin retrieving logs.
|
|
647
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
648
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
649
|
-
*/
|
|
650
|
-
public getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
|
|
651
|
-
return this.logsSource.getPrivateLogs(from, limit);
|
|
703
|
+
public getPrivateLogsByTags(tags: SiloedTag[], page?: number): Promise<TxScopedL2Log[][]> {
|
|
704
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
652
705
|
}
|
|
653
706
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
*/
|
|
661
|
-
public getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
|
|
662
|
-
return this.logsSource.getLogsByTags(tags, logsPerTag);
|
|
707
|
+
public getPublicLogsByTagsFromContract(
|
|
708
|
+
contractAddress: AztecAddress,
|
|
709
|
+
tags: Tag[],
|
|
710
|
+
page?: number,
|
|
711
|
+
): Promise<TxScopedL2Log[][]> {
|
|
712
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
663
713
|
}
|
|
664
714
|
|
|
665
715
|
/**
|
|
@@ -685,7 +735,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
735
|
* @param tx - The transaction to be submitted.
|
|
686
736
|
*/
|
|
687
737
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
738
|
+
await this.#sendTx(tx);
|
|
689
739
|
}
|
|
690
740
|
|
|
691
741
|
async #sendTx(tx: Tx) {
|
|
@@ -732,7 +782,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
782
|
*/
|
|
733
783
|
public async stop() {
|
|
734
784
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
785
|
await tryStop(this.validatorsSentinel);
|
|
737
786
|
await tryStop(this.epochPruneWatcher);
|
|
738
787
|
await tryStop(this.slasherClient);
|
|
@@ -741,10 +790,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
741
790
|
await tryStop(this.p2pClient);
|
|
742
791
|
await tryStop(this.worldStateSynchronizer);
|
|
743
792
|
await tryStop(this.blockSource);
|
|
793
|
+
await tryStop(this.blobClient);
|
|
744
794
|
await tryStop(this.telemetry);
|
|
745
795
|
this.log.info(`Stopped Aztec Node`);
|
|
746
796
|
}
|
|
747
797
|
|
|
798
|
+
/**
|
|
799
|
+
* Returns the blob client used by this node.
|
|
800
|
+
* @internal - Exposed for testing purposes only.
|
|
801
|
+
*/
|
|
802
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
803
|
+
return this.blobClient;
|
|
804
|
+
}
|
|
805
|
+
|
|
748
806
|
/**
|
|
749
807
|
* Method to retrieve pending txs.
|
|
750
808
|
* @param limit - The number of items to returns
|
|
@@ -777,20 +835,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
835
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
836
|
}
|
|
779
837
|
|
|
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
838
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
839
|
+
block: BlockParameter,
|
|
790
840
|
treeId: MerkleTreeId,
|
|
791
841
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this.#getWorldState(
|
|
842
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
843
|
+
const committedDb = await this.#getWorldState(block);
|
|
794
844
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
845
|
treeId,
|
|
796
846
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -815,7 +865,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
815
865
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
816
866
|
const blockHashes = await Promise.all(
|
|
817
867
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
868
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
869
|
}),
|
|
820
870
|
);
|
|
821
871
|
|
|
@@ -826,7 +876,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
876
|
}
|
|
827
877
|
}
|
|
828
878
|
|
|
829
|
-
// Create
|
|
879
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
830
880
|
return maybeIndices.map((index, i) => {
|
|
831
881
|
if (index === undefined) {
|
|
832
882
|
return undefined;
|
|
@@ -841,46 +891,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
841
891
|
return undefined;
|
|
842
892
|
}
|
|
843
893
|
return {
|
|
844
|
-
l2BlockNumber: Number(blockNumber),
|
|
894
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
845
895
|
l2BlockHash: L2BlockHash.fromField(blockHash),
|
|
846
896
|
data: index,
|
|
847
897
|
};
|
|
848
898
|
});
|
|
849
899
|
}
|
|
850
900
|
|
|
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
901
|
public async getNullifierSiblingPath(
|
|
858
|
-
|
|
902
|
+
block: BlockParameter,
|
|
859
903
|
leafIndex: bigint,
|
|
860
904
|
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
861
|
-
const committedDb = await this.#getWorldState(
|
|
905
|
+
const committedDb = await this.#getWorldState(block);
|
|
862
906
|
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
863
907
|
}
|
|
864
908
|
|
|
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
909
|
public async getNoteHashSiblingPath(
|
|
872
|
-
|
|
910
|
+
block: BlockParameter,
|
|
873
911
|
leafIndex: bigint,
|
|
874
912
|
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
875
|
-
const committedDb = await this.#getWorldState(
|
|
913
|
+
const committedDb = await this.#getWorldState(block);
|
|
876
914
|
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
877
915
|
}
|
|
878
916
|
|
|
879
917
|
public async getArchiveMembershipWitness(
|
|
880
|
-
|
|
918
|
+
block: BlockParameter,
|
|
881
919
|
archive: Fr,
|
|
882
920
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
const committedDb = await this.#getWorldState(
|
|
921
|
+
const committedDb = await this.#getWorldState(block);
|
|
884
922
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
|
|
885
923
|
return pathAndIndex === undefined
|
|
886
924
|
? undefined
|
|
@@ -888,10 +926,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
888
926
|
}
|
|
889
927
|
|
|
890
928
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
929
|
+
block: BlockParameter,
|
|
892
930
|
noteHash: Fr,
|
|
893
931
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this.#getWorldState(
|
|
932
|
+
const committedDb = await this.#getWorldState(block);
|
|
895
933
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
934
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
935
|
[noteHash],
|
|
@@ -901,17 +939,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
939
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
940
|
}
|
|
903
941
|
|
|
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
942
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
943
|
+
block: BlockParameter,
|
|
912
944
|
l1ToL2Message: Fr,
|
|
913
945
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this.#getWorldState(
|
|
946
|
+
const db = await this.#getWorldState(block);
|
|
915
947
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
948
|
if (!witness) {
|
|
917
949
|
return undefined;
|
|
@@ -921,9 +953,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
953
|
return [witness.index, witness.path];
|
|
922
954
|
}
|
|
923
955
|
|
|
924
|
-
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<
|
|
956
|
+
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
925
957
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex
|
|
958
|
+
return messageIndex
|
|
959
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
960
|
+
: undefined;
|
|
927
961
|
}
|
|
928
962
|
|
|
929
963
|
/**
|
|
@@ -937,54 +971,51 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
971
|
}
|
|
938
972
|
|
|
939
973
|
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in
|
|
941
|
-
* @param
|
|
942
|
-
* @returns The L2 to L1 messages (
|
|
974
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
975
|
+
* @param epoch - The epoch at which to get the data.
|
|
976
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
943
977
|
*/
|
|
944
|
-
public async getL2ToL1Messages(
|
|
945
|
-
|
|
946
|
-
|
|
978
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
|
+
// Assumes `getBlocksForEpoch` returns blocks in ascending order of block number.
|
|
980
|
+
const blocks = await this.blockSource.getBlocksForEpoch(epoch);
|
|
981
|
+
const blocksInCheckpoints: L2BlockNew[][] = [];
|
|
982
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
983
|
+
let checkpointIndex = -1;
|
|
984
|
+
for (const block of blocks) {
|
|
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
|
+
);
|
|
947
996
|
}
|
|
948
997
|
|
|
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
998
|
public async getArchiveSiblingPath(
|
|
956
|
-
|
|
999
|
+
block: BlockParameter,
|
|
957
1000
|
leafIndex: bigint,
|
|
958
1001
|
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
959
|
-
const committedDb = await this.#getWorldState(
|
|
1002
|
+
const committedDb = await this.#getWorldState(block);
|
|
960
1003
|
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
961
1004
|
}
|
|
962
1005
|
|
|
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
1006
|
public async getPublicDataSiblingPath(
|
|
970
|
-
|
|
1007
|
+
block: BlockParameter,
|
|
971
1008
|
leafIndex: bigint,
|
|
972
1009
|
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
973
|
-
const committedDb = await this.#getWorldState(
|
|
1010
|
+
const committedDb = await this.#getWorldState(block);
|
|
974
1011
|
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
975
1012
|
}
|
|
976
1013
|
|
|
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
1014
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1015
|
+
block: BlockParameter,
|
|
985
1016
|
nullifier: Fr,
|
|
986
1017
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this.#getWorldState(
|
|
1018
|
+
const db = await this.#getWorldState(block);
|
|
988
1019
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1020
|
if (!witness) {
|
|
990
1021
|
return undefined;
|
|
@@ -1001,7 +1032,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1032
|
|
|
1002
1033
|
/**
|
|
1003
1034
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param
|
|
1035
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1005
1036
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
1037
|
* @returns The low nullifier membership witness (if found).
|
|
1007
1038
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1014,10 +1045,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1045
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
1046
|
*/
|
|
1016
1047
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1048
|
+
block: BlockParameter,
|
|
1018
1049
|
nullifier: Fr,
|
|
1019
1050
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(
|
|
1051
|
+
const committedDb = await this.#getWorldState(block);
|
|
1021
1052
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1053
|
if (!findResult) {
|
|
1023
1054
|
return undefined;
|
|
@@ -1032,8 +1063,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1063
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1064
|
}
|
|
1034
1065
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this.#getWorldState(
|
|
1066
|
+
async getPublicDataWitness(block: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1067
|
+
const committedDb = await this.#getWorldState(block);
|
|
1037
1068
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1069
|
if (!lowLeafResult) {
|
|
1039
1070
|
return undefined;
|
|
@@ -1047,19 +1078,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1078
|
}
|
|
1048
1079
|
}
|
|
1049
1080
|
|
|
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);
|
|
1081
|
+
public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1082
|
+
const committedDb = await this.#getWorldState(block);
|
|
1063
1083
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1084
|
|
|
1065
1085
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1093,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1093
|
return preimage.leaf.value;
|
|
1074
1094
|
}
|
|
1075
1095
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1096
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1097
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
1098
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1099
|
+
if (block.equals(initialBlockHash)) {
|
|
1100
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1101
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1102
|
+
}
|
|
1103
|
+
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1104
|
+
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1105
|
+
} else {
|
|
1106
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1107
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1108
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1109
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1110
|
+
}
|
|
1111
|
+
return this.blockSource.getBlockHeader(block);
|
|
1112
|
+
}
|
|
1093
1113
|
}
|
|
1094
1114
|
|
|
1095
1115
|
/**
|
|
@@ -1124,7 +1144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1144
|
}
|
|
1125
1145
|
|
|
1126
1146
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1147
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1128
1148
|
|
|
1129
1149
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1150
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1149,11 +1169,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1149
1169
|
|
|
1150
1170
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1171
|
try {
|
|
1152
|
-
const
|
|
1172
|
+
const config = PublicSimulatorConfig.from({
|
|
1153
1173
|
skipFeeEnforcement,
|
|
1154
|
-
|
|
1155
|
-
|
|
1174
|
+
collectDebugLogs: true,
|
|
1175
|
+
collectHints: false,
|
|
1176
|
+
collectCallMetadata: true,
|
|
1177
|
+
collectStatistics: false,
|
|
1178
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1179
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1180
|
+
}),
|
|
1156
1181
|
});
|
|
1182
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1157
1183
|
|
|
1158
1184
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1159
1185
|
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
@@ -1185,14 +1211,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1185
1211
|
|
|
1186
1212
|
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
1187
1213
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1188
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1214
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1189
1215
|
const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
|
|
1190
1216
|
timestamp: nextSlotTimestamp,
|
|
1191
1217
|
blockNumber,
|
|
1192
1218
|
l1ChainId: this.l1ChainId,
|
|
1193
1219
|
rollupVersion: this.version,
|
|
1194
1220
|
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1195
|
-
gasFees: await this.
|
|
1221
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1196
1222
|
skipFeeEnforcement,
|
|
1197
1223
|
txsPermitted: !this.config.disableTransactions,
|
|
1198
1224
|
});
|
|
@@ -1242,8 +1268,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1242
1268
|
|
|
1243
1269
|
public getValidatorStats(
|
|
1244
1270
|
validatorAddress: EthAddress,
|
|
1245
|
-
fromSlot?:
|
|
1246
|
-
toSlot?:
|
|
1271
|
+
fromSlot?: SlotNumber,
|
|
1272
|
+
toSlot?: SlotNumber,
|
|
1247
1273
|
): Promise<SingleValidatorStats | undefined> {
|
|
1248
1274
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1249
1275
|
}
|
|
@@ -1264,7 +1290,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1264
1290
|
}
|
|
1265
1291
|
|
|
1266
1292
|
// And it has an L2 block hash
|
|
1267
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1293
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1268
1294
|
if (!l2BlockHash) {
|
|
1269
1295
|
this.metrics.recordSnapshotError();
|
|
1270
1296
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1292,13 +1318,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1292
1318
|
return Promise.resolve();
|
|
1293
1319
|
}
|
|
1294
1320
|
|
|
1295
|
-
public async rollbackTo(targetBlock:
|
|
1321
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1296
1322
|
const archiver = this.blockSource as Archiver;
|
|
1297
1323
|
if (!('rollbackTo' in archiver)) {
|
|
1298
1324
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1299
1325
|
}
|
|
1300
1326
|
|
|
1301
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1327
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1302
1328
|
if (targetBlock < finalizedBlock) {
|
|
1303
1329
|
if (force) {
|
|
1304
1330
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1359,17 +1385,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1359
1385
|
}
|
|
1360
1386
|
}
|
|
1361
1387
|
|
|
1388
|
+
#getInitialHeaderHash(): Promise<L2BlockHash> {
|
|
1389
|
+
if (!this.initialHeaderHashPromise) {
|
|
1390
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer
|
|
1391
|
+
.getCommitted()
|
|
1392
|
+
.getInitialHeader()
|
|
1393
|
+
.hash()
|
|
1394
|
+
.then(hash => L2BlockHash.fromField(hash));
|
|
1395
|
+
}
|
|
1396
|
+
return this.initialHeaderHashPromise;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1362
1399
|
/**
|
|
1363
1400
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1364
|
-
* @param
|
|
1401
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1365
1402
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1366
1403
|
*/
|
|
1367
|
-
async #getWorldState(
|
|
1368
|
-
|
|
1369
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
let blockSyncedTo: number = 0;
|
|
1404
|
+
async #getWorldState(block: BlockParameter) {
|
|
1405
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1373
1406
|
try {
|
|
1374
1407
|
// Attempt to sync the world state if necessary
|
|
1375
1408
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1377,15 +1410,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1377
1410
|
this.log.error(`Error getting world state: ${err}`);
|
|
1378
1411
|
}
|
|
1379
1412
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1413
|
+
if (block === 'latest') {
|
|
1414
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1383
1415
|
return this.worldStateSynchronizer.getCommitted();
|
|
1384
|
-
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
if (L2BlockHash.isL2BlockHash(block)) {
|
|
1419
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1420
|
+
if (block.equals(initialBlockHash)) {
|
|
1421
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1422
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1426
|
+
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1427
|
+
if (!header) {
|
|
1428
|
+
throw new Error(
|
|
1429
|
+
`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.`,
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1432
|
+
const blockNumber = header.getBlockNumber();
|
|
1433
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1434
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// Block number provided
|
|
1438
|
+
{
|
|
1439
|
+
const blockNumber = block as BlockNumber;
|
|
1440
|
+
|
|
1441
|
+
if (blockNumber > blockSyncedTo) {
|
|
1442
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1385
1445
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1386
1446
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1387
|
-
} else {
|
|
1388
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1389
1447
|
}
|
|
1390
1448
|
}
|
|
1391
1449
|
|
|
@@ -1393,8 +1451,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1393
1451
|
* Ensure we fully sync the world state
|
|
1394
1452
|
* @returns A promise that fulfils once the world state is synced
|
|
1395
1453
|
*/
|
|
1396
|
-
async #syncWorldState(): Promise<
|
|
1454
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1397
1455
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1398
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1456
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1399
1457
|
}
|
|
1400
1458
|
}
|