@aztec/aztec-node 0.0.1-fake-c83136db25 → 0.0.1-private.d0bedffd
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 +5 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +20 -6
- package/dest/aztec-node/server.d.ts +69 -125
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +869 -270
- 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 +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 +35 -15
- package/src/aztec-node/node_metrics.ts +23 -6
- package/src/aztec-node/server.ts +611 -348
- package/src/sentinel/factory.ts +2 -7
- 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
|
|
|
@@ -255,10 +271,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
255
271
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
256
272
|
|
|
257
273
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
258
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
274
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
259
275
|
rollupContract.getL1GenesisTime(),
|
|
260
276
|
rollupContract.getSlotDuration(),
|
|
261
277
|
rollupContract.getVersion(),
|
|
278
|
+
rollupContract.getManaLimit().then(Number),
|
|
262
279
|
] as const);
|
|
263
280
|
|
|
264
281
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -269,6 +286,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
269
286
|
);
|
|
270
287
|
}
|
|
271
288
|
|
|
289
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
290
|
+
|
|
272
291
|
// attempt snapshot sync if possible
|
|
273
292
|
await trySnapshotSync(config, log);
|
|
274
293
|
|
|
@@ -276,7 +295,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
276
295
|
|
|
277
296
|
const archiver = await createArchiver(
|
|
278
297
|
config,
|
|
279
|
-
{
|
|
298
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
280
299
|
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
281
300
|
);
|
|
282
301
|
|
|
@@ -287,15 +306,32 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
287
306
|
options.prefilledPublicData,
|
|
288
307
|
telemetry,
|
|
289
308
|
);
|
|
290
|
-
const circuitVerifier =
|
|
309
|
+
const circuitVerifier =
|
|
310
|
+
config.realProofs || config.debugForceTxProofVerification
|
|
311
|
+
? await BBCircuitVerifier.new(config)
|
|
312
|
+
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
313
|
+
|
|
314
|
+
let debugLogStore: DebugLogStore;
|
|
291
315
|
if (!config.realProofs) {
|
|
292
316
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
317
|
+
|
|
318
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
319
|
+
log.info(
|
|
320
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
321
|
+
);
|
|
322
|
+
} else {
|
|
323
|
+
debugLogStore = new NullDebugLogStore();
|
|
293
324
|
}
|
|
325
|
+
|
|
294
326
|
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
295
327
|
|
|
328
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
329
|
+
if (proverOnly) {
|
|
330
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
331
|
+
}
|
|
332
|
+
|
|
296
333
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
297
334
|
const p2pClient = await createP2PClient(
|
|
298
|
-
P2PClientType.Full,
|
|
299
335
|
config,
|
|
300
336
|
archiver,
|
|
301
337
|
proofVerifier,
|
|
@@ -307,55 +343,69 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
307
343
|
deps.p2pClientDeps,
|
|
308
344
|
);
|
|
309
345
|
|
|
310
|
-
// We
|
|
311
|
-
|
|
346
|
+
// We'll accumulate sentinel watchers here
|
|
347
|
+
const watchers: Watcher[] = [];
|
|
312
348
|
|
|
313
|
-
|
|
314
|
-
|
|
349
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
350
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
351
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
352
|
+
{
|
|
353
|
+
...config,
|
|
354
|
+
l1GenesisTime,
|
|
355
|
+
slotDuration: Number(slotDuration),
|
|
356
|
+
rollupManaLimit,
|
|
357
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
358
|
+
},
|
|
315
359
|
worldStateSynchronizer,
|
|
316
360
|
archiver,
|
|
317
361
|
dateProvider,
|
|
318
362
|
telemetry,
|
|
319
363
|
);
|
|
320
364
|
|
|
321
|
-
|
|
322
|
-
const watchers: Watcher[] = [];
|
|
365
|
+
let validatorClient: ValidatorClient | undefined;
|
|
323
366
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
367
|
+
if (!proverOnly) {
|
|
368
|
+
// Create validator client if required
|
|
369
|
+
validatorClient = await createValidatorClient(config, {
|
|
370
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
371
|
+
worldState: worldStateSynchronizer,
|
|
372
|
+
p2pClient,
|
|
373
|
+
telemetry,
|
|
374
|
+
dateProvider,
|
|
375
|
+
epochCache,
|
|
376
|
+
blockSource: archiver,
|
|
377
|
+
l1ToL2MessageSource: archiver,
|
|
378
|
+
keyStoreManager,
|
|
379
|
+
blobClient,
|
|
380
|
+
});
|
|
335
381
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
382
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
383
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
384
|
+
// like attestations or auths will fail.
|
|
385
|
+
if (validatorClient) {
|
|
386
|
+
watchers.push(validatorClient);
|
|
387
|
+
if (!options.dontStartSequencer) {
|
|
388
|
+
await validatorClient.registerHandlers();
|
|
389
|
+
}
|
|
343
390
|
}
|
|
344
391
|
}
|
|
345
392
|
|
|
346
|
-
// If there's no validator client
|
|
347
|
-
//
|
|
348
|
-
|
|
349
|
-
|
|
393
|
+
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
394
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
395
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
396
|
+
if (!validatorClient) {
|
|
397
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
398
|
+
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
350
399
|
createBlockProposalHandler(config, {
|
|
351
|
-
|
|
400
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
401
|
+
worldState: worldStateSynchronizer,
|
|
352
402
|
epochCache,
|
|
353
403
|
blockSource: archiver,
|
|
354
404
|
l1ToL2MessageSource: archiver,
|
|
355
405
|
p2pClient,
|
|
356
406
|
dateProvider,
|
|
357
407
|
telemetry,
|
|
358
|
-
}).
|
|
408
|
+
}).register(p2pClient, reexecute);
|
|
359
409
|
}
|
|
360
410
|
|
|
361
411
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -364,29 +414,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
364
414
|
// Start p2p. Note that it depends on world state to be running.
|
|
365
415
|
await p2pClient.start();
|
|
366
416
|
|
|
367
|
-
|
|
368
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
369
|
-
watchers.push(validatorsSentinel);
|
|
370
|
-
}
|
|
371
|
-
|
|
417
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
372
418
|
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
419
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
420
|
+
|
|
421
|
+
if (!proverOnly) {
|
|
422
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
423
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
424
|
+
watchers.push(validatorsSentinel);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
428
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
429
|
+
archiver,
|
|
430
|
+
archiver,
|
|
431
|
+
epochCache,
|
|
432
|
+
p2pClient.getTxProvider(),
|
|
433
|
+
validatorCheckpointsBuilder,
|
|
434
|
+
config,
|
|
435
|
+
);
|
|
436
|
+
watchers.push(epochPruneWatcher);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
440
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
441
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
442
|
+
watchers.push(attestationsBlockWatcher);
|
|
443
|
+
}
|
|
390
444
|
}
|
|
391
445
|
|
|
392
446
|
// Start p2p-related services once the archiver has completed sync
|
|
@@ -404,7 +458,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
404
458
|
// Validator enabled, create/start relevant service
|
|
405
459
|
let sequencer: SequencerClient | undefined;
|
|
406
460
|
let slasherClient: SlasherClientInterface | undefined;
|
|
407
|
-
if (!config.disableValidator) {
|
|
461
|
+
if (!config.disableValidator && validatorClient) {
|
|
408
462
|
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
409
463
|
// as they are executed when the node is selected as proposer.
|
|
410
464
|
const validatorAddresses = keyStoreManager
|
|
@@ -423,14 +477,31 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
423
477
|
);
|
|
424
478
|
await slasherClient.start();
|
|
425
479
|
|
|
426
|
-
const l1TxUtils =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
480
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
481
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
482
|
+
publicClient,
|
|
483
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
484
|
+
config.sequencerPublisherForwarderAddress,
|
|
485
|
+
{ ...config, scope: 'sequencer' },
|
|
486
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
487
|
+
)
|
|
488
|
+
: await createL1TxUtilsFromSigners(
|
|
489
|
+
publicClient,
|
|
490
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
491
|
+
{ ...config, scope: 'sequencer' },
|
|
492
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
493
|
+
);
|
|
432
494
|
|
|
433
495
|
// Create and start the sequencer client
|
|
496
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
497
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
498
|
+
worldStateSynchronizer,
|
|
499
|
+
archiver,
|
|
500
|
+
dateProvider,
|
|
501
|
+
telemetry,
|
|
502
|
+
debugLogStore,
|
|
503
|
+
);
|
|
504
|
+
|
|
434
505
|
sequencer = await SequencerClient.new(config, {
|
|
435
506
|
...deps,
|
|
436
507
|
epochCache,
|
|
@@ -439,12 +510,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
439
510
|
p2pClient,
|
|
440
511
|
worldStateSynchronizer,
|
|
441
512
|
slasherClient,
|
|
442
|
-
|
|
513
|
+
checkpointsBuilder,
|
|
443
514
|
l2BlockSource: archiver,
|
|
444
515
|
l1ToL2MessageSource: archiver,
|
|
445
516
|
telemetry,
|
|
446
517
|
dateProvider,
|
|
447
|
-
|
|
518
|
+
blobClient,
|
|
448
519
|
nodeKeyStore: keyStoreManager!,
|
|
449
520
|
});
|
|
450
521
|
}
|
|
@@ -456,7 +527,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
456
527
|
log.warn(`Sequencer created but not started`);
|
|
457
528
|
}
|
|
458
529
|
|
|
459
|
-
|
|
530
|
+
// Create prover node subsystem if enabled
|
|
531
|
+
let proverNode: ProverNode | undefined;
|
|
532
|
+
if (config.enableProverNode) {
|
|
533
|
+
proverNode = await createProverNode(config, {
|
|
534
|
+
...deps.proverNodeDeps,
|
|
535
|
+
telemetry,
|
|
536
|
+
dateProvider,
|
|
537
|
+
archiver,
|
|
538
|
+
worldStateSynchronizer,
|
|
539
|
+
p2pClient,
|
|
540
|
+
epochCache,
|
|
541
|
+
blobClient,
|
|
542
|
+
keyStoreManager,
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
if (!options.dontStartProverNode) {
|
|
546
|
+
await proverNode.start();
|
|
547
|
+
log.info(`Prover node subsystem started`);
|
|
548
|
+
} else {
|
|
549
|
+
log.info(`Prover node subsystem created but not started`);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const globalVariableBuilder = new GlobalVariableBuilder({
|
|
554
|
+
...config,
|
|
555
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
556
|
+
l1GenesisTime,
|
|
557
|
+
slotDuration: Number(slotDuration),
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
const node = new AztecNodeService(
|
|
460
561
|
config,
|
|
461
562
|
p2pClient,
|
|
462
563
|
archiver,
|
|
@@ -465,18 +566,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
465
566
|
archiver,
|
|
466
567
|
worldStateSynchronizer,
|
|
467
568
|
sequencer,
|
|
569
|
+
proverNode,
|
|
468
570
|
slasherClient,
|
|
469
571
|
validatorsSentinel,
|
|
470
572
|
epochPruneWatcher,
|
|
471
573
|
ethereumChain.chainInfo.id,
|
|
472
574
|
config.rollupVersion,
|
|
473
|
-
|
|
575
|
+
globalVariableBuilder,
|
|
474
576
|
epochCache,
|
|
475
577
|
packageVersion,
|
|
476
578
|
proofVerifier,
|
|
477
579
|
telemetry,
|
|
478
580
|
log,
|
|
581
|
+
blobClient,
|
|
582
|
+
validatorClient,
|
|
583
|
+
keyStoreManager,
|
|
584
|
+
debugLogStore,
|
|
479
585
|
);
|
|
586
|
+
|
|
587
|
+
return node;
|
|
480
588
|
}
|
|
481
589
|
|
|
482
590
|
/**
|
|
@@ -487,6 +595,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
487
595
|
return this.sequencer;
|
|
488
596
|
}
|
|
489
597
|
|
|
598
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
599
|
+
public getProverNode(): ProverNode | undefined {
|
|
600
|
+
return this.proverNode;
|
|
601
|
+
}
|
|
602
|
+
|
|
490
603
|
public getBlockSource(): L2BlockSource {
|
|
491
604
|
return this.blockSource;
|
|
492
605
|
}
|
|
@@ -512,7 +625,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
512
625
|
}
|
|
513
626
|
|
|
514
627
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
515
|
-
return this.config.
|
|
628
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
516
629
|
}
|
|
517
630
|
|
|
518
631
|
/**
|
|
@@ -540,19 +653,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
653
|
enr,
|
|
541
654
|
l1ContractAddresses: contractAddresses,
|
|
542
655
|
protocolContractAddresses: protocolContractAddresses,
|
|
656
|
+
realProofs: !!this.config.realProofs,
|
|
543
657
|
};
|
|
544
658
|
|
|
545
659
|
return nodeInfo;
|
|
546
660
|
}
|
|
547
661
|
|
|
548
662
|
/**
|
|
549
|
-
* Get a block specified by its number.
|
|
550
|
-
* @param
|
|
663
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
664
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
551
665
|
* @returns The requested block.
|
|
552
666
|
*/
|
|
553
|
-
public async getBlock(
|
|
554
|
-
|
|
555
|
-
|
|
667
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
668
|
+
if (BlockHash.isBlockHash(block)) {
|
|
669
|
+
return this.getBlockByHash(block);
|
|
670
|
+
}
|
|
671
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
672
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
673
|
+
return this.buildInitialBlock();
|
|
674
|
+
}
|
|
675
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
556
676
|
}
|
|
557
677
|
|
|
558
678
|
/**
|
|
@@ -560,9 +680,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
560
680
|
* @param blockHash - The block hash being requested.
|
|
561
681
|
* @returns The requested block.
|
|
562
682
|
*/
|
|
563
|
-
public async getBlockByHash(blockHash:
|
|
564
|
-
const
|
|
565
|
-
|
|
683
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
684
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
685
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
686
|
+
return this.buildInitialBlock();
|
|
687
|
+
}
|
|
688
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
private buildInitialBlock(): L2Block {
|
|
692
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
693
|
+
return L2Block.empty(initialHeader);
|
|
566
694
|
}
|
|
567
695
|
|
|
568
696
|
/**
|
|
@@ -571,8 +699,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
571
699
|
* @returns The requested block.
|
|
572
700
|
*/
|
|
573
701
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
|
|
575
|
-
return publishedBlock?.block;
|
|
702
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
576
703
|
}
|
|
577
704
|
|
|
578
705
|
/**
|
|
@@ -581,34 +708,54 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
581
708
|
* @param limit - The maximum number of blocks to obtain.
|
|
582
709
|
* @returns The blocks requested.
|
|
583
710
|
*/
|
|
584
|
-
public async getBlocks(from:
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
711
|
+
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
712
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
716
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
586
717
|
}
|
|
587
718
|
|
|
588
|
-
public async
|
|
589
|
-
return (await this.blockSource.
|
|
719
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
720
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
590
721
|
}
|
|
591
722
|
|
|
592
723
|
/**
|
|
593
|
-
* Method to fetch the current
|
|
594
|
-
* @returns The current
|
|
724
|
+
* Method to fetch the current min L2 fees.
|
|
725
|
+
* @returns The current min L2 fees.
|
|
595
726
|
*/
|
|
596
|
-
public async
|
|
597
|
-
return await this.globalVariableBuilder.
|
|
727
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
728
|
+
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
732
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
733
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
598
737
|
}
|
|
599
738
|
|
|
600
739
|
/**
|
|
601
740
|
* Method to fetch the latest block number synchronized by the node.
|
|
602
741
|
* @returns The block number.
|
|
603
742
|
*/
|
|
604
|
-
public async getBlockNumber(): Promise<
|
|
743
|
+
public async getBlockNumber(): Promise<BlockNumber> {
|
|
605
744
|
return await this.blockSource.getBlockNumber();
|
|
606
745
|
}
|
|
607
746
|
|
|
608
|
-
public async getProvenBlockNumber(): Promise<
|
|
747
|
+
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
609
748
|
return await this.blockSource.getProvenBlockNumber();
|
|
610
749
|
}
|
|
611
750
|
|
|
751
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
752
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
756
|
+
return this.blockSource.getCheckpointNumber();
|
|
757
|
+
}
|
|
758
|
+
|
|
612
759
|
/**
|
|
613
760
|
* Method to fetch the version of the package.
|
|
614
761
|
* @returns The node package version
|
|
@@ -641,25 +788,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
788
|
return this.contractDataSource.getContract(address);
|
|
642
789
|
}
|
|
643
790
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
791
|
+
public async getPrivateLogsByTags(
|
|
792
|
+
tags: SiloedTag[],
|
|
793
|
+
page?: number,
|
|
794
|
+
referenceBlock?: BlockHash,
|
|
795
|
+
): Promise<TxScopedL2Log[][]> {
|
|
796
|
+
if (referenceBlock) {
|
|
797
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
798
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
799
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
800
|
+
if (!header) {
|
|
801
|
+
throw new Error(
|
|
802
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
public async getPublicLogsByTagsFromContract(
|
|
811
|
+
contractAddress: AztecAddress,
|
|
812
|
+
tags: Tag[],
|
|
813
|
+
page?: number,
|
|
814
|
+
referenceBlock?: BlockHash,
|
|
815
|
+
): Promise<TxScopedL2Log[][]> {
|
|
816
|
+
if (referenceBlock) {
|
|
817
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
818
|
+
if (!referenceBlock.equals(initialBlockHash)) {
|
|
819
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
820
|
+
if (!header) {
|
|
821
|
+
throw new Error(
|
|
822
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
663
828
|
}
|
|
664
829
|
|
|
665
830
|
/**
|
|
@@ -685,7 +850,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
850
|
* @param tx - The transaction to be submitted.
|
|
686
851
|
*/
|
|
687
852
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
853
|
+
await this.#sendTx(tx);
|
|
689
854
|
}
|
|
690
855
|
|
|
691
856
|
async #sendTx(tx: Tx) {
|
|
@@ -701,26 +866,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
701
866
|
}
|
|
702
867
|
|
|
703
868
|
await this.p2pClient!.sendTx(tx);
|
|
704
|
-
|
|
705
|
-
this.
|
|
869
|
+
const duration = timer.ms();
|
|
870
|
+
this.metrics.receivedTx(duration, true);
|
|
871
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
706
872
|
}
|
|
707
873
|
|
|
708
874
|
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
|
-
}
|
|
875
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
876
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
877
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
878
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
879
|
|
|
880
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
881
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
882
|
+
|
|
883
|
+
let receipt: TxReceipt;
|
|
719
884
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
885
|
+
receipt = settledTxReceipt;
|
|
886
|
+
} else if (isKnownToPool) {
|
|
887
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
888
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
889
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
890
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
891
|
+
} else {
|
|
892
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
893
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
721
894
|
}
|
|
722
895
|
|
|
723
|
-
|
|
896
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
897
|
+
|
|
898
|
+
return receipt;
|
|
724
899
|
}
|
|
725
900
|
|
|
726
901
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,19 +907,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
907
|
*/
|
|
733
908
|
public async stop() {
|
|
734
909
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.txQueue.end();
|
|
736
910
|
await tryStop(this.validatorsSentinel);
|
|
737
911
|
await tryStop(this.epochPruneWatcher);
|
|
738
912
|
await tryStop(this.slasherClient);
|
|
739
913
|
await tryStop(this.proofVerifier);
|
|
740
914
|
await tryStop(this.sequencer);
|
|
915
|
+
await tryStop(this.proverNode);
|
|
741
916
|
await tryStop(this.p2pClient);
|
|
742
917
|
await tryStop(this.worldStateSynchronizer);
|
|
743
918
|
await tryStop(this.blockSource);
|
|
919
|
+
await tryStop(this.blobClient);
|
|
744
920
|
await tryStop(this.telemetry);
|
|
745
921
|
this.log.info(`Stopped Aztec Node`);
|
|
746
922
|
}
|
|
747
923
|
|
|
924
|
+
/**
|
|
925
|
+
* Returns the blob client used by this node.
|
|
926
|
+
* @internal - Exposed for testing purposes only.
|
|
927
|
+
*/
|
|
928
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
929
|
+
return this.blobClient;
|
|
930
|
+
}
|
|
931
|
+
|
|
748
932
|
/**
|
|
749
933
|
* Method to retrieve pending txs.
|
|
750
934
|
* @param limit - The number of items to returns
|
|
@@ -777,20 +961,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
961
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
962
|
}
|
|
779
963
|
|
|
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
964
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
965
|
+
referenceBlock: BlockParameter,
|
|
790
966
|
treeId: MerkleTreeId,
|
|
791
967
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this.#getWorldState(
|
|
968
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
969
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
794
970
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
971
|
treeId,
|
|
796
972
|
leafValues.map(x => x.toBuffer()),
|
|
@@ -815,7 +991,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
815
991
|
// (note that block number corresponds to the leaf index in the archive tree).
|
|
816
992
|
const blockHashes = await Promise.all(
|
|
817
993
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
994
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
995
|
}),
|
|
820
996
|
);
|
|
821
997
|
|
|
@@ -826,7 +1002,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
1002
|
}
|
|
827
1003
|
}
|
|
828
1004
|
|
|
829
|
-
// Create
|
|
1005
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
830
1006
|
return maybeIndices.map((index, i) => {
|
|
831
1007
|
if (index === undefined) {
|
|
832
1008
|
return undefined;
|
|
@@ -841,57 +1017,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
841
1017
|
return undefined;
|
|
842
1018
|
}
|
|
843
1019
|
return {
|
|
844
|
-
l2BlockNumber: Number(blockNumber),
|
|
845
|
-
l2BlockHash:
|
|
1020
|
+
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
1021
|
+
l2BlockHash: new BlockHash(blockHash),
|
|
846
1022
|
data: index,
|
|
847
1023
|
};
|
|
848
1024
|
});
|
|
849
1025
|
}
|
|
850
1026
|
|
|
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,
|
|
1027
|
+
public async getBlockHashMembershipWitness(
|
|
1028
|
+
referenceBlock: BlockParameter,
|
|
1029
|
+
blockHash: BlockHash,
|
|
882
1030
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
const committedDb = await this.#getWorldState(
|
|
884
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [
|
|
1031
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1032
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
885
1033
|
return pathAndIndex === undefined
|
|
886
1034
|
? undefined
|
|
887
1035
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
888
1036
|
}
|
|
889
1037
|
|
|
890
1038
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
1039
|
+
referenceBlock: BlockParameter,
|
|
892
1040
|
noteHash: Fr,
|
|
893
1041
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this.#getWorldState(
|
|
1042
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
895
1043
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
1044
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
1045
|
[noteHash],
|
|
@@ -901,17 +1049,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
1049
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
1050
|
}
|
|
903
1051
|
|
|
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
1052
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
1053
|
+
referenceBlock: BlockParameter,
|
|
912
1054
|
l1ToL2Message: Fr,
|
|
913
1055
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this.#getWorldState(
|
|
1056
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
915
1057
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
1058
|
if (!witness) {
|
|
917
1059
|
return undefined;
|
|
@@ -921,9 +1063,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
1063
|
return [witness.index, witness.path];
|
|
922
1064
|
}
|
|
923
1065
|
|
|
924
|
-
public async
|
|
1066
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
925
1067
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex ? InboxLeaf.
|
|
1068
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
927
1069
|
}
|
|
928
1070
|
|
|
929
1071
|
/**
|
|
@@ -937,54 +1079,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
937
1079
|
}
|
|
938
1080
|
|
|
939
1081
|
/**
|
|
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.
|
|
1082
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1083
|
+
* @param epoch - The epoch at which to get the data.
|
|
1084
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
954
1085
|
*/
|
|
955
|
-
public async
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1086
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1087
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1088
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1089
|
+
const blocksInCheckpoints: L2Block[][] = [];
|
|
1090
|
+
let previousSlotNumber = SlotNumber.ZERO;
|
|
1091
|
+
let checkpointIndex = -1;
|
|
1092
|
+
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1093
|
+
const block = checkpointedBlock.block;
|
|
1094
|
+
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1095
|
+
if (slotNumber !== previousSlotNumber) {
|
|
1096
|
+
checkpointIndex++;
|
|
1097
|
+
blocksInCheckpoints.push([]);
|
|
1098
|
+
previousSlotNumber = slotNumber;
|
|
1099
|
+
}
|
|
1100
|
+
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1101
|
+
}
|
|
1102
|
+
return blocksInCheckpoints.map(blocks =>
|
|
1103
|
+
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1104
|
+
);
|
|
975
1105
|
}
|
|
976
1106
|
|
|
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
1107
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1108
|
+
referenceBlock: BlockParameter,
|
|
985
1109
|
nullifier: Fr,
|
|
986
1110
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this.#getWorldState(
|
|
1111
|
+
const db = await this.#getWorldState(referenceBlock);
|
|
988
1112
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1113
|
if (!witness) {
|
|
990
1114
|
return undefined;
|
|
@@ -1001,7 +1125,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1001
1125
|
|
|
1002
1126
|
/**
|
|
1003
1127
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param
|
|
1128
|
+
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1129
|
+
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1005
1130
|
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
1131
|
* @returns The low nullifier membership witness (if found).
|
|
1007
1132
|
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
@@ -1014,10 +1139,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1014
1139
|
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
1140
|
*/
|
|
1016
1141
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1142
|
+
referenceBlock: BlockParameter,
|
|
1018
1143
|
nullifier: Fr,
|
|
1019
1144
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this.#getWorldState(
|
|
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;
|
|
@@ -1032,8 +1157,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1157
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1158
|
}
|
|
1034
1159
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this.#getWorldState(
|
|
1160
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1161
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1037
1162
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1163
|
if (!lowLeafResult) {
|
|
1039
1164
|
return undefined;
|
|
@@ -1047,19 +1172,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1172
|
}
|
|
1048
1173
|
}
|
|
1049
1174
|
|
|
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);
|
|
1175
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1176
|
+
const committedDb = await this.#getWorldState(referenceBlock);
|
|
1063
1177
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1178
|
|
|
1065
1179
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,23 +1187,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1187
|
return preimage.leaf.value;
|
|
1074
1188
|
}
|
|
1075
1189
|
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1190
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1191
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1192
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1193
|
+
if (block.equals(initialBlockHash)) {
|
|
1194
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1195
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1196
|
+
}
|
|
1197
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1198
|
+
} else {
|
|
1199
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1200
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1201
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1202
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1203
|
+
}
|
|
1204
|
+
return this.blockSource.getBlockHeader(block);
|
|
1205
|
+
}
|
|
1093
1206
|
}
|
|
1094
1207
|
|
|
1095
1208
|
/**
|
|
@@ -1101,6 +1214,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1101
1214
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1102
1215
|
}
|
|
1103
1216
|
|
|
1217
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1218
|
+
return this.blockSource.getBlockData(number);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1222
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1104
1225
|
/**
|
|
1105
1226
|
* Simulates the public part of a transaction with the current state.
|
|
1106
1227
|
* @param tx - The transaction to simulate.
|
|
@@ -1124,7 +1245,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1245
|
}
|
|
1125
1246
|
|
|
1126
1247
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const
|
|
1248
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1249
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1128
1250
|
|
|
1129
1251
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1252
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1139,6 +1261,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1261
|
this.contractDataSource,
|
|
1140
1262
|
new DateProvider(),
|
|
1141
1263
|
this.telemetry,
|
|
1264
|
+
this.log.getBindings(),
|
|
1142
1265
|
);
|
|
1143
1266
|
|
|
1144
1267
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1147,16 +1270,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1147
1270
|
blockNumber,
|
|
1148
1271
|
});
|
|
1149
1272
|
|
|
1273
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1274
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1150
1275
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1151
1276
|
try {
|
|
1152
|
-
const
|
|
1277
|
+
const config = PublicSimulatorConfig.from({
|
|
1153
1278
|
skipFeeEnforcement,
|
|
1154
|
-
|
|
1155
|
-
|
|
1279
|
+
collectDebugLogs: true,
|
|
1280
|
+
collectHints: false,
|
|
1281
|
+
collectCallMetadata: true,
|
|
1282
|
+
collectStatistics: false,
|
|
1283
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1284
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1285
|
+
}),
|
|
1156
1286
|
});
|
|
1287
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1157
1288
|
|
|
1158
1289
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1159
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1290
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1160
1291
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1161
1292
|
if (failedTxs.length) {
|
|
1162
1293
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1170,6 +1301,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1170
1301
|
processedTx.txEffect,
|
|
1171
1302
|
returns,
|
|
1172
1303
|
processedTx.gasUsed,
|
|
1304
|
+
debugLogs,
|
|
1173
1305
|
);
|
|
1174
1306
|
} finally {
|
|
1175
1307
|
await merkleTreeFork.close();
|
|
@@ -1183,19 +1315,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1183
1315
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1184
1316
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
1185
1317
|
|
|
1186
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1318
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1187
1319
|
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
|
-
|
|
1320
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1321
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1322
|
+
db,
|
|
1323
|
+
this.contractDataSource,
|
|
1324
|
+
verifier,
|
|
1325
|
+
{
|
|
1326
|
+
timestamp: nextSlotTimestamp,
|
|
1327
|
+
blockNumber,
|
|
1328
|
+
l1ChainId: this.l1ChainId,
|
|
1329
|
+
rollupVersion: this.version,
|
|
1330
|
+
setupAllowList: [
|
|
1331
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1332
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1333
|
+
],
|
|
1334
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1335
|
+
skipFeeEnforcement,
|
|
1336
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1337
|
+
},
|
|
1338
|
+
this.log.getBindings(),
|
|
1339
|
+
);
|
|
1199
1340
|
|
|
1200
1341
|
return await validator.validateTx(tx);
|
|
1201
1342
|
}
|
|
@@ -1242,8 +1383,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1242
1383
|
|
|
1243
1384
|
public getValidatorStats(
|
|
1244
1385
|
validatorAddress: EthAddress,
|
|
1245
|
-
fromSlot?:
|
|
1246
|
-
toSlot?:
|
|
1386
|
+
fromSlot?: SlotNumber,
|
|
1387
|
+
toSlot?: SlotNumber,
|
|
1247
1388
|
): Promise<SingleValidatorStats | undefined> {
|
|
1248
1389
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1249
1390
|
}
|
|
@@ -1253,45 +1394,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1253
1394
|
// We break support for archiver running remotely to the node
|
|
1254
1395
|
const archiver = this.blockSource as Archiver;
|
|
1255
1396
|
if (!('backupTo' in archiver)) {
|
|
1397
|
+
this.metrics.recordSnapshotError();
|
|
1256
1398
|
throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
|
|
1257
1399
|
}
|
|
1258
1400
|
|
|
1259
1401
|
// Test that the archiver has done an initial sync.
|
|
1260
1402
|
if (!archiver.isInitialSyncComplete()) {
|
|
1403
|
+
this.metrics.recordSnapshotError();
|
|
1261
1404
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
1262
1405
|
}
|
|
1263
1406
|
|
|
1264
1407
|
// And it has an L2 block hash
|
|
1265
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1408
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1266
1409
|
if (!l2BlockHash) {
|
|
1410
|
+
this.metrics.recordSnapshotError();
|
|
1267
1411
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
1268
1412
|
}
|
|
1269
1413
|
|
|
1270
1414
|
if (this.isUploadingSnapshot) {
|
|
1415
|
+
this.metrics.recordSnapshotError();
|
|
1271
1416
|
throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
|
|
1272
1417
|
}
|
|
1273
1418
|
|
|
1274
1419
|
// Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
|
|
1275
1420
|
this.isUploadingSnapshot = true;
|
|
1421
|
+
const timer = new Timer();
|
|
1276
1422
|
void uploadSnapshot(location, this.blockSource as Archiver, this.worldStateSynchronizer, this.config, this.log)
|
|
1277
1423
|
.then(() => {
|
|
1278
1424
|
this.isUploadingSnapshot = false;
|
|
1425
|
+
this.metrics.recordSnapshot(timer.ms());
|
|
1279
1426
|
})
|
|
1280
1427
|
.catch(err => {
|
|
1281
1428
|
this.isUploadingSnapshot = false;
|
|
1429
|
+
this.metrics.recordSnapshotError();
|
|
1282
1430
|
this.log.error(`Error uploading snapshot: ${err}`);
|
|
1283
1431
|
});
|
|
1284
1432
|
|
|
1285
1433
|
return Promise.resolve();
|
|
1286
1434
|
}
|
|
1287
1435
|
|
|
1288
|
-
public async rollbackTo(targetBlock:
|
|
1436
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1289
1437
|
const archiver = this.blockSource as Archiver;
|
|
1290
1438
|
if (!('rollbackTo' in archiver)) {
|
|
1291
1439
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1292
1440
|
}
|
|
1293
1441
|
|
|
1294
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1442
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1295
1443
|
if (targetBlock < finalizedBlock) {
|
|
1296
1444
|
if (force) {
|
|
1297
1445
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1352,17 +1500,108 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1352
1500
|
}
|
|
1353
1501
|
}
|
|
1354
1502
|
|
|
1503
|
+
public async reloadKeystore(): Promise<void> {
|
|
1504
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1505
|
+
throw new BadRequestError(
|
|
1506
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1507
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
if (!this.validatorClient) {
|
|
1511
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
this.log.info('Reloading keystore from disk');
|
|
1515
|
+
|
|
1516
|
+
// Re-read and validate keystore files
|
|
1517
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1518
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1519
|
+
await newManager.validateSigners();
|
|
1520
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1521
|
+
|
|
1522
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1523
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1524
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1525
|
+
// would silently fail on every proposer slot.
|
|
1526
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1527
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1528
|
+
const availablePublishers = new Set(
|
|
1529
|
+
oldAdapter
|
|
1530
|
+
.getAttesterAddresses()
|
|
1531
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1532
|
+
);
|
|
1533
|
+
|
|
1534
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1535
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1536
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1537
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1538
|
+
throw new BadRequestError(
|
|
1539
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1540
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1541
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1542
|
+
`use an existing publisher key or restart the node.`,
|
|
1543
|
+
);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// Build adapters for old and new keystores to compute diff
|
|
1549
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1550
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1551
|
+
const oldAddresses = this.keyStoreManager
|
|
1552
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1553
|
+
: [];
|
|
1554
|
+
|
|
1555
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1556
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1557
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1558
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1559
|
+
|
|
1560
|
+
if (added.length > 0) {
|
|
1561
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1562
|
+
}
|
|
1563
|
+
if (removed.length > 0) {
|
|
1564
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1565
|
+
}
|
|
1566
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1567
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1571
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1572
|
+
|
|
1573
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1574
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1575
|
+
if (this.sequencer) {
|
|
1576
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1580
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1581
|
+
const slashValidatorsNever = unique(
|
|
1582
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1583
|
+
).map(EthAddress.fromString);
|
|
1584
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
this.keyStoreManager = newManager;
|
|
1588
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1592
|
+
if (!this.initialHeaderHashPromise) {
|
|
1593
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1594
|
+
}
|
|
1595
|
+
return this.initialHeaderHashPromise;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1355
1598
|
/**
|
|
1356
1599
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1357
|
-
* @param
|
|
1600
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1358
1601
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1359
1602
|
*/
|
|
1360
|
-
async #getWorldState(
|
|
1361
|
-
|
|
1362
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1363
|
-
}
|
|
1364
|
-
|
|
1365
|
-
let blockSyncedTo: number = 0;
|
|
1603
|
+
async #getWorldState(block: BlockParameter) {
|
|
1604
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1366
1605
|
try {
|
|
1367
1606
|
// Attempt to sync the world state if necessary
|
|
1368
1607
|
blockSyncedTo = await this.#syncWorldState();
|
|
@@ -1370,15 +1609,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1370
1609
|
this.log.error(`Error getting world state: ${err}`);
|
|
1371
1610
|
}
|
|
1372
1611
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1612
|
+
if (block === 'latest') {
|
|
1613
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1376
1614
|
return this.worldStateSynchronizer.getCommitted();
|
|
1377
|
-
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1618
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1619
|
+
if (block.equals(initialBlockHash)) {
|
|
1620
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1621
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1625
|
+
if (!header) {
|
|
1626
|
+
throw new Error(
|
|
1627
|
+
`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.`,
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
const blockNumber = header.getBlockNumber();
|
|
1631
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1632
|
+
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// Block number provided
|
|
1636
|
+
{
|
|
1637
|
+
const blockNumber = block as BlockNumber;
|
|
1638
|
+
|
|
1639
|
+
if (blockNumber > blockSyncedTo) {
|
|
1640
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1378
1643
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1379
1644
|
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1380
|
-
} else {
|
|
1381
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1382
1645
|
}
|
|
1383
1646
|
}
|
|
1384
1647
|
|
|
@@ -1386,8 +1649,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1386
1649
|
* Ensure we fully sync the world state
|
|
1387
1650
|
* @returns A promise that fulfils once the world state is synced
|
|
1388
1651
|
*/
|
|
1389
|
-
async #syncWorldState(): Promise<
|
|
1652
|
+
async #syncWorldState(): Promise<BlockNumber> {
|
|
1390
1653
|
const blockSourceHeight = await this.blockSource.getBlockNumber();
|
|
1391
|
-
return this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1654
|
+
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1392
1655
|
}
|
|
1393
1656
|
}
|