@aztec/aztec-node 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
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 +11 -5
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +17 -3
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +9 -16
- package/dest/aztec-node/server.d.ts +78 -138
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +941 -302
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/sentinel.d.ts +6 -5
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +85 -54
- 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 +30 -28
- package/src/aztec-node/config.ts +34 -14
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +703 -379
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +97 -55
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
INITIAL_L2_BLOCK_NUM,
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
3
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
4
|
+
import { Blob } from '@aztec/blob-lib';
|
|
5
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
6
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from '@aztec/
|
|
20
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
21
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
7
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
11
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
22
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
23
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
24
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
25
16
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
17
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
26
18
|
import { count } from '@aztec/foundation/string';
|
|
27
19
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
28
20
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
21
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
22
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
31
|
-
import {
|
|
32
|
-
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
33
|
-
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
23
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
34
24
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} from '@aztec/
|
|
25
|
+
type P2P,
|
|
26
|
+
type P2PClientDeps,
|
|
27
|
+
createP2PClient,
|
|
28
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
29
|
+
getDefaultAllowedSetupFunctions,
|
|
30
|
+
} from '@aztec/p2p';
|
|
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';
|
|
34
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
41
35
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
42
36
|
import {
|
|
43
37
|
AttestationsBlockWatcher,
|
|
@@ -46,16 +40,17 @@ import {
|
|
|
46
40
|
type Watcher,
|
|
47
41
|
createSlasher,
|
|
48
42
|
} from '@aztec/slasher';
|
|
49
|
-
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
43
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
50
44
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
51
45
|
import {
|
|
52
|
-
type
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
type
|
|
46
|
+
type BlockData,
|
|
47
|
+
BlockHash,
|
|
48
|
+
type BlockParameter,
|
|
49
|
+
type DataInBlock,
|
|
50
|
+
L2Block,
|
|
56
51
|
type L2BlockSource,
|
|
57
|
-
type PublishedL2Block,
|
|
58
52
|
} from '@aztec/stdlib/block';
|
|
53
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
59
54
|
import type {
|
|
60
55
|
ContractClassPublic,
|
|
61
56
|
ContractDataSource,
|
|
@@ -70,6 +65,7 @@ import {
|
|
|
70
65
|
type AztecNodeAdmin,
|
|
71
66
|
type AztecNodeAdminConfig,
|
|
72
67
|
AztecNodeAdminConfigSchema,
|
|
68
|
+
type AztecNodeDebug,
|
|
73
69
|
type GetContractClassLogsResponse,
|
|
74
70
|
type GetPublicLogsResponse,
|
|
75
71
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -82,9 +78,9 @@ import {
|
|
|
82
78
|
type WorldStateSynchronizer,
|
|
83
79
|
tryStop,
|
|
84
80
|
} from '@aztec/stdlib/interfaces/server';
|
|
85
|
-
import type { LogFilter,
|
|
81
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
82
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
86
83
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
87
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
88
84
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
89
85
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
90
86
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -110,14 +106,17 @@ import {
|
|
|
110
106
|
trackSpan,
|
|
111
107
|
} from '@aztec/telemetry-client';
|
|
112
108
|
import {
|
|
109
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
110
|
+
FullNodeCheckpointsBuilder,
|
|
113
111
|
NodeKeystoreAdapter,
|
|
114
112
|
ValidatorClient,
|
|
115
|
-
|
|
113
|
+
createProposalHandler,
|
|
116
114
|
createValidatorClient,
|
|
117
115
|
} from '@aztec/validator-client';
|
|
116
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
118
117
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
119
118
|
|
|
120
|
-
import { createPublicClient
|
|
119
|
+
import { createPublicClient } from 'viem';
|
|
121
120
|
|
|
122
121
|
import { createSentinel } from '../sentinel/factory.js';
|
|
123
122
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -127,8 +126,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
127
126
|
/**
|
|
128
127
|
* The aztec node.
|
|
129
128
|
*/
|
|
130
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
129
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
131
130
|
private metrics: NodeMetrics;
|
|
131
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
132
132
|
|
|
133
133
|
// Prevent two snapshot operations to happen simultaneously
|
|
134
134
|
private isUploadingSnapshot = false;
|
|
@@ -144,6 +144,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
144
144
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
145
145
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
146
146
|
protected readonly sequencer: SequencerClient | undefined,
|
|
147
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
147
148
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
148
149
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
149
150
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -155,12 +156,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
155
156
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
156
157
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
157
158
|
private log = createLogger('node'),
|
|
159
|
+
private blobClient?: BlobClientInterface,
|
|
160
|
+
private validatorClient?: ValidatorClient,
|
|
161
|
+
private keyStoreManager?: KeystoreManager,
|
|
162
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
158
163
|
) {
|
|
159
164
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
165
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
161
166
|
|
|
162
167
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
163
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
|
+
}
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -184,12 +196,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
196
|
logger?: Logger;
|
|
185
197
|
publisher?: SequencerPublisher;
|
|
186
198
|
dateProvider?: DateProvider;
|
|
187
|
-
|
|
188
|
-
|
|
199
|
+
p2pClientDeps?: P2PClientDeps;
|
|
200
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
201
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
189
202
|
} = {},
|
|
190
203
|
options: {
|
|
191
204
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
192
205
|
dontStartSequencer?: boolean;
|
|
206
|
+
dontStartProverNode?: boolean;
|
|
193
207
|
} = {},
|
|
194
208
|
): Promise<AztecNodeService> {
|
|
195
209
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -197,20 +211,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
197
211
|
const packageVersion = getPackageVersion() ?? '';
|
|
198
212
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
199
213
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
200
|
-
const blobSinkClient =
|
|
201
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
202
214
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
203
215
|
|
|
204
|
-
// 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.
|
|
205
218
|
let keyStoreManager: KeystoreManager | undefined;
|
|
206
219
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
207
220
|
if (keyStoreProvided) {
|
|
208
221
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
209
222
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
210
223
|
} else {
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
);
|
|
214
239
|
}
|
|
215
240
|
}
|
|
216
241
|
|
|
@@ -221,10 +246,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
221
246
|
if (keyStoreManager === undefined) {
|
|
222
247
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
223
248
|
}
|
|
224
|
-
if (!keyStoreProvided) {
|
|
225
|
-
log.warn(
|
|
226
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
227
|
-
);
|
|
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");
|
|
228
251
|
}
|
|
229
252
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
230
253
|
}
|
|
@@ -238,7 +261,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
238
261
|
|
|
239
262
|
const publicClient = createPublicClient({
|
|
240
263
|
chain: ethereumChain.chainInfo,
|
|
241
|
-
transport:
|
|
264
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
242
265
|
pollingInterval: config.viemPollingIntervalMS,
|
|
243
266
|
});
|
|
244
267
|
|
|
@@ -252,10 +275,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
252
275
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
253
276
|
|
|
254
277
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
255
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
278
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
256
279
|
rollupContract.getL1GenesisTime(),
|
|
257
280
|
rollupContract.getSlotDuration(),
|
|
258
281
|
rollupContract.getVersion(),
|
|
282
|
+
rollupContract.getManaLimit().then(Number),
|
|
259
283
|
] as const);
|
|
260
284
|
|
|
261
285
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -266,6 +290,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
266
290
|
);
|
|
267
291
|
}
|
|
268
292
|
|
|
293
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
294
|
+
|
|
269
295
|
// attempt snapshot sync if possible
|
|
270
296
|
await trySnapshotSync(config, log);
|
|
271
297
|
|
|
@@ -273,7 +299,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
273
299
|
|
|
274
300
|
const archiver = await createArchiver(
|
|
275
301
|
config,
|
|
276
|
-
{
|
|
302
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
277
303
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
278
304
|
);
|
|
279
305
|
|
|
@@ -284,17 +310,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
284
310
|
options.prefilledPublicData,
|
|
285
311
|
telemetry,
|
|
286
312
|
);
|
|
287
|
-
const circuitVerifier =
|
|
288
|
-
|
|
289
|
-
|
|
313
|
+
const circuitVerifier =
|
|
314
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
315
|
+
? await BBCircuitVerifier.new(config)
|
|
316
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
317
|
+
|
|
318
|
+
let debugLogStore: DebugLogStore;
|
|
290
319
|
if (!config.realProofs) {
|
|
291
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();
|
|
292
328
|
}
|
|
329
|
+
|
|
293
330
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
294
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
|
+
|
|
295
337
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
296
338
|
const p2pClient = await createP2PClient(
|
|
297
|
-
P2PClientType.Full,
|
|
298
339
|
config,
|
|
299
340
|
archiver,
|
|
300
341
|
proofVerifier,
|
|
@@ -306,55 +347,72 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
347
|
deps.p2pClientDeps,
|
|
307
348
|
);
|
|
308
349
|
|
|
309
|
-
// We
|
|
310
|
-
|
|
350
|
+
// We'll accumulate sentinel watchers here
|
|
351
|
+
const watchers: Watcher[] = [];
|
|
311
352
|
|
|
312
|
-
|
|
313
|
-
|
|
353
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
354
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
355
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
356
|
+
{
|
|
357
|
+
...config,
|
|
358
|
+
l1GenesisTime,
|
|
359
|
+
slotDuration: Number(slotDuration),
|
|
360
|
+
rollupManaLimit,
|
|
361
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
362
|
+
},
|
|
314
363
|
worldStateSynchronizer,
|
|
315
364
|
archiver,
|
|
316
365
|
dateProvider,
|
|
317
366
|
telemetry,
|
|
318
367
|
);
|
|
319
368
|
|
|
320
|
-
|
|
321
|
-
const watchers: Watcher[] = [];
|
|
369
|
+
let validatorClient: ValidatorClient | undefined;
|
|
322
370
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
+
});
|
|
334
386
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
+
}
|
|
342
395
|
}
|
|
343
396
|
}
|
|
344
397
|
|
|
345
|
-
// If there's no validator client
|
|
346
|
-
//
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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, {
|
|
406
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
407
|
+
worldState: worldStateSynchronizer,
|
|
351
408
|
epochCache,
|
|
352
409
|
blockSource: archiver,
|
|
353
410
|
l1ToL2MessageSource: archiver,
|
|
354
411
|
p2pClient,
|
|
412
|
+
blobClient,
|
|
355
413
|
dateProvider,
|
|
356
414
|
telemetry,
|
|
357
|
-
}).
|
|
415
|
+
}).register(p2pClient, reexecute);
|
|
358
416
|
}
|
|
359
417
|
|
|
360
418
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -363,29 +421,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
363
421
|
// Start p2p. Note that it depends on world state to be running.
|
|
364
422
|
await p2pClient.start();
|
|
365
423
|
|
|
366
|
-
|
|
367
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
368
|
-
watchers.push(validatorsSentinel);
|
|
369
|
-
}
|
|
370
|
-
|
|
424
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
371
425
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
372
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
373
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
374
|
-
archiver,
|
|
375
|
-
archiver,
|
|
376
|
-
epochCache,
|
|
377
|
-
p2pClient.getTxProvider(),
|
|
378
|
-
blockBuilder,
|
|
379
|
-
config,
|
|
380
|
-
);
|
|
381
|
-
watchers.push(epochPruneWatcher);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
385
426
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
+
}
|
|
389
451
|
}
|
|
390
452
|
|
|
391
453
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -400,10 +462,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
400
462
|
})
|
|
401
463
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
402
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
|
+
|
|
403
473
|
// Validator enabled, create/start relevant service
|
|
404
474
|
let sequencer: SequencerClient | undefined;
|
|
405
475
|
let slasherClient: SlasherClientInterface | undefined;
|
|
406
|
-
if (!config.disableValidator) {
|
|
476
|
+
if (!config.disableValidator && validatorClient) {
|
|
407
477
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
408
478
|
// as they are executed when the node is selected as proposer.
|
|
409
479
|
const validatorAddresses = keyStoreManager
|
|
@@ -422,14 +492,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
422
492
|
);
|
|
423
493
|
await slasherClient.start();
|
|
424
494
|
|
|
425
|
-
const l1TxUtils =
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
495
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
496
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
497
|
+
publicClient,
|
|
498
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
499
|
+
config.sequencerPublisherForwarderAddress,
|
|
500
|
+
{ ...config, scope: 'sequencer' },
|
|
501
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
502
|
+
)
|
|
503
|
+
: await createL1TxUtilsFromSigners(
|
|
504
|
+
publicClient,
|
|
505
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
506
|
+
{ ...config, scope: 'sequencer' },
|
|
507
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
508
|
+
);
|
|
431
509
|
|
|
432
510
|
// Create and start the sequencer client
|
|
511
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
512
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
513
|
+
worldStateSynchronizer,
|
|
514
|
+
archiver,
|
|
515
|
+
dateProvider,
|
|
516
|
+
telemetry,
|
|
517
|
+
debugLogStore,
|
|
518
|
+
);
|
|
519
|
+
|
|
433
520
|
sequencer = await SequencerClient.new(config, {
|
|
434
521
|
...deps,
|
|
435
522
|
epochCache,
|
|
@@ -438,13 +525,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
438
525
|
p2pClient,
|
|
439
526
|
worldStateSynchronizer,
|
|
440
527
|
slasherClient,
|
|
441
|
-
|
|
528
|
+
checkpointsBuilder,
|
|
442
529
|
l2BlockSource: archiver,
|
|
443
530
|
l1ToL2MessageSource: archiver,
|
|
444
531
|
telemetry,
|
|
445
532
|
dateProvider,
|
|
446
|
-
|
|
533
|
+
blobClient,
|
|
447
534
|
nodeKeyStore: keyStoreManager!,
|
|
535
|
+
globalVariableBuilder,
|
|
448
536
|
});
|
|
449
537
|
}
|
|
450
538
|
|
|
@@ -455,7 +543,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
455
543
|
log.warn(`Sequencer created but not started`);
|
|
456
544
|
}
|
|
457
545
|
|
|
458
|
-
|
|
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
|
+
});
|
|
560
|
+
|
|
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(
|
|
459
570
|
config,
|
|
460
571
|
p2pClient,
|
|
461
572
|
archiver,
|
|
@@ -464,18 +575,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
464
575
|
archiver,
|
|
465
576
|
worldStateSynchronizer,
|
|
466
577
|
sequencer,
|
|
578
|
+
proverNode,
|
|
467
579
|
slasherClient,
|
|
468
580
|
validatorsSentinel,
|
|
469
581
|
epochPruneWatcher,
|
|
470
582
|
ethereumChain.chainInfo.id,
|
|
471
583
|
config.rollupVersion,
|
|
472
|
-
|
|
584
|
+
globalVariableBuilder,
|
|
473
585
|
epochCache,
|
|
474
586
|
packageVersion,
|
|
475
587
|
proofVerifier,
|
|
476
588
|
telemetry,
|
|
477
589
|
log,
|
|
590
|
+
blobClient,
|
|
591
|
+
validatorClient,
|
|
592
|
+
keyStoreManager,
|
|
593
|
+
debugLogStore,
|
|
478
594
|
);
|
|
595
|
+
|
|
596
|
+
return node;
|
|
479
597
|
}
|
|
480
598
|
|
|
481
599
|
/**
|
|
@@ -486,6 +604,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
486
604
|
return this.sequencer;
|
|
487
605
|
}
|
|
488
606
|
|
|
607
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
608
|
+
public getProverNode(): ProverNode | undefined {
|
|
609
|
+
return this.proverNode;
|
|
610
|
+
}
|
|
611
|
+
|
|
489
612
|
public getBlockSource(): L2BlockSource {
|
|
490
613
|
return this.blockSource;
|
|
491
614
|
}
|
|
@@ -511,7 +634,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
511
634
|
}
|
|
512
635
|
|
|
513
636
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
514
|
-
return this.config.
|
|
637
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
515
638
|
}
|
|
516
639
|
|
|
517
640
|
/**
|
|
@@ -539,19 +662,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
539
662
|
enr,
|
|
540
663
|
l1ContractAddresses: contractAddresses,
|
|
541
664
|
protocolContractAddresses: protocolContractAddresses,
|
|
665
|
+
realProofs: !!this.config.realProofs,
|
|
542
666
|
};
|
|
543
667
|
|
|
544
668
|
return nodeInfo;
|
|
545
669
|
}
|
|
546
670
|
|
|
547
671
|
/**
|
|
548
|
-
* Get a block specified by its number.
|
|
549
|
-
* @param
|
|
672
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
673
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
550
674
|
* @returns The requested block.
|
|
551
675
|
*/
|
|
552
|
-
public async getBlock(
|
|
553
|
-
|
|
554
|
-
|
|
676
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
677
|
+
if (BlockHash.isBlockHash(block)) {
|
|
678
|
+
return this.getBlockByHash(block);
|
|
679
|
+
}
|
|
680
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
681
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
682
|
+
return this.buildInitialBlock();
|
|
683
|
+
}
|
|
684
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
555
685
|
}
|
|
556
686
|
|
|
557
687
|
/**
|
|
@@ -559,9 +689,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
559
689
|
* @param blockHash - The block hash being requested.
|
|
560
690
|
* @returns The requested block.
|
|
561
691
|
*/
|
|
562
|
-
public async getBlockByHash(blockHash:
|
|
563
|
-
const
|
|
564
|
-
|
|
692
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
693
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
694
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
695
|
+
return this.buildInitialBlock();
|
|
696
|
+
}
|
|
697
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private buildInitialBlock(): L2Block {
|
|
701
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
702
|
+
return L2Block.empty(initialHeader);
|
|
565
703
|
}
|
|
566
704
|
|
|
567
705
|
/**
|
|
@@ -570,8 +708,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
570
708
|
* @returns The requested block.
|
|
571
709
|
*/
|
|
572
710
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
573
|
-
|
|
574
|
-
return publishedBlock?.block;
|
|
711
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
575
712
|
}
|
|
576
713
|
|
|
577
714
|
/**
|
|
@@ -580,20 +717,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
580
717
|
* @param limit - The maximum number of blocks to obtain.
|
|
581
718
|
* @returns The blocks requested.
|
|
582
719
|
*/
|
|
583
|
-
public async getBlocks(from:
|
|
584
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
720
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
721
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
725
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
585
726
|
}
|
|
586
727
|
|
|
587
|
-
public async
|
|
588
|
-
return (await this.blockSource.
|
|
728
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
729
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
733
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
589
734
|
}
|
|
590
735
|
|
|
591
736
|
/**
|
|
592
|
-
* Method to fetch the current
|
|
593
|
-
* @returns The current
|
|
737
|
+
* Method to fetch the current min L2 fees.
|
|
738
|
+
* @returns The current min L2 fees.
|
|
594
739
|
*/
|
|
595
|
-
public async
|
|
596
|
-
return await this.globalVariableBuilder.
|
|
740
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
741
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
597
742
|
}
|
|
598
743
|
|
|
599
744
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -608,14 +753,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
608
753
|
* Method to fetch the latest block number synchronized by the node.
|
|
609
754
|
* @returns The block number.
|
|
610
755
|
*/
|
|
611
|
-
public async getBlockNumber(): Promise<
|
|
756
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
612
757
|
return await this.blockSource.getBlockNumber();
|
|
613
758
|
}
|
|
614
759
|
|
|
615
|
-
public async getProvenBlockNumber(): Promise<
|
|
760
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
616
761
|
return await this.blockSource.getProvenBlockNumber();
|
|
617
762
|
}
|
|
618
763
|
|
|
764
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
765
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
769
|
+
return this.blockSource.getCheckpointNumber();
|
|
770
|
+
}
|
|
771
|
+
|
|
619
772
|
/**
|
|
620
773
|
* Method to fetch the version of the package.
|
|
621
774
|
* @returns The node package version
|
|
@@ -648,25 +801,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
648
801
|
return this.contractDataSource.getContract(address);
|
|
649
802
|
}
|
|
650
803
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
804
|
+
public async getPrivateLogsByTags(
|
|
805
|
+
tags: SiloedTag[],
|
|
806
|
+
page?: number,
|
|
807
|
+
referenceBlock?: BlockHash,
|
|
808
|
+
): Promise<TxScopedL2Log[][]> {
|
|
809
|
+
if (referenceBlock) {
|
|
810
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
811
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
812
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
813
|
+
if (!header) {
|
|
814
|
+
throw new Error(
|
|
815
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
public async getPublicLogsByTagsFromContract(
|
|
824
|
+
contractAddress: AztecAddress,
|
|
825
|
+
tags: Tag[],
|
|
826
|
+
page?: number,
|
|
827
|
+
referenceBlock?: BlockHash,
|
|
828
|
+
): Promise<TxScopedL2Log[][]> {
|
|
829
|
+
if (referenceBlock) {
|
|
830
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
831
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
832
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
833
|
+
if (!header) {
|
|
834
|
+
throw new Error(
|
|
835
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
670
841
|
}
|
|
671
842
|
|
|
672
843
|
/**
|
|
@@ -708,26 +879,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
708
879
|
}
|
|
709
880
|
|
|
710
881
|
await this.p2pClient!.sendTx(tx);
|
|
711
|
-
|
|
712
|
-
this.
|
|
882
|
+
const duration = timer.ms();
|
|
883
|
+
this.metrics.receivedTx(duration, true);
|
|
884
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
713
885
|
}
|
|
714
886
|
|
|
715
887
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
721
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
722
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
723
|
-
}
|
|
888
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
889
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
890
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
891
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
724
892
|
|
|
893
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
725
894
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
895
|
+
|
|
896
|
+
let receipt: TxReceipt;
|
|
726
897
|
if (settledTxReceipt) {
|
|
727
|
-
|
|
898
|
+
receipt = settledTxReceipt;
|
|
899
|
+
} else if (isKnownToPool) {
|
|
900
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
901
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
902
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
903
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
904
|
+
} else {
|
|
905
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
906
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
728
907
|
}
|
|
729
908
|
|
|
730
|
-
|
|
909
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
910
|
+
|
|
911
|
+
return receipt;
|
|
731
912
|
}
|
|
732
913
|
|
|
733
914
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -744,13 +925,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
744
925
|
await tryStop(this.slasherClient);
|
|
745
926
|
await tryStop(this.proofVerifier);
|
|
746
927
|
await tryStop(this.sequencer);
|
|
928
|
+
await tryStop(this.proverNode);
|
|
747
929
|
await tryStop(this.p2pClient);
|
|
748
930
|
await tryStop(this.worldStateSynchronizer);
|
|
749
931
|
await tryStop(this.blockSource);
|
|
932
|
+
await tryStop(this.blobClient);
|
|
750
933
|
await tryStop(this.telemetry);
|
|
751
934
|
this.log.info(`Stopped Aztec Node`);
|
|
752
935
|
}
|
|
753
936
|
|
|
937
|
+
/**
|
|
938
|
+
* Returns the blob client used by this node.
|
|
939
|
+
* @internal - Exposed for testing purposes only.
|
|
940
|
+
*/
|
|
941
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
942
|
+
return this.blobClient;
|
|
943
|
+
}
|
|
944
|
+
|
|
754
945
|
/**
|
|
755
946
|
* Method to retrieve pending txs.
|
|
756
947
|
* @param limit - The number of items to returns
|
|
@@ -783,121 +974,105 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
783
974
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
784
975
|
}
|
|
785
976
|
|
|
786
|
-
/**
|
|
787
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
788
|
-
* the leaves were inserted.
|
|
789
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
790
|
-
* @param treeId - The tree to search in.
|
|
791
|
-
* @param leafValues - The values to search for.
|
|
792
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
793
|
-
*/
|
|
794
977
|
public async findLeavesIndexes(
|
|
795
|
-
|
|
978
|
+
referenceBlock: BlockParameter,
|
|
796
979
|
treeId: MerkleTreeId,
|
|
797
980
|
leafValues: Fr[],
|
|
798
|
-
): Promise<(
|
|
799
|
-
const committedDb = await this
|
|
981
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
982
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
800
983
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
801
984
|
treeId,
|
|
802
985
|
leafValues.map(x => x.toBuffer()),
|
|
803
986
|
);
|
|
804
|
-
//
|
|
805
|
-
const
|
|
987
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
988
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
806
989
|
|
|
807
|
-
// Now we find the block numbers for the indices
|
|
808
|
-
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);
|
|
809
992
|
|
|
810
|
-
//
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
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
|
+
);
|
|
814
1001
|
}
|
|
1002
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
815
1003
|
}
|
|
816
1004
|
|
|
817
1005
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
818
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1006
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
819
1007
|
|
|
820
|
-
// Now we obtain the block hashes from the archive tree
|
|
821
|
-
// (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).
|
|
822
1009
|
const blockHashes = await Promise.all(
|
|
823
1010
|
uniqueBlockNumbers.map(blockNumber => {
|
|
824
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
1011
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
825
1012
|
}),
|
|
826
1013
|
);
|
|
827
1014
|
|
|
828
|
-
//
|
|
1015
|
+
// Build a map from block number to block hash
|
|
1016
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
829
1017
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
830
|
-
|
|
1018
|
+
const blockHash = blockHashes[i];
|
|
1019
|
+
if (blockHash === undefined) {
|
|
831
1020
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
832
1021
|
}
|
|
1022
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
833
1023
|
}
|
|
834
1024
|
|
|
835
|
-
// Create
|
|
836
|
-
return maybeIndices.map(
|
|
1025
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1026
|
+
return maybeIndices.map(index => {
|
|
837
1027
|
if (index === undefined) {
|
|
838
1028
|
return undefined;
|
|
839
1029
|
}
|
|
840
|
-
const blockNumber =
|
|
1030
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
841
1031
|
if (blockNumber === undefined) {
|
|
842
|
-
|
|
1032
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
843
1033
|
}
|
|
844
|
-
const
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
return undefined;
|
|
1034
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1035
|
+
if (blockHash === undefined) {
|
|
1036
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
848
1037
|
}
|
|
849
1038
|
return {
|
|
850
|
-
l2BlockNumber:
|
|
851
|
-
l2BlockHash:
|
|
1039
|
+
l2BlockNumber: blockNumber,
|
|
1040
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
852
1041
|
data: index,
|
|
853
1042
|
};
|
|
854
1043
|
});
|
|
855
1044
|
}
|
|
856
1045
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
861
|
-
* @returns The sibling path for the leaf index.
|
|
862
|
-
*/
|
|
863
|
-
public async getNullifierSiblingPath(
|
|
864
|
-
blockNumber: L2BlockNumber,
|
|
865
|
-
leafIndex: bigint,
|
|
866
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
867
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
868
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
/**
|
|
872
|
-
* Returns a sibling path for the given index in the data tree.
|
|
873
|
-
* @param blockNumber - The block number at which to get the data.
|
|
874
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
875
|
-
* @returns The sibling path for the leaf index.
|
|
876
|
-
*/
|
|
877
|
-
public async getNoteHashSiblingPath(
|
|
878
|
-
blockNumber: L2BlockNumber,
|
|
879
|
-
leafIndex: bigint,
|
|
880
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
881
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
882
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
public async getArchiveMembershipWitness(
|
|
886
|
-
blockNumber: L2BlockNumber,
|
|
887
|
-
archive: Fr,
|
|
1046
|
+
public async getBlockHashMembershipWitness(
|
|
1047
|
+
referenceBlock: BlockParameter,
|
|
1048
|
+
blockHash: BlockHash,
|
|
888
1049
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
889
|
-
|
|
890
|
-
|
|
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));
|
|
1065
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
891
1066
|
return pathAndIndex === undefined
|
|
892
1067
|
? undefined
|
|
893
1068
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
894
1069
|
}
|
|
895
1070
|
|
|
896
1071
|
public async getNoteHashMembershipWitness(
|
|
897
|
-
|
|
1072
|
+
referenceBlock: BlockParameter,
|
|
898
1073
|
noteHash: Fr,
|
|
899
1074
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
900
|
-
const committedDb = await this
|
|
1075
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
901
1076
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
902
1077
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
903
1078
|
[noteHash],
|
|
@@ -907,17 +1082,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
907
1082
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
908
1083
|
}
|
|
909
1084
|
|
|
910
|
-
/**
|
|
911
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
912
|
-
* @param blockNumber - The block number at which to get the data.
|
|
913
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
914
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
915
|
-
*/
|
|
916
1085
|
public async getL1ToL2MessageMembershipWitness(
|
|
917
|
-
|
|
1086
|
+
referenceBlock: BlockParameter,
|
|
918
1087
|
l1ToL2Message: Fr,
|
|
919
1088
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
920
|
-
const db = await this
|
|
1089
|
+
const db = await this.getWorldState(referenceBlock);
|
|
921
1090
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
922
1091
|
if (!witness) {
|
|
923
1092
|
return undefined;
|
|
@@ -927,9 +1096,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
927
1096
|
return [witness.index, witness.path];
|
|
928
1097
|
}
|
|
929
1098
|
|
|
930
|
-
public async
|
|
1099
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
931
1100
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
932
|
-
return messageIndex ? InboxLeaf.
|
|
1101
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
933
1102
|
}
|
|
934
1103
|
|
|
935
1104
|
/**
|
|
@@ -943,54 +1112,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
943
1112
|
}
|
|
944
1113
|
|
|
945
1114
|
/**
|
|
946
|
-
* Returns all the L2 to L1 messages in
|
|
947
|
-
* @param
|
|
948
|
-
* @returns The L2 to L1 messages (
|
|
949
|
-
*/
|
|
950
|
-
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
951
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
952
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/**
|
|
956
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
957
|
-
* @param blockNumber - The block number at which to get the data.
|
|
958
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
959
|
-
* @returns The sibling path.
|
|
960
|
-
*/
|
|
961
|
-
public async getArchiveSiblingPath(
|
|
962
|
-
blockNumber: L2BlockNumber,
|
|
963
|
-
leafIndex: bigint,
|
|
964
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
965
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
966
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
/**
|
|
970
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
971
|
-
* @param blockNumber - The block number at which to get the data.
|
|
972
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
973
|
-
* @returns The sibling path.
|
|
1115
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1116
|
+
* @param epoch - The epoch at which to get the data.
|
|
1117
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
974
1118
|
*/
|
|
975
|
-
public async
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1119
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1120
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1121
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1122
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1123
|
+
group => group.map(cb => cb.block),
|
|
1124
|
+
);
|
|
1125
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1126
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1127
|
+
);
|
|
981
1128
|
}
|
|
982
1129
|
|
|
983
|
-
/**
|
|
984
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
985
|
-
* @param blockNumber - The block number at which to get the index.
|
|
986
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
987
|
-
* @returns The nullifier membership witness (if found).
|
|
988
|
-
*/
|
|
989
1130
|
public async getNullifierMembershipWitness(
|
|
990
|
-
|
|
1131
|
+
referenceBlock: BlockParameter,
|
|
991
1132
|
nullifier: Fr,
|
|
992
1133
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
993
|
-
const db = await this
|
|
1134
|
+
const db = await this.getWorldState(referenceBlock);
|
|
994
1135
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
995
1136
|
if (!witness) {
|
|
996
1137
|
return undefined;
|
|
@@ -1005,32 +1146,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1005
1146
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1006
1147
|
}
|
|
1007
1148
|
|
|
1008
|
-
/**
|
|
1009
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1010
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1011
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1012
|
-
* @returns The low nullifier membership witness (if found).
|
|
1013
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1014
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1015
|
-
* we are trying to prove non-inclusion for.
|
|
1016
|
-
*
|
|
1017
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1018
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1019
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1020
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1021
|
-
*/
|
|
1022
1149
|
public async getLowNullifierMembershipWitness(
|
|
1023
|
-
|
|
1150
|
+
referenceBlock: BlockParameter,
|
|
1024
1151
|
nullifier: Fr,
|
|
1025
1152
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1026
|
-
const committedDb = await this
|
|
1153
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1027
1154
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1028
1155
|
if (!findResult) {
|
|
1029
1156
|
return undefined;
|
|
1030
1157
|
}
|
|
1031
1158
|
const { index, alreadyPresent } = findResult;
|
|
1032
1159
|
if (alreadyPresent) {
|
|
1033
|
-
|
|
1160
|
+
throw new Error(
|
|
1161
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1162
|
+
);
|
|
1034
1163
|
}
|
|
1035
1164
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1036
1165
|
|
|
@@ -1038,8 +1167,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1038
1167
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1039
1168
|
}
|
|
1040
1169
|
|
|
1041
|
-
async getPublicDataWitness(
|
|
1042
|
-
const committedDb = await this
|
|
1170
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1171
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1043
1172
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1044
1173
|
if (!lowLeafResult) {
|
|
1045
1174
|
return undefined;
|
|
@@ -1053,19 +1182,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1053
1182
|
}
|
|
1054
1183
|
}
|
|
1055
1184
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
*
|
|
1059
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1060
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1061
|
-
*
|
|
1062
|
-
* @param contract - Address of the contract to query.
|
|
1063
|
-
* @param slot - Slot to query.
|
|
1064
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1065
|
-
* @returns Storage value at the given contract slot.
|
|
1066
|
-
*/
|
|
1067
|
-
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1068
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1185
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1186
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1069
1187
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1070
1188
|
|
|
1071
1189
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1079,23 +1197,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1079
1197
|
return preimage.leaf.value;
|
|
1080
1198
|
}
|
|
1081
1199
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1200
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1201
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1202
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1203
|
+
if (block.equals(initialBlockHash)) {
|
|
1204
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1205
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1206
|
+
}
|
|
1207
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1208
|
+
} else {
|
|
1209
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1210
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1211
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1212
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1213
|
+
}
|
|
1214
|
+
return this.blockSource.getBlockHeader(block);
|
|
1215
|
+
}
|
|
1099
1216
|
}
|
|
1100
1217
|
|
|
1101
1218
|
/**
|
|
@@ -1107,6 +1224,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1107
1224
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1108
1225
|
}
|
|
1109
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
|
+
|
|
1110
1235
|
/**
|
|
1111
1236
|
* Simulates the public part of a transaction with the current state.
|
|
1112
1237
|
* @param tx - The transaction to simulate.
|
|
@@ -1130,7 +1255,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1130
1255
|
}
|
|
1131
1256
|
|
|
1132
1257
|
const txHash = tx.getTxHash();
|
|
1133
|
-
const
|
|
1258
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1259
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1134
1260
|
|
|
1135
1261
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1136
1262
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1145,6 +1271,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1145
1271
|
this.contractDataSource,
|
|
1146
1272
|
new DateProvider(),
|
|
1147
1273
|
this.telemetry,
|
|
1274
|
+
this.log.getBindings(),
|
|
1148
1275
|
);
|
|
1149
1276
|
|
|
1150
1277
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1153,6 +1280,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1153
1280
|
blockNumber,
|
|
1154
1281
|
});
|
|
1155
1282
|
|
|
1283
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1284
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1156
1285
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1157
1286
|
try {
|
|
1158
1287
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1160,13 +1289,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1160
1289
|
collectDebugLogs: true,
|
|
1161
1290
|
collectHints: false,
|
|
1162
1291
|
collectCallMetadata: true,
|
|
1163
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1164
1292
|
collectStatistics: false,
|
|
1293
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1294
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1295
|
+
}),
|
|
1165
1296
|
});
|
|
1166
1297
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1167
1298
|
|
|
1168
1299
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1169
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1300
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1170
1301
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1171
1302
|
if (failedTxs.length) {
|
|
1172
1303
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1180,6 +1311,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1180
1311
|
processedTx.txEffect,
|
|
1181
1312
|
returns,
|
|
1182
1313
|
processedTx.gasUsed,
|
|
1314
|
+
debugLogs,
|
|
1183
1315
|
);
|
|
1184
1316
|
} finally {
|
|
1185
1317
|
await merkleTreeFork.close();
|
|
@@ -1193,19 +1325,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1193
1325
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1194
1326
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1195
1327
|
|
|
1196
|
-
// 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)
|
|
1197
1329
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1198
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1199
|
-
const
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1330
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1331
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1332
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1333
|
+
db,
|
|
1334
|
+
this.contractDataSource,
|
|
1335
|
+
verifier,
|
|
1336
|
+
{
|
|
1337
|
+
timestamp: nextSlotTimestamp,
|
|
1338
|
+
blockNumber,
|
|
1339
|
+
l1ChainId: this.l1ChainId,
|
|
1340
|
+
rollupVersion: this.version,
|
|
1341
|
+
setupAllowList: [
|
|
1342
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1343
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1344
|
+
],
|
|
1345
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1346
|
+
skipFeeEnforcement,
|
|
1347
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1348
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1349
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1350
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1351
|
+
},
|
|
1352
|
+
this.log.getBindings(),
|
|
1353
|
+
);
|
|
1209
1354
|
|
|
1210
1355
|
return await validator.validateTx(tx);
|
|
1211
1356
|
}
|
|
@@ -1274,7 +1419,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1274
1419
|
}
|
|
1275
1420
|
|
|
1276
1421
|
// And it has an L2 block hash
|
|
1277
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1422
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1278
1423
|
if (!l2BlockHash) {
|
|
1279
1424
|
this.metrics.recordSnapshotError();
|
|
1280
1425
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1302,13 +1447,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1302
1447
|
return Promise.resolve();
|
|
1303
1448
|
}
|
|
1304
1449
|
|
|
1305
|
-
public async rollbackTo(targetBlock:
|
|
1450
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1306
1451
|
const archiver = this.blockSource as Archiver;
|
|
1307
1452
|
if (!('rollbackTo' in archiver)) {
|
|
1308
1453
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1309
1454
|
}
|
|
1310
1455
|
|
|
1311
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1456
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1312
1457
|
if (targetBlock < finalizedBlock) {
|
|
1313
1458
|
if (force) {
|
|
1314
1459
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1369,17 +1514,142 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1369
1514
|
}
|
|
1370
1515
|
}
|
|
1371
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
|
+
|
|
1639
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1640
|
+
if (!this.initialHeaderHashPromise) {
|
|
1641
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1642
|
+
}
|
|
1643
|
+
return this.initialHeaderHashPromise;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1372
1646
|
/**
|
|
1373
1647
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1374
|
-
* @param
|
|
1648
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1375
1649
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1376
1650
|
*/
|
|
1377
|
-
async
|
|
1378
|
-
|
|
1379
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
let blockSyncedTo: number = 0;
|
|
1651
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1652
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1383
1653
|
try {
|
|
1384
1654
|
// Attempt to sync the world state if necessary
|
|
1385
1655
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1387,24 +1657,78 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1387
1657
|
this.log.error(`Error getting world state: ${err}`);
|
|
1388
1658
|
}
|
|
1389
1659
|
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1660
|
+
if (block === 'latest') {
|
|
1661
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1393
1662
|
return this.worldStateSynchronizer.getCommitted();
|
|
1394
|
-
}
|
|
1395
|
-
|
|
1396
|
-
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1666
|
+
let blockNumber: BlockNumber;
|
|
1667
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1668
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1669
|
+
if (block.equals(initialBlockHash)) {
|
|
1670
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1671
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1675
|
+
if (!header) {
|
|
1676
|
+
throw new Error(
|
|
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.`,
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
blockNumber = header.getBlockNumber();
|
|
1397
1682
|
} else {
|
|
1398
|
-
|
|
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}).`);
|
|
1689
|
+
}
|
|
1690
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1691
|
+
|
|
1692
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1693
|
+
|
|
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
|
+
);
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
return snapshot;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
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();
|
|
1399
1722
|
}
|
|
1723
|
+
return block as BlockNumber;
|
|
1400
1724
|
}
|
|
1401
1725
|
|
|
1402
1726
|
/**
|
|
1403
1727
|
* Ensure we fully sync the world state
|
|
1404
1728
|
* @returns A promise that fulfils once the world state is synced
|
|
1405
1729
|
*/
|
|
1406
|
-
async #syncWorldState(): Promise<
|
|
1730
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1407
1731
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1408
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1732
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1409
1733
|
}
|
|
1410
1734
|
}
|