@aztec/aztec-node 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +8 -4
- package/dest/aztec-node/server.d.ts +69 -124
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +582 -318
- 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/sentinel.d.ts +2 -2
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +62 -36
- package/dest/sentinel/store.d.ts +2 -2
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +11 -7
- package/package.json +27 -25
- package/src/aztec-node/config.ts +25 -9
- package/src/aztec-node/node_metrics.ts +12 -5
- package/src/aztec-node/server.ts +706 -398
- package/src/sentinel/factory.ts +2 -7
- package/src/sentinel/sentinel.ts +65 -32
- package/src/sentinel/store.ts +12 -12
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,37 +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';
|
|
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';
|
|
5
|
+
import { Blob } from '@aztec/blob-lib';
|
|
6
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
14
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
15
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
16
11
|
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
17
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
18
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
19
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
20
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
21
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
22
18
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
19
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
23
20
|
import { count } from '@aztec/foundation/string';
|
|
24
21
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
25
22
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
26
|
-
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
23
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
27
24
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
25
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
28
26
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
type P2P,
|
|
28
|
+
type P2PClientDeps,
|
|
29
|
+
createP2PClient,
|
|
30
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
31
|
+
getDefaultAllowedSetupFunctions,
|
|
32
|
+
} from '@aztec/p2p';
|
|
33
33
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
34
|
-
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';
|
|
35
42
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
43
|
import {
|
|
37
44
|
AttestationsBlockWatcher,
|
|
@@ -43,13 +50,12 @@ import {
|
|
|
43
50
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
51
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
52
|
import {
|
|
53
|
+
type BlockData,
|
|
54
|
+
BlockHash,
|
|
46
55
|
type BlockParameter,
|
|
47
56
|
type DataInBlock,
|
|
48
|
-
|
|
49
|
-
L2BlockHash,
|
|
50
|
-
L2BlockNew,
|
|
57
|
+
L2Block,
|
|
51
58
|
type L2BlockSource,
|
|
52
|
-
type PublishedL2Block,
|
|
53
59
|
} from '@aztec/stdlib/block';
|
|
54
60
|
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
55
61
|
import type {
|
|
@@ -59,13 +65,14 @@ import type {
|
|
|
59
65
|
NodeInfo,
|
|
60
66
|
ProtocolContractAddresses,
|
|
61
67
|
} from '@aztec/stdlib/contract';
|
|
62
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
68
|
+
import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
63
69
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
64
70
|
import {
|
|
65
71
|
type AztecNode,
|
|
66
72
|
type AztecNodeAdmin,
|
|
67
73
|
type AztecNodeAdminConfig,
|
|
68
74
|
AztecNodeAdminConfigSchema,
|
|
75
|
+
type AztecNodeDebug,
|
|
69
76
|
type GetContractClassLogsResponse,
|
|
70
77
|
type GetPublicLogsResponse,
|
|
71
78
|
} from '@aztec/stdlib/interfaces/client';
|
|
@@ -78,14 +85,15 @@ import {
|
|
|
78
85
|
type WorldStateSynchronizer,
|
|
79
86
|
tryStop,
|
|
80
87
|
} from '@aztec/stdlib/interfaces/server';
|
|
81
|
-
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';
|
|
82
90
|
import { InboxLeaf, type L1ToL2MessageSource } from '@aztec/stdlib/messaging';
|
|
83
|
-
import {
|
|
84
|
-
import type {
|
|
85
|
-
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';
|
|
86
93
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
87
94
|
import {
|
|
88
95
|
type BlockHeader,
|
|
96
|
+
type FeeProvider,
|
|
89
97
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
90
98
|
type IndexedTxEffect,
|
|
91
99
|
PublicSimulationOutput,
|
|
@@ -97,6 +105,7 @@ import {
|
|
|
97
105
|
} from '@aztec/stdlib/tx';
|
|
98
106
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
99
107
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
108
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
100
109
|
import {
|
|
101
110
|
Attributes,
|
|
102
111
|
type TelemetryClient,
|
|
@@ -110,13 +119,13 @@ import {
|
|
|
110
119
|
FullNodeCheckpointsBuilder,
|
|
111
120
|
NodeKeystoreAdapter,
|
|
112
121
|
ValidatorClient,
|
|
113
|
-
|
|
122
|
+
createProposalHandler,
|
|
114
123
|
createValidatorClient,
|
|
115
|
-
createValidatorForAcceptingTxs,
|
|
116
124
|
} from '@aztec/validator-client';
|
|
125
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
117
126
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
127
|
|
|
119
|
-
import { createPublicClient
|
|
128
|
+
import { createPublicClient } from 'viem';
|
|
120
129
|
|
|
121
130
|
import { createSentinel } from '../sentinel/factory.js';
|
|
122
131
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
@@ -126,8 +135,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
126
135
|
/**
|
|
127
136
|
* The aztec node.
|
|
128
137
|
*/
|
|
129
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
138
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
130
139
|
private metrics: NodeMetrics;
|
|
140
|
+
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
131
141
|
|
|
132
142
|
// Prevent two snapshot operations to happen simultaneously
|
|
133
143
|
private isUploadingSnapshot = false;
|
|
@@ -143,24 +153,42 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
143
153
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
144
154
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
145
155
|
protected readonly sequencer: SequencerClient | undefined,
|
|
156
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
146
157
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
147
158
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
148
159
|
protected readonly epochPruneWatcher: EpochPruneWatcher | undefined,
|
|
149
160
|
protected readonly l1ChainId: number,
|
|
150
161
|
protected readonly version: number,
|
|
151
162
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
163
|
+
protected readonly feeProvider: FeeProvider,
|
|
152
164
|
protected readonly epochCache: EpochCacheInterface,
|
|
153
165
|
protected readonly packageVersion: string,
|
|
154
|
-
private
|
|
166
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
167
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
155
168
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
156
169
|
private log = createLogger('node'),
|
|
157
170
|
private blobClient?: BlobClientInterface,
|
|
171
|
+
private validatorClient?: ValidatorClient,
|
|
172
|
+
private keyStoreManager?: KeystoreManager,
|
|
173
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
158
174
|
) {
|
|
159
175
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
160
176
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
161
177
|
|
|
162
178
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
163
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;
|
|
164
192
|
}
|
|
165
193
|
|
|
166
194
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -184,11 +212,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
184
212
|
logger?: Logger;
|
|
185
213
|
publisher?: SequencerPublisher;
|
|
186
214
|
dateProvider?: DateProvider;
|
|
187
|
-
p2pClientDeps?: P2PClientDeps
|
|
215
|
+
p2pClientDeps?: P2PClientDeps;
|
|
216
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
217
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
188
218
|
} = {},
|
|
189
219
|
options: {
|
|
190
|
-
|
|
220
|
+
genesis?: GenesisData;
|
|
191
221
|
dontStartSequencer?: boolean;
|
|
222
|
+
dontStartProverNode?: boolean;
|
|
192
223
|
} = {},
|
|
193
224
|
): Promise<AztecNodeService> {
|
|
194
225
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
@@ -198,16 +229,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
198
229
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
199
230
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
200
231
|
|
|
201
|
-
// 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.
|
|
202
234
|
let keyStoreManager: KeystoreManager | undefined;
|
|
203
235
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
204
236
|
if (keyStoreProvided) {
|
|
205
237
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
206
238
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
207
239
|
} else {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
);
|
|
211
255
|
}
|
|
212
256
|
}
|
|
213
257
|
|
|
@@ -218,10 +262,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
218
262
|
if (keyStoreManager === undefined) {
|
|
219
263
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
220
264
|
}
|
|
221
|
-
if (!keyStoreProvided) {
|
|
222
|
-
log.warn(
|
|
223
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
224
|
-
);
|
|
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");
|
|
225
267
|
}
|
|
226
268
|
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
227
269
|
}
|
|
@@ -235,7 +277,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
235
277
|
|
|
236
278
|
const publicClient = createPublicClient({
|
|
237
279
|
chain: ethereumChain.chainInfo,
|
|
238
|
-
transport:
|
|
280
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
239
281
|
pollingInterval: config.viemPollingIntervalMS,
|
|
240
282
|
});
|
|
241
283
|
|
|
@@ -249,10 +291,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
249
291
|
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
250
292
|
|
|
251
293
|
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
252
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
294
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
253
295
|
rollupContract.getL1GenesisTime(),
|
|
254
296
|
rollupContract.getSlotDuration(),
|
|
255
297
|
rollupContract.getVersion(),
|
|
298
|
+
rollupContract.getManaLimit().then(Number),
|
|
256
299
|
] as const);
|
|
257
300
|
|
|
258
301
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -263,7 +306,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
263
306
|
);
|
|
264
307
|
}
|
|
265
308
|
|
|
266
|
-
const blobClient = await createBlobClientWithFileStores(config,
|
|
309
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
267
310
|
|
|
268
311
|
// attempt snapshot sync if possible
|
|
269
312
|
await trySnapshotSync(config, log);
|
|
@@ -277,27 +320,41 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
277
320
|
);
|
|
278
321
|
|
|
279
322
|
// now create the merkle trees and the world state synchronizer
|
|
280
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
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;
|
|
290
337
|
if (!config.realProofs) {
|
|
291
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');
|
|
292
351
|
}
|
|
293
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
294
352
|
|
|
295
353
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
296
354
|
const p2pClient = await createP2PClient(
|
|
297
|
-
P2PClientType.Full,
|
|
298
355
|
config,
|
|
299
356
|
archiver,
|
|
300
|
-
|
|
357
|
+
peerProofVerifier,
|
|
301
358
|
worldStateSynchronizer,
|
|
302
359
|
epochCache,
|
|
303
360
|
packageVersion,
|
|
@@ -306,67 +363,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
306
363
|
deps.p2pClientDeps,
|
|
307
364
|
);
|
|
308
365
|
|
|
309
|
-
// We
|
|
310
|
-
|
|
366
|
+
// We'll accumulate sentinel watchers here
|
|
367
|
+
const watchers: Watcher[] = [];
|
|
311
368
|
|
|
312
|
-
// Create
|
|
313
|
-
|
|
314
|
-
|
|
369
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
370
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
371
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
372
|
+
{
|
|
373
|
+
...config,
|
|
374
|
+
l1GenesisTime,
|
|
375
|
+
slotDuration: Number(slotDuration),
|
|
376
|
+
rollupManaLimit,
|
|
377
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
378
|
+
},
|
|
315
379
|
worldStateSynchronizer,
|
|
316
380
|
archiver,
|
|
317
381
|
dateProvider,
|
|
318
382
|
telemetry,
|
|
319
383
|
);
|
|
320
384
|
|
|
321
|
-
|
|
322
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
323
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
324
|
-
archiver,
|
|
325
|
-
dateProvider,
|
|
326
|
-
telemetry,
|
|
327
|
-
);
|
|
385
|
+
let validatorClient: ValidatorClient | undefined;
|
|
328
386
|
|
|
329
|
-
|
|
330
|
-
|
|
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
|
+
});
|
|
331
402
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
l1ToL2MessageSource: archiver,
|
|
342
|
-
keyStoreManager,
|
|
343
|
-
blobClient,
|
|
344
|
-
});
|
|
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);
|
|
345
412
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (validatorClient) {
|
|
350
|
-
watchers.push(validatorClient);
|
|
351
|
-
if (!options.dontStartSequencer) {
|
|
352
|
-
await validatorClient.registerHandlers();
|
|
413
|
+
if (!options.dontStartSequencer) {
|
|
414
|
+
await validatorClient.registerHandlers();
|
|
415
|
+
}
|
|
353
416
|
}
|
|
354
417
|
}
|
|
355
418
|
|
|
356
|
-
// If there's no validator client
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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, {
|
|
361
427
|
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
362
428
|
worldState: worldStateSynchronizer,
|
|
363
429
|
epochCache,
|
|
364
430
|
blockSource: archiver,
|
|
365
431
|
l1ToL2MessageSource: archiver,
|
|
366
432
|
p2pClient,
|
|
433
|
+
blobClient,
|
|
367
434
|
dateProvider,
|
|
368
435
|
telemetry,
|
|
369
|
-
}).
|
|
436
|
+
}).register(p2pClient, reexecute, archiver);
|
|
370
437
|
}
|
|
371
438
|
|
|
372
439
|
// Start world state and wait for it to sync to the archiver.
|
|
@@ -375,36 +442,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
375
442
|
// Start p2p. Note that it depends on world state to be running.
|
|
376
443
|
await p2pClient.start();
|
|
377
444
|
|
|
378
|
-
|
|
379
|
-
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
380
|
-
watchers.push(validatorsSentinel);
|
|
381
|
-
}
|
|
382
|
-
|
|
445
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
383
446
|
let epochPruneWatcher: EpochPruneWatcher | undefined;
|
|
384
|
-
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
385
|
-
epochPruneWatcher = new EpochPruneWatcher(
|
|
386
|
-
archiver,
|
|
387
|
-
archiver,
|
|
388
|
-
epochCache,
|
|
389
|
-
p2pClient.getTxProvider(),
|
|
390
|
-
blockBuilder,
|
|
391
|
-
config,
|
|
392
|
-
);
|
|
393
|
-
watchers.push(epochPruneWatcher);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
397
447
|
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
+
}
|
|
401
472
|
}
|
|
402
473
|
|
|
403
474
|
// Start p2p-related services once the archiver has completed sync
|
|
404
475
|
void archiver
|
|
405
476
|
.waitForInitialSync()
|
|
406
477
|
.then(async () => {
|
|
407
|
-
await p2pClient.start();
|
|
408
478
|
await validatorsSentinel?.start();
|
|
409
479
|
await epochPruneWatcher?.start();
|
|
410
480
|
await attestationsBlockWatcher?.start();
|
|
@@ -412,6 +482,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
412
482
|
})
|
|
413
483
|
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
414
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
|
+
|
|
415
496
|
// Validator enabled, create/start relevant service
|
|
416
497
|
let sequencer: SequencerClient | undefined;
|
|
417
498
|
let slasherClient: SlasherClientInterface | undefined;
|
|
@@ -434,33 +515,49 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
434
515
|
);
|
|
435
516
|
await slasherClient.start();
|
|
436
517
|
|
|
437
|
-
const l1TxUtils = config.
|
|
438
|
-
? await
|
|
518
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
519
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
439
520
|
publicClient,
|
|
440
521
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
441
|
-
config.
|
|
522
|
+
config.sequencerPublisherForwarderAddress,
|
|
442
523
|
{ ...config, scope: 'sequencer' },
|
|
443
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
524
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
444
525
|
)
|
|
445
|
-
: await
|
|
526
|
+
: await createL1TxUtilsFromSigners(
|
|
446
527
|
publicClient,
|
|
447
528
|
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
448
529
|
{ ...config, scope: 'sequencer' },
|
|
449
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
530
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
450
531
|
);
|
|
451
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
|
+
|
|
452
546
|
// Create and start the sequencer client
|
|
453
547
|
const checkpointsBuilder = new CheckpointsBuilder(
|
|
454
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
548
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
549
|
+
worldStateSynchronizer,
|
|
455
550
|
archiver,
|
|
456
551
|
dateProvider,
|
|
457
552
|
telemetry,
|
|
553
|
+
debugLogStore,
|
|
458
554
|
);
|
|
459
555
|
|
|
460
556
|
sequencer = await SequencerClient.new(config, {
|
|
461
557
|
...deps,
|
|
462
558
|
epochCache,
|
|
463
559
|
l1TxUtils,
|
|
560
|
+
funderL1TxUtils,
|
|
464
561
|
validatorClient,
|
|
465
562
|
p2pClient,
|
|
466
563
|
worldStateSynchronizer,
|
|
@@ -472,6 +569,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
472
569
|
dateProvider,
|
|
473
570
|
blobClient,
|
|
474
571
|
nodeKeyStore: keyStoreManager!,
|
|
572
|
+
globalVariableBuilder,
|
|
475
573
|
});
|
|
476
574
|
}
|
|
477
575
|
|
|
@@ -482,14 +580,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
482
580
|
log.warn(`Sequencer created but not started`);
|
|
483
581
|
}
|
|
484
582
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
+
}
|
|
491
605
|
|
|
492
|
-
|
|
606
|
+
const node = new AztecNodeService(
|
|
493
607
|
config,
|
|
494
608
|
p2pClient,
|
|
495
609
|
archiver,
|
|
@@ -498,19 +612,27 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
498
612
|
archiver,
|
|
499
613
|
worldStateSynchronizer,
|
|
500
614
|
sequencer,
|
|
615
|
+
proverNode,
|
|
501
616
|
slasherClient,
|
|
502
617
|
validatorsSentinel,
|
|
503
618
|
epochPruneWatcher,
|
|
504
619
|
ethereumChain.chainInfo.id,
|
|
505
620
|
config.rollupVersion,
|
|
506
621
|
globalVariableBuilder,
|
|
622
|
+
feeProvider,
|
|
507
623
|
epochCache,
|
|
508
624
|
packageVersion,
|
|
509
|
-
|
|
625
|
+
peerProofVerifier,
|
|
626
|
+
rpcProofVerifier,
|
|
510
627
|
telemetry,
|
|
511
628
|
log,
|
|
512
629
|
blobClient,
|
|
630
|
+
validatorClient,
|
|
631
|
+
keyStoreManager,
|
|
632
|
+
debugLogStore,
|
|
513
633
|
);
|
|
634
|
+
|
|
635
|
+
return node;
|
|
514
636
|
}
|
|
515
637
|
|
|
516
638
|
/**
|
|
@@ -521,6 +643,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
521
643
|
return this.sequencer;
|
|
522
644
|
}
|
|
523
645
|
|
|
646
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
647
|
+
public getProverNode(): ProverNode | undefined {
|
|
648
|
+
return this.proverNode;
|
|
649
|
+
}
|
|
650
|
+
|
|
524
651
|
public getBlockSource(): L2BlockSource {
|
|
525
652
|
return this.blockSource;
|
|
526
653
|
}
|
|
@@ -546,7 +673,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
546
673
|
}
|
|
547
674
|
|
|
548
675
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
549
|
-
return this.config.
|
|
676
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
550
677
|
}
|
|
551
678
|
|
|
552
679
|
/**
|
|
@@ -574,19 +701,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
574
701
|
enr,
|
|
575
702
|
l1ContractAddresses: contractAddresses,
|
|
576
703
|
protocolContractAddresses: protocolContractAddresses,
|
|
704
|
+
realProofs: !!this.config.realProofs,
|
|
577
705
|
};
|
|
578
706
|
|
|
579
707
|
return nodeInfo;
|
|
580
708
|
}
|
|
581
709
|
|
|
582
710
|
/**
|
|
583
|
-
* Get a block specified by its number.
|
|
584
|
-
* @param
|
|
711
|
+
* Get a block specified by its block number, block hash, or 'latest'.
|
|
712
|
+
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
585
713
|
* @returns The requested block.
|
|
586
714
|
*/
|
|
587
|
-
public async getBlock(
|
|
588
|
-
|
|
589
|
-
|
|
715
|
+
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
716
|
+
if (BlockHash.isBlockHash(block)) {
|
|
717
|
+
return this.getBlockByHash(block);
|
|
718
|
+
}
|
|
719
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
720
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
721
|
+
return this.buildInitialBlock();
|
|
722
|
+
}
|
|
723
|
+
return await this.blockSource.getL2Block(blockNumber);
|
|
590
724
|
}
|
|
591
725
|
|
|
592
726
|
/**
|
|
@@ -594,9 +728,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
594
728
|
* @param blockHash - The block hash being requested.
|
|
595
729
|
* @returns The requested block.
|
|
596
730
|
*/
|
|
597
|
-
public async getBlockByHash(blockHash:
|
|
598
|
-
const
|
|
599
|
-
|
|
731
|
+
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
732
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
733
|
+
if (blockHash.equals(initialBlockHash)) {
|
|
734
|
+
return this.buildInitialBlock();
|
|
735
|
+
}
|
|
736
|
+
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
private buildInitialBlock(): L2Block {
|
|
740
|
+
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
741
|
+
return L2Block.empty(initialHeader);
|
|
600
742
|
}
|
|
601
743
|
|
|
602
744
|
/**
|
|
@@ -605,8 +747,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
605
747
|
* @returns The requested block.
|
|
606
748
|
*/
|
|
607
749
|
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
608
|
-
|
|
609
|
-
return publishedBlock?.block;
|
|
750
|
+
return await this.blockSource.getL2BlockByArchive(archive);
|
|
610
751
|
}
|
|
611
752
|
|
|
612
753
|
/**
|
|
@@ -616,31 +757,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
616
757
|
* @returns The blocks requested.
|
|
617
758
|
*/
|
|
618
759
|
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
619
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
760
|
+
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
620
761
|
}
|
|
621
762
|
|
|
622
|
-
public async
|
|
623
|
-
return (await this.blockSource.
|
|
763
|
+
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
764
|
+
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
624
765
|
}
|
|
625
766
|
|
|
626
|
-
public async
|
|
627
|
-
return (await this.blockSource.
|
|
767
|
+
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
768
|
+
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
628
769
|
}
|
|
629
770
|
|
|
630
|
-
public
|
|
631
|
-
return
|
|
771
|
+
public getCheckpointsDataForEpoch(epochNumber: EpochNumber) {
|
|
772
|
+
return this.blockSource.getCheckpointsDataForEpoch(epochNumber);
|
|
632
773
|
}
|
|
633
774
|
|
|
634
|
-
public async
|
|
635
|
-
return
|
|
775
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
776
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
636
777
|
}
|
|
637
778
|
|
|
638
|
-
/**
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
*/
|
|
642
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
643
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
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);
|
|
644
782
|
}
|
|
645
783
|
|
|
646
784
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -663,6 +801,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
663
801
|
return await this.blockSource.getProvenBlockNumber();
|
|
664
802
|
}
|
|
665
803
|
|
|
804
|
+
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
805
|
+
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
809
|
+
return this.blockSource.getCheckpointNumber();
|
|
810
|
+
}
|
|
811
|
+
|
|
666
812
|
/**
|
|
667
813
|
* Method to fetch the version of the package.
|
|
668
814
|
* @returns The node package version
|
|
@@ -695,12 +841,51 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
695
841
|
return this.contractDataSource.getContract(address);
|
|
696
842
|
}
|
|
697
843
|
|
|
698
|
-
public getPrivateLogsByTags(
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
844
|
+
public async getPrivateLogsByTags(
|
|
845
|
+
tags: SiloedTag[],
|
|
846
|
+
page?: number,
|
|
847
|
+
referenceBlock?: BlockHash,
|
|
848
|
+
): Promise<TxScopedL2Log[][]> {
|
|
849
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
850
|
+
if (referenceBlock) {
|
|
851
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
852
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
853
|
+
upToBlockNumber = BlockNumber(0);
|
|
854
|
+
} else {
|
|
855
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
856
|
+
if (!header) {
|
|
857
|
+
throw new Error(
|
|
858
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
public async getPublicLogsByTagsFromContract(
|
|
868
|
+
contractAddress: AztecAddress,
|
|
869
|
+
tags: Tag[],
|
|
870
|
+
page?: number,
|
|
871
|
+
referenceBlock?: BlockHash,
|
|
872
|
+
): Promise<TxScopedL2Log[][]> {
|
|
873
|
+
let upToBlockNumber: BlockNumber | undefined;
|
|
874
|
+
if (referenceBlock) {
|
|
875
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
876
|
+
if (referenceBlock.equals(initialBlockHash)) {
|
|
877
|
+
upToBlockNumber = BlockNumber(0);
|
|
878
|
+
} else {
|
|
879
|
+
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
880
|
+
if (!header) {
|
|
881
|
+
throw new Error(
|
|
882
|
+
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
upToBlockNumber = header.globalVariables.blockNumber;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page, upToBlockNumber);
|
|
704
889
|
}
|
|
705
890
|
|
|
706
891
|
/**
|
|
@@ -742,26 +927,36 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
742
927
|
}
|
|
743
928
|
|
|
744
929
|
await this.p2pClient!.sendTx(tx);
|
|
745
|
-
|
|
746
|
-
this.
|
|
930
|
+
const duration = timer.ms();
|
|
931
|
+
this.metrics.receivedTx(duration, true);
|
|
932
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
747
933
|
}
|
|
748
934
|
|
|
749
935
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
755
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
756
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
757
|
-
}
|
|
936
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
937
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
938
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
939
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
758
940
|
|
|
941
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
759
942
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
943
|
+
|
|
944
|
+
let receipt: TxReceipt;
|
|
760
945
|
if (settledTxReceipt) {
|
|
761
|
-
|
|
946
|
+
receipt = settledTxReceipt;
|
|
947
|
+
} else if (isKnownToPool) {
|
|
948
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
949
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
950
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
951
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
952
|
+
} else {
|
|
953
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
954
|
+
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
762
955
|
}
|
|
763
956
|
|
|
764
|
-
|
|
957
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
958
|
+
|
|
959
|
+
return receipt;
|
|
765
960
|
}
|
|
766
961
|
|
|
767
962
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -776,8 +971,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
776
971
|
await tryStop(this.validatorsSentinel);
|
|
777
972
|
await tryStop(this.epochPruneWatcher);
|
|
778
973
|
await tryStop(this.slasherClient);
|
|
779
|
-
await tryStop(this.
|
|
974
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
780
975
|
await tryStop(this.sequencer);
|
|
976
|
+
await tryStop(this.proverNode);
|
|
781
977
|
await tryStop(this.p2pClient);
|
|
782
978
|
await tryStop(this.worldStateSynchronizer);
|
|
783
979
|
await tryStop(this.blockSource);
|
|
@@ -826,121 +1022,99 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
826
1022
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
827
1023
|
}
|
|
828
1024
|
|
|
829
|
-
/**
|
|
830
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
831
|
-
* the leaves were inserted.
|
|
832
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
833
|
-
* @param treeId - The tree to search in.
|
|
834
|
-
* @param leafValues - The values to search for.
|
|
835
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
836
|
-
*/
|
|
837
1025
|
public async findLeavesIndexes(
|
|
838
|
-
|
|
1026
|
+
referenceBlock: BlockParameter,
|
|
839
1027
|
treeId: MerkleTreeId,
|
|
840
1028
|
leafValues: Fr[],
|
|
841
1029
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
842
|
-
const committedDb = await this
|
|
1030
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
843
1031
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
844
1032
|
treeId,
|
|
845
1033
|
leafValues.map(x => x.toBuffer()),
|
|
846
1034
|
);
|
|
847
|
-
//
|
|
848
|
-
const
|
|
1035
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1036
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
849
1037
|
|
|
850
|
-
// Now we find the block numbers for the indices
|
|
851
|
-
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);
|
|
852
1040
|
|
|
853
|
-
//
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
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
|
+
);
|
|
857
1049
|
}
|
|
1050
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
858
1051
|
}
|
|
859
1052
|
|
|
860
1053
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
861
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1054
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
862
1055
|
|
|
863
|
-
// Now we obtain the block hashes from the archive tree
|
|
864
|
-
// (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).
|
|
865
1057
|
const blockHashes = await Promise.all(
|
|
866
1058
|
uniqueBlockNumbers.map(blockNumber => {
|
|
867
1059
|
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
868
1060
|
}),
|
|
869
1061
|
);
|
|
870
1062
|
|
|
871
|
-
//
|
|
1063
|
+
// Build a map from block number to block hash
|
|
1064
|
+
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
872
1065
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
873
|
-
|
|
1066
|
+
const blockHash = blockHashes[i];
|
|
1067
|
+
if (blockHash === undefined) {
|
|
874
1068
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
875
1069
|
}
|
|
1070
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
876
1071
|
}
|
|
877
1072
|
|
|
878
1073
|
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
879
|
-
return maybeIndices.map(
|
|
1074
|
+
return maybeIndices.map(index => {
|
|
880
1075
|
if (index === undefined) {
|
|
881
1076
|
return undefined;
|
|
882
1077
|
}
|
|
883
|
-
const blockNumber =
|
|
1078
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
884
1079
|
if (blockNumber === undefined) {
|
|
885
|
-
|
|
1080
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
886
1081
|
}
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
return undefined;
|
|
1082
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1083
|
+
if (l2BlockHash === undefined) {
|
|
1084
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
891
1085
|
}
|
|
892
1086
|
return {
|
|
893
|
-
l2BlockNumber:
|
|
894
|
-
l2BlockHash
|
|
1087
|
+
l2BlockNumber: blockNumber,
|
|
1088
|
+
l2BlockHash,
|
|
895
1089
|
data: index,
|
|
896
1090
|
};
|
|
897
1091
|
});
|
|
898
1092
|
}
|
|
899
1093
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
904
|
-
* @returns The sibling path for the leaf index.
|
|
905
|
-
*/
|
|
906
|
-
public async getNullifierSiblingPath(
|
|
907
|
-
blockNumber: BlockParameter,
|
|
908
|
-
leafIndex: bigint,
|
|
909
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
910
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
911
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
/**
|
|
915
|
-
* Returns a sibling path for the given index in the data tree.
|
|
916
|
-
* @param blockNumber - The block number at which to get the data.
|
|
917
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
918
|
-
* @returns The sibling path for the leaf index.
|
|
919
|
-
*/
|
|
920
|
-
public async getNoteHashSiblingPath(
|
|
921
|
-
blockNumber: BlockParameter,
|
|
922
|
-
leafIndex: bigint,
|
|
923
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
924
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
925
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
public async getArchiveMembershipWitness(
|
|
929
|
-
blockNumber: BlockParameter,
|
|
930
|
-
archive: Fr,
|
|
1094
|
+
public async getBlockHashMembershipWitness(
|
|
1095
|
+
referenceBlock: BlockParameter,
|
|
1096
|
+
blockHash: BlockHash,
|
|
931
1097
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
932
|
-
|
|
933
|
-
|
|
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));
|
|
1107
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
934
1108
|
return pathAndIndex === undefined
|
|
935
1109
|
? undefined
|
|
936
1110
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
937
1111
|
}
|
|
938
1112
|
|
|
939
1113
|
public async getNoteHashMembershipWitness(
|
|
940
|
-
|
|
1114
|
+
referenceBlock: BlockParameter,
|
|
941
1115
|
noteHash: Fr,
|
|
942
1116
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
943
|
-
const committedDb = await this
|
|
1117
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
944
1118
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
945
1119
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
946
1120
|
[noteHash],
|
|
@@ -950,17 +1124,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
1124
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
951
1125
|
}
|
|
952
1126
|
|
|
953
|
-
/**
|
|
954
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
955
|
-
* @param blockNumber - The block number at which to get the data.
|
|
956
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
957
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
958
|
-
*/
|
|
959
1127
|
public async getL1ToL2MessageMembershipWitness(
|
|
960
|
-
|
|
1128
|
+
referenceBlock: BlockParameter,
|
|
961
1129
|
l1ToL2Message: Fr,
|
|
962
1130
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
963
|
-
const db = await this
|
|
1131
|
+
const db = await this.getWorldState(referenceBlock);
|
|
964
1132
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
965
1133
|
if (!witness) {
|
|
966
1134
|
return undefined;
|
|
@@ -970,11 +1138,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
970
1138
|
return [witness.index, witness.path];
|
|
971
1139
|
}
|
|
972
1140
|
|
|
973
|
-
public async
|
|
1141
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
974
1142
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
975
|
-
return messageIndex
|
|
976
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
977
|
-
: undefined;
|
|
1143
|
+
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
978
1144
|
}
|
|
979
1145
|
|
|
980
1146
|
/**
|
|
@@ -993,64 +1159,21 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
993
1159
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
994
1160
|
*/
|
|
995
1161
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
996
|
-
// Assumes `
|
|
997
|
-
const
|
|
998
|
-
const blocksInCheckpoints
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
for (const block of blocks) {
|
|
1002
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1003
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1004
|
-
checkpointIndex++;
|
|
1005
|
-
blocksInCheckpoints.push([]);
|
|
1006
|
-
previousSlotNumber = slotNumber;
|
|
1007
|
-
}
|
|
1008
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1009
|
-
}
|
|
1162
|
+
// Assumes `getCheckpointedBlocksForEpoch` returns blocks in ascending order of block number.
|
|
1163
|
+
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1164
|
+
const blocksInCheckpoints = chunkBy(checkpointedBlocks, cb => cb.block.header.globalVariables.slotNumber).map(
|
|
1165
|
+
group => group.map(cb => cb.block),
|
|
1166
|
+
);
|
|
1010
1167
|
return blocksInCheckpoints.map(blocks =>
|
|
1011
1168
|
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1012
1169
|
);
|
|
1013
1170
|
}
|
|
1014
1171
|
|
|
1015
|
-
/**
|
|
1016
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
1017
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1018
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1019
|
-
* @returns The sibling path.
|
|
1020
|
-
*/
|
|
1021
|
-
public async getArchiveSiblingPath(
|
|
1022
|
-
blockNumber: BlockParameter,
|
|
1023
|
-
leafIndex: bigint,
|
|
1024
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1025
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1026
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Returns a sibling path for a leaf in the committed public data tree.
|
|
1031
|
-
* @param blockNumber - The block number at which to get the data.
|
|
1032
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
1033
|
-
* @returns The sibling path.
|
|
1034
|
-
*/
|
|
1035
|
-
public async getPublicDataSiblingPath(
|
|
1036
|
-
blockNumber: BlockParameter,
|
|
1037
|
-
leafIndex: bigint,
|
|
1038
|
-
): Promise<SiblingPath<typeof PUBLIC_DATA_TREE_HEIGHT>> {
|
|
1039
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1040
|
-
return committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex);
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
1045
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1046
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
1047
|
-
* @returns The nullifier membership witness (if found).
|
|
1048
|
-
*/
|
|
1049
1172
|
public async getNullifierMembershipWitness(
|
|
1050
|
-
|
|
1173
|
+
referenceBlock: BlockParameter,
|
|
1051
1174
|
nullifier: Fr,
|
|
1052
1175
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1053
|
-
const db = await this
|
|
1176
|
+
const db = await this.getWorldState(referenceBlock);
|
|
1054
1177
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1055
1178
|
if (!witness) {
|
|
1056
1179
|
return undefined;
|
|
@@ -1065,32 +1188,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1065
1188
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1066
1189
|
}
|
|
1067
1190
|
|
|
1068
|
-
/**
|
|
1069
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1070
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1071
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1072
|
-
* @returns The low nullifier membership witness (if found).
|
|
1073
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1074
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1075
|
-
* we are trying to prove non-inclusion for.
|
|
1076
|
-
*
|
|
1077
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1078
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1079
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1080
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1081
|
-
*/
|
|
1082
1191
|
public async getLowNullifierMembershipWitness(
|
|
1083
|
-
|
|
1192
|
+
referenceBlock: BlockParameter,
|
|
1084
1193
|
nullifier: Fr,
|
|
1085
1194
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1086
|
-
const committedDb = await this
|
|
1195
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1087
1196
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1088
1197
|
if (!findResult) {
|
|
1089
1198
|
return undefined;
|
|
1090
1199
|
}
|
|
1091
1200
|
const { index, alreadyPresent } = findResult;
|
|
1092
1201
|
if (alreadyPresent) {
|
|
1093
|
-
|
|
1202
|
+
throw new Error(
|
|
1203
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1204
|
+
);
|
|
1094
1205
|
}
|
|
1095
1206
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1096
1207
|
|
|
@@ -1098,8 +1209,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1098
1209
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1099
1210
|
}
|
|
1100
1211
|
|
|
1101
|
-
async getPublicDataWitness(
|
|
1102
|
-
const committedDb = await this
|
|
1212
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1213
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1103
1214
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1104
1215
|
if (!lowLeafResult) {
|
|
1105
1216
|
return undefined;
|
|
@@ -1113,19 +1224,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1113
1224
|
}
|
|
1114
1225
|
}
|
|
1115
1226
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
*
|
|
1119
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1120
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1121
|
-
*
|
|
1122
|
-
* @param contract - Address of the contract to query.
|
|
1123
|
-
* @param slot - Slot to query.
|
|
1124
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1125
|
-
* @returns Storage value at the given contract slot.
|
|
1126
|
-
*/
|
|
1127
|
-
public async getPublicStorageAt(blockNumber: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1128
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1227
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1228
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1129
1229
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1130
1230
|
|
|
1131
1231
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1139,24 +1239,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1139
1239
|
return preimage.leaf.value;
|
|
1140
1240
|
}
|
|
1141
1241
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1159
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1242
|
+
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1243
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1244
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1245
|
+
if (block.equals(initialBlockHash)) {
|
|
1246
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1247
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1248
|
+
}
|
|
1249
|
+
return this.blockSource.getBlockHeaderByHash(block);
|
|
1250
|
+
} else {
|
|
1251
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1252
|
+
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1253
|
+
if (blockNumber === BlockNumber.ZERO) {
|
|
1254
|
+
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1255
|
+
}
|
|
1256
|
+
return this.blockSource.getBlockHeader(block);
|
|
1257
|
+
}
|
|
1160
1258
|
}
|
|
1161
1259
|
|
|
1162
1260
|
/**
|
|
@@ -1168,6 +1266,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1168
1266
|
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1169
1267
|
}
|
|
1170
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
|
+
|
|
1171
1277
|
/**
|
|
1172
1278
|
* Simulates the public part of a transaction with the current state.
|
|
1173
1279
|
* @param tx - The transaction to simulate.
|
|
@@ -1191,7 +1297,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1191
1297
|
}
|
|
1192
1298
|
|
|
1193
1299
|
const txHash = tx.getTxHash();
|
|
1194
|
-
const
|
|
1300
|
+
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1301
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1195
1302
|
|
|
1196
1303
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1197
1304
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1206,6 +1313,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1206
1313
|
this.contractDataSource,
|
|
1207
1314
|
new DateProvider(),
|
|
1208
1315
|
this.telemetry,
|
|
1316
|
+
this.log.getBindings(),
|
|
1209
1317
|
);
|
|
1210
1318
|
|
|
1211
1319
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1214,6 +1322,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1214
1322
|
blockNumber,
|
|
1215
1323
|
});
|
|
1216
1324
|
|
|
1325
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1326
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1217
1327
|
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1218
1328
|
try {
|
|
1219
1329
|
const config = PublicSimulatorConfig.from({
|
|
@@ -1229,7 +1339,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1229
1339
|
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1230
1340
|
|
|
1231
1341
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1232
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1342
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1233
1343
|
// REFACTOR: Consider returning the error rather than throwing
|
|
1234
1344
|
if (failedTxs.length) {
|
|
1235
1345
|
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
@@ -1243,6 +1353,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1353
|
processedTx.txEffect,
|
|
1244
1354
|
returns,
|
|
1245
1355
|
processedTx.gasUsed,
|
|
1356
|
+
debugLogs,
|
|
1246
1357
|
);
|
|
1247
1358
|
} finally {
|
|
1248
1359
|
await merkleTreeFork.close();
|
|
@@ -1254,21 +1365,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1254
1365
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1255
1366
|
): Promise<TxValidationResult> {
|
|
1256
1367
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1257
|
-
const verifier = isSimulation ? undefined : this.
|
|
1368
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1258
1369
|
|
|
1259
|
-
// 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)
|
|
1260
1371
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1261
1372
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1373
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1374
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1375
|
+
db,
|
|
1376
|
+
this.contractDataSource,
|
|
1377
|
+
verifier,
|
|
1378
|
+
{
|
|
1379
|
+
timestamp: nextSlotTimestamp,
|
|
1380
|
+
blockNumber,
|
|
1381
|
+
l1ChainId: this.l1ChainId,
|
|
1382
|
+
rollupVersion: this.version,
|
|
1383
|
+
setupAllowList: [
|
|
1384
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1385
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1386
|
+
],
|
|
1387
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1388
|
+
skipFeeEnforcement,
|
|
1389
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1390
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1391
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1392
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1393
|
+
},
|
|
1394
|
+
this.log.getBindings(),
|
|
1395
|
+
);
|
|
1272
1396
|
|
|
1273
1397
|
return await validator.validateTx(tx);
|
|
1274
1398
|
}
|
|
@@ -1290,7 +1414,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1290
1414
|
archiver.updateConfig(config);
|
|
1291
1415
|
}
|
|
1292
1416
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1293
|
-
|
|
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
|
+
}
|
|
1294
1426
|
}
|
|
1295
1427
|
|
|
1296
1428
|
this.config = newConfig;
|
|
@@ -1365,7 +1497,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1365
1497
|
return Promise.resolve();
|
|
1366
1498
|
}
|
|
1367
1499
|
|
|
1368
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1500
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1369
1501
|
const archiver = this.blockSource as Archiver;
|
|
1370
1502
|
if (!('rollbackTo' in archiver)) {
|
|
1371
1503
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1395,9 +1527,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1395
1527
|
this.log.error(`Error during rollback`, err);
|
|
1396
1528
|
throw err;
|
|
1397
1529
|
} finally {
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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
|
+
}
|
|
1401
1537
|
}
|
|
1402
1538
|
}
|
|
1403
1539
|
|
|
@@ -1414,34 +1550,152 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1414
1550
|
return Promise.resolve();
|
|
1415
1551
|
}
|
|
1416
1552
|
|
|
1417
|
-
public getSlashPayloads(): Promise<SlashPayloadRound[]> {
|
|
1418
|
-
if (!this.slasherClient) {
|
|
1419
|
-
throw new Error(`Slasher client not enabled`);
|
|
1420
|
-
}
|
|
1421
|
-
return this.slasherClient.getSlashPayloads();
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
1553
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
1425
1554
|
if (!this.slasherClient) {
|
|
1426
1555
|
throw new Error(`Slasher client not enabled`);
|
|
1427
1556
|
}
|
|
1428
1557
|
if (round === 'all') {
|
|
1429
|
-
return this.slasherClient.
|
|
1558
|
+
return this.slasherClient.getOffenses();
|
|
1430
1559
|
} else {
|
|
1431
1560
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1432
1561
|
}
|
|
1433
1562
|
}
|
|
1434
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
|
+
|
|
1686
|
+
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1687
|
+
if (!this.initialHeaderHashPromise) {
|
|
1688
|
+
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1689
|
+
}
|
|
1690
|
+
return this.initialHeaderHashPromise;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1435
1693
|
/**
|
|
1436
1694
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1437
|
-
* @param
|
|
1695
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1438
1696
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1439
1697
|
*/
|
|
1440
|
-
async
|
|
1441
|
-
if (typeof blockNumber === 'number' && blockNumber < INITIAL_L2_BLOCK_NUM - 1) {
|
|
1442
|
-
throw new Error('Invalid block number to get world state for: ' + blockNumber);
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1698
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1445
1699
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1446
1700
|
try {
|
|
1447
1701
|
// Attempt to sync the world state if necessary
|
|
@@ -1450,16 +1704,70 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1450
1704
|
this.log.error(`Error getting world state: ${err}`);
|
|
1451
1705
|
}
|
|
1452
1706
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1707
|
+
if (block === 'latest') {
|
|
1708
|
+
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1456
1709
|
return this.worldStateSynchronizer.getCommitted();
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
// Get the block number, either directly from the parameter or by quering the archiver with the block hash
|
|
1713
|
+
let blockNumber: BlockNumber;
|
|
1714
|
+
if (BlockHash.isBlockHash(block)) {
|
|
1715
|
+
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1716
|
+
if (block.equals(initialBlockHash)) {
|
|
1717
|
+
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1718
|
+
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1722
|
+
if (!header) {
|
|
1723
|
+
throw new Error(
|
|
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.`,
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
blockNumber = header.getBlockNumber();
|
|
1460
1729
|
} else {
|
|
1461
|
-
|
|
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}).`);
|
|
1736
|
+
}
|
|
1737
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1738
|
+
|
|
1739
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1740
|
+
|
|
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
|
+
);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
return snapshot;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
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();
|
|
1462
1769
|
}
|
|
1770
|
+
return block as BlockNumber;
|
|
1463
1771
|
}
|
|
1464
1772
|
|
|
1465
1773
|
/**
|