@aztec/aztec-node 0.0.1-commit.10bd49492 → 0.0.1-commit.11bf3dd6e
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/server.d.ts +28 -31
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +203 -106
- package/dest/sentinel/sentinel.js +6 -6
- package/package.json +26 -27
- package/src/aztec-node/server.ts +226 -115
- package/src/sentinel/sentinel.ts +6 -6
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
5
|
import { Blob } from '@aztec/blob-lib';
|
|
5
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
11
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
-
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
16
18
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
19
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
20
|
import { count } from '@aztec/foundation/string';
|
|
18
21
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
19
22
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
@@ -30,7 +33,12 @@ import {
|
|
|
30
33
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
31
34
|
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
32
35
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
FeeProviderImpl,
|
|
38
|
+
GlobalVariableBuilder,
|
|
39
|
+
SequencerClient,
|
|
40
|
+
type SequencerPublisher,
|
|
41
|
+
} from '@aztec/sequencer-client';
|
|
34
42
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
35
43
|
import {
|
|
36
44
|
AttestationsBlockWatcher,
|
|
@@ -57,13 +65,14 @@ import type {
|
|
|
57
65
|
NodeInfo,
|
|
58
66
|
ProtocolContractAddresses,
|
|
59
67
|
} from '@aztec/stdlib/contract';
|
|
60
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
68
|
+
import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
61
69
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
62
70
|
import {
|
|
63
71
|
type AztecNode,
|
|
64
72
|
type AztecNodeAdmin,
|
|
65
73
|
type AztecNodeAdminConfig,
|
|
66
74
|
AztecNodeAdminConfigSchema,
|
|
75
|
+
type AztecNodeDebug,
|
|
67
76
|
type GetContractClassLogsResponse,
|
|
68
77
|
type GetPublicLogsResponse,
|
|
69
78
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -79,11 +88,12 @@ import {
|
|
|
79
88
|
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
80
89
|
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
81
90
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
82
|
-
import type { Offense
|
|
83
|
-
import type { NullifierLeafPreimage,
|
|
91
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
92
|
+
import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
84
93
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
85
94
|
import {
|
|
86
95
|
type BlockHeader,
|
|
96
|
+
type FeeProvider,
|
|
87
97
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
88
98
|
type IndexedTxEffect,
|
|
89
99
|
PublicSimulationOutput,
|
|
@@ -95,6 +105,7 @@ import {
|
|
|
95
105
|
} from '@aztec/stdlib/tx';
|
|
96
106
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
97
107
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
108
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
98
109
|
import {
|
|
99
110
|
Attributes,
|
|
100
111
|
type TelemetryClient,
|
|
@@ -108,12 +119,13 @@ import {
|
|
|
108
119
|
FullNodeCheckpointsBuilder,
|
|
109
120
|
NodeKeystoreAdapter,
|
|
110
121
|
ValidatorClient,
|
|
111
|
-
|
|
122
|
+
createProposalHandler,
|
|
112
123
|
createValidatorClient,
|
|
113
124
|
} from '@aztec/validator-client';
|
|
125
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
114
126
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
115
127
|
|
|
116
|
-
import { createPublicClient
|
|
128
|
+
import { createPublicClient } from 'viem';
|
|
117
129
|
|
|
118
130
|
import { createSentinel } from '../sentinel/factory.js';
|
|
119
131
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -123,7 +135,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
123
135
|
/**
|
|
124
136
|
* The aztec node.
|
|
125
137
|
*/
|
|
126
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
138
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
127
139
|
private metrics: NodeMetrics;
|
|
128
140
|
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
129
141
|
|
|
@@ -148,9 +160,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
148
160
|
protected readonly l1ChainId: number,
|
|
149
161
|
protected readonly version: number,
|
|
150
162
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
163
|
+
protected readonly feeProvider: FeeProvider,
|
|
151
164
|
protected readonly epochCache: EpochCacheInterface,
|
|
152
165
|
protected readonly packageVersion: string,
|
|
153
|
-
private
|
|
166
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
167
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
154
168
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
155
169
|
private log = createLogger('node'),
|
|
156
170
|
private blobClient?: BlobClientInterface,
|
|
@@ -172,6 +186,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
172
186
|
}
|
|
173
187
|
}
|
|
174
188
|
|
|
189
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
190
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
191
|
+
return this.rpcProofVerifier;
|
|
192
|
+
}
|
|
193
|
+
|
|
175
194
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
176
195
|
const status = await this.worldStateSynchronizer.status();
|
|
177
196
|
return status.syncSummary;
|
|
@@ -195,9 +214,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
195
214
|
dateProvider?: DateProvider;
|
|
196
215
|
p2pClientDeps?: P2PClientDeps;
|
|
197
216
|
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
217
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
198
218
|
} = {},
|
|
199
219
|
options: {
|
|
200
|
-
|
|
220
|
+
genesis?: GenesisData;
|
|
201
221
|
dontStartSequencer?: boolean;
|
|
202
222
|
dontStartProverNode?: boolean;
|
|
203
223
|
} = {},
|
|
@@ -257,7 +277,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
257
277
|
|
|
258
278
|
const publicClient = createPublicClient({
|
|
259
279
|
chain: ethereumChain.chainInfo,
|
|
260
|
-
transport:
|
|
280
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
261
281
|
pollingInterval: config.viemPollingIntervalMS,
|
|
262
282
|
});
|
|
263
283
|
|
|
@@ -300,16 +320,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
300
320
|
);
|
|
301
321
|
|
|
302
322
|
// now create the merkle trees and the world state synchronizer
|
|
303
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
323
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
324
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
325
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
326
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
327
|
+
if (useRealVerifiers) {
|
|
328
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
329
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
330
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
331
|
+
} else {
|
|
332
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
333
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
334
|
+
}
|
|
313
335
|
|
|
314
336
|
let debugLogStore: DebugLogStore;
|
|
315
337
|
if (!config.realProofs) {
|
|
@@ -323,8 +345,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
323
345
|
debugLogStore = new NullDebugLogStore();
|
|
324
346
|
}
|
|
325
347
|
|
|
326
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
327
|
-
|
|
328
348
|
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
329
349
|
if (proverOnly) {
|
|
330
350
|
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
@@ -334,7 +354,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
334
354
|
const p2pClient = await createP2PClient(
|
|
335
355
|
config,
|
|
336
356
|
archiver,
|
|
337
|
-
|
|
357
|
+
peerProofVerifier,
|
|
338
358
|
worldStateSynchronizer,
|
|
339
359
|
epochCache,
|
|
340
360
|
packageVersion,
|
|
@@ -377,6 +397,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
377
397
|
l1ToL2MessageSource: archiver,
|
|
378
398
|
keyStoreManager,
|
|
379
399
|
blobClient,
|
|
400
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
380
401
|
});
|
|
381
402
|
|
|
382
403
|
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
@@ -384,28 +405,35 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
384
405
|
// like attestations or auths will fail.
|
|
385
406
|
if (validatorClient) {
|
|
386
407
|
watchers.push(validatorClient);
|
|
408
|
+
|
|
409
|
+
const vc = validatorClient;
|
|
410
|
+
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
411
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
412
|
+
|
|
387
413
|
if (!options.dontStartSequencer) {
|
|
388
414
|
await validatorClient.registerHandlers();
|
|
389
415
|
}
|
|
390
416
|
}
|
|
391
417
|
}
|
|
392
418
|
|
|
393
|
-
// If there's no validator client, create a
|
|
419
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
394
420
|
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
395
421
|
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
422
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
396
423
|
if (!validatorClient) {
|
|
397
424
|
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
398
|
-
log.info(`Setting up
|
|
399
|
-
|
|
425
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
426
|
+
createProposalHandler(config, {
|
|
400
427
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
401
428
|
worldState: worldStateSynchronizer,
|
|
402
429
|
epochCache,
|
|
403
430
|
blockSource: archiver,
|
|
404
431
|
l1ToL2MessageSource: archiver,
|
|
405
432
|
p2pClient,
|
|
433
|
+
blobClient,
|
|
406
434
|
dateProvider,
|
|
407
435
|
telemetry,
|
|
408
|
-
}).register(p2pClient, reexecute);
|
|
436
|
+
}).register(p2pClient, reexecute, archiver);
|
|
409
437
|
}
|
|
410
438
|
|
|
411
439
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -447,7 +475,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
447
475
|
void archiver
|
|
448
476
|
.waitForInitialSync()
|
|
449
477
|
.then(async () => {
|
|
450
|
-
await p2pClient.start();
|
|
451
478
|
await validatorsSentinel?.start();
|
|
452
479
|
await epochPruneWatcher?.start();
|
|
453
480
|
await attestationsBlockWatcher?.start();
|
|
@@ -455,6 +482,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
482
|
})
|
|
456
483
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
457
484
|
|
|
485
|
+
const globalVariableBuilderConfig = {
|
|
486
|
+
l1Contracts: config.l1Contracts,
|
|
487
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
488
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
489
|
+
l1GenesisTime,
|
|
490
|
+
slotDuration: Number(slotDuration),
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
494
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
495
|
+
|
|
458
496
|
// Validator enabled, create/start relevant service
|
|
459
497
|
let sequencer: SequencerClient | undefined;
|
|
460
498
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -492,6 +530,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
492
530
|
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
493
531
|
);
|
|
494
532
|
|
|
533
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
534
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
535
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
536
|
+
if (fundingSigner) {
|
|
537
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
538
|
+
publicClient,
|
|
539
|
+
[fundingSigner],
|
|
540
|
+
{ ...config, scope: 'sequencer' },
|
|
541
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
542
|
+
);
|
|
543
|
+
funderL1TxUtils = funder;
|
|
544
|
+
}
|
|
545
|
+
|
|
495
546
|
// Create and start the sequencer client
|
|
496
547
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
497
548
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
@@ -506,6 +557,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
506
557
|
...deps,
|
|
507
558
|
epochCache,
|
|
508
559
|
l1TxUtils,
|
|
560
|
+
funderL1TxUtils,
|
|
509
561
|
validatorClient,
|
|
510
562
|
p2pClient,
|
|
511
563
|
worldStateSynchronizer,
|
|
@@ -517,6 +569,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
517
569
|
dateProvider,
|
|
518
570
|
blobClient,
|
|
519
571
|
nodeKeyStore: keyStoreManager!,
|
|
572
|
+
globalVariableBuilder,
|
|
520
573
|
});
|
|
521
574
|
}
|
|
522
575
|
|
|
@@ -550,13 +603,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
550
603
|
}
|
|
551
604
|
}
|
|
552
605
|
|
|
553
|
-
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
554
|
-
...config,
|
|
555
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
556
|
-
l1GenesisTime,
|
|
557
|
-
slotDuration: Number(slotDuration),
|
|
558
|
-
});
|
|
559
|
-
|
|
560
606
|
const node = new AztecNodeService(
|
|
561
607
|
config,
|
|
562
608
|
p2pClient,
|
|
@@ -573,9 +619,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
573
619
|
ethereumChain.chainInfo.id,
|
|
574
620
|
config.rollupVersion,
|
|
575
621
|
globalVariableBuilder,
|
|
622
|
+
feeProvider,
|
|
576
623
|
epochCache,
|
|
577
624
|
packageVersion,
|
|
578
|
-
|
|
625
|
+
peerProofVerifier,
|
|
626
|
+
rpcProofVerifier,
|
|
579
627
|
telemetry,
|
|
580
628
|
log,
|
|
581
629
|
blobClient,
|
|
@@ -724,12 +772,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
724
772
|
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
725
773
|
}
|
|
726
774
|
|
|
727
|
-
/**
|
|
728
|
-
* Method to fetch the current min L2 fees.
|
|
729
|
-
* @returns The current min L2 fees.
|
|
730
|
-
*/
|
|
731
775
|
public async getCurrentMinFees(): Promise<GasFees> {
|
|
732
|
-
return await this.
|
|
776
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** Returns predicted min fees for the current slot and next N slots. */
|
|
780
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
781
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
733
782
|
}
|
|
734
783
|
|
|
735
784
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -797,18 +846,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
797
846
|
page?: number,
|
|
798
847
|
referenceBlock?: BlockHash,
|
|
799
848
|
): Promise<TxScopedL2Log[][]> {
|
|
849
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
800
850
|
if (referenceBlock) {
|
|
801
851
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
802
|
-
if (
|
|
852
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
853
|
+
upToBlockNumber = BlockNumber(0);
|
|
854
|
+
} else {
|
|
803
855
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
804
856
|
if (!header) {
|
|
805
857
|
throw new Error(
|
|
806
858
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
807
859
|
);
|
|
808
860
|
}
|
|
861
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
809
862
|
}
|
|
810
863
|
}
|
|
811
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
864
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
812
865
|
}
|
|
813
866
|
|
|
814
867
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -817,18 +870,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
817
870
|
page?: number,
|
|
818
871
|
referenceBlock?: BlockHash,
|
|
819
872
|
): Promise<TxScopedL2Log[][]> {
|
|
873
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
820
874
|
if (referenceBlock) {
|
|
821
875
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
822
|
-
if (
|
|
876
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
877
|
+
upToBlockNumber = BlockNumber(0);
|
|
878
|
+
} else {
|
|
823
879
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
824
880
|
if (!header) {
|
|
825
881
|
throw new Error(
|
|
826
882
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
827
883
|
);
|
|
828
884
|
}
|
|
885
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
829
886
|
}
|
|
830
887
|
}
|
|
831
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
888
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
832
889
|
}
|
|
833
890
|
|
|
834
891
|
/**
|
|
@@ -914,7 +971,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
914
971
|
await tryStop(this.validatorsSentinel);
|
|
915
972
|
await tryStop(this.epochPruneWatcher);
|
|
916
973
|
await tryStop(this.slasherClient);
|
|
917
|
-
await tryStop(this.
|
|
974
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
918
975
|
await tryStop(this.sequencer);
|
|
919
976
|
await tryStop(this.proverNode);
|
|
920
977
|
await tryStop(this.p2pClient);
|
|
@@ -970,7 +1027,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
970
1027
|
treeId: MerkleTreeId,
|
|
971
1028
|
leafValues: Fr[],
|
|
972
1029
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
973
|
-
const committedDb = await this
|
|
1030
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
974
1031
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
975
1032
|
treeId,
|
|
976
1033
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -1004,7 +1061,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1004
1061
|
);
|
|
1005
1062
|
|
|
1006
1063
|
// Build a map from block number to block hash
|
|
1007
|
-
const blockNumberToHash = new Map<BlockNumber,
|
|
1064
|
+
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
1008
1065
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1009
1066
|
const blockHash = blockHashes[i];
|
|
1010
1067
|
if (blockHash === undefined) {
|
|
@@ -1022,13 +1079,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1022
1079
|
if (blockNumber === undefined) {
|
|
1023
1080
|
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1024
1081
|
}
|
|
1025
|
-
const
|
|
1026
|
-
if (
|
|
1082
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1083
|
+
if (l2BlockHash === undefined) {
|
|
1027
1084
|
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1028
1085
|
}
|
|
1029
1086
|
return {
|
|
1030
1087
|
l2BlockNumber: blockNumber,
|
|
1031
|
-
l2BlockHash
|
|
1088
|
+
l2BlockHash,
|
|
1032
1089
|
data: index,
|
|
1033
1090
|
};
|
|
1034
1091
|
});
|
|
@@ -1038,7 +1095,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1038
1095
|
referenceBlock: BlockParameter,
|
|
1039
1096
|
blockHash: BlockHash,
|
|
1040
1097
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1041
|
-
|
|
1098
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1099
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1100
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1101
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1102
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1103
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1104
|
+
return undefined;
|
|
1105
|
+
}
|
|
1106
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1042
1107
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1043
1108
|
return pathAndIndex === undefined
|
|
1044
1109
|
? undefined
|
|
@@ -1049,7 +1114,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1049
1114
|
referenceBlock: BlockParameter,
|
|
1050
1115
|
noteHash: Fr,
|
|
1051
1116
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1052
|
-
const committedDb = await this
|
|
1117
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1053
1118
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1054
1119
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
1055
1120
|
[noteHash],
|
|
@@ -1063,7 +1128,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1063
1128
|
referenceBlock: BlockParameter,
|
|
1064
1129
|
l1ToL2Message: Fr,
|
|
1065
1130
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1066
|
-
const db = await this
|
|
1131
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1067
1132
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1068
1133
|
if (!witness) {
|
|
1069
1134
|
return undefined;
|
|
@@ -1096,19 +1161,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1096
1161
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1097
1162
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1098
1163
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1099
|
-
const blocksInCheckpoints
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1103
|
-
const block = checkpointedBlock.block;
|
|
1104
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1105
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1106
|
-
checkpointIndex++;
|
|
1107
|
-
blocksInCheckpoints.push([]);
|
|
1108
|
-
previousSlotNumber = slotNumber;
|
|
1109
|
-
}
|
|
1110
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1111
|
-
}
|
|
1164
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1165
|
+
group => group.map(cb => cb.block),
|
|
1166
|
+
);
|
|
1112
1167
|
return blocksInCheckpoints.map(blocks =>
|
|
1113
1168
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1114
1169
|
);
|
|
@@ -1118,7 +1173,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1118
1173
|
referenceBlock: BlockParameter,
|
|
1119
1174
|
nullifier: Fr,
|
|
1120
1175
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1121
|
-
const db = await this
|
|
1176
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1122
1177
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1123
1178
|
if (!witness) {
|
|
1124
1179
|
return undefined;
|
|
@@ -1133,33 +1188,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1133
1188
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1134
1189
|
}
|
|
1135
1190
|
|
|
1136
|
-
/**
|
|
1137
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1138
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1139
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1140
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1141
|
-
* @returns The low nullifier membership witness (if found).
|
|
1142
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1143
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1144
|
-
* we are trying to prove non-inclusion for.
|
|
1145
|
-
*
|
|
1146
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1147
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1148
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1149
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1150
|
-
*/
|
|
1151
1191
|
public async getLowNullifierMembershipWitness(
|
|
1152
1192
|
referenceBlock: BlockParameter,
|
|
1153
1193
|
nullifier: Fr,
|
|
1154
1194
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1155
|
-
const committedDb = await this
|
|
1195
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1156
1196
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1157
1197
|
if (!findResult) {
|
|
1158
1198
|
return undefined;
|
|
1159
1199
|
}
|
|
1160
1200
|
const { index, alreadyPresent } = findResult;
|
|
1161
1201
|
if (alreadyPresent) {
|
|
1162
|
-
|
|
1202
|
+
throw new Error(
|
|
1203
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1204
|
+
);
|
|
1163
1205
|
}
|
|
1164
1206
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1165
1207
|
|
|
@@ -1168,7 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1210
|
}
|
|
1169
1211
|
|
|
1170
1212
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1171
|
-
const committedDb = await this
|
|
1213
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1172
1214
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1173
1215
|
if (!lowLeafResult) {
|
|
1174
1216
|
return undefined;
|
|
@@ -1183,7 +1225,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1183
1225
|
}
|
|
1184
1226
|
|
|
1185
1227
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1186
|
-
const committedDb = await this
|
|
1228
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1187
1229
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1188
1230
|
|
|
1189
1231
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1323,7 +1365,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1323
1365
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1324
1366
|
): Promise<TxValidationResult> {
|
|
1325
1367
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1326
|
-
const verifier = isSimulation ? undefined : this.
|
|
1368
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1327
1369
|
|
|
1328
1370
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1329
1371
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -1372,7 +1414,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1372
1414
|
archiver.updateConfig(config);
|
|
1373
1415
|
}
|
|
1374
1416
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1375
|
-
|
|
1417
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1418
|
+
if (newConfig.realProofs) {
|
|
1419
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1420
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1421
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1422
|
+
} else {
|
|
1423
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1424
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1425
|
+
}
|
|
1376
1426
|
}
|
|
1377
1427
|
|
|
1378
1428
|
this.config = newConfig;
|
|
@@ -1447,7 +1497,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1447
1497
|
return Promise.resolve();
|
|
1448
1498
|
}
|
|
1449
1499
|
|
|
1450
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1500
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1451
1501
|
const archiver = this.blockSource as Archiver;
|
|
1452
1502
|
if (!('rollbackTo' in archiver)) {
|
|
1453
1503
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1477,9 +1527,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1477
1527
|
this.log.error(`Error during rollback`, err);
|
|
1478
1528
|
throw err;
|
|
1479
1529
|
} finally {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1530
|
+
if (resumeSync) {
|
|
1531
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1532
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1533
|
+
archiver.resume();
|
|
1534
|
+
} else {
|
|
1535
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1536
|
+
}
|
|
1483
1537
|
}
|
|
1484
1538
|
}
|
|
1485
1539
|
|
|
@@ -1496,19 +1550,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1496
1550
|
return Promise.resolve();
|
|
1497
1551
|
}
|
|
1498
1552
|
|
|
1499
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
1500
|
-
if (!this.slasherClient) {
|
|
1501
|
-
throw new Error(`Slasher client not enabled`);
|
|
1502
|
-
}
|
|
1503
|
-
return this.slasherClient.getSlashPayloads();
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
1553
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
1507
1554
|
if (!this.slasherClient) {
|
|
1508
1555
|
throw new Error(`Slasher client not enabled`);
|
|
1509
1556
|
}
|
|
1510
1557
|
if (round === 'all') {
|
|
1511
|
-
return this.slasherClient.
|
|
1558
|
+
return this.slasherClient.getOffenses();
|
|
1512
1559
|
} else {
|
|
1513
1560
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1514
1561
|
}
|
|
@@ -1602,6 +1649,40 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1602
1649
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1603
1650
|
}
|
|
1604
1651
|
|
|
1652
|
+
public async mineBlock(): Promise<void> {
|
|
1653
|
+
if (!this.sequencer) {
|
|
1654
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1658
|
+
|
|
1659
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1660
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1661
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1662
|
+
|
|
1663
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1664
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1665
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1666
|
+
|
|
1667
|
+
try {
|
|
1668
|
+
// Trigger the sequencer to produce a block immediately
|
|
1669
|
+
void this.sequencer.trigger();
|
|
1670
|
+
|
|
1671
|
+
// Wait for the new L2 block to appear
|
|
1672
|
+
await retryUntil(
|
|
1673
|
+
async () => {
|
|
1674
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1675
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1676
|
+
},
|
|
1677
|
+
'mineBlock',
|
|
1678
|
+
timeoutSeconds,
|
|
1679
|
+
0.1,
|
|
1680
|
+
);
|
|
1681
|
+
} finally {
|
|
1682
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1605
1686
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1606
1687
|
if (!this.initialHeaderHashPromise) {
|
|
1607
1688
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1614,7 +1695,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1614
1695
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1615
1696
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1616
1697
|
*/
|
|
1617
|
-
async
|
|
1698
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1618
1699
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1619
1700
|
try {
|
|
1620
1701
|
// Attempt to sync the world state if necessary
|
|
@@ -1628,6 +1709,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1628
1709
|
return this.worldStateSynchronizer.getCommitted();
|
|
1629
1710
|
}
|
|
1630
1711
|
|
|
1712
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1713
|
+
let blockNumber: BlockNumber;
|
|
1631
1714
|
if (BlockHash.isBlockHash(block)) {
|
|
1632
1715
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1633
1716
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1641,22 +1724,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1641
1724
|
`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.`,
|
|
1642
1725
|
);
|
|
1643
1726
|
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1727
|
+
|
|
1728
|
+
blockNumber = header.getBlockNumber();
|
|
1729
|
+
} else {
|
|
1730
|
+
blockNumber = block as BlockNumber;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// Check it's within world state sync range
|
|
1734
|
+
if (blockNumber > blockSyncedTo) {
|
|
1735
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1647
1736
|
}
|
|
1737
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1648
1738
|
|
|
1649
|
-
|
|
1650
|
-
{
|
|
1651
|
-
const blockNumber = block as BlockNumber;
|
|
1739
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1652
1740
|
|
|
1653
|
-
|
|
1654
|
-
|
|
1741
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1742
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1743
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1744
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1745
|
+
throw new Error(
|
|
1746
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1747
|
+
);
|
|
1655
1748
|
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
return snapshot;
|
|
1752
|
+
}
|
|
1656
1753
|
|
|
1657
|
-
|
|
1658
|
-
|
|
1754
|
+
/** Resolves a block parameter to a block number. */
|
|
1755
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1756
|
+
if (block === 'latest') {
|
|
1757
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1758
|
+
}
|
|
1759
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1760
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1761
|
+
if (block.equals(initialBlockHash)) {
|
|
1762
|
+
return BlockNumber.ZERO;
|
|
1763
|
+
}
|
|
1764
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1765
|
+
if (!header) {
|
|
1766
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1767
|
+
}
|
|
1768
|
+
return header.getBlockNumber();
|
|
1659
1769
|
}
|
|
1770
|
+
return block as BlockNumber;
|
|
1660
1771
|
}
|
|
1661
1772
|
|
|
1662
1773
|
/**
|