@aztec/aztec-node 0.0.1-commit.8afd444 → 0.0.1-commit.8c0b8ff
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 +7 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +10 -2
- package/dest/aztec-node/server.d.ts +35 -24
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +388 -167
- package/dest/sentinel/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +56 -30
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +27 -25
- package/src/aztec-node/config.ts +24 -8
- package/src/aztec-node/server.ts +469 -179
- package/src/sentinel/sentinel.ts +59 -26
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
3
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
+
import { Blob } from '@aztec/blob-lib';
|
|
4
5
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
5
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
6
7
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
7
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
8
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
8
9
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
9
10
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
10
11
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
12
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
12
13
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
15
16
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
16
18
|
import { count } from '@aztec/foundation/string';
|
|
17
19
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
18
20
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
19
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
21
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
22
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
23
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
21
24
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
type P2P,
|
|
26
|
+
type P2PClientDeps,
|
|
27
|
+
createP2PClient,
|
|
28
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
29
|
+
getDefaultAllowedSetupFunctions,
|
|
30
|
+
} from '@aztec/p2p';
|
|
26
31
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
32
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
33
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
27
34
|
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
28
35
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
29
36
|
import {
|
|
@@ -35,7 +42,14 @@ import {
|
|
|
35
42
|
} from '@aztec/slasher';
|
|
36
43
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
37
44
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
38
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
type BlockData,
|
|
47
|
+
BlockHash,
|
|
48
|
+
type BlockParameter,
|
|
49
|
+
type DataInBlock,
|
|
50
|
+
L2Block,
|
|
51
|
+
type L2BlockSource,
|
|
52
|
+
} from '@aztec/stdlib/block';
|
|
39
53
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
40
54
|
import type {
|
|
41
55
|
ContractClassPublic,
|
|
@@ -51,6 +65,7 @@ import {
|
|
|
51
65
|
type AztecNodeAdmin,
|
|
52
66
|
type AztecNodeAdminConfig,
|
|
53
67
|
AztecNodeAdminConfigSchema,
|
|
68
|
+
type AztecNodeDebug,
|
|
54
69
|
type GetContractClassLogsResponse,
|
|
55
70
|
type GetPublicLogsResponse,
|
|
56
71
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -63,9 +78,9 @@ import {
|
|
|
63
78
|
type WorldStateSynchronizer,
|
|
64
79
|
tryStop,
|
|
65
80
|
} from '@aztec/stdlib/interfaces/server';
|
|
66
|
-
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
81
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
82
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
67
83
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
68
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
69
84
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
70
85
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
71
86
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -95,13 +110,13 @@ import {
|
|
|
95
110
|
FullNodeCheckpointsBuilder,
|
|
96
111
|
NodeKeystoreAdapter,
|
|
97
112
|
ValidatorClient,
|
|
98
|
-
|
|
113
|
+
createProposalHandler,
|
|
99
114
|
createValidatorClient,
|
|
100
|
-
createValidatorForAcceptingTxs,
|
|
101
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
102
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
103
118
|
|
|
104
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
105
120
|
|
|
106
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
107
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -111,7 +126,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
111
126
|
/**
|
|
112
127
|
* The aztec node.
|
|
113
128
|
*/
|
|
114
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
129
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
115
130
|
private metrics: NodeMetrics;
|
|
116
131
|
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
117
132
|
|
|
@@ -129,6 +144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
129
144
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
130
145
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
131
146
|
protected readonly sequencer: SequencerClient | undefined,
|
|
147
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
132
148
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
133
149
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
134
150
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -141,12 +157,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
141
157
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
142
158
|
private log = createLogger('node'),
|
|
143
159
|
private blobClient?: BlobClientInterface,
|
|
160
|
+
private validatorClient?: ValidatorClient,
|
|
161
|
+
private keyStoreManager?: KeystoreManager,
|
|
162
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
144
163
|
) {
|
|
145
164
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
146
165
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
147
166
|
|
|
148
167
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
149
168
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
169
|
+
|
|
170
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
171
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
172
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
173
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
174
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
175
|
+
}
|
|
150
176
|
}
|
|
151
177
|
|
|
152
178
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -170,11 +196,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
170
196
|
logger?: Logger;
|
|
171
197
|
publisher?: SequencerPublisher;
|
|
172
198
|
dateProvider?: DateProvider;
|
|
173
|
-
p2pClientDeps?: P2PClientDeps
|
|
199
|
+
p2pClientDeps?: P2PClientDeps;
|
|
200
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
201
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
174
202
|
} = {},
|
|
175
203
|
options: {
|
|
176
204
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
177
205
|
dontStartSequencer?: boolean;
|
|
206
|
+
dontStartProverNode?: boolean;
|
|
178
207
|
} = {},
|
|
179
208
|
): Promise<AztecNodeService> {
|
|
180
209
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -184,16 +213,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
213
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
185
214
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
186
215
|
|
|
187
|
-
// Build a key store from file if given or from environment otherwise
|
|
216
|
+
// Build a key store from file if given or from environment otherwise.
|
|
217
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
188
218
|
let keyStoreManager: KeystoreManager | undefined;
|
|
189
219
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
190
220
|
if (keyStoreProvided) {
|
|
191
221
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
192
222
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
193
223
|
} else {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
224
|
+
const rawKeyStores: KeyStore[] = [];
|
|
225
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
226
|
+
if (validatorKeyStore) {
|
|
227
|
+
rawKeyStores.push(validatorKeyStore);
|
|
228
|
+
}
|
|
229
|
+
if (config.enableProverNode) {
|
|
230
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
231
|
+
if (proverKeyStore) {
|
|
232
|
+
rawKeyStores.push(proverKeyStore);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (rawKeyStores.length > 0) {
|
|
236
|
+
keyStoreManager = new KeystoreManager(
|
|
237
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
238
|
+
);
|
|
197
239
|
}
|
|
198
240
|
}
|
|
199
241
|
|
|
@@ -204,10 +246,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
204
246
|
if (keyStoreManager === undefined) {
|
|
205
247
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
206
248
|
}
|
|
207
|
-
if (!keyStoreProvided) {
|
|
208
|
-
log.warn(
|
|
209
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
210
|
-
);
|
|
249
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
250
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
211
251
|
}
|
|
212
252
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
213
253
|
}
|
|
@@ -221,7 +261,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
221
261
|
|
|
222
262
|
const publicClient = createPublicClient({
|
|
223
263
|
chain: ethereumChain.chainInfo,
|
|
224
|
-
transport:
|
|
264
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
225
265
|
pollingInterval: config.viemPollingIntervalMS,
|
|
226
266
|
});
|
|
227
267
|
|
|
@@ -235,10 +275,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
235
275
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
236
276
|
|
|
237
277
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
238
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
278
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
239
279
|
rollupContract.getL1GenesisTime(),
|
|
240
280
|
rollupContract.getSlotDuration(),
|
|
241
281
|
rollupContract.getVersion(),
|
|
282
|
+
rollupContract.getManaLimit().then(Number),
|
|
242
283
|
] as const);
|
|
243
284
|
|
|
244
285
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -249,7 +290,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
249
290
|
);
|
|
250
291
|
}
|
|
251
292
|
|
|
252
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
293
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
253
294
|
|
|
254
295
|
// attempt snapshot sync if possible
|
|
255
296
|
await trySnapshotSync(config, log);
|
|
@@ -273,14 +314,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
273
314
|
config.realProofs || config.debugForceTxProofVerification
|
|
274
315
|
? await BBCircuitVerifier.new(config)
|
|
275
316
|
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
317
|
+
|
|
318
|
+
let debugLogStore: DebugLogStore;
|
|
276
319
|
if (!config.realProofs) {
|
|
277
320
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
321
|
+
|
|
322
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
323
|
+
log.info(
|
|
324
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
debugLogStore = new NullDebugLogStore();
|
|
278
328
|
}
|
|
329
|
+
|
|
279
330
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
280
331
|
|
|
332
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
333
|
+
if (proverOnly) {
|
|
334
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
335
|
+
}
|
|
336
|
+
|
|
281
337
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
282
338
|
const p2pClient = await createP2PClient(
|
|
283
|
-
P2PClientType.Full,
|
|
284
339
|
config,
|
|
285
340
|
archiver,
|
|
286
341
|
proofVerifier,
|
|
@@ -292,59 +347,72 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
292
347
|
deps.p2pClientDeps,
|
|
293
348
|
);
|
|
294
349
|
|
|
295
|
-
// We
|
|
296
|
-
|
|
350
|
+
// We'll accumulate sentinel watchers here
|
|
351
|
+
const watchers: Watcher[] = [];
|
|
297
352
|
|
|
298
|
-
// Create FullNodeCheckpointsBuilder for
|
|
353
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
354
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
299
355
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
300
|
-
{
|
|
356
|
+
{
|
|
357
|
+
...config,
|
|
358
|
+
l1GenesisTime,
|
|
359
|
+
slotDuration: Number(slotDuration),
|
|
360
|
+
rollupManaLimit,
|
|
361
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
362
|
+
},
|
|
301
363
|
worldStateSynchronizer,
|
|
302
364
|
archiver,
|
|
303
365
|
dateProvider,
|
|
304
366
|
telemetry,
|
|
305
367
|
);
|
|
306
368
|
|
|
307
|
-
|
|
308
|
-
const watchers: Watcher[] = [];
|
|
369
|
+
let validatorClient: ValidatorClient | undefined;
|
|
309
370
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
371
|
+
if (!proverOnly) {
|
|
372
|
+
// Create validator client if required
|
|
373
|
+
validatorClient = await createValidatorClient(config, {
|
|
374
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
375
|
+
worldState: worldStateSynchronizer,
|
|
376
|
+
p2pClient,
|
|
377
|
+
telemetry,
|
|
378
|
+
dateProvider,
|
|
379
|
+
epochCache,
|
|
380
|
+
blockSource: archiver,
|
|
381
|
+
l1ToL2MessageSource: archiver,
|
|
382
|
+
keyStoreManager,
|
|
383
|
+
blobClient,
|
|
384
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
385
|
+
});
|
|
323
386
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
387
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
388
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
389
|
+
// like attestations or auths will fail.
|
|
390
|
+
if (validatorClient) {
|
|
391
|
+
watchers.push(validatorClient);
|
|
392
|
+
if (!options.dontStartSequencer) {
|
|
393
|
+
await validatorClient.registerHandlers();
|
|
394
|
+
}
|
|
331
395
|
}
|
|
332
396
|
}
|
|
333
397
|
|
|
334
|
-
// If there's no validator client
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
398
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
399
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
400
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
401
|
+
// Checkpoint proposals are handled if the blob client can upload blobs.
|
|
402
|
+
if (!validatorClient) {
|
|
403
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
404
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
405
|
+
createProposalHandler(config, {
|
|
339
406
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
340
407
|
worldState: worldStateSynchronizer,
|
|
341
408
|
epochCache,
|
|
342
409
|
blockSource: archiver,
|
|
343
410
|
l1ToL2MessageSource: archiver,
|
|
344
411
|
p2pClient,
|
|
412
|
+
blobClient,
|
|
345
413
|
dateProvider,
|
|
346
414
|
telemetry,
|
|
347
|
-
}).
|
|
415
|
+
}).register(p2pClient, reexecute);
|
|
348
416
|
}
|
|
349
417
|
|
|
350
418
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -353,29 +421,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
353
421
|
// Start p2p. Note that it depends on world state to be running.
|
|
354
422
|
await p2pClient.start();
|
|
355
423
|
|
|
356
|
-
|
|
357
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
358
|
-
watchers.push(validatorsSentinel);
|
|
359
|
-
}
|
|
360
|
-
|
|
424
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
361
425
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
362
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
363
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
364
|
-
archiver,
|
|
365
|
-
archiver,
|
|
366
|
-
epochCache,
|
|
367
|
-
p2pClient.getTxProvider(),
|
|
368
|
-
validatorCheckpointsBuilder,
|
|
369
|
-
config,
|
|
370
|
-
);
|
|
371
|
-
watchers.push(epochPruneWatcher);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
375
426
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
427
|
+
|
|
428
|
+
if (!proverOnly) {
|
|
429
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
430
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
431
|
+
watchers.push(validatorsSentinel);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
435
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
436
|
+
archiver,
|
|
437
|
+
archiver,
|
|
438
|
+
epochCache,
|
|
439
|
+
p2pClient.getTxProvider(),
|
|
440
|
+
validatorCheckpointsBuilder,
|
|
441
|
+
config,
|
|
442
|
+
);
|
|
443
|
+
watchers.push(epochPruneWatcher);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
447
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
448
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
449
|
+
watchers.push(attestationsBlockWatcher);
|
|
450
|
+
}
|
|
379
451
|
}
|
|
380
452
|
|
|
381
453
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -390,6 +462,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
390
462
|
})
|
|
391
463
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
392
464
|
|
|
465
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, {
|
|
466
|
+
l1Contracts: config.l1Contracts,
|
|
467
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
468
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
469
|
+
l1GenesisTime,
|
|
470
|
+
slotDuration: Number(slotDuration),
|
|
471
|
+
});
|
|
472
|
+
|
|
393
473
|
// Validator enabled, create/start relevant service
|
|
394
474
|
let sequencer: SequencerClient | undefined;
|
|
395
475
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -412,28 +492,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
412
492
|
);
|
|
413
493
|
await slasherClient.start();
|
|
414
494
|
|
|
415
|
-
const l1TxUtils = config.
|
|
416
|
-
? await
|
|
495
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
496
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
417
497
|
publicClient,
|
|
418
498
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
419
|
-
config.
|
|
499
|
+
config.sequencerPublisherForwarderAddress,
|
|
420
500
|
{ ...config, scope: 'sequencer' },
|
|
421
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
501
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
422
502
|
)
|
|
423
|
-
: await
|
|
503
|
+
: await createL1TxUtilsFromSigners(
|
|
424
504
|
publicClient,
|
|
425
505
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
426
506
|
{ ...config, scope: 'sequencer' },
|
|
427
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
507
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
428
508
|
);
|
|
429
509
|
|
|
430
510
|
// Create and start the sequencer client
|
|
431
511
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
432
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
512
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
433
513
|
worldStateSynchronizer,
|
|
434
514
|
archiver,
|
|
435
515
|
dateProvider,
|
|
436
516
|
telemetry,
|
|
517
|
+
debugLogStore,
|
|
437
518
|
);
|
|
438
519
|
|
|
439
520
|
sequencer = await SequencerClient.new(config, {
|
|
@@ -451,6 +532,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
451
532
|
dateProvider,
|
|
452
533
|
blobClient,
|
|
453
534
|
nodeKeyStore: keyStoreManager!,
|
|
535
|
+
globalVariableBuilder,
|
|
454
536
|
});
|
|
455
537
|
}
|
|
456
538
|
|
|
@@ -461,14 +543,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
461
543
|
log.warn(`Sequencer created but not started`);
|
|
462
544
|
}
|
|
463
545
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
546
|
+
// Create prover node subsystem if enabled
|
|
547
|
+
let proverNode: ProverNode | undefined;
|
|
548
|
+
if (config.enableProverNode) {
|
|
549
|
+
proverNode = await createProverNode(config, {
|
|
550
|
+
...deps.proverNodeDeps,
|
|
551
|
+
telemetry,
|
|
552
|
+
dateProvider,
|
|
553
|
+
archiver,
|
|
554
|
+
worldStateSynchronizer,
|
|
555
|
+
p2pClient,
|
|
556
|
+
epochCache,
|
|
557
|
+
blobClient,
|
|
558
|
+
keyStoreManager,
|
|
559
|
+
});
|
|
470
560
|
|
|
471
|
-
|
|
561
|
+
if (!options.dontStartProverNode) {
|
|
562
|
+
await proverNode.start();
|
|
563
|
+
log.info(`Prover node subsystem started`);
|
|
564
|
+
} else {
|
|
565
|
+
log.info(`Prover node subsystem created but not started`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const node = new AztecNodeService(
|
|
472
570
|
config,
|
|
473
571
|
p2pClient,
|
|
474
572
|
archiver,
|
|
@@ -477,6 +575,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
477
575
|
archiver,
|
|
478
576
|
worldStateSynchronizer,
|
|
479
577
|
sequencer,
|
|
578
|
+
proverNode,
|
|
480
579
|
slasherClient,
|
|
481
580
|
validatorsSentinel,
|
|
482
581
|
epochPruneWatcher,
|
|
@@ -489,7 +588,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
489
588
|
telemetry,
|
|
490
589
|
log,
|
|
491
590
|
blobClient,
|
|
591
|
+
validatorClient,
|
|
592
|
+
keyStoreManager,
|
|
593
|
+
debugLogStore,
|
|
492
594
|
);
|
|
595
|
+
|
|
596
|
+
return node;
|
|
493
597
|
}
|
|
494
598
|
|
|
495
599
|
/**
|
|
@@ -500,6 +604,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
500
604
|
return this.sequencer;
|
|
501
605
|
}
|
|
502
606
|
|
|
607
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
608
|
+
public getProverNode(): ProverNode | undefined {
|
|
609
|
+
return this.proverNode;
|
|
610
|
+
}
|
|
611
|
+
|
|
503
612
|
public getBlockSource(): L2BlockSource {
|
|
504
613
|
return this.blockSource;
|
|
505
614
|
}
|
|
@@ -525,7 +634,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
525
634
|
}
|
|
526
635
|
|
|
527
636
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
528
|
-
return this.config.
|
|
637
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
529
638
|
}
|
|
530
639
|
|
|
531
640
|
/**
|
|
@@ -553,6 +662,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
553
662
|
enr,
|
|
554
663
|
l1ContractAddresses: contractAddresses,
|
|
555
664
|
protocolContractAddresses: protocolContractAddresses,
|
|
665
|
+
realProofs: !!this.config.realProofs,
|
|
556
666
|
};
|
|
557
667
|
|
|
558
668
|
return nodeInfo;
|
|
@@ -619,6 +729,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
619
729
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
620
730
|
}
|
|
621
731
|
|
|
732
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
733
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
734
|
+
}
|
|
735
|
+
|
|
622
736
|
/**
|
|
623
737
|
* Method to fetch the current min L2 fees.
|
|
624
738
|
* @returns The current min L2 fees.
|
|
@@ -651,6 +765,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
651
765
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
652
766
|
}
|
|
653
767
|
|
|
768
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
769
|
+
return this.blockSource.getCheckpointNumber();
|
|
770
|
+
}
|
|
771
|
+
|
|
654
772
|
/**
|
|
655
773
|
* Method to fetch the version of the package.
|
|
656
774
|
* @returns The node package version
|
|
@@ -761,8 +879,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
761
879
|
}
|
|
762
880
|
|
|
763
881
|
await this.p2pClient!.sendTx(tx);
|
|
764
|
-
|
|
765
|
-
this.
|
|
882
|
+
const duration = timer.ms();
|
|
883
|
+
this.metrics.receivedTx(duration, true);
|
|
884
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
766
885
|
}
|
|
767
886
|
|
|
768
887
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
@@ -774,18 +893,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
774
893
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
775
894
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
776
895
|
|
|
896
|
+
let receipt: TxReceipt;
|
|
777
897
|
if (settledTxReceipt) {
|
|
778
|
-
|
|
779
|
-
return settledTxReceipt;
|
|
898
|
+
receipt = settledTxReceipt;
|
|
780
899
|
} else if (isKnownToPool) {
|
|
781
900
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
782
901
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
783
902
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
784
|
-
|
|
903
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
785
904
|
} else {
|
|
786
905
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
787
|
-
|
|
906
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
788
907
|
}
|
|
908
|
+
|
|
909
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
910
|
+
|
|
911
|
+
return receipt;
|
|
789
912
|
}
|
|
790
913
|
|
|
791
914
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -802,6 +925,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
802
925
|
await tryStop(this.slasherClient);
|
|
803
926
|
await tryStop(this.proofVerifier);
|
|
804
927
|
await tryStop(this.sequencer);
|
|
928
|
+
await tryStop(this.proverNode);
|
|
805
929
|
await tryStop(this.p2pClient);
|
|
806
930
|
await tryStop(this.worldStateSynchronizer);
|
|
807
931
|
await tryStop(this.blockSource);
|
|
@@ -855,58 +979,64 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
855
979
|
treeId: MerkleTreeId,
|
|
856
980
|
leafValues: Fr[],
|
|
857
981
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
858
|
-
const committedDb = await this
|
|
982
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
859
983
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
860
984
|
treeId,
|
|
861
985
|
leafValues.map(x => x.toBuffer()),
|
|
862
986
|
);
|
|
863
|
-
//
|
|
864
|
-
const
|
|
987
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
988
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
865
989
|
|
|
866
|
-
// Now we find the block numbers for the indices
|
|
867
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
990
|
+
// Now we find the block numbers for the defined indices
|
|
991
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
868
992
|
|
|
869
|
-
//
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
993
|
+
// Build a map from leaf index to block number
|
|
994
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
995
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
996
|
+
const blockNumber = blockNumbers[i];
|
|
997
|
+
if (blockNumber === undefined) {
|
|
998
|
+
throw new Error(
|
|
999
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1000
|
+
);
|
|
873
1001
|
}
|
|
1002
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
874
1003
|
}
|
|
875
1004
|
|
|
876
1005
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
877
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1006
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
878
1007
|
|
|
879
|
-
// Now we obtain the block hashes from the archive tree
|
|
880
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1008
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
881
1009
|
const blockHashes = await Promise.all(
|
|
882
1010
|
uniqueBlockNumbers.map(blockNumber => {
|
|
883
1011
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
884
1012
|
}),
|
|
885
1013
|
);
|
|
886
1014
|
|
|
887
|
-
//
|
|
1015
|
+
// Build a map from block number to block hash
|
|
1016
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
888
1017
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
889
|
-
|
|
1018
|
+
const blockHash = blockHashes[i];
|
|
1019
|
+
if (blockHash === undefined) {
|
|
890
1020
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
891
1021
|
}
|
|
1022
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
892
1023
|
}
|
|
893
1024
|
|
|
894
1025
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
895
|
-
return maybeIndices.map(
|
|
1026
|
+
return maybeIndices.map(index => {
|
|
896
1027
|
if (index === undefined) {
|
|
897
1028
|
return undefined;
|
|
898
1029
|
}
|
|
899
|
-
const blockNumber =
|
|
1030
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
900
1031
|
if (blockNumber === undefined) {
|
|
901
|
-
|
|
1032
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
902
1033
|
}
|
|
903
|
-
const
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
return undefined;
|
|
1034
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1035
|
+
if (blockHash === undefined) {
|
|
1036
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
907
1037
|
}
|
|
908
1038
|
return {
|
|
909
|
-
l2BlockNumber:
|
|
1039
|
+
l2BlockNumber: blockNumber,
|
|
910
1040
|
l2BlockHash: new BlockHash(blockHash),
|
|
911
1041
|
data: index,
|
|
912
1042
|
};
|
|
@@ -917,7 +1047,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
917
1047
|
referenceBlock: BlockParameter,
|
|
918
1048
|
blockHash: BlockHash,
|
|
919
1049
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
920
|
-
|
|
1050
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1051
|
+
if (referenceBlock === BlockNumber.ZERO) {
|
|
1052
|
+
return undefined;
|
|
1053
|
+
}
|
|
1054
|
+
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1055
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1056
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
1057
|
+
return undefined;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1061
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1062
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1063
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1064
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
921
1065
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
922
1066
|
return pathAndIndex === undefined
|
|
923
1067
|
? undefined
|
|
@@ -928,7 +1072,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
928
1072
|
referenceBlock: BlockParameter,
|
|
929
1073
|
noteHash: Fr,
|
|
930
1074
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
931
|
-
const committedDb = await this
|
|
1075
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
932
1076
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
933
1077
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
934
1078
|
[noteHash],
|
|
@@ -942,7 +1086,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
942
1086
|
referenceBlock: BlockParameter,
|
|
943
1087
|
l1ToL2Message: Fr,
|
|
944
1088
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
945
|
-
const db = await this
|
|
1089
|
+
const db = await this.getWorldState(referenceBlock);
|
|
946
1090
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
947
1091
|
if (!witness) {
|
|
948
1092
|
return undefined;
|
|
@@ -952,11 +1096,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
952
1096
|
return [witness.index, witness.path];
|
|
953
1097
|
}
|
|
954
1098
|
|
|
955
|
-
public async
|
|
1099
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
956
1100
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
957
|
-
return messageIndex
|
|
958
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
959
|
-
: undefined;
|
|
1101
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
960
1102
|
}
|
|
961
1103
|
|
|
962
1104
|
/**
|
|
@@ -977,19 +1119,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
977
1119
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
978
1120
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
979
1121
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
980
|
-
const blocksInCheckpoints
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
984
|
-
const block = checkpointedBlock.block;
|
|
985
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
986
|
-
if (slotNumber !== previousSlotNumber) {
|
|
987
|
-
checkpointIndex++;
|
|
988
|
-
blocksInCheckpoints.push([]);
|
|
989
|
-
previousSlotNumber = slotNumber;
|
|
990
|
-
}
|
|
991
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
992
|
-
}
|
|
1122
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1123
|
+
group => group.map(cb => cb.block),
|
|
1124
|
+
);
|
|
993
1125
|
return blocksInCheckpoints.map(blocks =>
|
|
994
1126
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
995
1127
|
);
|
|
@@ -999,7 +1131,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
999
1131
|
referenceBlock: BlockParameter,
|
|
1000
1132
|
nullifier: Fr,
|
|
1001
1133
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1002
|
-
const db = await this
|
|
1134
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1003
1135
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1004
1136
|
if (!witness) {
|
|
1005
1137
|
return undefined;
|
|
@@ -1014,33 +1146,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1146
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1015
1147
|
}
|
|
1016
1148
|
|
|
1017
|
-
/**
|
|
1018
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1019
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1020
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1021
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1022
|
-
* @returns The low nullifier membership witness (if found).
|
|
1023
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1024
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1025
|
-
* we are trying to prove non-inclusion for.
|
|
1026
|
-
*
|
|
1027
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1028
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1029
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1030
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1031
|
-
*/
|
|
1032
1149
|
public async getLowNullifierMembershipWitness(
|
|
1033
1150
|
referenceBlock: BlockParameter,
|
|
1034
1151
|
nullifier: Fr,
|
|
1035
1152
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1036
|
-
const committedDb = await this
|
|
1153
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1037
1154
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1038
1155
|
if (!findResult) {
|
|
1039
1156
|
return undefined;
|
|
1040
1157
|
}
|
|
1041
1158
|
const { index, alreadyPresent } = findResult;
|
|
1042
1159
|
if (alreadyPresent) {
|
|
1043
|
-
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1162
|
+
);
|
|
1044
1163
|
}
|
|
1045
1164
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1046
1165
|
|
|
@@ -1049,7 +1168,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1049
1168
|
}
|
|
1050
1169
|
|
|
1051
1170
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1052
|
-
const committedDb = await this
|
|
1171
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1053
1172
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1054
1173
|
if (!lowLeafResult) {
|
|
1055
1174
|
return undefined;
|
|
@@ -1064,7 +1183,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1064
1183
|
}
|
|
1065
1184
|
|
|
1066
1185
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1067
|
-
const committedDb = await this
|
|
1186
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1068
1187
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1069
1188
|
|
|
1070
1189
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1105,6 +1224,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1105
1224
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1106
1225
|
}
|
|
1107
1226
|
|
|
1227
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1228
|
+
return this.blockSource.getBlockData(number);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1232
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1108
1235
|
/**
|
|
1109
1236
|
* Simulates the public part of a transaction with the current state.
|
|
1110
1237
|
* @param tx - The transaction to simulate.
|
|
@@ -1128,7 +1255,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1128
1255
|
}
|
|
1129
1256
|
|
|
1130
1257
|
const txHash = tx.getTxHash();
|
|
1131
|
-
const
|
|
1258
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1259
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1132
1260
|
|
|
1133
1261
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1134
1262
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1152,6 +1280,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1152
1280
|
blockNumber,
|
|
1153
1281
|
});
|
|
1154
1282
|
|
|
1283
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1284
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1155
1285
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1156
1286
|
try {
|
|
1157
1287
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1167,7 +1297,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1167
1297
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1168
1298
|
|
|
1169
1299
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1170
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1300
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1171
1301
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1172
1302
|
if (failedTxs.length) {
|
|
1173
1303
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1181,6 +1311,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1181
1311
|
processedTx.txEffect,
|
|
1182
1312
|
returns,
|
|
1183
1313
|
processedTx.gasUsed,
|
|
1314
|
+
debugLogs,
|
|
1184
1315
|
);
|
|
1185
1316
|
} finally {
|
|
1186
1317
|
await merkleTreeFork.close();
|
|
@@ -1194,10 +1325,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1194
1325
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1195
1326
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1196
1327
|
|
|
1197
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1328
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1198
1329
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1199
1330
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1200
|
-
const
|
|
1331
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1332
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1201
1333
|
db,
|
|
1202
1334
|
this.contractDataSource,
|
|
1203
1335
|
verifier,
|
|
@@ -1206,10 +1338,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1338
|
blockNumber,
|
|
1207
1339
|
l1ChainId: this.l1ChainId,
|
|
1208
1340
|
rollupVersion: this.version,
|
|
1209
|
-
setupAllowList:
|
|
1341
|
+
setupAllowList: [
|
|
1342
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1343
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1344
|
+
],
|
|
1210
1345
|
gasFees: await this.getCurrentMinFees(),
|
|
1211
1346
|
skipFeeEnforcement,
|
|
1212
1347
|
txsPermitted: !this.config.disableTransactions,
|
|
1348
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1349
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1350
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1213
1351
|
},
|
|
1214
1352
|
this.log.getBindings(),
|
|
1215
1353
|
);
|
|
@@ -1376,6 +1514,128 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1376
1514
|
}
|
|
1377
1515
|
}
|
|
1378
1516
|
|
|
1517
|
+
public async reloadKeystore(): Promise<void> {
|
|
1518
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1519
|
+
throw new BadRequestError(
|
|
1520
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1521
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
if (!this.validatorClient) {
|
|
1525
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
this.log.info('Reloading keystore from disk');
|
|
1529
|
+
|
|
1530
|
+
// Re-read and validate keystore files
|
|
1531
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1532
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1533
|
+
await newManager.validateSigners();
|
|
1534
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1535
|
+
|
|
1536
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1537
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1538
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1539
|
+
// would silently fail on every proposer slot.
|
|
1540
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1541
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1542
|
+
const availablePublishers = new Set(
|
|
1543
|
+
oldAdapter
|
|
1544
|
+
.getAttesterAddresses()
|
|
1545
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1546
|
+
);
|
|
1547
|
+
|
|
1548
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1549
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1550
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1551
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1552
|
+
throw new BadRequestError(
|
|
1553
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1554
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1555
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1556
|
+
`use an existing publisher key or restart the node.`,
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// Build adapters for old and new keystores to compute diff
|
|
1563
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1564
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1565
|
+
const oldAddresses = this.keyStoreManager
|
|
1566
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1567
|
+
: [];
|
|
1568
|
+
|
|
1569
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1570
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1571
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1572
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1573
|
+
|
|
1574
|
+
if (added.length > 0) {
|
|
1575
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1576
|
+
}
|
|
1577
|
+
if (removed.length > 0) {
|
|
1578
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1579
|
+
}
|
|
1580
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1581
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1585
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1586
|
+
|
|
1587
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1588
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1589
|
+
if (this.sequencer) {
|
|
1590
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1594
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1595
|
+
const slashValidatorsNever = unique(
|
|
1596
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1597
|
+
).map(EthAddress.fromString);
|
|
1598
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
this.keyStoreManager = newManager;
|
|
1602
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
public async mineBlock(): Promise<void> {
|
|
1606
|
+
if (!this.sequencer) {
|
|
1607
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1611
|
+
|
|
1612
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1613
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1614
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1615
|
+
|
|
1616
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1617
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1618
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1619
|
+
|
|
1620
|
+
try {
|
|
1621
|
+
// Trigger the sequencer to produce a block immediately
|
|
1622
|
+
void this.sequencer.trigger();
|
|
1623
|
+
|
|
1624
|
+
// Wait for the new L2 block to appear
|
|
1625
|
+
await retryUntil(
|
|
1626
|
+
async () => {
|
|
1627
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1628
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1629
|
+
},
|
|
1630
|
+
'mineBlock',
|
|
1631
|
+
timeoutSeconds,
|
|
1632
|
+
0.1,
|
|
1633
|
+
);
|
|
1634
|
+
} finally {
|
|
1635
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1379
1639
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1380
1640
|
if (!this.initialHeaderHashPromise) {
|
|
1381
1641
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1388,7 +1648,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1388
1648
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1389
1649
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1390
1650
|
*/
|
|
1391
|
-
async
|
|
1651
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1392
1652
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1393
1653
|
try {
|
|
1394
1654
|
// Attempt to sync the world state if necessary
|
|
@@ -1402,6 +1662,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1402
1662
|
return this.worldStateSynchronizer.getCommitted();
|
|
1403
1663
|
}
|
|
1404
1664
|
|
|
1665
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1666
|
+
let blockNumber: BlockNumber;
|
|
1405
1667
|
if (BlockHash.isBlockHash(block)) {
|
|
1406
1668
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1407
1669
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1415,22 +1677,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1415
1677
|
`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1416
1678
|
);
|
|
1417
1679
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1680
|
+
|
|
1681
|
+
blockNumber = header.getBlockNumber();
|
|
1682
|
+
} else {
|
|
1683
|
+
blockNumber = block as BlockNumber;
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// Check it's within world state sync range
|
|
1687
|
+
if (blockNumber > blockSyncedTo) {
|
|
1688
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1421
1689
|
}
|
|
1690
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1422
1691
|
|
|
1423
|
-
|
|
1424
|
-
{
|
|
1425
|
-
const blockNumber = block as BlockNumber;
|
|
1692
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1426
1693
|
|
|
1427
|
-
|
|
1428
|
-
|
|
1694
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1695
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1696
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1697
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`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.`,
|
|
1700
|
+
);
|
|
1429
1701
|
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
return snapshot;
|
|
1705
|
+
}
|
|
1430
1706
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1707
|
+
/** Resolves a block parameter to a block number. */
|
|
1708
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1709
|
+
if (block === 'latest') {
|
|
1710
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1711
|
+
}
|
|
1712
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1713
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1714
|
+
if (block.equals(initialBlockHash)) {
|
|
1715
|
+
return BlockNumber.ZERO;
|
|
1716
|
+
}
|
|
1717
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1718
|
+
if (!header) {
|
|
1719
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1720
|
+
}
|
|
1721
|
+
return header.getBlockNumber();
|
|
1433
1722
|
}
|
|
1723
|
+
return block as BlockNumber;
|
|
1434
1724
|
}
|
|
1435
1725
|
|
|
1436
1726
|
/**
|