@aztec/aztec-node 0.0.1-commit.b655e406 → 0.0.1-commit.b6e433891
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 +12 -6
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +18 -4
- 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 +921 -307
- package/dest/bin/index.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/sentinel/config.d.ts +1 -1
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +1 -1
- package/dest/sentinel/index.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts +22 -20
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +108 -70
- package/dest/sentinel/store.d.ts +6 -5
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +14 -9
- package/dest/test/index.d.ts +1 -1
- package/package.json +30 -28
- package/src/aztec-node/config.ts +35 -15
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +676 -384
- package/src/sentinel/factory.ts +2 -7
- package/src/sentinel/sentinel.ts +143 -89
- package/src/sentinel/store.ts +22 -21
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
3
|
-
import { type
|
|
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 { 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';
|
|
21
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
22
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
23
15
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
24
16
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
25
|
-
import { SerialQueue } from '@aztec/foundation/queue';
|
|
26
17
|
import { count } from '@aztec/foundation/string';
|
|
27
18
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
28
19
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
21
|
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';
|
|
22
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
34
23
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} from '@aztec/
|
|
24
|
+
type P2P,
|
|
25
|
+
type P2PClientDeps,
|
|
26
|
+
createP2PClient,
|
|
27
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
+
getDefaultAllowedSetupFunctions,
|
|
29
|
+
} from '@aztec/p2p';
|
|
30
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
31
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
32
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
33
|
+
import { GlobalVariableBuilder, SequencerClient, type SequencerPublisher } from '@aztec/sequencer-client';
|
|
41
34
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
42
35
|
import {
|
|
43
36
|
AttestationsBlockWatcher,
|
|
@@ -46,15 +39,17 @@ import {
|
|
|
46
39
|
type Watcher,
|
|
47
40
|
createSlasher,
|
|
48
41
|
} from '@aztec/slasher';
|
|
42
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
49
43
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
50
44
|
import {
|
|
51
|
-
type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
type
|
|
45
|
+
type BlockData,
|
|
46
|
+
BlockHash,
|
|
47
|
+
type BlockParameter,
|
|
48
|
+
type DataInBlock,
|
|
49
|
+
L2Block,
|
|
55
50
|
type L2BlockSource,
|
|
56
|
-
type PublishedL2Block,
|
|
57
51
|
} from '@aztec/stdlib/block';
|
|
52
|
+
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
58
53
|
import type {
|
|
59
54
|
ContractClassPublic,
|
|
60
55
|
ContractDataSource,
|
|
@@ -62,7 +57,7 @@ import type {
|
|
|
62
57
|
NodeInfo,
|
|
63
58
|
ProtocolContractAddresses,
|
|
64
59
|
} from '@aztec/stdlib/contract';
|
|
65
|
-
import
|
|
60
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
66
61
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
67
62
|
import {
|
|
68
63
|
type AztecNode,
|
|
@@ -81,9 +76,9 @@ import {
|
|
|
81
76
|
type WorldStateSynchronizer,
|
|
82
77
|
tryStop,
|
|
83
78
|
} from '@aztec/stdlib/interfaces/server';
|
|
84
|
-
import type { LogFilter,
|
|
79
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
80
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
85
81
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
86
|
-
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
87
82
|
import type { Offense, SlashPayloadRound } from '@aztec/stdlib/slashing';
|
|
88
83
|
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
89
84
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
@@ -109,14 +104,17 @@ import {
|
|
|
109
104
|
trackSpan,
|
|
110
105
|
} from '@aztec/telemetry-client';
|
|
111
106
|
import {
|
|
107
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
108
|
+
FullNodeCheckpointsBuilder,
|
|
112
109
|
NodeKeystoreAdapter,
|
|
113
110
|
ValidatorClient,
|
|
114
111
|
createBlockProposalHandler,
|
|
115
112
|
createValidatorClient,
|
|
116
113
|
} from '@aztec/validator-client';
|
|
114
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
117
115
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
116
|
|
|
119
|
-
import { createPublicClient
|
|
117
|
+
import { createPublicClient } from 'viem';
|
|
120
118
|
|
|
121
119
|
import { createSentinel } from '../sentinel/factory.js';
|
|
122
120
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -128,13 +126,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
126
|
*/
|
|
129
127
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
128
|
private metrics: NodeMetrics;
|
|
129
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
130
|
|
|
132
131
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
132
|
private isUploadingSnapshot = false;
|
|
134
133
|
|
|
135
|
-
// Serial queue to ensure that we only send one tx at a time
|
|
136
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
137
|
-
|
|
138
134
|
public readonly tracer: Tracer;
|
|
139
135
|
|
|
140
136
|
constructor(
|
|
@@ -146,6 +142,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
146
142
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
147
143
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
148
144
|
protected readonly sequencer: SequencerClient | undefined,
|
|
145
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
149
146
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
150
147
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
151
148
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -157,13 +154,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
157
154
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
158
155
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
159
156
|
private log = createLogger('node'),
|
|
157
|
+
private blobClient?: BlobClientInterface,
|
|
158
|
+
private validatorClient?: ValidatorClient,
|
|
159
|
+
private keyStoreManager?: KeystoreManager,
|
|
160
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
160
161
|
) {
|
|
161
162
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
162
163
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
163
|
-
this.txQueue.start();
|
|
164
164
|
|
|
165
165
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
166
166
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
167
|
+
|
|
168
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
169
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
170
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
171
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
172
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
173
|
+
}
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -187,12 +194,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
187
194
|
logger?: Logger;
|
|
188
195
|
publisher?: SequencerPublisher;
|
|
189
196
|
dateProvider?: DateProvider;
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
p2pClientDeps?: P2PClientDeps;
|
|
198
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
199
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
192
200
|
} = {},
|
|
193
201
|
options: {
|
|
194
202
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
195
203
|
dontStartSequencer?: boolean;
|
|
204
|
+
dontStartProverNode?: boolean;
|
|
196
205
|
} = {},
|
|
197
206
|
): Promise<AztecNodeService> {
|
|
198
207
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -200,20 +209,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
200
209
|
const packageVersion = getPackageVersion() ?? '';
|
|
201
210
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
202
211
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
203
|
-
const blobSinkClient =
|
|
204
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
205
212
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
206
213
|
|
|
207
|
-
// Build a key store from file if given or from environment otherwise
|
|
214
|
+
// Build a key store from file if given or from environment otherwise.
|
|
215
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
208
216
|
let keyStoreManager: KeystoreManager | undefined;
|
|
209
217
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
210
218
|
if (keyStoreProvided) {
|
|
211
219
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
212
220
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
213
221
|
} else {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
const rawKeyStores: KeyStore[] = [];
|
|
223
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
224
|
+
if (validatorKeyStore) {
|
|
225
|
+
rawKeyStores.push(validatorKeyStore);
|
|
226
|
+
}
|
|
227
|
+
if (config.enableProverNode) {
|
|
228
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
229
|
+
if (proverKeyStore) {
|
|
230
|
+
rawKeyStores.push(proverKeyStore);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (rawKeyStores.length > 0) {
|
|
234
|
+
keyStoreManager = new KeystoreManager(
|
|
235
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
236
|
+
);
|
|
217
237
|
}
|
|
218
238
|
}
|
|
219
239
|
|
|
@@ -224,10 +244,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
224
244
|
if (keyStoreManager === undefined) {
|
|
225
245
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
226
246
|
}
|
|
227
|
-
if (!keyStoreProvided) {
|
|
228
|
-
log.warn(
|
|
229
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
230
|
-
);
|
|
247
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
248
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
231
249
|
}
|
|
232
250
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
233
251
|
}
|
|
@@ -241,7 +259,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
241
259
|
|
|
242
260
|
const publicClient = createPublicClient({
|
|
243
261
|
chain: ethereumChain.chainInfo,
|
|
244
|
-
transport:
|
|
262
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
245
263
|
pollingInterval: config.viemPollingIntervalMS,
|
|
246
264
|
});
|
|
247
265
|
|
|
@@ -255,10 +273,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
255
273
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
256
274
|
|
|
257
275
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
258
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
276
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
259
277
|
rollupContract.getL1GenesisTime(),
|
|
260
278
|
rollupContract.getSlotDuration(),
|
|
261
279
|
rollupContract.getVersion(),
|
|
280
|
+
rollupContract.getManaLimit().then(Number),
|
|
262
281
|
] as const);
|
|
263
282
|
|
|
264
283
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -269,6 +288,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
269
288
|
);
|
|
270
289
|
}
|
|
271
290
|
|
|
291
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
292
|
+
|
|
272
293
|
// attempt snapshot sync if possible
|
|
273
294
|
await trySnapshotSync(config, log);
|
|
274
295
|
|
|
@@ -276,7 +297,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
276
297
|
|
|
277
298
|
const archiver = await createArchiver(
|
|
278
299
|
config,
|
|
279
|
-
{
|
|
300
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
280
301
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
281
302
|
);
|
|
282
303
|
|
|
@@ -287,15 +308,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
308
|
options.prefilledPublicData,
|
|
288
309
|
telemetry,
|
|
289
310
|
);
|
|
290
|
-
const circuitVerifier =
|
|
311
|
+
const circuitVerifier =
|
|
312
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
313
|
+
? await BBCircuitVerifier.new(config)
|
|
314
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
315
|
+
|
|
316
|
+
let debugLogStore: DebugLogStore;
|
|
291
317
|
if (!config.realProofs) {
|
|
292
318
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
319
|
+
|
|
320
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
321
|
+
log.info(
|
|
322
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
323
|
+
);
|
|
324
|
+
} else {
|
|
325
|
+
debugLogStore = new NullDebugLogStore();
|
|
293
326
|
}
|
|
327
|
+
|
|
294
328
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
295
329
|
|
|
330
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
331
|
+
if (proverOnly) {
|
|
332
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
333
|
+
}
|
|
334
|
+
|
|
296
335
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
297
336
|
const p2pClient = await createP2PClient(
|
|
298
|
-
P2PClientType.Full,
|
|
299
337
|
config,
|
|
300
338
|
archiver,
|
|
301
339
|
proofVerifier,
|
|
@@ -307,55 +345,70 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
307
345
|
deps.p2pClientDeps,
|
|
308
346
|
);
|
|
309
347
|
|
|
310
|
-
// We
|
|
311
|
-
|
|
348
|
+
// We'll accumulate sentinel watchers here
|
|
349
|
+
const watchers: Watcher[] = [];
|
|
312
350
|
|
|
313
|
-
|
|
314
|
-
|
|
351
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
352
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
353
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
354
|
+
{
|
|
355
|
+
...config,
|
|
356
|
+
l1GenesisTime,
|
|
357
|
+
slotDuration: Number(slotDuration),
|
|
358
|
+
rollupManaLimit,
|
|
359
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
360
|
+
},
|
|
315
361
|
worldStateSynchronizer,
|
|
316
362
|
archiver,
|
|
317
363
|
dateProvider,
|
|
318
364
|
telemetry,
|
|
319
365
|
);
|
|
320
366
|
|
|
321
|
-
|
|
322
|
-
const watchers: Watcher[] = [];
|
|
367
|
+
let validatorClient: ValidatorClient | undefined;
|
|
323
368
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
369
|
+
if (!proverOnly) {
|
|
370
|
+
// Create validator client if required
|
|
371
|
+
validatorClient = await createValidatorClient(config, {
|
|
372
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
373
|
+
worldState: worldStateSynchronizer,
|
|
374
|
+
p2pClient,
|
|
375
|
+
telemetry,
|
|
376
|
+
dateProvider,
|
|
377
|
+
epochCache,
|
|
378
|
+
blockSource: archiver,
|
|
379
|
+
l1ToL2MessageSource: archiver,
|
|
380
|
+
keyStoreManager,
|
|
381
|
+
blobClient,
|
|
382
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
383
|
+
});
|
|
335
384
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
385
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
386
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
387
|
+
// like attestations or auths will fail.
|
|
388
|
+
if (validatorClient) {
|
|
389
|
+
watchers.push(validatorClient);
|
|
390
|
+
if (!options.dontStartSequencer) {
|
|
391
|
+
await validatorClient.registerHandlers();
|
|
392
|
+
}
|
|
343
393
|
}
|
|
344
394
|
}
|
|
345
395
|
|
|
346
|
-
// If there's no validator client
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
|
|
396
|
+
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
397
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
398
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
399
|
+
if (!validatorClient) {
|
|
400
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
401
|
+
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
350
402
|
createBlockProposalHandler(config, {
|
|
351
|
-
|
|
403
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
404
|
+
worldState: worldStateSynchronizer,
|
|
352
405
|
epochCache,
|
|
353
406
|
blockSource: archiver,
|
|
354
407
|
l1ToL2MessageSource: archiver,
|
|
355
408
|
p2pClient,
|
|
356
409
|
dateProvider,
|
|
357
410
|
telemetry,
|
|
358
|
-
}).
|
|
411
|
+
}).register(p2pClient, reexecute);
|
|
359
412
|
}
|
|
360
413
|
|
|
361
414
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -364,29 +417,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
364
417
|
// Start p2p. Note that it depends on world state to be running.
|
|
365
418
|
await p2pClient.start();
|
|
366
419
|
|
|
367
|
-
|
|
368
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
369
|
-
watchers.push(validatorsSentinel);
|
|
370
|
-
}
|
|
371
|
-
|
|
420
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
372
421
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
373
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
374
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
375
|
-
archiver,
|
|
376
|
-
archiver,
|
|
377
|
-
epochCache,
|
|
378
|
-
p2pClient.getTxProvider(),
|
|
379
|
-
blockBuilder,
|
|
380
|
-
config,
|
|
381
|
-
);
|
|
382
|
-
watchers.push(epochPruneWatcher);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
386
422
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
423
|
+
|
|
424
|
+
if (!proverOnly) {
|
|
425
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
426
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
427
|
+
watchers.push(validatorsSentinel);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
431
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
432
|
+
archiver,
|
|
433
|
+
archiver,
|
|
434
|
+
epochCache,
|
|
435
|
+
p2pClient.getTxProvider(),
|
|
436
|
+
validatorCheckpointsBuilder,
|
|
437
|
+
config,
|
|
438
|
+
);
|
|
439
|
+
watchers.push(epochPruneWatcher);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
443
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
444
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
445
|
+
watchers.push(attestationsBlockWatcher);
|
|
446
|
+
}
|
|
390
447
|
}
|
|
391
448
|
|
|
392
449
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -404,7 +461,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
404
461
|
// Validator enabled, create/start relevant service
|
|
405
462
|
let sequencer: SequencerClient | undefined;
|
|
406
463
|
let slasherClient: SlasherClientInterface | undefined;
|
|
407
|
-
if (!config.disableValidator) {
|
|
464
|
+
if (!config.disableValidator && validatorClient) {
|
|
408
465
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
409
466
|
// as they are executed when the node is selected as proposer.
|
|
410
467
|
const validatorAddresses = keyStoreManager
|
|
@@ -423,14 +480,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
423
480
|
);
|
|
424
481
|
await slasherClient.start();
|
|
425
482
|
|
|
426
|
-
const l1TxUtils =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
483
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
484
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
485
|
+
publicClient,
|
|
486
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
487
|
+
config.sequencerPublisherForwarderAddress,
|
|
488
|
+
{ ...config, scope: 'sequencer' },
|
|
489
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
490
|
+
)
|
|
491
|
+
: await createL1TxUtilsFromSigners(
|
|
492
|
+
publicClient,
|
|
493
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
494
|
+
{ ...config, scope: 'sequencer' },
|
|
495
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
496
|
+
);
|
|
432
497
|
|
|
433
498
|
// Create and start the sequencer client
|
|
499
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
500
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
501
|
+
worldStateSynchronizer,
|
|
502
|
+
archiver,
|
|
503
|
+
dateProvider,
|
|
504
|
+
telemetry,
|
|
505
|
+
debugLogStore,
|
|
506
|
+
);
|
|
507
|
+
|
|
434
508
|
sequencer = await SequencerClient.new(config, {
|
|
435
509
|
...deps,
|
|
436
510
|
epochCache,
|
|
@@ -439,12 +513,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
439
513
|
p2pClient,
|
|
440
514
|
worldStateSynchronizer,
|
|
441
515
|
slasherClient,
|
|
442
|
-
|
|
516
|
+
checkpointsBuilder,
|
|
443
517
|
l2BlockSource: archiver,
|
|
444
518
|
l1ToL2MessageSource: archiver,
|
|
445
519
|
telemetry,
|
|
446
520
|
dateProvider,
|
|
447
|
-
|
|
521
|
+
blobClient,
|
|
448
522
|
nodeKeyStore: keyStoreManager!,
|
|
449
523
|
});
|
|
450
524
|
}
|
|
@@ -456,7 +530,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
456
530
|
log.warn(`Sequencer created but not started`);
|
|
457
531
|
}
|
|
458
532
|
|
|
459
|
-
|
|
533
|
+
// Create prover node subsystem if enabled
|
|
534
|
+
let proverNode: ProverNode | undefined;
|
|
535
|
+
if (config.enableProverNode) {
|
|
536
|
+
proverNode = await createProverNode(config, {
|
|
537
|
+
...deps.proverNodeDeps,
|
|
538
|
+
telemetry,
|
|
539
|
+
dateProvider,
|
|
540
|
+
archiver,
|
|
541
|
+
worldStateSynchronizer,
|
|
542
|
+
p2pClient,
|
|
543
|
+
epochCache,
|
|
544
|
+
blobClient,
|
|
545
|
+
keyStoreManager,
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
if (!options.dontStartProverNode) {
|
|
549
|
+
await proverNode.start();
|
|
550
|
+
log.info(`Prover node subsystem started`);
|
|
551
|
+
} else {
|
|
552
|
+
log.info(`Prover node subsystem created but not started`);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
557
|
+
...config,
|
|
558
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
559
|
+
l1GenesisTime,
|
|
560
|
+
slotDuration: Number(slotDuration),
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
const node = new AztecNodeService(
|
|
460
564
|
config,
|
|
461
565
|
p2pClient,
|
|
462
566
|
archiver,
|
|
@@ -465,18 +569,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
465
569
|
archiver,
|
|
466
570
|
worldStateSynchronizer,
|
|
467
571
|
sequencer,
|
|
572
|
+
proverNode,
|
|
468
573
|
slasherClient,
|
|
469
574
|
validatorsSentinel,
|
|
470
575
|
epochPruneWatcher,
|
|
471
576
|
ethereumChain.chainInfo.id,
|
|
472
577
|
config.rollupVersion,
|
|
473
|
-
|
|
578
|
+
globalVariableBuilder,
|
|
474
579
|
epochCache,
|
|
475
580
|
packageVersion,
|
|
476
581
|
proofVerifier,
|
|
477
582
|
telemetry,
|
|
478
583
|
log,
|
|
584
|
+
blobClient,
|
|
585
|
+
validatorClient,
|
|
586
|
+
keyStoreManager,
|
|
587
|
+
debugLogStore,
|
|
479
588
|
);
|
|
589
|
+
|
|
590
|
+
return node;
|
|
480
591
|
}
|
|
481
592
|
|
|
482
593
|
/**
|
|
@@ -487,6 +598,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
487
598
|
return this.sequencer;
|
|
488
599
|
}
|
|
489
600
|
|
|
601
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
602
|
+
public getProverNode(): ProverNode | undefined {
|
|
603
|
+
return this.proverNode;
|
|
604
|
+
}
|
|
605
|
+
|
|
490
606
|
public getBlockSource(): L2BlockSource {
|
|
491
607
|
return this.blockSource;
|
|
492
608
|
}
|
|
@@ -512,7 +628,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
512
628
|
}
|
|
513
629
|
|
|
514
630
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
515
|
-
return this.config.
|
|
631
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
516
632
|
}
|
|
517
633
|
|
|
518
634
|
/**
|
|
@@ -540,19 +656,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
656
|
enr,
|
|
541
657
|
l1ContractAddresses: contractAddresses,
|
|
542
658
|
protocolContractAddresses: protocolContractAddresses,
|
|
659
|
+
realProofs: !!this.config.realProofs,
|
|
543
660
|
};
|
|
544
661
|
|
|
545
662
|
return nodeInfo;
|
|
546
663
|
}
|
|
547
664
|
|
|
548
665
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
666
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
667
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
668
|
* @returns The requested block.
|
|
552
669
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
670
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
671
|
+
if (BlockHash.isBlockHash(block)) {
|
|
672
|
+
return this.getBlockByHash(block);
|
|
673
|
+
}
|
|
674
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
675
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
676
|
+
return this.buildInitialBlock();
|
|
677
|
+
}
|
|
678
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
556
679
|
}
|
|
557
680
|
|
|
558
681
|
/**
|
|
@@ -560,9 +683,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
683
|
* @param blockHash - The block hash being requested.
|
|
561
684
|
* @returns The requested block.
|
|
562
685
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash:
|
|
564
|
-
const
|
|
565
|
-
|
|
686
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
687
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
688
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
689
|
+
return this.buildInitialBlock();
|
|
690
|
+
}
|
|
691
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
private buildInitialBlock(): L2Block {
|
|
695
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
696
|
+
return L2Block.empty(initialHeader);
|
|
566
697
|
}
|
|
567
698
|
|
|
568
699
|
/**
|
|
@@ -571,8 +702,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
571
702
|
* @returns The requested block.
|
|
572
703
|
*/
|
|
573
704
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
705
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
576
706
|
}
|
|
577
707
|
|
|
578
708
|
/**
|
|
@@ -581,34 +711,58 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
711
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
712
|
* @returns The blocks requested.
|
|
583
713
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
714
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
715
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
586
716
|
}
|
|
587
717
|
|
|
588
|
-
public async
|
|
589
|
-
return (await this.blockSource.
|
|
718
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
719
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
723
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
727
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
590
728
|
}
|
|
591
729
|
|
|
592
730
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
731
|
+
* Method to fetch the current min L2 fees.
|
|
732
|
+
* @returns The current min L2 fees.
|
|
595
733
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
734
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
735
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
739
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
740
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
744
|
}
|
|
599
745
|
|
|
600
746
|
/**
|
|
601
747
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
748
|
* @returns The block number.
|
|
603
749
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
750
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
751
|
return await this.blockSource.getBlockNumber();
|
|
606
752
|
}
|
|
607
753
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
754
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
755
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
756
|
}
|
|
611
757
|
|
|
758
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
759
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
763
|
+
return this.blockSource.getCheckpointNumber();
|
|
764
|
+
}
|
|
765
|
+
|
|
612
766
|
/**
|
|
613
767
|
* Method to fetch the version of the package.
|
|
614
768
|
* @returns The node package version
|
|
@@ -641,25 +795,51 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
795
|
return this.contractDataSource.getContract(address);
|
|
642
796
|
}
|
|
643
797
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
798
|
+
public async getPrivateLogsByTags(
|
|
799
|
+
tags: SiloedTag[],
|
|
800
|
+
page?: number,
|
|
801
|
+
referenceBlock?: BlockHash,
|
|
802
|
+
): Promise<TxScopedL2Log[][]> {
|
|
803
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
804
|
+
if (referenceBlock) {
|
|
805
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
806
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
807
|
+
upToBlockNumber = BlockNumber(0);
|
|
808
|
+
} else {
|
|
809
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
810
|
+
if (!header) {
|
|
811
|
+
throw new Error(
|
|
812
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
public async getPublicLogsByTagsFromContract(
|
|
822
|
+
contractAddress: AztecAddress,
|
|
823
|
+
tags: Tag[],
|
|
824
|
+
page?: number,
|
|
825
|
+
referenceBlock?: BlockHash,
|
|
826
|
+
): Promise<TxScopedL2Log[][]> {
|
|
827
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
828
|
+
if (referenceBlock) {
|
|
829
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
830
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
831
|
+
upToBlockNumber = BlockNumber(0);
|
|
832
|
+
} else {
|
|
833
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
834
|
+
if (!header) {
|
|
835
|
+
throw new Error(
|
|
836
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
837
|
+
);
|
|
838
|
+
}
|
|
839
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
663
843
|
}
|
|
664
844
|
|
|
665
845
|
/**
|
|
@@ -685,7 +865,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
865
|
* @param tx - The transaction to be submitted.
|
|
686
866
|
*/
|
|
687
867
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
868
|
+
await this.#sendTx(tx);
|
|
689
869
|
}
|
|
690
870
|
|
|
691
871
|
async #sendTx(tx: Tx) {
|
|
@@ -701,26 +881,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
701
881
|
}
|
|
702
882
|
|
|
703
883
|
await this.p2pClient!.sendTx(tx);
|
|
704
|
-
|
|
705
|
-
this.
|
|
884
|
+
const duration = timer.ms();
|
|
885
|
+
this.metrics.receivedTx(duration, true);
|
|
886
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
706
887
|
}
|
|
707
888
|
|
|
708
889
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
714
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
715
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
716
|
-
}
|
|
890
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
891
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
892
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
893
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
894
|
|
|
895
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
896
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
897
|
+
|
|
898
|
+
let receipt: TxReceipt;
|
|
719
899
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
900
|
+
receipt = settledTxReceipt;
|
|
901
|
+
} else if (isKnownToPool) {
|
|
902
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
903
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
904
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
905
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
906
|
+
} else {
|
|
907
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
908
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
721
909
|
}
|
|
722
910
|
|
|
723
|
-
|
|
911
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
912
|
+
|
|
913
|
+
return receipt;
|
|
724
914
|
}
|
|
725
915
|
|
|
726
916
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,19 +922,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
922
|
*/
|
|
733
923
|
public async stop() {
|
|
734
924
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
925
|
await tryStop(this.validatorsSentinel);
|
|
737
926
|
await tryStop(this.epochPruneWatcher);
|
|
738
927
|
await tryStop(this.slasherClient);
|
|
739
928
|
await tryStop(this.proofVerifier);
|
|
740
929
|
await tryStop(this.sequencer);
|
|
930
|
+
await tryStop(this.proverNode);
|
|
741
931
|
await tryStop(this.p2pClient);
|
|
742
932
|
await tryStop(this.worldStateSynchronizer);
|
|
743
933
|
await tryStop(this.blockSource);
|
|
934
|
+
await tryStop(this.blobClient);
|
|
744
935
|
await tryStop(this.telemetry);
|
|
745
936
|
this.log.info(`Stopped Aztec Node`);
|
|
746
937
|
}
|
|
747
938
|
|
|
939
|
+
/**
|
|
940
|
+
* Returns the blob client used by this node.
|
|
941
|
+
* @internal - Exposed for testing purposes only.
|
|
942
|
+
*/
|
|
943
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
944
|
+
return this.blobClient;
|
|
945
|
+
}
|
|
946
|
+
|
|
748
947
|
/**
|
|
749
948
|
* Method to retrieve pending txs.
|
|
750
949
|
* @param limit - The number of items to returns
|
|
@@ -777,121 +976,95 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
976
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
977
|
}
|
|
779
978
|
|
|
780
|
-
/**
|
|
781
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
782
|
-
* the leaves were inserted.
|
|
783
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
784
|
-
* @param treeId - The tree to search in.
|
|
785
|
-
* @param leafValues - The values to search for.
|
|
786
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
787
|
-
*/
|
|
788
979
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
980
|
+
referenceBlock: BlockParameter,
|
|
790
981
|
treeId: MerkleTreeId,
|
|
791
982
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this
|
|
983
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
984
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
794
985
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
986
|
treeId,
|
|
796
987
|
leafValues.map(x => x.toBuffer()),
|
|
797
988
|
);
|
|
798
|
-
//
|
|
799
|
-
const
|
|
989
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
990
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
800
991
|
|
|
801
|
-
// Now we find the block numbers for the indices
|
|
802
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
992
|
+
// Now we find the block numbers for the defined indices
|
|
993
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
803
994
|
|
|
804
|
-
//
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
995
|
+
// Build a map from leaf index to block number
|
|
996
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
997
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
998
|
+
const blockNumber = blockNumbers[i];
|
|
999
|
+
if (blockNumber === undefined) {
|
|
1000
|
+
throw new Error(
|
|
1001
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1002
|
+
);
|
|
808
1003
|
}
|
|
1004
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
809
1005
|
}
|
|
810
1006
|
|
|
811
1007
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
812
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1008
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
813
1009
|
|
|
814
|
-
// Now we obtain the block hashes from the archive tree
|
|
815
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1010
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
816
1011
|
const blockHashes = await Promise.all(
|
|
817
1012
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
1013
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
1014
|
}),
|
|
820
1015
|
);
|
|
821
1016
|
|
|
822
|
-
//
|
|
1017
|
+
// Build a map from block number to block hash
|
|
1018
|
+
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
823
1019
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
824
|
-
|
|
1020
|
+
const blockHash = blockHashes[i];
|
|
1021
|
+
if (blockHash === undefined) {
|
|
825
1022
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
826
1023
|
}
|
|
1024
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
827
1025
|
}
|
|
828
1026
|
|
|
829
|
-
// Create
|
|
830
|
-
return maybeIndices.map(
|
|
1027
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1028
|
+
return maybeIndices.map(index => {
|
|
831
1029
|
if (index === undefined) {
|
|
832
1030
|
return undefined;
|
|
833
1031
|
}
|
|
834
|
-
const blockNumber =
|
|
1032
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
835
1033
|
if (blockNumber === undefined) {
|
|
836
|
-
|
|
1034
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
837
1035
|
}
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
return undefined;
|
|
1036
|
+
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1037
|
+
if (blockHash === undefined) {
|
|
1038
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
842
1039
|
}
|
|
843
1040
|
return {
|
|
844
|
-
l2BlockNumber:
|
|
845
|
-
l2BlockHash:
|
|
1041
|
+
l2BlockNumber: blockNumber,
|
|
1042
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
846
1043
|
data: index,
|
|
847
1044
|
};
|
|
848
1045
|
});
|
|
849
1046
|
}
|
|
850
1047
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
855
|
-
* @returns The sibling path for the leaf index.
|
|
856
|
-
*/
|
|
857
|
-
public async getNullifierSiblingPath(
|
|
858
|
-
blockNumber: L2BlockNumber,
|
|
859
|
-
leafIndex: bigint,
|
|
860
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
861
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
862
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Returns a sibling path for the given index in the data tree.
|
|
867
|
-
* @param blockNumber - The block number at which to get the data.
|
|
868
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
869
|
-
* @returns The sibling path for the leaf index.
|
|
870
|
-
*/
|
|
871
|
-
public async getNoteHashSiblingPath(
|
|
872
|
-
blockNumber: L2BlockNumber,
|
|
873
|
-
leafIndex: bigint,
|
|
874
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
875
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
876
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
public async getArchiveMembershipWitness(
|
|
880
|
-
blockNumber: L2BlockNumber,
|
|
881
|
-
archive: Fr,
|
|
1048
|
+
public async getBlockHashMembershipWitness(
|
|
1049
|
+
referenceBlock: BlockParameter,
|
|
1050
|
+
blockHash: BlockHash,
|
|
882
1051
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
|
|
884
|
-
|
|
1052
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1053
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1054
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1055
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1056
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1057
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
885
1058
|
return pathAndIndex === undefined
|
|
886
1059
|
? undefined
|
|
887
1060
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
888
1061
|
}
|
|
889
1062
|
|
|
890
1063
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
1064
|
+
referenceBlock: BlockParameter,
|
|
892
1065
|
noteHash: Fr,
|
|
893
1066
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this
|
|
1067
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
895
1068
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
1069
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
1070
|
[noteHash],
|
|
@@ -901,17 +1074,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
1074
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
1075
|
}
|
|
903
1076
|
|
|
904
|
-
/**
|
|
905
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
906
|
-
* @param blockNumber - The block number at which to get the data.
|
|
907
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
908
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
909
|
-
*/
|
|
910
1077
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
1078
|
+
referenceBlock: BlockParameter,
|
|
912
1079
|
l1ToL2Message: Fr,
|
|
913
1080
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this
|
|
1081
|
+
const db = await this.getWorldState(referenceBlock);
|
|
915
1082
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
1083
|
if (!witness) {
|
|
917
1084
|
return undefined;
|
|
@@ -921,9 +1088,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
1088
|
return [witness.index, witness.path];
|
|
922
1089
|
}
|
|
923
1090
|
|
|
924
|
-
public async
|
|
1091
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
925
1092
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex ? InboxLeaf.
|
|
1093
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
927
1094
|
}
|
|
928
1095
|
|
|
929
1096
|
/**
|
|
@@ -937,54 +1104,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
1104
|
}
|
|
938
1105
|
|
|
939
1106
|
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in
|
|
941
|
-
* @param
|
|
942
|
-
* @returns The L2 to L1 messages (
|
|
943
|
-
*/
|
|
944
|
-
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
945
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
946
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
951
|
-
* @param blockNumber - The block number at which to get the data.
|
|
952
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
953
|
-
* @returns The sibling path.
|
|
954
|
-
*/
|
|
955
|
-
public async getArchiveSiblingPath(
|
|
956
|
-
blockNumber: L2BlockNumber,
|
|
957
|
-
leafIndex: bigint,
|
|
958
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
959
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
960
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
/**
|
|
964
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
965
|
-
* @param blockNumber - The block number at which to get the data.
|
|
966
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
967
|
-
* @returns The sibling path.
|
|
1107
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1108
|
+
* @param epoch - The epoch at which to get the data.
|
|
1109
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
968
1110
|
*/
|
|
969
|
-
public async
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1111
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1112
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1113
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1114
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1115
|
+
group => group.map(cb => cb.block),
|
|
1116
|
+
);
|
|
1117
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1118
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1119
|
+
);
|
|
975
1120
|
}
|
|
976
1121
|
|
|
977
|
-
/**
|
|
978
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
979
|
-
* @param blockNumber - The block number at which to get the index.
|
|
980
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
981
|
-
* @returns The nullifier membership witness (if found).
|
|
982
|
-
*/
|
|
983
1122
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1123
|
+
referenceBlock: BlockParameter,
|
|
985
1124
|
nullifier: Fr,
|
|
986
1125
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this
|
|
1126
|
+
const db = await this.getWorldState(referenceBlock);
|
|
988
1127
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1128
|
if (!witness) {
|
|
990
1129
|
return undefined;
|
|
@@ -999,32 +1138,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
999
1138
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1000
1139
|
}
|
|
1001
1140
|
|
|
1002
|
-
/**
|
|
1003
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1005
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
|
-
* @returns The low nullifier membership witness (if found).
|
|
1007
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1008
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1009
|
-
* we are trying to prove non-inclusion for.
|
|
1010
|
-
*
|
|
1011
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1012
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1013
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1014
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
|
-
*/
|
|
1016
1141
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1142
|
+
referenceBlock: BlockParameter,
|
|
1018
1143
|
nullifier: Fr,
|
|
1019
1144
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this
|
|
1145
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1021
1146
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1147
|
if (!findResult) {
|
|
1023
1148
|
return undefined;
|
|
1024
1149
|
}
|
|
1025
1150
|
const { index, alreadyPresent } = findResult;
|
|
1026
1151
|
if (alreadyPresent) {
|
|
1027
|
-
|
|
1152
|
+
throw new Error(
|
|
1153
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1154
|
+
);
|
|
1028
1155
|
}
|
|
1029
1156
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1030
1157
|
|
|
@@ -1032,8 +1159,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1159
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1160
|
}
|
|
1034
1161
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this
|
|
1162
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1163
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1037
1164
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1165
|
if (!lowLeafResult) {
|
|
1039
1166
|
return undefined;
|
|
@@ -1047,19 +1174,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1174
|
}
|
|
1048
1175
|
}
|
|
1049
1176
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
*
|
|
1053
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1054
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1055
|
-
*
|
|
1056
|
-
* @param contract - Address of the contract to query.
|
|
1057
|
-
* @param slot - Slot to query.
|
|
1058
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1059
|
-
* @returns Storage value at the given contract slot.
|
|
1060
|
-
*/
|
|
1061
|
-
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1062
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1177
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1178
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1063
1179
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1180
|
|
|
1065
1181
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1189,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1189
|
return preimage.leaf.value;
|
|
1074
1190
|
}
|
|
1075
1191
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1192
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1193
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1194
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1195
|
+
if (block.equals(initialBlockHash)) {
|
|
1196
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1197
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1198
|
+
}
|
|
1199
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1200
|
+
} else {
|
|
1201
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1202
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1203
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1204
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1205
|
+
}
|
|
1206
|
+
return this.blockSource.getBlockHeader(block);
|
|
1207
|
+
}
|
|
1093
1208
|
}
|
|
1094
1209
|
|
|
1095
1210
|
/**
|
|
@@ -1101,6 +1216,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1101
1216
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1102
1217
|
}
|
|
1103
1218
|
|
|
1219
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1220
|
+
return this.blockSource.getBlockData(number);
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1224
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1104
1227
|
/**
|
|
1105
1228
|
* Simulates the public part of a transaction with the current state.
|
|
1106
1229
|
* @param tx - The transaction to simulate.
|
|
@@ -1124,7 +1247,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1247
|
}
|
|
1125
1248
|
|
|
1126
1249
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const
|
|
1250
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1251
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1128
1252
|
|
|
1129
1253
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1254
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1139,6 +1263,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1263
|
this.contractDataSource,
|
|
1140
1264
|
new DateProvider(),
|
|
1141
1265
|
this.telemetry,
|
|
1266
|
+
this.log.getBindings(),
|
|
1142
1267
|
);
|
|
1143
1268
|
|
|
1144
1269
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1147,16 +1272,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1147
1272
|
blockNumber,
|
|
1148
1273
|
});
|
|
1149
1274
|
|
|
1275
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1276
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1150
1277
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1278
|
try {
|
|
1152
|
-
const
|
|
1279
|
+
const config = PublicSimulatorConfig.from({
|
|
1153
1280
|
skipFeeEnforcement,
|
|
1154
|
-
|
|
1155
|
-
|
|
1281
|
+
collectDebugLogs: true,
|
|
1282
|
+
collectHints: false,
|
|
1283
|
+
collectCallMetadata: true,
|
|
1284
|
+
collectStatistics: false,
|
|
1285
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1286
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1287
|
+
}),
|
|
1156
1288
|
});
|
|
1289
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1157
1290
|
|
|
1158
1291
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1159
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1292
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1160
1293
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1161
1294
|
if (failedTxs.length) {
|
|
1162
1295
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1170,6 +1303,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1170
1303
|
processedTx.txEffect,
|
|
1171
1304
|
returns,
|
|
1172
1305
|
processedTx.gasUsed,
|
|
1306
|
+
debugLogs,
|
|
1173
1307
|
);
|
|
1174
1308
|
} finally {
|
|
1175
1309
|
await merkleTreeFork.close();
|
|
@@ -1183,19 +1317,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1183
1317
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1184
1318
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1185
1319
|
|
|
1186
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1320
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1187
1321
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1188
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1322
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1323
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1324
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1325
|
+
db,
|
|
1326
|
+
this.contractDataSource,
|
|
1327
|
+
verifier,
|
|
1328
|
+
{
|
|
1329
|
+
timestamp: nextSlotTimestamp,
|
|
1330
|
+
blockNumber,
|
|
1331
|
+
l1ChainId: this.l1ChainId,
|
|
1332
|
+
rollupVersion: this.version,
|
|
1333
|
+
setupAllowList: [
|
|
1334
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1335
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1336
|
+
],
|
|
1337
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1338
|
+
skipFeeEnforcement,
|
|
1339
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1340
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1341
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1342
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1343
|
+
},
|
|
1344
|
+
this.log.getBindings(),
|
|
1345
|
+
);
|
|
1199
1346
|
|
|
1200
1347
|
return await validator.validateTx(tx);
|
|
1201
1348
|
}
|
|
@@ -1242,8 +1389,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1242
1389
|
|
|
1243
1390
|
public getValidatorStats(
|
|
1244
1391
|
validatorAddress: EthAddress,
|
|
1245
|
-
fromSlot?:
|
|
1246
|
-
toSlot?:
|
|
1392
|
+
fromSlot?: SlotNumber,
|
|
1393
|
+
toSlot?: SlotNumber,
|
|
1247
1394
|
): Promise<SingleValidatorStats | undefined> {
|
|
1248
1395
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1249
1396
|
}
|
|
@@ -1264,7 +1411,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1264
1411
|
}
|
|
1265
1412
|
|
|
1266
1413
|
// And it has an L2 block hash
|
|
1267
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1414
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1268
1415
|
if (!l2BlockHash) {
|
|
1269
1416
|
this.metrics.recordSnapshotError();
|
|
1270
1417
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1292,13 +1439,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1292
1439
|
return Promise.resolve();
|
|
1293
1440
|
}
|
|
1294
1441
|
|
|
1295
|
-
public async rollbackTo(targetBlock:
|
|
1442
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1296
1443
|
const archiver = this.blockSource as Archiver;
|
|
1297
1444
|
if (!('rollbackTo' in archiver)) {
|
|
1298
1445
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1299
1446
|
}
|
|
1300
1447
|
|
|
1301
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1448
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1302
1449
|
if (targetBlock < finalizedBlock) {
|
|
1303
1450
|
if (force) {
|
|
1304
1451
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1359,17 +1506,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1359
1506
|
}
|
|
1360
1507
|
}
|
|
1361
1508
|
|
|
1509
|
+
public async reloadKeystore(): Promise<void> {
|
|
1510
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1511
|
+
throw new BadRequestError(
|
|
1512
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1513
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
if (!this.validatorClient) {
|
|
1517
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
this.log.info('Reloading keystore from disk');
|
|
1521
|
+
|
|
1522
|
+
// Re-read and validate keystore files
|
|
1523
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1524
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1525
|
+
await newManager.validateSigners();
|
|
1526
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1527
|
+
|
|
1528
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1529
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1530
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1531
|
+
// would silently fail on every proposer slot.
|
|
1532
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1533
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1534
|
+
const availablePublishers = new Set(
|
|
1535
|
+
oldAdapter
|
|
1536
|
+
.getAttesterAddresses()
|
|
1537
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1538
|
+
);
|
|
1539
|
+
|
|
1540
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1541
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1542
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1543
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1544
|
+
throw new BadRequestError(
|
|
1545
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1546
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1547
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1548
|
+
`use an existing publisher key or restart the node.`,
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
// Build adapters for old and new keystores to compute diff
|
|
1555
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1556
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1557
|
+
const oldAddresses = this.keyStoreManager
|
|
1558
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1559
|
+
: [];
|
|
1560
|
+
|
|
1561
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1562
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1563
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1564
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1565
|
+
|
|
1566
|
+
if (added.length > 0) {
|
|
1567
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1568
|
+
}
|
|
1569
|
+
if (removed.length > 0) {
|
|
1570
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1571
|
+
}
|
|
1572
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1573
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1577
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1578
|
+
|
|
1579
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1580
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1581
|
+
if (this.sequencer) {
|
|
1582
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1586
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1587
|
+
const slashValidatorsNever = unique(
|
|
1588
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1589
|
+
).map(EthAddress.fromString);
|
|
1590
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
this.keyStoreManager = newManager;
|
|
1594
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1598
|
+
if (!this.initialHeaderHashPromise) {
|
|
1599
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1600
|
+
}
|
|
1601
|
+
return this.initialHeaderHashPromise;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1362
1604
|
/**
|
|
1363
1605
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1364
|
-
* @param
|
|
1606
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1365
1607
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1366
1608
|
*/
|
|
1367
|
-
async
|
|
1368
|
-
|
|
1369
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
let blockSyncedTo: number = 0;
|
|
1609
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1610
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1373
1611
|
try {
|
|
1374
1612
|
// Attempt to sync the world state if necessary
|
|
1375
1613
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1377,24 +1615,78 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1377
1615
|
this.log.error(`Error getting world state: ${err}`);
|
|
1378
1616
|
}
|
|
1379
1617
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1618
|
+
if (block === 'latest') {
|
|
1619
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1383
1620
|
return this.worldStateSynchronizer.getCommitted();
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1624
|
+
let blockNumber: BlockNumber;
|
|
1625
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1626
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1627
|
+
if (block.equals(initialBlockHash)) {
|
|
1628
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1629
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1633
|
+
if (!header) {
|
|
1634
|
+
throw new Error(
|
|
1635
|
+
`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.`,
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
blockNumber = header.getBlockNumber();
|
|
1387
1640
|
} else {
|
|
1388
|
-
|
|
1641
|
+
blockNumber = block as BlockNumber;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
// Check it's within world state sync range
|
|
1645
|
+
if (blockNumber > blockSyncedTo) {
|
|
1646
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1647
|
+
}
|
|
1648
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1649
|
+
|
|
1650
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1651
|
+
|
|
1652
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1653
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1654
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1655
|
+
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1656
|
+
throw new Error(
|
|
1657
|
+
`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.`,
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
return snapshot;
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/** Resolves a block parameter to a block number. */
|
|
1666
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1667
|
+
if (block === 'latest') {
|
|
1668
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1669
|
+
}
|
|
1670
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1671
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1672
|
+
if (block.equals(initialBlockHash)) {
|
|
1673
|
+
return BlockNumber.ZERO;
|
|
1674
|
+
}
|
|
1675
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1676
|
+
if (!header) {
|
|
1677
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1678
|
+
}
|
|
1679
|
+
return header.getBlockNumber();
|
|
1389
1680
|
}
|
|
1681
|
+
return block as BlockNumber;
|
|
1390
1682
|
}
|
|
1391
1683
|
|
|
1392
1684
|
/**
|
|
1393
1685
|
* Ensure we fully sync the world state
|
|
1394
1686
|
* @returns A promise that fulfils once the world state is synced
|
|
1395
1687
|
*/
|
|
1396
|
-
async #syncWorldState(): Promise<
|
|
1688
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1397
1689
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1398
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1690
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1399
1691
|
}
|
|
1400
1692
|
}
|