@aztec/aztec-node 0.0.1-commit.2448fdb → 0.0.1-commit.2606882
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/block_response_helpers.d.ts +25 -0
- package/dest/aztec-node/block_response_helpers.d.ts.map +1 -0
- package/dest/aztec-node/block_response_helpers.js +112 -0
- 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 +6 -6
- package/dest/aztec-node/public_data_overrides.d.ts +13 -0
- package/dest/aztec-node/public_data_overrides.d.ts.map +1 -0
- package/dest/aztec-node/public_data_overrides.js +21 -0
- package/dest/aztec-node/server.d.ts +63 -94
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +930 -482
- package/dest/sentinel/config.d.ts +3 -2
- package/dest/sentinel/config.d.ts.map +1 -1
- package/dest/sentinel/config.js +15 -5
- package/dest/sentinel/factory.d.ts +5 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +4 -4
- package/dest/sentinel/sentinel.d.ts +133 -9
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +212 -70
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +25 -17
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +27 -27
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +12 -8
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/server.ts +1022 -611
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +8 -5
- package/src/sentinel/sentinel.ts +267 -82
- package/src/sentinel/store.ts +26 -18
- package/src/test/index.ts +2 -2
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
1
|
+
import { Archiver, L1ToL2MessagesNotReadyError, createArchiver } from '@aztec/archiver';
|
|
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
5
|
import { Blob } from '@aztec/blob-lib';
|
|
5
6
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
@@ -7,7 +8,8 @@ import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
|
7
8
|
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
8
9
|
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
9
10
|
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
10
|
-
import type
|
|
11
|
+
import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
11
13
|
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
12
14
|
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
15
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
@@ -18,6 +20,7 @@ import { retryUntil } from '@aztec/foundation/retry';
|
|
|
18
20
|
import { count } from '@aztec/foundation/string';
|
|
19
21
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
20
22
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
23
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
21
24
|
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
22
25
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
23
26
|
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
@@ -31,26 +34,47 @@ import {
|
|
|
31
34
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
32
35
|
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
33
36
|
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
34
|
-
import {
|
|
35
|
-
|
|
37
|
+
import {
|
|
38
|
+
AutomineSequencer,
|
|
39
|
+
FeeProviderImpl,
|
|
40
|
+
GlobalVariableBuilder,
|
|
41
|
+
SequencerClient,
|
|
42
|
+
type SequencerPublisher,
|
|
43
|
+
createAutomineSequencer,
|
|
44
|
+
} from '@aztec/sequencer-client';
|
|
45
|
+
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
36
46
|
import {
|
|
37
47
|
AttestationsBlockWatcher,
|
|
38
|
-
|
|
48
|
+
AttestedInvalidProposalWatcher,
|
|
49
|
+
BroadcastedInvalidCheckpointProposalWatcher,
|
|
50
|
+
CheckpointEquivocationWatcher,
|
|
51
|
+
DataWithholdingWatcher,
|
|
39
52
|
type SlasherClientInterface,
|
|
40
53
|
type Watcher,
|
|
41
54
|
createSlasher,
|
|
42
55
|
} from '@aztec/slasher';
|
|
56
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
43
57
|
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
44
58
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
45
59
|
import {
|
|
46
60
|
type BlockData,
|
|
47
61
|
BlockHash,
|
|
48
62
|
type BlockParameter,
|
|
63
|
+
BlockTag,
|
|
64
|
+
type CheckpointsQuery,
|
|
65
|
+
type CommitteeAttestation,
|
|
49
66
|
type DataInBlock,
|
|
50
|
-
L2Block,
|
|
51
67
|
type L2BlockSource,
|
|
68
|
+
type L2Tips,
|
|
69
|
+
type NormalizedBlockParameter,
|
|
70
|
+
inspectBlockParameter,
|
|
52
71
|
} from '@aztec/stdlib/block';
|
|
53
|
-
import
|
|
72
|
+
import {
|
|
73
|
+
type CheckpointData,
|
|
74
|
+
CheckpointReexecutionTracker,
|
|
75
|
+
L1PublishedData,
|
|
76
|
+
type PublishedCheckpoint,
|
|
77
|
+
} from '@aztec/stdlib/checkpoint';
|
|
54
78
|
import type {
|
|
55
79
|
ContractClassPublic,
|
|
56
80
|
ContractDataSource,
|
|
@@ -58,17 +82,24 @@ import type {
|
|
|
58
82
|
NodeInfo,
|
|
59
83
|
ProtocolContractAddresses,
|
|
60
84
|
} from '@aztec/stdlib/contract';
|
|
61
|
-
import {
|
|
85
|
+
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
86
|
+
import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
62
87
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
88
|
+
import type {
|
|
89
|
+
AztecNode,
|
|
90
|
+
AztecNodeAdmin,
|
|
91
|
+
AztecNodeAdminConfig,
|
|
92
|
+
AztecNodeDebug,
|
|
93
|
+
BlockIncludeOptions,
|
|
94
|
+
BlockResponse,
|
|
95
|
+
BlocksIncludeOptions,
|
|
96
|
+
ChainTip,
|
|
97
|
+
ChainTips,
|
|
98
|
+
CheckpointIncludeOptions,
|
|
99
|
+
CheckpointParameter,
|
|
100
|
+
CheckpointResponse,
|
|
71
101
|
} from '@aztec/stdlib/interfaces/client';
|
|
102
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
72
103
|
import {
|
|
73
104
|
type AllowedElement,
|
|
74
105
|
type ClientProtocolCircuitVerifier,
|
|
@@ -78,25 +109,38 @@ import {
|
|
|
78
109
|
type WorldStateSynchronizer,
|
|
79
110
|
tryStop,
|
|
80
111
|
} from '@aztec/stdlib/interfaces/server';
|
|
81
|
-
import type { DebugLogStore,
|
|
112
|
+
import type { DebugLogStore, LogResult, PrivateLogsQuery, PublicLogsQuery } from '@aztec/stdlib/logs';
|
|
82
113
|
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
83
|
-
import {
|
|
84
|
-
|
|
85
|
-
|
|
114
|
+
import {
|
|
115
|
+
InboxLeaf,
|
|
116
|
+
type L1ToL2MessageSource,
|
|
117
|
+
type L2ToL1MembershipWitness,
|
|
118
|
+
appendL1ToL2MessagesToTree,
|
|
119
|
+
} from '@aztec/stdlib/messaging';
|
|
120
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
121
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
122
|
+
import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
86
123
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
87
124
|
import {
|
|
88
|
-
|
|
125
|
+
DroppedTxReceipt,
|
|
126
|
+
type FeeProvider,
|
|
127
|
+
type GetTxReceiptOptions,
|
|
89
128
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
90
129
|
type IndexedTxEffect,
|
|
130
|
+
MinedTxReceipt,
|
|
131
|
+
type MinedTxStatus,
|
|
132
|
+
PendingTxReceipt,
|
|
91
133
|
PublicSimulationOutput,
|
|
134
|
+
type SimulationOverrides,
|
|
92
135
|
Tx,
|
|
93
136
|
type TxHash,
|
|
94
|
-
TxReceipt,
|
|
137
|
+
type TxReceipt,
|
|
95
138
|
TxStatus,
|
|
96
139
|
type TxValidationResult,
|
|
97
140
|
} from '@aztec/stdlib/tx';
|
|
98
141
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
99
142
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
143
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
100
144
|
import {
|
|
101
145
|
Attributes,
|
|
102
146
|
type TelemetryClient,
|
|
@@ -114,24 +158,32 @@ import {
|
|
|
114
158
|
createValidatorClient,
|
|
115
159
|
} from '@aztec/validator-client';
|
|
116
160
|
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
117
|
-
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
161
|
+
import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
|
|
118
162
|
|
|
119
163
|
import { createPublicClient } from 'viem';
|
|
120
164
|
|
|
121
165
|
import { createSentinel } from '../sentinel/factory.js';
|
|
122
166
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
167
|
+
import {
|
|
168
|
+
blockResponseFromBlockData,
|
|
169
|
+
blockResponseFromL2Block,
|
|
170
|
+
checkpointResponseFromCheckpointData,
|
|
171
|
+
checkpointResponseFromPublishedCheckpoint,
|
|
172
|
+
projectProposedToCheckpointResponse,
|
|
173
|
+
} from './block_response_helpers.js';
|
|
123
174
|
import { type AztecNodeConfig, createKeyStoreForValidator } from './config.js';
|
|
124
175
|
import { NodeMetrics } from './node_metrics.js';
|
|
176
|
+
import { applyPublicDataOverrides } from './public_data_overrides.js';
|
|
125
177
|
|
|
126
178
|
/**
|
|
127
179
|
* The aztec node.
|
|
128
180
|
*/
|
|
129
181
|
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
130
182
|
private metrics: NodeMetrics;
|
|
131
|
-
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
132
|
-
|
|
133
183
|
// Prevent two snapshot operations to happen simultaneously
|
|
134
184
|
private isUploadingSnapshot = false;
|
|
185
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
186
|
+
private sequencerPausedMinTxsPerBlock: number | undefined;
|
|
135
187
|
|
|
136
188
|
public readonly tracer: Tracer;
|
|
137
189
|
|
|
@@ -147,25 +199,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
147
199
|
protected readonly proverNode: ProverNode | undefined,
|
|
148
200
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
149
201
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
150
|
-
|
|
202
|
+
private readonly stopStartedWatchers: () => Promise<void>,
|
|
151
203
|
protected readonly l1ChainId: number,
|
|
152
204
|
protected readonly version: number,
|
|
153
205
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
206
|
+
protected readonly feeProvider: FeeProvider,
|
|
154
207
|
protected readonly epochCache: EpochCacheInterface,
|
|
155
208
|
protected readonly packageVersion: string,
|
|
156
|
-
private
|
|
209
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
210
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
211
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
158
212
|
private log = createLogger('node'),
|
|
159
213
|
private blobClient?: BlobClientInterface,
|
|
160
214
|
private validatorClient?: ValidatorClient,
|
|
161
215
|
private keyStoreManager?: KeystoreManager,
|
|
162
216
|
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
217
|
+
private readonly automineSequencer?: AutomineSequencer,
|
|
163
218
|
) {
|
|
164
219
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
165
220
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
166
221
|
|
|
167
222
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
168
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
223
|
+
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
169
224
|
|
|
170
225
|
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
171
226
|
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
@@ -175,13 +230,248 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
175
230
|
}
|
|
176
231
|
}
|
|
177
232
|
|
|
233
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
234
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
235
|
+
return this.rpcProofVerifier;
|
|
236
|
+
}
|
|
237
|
+
|
|
178
238
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
179
239
|
const status = await this.worldStateSynchronizer.status();
|
|
180
240
|
return status.syncSummary;
|
|
181
241
|
}
|
|
182
242
|
|
|
183
|
-
public
|
|
184
|
-
|
|
243
|
+
public async getChainTips(): Promise<ChainTips> {
|
|
244
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
245
|
+
return { proposed, checkpointed, proven, finalized };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
public getCheckpointsData(query: CheckpointsQuery) {
|
|
249
|
+
return this.blockSource.getCheckpointsData(query);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public async getBlockNumber(tip?: ChainTip): Promise<BlockNumber> {
|
|
253
|
+
if (tip === undefined || tip === 'proposed') {
|
|
254
|
+
return this.blockSource.getBlockNumber();
|
|
255
|
+
}
|
|
256
|
+
return (await this.blockSource.getBlockNumber({ tag: tip })) ?? BlockNumber.ZERO;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
public async getCheckpointNumber(tip?: ChainTip): Promise<CheckpointNumber> {
|
|
260
|
+
const tips = await this.blockSource.getL2Tips();
|
|
261
|
+
switch (tip) {
|
|
262
|
+
case undefined:
|
|
263
|
+
case 'checkpointed':
|
|
264
|
+
return tips.checkpointed.checkpoint.number;
|
|
265
|
+
case 'proposed':
|
|
266
|
+
return tips.proposedCheckpoint.checkpoint.number;
|
|
267
|
+
case 'proven':
|
|
268
|
+
return tips.proven.checkpoint.number;
|
|
269
|
+
case 'finalized':
|
|
270
|
+
return tips.finalized.checkpoint.number;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private isChainTip(value: unknown): value is ChainTip {
|
|
275
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
280
|
+
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
281
|
+
* lookups are deferred to the underlying block source.
|
|
282
|
+
*/
|
|
283
|
+
private normalizeBlockParameter(param: BlockParameter): NormalizedBlockParameter {
|
|
284
|
+
if (BlockHash.isBlockHash(param)) {
|
|
285
|
+
return { hash: param };
|
|
286
|
+
}
|
|
287
|
+
if (typeof param === 'number') {
|
|
288
|
+
return { number: param as BlockNumber };
|
|
289
|
+
}
|
|
290
|
+
if (typeof param === 'string') {
|
|
291
|
+
if (this.isBlockTag(param)) {
|
|
292
|
+
return { tag: param === 'latest' ? 'proposed' : param };
|
|
293
|
+
}
|
|
294
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
295
|
+
}
|
|
296
|
+
if (typeof param === 'object' && param !== null) {
|
|
297
|
+
if ('number' in param) {
|
|
298
|
+
return { number: param.number };
|
|
299
|
+
}
|
|
300
|
+
if ('hash' in param) {
|
|
301
|
+
return { hash: param.hash };
|
|
302
|
+
}
|
|
303
|
+
if ('archive' in param) {
|
|
304
|
+
return { archive: param.archive };
|
|
305
|
+
}
|
|
306
|
+
if ('tag' in param) {
|
|
307
|
+
if (this.isBlockTag(param.tag)) {
|
|
308
|
+
return { tag: param.tag };
|
|
309
|
+
}
|
|
310
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private isBlockTag(value: string): value is BlockTag {
|
|
317
|
+
return BlockTag.includes(value as BlockTag);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
322
|
+
*
|
|
323
|
+
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
324
|
+
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
325
|
+
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
326
|
+
* confirmed→proposed lookup against either store.
|
|
327
|
+
*/
|
|
328
|
+
private async resolveCheckpointParameter(
|
|
329
|
+
param: CheckpointParameter,
|
|
330
|
+
): Promise<{ number: CheckpointNumber } | { slot: SlotNumber }> {
|
|
331
|
+
if (typeof param === 'number') {
|
|
332
|
+
return { number: param as CheckpointNumber };
|
|
333
|
+
}
|
|
334
|
+
if (this.isChainTip(param)) {
|
|
335
|
+
const tips = await this.blockSource.getL2Tips();
|
|
336
|
+
switch (param) {
|
|
337
|
+
case 'proposed':
|
|
338
|
+
return { number: tips.proposedCheckpoint.checkpoint.number };
|
|
339
|
+
case 'checkpointed':
|
|
340
|
+
return { number: tips.checkpointed.checkpoint.number };
|
|
341
|
+
case 'proven':
|
|
342
|
+
return { number: tips.proven.checkpoint.number };
|
|
343
|
+
case 'finalized':
|
|
344
|
+
return { number: tips.finalized.checkpoint.number };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (typeof param === 'object' && param !== null) {
|
|
348
|
+
if ('number' in param) {
|
|
349
|
+
return { number: param.number };
|
|
350
|
+
}
|
|
351
|
+
if ('slot' in param) {
|
|
352
|
+
return { slot: param.slot };
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */
|
|
359
|
+
async #getCheckpointContext(
|
|
360
|
+
checkpointNumber: CheckpointNumber,
|
|
361
|
+
): Promise<{ l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined> {
|
|
362
|
+
const checkpoint = await this.blockSource.getCheckpointData({ number: checkpointNumber });
|
|
363
|
+
if (!checkpoint) {
|
|
364
|
+
return undefined;
|
|
365
|
+
}
|
|
366
|
+
return { l1: checkpoint.l1, attestations: checkpoint.attestations };
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public async getBlock<Opts extends BlockIncludeOptions = {}>(
|
|
370
|
+
param: BlockParameter,
|
|
371
|
+
options: Opts = {} as Opts,
|
|
372
|
+
): Promise<BlockResponse<Opts> | undefined> {
|
|
373
|
+
const query = this.normalizeBlockParameter(param);
|
|
374
|
+
const wantTxs = !!options.includeTransactions;
|
|
375
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
376
|
+
|
|
377
|
+
if (wantTxs) {
|
|
378
|
+
const block = await this.blockSource.getBlock(query);
|
|
379
|
+
if (!block) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
383
|
+
return (await blockResponseFromL2Block(block, options, ctx)) as BlockResponse<Opts>;
|
|
384
|
+
}
|
|
385
|
+
const data = await this.blockSource.getBlockData(query);
|
|
386
|
+
if (!data) {
|
|
387
|
+
return undefined;
|
|
388
|
+
}
|
|
389
|
+
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
390
|
+
return blockResponseFromBlockData(data, options, ctx) as BlockResponse<Opts>;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
|
|
394
|
+
const query = this.normalizeBlockParameter(param);
|
|
395
|
+
return this.blockSource.getBlockData(query);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
public async getBlocks<Opts extends BlocksIncludeOptions = {}>(
|
|
399
|
+
from: BlockNumber,
|
|
400
|
+
limit: number,
|
|
401
|
+
options: Opts = {} as Opts,
|
|
402
|
+
): Promise<BlockResponse<Opts>[]> {
|
|
403
|
+
const wantTxs = !!options.includeTransactions;
|
|
404
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
405
|
+
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
406
|
+
if (wantTxs) {
|
|
407
|
+
const blocks = await this.blockSource.getBlocks({ from, limit, onlyCheckpointed });
|
|
408
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
409
|
+
return (await Promise.all(
|
|
410
|
+
blocks.map(block => blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))),
|
|
411
|
+
)) as BlockResponse<Opts>[];
|
|
412
|
+
}
|
|
413
|
+
const dataItems = await this.blockSource.getBlocksData({ from, limit, onlyCheckpointed });
|
|
414
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
415
|
+
return (await Promise.all(
|
|
416
|
+
dataItems.map(data => blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))),
|
|
417
|
+
)) as BlockResponse<Opts>[];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */
|
|
421
|
+
async #getCheckpointContextsForBlocks(
|
|
422
|
+
blocks: { checkpointNumber: CheckpointNumber }[],
|
|
423
|
+
): Promise<Map<CheckpointNumber, { l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined>> {
|
|
424
|
+
const unique = Array.from(new Set(blocks.map(b => b.checkpointNumber)));
|
|
425
|
+
const entries = await Promise.all(unique.map(async n => [n, await this.#getCheckpointContext(n)] as const));
|
|
426
|
+
return new Map(entries);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
public async getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
|
|
430
|
+
param: CheckpointParameter,
|
|
431
|
+
options: Opts = {} as Opts,
|
|
432
|
+
): Promise<CheckpointResponse<Opts> | undefined> {
|
|
433
|
+
const query = await this.resolveCheckpointParameter(param);
|
|
434
|
+
|
|
435
|
+
// Try the confirmed store first.
|
|
436
|
+
const confirmed = options.includeBlocks
|
|
437
|
+
? await this.blockSource.getCheckpoint(query)
|
|
438
|
+
: await this.blockSource.getCheckpointData(query);
|
|
439
|
+
if (confirmed) {
|
|
440
|
+
return (await (options.includeBlocks
|
|
441
|
+
? checkpointResponseFromPublishedCheckpoint(confirmed as PublishedCheckpoint, options)
|
|
442
|
+
: checkpointResponseFromCheckpointData(confirmed as CheckpointData, options))) as CheckpointResponse<Opts>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Fall back to the proposed store.
|
|
446
|
+
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
447
|
+
if (proposed) {
|
|
448
|
+
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
449
|
+
throw new BadRequestError(
|
|
450
|
+
`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`,
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
const blocks = options.includeBlocks
|
|
454
|
+
? await this.blockSource.getBlocks({ from: proposed.startBlock, limit: proposed.blockCount })
|
|
455
|
+
: undefined;
|
|
456
|
+
return (await projectProposedToCheckpointResponse(proposed, options, blocks)) as CheckpointResponse<Opts>;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return undefined;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
public async getCheckpoints<Opts extends CheckpointIncludeOptions = {}>(
|
|
463
|
+
from: CheckpointNumber,
|
|
464
|
+
limit: number,
|
|
465
|
+
options: Opts = {} as Opts,
|
|
466
|
+
): Promise<CheckpointResponse<Opts>[]> {
|
|
467
|
+
if (options.includeBlocks) {
|
|
468
|
+
const checkpoints = await this.blockSource.getCheckpoints({ from, limit });
|
|
469
|
+
return (await Promise.all(
|
|
470
|
+
checkpoints.map(cp => checkpointResponseFromPublishedCheckpoint(cp, options)),
|
|
471
|
+
)) as CheckpointResponse<Opts>[];
|
|
472
|
+
}
|
|
473
|
+
const datas = await this.blockSource.getCheckpointsData({ from, limit });
|
|
474
|
+
return datas.map(d => checkpointResponseFromCheckpointData(d, options)) as CheckpointResponse<Opts>[];
|
|
185
475
|
}
|
|
186
476
|
|
|
187
477
|
/**
|
|
@@ -201,14 +491,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
201
491
|
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
202
492
|
} = {},
|
|
203
493
|
options: {
|
|
204
|
-
|
|
494
|
+
genesis?: GenesisData;
|
|
205
495
|
dontStartSequencer?: boolean;
|
|
206
496
|
dontStartProverNode?: boolean;
|
|
207
497
|
} = {},
|
|
208
498
|
): Promise<AztecNodeService> {
|
|
209
499
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
210
500
|
const log = deps.logger ?? createLogger('node');
|
|
211
|
-
const packageVersion = getPackageVersion()
|
|
501
|
+
const packageVersion = getPackageVersion();
|
|
212
502
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
213
503
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
214
504
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
@@ -267,14 +557,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
267
557
|
|
|
268
558
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(
|
|
269
559
|
publicClient,
|
|
270
|
-
config.
|
|
560
|
+
config.registryAddress,
|
|
271
561
|
config.rollupVersion ?? 'canonical',
|
|
272
562
|
);
|
|
273
563
|
|
|
274
|
-
|
|
275
|
-
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
564
|
+
Object.assign(config, l1ContractsAddresses);
|
|
276
565
|
|
|
277
|
-
const rollupContract = new RollupContract(publicClient, config.
|
|
566
|
+
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
278
567
|
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
279
568
|
rollupContract.getL1GenesisTime(),
|
|
280
569
|
rollupContract.getSlotDuration(),
|
|
@@ -295,305 +584,447 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
295
584
|
// attempt snapshot sync if possible
|
|
296
585
|
await trySnapshotSync(config, log);
|
|
297
586
|
|
|
298
|
-
const epochCache = await EpochCache.create(config.
|
|
587
|
+
const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
|
|
299
588
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
log.info(
|
|
324
|
-
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
589
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
590
|
+
const started: { stop?(): Promise<void> | void }[] = [];
|
|
591
|
+
try {
|
|
592
|
+
// Default the orphan-prune grace window from the block build duration when unset, so the archiver
|
|
593
|
+
// waits roughly one build slot for a proposed checkpoint to arrive before pruning a block-only tip.
|
|
594
|
+
config.orphanProposedBlockPruneGraceSeconds ??=
|
|
595
|
+
config.blockDurationMs !== undefined ? Math.ceil(config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
596
|
+
|
|
597
|
+
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
598
|
+
const nativeWs = await createWorldState(config, options.genesis);
|
|
599
|
+
const initialHeader = nativeWs.getInitialHeader();
|
|
600
|
+
const initialBlockHash = await initialHeader.hash();
|
|
601
|
+
const archiver = await createArchiver(
|
|
602
|
+
config,
|
|
603
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
604
|
+
{
|
|
605
|
+
blockUntilSync: !config.skipArchiverInitialSync,
|
|
606
|
+
// The non-pipelined automine sequencer publishes each checkpoint in-slot, so it never
|
|
607
|
+
// leaves orphan proposed blocks; pruning would race its local push. See pruneOrphanProposedBlocks.
|
|
608
|
+
enableOrphanProposedBlockPruning: !config.useAutomineSequencer,
|
|
609
|
+
},
|
|
610
|
+
initialHeader,
|
|
611
|
+
initialBlockHash,
|
|
325
612
|
);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
613
|
+
started.push(archiver);
|
|
614
|
+
|
|
615
|
+
// The synchronizer takes ownership of the native world-state from here
|
|
616
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
617
|
+
started.push(worldStateSynchronizer);
|
|
618
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
619
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
620
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
621
|
+
if (useRealVerifiers) {
|
|
622
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
623
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
624
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
625
|
+
} else {
|
|
626
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
627
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
628
|
+
}
|
|
629
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
336
630
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
archiver,
|
|
341
|
-
proofVerifier,
|
|
342
|
-
worldStateSynchronizer,
|
|
343
|
-
epochCache,
|
|
344
|
-
packageVersion,
|
|
345
|
-
dateProvider,
|
|
346
|
-
telemetry,
|
|
347
|
-
deps.p2pClientDeps,
|
|
348
|
-
);
|
|
631
|
+
let debugLogStore: DebugLogStore;
|
|
632
|
+
if (!config.realProofs) {
|
|
633
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
349
634
|
|
|
350
|
-
|
|
351
|
-
|
|
635
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
636
|
+
log.info(
|
|
637
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
638
|
+
);
|
|
639
|
+
} else {
|
|
640
|
+
debugLogStore = new NullDebugLogStore();
|
|
641
|
+
}
|
|
352
642
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
...config,
|
|
643
|
+
const globalVariableBuilderConfig = {
|
|
644
|
+
rollupAddress: config.rollupAddress,
|
|
645
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
646
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
358
647
|
l1GenesisTime,
|
|
359
648
|
slotDuration: Number(slotDuration),
|
|
360
|
-
|
|
361
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
362
|
-
},
|
|
363
|
-
worldStateSynchronizer,
|
|
364
|
-
archiver,
|
|
365
|
-
dateProvider,
|
|
366
|
-
telemetry,
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
let validatorClient: ValidatorClient | undefined;
|
|
649
|
+
};
|
|
370
650
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
validatorClient = await createValidatorClient(config, {
|
|
374
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
375
|
-
worldState: worldStateSynchronizer,
|
|
376
|
-
p2pClient,
|
|
377
|
-
telemetry,
|
|
378
|
-
dateProvider,
|
|
379
|
-
epochCache,
|
|
380
|
-
blockSource: archiver,
|
|
381
|
-
l1ToL2MessageSource: archiver,
|
|
382
|
-
keyStoreManager,
|
|
383
|
-
blobClient,
|
|
384
|
-
slashingProtectionDb: deps.slashingProtectionDb,
|
|
385
|
-
});
|
|
651
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
652
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
386
653
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (validatorClient) {
|
|
391
|
-
watchers.push(validatorClient);
|
|
392
|
-
if (!options.dontStartSequencer) {
|
|
393
|
-
await validatorClient.registerHandlers();
|
|
394
|
-
}
|
|
654
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
655
|
+
if (proverOnly) {
|
|
656
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
395
657
|
}
|
|
396
|
-
}
|
|
397
658
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
405
|
-
createProposalHandler(config, {
|
|
406
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
407
|
-
worldState: worldStateSynchronizer,
|
|
659
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
660
|
+
const p2pClient = await createP2PClient(
|
|
661
|
+
config,
|
|
662
|
+
archiver,
|
|
663
|
+
peerProofVerifier,
|
|
664
|
+
worldStateSynchronizer,
|
|
408
665
|
epochCache,
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
p2pClient,
|
|
412
|
-
blobClient,
|
|
666
|
+
feeProvider,
|
|
667
|
+
packageVersion,
|
|
413
668
|
dateProvider,
|
|
414
669
|
telemetry,
|
|
415
|
-
|
|
416
|
-
|
|
670
|
+
deps.p2pClientDeps,
|
|
671
|
+
initialBlockHash,
|
|
672
|
+
);
|
|
673
|
+
started.push(p2pClient);
|
|
674
|
+
|
|
675
|
+
// We'll accumulate sentinel watchers here
|
|
676
|
+
const watchers: Watcher[] = [];
|
|
677
|
+
|
|
678
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
679
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
680
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
681
|
+
{
|
|
682
|
+
...config,
|
|
683
|
+
l1GenesisTime,
|
|
684
|
+
slotDuration: Number(slotDuration),
|
|
685
|
+
rollupManaLimit,
|
|
686
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
687
|
+
},
|
|
688
|
+
worldStateSynchronizer,
|
|
689
|
+
archiver,
|
|
690
|
+
dateProvider,
|
|
691
|
+
telemetry,
|
|
692
|
+
);
|
|
417
693
|
|
|
418
|
-
|
|
419
|
-
await worldStateSynchronizer.start();
|
|
694
|
+
let validatorClient: ValidatorClient | undefined;
|
|
420
695
|
|
|
421
|
-
|
|
422
|
-
|
|
696
|
+
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
697
|
+
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
423
698
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
699
|
+
if (!config.disableValidator) {
|
|
700
|
+
// Create validator client if required
|
|
701
|
+
validatorClient = await createValidatorClient(config, {
|
|
702
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
703
|
+
worldState: worldStateSynchronizer,
|
|
704
|
+
p2pClient,
|
|
705
|
+
telemetry,
|
|
706
|
+
dateProvider,
|
|
707
|
+
epochCache,
|
|
708
|
+
blockSource: archiver,
|
|
709
|
+
l1ToL2MessageSource: archiver,
|
|
710
|
+
keyStoreManager,
|
|
711
|
+
blobClient,
|
|
712
|
+
reexecutionTracker,
|
|
713
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
717
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
718
|
+
// like attestations or auths will fail.
|
|
719
|
+
if (validatorClient) {
|
|
720
|
+
watchers.push(validatorClient);
|
|
721
|
+
|
|
722
|
+
const vc = validatorClient;
|
|
723
|
+
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
724
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
725
|
+
|
|
726
|
+
if (!options.dontStartSequencer) {
|
|
727
|
+
await validatorClient.registerHandlers();
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
427
731
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
732
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
733
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
734
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
735
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
736
|
+
if (!validatorClient) {
|
|
737
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
738
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
739
|
+
createProposalHandler(config, {
|
|
740
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
741
|
+
worldState: worldStateSynchronizer,
|
|
742
|
+
epochCache,
|
|
743
|
+
blockSource: archiver,
|
|
744
|
+
l1ToL2MessageSource: archiver,
|
|
745
|
+
p2pClient,
|
|
746
|
+
blobClient,
|
|
747
|
+
dateProvider,
|
|
748
|
+
telemetry,
|
|
749
|
+
reexecutionTracker,
|
|
750
|
+
}).register(p2pClient, reexecute, archiver);
|
|
432
751
|
}
|
|
433
752
|
|
|
434
|
-
|
|
435
|
-
|
|
753
|
+
// Start world state and wait for it to sync to the archiver.
|
|
754
|
+
await worldStateSynchronizer.start();
|
|
755
|
+
|
|
756
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
757
|
+
await p2pClient.start();
|
|
758
|
+
|
|
759
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
760
|
+
let dataWithholdingWatcher: DataWithholdingWatcher | undefined;
|
|
761
|
+
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
762
|
+
let attestedInvalidProposalWatcher: AttestedInvalidProposalWatcher | undefined;
|
|
763
|
+
let broadcastedInvalidCheckpointProposalWatcher: BroadcastedInvalidCheckpointProposalWatcher | undefined;
|
|
764
|
+
let checkpointEquivocationWatcher: CheckpointEquivocationWatcher | undefined;
|
|
765
|
+
|
|
766
|
+
if (!proverOnly) {
|
|
767
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
768
|
+
if (validatorsSentinel) {
|
|
769
|
+
watchers.push(validatorsSentinel);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
dataWithholdingWatcher = new DataWithholdingWatcher(
|
|
773
|
+
epochCache,
|
|
436
774
|
archiver,
|
|
775
|
+
p2pClient.getTxProvider(),
|
|
776
|
+
p2pClient,
|
|
777
|
+
reexecutionTracker,
|
|
778
|
+
{ chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
|
|
779
|
+
config,
|
|
780
|
+
);
|
|
781
|
+
watchers.push(dataWithholdingWatcher);
|
|
782
|
+
|
|
783
|
+
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(
|
|
784
|
+
p2pClient,
|
|
437
785
|
archiver,
|
|
438
786
|
epochCache,
|
|
439
|
-
p2pClient.getTxProvider(),
|
|
440
|
-
validatorCheckpointsBuilder,
|
|
441
787
|
config,
|
|
442
788
|
);
|
|
443
|
-
watchers.push(
|
|
444
|
-
|
|
789
|
+
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
790
|
+
|
|
791
|
+
if (validatorClient) {
|
|
792
|
+
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(
|
|
793
|
+
p2pClient,
|
|
794
|
+
validatorClient,
|
|
795
|
+
archiver,
|
|
796
|
+
epochCache,
|
|
797
|
+
config,
|
|
798
|
+
{ log: log.createChild('attested-invalid-proposal-watcher') },
|
|
799
|
+
);
|
|
800
|
+
watchers.push(attestedInvalidProposalWatcher);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
804
|
+
watchers.push(checkpointEquivocationWatcher);
|
|
445
805
|
|
|
446
|
-
|
|
447
|
-
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
448
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
806
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
449
807
|
watchers.push(attestationsBlockWatcher);
|
|
450
808
|
}
|
|
451
|
-
}
|
|
452
809
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
468
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
469
|
-
l1GenesisTime,
|
|
470
|
-
slotDuration: Number(slotDuration),
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
// Validator enabled, create/start relevant service
|
|
474
|
-
let sequencer: SequencerClient | undefined;
|
|
475
|
-
let slasherClient: SlasherClientInterface | undefined;
|
|
476
|
-
if (!config.disableValidator && validatorClient) {
|
|
477
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
478
|
-
// as they are executed when the node is selected as proposer.
|
|
479
|
-
const validatorAddresses = keyStoreManager
|
|
480
|
-
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
481
|
-
: [];
|
|
482
|
-
|
|
483
|
-
slasherClient = await createSlasher(
|
|
484
|
-
config,
|
|
485
|
-
config.l1Contracts,
|
|
486
|
-
getPublicClient(config),
|
|
487
|
-
watchers,
|
|
488
|
-
dateProvider,
|
|
489
|
-
epochCache,
|
|
490
|
-
validatorAddresses,
|
|
491
|
-
undefined, // logger
|
|
492
|
-
);
|
|
493
|
-
await slasherClient.start();
|
|
810
|
+
const watchersToStart = compactArray([
|
|
811
|
+
validatorsSentinel,
|
|
812
|
+
dataWithholdingWatcher,
|
|
813
|
+
attestationsBlockWatcher,
|
|
814
|
+
broadcastedInvalidCheckpointProposalWatcher,
|
|
815
|
+
attestedInvalidProposalWatcher,
|
|
816
|
+
checkpointEquivocationWatcher,
|
|
817
|
+
]);
|
|
818
|
+
const startedWatchers: Watcher[] = [];
|
|
819
|
+
const stopStartedWatchers = async () => {
|
|
820
|
+
for (const watcher of startedWatchers) {
|
|
821
|
+
await tryStop(watcher);
|
|
822
|
+
}
|
|
823
|
+
};
|
|
494
824
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
825
|
+
// Start p2p-related services once the archiver has completed sync
|
|
826
|
+
void archiver
|
|
827
|
+
.waitForInitialSync()
|
|
828
|
+
.then(async () => {
|
|
829
|
+
for (const watcher of watchersToStart) {
|
|
830
|
+
await watcher.start();
|
|
831
|
+
startedWatchers.push(watcher);
|
|
832
|
+
}
|
|
833
|
+
log.info(`All p2p services started`);
|
|
834
|
+
})
|
|
835
|
+
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
836
|
+
started.push({ stop: stopStartedWatchers });
|
|
837
|
+
|
|
838
|
+
// Validator enabled, create/start relevant service
|
|
839
|
+
let sequencer: SequencerClient | undefined;
|
|
840
|
+
let automineSequencer: AutomineSequencer | undefined;
|
|
841
|
+
let slasherClient: SlasherClientInterface | undefined;
|
|
842
|
+
if (!config.disableValidator && validatorClient) {
|
|
843
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
844
|
+
// as they are executed when the node is selected as proposer.
|
|
845
|
+
const validatorAddresses = keyStoreManager
|
|
846
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
847
|
+
: [];
|
|
848
|
+
|
|
849
|
+
slasherClient = await createSlasher(
|
|
850
|
+
config,
|
|
851
|
+
pickL1ContractAddresses(config),
|
|
852
|
+
getPublicClient(config),
|
|
853
|
+
watchers,
|
|
854
|
+
dateProvider,
|
|
855
|
+
epochCache,
|
|
856
|
+
validatorAddresses,
|
|
857
|
+
undefined, // logger
|
|
858
|
+
);
|
|
859
|
+
await slasherClient.start();
|
|
860
|
+
started.push(slasherClient);
|
|
861
|
+
|
|
862
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
863
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
864
|
+
publicClient,
|
|
865
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
866
|
+
config.sequencerPublisherForwarderAddress,
|
|
867
|
+
{ ...config, scope: 'sequencer' },
|
|
868
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
869
|
+
)
|
|
870
|
+
: await createL1TxUtilsFromSigners(
|
|
871
|
+
publicClient,
|
|
872
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
873
|
+
{ ...config, scope: 'sequencer' },
|
|
874
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
878
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
879
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
880
|
+
if (fundingSigner) {
|
|
881
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
504
882
|
publicClient,
|
|
505
|
-
|
|
883
|
+
[fundingSigner],
|
|
506
884
|
{ ...config, scope: 'sequencer' },
|
|
507
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider
|
|
885
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
508
886
|
);
|
|
887
|
+
funderL1TxUtils = funder;
|
|
888
|
+
}
|
|
509
889
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
890
|
+
// Create and start the sequencer client
|
|
891
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
892
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
893
|
+
worldStateSynchronizer,
|
|
894
|
+
archiver,
|
|
895
|
+
dateProvider,
|
|
896
|
+
telemetry,
|
|
897
|
+
debugLogStore,
|
|
898
|
+
);
|
|
519
899
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
900
|
+
if (config.useAutomineSequencer) {
|
|
901
|
+
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
902
|
+
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
903
|
+
automineSequencer = await createAutomineSequencer({
|
|
904
|
+
config,
|
|
905
|
+
l1TxUtils,
|
|
906
|
+
funderL1TxUtils,
|
|
907
|
+
publicClient,
|
|
908
|
+
rollupContract,
|
|
909
|
+
epochCache,
|
|
910
|
+
blobClient,
|
|
911
|
+
telemetry,
|
|
912
|
+
dateProvider,
|
|
913
|
+
keyStoreManager: keyStoreManager!,
|
|
914
|
+
validatorClient,
|
|
915
|
+
checkpointsBuilder,
|
|
916
|
+
globalVariableBuilder,
|
|
917
|
+
worldStateSynchronizer,
|
|
918
|
+
archiver,
|
|
919
|
+
p2pClient,
|
|
920
|
+
l1Constants: {
|
|
921
|
+
l1GenesisTime,
|
|
922
|
+
slotDuration: Number(slotDuration),
|
|
923
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
924
|
+
rollupManaLimit,
|
|
925
|
+
},
|
|
926
|
+
log,
|
|
927
|
+
});
|
|
928
|
+
} else {
|
|
929
|
+
sequencer = await SequencerClient.new(config, {
|
|
930
|
+
...deps,
|
|
931
|
+
epochCache,
|
|
932
|
+
l1TxUtils,
|
|
933
|
+
funderL1TxUtils,
|
|
934
|
+
validatorClient,
|
|
935
|
+
p2pClient,
|
|
936
|
+
worldStateSynchronizer,
|
|
937
|
+
slasherClient,
|
|
938
|
+
checkpointsBuilder,
|
|
939
|
+
l2BlockSource: archiver,
|
|
940
|
+
l1ToL2MessageSource: archiver,
|
|
941
|
+
telemetry,
|
|
942
|
+
dateProvider,
|
|
943
|
+
blobClient,
|
|
944
|
+
nodeKeyStore: keyStoreManager!,
|
|
945
|
+
globalVariableBuilder,
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
}
|
|
538
949
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
950
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
951
|
+
await sequencer.start();
|
|
952
|
+
started.push(sequencer);
|
|
953
|
+
log.verbose(`Sequencer started`);
|
|
954
|
+
} else if (sequencer) {
|
|
955
|
+
log.warn(`Sequencer created but not started`);
|
|
956
|
+
}
|
|
545
957
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
958
|
+
if (!options.dontStartSequencer && automineSequencer) {
|
|
959
|
+
await automineSequencer.start();
|
|
960
|
+
started.push({ stop: () => automineSequencer!.stop() });
|
|
961
|
+
log.verbose(`AutomineSequencer started`);
|
|
962
|
+
} else if (automineSequencer) {
|
|
963
|
+
log.warn(`AutomineSequencer created but not started`);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// Create prover node subsystem if enabled
|
|
967
|
+
let proverNode: ProverNode | undefined;
|
|
968
|
+
if (config.enableProverNode) {
|
|
969
|
+
proverNode = await createProverNode(config, {
|
|
970
|
+
...deps.proverNodeDeps,
|
|
971
|
+
telemetry,
|
|
972
|
+
dateProvider,
|
|
973
|
+
archiver,
|
|
974
|
+
worldStateSynchronizer,
|
|
975
|
+
p2pClient,
|
|
976
|
+
epochCache,
|
|
977
|
+
blobClient,
|
|
978
|
+
keyStoreManager,
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
if (!options.dontStartProverNode) {
|
|
982
|
+
await proverNode.start();
|
|
983
|
+
started.push(proverNode);
|
|
984
|
+
log.info(`Prover node subsystem started`);
|
|
985
|
+
} else {
|
|
986
|
+
log.info(`Prover node subsystem created but not started`);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
const node = new AztecNodeService(
|
|
991
|
+
config,
|
|
992
|
+
p2pClient,
|
|
993
|
+
archiver,
|
|
994
|
+
archiver,
|
|
995
|
+
archiver,
|
|
553
996
|
archiver,
|
|
554
997
|
worldStateSynchronizer,
|
|
555
|
-
|
|
998
|
+
sequencer,
|
|
999
|
+
proverNode,
|
|
1000
|
+
slasherClient,
|
|
1001
|
+
validatorsSentinel,
|
|
1002
|
+
stopStartedWatchers,
|
|
1003
|
+
ethereumChain.chainInfo.id,
|
|
1004
|
+
config.rollupVersion,
|
|
1005
|
+
globalVariableBuilder,
|
|
1006
|
+
feeProvider,
|
|
556
1007
|
epochCache,
|
|
1008
|
+
packageVersion,
|
|
1009
|
+
peerProofVerifier,
|
|
1010
|
+
rpcProofVerifier,
|
|
1011
|
+
telemetry,
|
|
1012
|
+
log,
|
|
557
1013
|
blobClient,
|
|
1014
|
+
validatorClient,
|
|
558
1015
|
keyStoreManager,
|
|
559
|
-
|
|
1016
|
+
debugLogStore,
|
|
1017
|
+
automineSequencer,
|
|
1018
|
+
);
|
|
560
1019
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
1020
|
+
return node;
|
|
1021
|
+
} catch (err) {
|
|
1022
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1023
|
+
for (const resource of started.reverse()) {
|
|
1024
|
+
await tryStop(resource);
|
|
566
1025
|
}
|
|
1026
|
+
throw err;
|
|
567
1027
|
}
|
|
568
|
-
|
|
569
|
-
const node = new AztecNodeService(
|
|
570
|
-
config,
|
|
571
|
-
p2pClient,
|
|
572
|
-
archiver,
|
|
573
|
-
archiver,
|
|
574
|
-
archiver,
|
|
575
|
-
archiver,
|
|
576
|
-
worldStateSynchronizer,
|
|
577
|
-
sequencer,
|
|
578
|
-
proverNode,
|
|
579
|
-
slasherClient,
|
|
580
|
-
validatorsSentinel,
|
|
581
|
-
epochPruneWatcher,
|
|
582
|
-
ethereumChain.chainInfo.id,
|
|
583
|
-
config.rollupVersion,
|
|
584
|
-
globalVariableBuilder,
|
|
585
|
-
epochCache,
|
|
586
|
-
packageVersion,
|
|
587
|
-
proofVerifier,
|
|
588
|
-
telemetry,
|
|
589
|
-
log,
|
|
590
|
-
blobClient,
|
|
591
|
-
validatorClient,
|
|
592
|
-
keyStoreManager,
|
|
593
|
-
debugLogStore,
|
|
594
|
-
);
|
|
595
|
-
|
|
596
|
-
return node;
|
|
597
1028
|
}
|
|
598
1029
|
|
|
599
1030
|
/**
|
|
@@ -604,6 +1035,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
604
1035
|
return this.sequencer;
|
|
605
1036
|
}
|
|
606
1037
|
|
|
1038
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
|
|
1039
|
+
public getAutomineSequencer(): AutomineSequencer | undefined {
|
|
1040
|
+
return this.automineSequencer;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
607
1043
|
/** Returns the prover node subsystem, if enabled. */
|
|
608
1044
|
public getProverNode(): ProverNode | undefined {
|
|
609
1045
|
return this.proverNode;
|
|
@@ -626,7 +1062,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
626
1062
|
* @returns - The currently deployed L1 contract addresses.
|
|
627
1063
|
*/
|
|
628
1064
|
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
|
|
629
|
-
return Promise.resolve(this.config
|
|
1065
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
630
1066
|
}
|
|
631
1067
|
|
|
632
1068
|
public getEncodedEnr(): Promise<string | undefined> {
|
|
@@ -668,77 +1104,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
668
1104
|
return nodeInfo;
|
|
669
1105
|
}
|
|
670
1106
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
674
|
-
* @returns The requested block.
|
|
675
|
-
*/
|
|
676
|
-
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
677
|
-
if (BlockHash.isBlockHash(block)) {
|
|
678
|
-
return this.getBlockByHash(block);
|
|
679
|
-
}
|
|
680
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
681
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
682
|
-
return this.buildInitialBlock();
|
|
683
|
-
}
|
|
684
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Get a block specified by its hash.
|
|
689
|
-
* @param blockHash - The block hash being requested.
|
|
690
|
-
* @returns The requested block.
|
|
691
|
-
*/
|
|
692
|
-
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
693
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
694
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
695
|
-
return this.buildInitialBlock();
|
|
696
|
-
}
|
|
697
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
private buildInitialBlock(): L2Block {
|
|
701
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
702
|
-
return L2Block.empty(initialHeader);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Get a block specified by its archive root.
|
|
707
|
-
* @param archive - The archive root being requested.
|
|
708
|
-
* @returns The requested block.
|
|
709
|
-
*/
|
|
710
|
-
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
711
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
716
|
-
* @param from - The start of the range of blocks to return.
|
|
717
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
718
|
-
* @returns The blocks requested.
|
|
719
|
-
*/
|
|
720
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
721
|
-
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
725
|
-
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
729
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
1107
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
1108
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
730
1109
|
}
|
|
731
1110
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
/**
|
|
737
|
-
* Method to fetch the current min L2 fees.
|
|
738
|
-
* @returns The current min L2 fees.
|
|
739
|
-
*/
|
|
740
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
741
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
1111
|
+
/** Returns predicted min fees for the current slot and next N slots. */
|
|
1112
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
1113
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
742
1114
|
}
|
|
743
1115
|
|
|
744
1116
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
@@ -749,26 +1121,6 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
749
1121
|
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
750
1122
|
}
|
|
751
1123
|
|
|
752
|
-
/**
|
|
753
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
754
|
-
* @returns The block number.
|
|
755
|
-
*/
|
|
756
|
-
public async getBlockNumber(): Promise<BlockNumber> {
|
|
757
|
-
return await this.blockSource.getBlockNumber();
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
761
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
765
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
769
|
-
return this.blockSource.getCheckpointNumber();
|
|
770
|
-
}
|
|
771
|
-
|
|
772
1124
|
/**
|
|
773
1125
|
* Method to fetch the version of the package.
|
|
774
1126
|
* @returns The node package version
|
|
@@ -801,61 +1153,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
801
1153
|
return this.contractDataSource.getContract(address);
|
|
802
1154
|
}
|
|
803
1155
|
|
|
804
|
-
public
|
|
805
|
-
|
|
806
|
-
page?: number,
|
|
807
|
-
referenceBlock?: BlockHash,
|
|
808
|
-
): Promise<TxScopedL2Log[][]> {
|
|
809
|
-
if (referenceBlock) {
|
|
810
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
811
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
812
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
813
|
-
if (!header) {
|
|
814
|
-
throw new Error(
|
|
815
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
816
|
-
);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
public async getPublicLogsByTagsFromContract(
|
|
824
|
-
contractAddress: AztecAddress,
|
|
825
|
-
tags: Tag[],
|
|
826
|
-
page?: number,
|
|
827
|
-
referenceBlock?: BlockHash,
|
|
828
|
-
): Promise<TxScopedL2Log[][]> {
|
|
829
|
-
if (referenceBlock) {
|
|
830
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
831
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
832
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
833
|
-
if (!header) {
|
|
834
|
-
throw new Error(
|
|
835
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
return this.logsSource.getPublicLogsByTagsFromContract(contractAddress, tags, page);
|
|
1156
|
+
public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
1157
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
841
1158
|
}
|
|
842
1159
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
* @param filter - The filter to apply to the logs.
|
|
846
|
-
* @returns The requested logs.
|
|
847
|
-
*/
|
|
848
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
849
|
-
return this.logsSource.getPublicLogs(filter);
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
/**
|
|
853
|
-
* Gets contract class logs based on the provided filter.
|
|
854
|
-
* @param filter - The filter to apply to the logs.
|
|
855
|
-
* @returns The requested logs.
|
|
856
|
-
*/
|
|
857
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
858
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
1160
|
+
public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
|
|
1161
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
859
1162
|
}
|
|
860
1163
|
|
|
861
1164
|
/**
|
|
@@ -878,32 +1181,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
878
1181
|
throw new Error(`Invalid tx: ${reason}`);
|
|
879
1182
|
}
|
|
880
1183
|
|
|
881
|
-
|
|
1184
|
+
try {
|
|
1185
|
+
await this.p2pClient!.sendTx(tx);
|
|
1186
|
+
} catch (err) {
|
|
1187
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1188
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${(err as Error).message}`, { txHash });
|
|
1189
|
+
throw err;
|
|
1190
|
+
}
|
|
882
1191
|
const duration = timer.ms();
|
|
883
1192
|
this.metrics.receivedTx(duration, true);
|
|
884
1193
|
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
885
1194
|
}
|
|
886
1195
|
|
|
887
|
-
public async getTxReceipt
|
|
1196
|
+
public async getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
|
|
1197
|
+
txHash: TxHash,
|
|
1198
|
+
options?: TGetTxReceiptOptions,
|
|
1199
|
+
): Promise<TxReceipt<TGetTxReceiptOptions>> {
|
|
888
1200
|
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
889
|
-
// as a fallback if we don't find a
|
|
1201
|
+
// as a fallback if we don't find a mined tx effect in the archiver.
|
|
890
1202
|
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
891
1203
|
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
892
1204
|
|
|
893
|
-
// Then get the
|
|
894
|
-
const
|
|
1205
|
+
// Then get the raw tx effect from the archiver, which tracks every tx in a mined block.
|
|
1206
|
+
const indexed = await this.blockSource.getTxEffect(txHash);
|
|
895
1207
|
|
|
896
1208
|
let receipt: TxReceipt;
|
|
897
|
-
if (
|
|
898
|
-
receipt =
|
|
1209
|
+
if (indexed) {
|
|
1210
|
+
receipt = await this.#assembleMinedReceipt(indexed, options);
|
|
899
1211
|
} else if (isKnownToPool) {
|
|
900
1212
|
// If the tx is in the pool but not in the archiver, it's pending.
|
|
901
1213
|
// This handles race conditions between archiver and p2p, where the archiver
|
|
902
1214
|
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
903
|
-
|
|
1215
|
+
let tx: Tx | undefined;
|
|
1216
|
+
if (options?.includePendingTx) {
|
|
1217
|
+
// The tx may have left the pool since we checked its status (mined or dropped); in that case we
|
|
1218
|
+
// leave `tx` unset and still return a pending receipt.
|
|
1219
|
+
const pendingTx = await this.p2pClient.getTxByHashFromPool(txHash);
|
|
1220
|
+
tx = pendingTx && !options.includeProof ? pendingTx.withoutProof() : pendingTx;
|
|
1221
|
+
}
|
|
1222
|
+
receipt = new PendingTxReceipt(txHash, tx);
|
|
904
1223
|
} else {
|
|
905
1224
|
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
906
|
-
receipt = new
|
|
1225
|
+
receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
|
|
907
1226
|
}
|
|
908
1227
|
|
|
909
1228
|
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
@@ -911,6 +1230,44 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
911
1230
|
return receipt;
|
|
912
1231
|
}
|
|
913
1232
|
|
|
1233
|
+
/**
|
|
1234
|
+
* Assembles a {@link MinedTxReceipt} from a raw {@link IndexedTxEffect}, deriving the finalization status from the
|
|
1235
|
+
* cached L2 tips and the epoch from the block's slot number.
|
|
1236
|
+
*/
|
|
1237
|
+
async #assembleMinedReceipt(indexed: IndexedTxEffect, options?: GetTxReceiptOptions): Promise<MinedTxReceipt> {
|
|
1238
|
+
const blockNumber = indexed.l2BlockNumber;
|
|
1239
|
+
const [tips, l1Constants] = await Promise.all([this.blockSource.getL2Tips(), this.blockSource.getL1Constants()]);
|
|
1240
|
+
|
|
1241
|
+
const status = this.#deriveMinedStatus(blockNumber, tips);
|
|
1242
|
+
const epochNumber = getEpochAtSlot(indexed.slotNumber, l1Constants);
|
|
1243
|
+
|
|
1244
|
+
return new MinedTxReceipt(
|
|
1245
|
+
indexed.data.txHash,
|
|
1246
|
+
status,
|
|
1247
|
+
MinedTxReceipt.executionResultFromRevertCode(indexed.data.revertCode),
|
|
1248
|
+
indexed.data.transactionFee.toBigInt(),
|
|
1249
|
+
indexed.l2BlockHash,
|
|
1250
|
+
blockNumber,
|
|
1251
|
+
indexed.slotNumber,
|
|
1252
|
+
indexed.txIndexInBlock,
|
|
1253
|
+
epochNumber,
|
|
1254
|
+
options?.includeTxEffect ? indexed.data : undefined,
|
|
1255
|
+
/*debugLogs=*/ undefined,
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
#deriveMinedStatus(blockNumber: BlockNumber, tips: L2Tips): MinedTxStatus {
|
|
1260
|
+
if (blockNumber <= tips.finalized.block.number) {
|
|
1261
|
+
return TxStatus.FINALIZED;
|
|
1262
|
+
} else if (blockNumber <= tips.proven.block.number) {
|
|
1263
|
+
return TxStatus.PROVEN;
|
|
1264
|
+
} else if (blockNumber <= tips.checkpointed.block.number) {
|
|
1265
|
+
return TxStatus.CHECKPOINTED;
|
|
1266
|
+
} else {
|
|
1267
|
+
return TxStatus.PROPOSED;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
914
1271
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
915
1272
|
return this.blockSource.getTxEffect(txHash);
|
|
916
1273
|
}
|
|
@@ -920,11 +1277,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
920
1277
|
*/
|
|
921
1278
|
public async stop() {
|
|
922
1279
|
this.log.info(`Stopping Aztec Node`);
|
|
923
|
-
await
|
|
924
|
-
await tryStop(this.epochPruneWatcher);
|
|
1280
|
+
await this.stopStartedWatchers();
|
|
925
1281
|
await tryStop(this.slasherClient);
|
|
926
|
-
await tryStop(this.
|
|
1282
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
927
1283
|
await tryStop(this.sequencer);
|
|
1284
|
+
await tryStop(this.automineSequencer);
|
|
928
1285
|
await tryStop(this.proverNode);
|
|
929
1286
|
await tryStop(this.p2pClient);
|
|
930
1287
|
await tryStop(this.worldStateSynchronizer);
|
|
@@ -1013,7 +1370,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1013
1370
|
);
|
|
1014
1371
|
|
|
1015
1372
|
// Build a map from block number to block hash
|
|
1016
|
-
const blockNumberToHash = new Map<BlockNumber,
|
|
1373
|
+
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
1017
1374
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1018
1375
|
const blockHash = blockHashes[i];
|
|
1019
1376
|
if (blockHash === undefined) {
|
|
@@ -1031,13 +1388,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1031
1388
|
if (blockNumber === undefined) {
|
|
1032
1389
|
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1033
1390
|
}
|
|
1034
|
-
const
|
|
1035
|
-
if (
|
|
1391
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1392
|
+
if (l2BlockHash === undefined) {
|
|
1036
1393
|
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1037
1394
|
}
|
|
1038
1395
|
return {
|
|
1039
1396
|
l2BlockNumber: blockNumber,
|
|
1040
|
-
l2BlockHash
|
|
1397
|
+
l2BlockHash,
|
|
1041
1398
|
data: index,
|
|
1042
1399
|
};
|
|
1043
1400
|
});
|
|
@@ -1047,20 +1404,14 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1047
1404
|
referenceBlock: BlockParameter,
|
|
1048
1405
|
blockHash: BlockHash,
|
|
1049
1406
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1050
|
-
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1051
|
-
if (referenceBlock === BlockNumber.ZERO) {
|
|
1052
|
-
return undefined;
|
|
1053
|
-
}
|
|
1054
|
-
if (BlockHash.isBlockHash(referenceBlock)) {
|
|
1055
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1056
|
-
if (referenceBlock.equals(initialBlockHash)) {
|
|
1057
|
-
return undefined;
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
1407
|
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1061
1408
|
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1062
1409
|
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1063
1410
|
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1411
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1412
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1413
|
+
return undefined;
|
|
1414
|
+
}
|
|
1064
1415
|
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1065
1416
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1066
1417
|
return pathAndIndex === undefined
|
|
@@ -1098,35 +1449,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1098
1449
|
|
|
1099
1450
|
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
1100
1451
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1101
|
-
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
/**
|
|
1105
|
-
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
1106
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
1107
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
1108
|
-
*/
|
|
1109
|
-
public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
1110
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
1111
|
-
return messageIndex !== undefined;
|
|
1452
|
+
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
1112
1453
|
}
|
|
1113
1454
|
|
|
1114
1455
|
/**
|
|
1115
1456
|
* Returns all the L2 to L1 messages in an epoch.
|
|
1457
|
+
*
|
|
1458
|
+
* @deprecated Use {@link getL2ToL1MembershipWitness} to get an L2-to-L1 message witness directly.
|
|
1459
|
+
*
|
|
1116
1460
|
* @param epoch - The epoch at which to get the data.
|
|
1117
1461
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1118
1462
|
*/
|
|
1119
1463
|
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1120
|
-
|
|
1121
|
-
const
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
);
|
|
1125
|
-
return blocksInCheckpoints.map(blocks =>
|
|
1126
|
-
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1464
|
+
const blocks = await this.blockSource.getBlocks({ epoch, onlyCheckpointed: true });
|
|
1465
|
+
const blocksInCheckpoints = chunkBy(blocks, block => block.header.globalVariables.slotNumber);
|
|
1466
|
+
return blocksInCheckpoints.map(slotBlocks =>
|
|
1467
|
+
slotBlocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1127
1468
|
);
|
|
1128
1469
|
}
|
|
1129
1470
|
|
|
1471
|
+
/**
|
|
1472
|
+
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
1473
|
+
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
1474
|
+
*/
|
|
1475
|
+
public getL2ToL1MembershipWitness(
|
|
1476
|
+
txHash: TxHash,
|
|
1477
|
+
message: Fr,
|
|
1478
|
+
messageIndexInTx?: number,
|
|
1479
|
+
): Promise<L2ToL1MembershipWitness | undefined> {
|
|
1480
|
+
return this.blockSource.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1130
1483
|
public async getNullifierMembershipWitness(
|
|
1131
1484
|
referenceBlock: BlockParameter,
|
|
1132
1485
|
nullifier: Fr,
|
|
@@ -1197,49 +1550,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1197
1550
|
return preimage.leaf.value;
|
|
1198
1551
|
}
|
|
1199
1552
|
|
|
1200
|
-
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1201
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1202
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1203
|
-
if (block.equals(initialBlockHash)) {
|
|
1204
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1205
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1206
|
-
}
|
|
1207
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1208
|
-
} else {
|
|
1209
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1210
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1211
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1212
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1213
|
-
}
|
|
1214
|
-
return this.blockSource.getBlockHeader(block);
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
/**
|
|
1219
|
-
* Get a block header specified by its archive root.
|
|
1220
|
-
* @param archive - The archive root being requested.
|
|
1221
|
-
* @returns The requested block header.
|
|
1222
|
-
*/
|
|
1223
|
-
public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
1224
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1228
|
-
return this.blockSource.getBlockData(number);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1232
|
-
return this.blockSource.getBlockDataByArchive(archive);
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
1553
|
/**
|
|
1236
1554
|
* Simulates the public part of a transaction with the current state.
|
|
1237
1555
|
* @param tx - The transaction to simulate.
|
|
1556
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
1557
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1238
1558
|
**/
|
|
1239
1559
|
@trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
|
|
1240
1560
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1241
1561
|
}))
|
|
1242
|
-
public async simulatePublicCalls(
|
|
1562
|
+
public async simulatePublicCalls(
|
|
1563
|
+
tx: Tx,
|
|
1564
|
+
skipFeeEnforcement = false,
|
|
1565
|
+
overrides?: SimulationOverrides,
|
|
1566
|
+
): Promise<PublicSimulationOutput> {
|
|
1243
1567
|
// Check total gas limit for simulation
|
|
1244
1568
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1245
1569
|
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
@@ -1255,7 +1579,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1255
1579
|
}
|
|
1256
1580
|
|
|
1257
1581
|
const txHash = tx.getTxHash();
|
|
1258
|
-
const
|
|
1582
|
+
const l2Tips = await this.blockSource.getL2Tips();
|
|
1583
|
+
const latestBlockNumber = l2Tips.proposed.number;
|
|
1259
1584
|
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1260
1585
|
|
|
1261
1586
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
@@ -1267,6 +1592,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1267
1592
|
coinbase,
|
|
1268
1593
|
feeRecipient,
|
|
1269
1594
|
);
|
|
1595
|
+
|
|
1270
1596
|
const publicProcessorFactory = new PublicProcessorFactory(
|
|
1271
1597
|
this.contractDataSource,
|
|
1272
1598
|
new DateProvider(),
|
|
@@ -1282,40 +1608,77 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1282
1608
|
|
|
1283
1609
|
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1284
1610
|
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1285
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1286
|
-
try {
|
|
1287
|
-
const config = PublicSimulatorConfig.from({
|
|
1288
|
-
skipFeeEnforcement,
|
|
1289
|
-
collectDebugLogs: true,
|
|
1290
|
-
collectHints: false,
|
|
1291
|
-
collectCallMetadata: true,
|
|
1292
|
-
collectStatistics: false,
|
|
1293
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1294
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1295
|
-
}),
|
|
1296
|
-
});
|
|
1297
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1298
|
-
|
|
1299
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1300
|
-
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1301
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1302
|
-
if (failedTxs.length) {
|
|
1303
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1304
|
-
throw failedTxs[0].error;
|
|
1305
|
-
}
|
|
1306
1611
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1612
|
+
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1613
|
+
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1614
|
+
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1615
|
+
// which means the next block would be the first block of the next checkpoint.
|
|
1616
|
+
const targetCheckpoint = CheckpointNumber(
|
|
1617
|
+
(l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1,
|
|
1618
|
+
);
|
|
1619
|
+
const nextCheckpointMessages: Fr[] | undefined =
|
|
1620
|
+
l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number
|
|
1621
|
+
? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch(err => {
|
|
1622
|
+
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1623
|
+
this.log.warn(
|
|
1624
|
+
`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`,
|
|
1625
|
+
);
|
|
1626
|
+
} else {
|
|
1627
|
+
this.log.error(
|
|
1628
|
+
`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`,
|
|
1629
|
+
err,
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
return undefined;
|
|
1633
|
+
})
|
|
1634
|
+
: undefined;
|
|
1635
|
+
|
|
1636
|
+
// Request a new fork of the world state at the latest block number, and apply any overrides and next checkpoint messages to it before simulation
|
|
1637
|
+
await using merkleTreeFork = await this.worldStateSynchronizer.fork(latestBlockNumber);
|
|
1638
|
+
|
|
1639
|
+
if (nextCheckpointMessages !== undefined) {
|
|
1640
|
+
this.log.debug(
|
|
1641
|
+
`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`,
|
|
1642
|
+
{ checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1 },
|
|
1315
1643
|
);
|
|
1316
|
-
|
|
1317
|
-
|
|
1644
|
+
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1645
|
+
}
|
|
1646
|
+
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
1647
|
+
|
|
1648
|
+
const config = PublicSimulatorConfig.from({
|
|
1649
|
+
skipFeeEnforcement,
|
|
1650
|
+
collectDebugLogs: true,
|
|
1651
|
+
collectHints: false,
|
|
1652
|
+
collectCallMetadata: true,
|
|
1653
|
+
collectStatistics: false,
|
|
1654
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1655
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1656
|
+
}),
|
|
1657
|
+
});
|
|
1658
|
+
|
|
1659
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1660
|
+
if (overrides?.contracts) {
|
|
1661
|
+
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance }) => instance));
|
|
1318
1662
|
}
|
|
1663
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
1664
|
+
|
|
1665
|
+
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1666
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1667
|
+
// REFACTOR: Consider returning the error rather than throwing
|
|
1668
|
+
if (failedTxs.length) {
|
|
1669
|
+
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1670
|
+
throw failedTxs[0].error;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
const [processedTx] = processedTxs;
|
|
1674
|
+
return new PublicSimulationOutput(
|
|
1675
|
+
processedTx.revertReason,
|
|
1676
|
+
processedTx.globalVariables,
|
|
1677
|
+
processedTx.txEffect,
|
|
1678
|
+
returns,
|
|
1679
|
+
processedTx.gasUsed,
|
|
1680
|
+
debugLogs,
|
|
1681
|
+
);
|
|
1319
1682
|
}
|
|
1320
1683
|
|
|
1321
1684
|
public async isValidTx(
|
|
@@ -1323,7 +1686,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1323
1686
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1324
1687
|
): Promise<TxValidationResult> {
|
|
1325
1688
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1326
|
-
const verifier = isSimulation ? undefined : this.
|
|
1689
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1327
1690
|
|
|
1328
1691
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1329
1692
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
@@ -1363,7 +1726,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1363
1726
|
|
|
1364
1727
|
public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
|
|
1365
1728
|
const newConfig = { ...this.config, ...config };
|
|
1366
|
-
|
|
1729
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
1730
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
1731
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
1732
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
1733
|
+
// pauseSequencer() still considers it paused.
|
|
1734
|
+
const sequencerUpdate = { ...config };
|
|
1735
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
1736
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
1737
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
1738
|
+
}
|
|
1739
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
1740
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
1367
1741
|
this.slasherClient?.updateConfig(config);
|
|
1368
1742
|
this.validatorsSentinel?.updateConfig(config);
|
|
1369
1743
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1372,7 +1746,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1372
1746
|
archiver.updateConfig(config);
|
|
1373
1747
|
}
|
|
1374
1748
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1375
|
-
|
|
1749
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1750
|
+
if (newConfig.realProofs) {
|
|
1751
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1752
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1753
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1754
|
+
} else {
|
|
1755
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1756
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1757
|
+
}
|
|
1376
1758
|
}
|
|
1377
1759
|
|
|
1378
1760
|
this.config = newConfig;
|
|
@@ -1383,7 +1765,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1383
1765
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1384
1766
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1385
1767
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1386
|
-
multiCallEntrypoint:
|
|
1768
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
1387
1769
|
});
|
|
1388
1770
|
}
|
|
1389
1771
|
|
|
@@ -1447,7 +1829,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1447
1829
|
return Promise.resolve();
|
|
1448
1830
|
}
|
|
1449
1831
|
|
|
1450
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
1832
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1451
1833
|
const archiver = this.blockSource as Archiver;
|
|
1452
1834
|
if (!('rollbackTo' in archiver)) {
|
|
1453
1835
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1477,9 +1859,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1477
1859
|
this.log.error(`Error during rollback`, err);
|
|
1478
1860
|
throw err;
|
|
1479
1861
|
} finally {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1862
|
+
if (resumeSync) {
|
|
1863
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1864
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1865
|
+
archiver.resume();
|
|
1866
|
+
} else {
|
|
1867
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1868
|
+
}
|
|
1483
1869
|
}
|
|
1484
1870
|
}
|
|
1485
1871
|
|
|
@@ -1496,11 +1882,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1496
1882
|
return Promise.resolve();
|
|
1497
1883
|
}
|
|
1498
1884
|
|
|
1499
|
-
public
|
|
1500
|
-
if (
|
|
1501
|
-
|
|
1885
|
+
public pauseSequencer(): Promise<void> {
|
|
1886
|
+
if (this.automineSequencer) {
|
|
1887
|
+
this.automineSequencer.pause();
|
|
1888
|
+
return Promise.resolve();
|
|
1502
1889
|
}
|
|
1503
|
-
|
|
1890
|
+
if (this.sequencer) {
|
|
1891
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
1892
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
1893
|
+
this.sequencer.updateConfig({ minTxsPerBlock: Number.MAX_SAFE_INTEGER });
|
|
1894
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
1895
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock,
|
|
1896
|
+
});
|
|
1897
|
+
}
|
|
1898
|
+
return Promise.resolve();
|
|
1899
|
+
}
|
|
1900
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
public resumeSequencer(): Promise<void> {
|
|
1904
|
+
if (this.automineSequencer) {
|
|
1905
|
+
this.automineSequencer.resume();
|
|
1906
|
+
return Promise.resolve();
|
|
1907
|
+
}
|
|
1908
|
+
if (this.sequencer) {
|
|
1909
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
1910
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
1911
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
1912
|
+
this.sequencer.updateConfig({ minTxsPerBlock: restored });
|
|
1913
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, { minTxsPerBlock: restored });
|
|
1914
|
+
}
|
|
1915
|
+
return Promise.resolve();
|
|
1916
|
+
}
|
|
1917
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1504
1918
|
}
|
|
1505
1919
|
|
|
1506
1920
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
@@ -1508,7 +1922,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1508
1922
|
throw new Error(`Slasher client not enabled`);
|
|
1509
1923
|
}
|
|
1510
1924
|
if (round === 'all') {
|
|
1511
|
-
return this.slasherClient.
|
|
1925
|
+
return this.slasherClient.getOffenses();
|
|
1512
1926
|
} else {
|
|
1513
1927
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1514
1928
|
}
|
|
@@ -1603,6 +2017,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1603
2017
|
}
|
|
1604
2018
|
|
|
1605
2019
|
public async mineBlock(): Promise<void> {
|
|
2020
|
+
if (this.automineSequencer) {
|
|
2021
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
1606
2024
|
if (!this.sequencer) {
|
|
1607
2025
|
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1608
2026
|
}
|
|
@@ -1636,67 +2054,58 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1636
2054
|
}
|
|
1637
2055
|
}
|
|
1638
2056
|
|
|
1639
|
-
#getInitialHeaderHash(): Promise<BlockHash> {
|
|
1640
|
-
if (!this.initialHeaderHashPromise) {
|
|
1641
|
-
this.initialHeaderHashPromise = this.worldStateSynchronizer.getCommitted().getInitialHeader().hash();
|
|
1642
|
-
}
|
|
1643
|
-
return this.initialHeaderHashPromise;
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
2057
|
/**
|
|
1647
2058
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1648
2059
|
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1649
2060
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1650
2061
|
*/
|
|
1651
2062
|
protected async getWorldState(block: BlockParameter) {
|
|
2063
|
+
const query = this.normalizeBlockParameter(block);
|
|
2064
|
+
|
|
2065
|
+
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
2066
|
+
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
2067
|
+
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
2068
|
+
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
2069
|
+
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
2070
|
+
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
2071
|
+
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
2072
|
+
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
2073
|
+
|
|
1652
2074
|
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1653
2075
|
try {
|
|
1654
2076
|
// Attempt to sync the world state if necessary
|
|
1655
|
-
blockSyncedTo = await this.#syncWorldState();
|
|
2077
|
+
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
1656
2078
|
} catch (err) {
|
|
1657
2079
|
this.log.error(`Error getting world state: ${err}`);
|
|
1658
2080
|
}
|
|
1659
2081
|
|
|
1660
|
-
if (
|
|
1661
|
-
this.log.debug(`Using committed db for block
|
|
2082
|
+
if ('tag' in query && query.tag === 'proposed') {
|
|
2083
|
+
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
1662
2084
|
return this.worldStateSynchronizer.getCommitted();
|
|
1663
2085
|
}
|
|
1664
2086
|
|
|
1665
|
-
|
|
1666
|
-
let blockNumber: BlockNumber;
|
|
1667
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1668
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1669
|
-
if (block.equals(initialBlockHash)) {
|
|
1670
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1671
|
-
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1672
|
-
}
|
|
1673
|
-
|
|
1674
|
-
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1675
|
-
if (!header) {
|
|
1676
|
-
throw new Error(
|
|
1677
|
-
`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.`,
|
|
1678
|
-
);
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
blockNumber = header.getBlockNumber();
|
|
1682
|
-
} else {
|
|
1683
|
-
blockNumber = block as BlockNumber;
|
|
1684
|
-
}
|
|
2087
|
+
const blockNumber = anchorBlockNumber ?? (await this.resolveBlockNumber(query));
|
|
1685
2088
|
|
|
1686
2089
|
// Check it's within world state sync range
|
|
1687
2090
|
if (blockNumber > blockSyncedTo) {
|
|
1688
|
-
throw new Error(
|
|
2091
|
+
throw new Error(
|
|
2092
|
+
`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`,
|
|
2093
|
+
);
|
|
1689
2094
|
}
|
|
1690
2095
|
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1691
2096
|
|
|
1692
2097
|
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1693
2098
|
|
|
1694
|
-
// Double-check world-state synced to the same block hash as was requested
|
|
1695
|
-
|
|
2099
|
+
// Double-check world-state synced to the same block hash as was requested.
|
|
2100
|
+
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2101
|
+
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2102
|
+
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2103
|
+
// the archiver when it resolves the hash query to block number 0.
|
|
2104
|
+
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
1696
2105
|
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1697
|
-
if (!blockHash || !
|
|
2106
|
+
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
1698
2107
|
throw new Error(
|
|
1699
|
-
`Block hash ${
|
|
2108
|
+
`Block hash ${requestedHash.toString()} not found in world state at block number ${blockNumber} (world state has ${blockHash?.toString() ?? 'no hash'} at that index, genesis header hash is ${this.blockSource.getGenesisBlockHash().toString()}). If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1700
2109
|
);
|
|
1701
2110
|
}
|
|
1702
2111
|
}
|
|
@@ -1704,31 +2113,33 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1704
2113
|
return snapshot;
|
|
1705
2114
|
}
|
|
1706
2115
|
|
|
1707
|
-
/** Resolves
|
|
2116
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */
|
|
1708
2117
|
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
2118
|
+
const query = this.normalizeBlockParameter(block);
|
|
2119
|
+
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
2120
|
+
if (blockNumber === undefined) {
|
|
2121
|
+
if ('hash' in query) {
|
|
2122
|
+
throw new Error(
|
|
2123
|
+
`Block hash ${query.hash.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
2124
|
+
);
|
|
1716
2125
|
}
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
2126
|
+
if ('archive' in query) {
|
|
2127
|
+
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
1720
2128
|
}
|
|
1721
|
-
|
|
2129
|
+
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
1722
2130
|
}
|
|
1723
|
-
return
|
|
2131
|
+
return blockNumber;
|
|
1724
2132
|
}
|
|
1725
2133
|
|
|
1726
2134
|
/**
|
|
1727
|
-
* Ensure
|
|
2135
|
+
* Ensure the world state is synced.
|
|
2136
|
+
* @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
|
|
2137
|
+
* @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
|
|
2138
|
+
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
1728
2139
|
* @returns A promise that fulfils once the world state is synced
|
|
1729
2140
|
*/
|
|
1730
|
-
async #syncWorldState(): Promise<BlockNumber> {
|
|
1731
|
-
const
|
|
1732
|
-
return await this.worldStateSynchronizer.syncImmediate(
|
|
2141
|
+
async #syncWorldState(targetBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber> {
|
|
2142
|
+
const target = targetBlockNumber ?? (await this.blockSource.getBlockNumber());
|
|
2143
|
+
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1733
2144
|
}
|
|
1734
2145
|
}
|