@aztec/aztec-node 0.0.1-commit.1bb068fb5 → 0.0.1-commit.1dcfe2301
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 +8 -5
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +11 -3
- package/dest/aztec-node/server.d.ts +48 -36
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +470 -198
- package/dest/sentinel/factory.d.ts +2 -2
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/sentinel.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +24 -17
- package/package.json +26 -25
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/server.ts +561 -225
- package/src/sentinel/factory.ts +1 -1
- package/src/sentinel/sentinel.ts +24 -15
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,30 +1,44 @@
|
|
|
1
1
|
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
4
|
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
5
|
+
import { Blob } from '@aztec/blob-lib';
|
|
4
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
5
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
6
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
7
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
8
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
9
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
10
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
11
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
12
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
13
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
14
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
15
18
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
19
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
16
20
|
import { count } from '@aztec/foundation/string';
|
|
17
21
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
18
22
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
19
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
23
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
20
24
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
25
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
21
26
|
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
type P2P,
|
|
28
|
+
type P2PClientDeps,
|
|
29
|
+
createP2PClient,
|
|
30
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
31
|
+
getDefaultAllowedSetupFunctions,
|
|
32
|
+
} from '@aztec/p2p';
|
|
26
33
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
27
|
-
import {
|
|
34
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
35
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
36
|
+
import {
|
|
37
|
+
FeeProviderImpl,
|
|
38
|
+
GlobalVariableBuilder,
|
|
39
|
+
SequencerClient,
|
|
40
|
+
type SequencerPublisher,
|
|
41
|
+
} from '@aztec/sequencer-client';
|
|
28
42
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
29
43
|
import {
|
|
30
44
|
AttestationsBlockWatcher,
|
|
@@ -35,7 +49,14 @@ import {
|
|
|
35
49
|
} from '@aztec/slasher';
|
|
36
50
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
37
51
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
38
|
-
import {
|
|
52
|
+
import {
|
|
53
|
+
type BlockData,
|
|
54
|
+
BlockHash,
|
|
55
|
+
type BlockParameter,
|
|
56
|
+
type DataInBlock,
|
|
57
|
+
L2Block,
|
|
58
|
+
type L2BlockSource,
|
|
59
|
+
} from '@aztec/stdlib/block';
|
|
39
60
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
40
61
|
import type {
|
|
41
62
|
ContractClassPublic,
|
|
@@ -44,13 +65,14 @@ import type {
|
|
|
44
65
|
NodeInfo,
|
|
45
66
|
ProtocolContractAddresses,
|
|
46
67
|
} from '@aztec/stdlib/contract';
|
|
47
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
68
|
+
import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
48
69
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
49
70
|
import {
|
|
50
71
|
type AztecNode,
|
|
51
72
|
type AztecNodeAdmin,
|
|
52
73
|
type AztecNodeAdminConfig,
|
|
53
74
|
AztecNodeAdminConfigSchema,
|
|
75
|
+
type AztecNodeDebug,
|
|
54
76
|
type GetContractClassLogsResponse,
|
|
55
77
|
type GetPublicLogsResponse,
|
|
56
78
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -63,14 +85,15 @@ import {
|
|
|
63
85
|
type WorldStateSynchronizer,
|
|
64
86
|
tryStop,
|
|
65
87
|
} from '@aztec/stdlib/interfaces/server';
|
|
66
|
-
import type { LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
88
|
+
import type { DebugLogStore, LogFilter, SiloedTag, Tag, TxScopedL2Log } from '@aztec/stdlib/logs';
|
|
89
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
67
90
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
68
|
-
import {
|
|
69
|
-
import type {
|
|
70
|
-
import type { NullifierLeafPreimage, PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
91
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
92
|
+
import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
71
93
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
72
94
|
import {
|
|
73
95
|
type BlockHeader,
|
|
96
|
+
type FeeProvider,
|
|
74
97
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
75
98
|
type IndexedTxEffect,
|
|
76
99
|
PublicSimulationOutput,
|
|
@@ -82,6 +105,7 @@ import {
|
|
|
82
105
|
} from '@aztec/stdlib/tx';
|
|
83
106
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
84
107
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
108
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
85
109
|
import {
|
|
86
110
|
Attributes,
|
|
87
111
|
type TelemetryClient,
|
|
@@ -95,13 +119,13 @@ import {
|
|
|
95
119
|
FullNodeCheckpointsBuilder,
|
|
96
120
|
NodeKeystoreAdapter,
|
|
97
121
|
ValidatorClient,
|
|
98
|
-
|
|
122
|
+
createProposalHandler,
|
|
99
123
|
createValidatorClient,
|
|
100
|
-
createValidatorForAcceptingTxs,
|
|
101
124
|
} from '@aztec/validator-client';
|
|
125
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
102
126
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
103
127
|
|
|
104
|
-
import { createPublicClient
|
|
128
|
+
import { createPublicClient } from 'viem';
|
|
105
129
|
|
|
106
130
|
import { createSentinel } from '../sentinel/factory.js';
|
|
107
131
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -111,7 +135,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
111
135
|
/**
|
|
112
136
|
* The aztec node.
|
|
113
137
|
*/
|
|
114
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
138
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
115
139
|
private metrics: NodeMetrics;
|
|
116
140
|
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
117
141
|
|
|
@@ -129,24 +153,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
129
153
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
130
154
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
131
155
|
protected readonly sequencer: SequencerClient | undefined,
|
|
156
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
132
157
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
133
158
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
134
159
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
135
160
|
protected readonly l1ChainId: number,
|
|
136
161
|
protected readonly version: number,
|
|
137
162
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
163
|
+
protected readonly feeProvider: FeeProvider,
|
|
138
164
|
protected readonly epochCache: EpochCacheInterface,
|
|
139
165
|
protected readonly packageVersion: string,
|
|
140
|
-
private
|
|
166
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
167
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
141
168
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
142
169
|
private log = createLogger('node'),
|
|
143
170
|
private blobClient?: BlobClientInterface,
|
|
171
|
+
private validatorClient?: ValidatorClient,
|
|
172
|
+
private keyStoreManager?: KeystoreManager,
|
|
173
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
144
174
|
) {
|
|
145
175
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
146
176
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
147
177
|
|
|
148
178
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
149
179
|
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config.l1Contracts);
|
|
180
|
+
|
|
181
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
182
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
183
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
184
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
185
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
190
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
191
|
+
return this.rpcProofVerifier;
|
|
150
192
|
}
|
|
151
193
|
|
|
152
194
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -170,11 +212,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
170
212
|
logger?: Logger;
|
|
171
213
|
publisher?: SequencerPublisher;
|
|
172
214
|
dateProvider?: DateProvider;
|
|
173
|
-
p2pClientDeps?: P2PClientDeps
|
|
215
|
+
p2pClientDeps?: P2PClientDeps;
|
|
216
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
217
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
174
218
|
} = {},
|
|
175
219
|
options: {
|
|
176
|
-
|
|
220
|
+
genesis?: GenesisData;
|
|
177
221
|
dontStartSequencer?: boolean;
|
|
222
|
+
dontStartProverNode?: boolean;
|
|
178
223
|
} = {},
|
|
179
224
|
): Promise<AztecNodeService> {
|
|
180
225
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -184,16 +229,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
229
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
185
230
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
186
231
|
|
|
187
|
-
// Build a key store from file if given or from environment otherwise
|
|
232
|
+
// Build a key store from file if given or from environment otherwise.
|
|
233
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
188
234
|
let keyStoreManager: KeystoreManager | undefined;
|
|
189
235
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
190
236
|
if (keyStoreProvided) {
|
|
191
237
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
192
238
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
193
239
|
} else {
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
240
|
+
const rawKeyStores: KeyStore[] = [];
|
|
241
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
242
|
+
if (validatorKeyStore) {
|
|
243
|
+
rawKeyStores.push(validatorKeyStore);
|
|
244
|
+
}
|
|
245
|
+
if (config.enableProverNode) {
|
|
246
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
247
|
+
if (proverKeyStore) {
|
|
248
|
+
rawKeyStores.push(proverKeyStore);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (rawKeyStores.length > 0) {
|
|
252
|
+
keyStoreManager = new KeystoreManager(
|
|
253
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
254
|
+
);
|
|
197
255
|
}
|
|
198
256
|
}
|
|
199
257
|
|
|
@@ -204,10 +262,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
204
262
|
if (keyStoreManager === undefined) {
|
|
205
263
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
206
264
|
}
|
|
207
|
-
if (!keyStoreProvided) {
|
|
208
|
-
log.warn(
|
|
209
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
210
|
-
);
|
|
265
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
266
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
211
267
|
}
|
|
212
268
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
213
269
|
}
|
|
@@ -221,7 +277,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
221
277
|
|
|
222
278
|
const publicClient = createPublicClient({
|
|
223
279
|
chain: ethereumChain.chainInfo,
|
|
224
|
-
transport:
|
|
280
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
225
281
|
pollingInterval: config.viemPollingIntervalMS,
|
|
226
282
|
});
|
|
227
283
|
|
|
@@ -235,10 +291,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
235
291
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
236
292
|
|
|
237
293
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
238
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
294
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
239
295
|
rollupContract.getL1GenesisTime(),
|
|
240
296
|
rollupContract.getSlotDuration(),
|
|
241
297
|
rollupContract.getVersion(),
|
|
298
|
+
rollupContract.getManaLimit().then(Number),
|
|
242
299
|
] as const);
|
|
243
300
|
|
|
244
301
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -249,7 +306,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
249
306
|
);
|
|
250
307
|
}
|
|
251
308
|
|
|
252
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
309
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
253
310
|
|
|
254
311
|
// attempt snapshot sync if possible
|
|
255
312
|
await trySnapshotSync(config, log);
|
|
@@ -263,27 +320,41 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
263
320
|
);
|
|
264
321
|
|
|
265
322
|
// now create the merkle trees and the world state synchronizer
|
|
266
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
323
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.genesis, telemetry);
|
|
324
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
325
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
326
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
327
|
+
if (useRealVerifiers) {
|
|
328
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
329
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
330
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
331
|
+
} else {
|
|
332
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
333
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let debugLogStore: DebugLogStore;
|
|
276
337
|
if (!config.realProofs) {
|
|
277
338
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
339
|
+
|
|
340
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
341
|
+
log.info(
|
|
342
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
343
|
+
);
|
|
344
|
+
} else {
|
|
345
|
+
debugLogStore = new NullDebugLogStore();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
349
|
+
if (proverOnly) {
|
|
350
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
278
351
|
}
|
|
279
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
280
352
|
|
|
281
353
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
282
354
|
const p2pClient = await createP2PClient(
|
|
283
|
-
P2PClientType.Full,
|
|
284
355
|
config,
|
|
285
356
|
archiver,
|
|
286
|
-
|
|
357
|
+
peerProofVerifier,
|
|
287
358
|
worldStateSynchronizer,
|
|
288
359
|
epochCache,
|
|
289
360
|
packageVersion,
|
|
@@ -292,59 +363,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
292
363
|
deps.p2pClientDeps,
|
|
293
364
|
);
|
|
294
365
|
|
|
295
|
-
// We
|
|
296
|
-
|
|
366
|
+
// We'll accumulate sentinel watchers here
|
|
367
|
+
const watchers: Watcher[] = [];
|
|
297
368
|
|
|
298
|
-
// Create FullNodeCheckpointsBuilder for
|
|
369
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
370
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
299
371
|
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
300
|
-
{
|
|
372
|
+
{
|
|
373
|
+
...config,
|
|
374
|
+
l1GenesisTime,
|
|
375
|
+
slotDuration: Number(slotDuration),
|
|
376
|
+
rollupManaLimit,
|
|
377
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
378
|
+
},
|
|
301
379
|
worldStateSynchronizer,
|
|
302
380
|
archiver,
|
|
303
381
|
dateProvider,
|
|
304
382
|
telemetry,
|
|
305
383
|
);
|
|
306
384
|
|
|
307
|
-
|
|
308
|
-
const watchers: Watcher[] = [];
|
|
385
|
+
let validatorClient: ValidatorClient | undefined;
|
|
309
386
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
387
|
+
if (!proverOnly) {
|
|
388
|
+
// Create validator client if required
|
|
389
|
+
validatorClient = await createValidatorClient(config, {
|
|
390
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
391
|
+
worldState: worldStateSynchronizer,
|
|
392
|
+
p2pClient,
|
|
393
|
+
telemetry,
|
|
394
|
+
dateProvider,
|
|
395
|
+
epochCache,
|
|
396
|
+
blockSource: archiver,
|
|
397
|
+
l1ToL2MessageSource: archiver,
|
|
398
|
+
keyStoreManager,
|
|
399
|
+
blobClient,
|
|
400
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
404
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
405
|
+
// like attestations or auths will fail.
|
|
406
|
+
if (validatorClient) {
|
|
407
|
+
watchers.push(validatorClient);
|
|
408
|
+
|
|
409
|
+
const vc = validatorClient;
|
|
410
|
+
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
411
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
323
412
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (validatorClient) {
|
|
328
|
-
watchers.push(validatorClient);
|
|
329
|
-
if (!options.dontStartSequencer) {
|
|
330
|
-
await validatorClient.registerHandlers();
|
|
413
|
+
if (!options.dontStartSequencer) {
|
|
414
|
+
await validatorClient.registerHandlers();
|
|
415
|
+
}
|
|
331
416
|
}
|
|
332
417
|
}
|
|
333
418
|
|
|
334
|
-
// If there's no validator client
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
419
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
420
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
421
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
422
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
423
|
+
if (!validatorClient) {
|
|
424
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
425
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
426
|
+
createProposalHandler(config, {
|
|
339
427
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
340
428
|
worldState: worldStateSynchronizer,
|
|
341
429
|
epochCache,
|
|
342
430
|
blockSource: archiver,
|
|
343
431
|
l1ToL2MessageSource: archiver,
|
|
344
432
|
p2pClient,
|
|
433
|
+
blobClient,
|
|
345
434
|
dateProvider,
|
|
346
435
|
telemetry,
|
|
347
|
-
}).
|
|
436
|
+
}).register(p2pClient, reexecute, archiver);
|
|
348
437
|
}
|
|
349
438
|
|
|
350
439
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -353,36 +442,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
353
442
|
// Start p2p. Note that it depends on world state to be running.
|
|
354
443
|
await p2pClient.start();
|
|
355
444
|
|
|
356
|
-
|
|
357
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
358
|
-
watchers.push(validatorsSentinel);
|
|
359
|
-
}
|
|
360
|
-
|
|
445
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
361
446
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
362
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
363
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
364
|
-
archiver,
|
|
365
|
-
archiver,
|
|
366
|
-
epochCache,
|
|
367
|
-
p2pClient.getTxProvider(),
|
|
368
|
-
validatorCheckpointsBuilder,
|
|
369
|
-
config,
|
|
370
|
-
);
|
|
371
|
-
watchers.push(epochPruneWatcher);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
375
447
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
448
|
+
|
|
449
|
+
if (!proverOnly) {
|
|
450
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
451
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
452
|
+
watchers.push(validatorsSentinel);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
456
|
+
epochPruneWatcher = new EpochPruneWatcher(
|
|
457
|
+
archiver,
|
|
458
|
+
archiver,
|
|
459
|
+
epochCache,
|
|
460
|
+
p2pClient.getTxProvider(),
|
|
461
|
+
validatorCheckpointsBuilder,
|
|
462
|
+
config,
|
|
463
|
+
);
|
|
464
|
+
watchers.push(epochPruneWatcher);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
468
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
469
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
470
|
+
watchers.push(attestationsBlockWatcher);
|
|
471
|
+
}
|
|
379
472
|
}
|
|
380
473
|
|
|
381
474
|
// Start p2p-related services once the archiver has completed sync
|
|
382
475
|
void archiver
|
|
383
476
|
.waitForInitialSync()
|
|
384
477
|
.then(async () => {
|
|
385
|
-
await p2pClient.start();
|
|
386
478
|
await validatorsSentinel?.start();
|
|
387
479
|
await epochPruneWatcher?.start();
|
|
388
480
|
await attestationsBlockWatcher?.start();
|
|
@@ -390,6 +482,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
390
482
|
})
|
|
391
483
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
392
484
|
|
|
485
|
+
const globalVariableBuilderConfig = {
|
|
486
|
+
l1Contracts: config.l1Contracts,
|
|
487
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
488
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
489
|
+
l1GenesisTime,
|
|
490
|
+
slotDuration: Number(slotDuration),
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
494
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
495
|
+
|
|
393
496
|
// Validator enabled, create/start relevant service
|
|
394
497
|
let sequencer: SequencerClient | undefined;
|
|
395
498
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -412,34 +515,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
412
515
|
);
|
|
413
516
|
await slasherClient.start();
|
|
414
517
|
|
|
415
|
-
const l1TxUtils = config.
|
|
416
|
-
? await
|
|
518
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
519
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
417
520
|
publicClient,
|
|
418
521
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
419
|
-
config.
|
|
522
|
+
config.sequencerPublisherForwarderAddress,
|
|
420
523
|
{ ...config, scope: 'sequencer' },
|
|
421
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
524
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
422
525
|
)
|
|
423
|
-
: await
|
|
526
|
+
: await createL1TxUtilsFromSigners(
|
|
424
527
|
publicClient,
|
|
425
528
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
426
529
|
{ ...config, scope: 'sequencer' },
|
|
427
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
530
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
428
531
|
);
|
|
429
532
|
|
|
533
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
534
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
535
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
536
|
+
if (fundingSigner) {
|
|
537
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
538
|
+
publicClient,
|
|
539
|
+
[fundingSigner],
|
|
540
|
+
{ ...config, scope: 'sequencer' },
|
|
541
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
542
|
+
);
|
|
543
|
+
funderL1TxUtils = funder;
|
|
544
|
+
}
|
|
545
|
+
|
|
430
546
|
// Create and start the sequencer client
|
|
431
547
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
432
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
548
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
433
549
|
worldStateSynchronizer,
|
|
434
550
|
archiver,
|
|
435
551
|
dateProvider,
|
|
436
552
|
telemetry,
|
|
553
|
+
debugLogStore,
|
|
437
554
|
);
|
|
438
555
|
|
|
439
556
|
sequencer = await SequencerClient.new(config, {
|
|
440
557
|
...deps,
|
|
441
558
|
epochCache,
|
|
442
559
|
l1TxUtils,
|
|
560
|
+
funderL1TxUtils,
|
|
443
561
|
validatorClient,
|
|
444
562
|
p2pClient,
|
|
445
563
|
worldStateSynchronizer,
|
|
@@ -451,6 +569,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
451
569
|
dateProvider,
|
|
452
570
|
blobClient,
|
|
453
571
|
nodeKeyStore: keyStoreManager!,
|
|
572
|
+
globalVariableBuilder,
|
|
454
573
|
});
|
|
455
574
|
}
|
|
456
575
|
|
|
@@ -461,14 +580,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
461
580
|
log.warn(`Sequencer created but not started`);
|
|
462
581
|
}
|
|
463
582
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
583
|
+
// Create prover node subsystem if enabled
|
|
584
|
+
let proverNode: ProverNode | undefined;
|
|
585
|
+
if (config.enableProverNode) {
|
|
586
|
+
proverNode = await createProverNode(config, {
|
|
587
|
+
...deps.proverNodeDeps,
|
|
588
|
+
telemetry,
|
|
589
|
+
dateProvider,
|
|
590
|
+
archiver,
|
|
591
|
+
worldStateSynchronizer,
|
|
592
|
+
p2pClient,
|
|
593
|
+
epochCache,
|
|
594
|
+
blobClient,
|
|
595
|
+
keyStoreManager,
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
if (!options.dontStartProverNode) {
|
|
599
|
+
await proverNode.start();
|
|
600
|
+
log.info(`Prover node subsystem started`);
|
|
601
|
+
} else {
|
|
602
|
+
log.info(`Prover node subsystem created but not started`);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
470
605
|
|
|
471
|
-
|
|
606
|
+
const node = new AztecNodeService(
|
|
472
607
|
config,
|
|
473
608
|
p2pClient,
|
|
474
609
|
archiver,
|
|
@@ -477,19 +612,27 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
477
612
|
archiver,
|
|
478
613
|
worldStateSynchronizer,
|
|
479
614
|
sequencer,
|
|
615
|
+
proverNode,
|
|
480
616
|
slasherClient,
|
|
481
617
|
validatorsSentinel,
|
|
482
618
|
epochPruneWatcher,
|
|
483
619
|
ethereumChain.chainInfo.id,
|
|
484
620
|
config.rollupVersion,
|
|
485
621
|
globalVariableBuilder,
|
|
622
|
+
feeProvider,
|
|
486
623
|
epochCache,
|
|
487
624
|
packageVersion,
|
|
488
|
-
|
|
625
|
+
peerProofVerifier,
|
|
626
|
+
rpcProofVerifier,
|
|
489
627
|
telemetry,
|
|
490
628
|
log,
|
|
491
629
|
blobClient,
|
|
630
|
+
validatorClient,
|
|
631
|
+
keyStoreManager,
|
|
632
|
+
debugLogStore,
|
|
492
633
|
);
|
|
634
|
+
|
|
635
|
+
return node;
|
|
493
636
|
}
|
|
494
637
|
|
|
495
638
|
/**
|
|
@@ -500,6 +643,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
500
643
|
return this.sequencer;
|
|
501
644
|
}
|
|
502
645
|
|
|
646
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
647
|
+
public getProverNode(): ProverNode | undefined {
|
|
648
|
+
return this.proverNode;
|
|
649
|
+
}
|
|
650
|
+
|
|
503
651
|
public getBlockSource(): L2BlockSource {
|
|
504
652
|
return this.blockSource;
|
|
505
653
|
}
|
|
@@ -525,7 +673,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
525
673
|
}
|
|
526
674
|
|
|
527
675
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
528
|
-
return this.config.
|
|
676
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
529
677
|
}
|
|
530
678
|
|
|
531
679
|
/**
|
|
@@ -620,12 +768,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
620
768
|
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
621
769
|
}
|
|
622
770
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
771
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
772
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
773
|
+
}
|
|
774
|
+
|
|
627
775
|
public async getCurrentMinFees(): Promise<GasFees> {
|
|
628
|
-
return await this.
|
|
776
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
/** Returns predicted min fees for the current slot and next N slots. */
|
|
780
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
781
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
629
782
|
}
|
|
630
783
|
|
|
631
784
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -652,6 +805,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
652
805
|
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
653
806
|
}
|
|
654
807
|
|
|
808
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
809
|
+
return this.blockSource.getCheckpointNumber();
|
|
810
|
+
}
|
|
811
|
+
|
|
655
812
|
/**
|
|
656
813
|
* Method to fetch the version of the package.
|
|
657
814
|
* @returns The node package version
|
|
@@ -689,18 +846,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
689
846
|
page?: number,
|
|
690
847
|
referenceBlock?: BlockHash,
|
|
691
848
|
): Promise<TxScopedL2Log[][]> {
|
|
849
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
692
850
|
if (referenceBlock) {
|
|
693
851
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
694
|
-
if (
|
|
852
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
853
|
+
upToBlockNumber = BlockNumber(0);
|
|
854
|
+
} else {
|
|
695
855
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
696
856
|
if (!header) {
|
|
697
857
|
throw new Error(
|
|
698
858
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
699
859
|
);
|
|
700
860
|
}
|
|
861
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
701
862
|
}
|
|
702
863
|
}
|
|
703
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
864
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
704
865
|
}
|
|
705
866
|
|
|
706
867
|
public async getPublicLogsByTagsFromContract(
|
|
@@ -709,18 +870,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
709
870
|
page?: number,
|
|
710
871
|
referenceBlock?: BlockHash,
|
|
711
872
|
): Promise<TxScopedL2Log[][]> {
|
|
873
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
712
874
|
if (referenceBlock) {
|
|
713
875
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
714
|
-
if (
|
|
876
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
877
|
+
upToBlockNumber = BlockNumber(0);
|
|
878
|
+
} else {
|
|
715
879
|
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
716
880
|
if (!header) {
|
|
717
881
|
throw new Error(
|
|
718
882
|
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
719
883
|
);
|
|
720
884
|
}
|
|
885
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
721
886
|
}
|
|
722
887
|
}
|
|
723
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
888
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
724
889
|
}
|
|
725
890
|
|
|
726
891
|
/**
|
|
@@ -762,8 +927,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
762
927
|
}
|
|
763
928
|
|
|
764
929
|
await this.p2pClient!.sendTx(tx);
|
|
765
|
-
|
|
766
|
-
this.
|
|
930
|
+
const duration = timer.ms();
|
|
931
|
+
this.metrics.receivedTx(duration, true);
|
|
932
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
767
933
|
}
|
|
768
934
|
|
|
769
935
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
@@ -775,18 +941,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
775
941
|
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
776
942
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
777
943
|
|
|
944
|
+
let receipt: TxReceipt;
|
|
778
945
|
if (settledTxReceipt) {
|
|
779
|
-
|
|
780
|
-
return settledTxReceipt;
|
|
946
|
+
receipt = settledTxReceipt;
|
|
781
947
|
} else if (isKnownToPool) {
|
|
782
948
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
783
949
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
784
950
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
785
|
-
|
|
951
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
786
952
|
} else {
|
|
787
953
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
788
|
-
|
|
954
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
789
955
|
}
|
|
956
|
+
|
|
957
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
958
|
+
|
|
959
|
+
return receipt;
|
|
790
960
|
}
|
|
791
961
|
|
|
792
962
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -801,8 +971,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
801
971
|
await tryStop(this.validatorsSentinel);
|
|
802
972
|
await tryStop(this.epochPruneWatcher);
|
|
803
973
|
await tryStop(this.slasherClient);
|
|
804
|
-
await tryStop(this.
|
|
974
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
805
975
|
await tryStop(this.sequencer);
|
|
976
|
+
await tryStop(this.proverNode);
|
|
806
977
|
await tryStop(this.p2pClient);
|
|
807
978
|
await tryStop(this.worldStateSynchronizer);
|
|
808
979
|
await tryStop(this.blockSource);
|
|
@@ -856,59 +1027,65 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
856
1027
|
treeId: MerkleTreeId,
|
|
857
1028
|
leafValues: Fr[],
|
|
858
1029
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
859
|
-
const committedDb = await this
|
|
1030
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
860
1031
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
861
1032
|
treeId,
|
|
862
1033
|
leafValues.map(x => x.toBuffer()),
|
|
863
1034
|
);
|
|
864
|
-
//
|
|
865
|
-
const
|
|
1035
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1036
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
866
1037
|
|
|
867
|
-
// Now we find the block numbers for the indices
|
|
868
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1038
|
+
// Now we find the block numbers for the defined indices
|
|
1039
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
869
1040
|
|
|
870
|
-
//
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1041
|
+
// Build a map from leaf index to block number
|
|
1042
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1043
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1044
|
+
const blockNumber = blockNumbers[i];
|
|
1045
|
+
if (blockNumber === undefined) {
|
|
1046
|
+
throw new Error(
|
|
1047
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1048
|
+
);
|
|
874
1049
|
}
|
|
1050
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
875
1051
|
}
|
|
876
1052
|
|
|
877
1053
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
878
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1054
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
879
1055
|
|
|
880
|
-
// Now we obtain the block hashes from the archive tree
|
|
881
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1056
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
882
1057
|
const blockHashes = await Promise.all(
|
|
883
1058
|
uniqueBlockNumbers.map(blockNumber => {
|
|
884
1059
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
885
1060
|
}),
|
|
886
1061
|
);
|
|
887
1062
|
|
|
888
|
-
//
|
|
1063
|
+
// Build a map from block number to block hash
|
|
1064
|
+
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
889
1065
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
890
|
-
|
|
1066
|
+
const blockHash = blockHashes[i];
|
|
1067
|
+
if (blockHash === undefined) {
|
|
891
1068
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
892
1069
|
}
|
|
1070
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
893
1071
|
}
|
|
894
1072
|
|
|
895
1073
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
896
|
-
return maybeIndices.map(
|
|
1074
|
+
return maybeIndices.map(index => {
|
|
897
1075
|
if (index === undefined) {
|
|
898
1076
|
return undefined;
|
|
899
1077
|
}
|
|
900
|
-
const blockNumber =
|
|
1078
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
901
1079
|
if (blockNumber === undefined) {
|
|
902
|
-
|
|
1080
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
903
1081
|
}
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
return undefined;
|
|
1082
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1083
|
+
if (l2BlockHash === undefined) {
|
|
1084
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
908
1085
|
}
|
|
909
1086
|
return {
|
|
910
|
-
l2BlockNumber:
|
|
911
|
-
l2BlockHash
|
|
1087
|
+
l2BlockNumber: blockNumber,
|
|
1088
|
+
l2BlockHash,
|
|
912
1089
|
data: index,
|
|
913
1090
|
};
|
|
914
1091
|
});
|
|
@@ -918,7 +1095,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
918
1095
|
referenceBlock: BlockParameter,
|
|
919
1096
|
blockHash: BlockHash,
|
|
920
1097
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
921
|
-
|
|
1098
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1099
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1100
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1101
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1102
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1103
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1104
|
+
return undefined;
|
|
1105
|
+
}
|
|
1106
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
922
1107
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
923
1108
|
return pathAndIndex === undefined
|
|
924
1109
|
? undefined
|
|
@@ -929,7 +1114,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
929
1114
|
referenceBlock: BlockParameter,
|
|
930
1115
|
noteHash: Fr,
|
|
931
1116
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
932
|
-
const committedDb = await this
|
|
1117
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
933
1118
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
934
1119
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
935
1120
|
[noteHash],
|
|
@@ -943,7 +1128,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
943
1128
|
referenceBlock: BlockParameter,
|
|
944
1129
|
l1ToL2Message: Fr,
|
|
945
1130
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
946
|
-
const db = await this
|
|
1131
|
+
const db = await this.getWorldState(referenceBlock);
|
|
947
1132
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
948
1133
|
if (!witness) {
|
|
949
1134
|
return undefined;
|
|
@@ -953,11 +1138,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
953
1138
|
return [witness.index, witness.path];
|
|
954
1139
|
}
|
|
955
1140
|
|
|
956
|
-
public async
|
|
1141
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
957
1142
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
958
|
-
return messageIndex
|
|
959
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
960
|
-
: undefined;
|
|
1143
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
961
1144
|
}
|
|
962
1145
|
|
|
963
1146
|
/**
|
|
@@ -978,19 +1161,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
978
1161
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
979
1162
|
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
980
1163
|
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
981
|
-
const blocksInCheckpoints
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
985
|
-
const block = checkpointedBlock.block;
|
|
986
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
987
|
-
if (slotNumber !== previousSlotNumber) {
|
|
988
|
-
checkpointIndex++;
|
|
989
|
-
blocksInCheckpoints.push([]);
|
|
990
|
-
previousSlotNumber = slotNumber;
|
|
991
|
-
}
|
|
992
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
993
|
-
}
|
|
1164
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1165
|
+
group => group.map(cb => cb.block),
|
|
1166
|
+
);
|
|
994
1167
|
return blocksInCheckpoints.map(blocks =>
|
|
995
1168
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
996
1169
|
);
|
|
@@ -1000,7 +1173,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1000
1173
|
referenceBlock: BlockParameter,
|
|
1001
1174
|
nullifier: Fr,
|
|
1002
1175
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1003
|
-
const db = await this
|
|
1176
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1004
1177
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1005
1178
|
if (!witness) {
|
|
1006
1179
|
return undefined;
|
|
@@ -1015,33 +1188,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1015
1188
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1016
1189
|
}
|
|
1017
1190
|
|
|
1018
|
-
/**
|
|
1019
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1020
|
-
* @param referenceBlock - The block parameter (block number, block hash, or 'latest') at which to get the data
|
|
1021
|
-
* (which contains the root of the nullifier tree in which we are searching for the nullifier).
|
|
1022
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1023
|
-
* @returns The low nullifier membership witness (if found).
|
|
1024
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1025
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1026
|
-
* we are trying to prove non-inclusion for.
|
|
1027
|
-
*
|
|
1028
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1029
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1030
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1031
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1032
|
-
*/
|
|
1033
1191
|
public async getLowNullifierMembershipWitness(
|
|
1034
1192
|
referenceBlock: BlockParameter,
|
|
1035
1193
|
nullifier: Fr,
|
|
1036
1194
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1037
|
-
const committedDb = await this
|
|
1195
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1038
1196
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1039
1197
|
if (!findResult) {
|
|
1040
1198
|
return undefined;
|
|
1041
1199
|
}
|
|
1042
1200
|
const { index, alreadyPresent } = findResult;
|
|
1043
1201
|
if (alreadyPresent) {
|
|
1044
|
-
|
|
1202
|
+
throw new Error(
|
|
1203
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1204
|
+
);
|
|
1045
1205
|
}
|
|
1046
1206
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1047
1207
|
|
|
@@ -1050,7 +1210,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1050
1210
|
}
|
|
1051
1211
|
|
|
1052
1212
|
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1053
|
-
const committedDb = await this
|
|
1213
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1054
1214
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1055
1215
|
if (!lowLeafResult) {
|
|
1056
1216
|
return undefined;
|
|
@@ -1065,7 +1225,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1065
1225
|
}
|
|
1066
1226
|
|
|
1067
1227
|
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1068
|
-
const committedDb = await this
|
|
1228
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1069
1229
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1070
1230
|
|
|
1071
1231
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1106,6 +1266,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1106
1266
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1107
1267
|
}
|
|
1108
1268
|
|
|
1269
|
+
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1270
|
+
return this.blockSource.getBlockData(number);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1274
|
+
return this.blockSource.getBlockDataByArchive(archive);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1109
1277
|
/**
|
|
1110
1278
|
* Simulates the public part of a transaction with the current state.
|
|
1111
1279
|
* @param tx - The transaction to simulate.
|
|
@@ -1129,7 +1297,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1129
1297
|
}
|
|
1130
1298
|
|
|
1131
1299
|
const txHash = tx.getTxHash();
|
|
1132
|
-
const
|
|
1300
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1301
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1133
1302
|
|
|
1134
1303
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1135
1304
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1153,6 +1322,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1153
1322
|
blockNumber,
|
|
1154
1323
|
});
|
|
1155
1324
|
|
|
1325
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1326
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1156
1327
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1157
1328
|
try {
|
|
1158
1329
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1168,7 +1339,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1339
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1169
1340
|
|
|
1170
1341
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1171
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1342
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1172
1343
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1173
1344
|
if (failedTxs.length) {
|
|
1174
1345
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1182,6 +1353,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1182
1353
|
processedTx.txEffect,
|
|
1183
1354
|
returns,
|
|
1184
1355
|
processedTx.gasUsed,
|
|
1356
|
+
debugLogs,
|
|
1185
1357
|
);
|
|
1186
1358
|
} finally {
|
|
1187
1359
|
await merkleTreeFork.close();
|
|
@@ -1193,12 +1365,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1193
1365
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1194
1366
|
): Promise<TxValidationResult> {
|
|
1195
1367
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1196
|
-
const verifier = isSimulation ? undefined : this.
|
|
1368
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1197
1369
|
|
|
1198
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1370
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1199
1371
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1200
1372
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1201
|
-
const
|
|
1373
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1374
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1202
1375
|
db,
|
|
1203
1376
|
this.contractDataSource,
|
|
1204
1377
|
verifier,
|
|
@@ -1207,10 +1380,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1207
1380
|
blockNumber,
|
|
1208
1381
|
l1ChainId: this.l1ChainId,
|
|
1209
1382
|
rollupVersion: this.version,
|
|
1210
|
-
setupAllowList:
|
|
1383
|
+
setupAllowList: [
|
|
1384
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1385
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1386
|
+
],
|
|
1211
1387
|
gasFees: await this.getCurrentMinFees(),
|
|
1212
1388
|
skipFeeEnforcement,
|
|
1213
1389
|
txsPermitted: !this.config.disableTransactions,
|
|
1390
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1391
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1392
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1214
1393
|
},
|
|
1215
1394
|
this.log.getBindings(),
|
|
1216
1395
|
);
|
|
@@ -1235,7 +1414,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1235
1414
|
archiver.updateConfig(config);
|
|
1236
1415
|
}
|
|
1237
1416
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1238
|
-
|
|
1417
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1418
|
+
if (newConfig.realProofs) {
|
|
1419
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1420
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1421
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1422
|
+
} else {
|
|
1423
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1424
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1425
|
+
}
|
|
1239
1426
|
}
|
|
1240
1427
|
|
|
1241
1428
|
this.config = newConfig;
|
|
@@ -1310,7 +1497,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1310
1497
|
return Promise.resolve();
|
|
1311
1498
|
}
|
|
1312
1499
|
|
|
1313
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1500
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1314
1501
|
const archiver = this.blockSource as Archiver;
|
|
1315
1502
|
if (!('rollbackTo' in archiver)) {
|
|
1316
1503
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1340,9 +1527,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1340
1527
|
this.log.error(`Error during rollback`, err);
|
|
1341
1528
|
throw err;
|
|
1342
1529
|
} finally {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1530
|
+
if (resumeSync) {
|
|
1531
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1532
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1533
|
+
archiver.resume();
|
|
1534
|
+
} else {
|
|
1535
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1536
|
+
}
|
|
1346
1537
|
}
|
|
1347
1538
|
}
|
|
1348
1539
|
|
|
@@ -1359,24 +1550,139 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1359
1550
|
return Promise.resolve();
|
|
1360
1551
|
}
|
|
1361
1552
|
|
|
1362
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
1363
|
-
if (!this.slasherClient) {
|
|
1364
|
-
throw new Error(`Slasher client not enabled`);
|
|
1365
|
-
}
|
|
1366
|
-
return this.slasherClient.getSlashPayloads();
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
1553
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
1370
1554
|
if (!this.slasherClient) {
|
|
1371
1555
|
throw new Error(`Slasher client not enabled`);
|
|
1372
1556
|
}
|
|
1373
1557
|
if (round === 'all') {
|
|
1374
|
-
return this.slasherClient.
|
|
1558
|
+
return this.slasherClient.getOffenses();
|
|
1375
1559
|
} else {
|
|
1376
1560
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1377
1561
|
}
|
|
1378
1562
|
}
|
|
1379
1563
|
|
|
1564
|
+
public async reloadKeystore(): Promise<void> {
|
|
1565
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1566
|
+
throw new BadRequestError(
|
|
1567
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1568
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
if (!this.validatorClient) {
|
|
1572
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
this.log.info('Reloading keystore from disk');
|
|
1576
|
+
|
|
1577
|
+
// Re-read and validate keystore files
|
|
1578
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1579
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1580
|
+
await newManager.validateSigners();
|
|
1581
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1582
|
+
|
|
1583
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1584
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1585
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1586
|
+
// would silently fail on every proposer slot.
|
|
1587
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1588
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1589
|
+
const availablePublishers = new Set(
|
|
1590
|
+
oldAdapter
|
|
1591
|
+
.getAttesterAddresses()
|
|
1592
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1593
|
+
);
|
|
1594
|
+
|
|
1595
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1596
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1597
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1598
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1599
|
+
throw new BadRequestError(
|
|
1600
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1601
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1602
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1603
|
+
`use an existing publisher key or restart the node.`,
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
// Build adapters for old and new keystores to compute diff
|
|
1610
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1611
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1612
|
+
const oldAddresses = this.keyStoreManager
|
|
1613
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1614
|
+
: [];
|
|
1615
|
+
|
|
1616
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1617
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1618
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1619
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1620
|
+
|
|
1621
|
+
if (added.length > 0) {
|
|
1622
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1623
|
+
}
|
|
1624
|
+
if (removed.length > 0) {
|
|
1625
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1626
|
+
}
|
|
1627
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1628
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1632
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1633
|
+
|
|
1634
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1635
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1636
|
+
if (this.sequencer) {
|
|
1637
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1641
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1642
|
+
const slashValidatorsNever = unique(
|
|
1643
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1644
|
+
).map(EthAddress.fromString);
|
|
1645
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
this.keyStoreManager = newManager;
|
|
1649
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
public async mineBlock(): Promise<void> {
|
|
1653
|
+
if (!this.sequencer) {
|
|
1654
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1655
|
+
}
|
|
1656
|
+
|
|
1657
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1658
|
+
|
|
1659
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1660
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1661
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1662
|
+
|
|
1663
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1664
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1665
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1666
|
+
|
|
1667
|
+
try {
|
|
1668
|
+
// Trigger the sequencer to produce a block immediately
|
|
1669
|
+
void this.sequencer.trigger();
|
|
1670
|
+
|
|
1671
|
+
// Wait for the new L2 block to appear
|
|
1672
|
+
await retryUntil(
|
|
1673
|
+
async () => {
|
|
1674
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1675
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1676
|
+
},
|
|
1677
|
+
'mineBlock',
|
|
1678
|
+
timeoutSeconds,
|
|
1679
|
+
0.1,
|
|
1680
|
+
);
|
|
1681
|
+
} finally {
|
|
1682
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1380
1686
|
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1381
1687
|
if (!this.initialHeaderHashPromise) {
|
|
1382
1688
|
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
@@ -1389,7 +1695,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1389
1695
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1390
1696
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1391
1697
|
*/
|
|
1392
|
-
async
|
|
1698
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1393
1699
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1394
1700
|
try {
|
|
1395
1701
|
// Attempt to sync the world state if necessary
|
|
@@ -1403,6 +1709,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1403
1709
|
return this.worldStateSynchronizer.getCommitted();
|
|
1404
1710
|
}
|
|
1405
1711
|
|
|
1712
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1713
|
+
let blockNumber: BlockNumber;
|
|
1406
1714
|
if (BlockHash.isBlockHash(block)) {
|
|
1407
1715
|
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1408
1716
|
if (block.equals(initialBlockHash)) {
|
|
@@ -1416,22 +1724,50 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1416
1724
|
`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.`,
|
|
1417
1725
|
);
|
|
1418
1726
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1727
|
+
|
|
1728
|
+
blockNumber = header.getBlockNumber();
|
|
1729
|
+
} else {
|
|
1730
|
+
blockNumber = block as BlockNumber;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
// Check it's within world state sync range
|
|
1734
|
+
if (blockNumber > blockSyncedTo) {
|
|
1735
|
+
throw new Error(`Queried block ${block} not yet synced by the node (node is synced upto ${blockSyncedTo}).`);
|
|
1422
1736
|
}
|
|
1737
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1423
1738
|
|
|
1424
|
-
|
|
1425
|
-
{
|
|
1426
|
-
const blockNumber = block as BlockNumber;
|
|
1739
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1427
1740
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1741
|
+
// Double-check world-state synced to the same block hash as was requested
|
|
1742
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1743
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1744
|
+
if (!blockHash || !block.equals(blockHash)) {
|
|
1745
|
+
throw new Error(
|
|
1746
|
+
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1747
|
+
);
|
|
1430
1748
|
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
return snapshot;
|
|
1752
|
+
}
|
|
1431
1753
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1754
|
+
/** Resolves a block parameter to a block number. */
|
|
1755
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1756
|
+
if (block === 'latest') {
|
|
1757
|
+
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1758
|
+
}
|
|
1759
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1760
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1761
|
+
if (block.equals(initialBlockHash)) {
|
|
1762
|
+
return BlockNumber.ZERO;
|
|
1763
|
+
}
|
|
1764
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1765
|
+
if (!header) {
|
|
1766
|
+
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1767
|
+
}
|
|
1768
|
+
return header.getBlockNumber();
|
|
1434
1769
|
}
|
|
1770
|
+
return block as BlockNumber;
|
|
1435
1771
|
}
|
|
1436
1772
|
|
|
1437
1773
|
/**
|