@aztec/aztec-node 0.0.1-commit.b655e406 → 0.0.1-commit.c0b82b2
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 +68 -125
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +846 -268
- package/dest/bin/index.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- package/dest/sentinel/config.d.ts +1 -1
- package/dest/sentinel/factory.d.ts +1 -1
- package/dest/sentinel/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 +101 -63
- 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 +31 -28
- package/src/aztec-node/config.ts +34 -14
- package/src/aztec-node/node_metrics.ts +6 -17
- package/src/aztec-node/server.ts +595 -351
- package/src/sentinel/factory.ts +1 -6
- package/src/sentinel/sentinel.ts +136 -82
- 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 } 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 { 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,6 +104,8 @@ 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,
|
|
@@ -128,13 +125,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
128
125
|
*/
|
|
129
126
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
130
127
|
private metrics: NodeMetrics;
|
|
128
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
129
|
|
|
132
130
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
131
|
private isUploadingSnapshot = false;
|
|
134
132
|
|
|
135
|
-
// Serial queue to ensure that we only send one tx at a time
|
|
136
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
137
|
-
|
|
138
133
|
public readonly tracer: Tracer;
|
|
139
134
|
|
|
140
135
|
constructor(
|
|
@@ -146,6 +141,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
146
141
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
147
142
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
148
143
|
protected readonly sequencer: SequencerClient | undefined,
|
|
144
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
149
145
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
150
146
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
151
147
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
@@ -157,13 +153,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
157
153
|
private proofVerifier: ClientProtocolCircuitVerifier,
|
|
158
154
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
159
155
|
private log = createLogger('node'),
|
|
156
|
+
private blobClient?: BlobClientInterface,
|
|
157
|
+
private validatorClient?: ValidatorClient,
|
|
158
|
+
private keyStoreManager?: KeystoreManager,
|
|
159
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
160
160
|
) {
|
|
161
161
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
162
162
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
163
|
-
this.txQueue.start();
|
|
164
163
|
|
|
165
164
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
166
165
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
166
|
+
|
|
167
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
168
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
169
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
170
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
171
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
172
|
+
}
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -187,12 +193,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
187
193
|
logger?: Logger;
|
|
188
194
|
publisher?: SequencerPublisher;
|
|
189
195
|
dateProvider?: DateProvider;
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
p2pClientDeps?: P2PClientDeps;
|
|
197
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
192
198
|
} = {},
|
|
193
199
|
options: {
|
|
194
200
|
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
195
201
|
dontStartSequencer?: boolean;
|
|
202
|
+
dontStartProverNode?: boolean;
|
|
196
203
|
} = {},
|
|
197
204
|
): Promise<AztecNodeService> {
|
|
198
205
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -200,20 +207,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
200
207
|
const packageVersion = getPackageVersion() ?? '';
|
|
201
208
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
202
209
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
203
|
-
const blobSinkClient =
|
|
204
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
205
210
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
206
211
|
|
|
207
|
-
// Build a key store from file if given or from environment otherwise
|
|
212
|
+
// Build a key store from file if given or from environment otherwise.
|
|
213
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
208
214
|
let keyStoreManager: KeystoreManager | undefined;
|
|
209
215
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
210
216
|
if (keyStoreProvided) {
|
|
211
217
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
212
218
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
213
219
|
} else {
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
220
|
+
const rawKeyStores: KeyStore[] = [];
|
|
221
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
222
|
+
if (validatorKeyStore) {
|
|
223
|
+
rawKeyStores.push(validatorKeyStore);
|
|
224
|
+
}
|
|
225
|
+
if (config.enableProverNode) {
|
|
226
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
227
|
+
if (proverKeyStore) {
|
|
228
|
+
rawKeyStores.push(proverKeyStore);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (rawKeyStores.length > 0) {
|
|
232
|
+
keyStoreManager = new KeystoreManager(
|
|
233
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
234
|
+
);
|
|
217
235
|
}
|
|
218
236
|
}
|
|
219
237
|
|
|
@@ -224,10 +242,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
224
242
|
if (keyStoreManager === undefined) {
|
|
225
243
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
226
244
|
}
|
|
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
|
-
);
|
|
245
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
246
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
231
247
|
}
|
|
232
248
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
233
249
|
}
|
|
@@ -241,7 +257,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
241
257
|
|
|
242
258
|
const publicClient = createPublicClient({
|
|
243
259
|
chain: ethereumChain.chainInfo,
|
|
244
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url))),
|
|
260
|
+
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
245
261
|
pollingInterval: config.viemPollingIntervalMS,
|
|
246
262
|
});
|
|
247
263
|
|
|
@@ -269,6 +285,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
269
285
|
);
|
|
270
286
|
}
|
|
271
287
|
|
|
288
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
289
|
+
|
|
272
290
|
// attempt snapshot sync if possible
|
|
273
291
|
await trySnapshotSync(config, log);
|
|
274
292
|
|
|
@@ -276,7 +294,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
276
294
|
|
|
277
295
|
const archiver = await createArchiver(
|
|
278
296
|
config,
|
|
279
|
-
{
|
|
297
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
280
298
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
281
299
|
);
|
|
282
300
|
|
|
@@ -287,15 +305,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
305
|
options.prefilledPublicData,
|
|
288
306
|
telemetry,
|
|
289
307
|
);
|
|
290
|
-
const circuitVerifier =
|
|
308
|
+
const circuitVerifier =
|
|
309
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
310
|
+
? await BBCircuitVerifier.new(config)
|
|
311
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
312
|
+
|
|
313
|
+
let debugLogStore: DebugLogStore;
|
|
291
314
|
if (!config.realProofs) {
|
|
292
315
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
316
|
+
|
|
317
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
318
|
+
log.info(
|
|
319
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
320
|
+
);
|
|
321
|
+
} else {
|
|
322
|
+
debugLogStore = new NullDebugLogStore();
|
|
293
323
|
}
|
|
324
|
+
|
|
294
325
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
295
326
|
|
|
327
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
328
|
+
if (proverOnly) {
|
|
329
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
330
|
+
}
|
|
331
|
+
|
|
296
332
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
297
333
|
const p2pClient = await createP2PClient(
|
|
298
|
-
P2PClientType.Full,
|
|
299
334
|
config,
|
|
300
335
|
archiver,
|
|
301
336
|
proofVerifier,
|
|
@@ -310,7 +345,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
310
345
|
// We should really not be modifying the config object
|
|
311
346
|
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
312
347
|
|
|
313
|
-
|
|
348
|
+
// We'll accumulate sentinel watchers here
|
|
349
|
+
const watchers: Watcher[] = [];
|
|
350
|
+
|
|
351
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation
|
|
352
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
314
353
|
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
315
354
|
worldStateSynchronizer,
|
|
316
355
|
archiver,
|
|
@@ -318,44 +357,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
318
357
|
telemetry,
|
|
319
358
|
);
|
|
320
359
|
|
|
321
|
-
|
|
322
|
-
const watchers: Watcher[] = [];
|
|
360
|
+
let validatorClient: ValidatorClient | undefined;
|
|
323
361
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
l1ToL2MessageSource: archiver,
|
|
333
|
-
keyStoreManager,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
337
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
338
|
-
// like attestations or auths will fail.
|
|
339
|
-
if (validatorClient) {
|
|
340
|
-
watchers.push(validatorClient);
|
|
341
|
-
if (!options.dontStartSequencer) {
|
|
342
|
-
await validatorClient.registerHandlers();
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
347
|
-
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
348
|
-
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
349
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
350
|
-
createBlockProposalHandler(config, {
|
|
351
|
-
blockBuilder,
|
|
362
|
+
if (!proverOnly) {
|
|
363
|
+
// Create validator client if required
|
|
364
|
+
validatorClient = await createValidatorClient(config, {
|
|
365
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
366
|
+
worldState: worldStateSynchronizer,
|
|
367
|
+
p2pClient,
|
|
368
|
+
telemetry,
|
|
369
|
+
dateProvider,
|
|
352
370
|
epochCache,
|
|
353
371
|
blockSource: archiver,
|
|
354
372
|
l1ToL2MessageSource: archiver,
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
373
|
+
keyStoreManager,
|
|
374
|
+
blobClient,
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
378
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
379
|
+
// like attestations or auths will fail.
|
|
380
|
+
if (validatorClient) {
|
|
381
|
+
watchers.push(validatorClient);
|
|
382
|
+
if (!options.dontStartSequencer) {
|
|
383
|
+
await validatorClient.registerHandlers();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
388
|
+
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
389
|
+
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
390
|
+
log.info('Setting up block proposal reexecution for monitoring');
|
|
391
|
+
createBlockProposalHandler(config, {
|
|
392
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
393
|
+
worldState: worldStateSynchronizer,
|
|
394
|
+
epochCache,
|
|
395
|
+
blockSource: archiver,
|
|
396
|
+
l1ToL2MessageSource: archiver,
|
|
397
|
+
p2pClient,
|
|
398
|
+
dateProvider,
|
|
399
|
+
telemetry,
|
|
400
|
+
}).registerForReexecution(p2pClient);
|
|
401
|
+
}
|
|
359
402
|
}
|
|
360
403
|
|
|
361
404
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -364,29 +407,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
364
407
|
// Start p2p. Note that it depends on world state to be running.
|
|
365
408
|
await p2pClient.start();
|
|
366
409
|
|
|
367
|
-
|
|
368
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
369
|
-
watchers.push(validatorsSentinel);
|
|
370
|
-
}
|
|
371
|
-
|
|
410
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
372
411
|
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
412
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
413
|
+
|
|
414
|
+
if (!proverOnly) {
|
|
415
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
416
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
417
|
+
watchers.push(validatorsSentinel);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
421
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
422
|
+
archiver,
|
|
423
|
+
archiver,
|
|
424
|
+
epochCache,
|
|
425
|
+
p2pClient.getTxProvider(),
|
|
426
|
+
validatorCheckpointsBuilder,
|
|
427
|
+
config,
|
|
428
|
+
);
|
|
429
|
+
watchers.push(epochPruneWatcher);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
433
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
434
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
435
|
+
watchers.push(attestationsBlockWatcher);
|
|
436
|
+
}
|
|
390
437
|
}
|
|
391
438
|
|
|
392
439
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -404,7 +451,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
404
451
|
// Validator enabled, create/start relevant service
|
|
405
452
|
let sequencer: SequencerClient | undefined;
|
|
406
453
|
let slasherClient: SlasherClientInterface | undefined;
|
|
407
|
-
if (!config.disableValidator) {
|
|
454
|
+
if (!config.disableValidator && validatorClient) {
|
|
408
455
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
409
456
|
// as they are executed when the node is selected as proposer.
|
|
410
457
|
const validatorAddresses = keyStoreManager
|
|
@@ -423,14 +470,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
423
470
|
);
|
|
424
471
|
await slasherClient.start();
|
|
425
472
|
|
|
426
|
-
const l1TxUtils =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
473
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
474
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
475
|
+
publicClient,
|
|
476
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
477
|
+
config.sequencerPublisherForwarderAddress,
|
|
478
|
+
{ ...config, scope: 'sequencer' },
|
|
479
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
480
|
+
)
|
|
481
|
+
: await createL1TxUtilsFromSigners(
|
|
482
|
+
publicClient,
|
|
483
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
484
|
+
{ ...config, scope: 'sequencer' },
|
|
485
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
486
|
+
);
|
|
432
487
|
|
|
433
488
|
// Create and start the sequencer client
|
|
489
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
490
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
491
|
+
worldStateSynchronizer,
|
|
492
|
+
archiver,
|
|
493
|
+
dateProvider,
|
|
494
|
+
telemetry,
|
|
495
|
+
debugLogStore,
|
|
496
|
+
);
|
|
497
|
+
|
|
434
498
|
sequencer = await SequencerClient.new(config, {
|
|
435
499
|
...deps,
|
|
436
500
|
epochCache,
|
|
@@ -439,12 +503,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
439
503
|
p2pClient,
|
|
440
504
|
worldStateSynchronizer,
|
|
441
505
|
slasherClient,
|
|
442
|
-
|
|
506
|
+
checkpointsBuilder,
|
|
443
507
|
l2BlockSource: archiver,
|
|
444
508
|
l1ToL2MessageSource: archiver,
|
|
445
509
|
telemetry,
|
|
446
510
|
dateProvider,
|
|
447
|
-
|
|
511
|
+
blobClient,
|
|
448
512
|
nodeKeyStore: keyStoreManager!,
|
|
449
513
|
});
|
|
450
514
|
}
|
|
@@ -456,7 +520,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
456
520
|
log.warn(`Sequencer created but not started`);
|
|
457
521
|
}
|
|
458
522
|
|
|
459
|
-
|
|
523
|
+
// Create prover node subsystem if enabled
|
|
524
|
+
let proverNode: ProverNode | undefined;
|
|
525
|
+
if (config.enableProverNode) {
|
|
526
|
+
proverNode = await createProverNode(config, {
|
|
527
|
+
...deps.proverNodeDeps,
|
|
528
|
+
telemetry,
|
|
529
|
+
dateProvider,
|
|
530
|
+
archiver,
|
|
531
|
+
worldStateSynchronizer,
|
|
532
|
+
p2pClient,
|
|
533
|
+
epochCache,
|
|
534
|
+
blobClient,
|
|
535
|
+
keyStoreManager,
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
if (!options.dontStartProverNode) {
|
|
539
|
+
await proverNode.start();
|
|
540
|
+
log.info(`Prover node subsystem started`);
|
|
541
|
+
} else {
|
|
542
|
+
log.info(`Prover node subsystem created but not started`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
547
|
+
...config,
|
|
548
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
549
|
+
l1GenesisTime,
|
|
550
|
+
slotDuration: Number(slotDuration),
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const node = new AztecNodeService(
|
|
460
554
|
config,
|
|
461
555
|
p2pClient,
|
|
462
556
|
archiver,
|
|
@@ -465,18 +559,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
465
559
|
archiver,
|
|
466
560
|
worldStateSynchronizer,
|
|
467
561
|
sequencer,
|
|
562
|
+
proverNode,
|
|
468
563
|
slasherClient,
|
|
469
564
|
validatorsSentinel,
|
|
470
565
|
epochPruneWatcher,
|
|
471
566
|
ethereumChain.chainInfo.id,
|
|
472
567
|
config.rollupVersion,
|
|
473
|
-
|
|
568
|
+
globalVariableBuilder,
|
|
474
569
|
epochCache,
|
|
475
570
|
packageVersion,
|
|
476
571
|
proofVerifier,
|
|
477
572
|
telemetry,
|
|
478
573
|
log,
|
|
574
|
+
blobClient,
|
|
575
|
+
validatorClient,
|
|
576
|
+
keyStoreManager,
|
|
577
|
+
debugLogStore,
|
|
479
578
|
);
|
|
579
|
+
|
|
580
|
+
return node;
|
|
480
581
|
}
|
|
481
582
|
|
|
482
583
|
/**
|
|
@@ -487,6 +588,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
487
588
|
return this.sequencer;
|
|
488
589
|
}
|
|
489
590
|
|
|
591
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
592
|
+
public getProverNode(): ProverNode | undefined {
|
|
593
|
+
return this.proverNode;
|
|
594
|
+
}
|
|
595
|
+
|
|
490
596
|
public getBlockSource(): L2BlockSource {
|
|
491
597
|
return this.blockSource;
|
|
492
598
|
}
|
|
@@ -540,19 +646,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
646
|
enr,
|
|
541
647
|
l1ContractAddresses: contractAddresses,
|
|
542
648
|
protocolContractAddresses: protocolContractAddresses,
|
|
649
|
+
realProofs: !!this.config.realProofs,
|
|
543
650
|
};
|
|
544
651
|
|
|
545
652
|
return nodeInfo;
|
|
546
653
|
}
|
|
547
654
|
|
|
548
655
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
656
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
657
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
658
|
* @returns The requested block.
|
|
552
659
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
660
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
661
|
+
if (BlockHash.isBlockHash(block)) {
|
|
662
|
+
return this.getBlockByHash(block);
|
|
663
|
+
}
|
|
664
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
665
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
666
|
+
return this.buildInitialBlock();
|
|
667
|
+
}
|
|
668
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
556
669
|
}
|
|
557
670
|
|
|
558
671
|
/**
|
|
@@ -560,9 +673,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
673
|
* @param blockHash - The block hash being requested.
|
|
561
674
|
* @returns The requested block.
|
|
562
675
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash:
|
|
564
|
-
const
|
|
565
|
-
|
|
676
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
677
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
678
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
679
|
+
return this.buildInitialBlock();
|
|
680
|
+
}
|
|
681
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private buildInitialBlock(): L2Block {
|
|
685
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
686
|
+
return L2Block.empty(initialHeader);
|
|
566
687
|
}
|
|
567
688
|
|
|
568
689
|
/**
|
|
@@ -571,8 +692,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
571
692
|
* @returns The requested block.
|
|
572
693
|
*/
|
|
573
694
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
695
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
576
696
|
}
|
|
577
697
|
|
|
578
698
|
/**
|
|
@@ -581,34 +701,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
701
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
702
|
* @returns The blocks requested.
|
|
583
703
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
704
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
705
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
709
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
586
710
|
}
|
|
587
711
|
|
|
588
|
-
public async
|
|
589
|
-
return (await this.blockSource.
|
|
712
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
713
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
590
714
|
}
|
|
591
715
|
|
|
592
716
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
717
|
+
* Method to fetch the current min L2 fees.
|
|
718
|
+
* @returns The current min L2 fees.
|
|
595
719
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
720
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
721
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
725
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
726
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
730
|
}
|
|
599
731
|
|
|
600
732
|
/**
|
|
601
733
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
734
|
* @returns The block number.
|
|
603
735
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
736
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
737
|
return await this.blockSource.getBlockNumber();
|
|
606
738
|
}
|
|
607
739
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
740
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
741
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
742
|
}
|
|
611
743
|
|
|
744
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
745
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
746
|
+
}
|
|
747
|
+
|
|
612
748
|
/**
|
|
613
749
|
* Method to fetch the version of the package.
|
|
614
750
|
* @returns The node package version
|
|
@@ -641,25 +777,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
777
|
return this.contractDataSource.getContract(address);
|
|
642
778
|
}
|
|
643
779
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
780
|
+
public async getPrivateLogsByTags(
|
|
781
|
+
tags: SiloedTag[],
|
|
782
|
+
page?: number,
|
|
783
|
+
referenceBlock?: BlockHash,
|
|
784
|
+
): Promise<TxScopedL2Log[][]> {
|
|
785
|
+
if (referenceBlock) {
|
|
786
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
787
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
788
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
789
|
+
if (!header) {
|
|
790
|
+
throw new Error(
|
|
791
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
public async getPublicLogsByTagsFromContract(
|
|
800
|
+
contractAddress: AztecAddress,
|
|
801
|
+
tags: Tag[],
|
|
802
|
+
page?: number,
|
|
803
|
+
referenceBlock?: BlockHash,
|
|
804
|
+
): Promise<TxScopedL2Log[][]> {
|
|
805
|
+
if (referenceBlock) {
|
|
806
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
807
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
808
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
809
|
+
if (!header) {
|
|
810
|
+
throw new Error(
|
|
811
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
663
817
|
}
|
|
664
818
|
|
|
665
819
|
/**
|
|
@@ -685,7 +839,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
839
|
* @param tx - The transaction to be submitted.
|
|
686
840
|
*/
|
|
687
841
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
842
|
+
await this.#sendTx(tx);
|
|
689
843
|
}
|
|
690
844
|
|
|
691
845
|
async #sendTx(tx: Tx) {
|
|
@@ -701,26 +855,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
701
855
|
}
|
|
702
856
|
|
|
703
857
|
await this.p2pClient!.sendTx(tx);
|
|
704
|
-
|
|
705
|
-
this.
|
|
858
|
+
const duration = timer.ms();
|
|
859
|
+
this.metrics.receivedTx(duration, true);
|
|
860
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
706
861
|
}
|
|
707
862
|
|
|
708
863
|
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
|
-
}
|
|
864
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
865
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
866
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
867
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
868
|
|
|
869
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
870
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
871
|
+
|
|
872
|
+
let receipt: TxReceipt;
|
|
719
873
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
874
|
+
receipt = settledTxReceipt;
|
|
875
|
+
} else if (isKnownToPool) {
|
|
876
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
877
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
878
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
879
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
880
|
+
} else {
|
|
881
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
882
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
721
883
|
}
|
|
722
884
|
|
|
723
|
-
|
|
885
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
886
|
+
|
|
887
|
+
return receipt;
|
|
724
888
|
}
|
|
725
889
|
|
|
726
890
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,19 +896,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
896
|
*/
|
|
733
897
|
public async stop() {
|
|
734
898
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
899
|
await tryStop(this.validatorsSentinel);
|
|
737
900
|
await tryStop(this.epochPruneWatcher);
|
|
738
901
|
await tryStop(this.slasherClient);
|
|
739
902
|
await tryStop(this.proofVerifier);
|
|
740
903
|
await tryStop(this.sequencer);
|
|
904
|
+
await tryStop(this.proverNode);
|
|
741
905
|
await tryStop(this.p2pClient);
|
|
742
906
|
await tryStop(this.worldStateSynchronizer);
|
|
743
907
|
await tryStop(this.blockSource);
|
|
908
|
+
await tryStop(this.blobClient);
|
|
744
909
|
await tryStop(this.telemetry);
|
|
745
910
|
this.log.info(`Stopped Aztec Node`);
|
|
746
911
|
}
|
|
747
912
|
|
|
913
|
+
/**
|
|
914
|
+
* Returns the blob client used by this node.
|
|
915
|
+
* @internal - Exposed for testing purposes only.
|
|
916
|
+
*/
|
|
917
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
918
|
+
return this.blobClient;
|
|
919
|
+
}
|
|
920
|
+
|
|
748
921
|
/**
|
|
749
922
|
* Method to retrieve pending txs.
|
|
750
923
|
* @param limit - The number of items to returns
|
|
@@ -777,20 +950,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
950
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
951
|
}
|
|
779
952
|
|
|
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
953
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
954
|
+
referenceBlock: BlockParameter,
|
|
790
955
|
treeId: MerkleTreeId,
|
|
791
956
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this.#getWorldState(
|
|
957
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
958
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
794
959
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
960
|
treeId,
|
|
796
961
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -815,7 +980,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
815
980
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
816
981
|
const blockHashes = await Promise.all(
|
|
817
982
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
983
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
984
|
}),
|
|
820
985
|
);
|
|
821
986
|
|
|
@@ -826,7 +991,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
991
|
}
|
|
827
992
|
}
|
|
828
993
|
|
|
829
|
-
// Create
|
|
994
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
830
995
|
return maybeIndices.map((index, i) => {
|
|
831
996
|
if (index === undefined) {
|
|
832
997
|
return undefined;
|
|
@@ -841,57 +1006,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
841
1006
|
return undefined;
|
|
842
1007
|
}
|
|
843
1008
|
return {
|
|
844
|
-
l2BlockNumber: Number(blockNumber),
|
|
845
|
-
l2BlockHash:
|
|
1009
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
1010
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
846
1011
|
data: index,
|
|
847
1012
|
};
|
|
848
1013
|
});
|
|
849
1014
|
}
|
|
850
1015
|
|
|
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,
|
|
1016
|
+
public async getBlockHashMembershipWitness(
|
|
1017
|
+
referenceBlock: BlockParameter,
|
|
1018
|
+
blockHash: BlockHash,
|
|
882
1019
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
const committedDb = await this.#getWorldState(
|
|
884
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
1020
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1021
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
885
1022
|
return pathAndIndex === undefined
|
|
886
1023
|
? undefined
|
|
887
1024
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
888
1025
|
}
|
|
889
1026
|
|
|
890
1027
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
1028
|
+
referenceBlock: BlockParameter,
|
|
892
1029
|
noteHash: Fr,
|
|
893
1030
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this.#getWorldState(
|
|
1031
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
895
1032
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
1033
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
1034
|
[noteHash],
|
|
@@ -901,17 +1038,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
1038
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
1039
|
}
|
|
903
1040
|
|
|
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
1041
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
1042
|
+
referenceBlock: BlockParameter,
|
|
912
1043
|
l1ToL2Message: Fr,
|
|
913
1044
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this.#getWorldState(
|
|
1045
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
915
1046
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
1047
|
if (!witness) {
|
|
917
1048
|
return undefined;
|
|
@@ -921,9 +1052,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
1052
|
return [witness.index, witness.path];
|
|
922
1053
|
}
|
|
923
1054
|
|
|
924
|
-
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<
|
|
1055
|
+
public async getL1ToL2MessageBlock(l1ToL2Message: Fr): Promise<BlockNumber | undefined> {
|
|
925
1056
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex
|
|
1057
|
+
return messageIndex
|
|
1058
|
+
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
1059
|
+
: undefined;
|
|
927
1060
|
}
|
|
928
1061
|
|
|
929
1062
|
/**
|
|
@@ -937,54 +1070,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
1070
|
}
|
|
938
1071
|
|
|
939
1072
|
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in
|
|
941
|
-
* @param
|
|
942
|
-
* @returns The L2 to L1 messages (
|
|
1073
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1074
|
+
* @param epoch - The epoch at which to get the data.
|
|
1075
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
943
1076
|
*/
|
|
944
|
-
public async getL2ToL1Messages(
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
return
|
|
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.
|
|
968
|
-
*/
|
|
969
|
-
public async getPublicDataSiblingPath(
|
|
970
|
-
blockNumber: L2BlockNumber,
|
|
971
|
-
leafIndex: bigint,
|
|
972
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
973
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
974
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1077
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1078
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1079
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1080
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
1081
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1082
|
+
let checkpointIndex = -1;
|
|
1083
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1084
|
+
const block = checkpointedBlock.block;
|
|
1085
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1086
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1087
|
+
checkpointIndex++;
|
|
1088
|
+
blocksInCheckpoints.push([]);
|
|
1089
|
+
previousSlotNumber = slotNumber;
|
|
1090
|
+
}
|
|
1091
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1092
|
+
}
|
|
1093
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1094
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1095
|
+
);
|
|
975
1096
|
}
|
|
976
1097
|
|
|
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
1098
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1099
|
+
referenceBlock: BlockParameter,
|
|
985
1100
|
nullifier: Fr,
|
|
986
1101
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this.#getWorldState(
|
|
1102
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
988
1103
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1104
|
if (!witness) {
|
|
990
1105
|
return undefined;
|
|
@@ -1001,7 +1116,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1116
|
|
|
1002
1117
|
/**
|
|
1003
1118
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param
|
|
1119
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1120
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1005
1121
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
1122
|
* @returns The low nullifier membership witness (if found).
|
|
1007
1123
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1014,10 +1130,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1130
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
1131
|
*/
|
|
1016
1132
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1133
|
+
referenceBlock: BlockParameter,
|
|
1018
1134
|
nullifier: Fr,
|
|
1019
1135
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(
|
|
1136
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1021
1137
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1138
|
if (!findResult) {
|
|
1023
1139
|
return undefined;
|
|
@@ -1032,8 +1148,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1148
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1149
|
}
|
|
1034
1150
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this.#getWorldState(
|
|
1151
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1152
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1037
1153
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1154
|
if (!lowLeafResult) {
|
|
1039
1155
|
return undefined;
|
|
@@ -1047,19 +1163,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1163
|
}
|
|
1048
1164
|
}
|
|
1049
1165
|
|
|
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);
|
|
1166
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1167
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1063
1168
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1169
|
|
|
1065
1170
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1178,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1178
|
return preimage.leaf.value;
|
|
1074
1179
|
}
|
|
1075
1180
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1181
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1182
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1183
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1184
|
+
if (block.equals(initialBlockHash)) {
|
|
1185
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1186
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1187
|
+
}
|
|
1188
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1189
|
+
} else {
|
|
1190
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1191
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1192
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1193
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1194
|
+
}
|
|
1195
|
+
return this.blockSource.getBlockHeader(block);
|
|
1196
|
+
}
|
|
1093
1197
|
}
|
|
1094
1198
|
|
|
1095
1199
|
/**
|
|
@@ -1101,6 +1205,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1101
1205
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1102
1206
|
}
|
|
1103
1207
|
|
|
1208
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1209
|
+
return this.blockSource.getBlockData(number);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1213
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1104
1216
|
/**
|
|
1105
1217
|
* Simulates the public part of a transaction with the current state.
|
|
1106
1218
|
* @param tx - The transaction to simulate.
|
|
@@ -1124,7 +1236,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1236
|
}
|
|
1125
1237
|
|
|
1126
1238
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const
|
|
1239
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1240
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1128
1241
|
|
|
1129
1242
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1243
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1139,6 +1252,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1252
|
this.contractDataSource,
|
|
1140
1253
|
new DateProvider(),
|
|
1141
1254
|
this.telemetry,
|
|
1255
|
+
this.log.getBindings(),
|
|
1142
1256
|
);
|
|
1143
1257
|
|
|
1144
1258
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1147,16 +1261,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1147
1261
|
blockNumber,
|
|
1148
1262
|
});
|
|
1149
1263
|
|
|
1264
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1265
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1150
1266
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1267
|
try {
|
|
1152
|
-
const
|
|
1268
|
+
const config = PublicSimulatorConfig.from({
|
|
1153
1269
|
skipFeeEnforcement,
|
|
1154
|
-
|
|
1155
|
-
|
|
1270
|
+
collectDebugLogs: true,
|
|
1271
|
+
collectHints: false,
|
|
1272
|
+
collectCallMetadata: true,
|
|
1273
|
+
collectStatistics: false,
|
|
1274
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1275
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1276
|
+
}),
|
|
1156
1277
|
});
|
|
1278
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1157
1279
|
|
|
1158
1280
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1159
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1281
|
+
const [processedTxs, failedTxs, _usedTxs, returns, _blobFields, debugLogs] = await processor.process([tx]);
|
|
1160
1282
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1161
1283
|
if (failedTxs.length) {
|
|
1162
1284
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1170,6 +1292,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1170
1292
|
processedTx.txEffect,
|
|
1171
1293
|
returns,
|
|
1172
1294
|
processedTx.gasUsed,
|
|
1295
|
+
debugLogs,
|
|
1173
1296
|
);
|
|
1174
1297
|
} finally {
|
|
1175
1298
|
await merkleTreeFork.close();
|
|
@@ -1183,19 +1306,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1183
1306
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1184
1307
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1185
1308
|
|
|
1186
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1309
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1187
1310
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1188
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1189
|
-
const validator =
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1311
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1312
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1313
|
+
db,
|
|
1314
|
+
this.contractDataSource,
|
|
1315
|
+
verifier,
|
|
1316
|
+
{
|
|
1317
|
+
timestamp: nextSlotTimestamp,
|
|
1318
|
+
blockNumber,
|
|
1319
|
+
l1ChainId: this.l1ChainId,
|
|
1320
|
+
rollupVersion: this.version,
|
|
1321
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
|
|
1322
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1323
|
+
skipFeeEnforcement,
|
|
1324
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1325
|
+
},
|
|
1326
|
+
this.log.getBindings(),
|
|
1327
|
+
);
|
|
1199
1328
|
|
|
1200
1329
|
return await validator.validateTx(tx);
|
|
1201
1330
|
}
|
|
@@ -1242,8 +1371,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1242
1371
|
|
|
1243
1372
|
public getValidatorStats(
|
|
1244
1373
|
validatorAddress: EthAddress,
|
|
1245
|
-
fromSlot?:
|
|
1246
|
-
toSlot?:
|
|
1374
|
+
fromSlot?: SlotNumber,
|
|
1375
|
+
toSlot?: SlotNumber,
|
|
1247
1376
|
): Promise<SingleValidatorStats | undefined> {
|
|
1248
1377
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1249
1378
|
}
|
|
@@ -1264,7 +1393,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1264
1393
|
}
|
|
1265
1394
|
|
|
1266
1395
|
// And it has an L2 block hash
|
|
1267
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1396
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1268
1397
|
if (!l2BlockHash) {
|
|
1269
1398
|
this.metrics.recordSnapshotError();
|
|
1270
1399
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
@@ -1292,13 +1421,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1292
1421
|
return Promise.resolve();
|
|
1293
1422
|
}
|
|
1294
1423
|
|
|
1295
|
-
public async rollbackTo(targetBlock:
|
|
1424
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1296
1425
|
const archiver = this.blockSource as Archiver;
|
|
1297
1426
|
if (!('rollbackTo' in archiver)) {
|
|
1298
1427
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1299
1428
|
}
|
|
1300
1429
|
|
|
1301
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1430
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1302
1431
|
if (targetBlock < finalizedBlock) {
|
|
1303
1432
|
if (force) {
|
|
1304
1433
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1359,17 +1488,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1359
1488
|
}
|
|
1360
1489
|
}
|
|
1361
1490
|
|
|
1491
|
+
public async reloadKeystore(): Promise<void> {
|
|
1492
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1493
|
+
throw new BadRequestError(
|
|
1494
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1495
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
if (!this.validatorClient) {
|
|
1499
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
this.log.info('Reloading keystore from disk');
|
|
1503
|
+
|
|
1504
|
+
// Re-read and validate keystore files
|
|
1505
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1506
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1507
|
+
await newManager.validateSigners();
|
|
1508
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1509
|
+
|
|
1510
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1511
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1512
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1513
|
+
// would silently fail on every proposer slot.
|
|
1514
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1515
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1516
|
+
const availablePublishers = new Set(
|
|
1517
|
+
oldAdapter
|
|
1518
|
+
.getAttesterAddresses()
|
|
1519
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1520
|
+
);
|
|
1521
|
+
|
|
1522
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1523
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1524
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1525
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1526
|
+
throw new BadRequestError(
|
|
1527
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1528
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1529
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1530
|
+
`use an existing publisher key or restart the node.`,
|
|
1531
|
+
);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// Build adapters for old and new keystores to compute diff
|
|
1537
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1538
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1539
|
+
const oldAddresses = this.keyStoreManager
|
|
1540
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1541
|
+
: [];
|
|
1542
|
+
|
|
1543
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1544
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1545
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1546
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1547
|
+
|
|
1548
|
+
if (added.length > 0) {
|
|
1549
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1550
|
+
}
|
|
1551
|
+
if (removed.length > 0) {
|
|
1552
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1553
|
+
}
|
|
1554
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1555
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1559
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1560
|
+
|
|
1561
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1562
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1563
|
+
if (this.sequencer) {
|
|
1564
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1568
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1569
|
+
const slashValidatorsNever = unique(
|
|
1570
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1571
|
+
).map(EthAddress.fromString);
|
|
1572
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
this.keyStoreManager = newManager;
|
|
1576
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1580
|
+
if (!this.initialHeaderHashPromise) {
|
|
1581
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1582
|
+
}
|
|
1583
|
+
return this.initialHeaderHashPromise;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1362
1586
|
/**
|
|
1363
1587
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1364
|
-
* @param
|
|
1588
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1365
1589
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1366
1590
|
*/
|
|
1367
|
-
async #getWorldState(
|
|
1368
|
-
|
|
1369
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
let blockSyncedTo: number = 0;
|
|
1591
|
+
async #getWorldState(block: BlockParameter) {
|
|
1592
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1373
1593
|
try {
|
|
1374
1594
|
// Attempt to sync the world state if necessary
|
|
1375
1595
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1377,15 +1597,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1377
1597
|
this.log.error(`Error getting world state: ${err}`);
|
|
1378
1598
|
}
|
|
1379
1599
|
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1600
|
+
if (block === 'latest') {
|
|
1601
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1383
1602
|
return this.worldStateSynchronizer.getCommitted();
|
|
1384
|
-
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1606
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1607
|
+
if (block.equals(initialBlockHash)) {
|
|
1608
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1609
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1613
|
+
if (!header) {
|
|
1614
|
+
throw new Error(
|
|
1615
|
+
`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.`,
|
|
1616
|
+
);
|
|
1617
|
+
}
|
|
1618
|
+
const blockNumber = header.getBlockNumber();
|
|
1619
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1620
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
// Block number provided
|
|
1624
|
+
{
|
|
1625
|
+
const blockNumber = block as BlockNumber;
|
|
1626
|
+
|
|
1627
|
+
if (blockNumber > blockSyncedTo) {
|
|
1628
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1385
1631
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1386
1632
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1387
|
-
} else {
|
|
1388
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1389
1633
|
}
|
|
1390
1634
|
}
|
|
1391
1635
|
|
|
@@ -1393,8 +1637,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1393
1637
|
* Ensure we fully sync the world state
|
|
1394
1638
|
* @returns A promise that fulfils once the world state is synced
|
|
1395
1639
|
*/
|
|
1396
|
-
async #syncWorldState(): Promise<
|
|
1640
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1397
1641
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1398
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1642
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1399
1643
|
}
|
|
1400
1644
|
}
|