@aztec/aztec-node 0.0.1-fake-ceab37513c → 0.0.1-private.5d121bfd
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 +17 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +22 -8
- package/dest/aztec-node/node_metrics.d.ts +5 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +20 -6
- package/dest/aztec-node/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 +107 -204
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +1569 -505
- package/dest/bin/index.d.ts +1 -1
- package/dest/index.d.ts +1 -1
- 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 +5 -5
- package/dest/sentinel/index.d.ts +1 -1
- package/dest/sentinel/sentinel.d.ts +151 -25
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +290 -110
- package/dest/sentinel/store.d.ts +11 -10
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +36 -23
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +31 -28
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +45 -21
- package/src/aztec-node/node_metrics.ts +23 -6
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/server.ts +1319 -643
- package/src/sentinel/README.md +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +9 -11
- package/src/sentinel/sentinel.ts +375 -136
- package/src/sentinel/store.ts +43 -34
- package/src/test/index.ts +2 -2
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,60 +1,79 @@
|
|
|
1
|
-
import { Archiver, createArchiver } from '@aztec/archiver';
|
|
2
|
-
import { BBCircuitVerifier,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type L1_TO_L2_MSG_TREE_HEIGHT,
|
|
8
|
-
type NOTE_HASH_TREE_HEIGHT,
|
|
9
|
-
type NULLIFIER_TREE_HEIGHT,
|
|
10
|
-
type PUBLIC_DATA_TREE_HEIGHT,
|
|
11
|
-
} from '@aztec/constants';
|
|
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';
|
|
4
|
+
import { type BlobClientInterface, createBlobClientWithFileStores } from '@aztec/blob-client/client';
|
|
5
|
+
import { Blob } from '@aztec/blob-lib';
|
|
6
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
12
7
|
import { EpochCache, type EpochCacheInterface } from '@aztec/epoch-cache';
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} from '@aztec/
|
|
20
|
-
import {
|
|
8
|
+
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
9
|
+
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
10
|
+
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
11
|
+
import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
+
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
13
|
+
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
14
|
+
import { chunkBy, compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
15
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
21
16
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
22
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
23
17
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
24
18
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
25
|
-
import {
|
|
19
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
26
20
|
import { count } from '@aztec/foundation/string';
|
|
27
21
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
28
22
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
|
-
import {
|
|
23
|
+
import { isErrorClass } from '@aztec/foundation/types';
|
|
24
|
+
import { type KeyStore, KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
30
25
|
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
26
|
+
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
27
|
+
import {
|
|
28
|
+
type P2P,
|
|
29
|
+
type P2PClientDeps,
|
|
30
|
+
createP2PClient,
|
|
31
|
+
createTxValidatorForAcceptingTxsOverRPC,
|
|
32
|
+
getDefaultAllowedSetupFunctions,
|
|
33
|
+
} from '@aztec/p2p';
|
|
33
34
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
35
|
+
import { type ProverNode, type ProverNodeDeps, createProverNode } from '@aztec/prover-node';
|
|
36
|
+
import { createKeyStoreForProver } from '@aztec/prover-node/config';
|
|
34
37
|
import {
|
|
35
|
-
|
|
38
|
+
AutomineSequencer,
|
|
39
|
+
FeeProviderImpl,
|
|
36
40
|
GlobalVariableBuilder,
|
|
37
41
|
SequencerClient,
|
|
38
42
|
type SequencerPublisher,
|
|
39
|
-
|
|
43
|
+
createAutomineSequencer,
|
|
40
44
|
} from '@aztec/sequencer-client';
|
|
41
|
-
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
45
|
+
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
42
46
|
import {
|
|
43
47
|
AttestationsBlockWatcher,
|
|
44
|
-
|
|
48
|
+
AttestedInvalidProposalWatcher,
|
|
49
|
+
BroadcastedInvalidCheckpointProposalWatcher,
|
|
50
|
+
CheckpointEquivocationWatcher,
|
|
51
|
+
DataWithholdingWatcher,
|
|
45
52
|
type SlasherClientInterface,
|
|
46
53
|
type Watcher,
|
|
47
54
|
createSlasher,
|
|
48
55
|
} from '@aztec/slasher';
|
|
56
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
57
|
+
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
49
58
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
50
59
|
import {
|
|
51
|
-
type
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
60
|
+
type BlockData,
|
|
61
|
+
BlockHash,
|
|
62
|
+
type BlockParameter,
|
|
63
|
+
BlockTag,
|
|
64
|
+
type CheckpointsQuery,
|
|
65
|
+
type CommitteeAttestation,
|
|
66
|
+
type DataInBlock,
|
|
55
67
|
type L2BlockSource,
|
|
56
|
-
type
|
|
68
|
+
type NormalizedBlockParameter,
|
|
69
|
+
inspectBlockParameter,
|
|
57
70
|
} from '@aztec/stdlib/block';
|
|
71
|
+
import {
|
|
72
|
+
type CheckpointData,
|
|
73
|
+
CheckpointReexecutionTracker,
|
|
74
|
+
L1PublishedData,
|
|
75
|
+
type PublishedCheckpoint,
|
|
76
|
+
} from '@aztec/stdlib/checkpoint';
|
|
58
77
|
import type {
|
|
59
78
|
ContractClassPublic,
|
|
60
79
|
ContractDataSource,
|
|
@@ -62,17 +81,25 @@ import type {
|
|
|
62
81
|
NodeInfo,
|
|
63
82
|
ProtocolContractAddresses,
|
|
64
83
|
} from '@aztec/stdlib/contract';
|
|
65
|
-
import
|
|
84
|
+
import { GasFees, type ManaUsageEstimate } from '@aztec/stdlib/gas';
|
|
66
85
|
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
import type {
|
|
87
|
+
AztecNode,
|
|
88
|
+
AztecNodeAdmin,
|
|
89
|
+
AztecNodeAdminConfig,
|
|
90
|
+
AztecNodeDebug,
|
|
91
|
+
BlockIncludeOptions,
|
|
92
|
+
BlockResponse,
|
|
93
|
+
BlocksIncludeOptions,
|
|
94
|
+
ChainTip,
|
|
95
|
+
ChainTips,
|
|
96
|
+
CheckpointIncludeOptions,
|
|
97
|
+
CheckpointParameter,
|
|
98
|
+
CheckpointResponse,
|
|
74
99
|
} from '@aztec/stdlib/interfaces/client';
|
|
100
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
75
101
|
import {
|
|
102
|
+
type AllowedElement,
|
|
76
103
|
type ClientProtocolCircuitVerifier,
|
|
77
104
|
type L2LogsSource,
|
|
78
105
|
type Service,
|
|
@@ -80,17 +107,19 @@ import {
|
|
|
80
107
|
type WorldStateSynchronizer,
|
|
81
108
|
tryStop,
|
|
82
109
|
} from '@aztec/stdlib/interfaces/server';
|
|
83
|
-
import type {
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
import type { Offense
|
|
87
|
-
import
|
|
110
|
+
import type { DebugLogStore, LogResult, PrivateLogsQuery, PublicLogsQuery } from '@aztec/stdlib/logs';
|
|
111
|
+
import { InMemoryDebugLogStore, NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
112
|
+
import { InboxLeaf, type L1ToL2MessageSource, appendL1ToL2MessagesToTree } from '@aztec/stdlib/messaging';
|
|
113
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
114
|
+
import { MIN_EXECUTION_TIME } from '@aztec/stdlib/timetable';
|
|
115
|
+
import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
88
116
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
89
117
|
import {
|
|
90
|
-
type
|
|
118
|
+
type FeeProvider,
|
|
91
119
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
92
120
|
type IndexedTxEffect,
|
|
93
121
|
PublicSimulationOutput,
|
|
122
|
+
type SimulationOverrides,
|
|
94
123
|
Tx,
|
|
95
124
|
type TxHash,
|
|
96
125
|
TxReceipt,
|
|
@@ -99,6 +128,7 @@ import {
|
|
|
99
128
|
} from '@aztec/stdlib/tx';
|
|
100
129
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
101
130
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
131
|
+
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
102
132
|
import {
|
|
103
133
|
Attributes,
|
|
104
134
|
type TelemetryClient,
|
|
@@ -108,31 +138,40 @@ import {
|
|
|
108
138
|
trackSpan,
|
|
109
139
|
} from '@aztec/telemetry-client';
|
|
110
140
|
import {
|
|
141
|
+
FullNodeCheckpointsBuilder as CheckpointsBuilder,
|
|
142
|
+
FullNodeCheckpointsBuilder,
|
|
111
143
|
NodeKeystoreAdapter,
|
|
112
144
|
ValidatorClient,
|
|
113
|
-
|
|
145
|
+
createProposalHandler,
|
|
114
146
|
createValidatorClient,
|
|
115
147
|
} from '@aztec/validator-client';
|
|
116
|
-
import {
|
|
148
|
+
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
149
|
+
import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
|
|
117
150
|
|
|
118
|
-
import { createPublicClient
|
|
151
|
+
import { createPublicClient } from 'viem';
|
|
119
152
|
|
|
120
153
|
import { createSentinel } from '../sentinel/factory.js';
|
|
121
154
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
155
|
+
import {
|
|
156
|
+
blockResponseFromBlockData,
|
|
157
|
+
blockResponseFromL2Block,
|
|
158
|
+
checkpointResponseFromCheckpointData,
|
|
159
|
+
checkpointResponseFromPublishedCheckpoint,
|
|
160
|
+
projectProposedToCheckpointResponse,
|
|
161
|
+
} from './block_response_helpers.js';
|
|
122
162
|
import { type AztecNodeConfig, createKeyStoreForValidator } from './config.js';
|
|
123
163
|
import { NodeMetrics } from './node_metrics.js';
|
|
164
|
+
import { applyPublicDataOverrides } from './public_data_overrides.js';
|
|
124
165
|
|
|
125
166
|
/**
|
|
126
167
|
* The aztec node.
|
|
127
168
|
*/
|
|
128
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
169
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
129
170
|
private metrics: NodeMetrics;
|
|
130
|
-
|
|
131
171
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
172
|
private isUploadingSnapshot = false;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
private txQueue: SerialQueue = new SerialQueue();
|
|
173
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
174
|
+
private sequencerPausedMinTxsPerBlock: number | undefined;
|
|
136
175
|
|
|
137
176
|
public readonly tracer: Tracer;
|
|
138
177
|
|
|
@@ -145,24 +184,43 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
145
184
|
protected readonly l1ToL2MessageSource: L1ToL2MessageSource,
|
|
146
185
|
protected readonly worldStateSynchronizer: WorldStateSynchronizer,
|
|
147
186
|
protected readonly sequencer: SequencerClient | undefined,
|
|
187
|
+
protected readonly proverNode: ProverNode | undefined,
|
|
148
188
|
protected readonly slasherClient: SlasherClientInterface | undefined,
|
|
149
189
|
protected readonly validatorsSentinel: Sentinel | undefined,
|
|
150
|
-
|
|
190
|
+
private readonly stopStartedWatchers: () => Promise<void>,
|
|
151
191
|
protected readonly l1ChainId: number,
|
|
152
192
|
protected readonly version: number,
|
|
153
193
|
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface,
|
|
194
|
+
protected readonly feeProvider: FeeProvider,
|
|
154
195
|
protected readonly epochCache: EpochCacheInterface,
|
|
155
196
|
protected readonly packageVersion: string,
|
|
156
|
-
private
|
|
197
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier,
|
|
198
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier,
|
|
157
199
|
private telemetry: TelemetryClient = getTelemetryClient(),
|
|
158
200
|
private log = createLogger('node'),
|
|
201
|
+
private blobClient?: BlobClientInterface,
|
|
202
|
+
private validatorClient?: ValidatorClient,
|
|
203
|
+
private keyStoreManager?: KeystoreManager,
|
|
204
|
+
private debugLogStore: DebugLogStore = new NullDebugLogStore(),
|
|
205
|
+
private readonly automineSequencer?: AutomineSequencer,
|
|
159
206
|
) {
|
|
160
207
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
161
208
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
162
|
-
this.txQueue.start();
|
|
163
209
|
|
|
164
210
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
165
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
211
|
+
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
212
|
+
|
|
213
|
+
// A defensive check that protects us against introducing a bug in the complex `createAndSync` function. We must
|
|
214
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
215
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
216
|
+
if (debugLogStore.isEnabled && config.realProofs) {
|
|
217
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
222
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
223
|
+
return this.rpcProofVerifier;
|
|
166
224
|
}
|
|
167
225
|
|
|
168
226
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -170,8 +228,238 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
170
228
|
return status.syncSummary;
|
|
171
229
|
}
|
|
172
230
|
|
|
173
|
-
public
|
|
174
|
-
|
|
231
|
+
public async getChainTips(): Promise<ChainTips> {
|
|
232
|
+
const { proposed, checkpointed, proven, finalized } = await this.blockSource.getL2Tips();
|
|
233
|
+
return { proposed, checkpointed, proven, finalized };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public getCheckpointsData(query: CheckpointsQuery) {
|
|
237
|
+
return this.blockSource.getCheckpointsData(query);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public async getBlockNumber(tip?: ChainTip): Promise<BlockNumber> {
|
|
241
|
+
if (tip === undefined || tip === 'proposed') {
|
|
242
|
+
return this.blockSource.getBlockNumber();
|
|
243
|
+
}
|
|
244
|
+
return (await this.blockSource.getBlockNumber({ tag: tip })) ?? BlockNumber.ZERO;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public async getCheckpointNumber(tip?: ChainTip): Promise<CheckpointNumber> {
|
|
248
|
+
const tips = await this.blockSource.getL2Tips();
|
|
249
|
+
switch (tip) {
|
|
250
|
+
case undefined:
|
|
251
|
+
case 'checkpointed':
|
|
252
|
+
return tips.checkpointed.checkpoint.number;
|
|
253
|
+
case 'proposed':
|
|
254
|
+
return tips.proposedCheckpoint.checkpoint.number;
|
|
255
|
+
case 'proven':
|
|
256
|
+
return tips.proven.checkpoint.number;
|
|
257
|
+
case 'finalized':
|
|
258
|
+
return tips.finalized.checkpoint.number;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private isChainTip(value: unknown): value is ChainTip {
|
|
263
|
+
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
268
|
+
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
269
|
+
* lookups are deferred to the underlying block source.
|
|
270
|
+
*/
|
|
271
|
+
private normalizeBlockParameter(param: BlockParameter): NormalizedBlockParameter {
|
|
272
|
+
if (BlockHash.isBlockHash(param)) {
|
|
273
|
+
return { hash: param };
|
|
274
|
+
}
|
|
275
|
+
if (typeof param === 'number') {
|
|
276
|
+
return { number: param as BlockNumber };
|
|
277
|
+
}
|
|
278
|
+
if (typeof param === 'string') {
|
|
279
|
+
if (this.isBlockTag(param)) {
|
|
280
|
+
return { tag: param === 'latest' ? 'proposed' : param };
|
|
281
|
+
}
|
|
282
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
283
|
+
}
|
|
284
|
+
if (typeof param === 'object' && param !== null) {
|
|
285
|
+
if ('number' in param) {
|
|
286
|
+
return { number: param.number };
|
|
287
|
+
}
|
|
288
|
+
if ('hash' in param) {
|
|
289
|
+
return { hash: param.hash };
|
|
290
|
+
}
|
|
291
|
+
if ('archive' in param) {
|
|
292
|
+
return { archive: param.archive };
|
|
293
|
+
}
|
|
294
|
+
if ('tag' in param) {
|
|
295
|
+
if (this.isBlockTag(param.tag)) {
|
|
296
|
+
return { tag: param.tag };
|
|
297
|
+
}
|
|
298
|
+
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private isBlockTag(value: string): value is BlockTag {
|
|
305
|
+
return BlockTag.includes(value as BlockTag);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
310
|
+
*
|
|
311
|
+
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
312
|
+
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
313
|
+
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
314
|
+
* confirmed→proposed lookup against either store.
|
|
315
|
+
*/
|
|
316
|
+
private async resolveCheckpointParameter(
|
|
317
|
+
param: CheckpointParameter,
|
|
318
|
+
): Promise<{ number: CheckpointNumber } | { slot: SlotNumber }> {
|
|
319
|
+
if (typeof param === 'number') {
|
|
320
|
+
return { number: param as CheckpointNumber };
|
|
321
|
+
}
|
|
322
|
+
if (this.isChainTip(param)) {
|
|
323
|
+
const tips = await this.blockSource.getL2Tips();
|
|
324
|
+
switch (param) {
|
|
325
|
+
case 'proposed':
|
|
326
|
+
return { number: tips.proposedCheckpoint.checkpoint.number };
|
|
327
|
+
case 'checkpointed':
|
|
328
|
+
return { number: tips.checkpointed.checkpoint.number };
|
|
329
|
+
case 'proven':
|
|
330
|
+
return { number: tips.proven.checkpoint.number };
|
|
331
|
+
case 'finalized':
|
|
332
|
+
return { number: tips.finalized.checkpoint.number };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (typeof param === 'object' && param !== null) {
|
|
336
|
+
if ('number' in param) {
|
|
337
|
+
return { number: param.number };
|
|
338
|
+
}
|
|
339
|
+
if ('slot' in param) {
|
|
340
|
+
return { slot: param.slot };
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */
|
|
347
|
+
async #getCheckpointContext(
|
|
348
|
+
checkpointNumber: CheckpointNumber,
|
|
349
|
+
): Promise<{ l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined> {
|
|
350
|
+
const checkpoint = await this.blockSource.getCheckpointData({ number: checkpointNumber });
|
|
351
|
+
if (!checkpoint) {
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
354
|
+
return { l1: checkpoint.l1, attestations: checkpoint.attestations };
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public async getBlock<Opts extends BlockIncludeOptions = {}>(
|
|
358
|
+
param: BlockParameter,
|
|
359
|
+
options: Opts = {} as Opts,
|
|
360
|
+
): Promise<BlockResponse<Opts> | undefined> {
|
|
361
|
+
const query = this.normalizeBlockParameter(param);
|
|
362
|
+
const wantTxs = !!options.includeTransactions;
|
|
363
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
364
|
+
|
|
365
|
+
if (wantTxs) {
|
|
366
|
+
const block = await this.blockSource.getBlock(query);
|
|
367
|
+
if (!block) {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
371
|
+
return (await blockResponseFromL2Block(block, options, ctx)) as BlockResponse<Opts>;
|
|
372
|
+
}
|
|
373
|
+
const data = await this.blockSource.getBlockData(query);
|
|
374
|
+
if (!data) {
|
|
375
|
+
return undefined;
|
|
376
|
+
}
|
|
377
|
+
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
378
|
+
return blockResponseFromBlockData(data, options, ctx) as BlockResponse<Opts>;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
|
|
382
|
+
const query = this.normalizeBlockParameter(param);
|
|
383
|
+
return this.blockSource.getBlockData(query);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
public async getBlocks<Opts extends BlocksIncludeOptions = {}>(
|
|
387
|
+
from: BlockNumber,
|
|
388
|
+
limit: number,
|
|
389
|
+
options: Opts = {} as Opts,
|
|
390
|
+
): Promise<BlockResponse<Opts>[]> {
|
|
391
|
+
const wantTxs = !!options.includeTransactions;
|
|
392
|
+
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
393
|
+
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
394
|
+
if (wantTxs) {
|
|
395
|
+
const blocks = await this.blockSource.getBlocks({ from, limit, onlyCheckpointed });
|
|
396
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
397
|
+
return (await Promise.all(
|
|
398
|
+
blocks.map(block => blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))),
|
|
399
|
+
)) as BlockResponse<Opts>[];
|
|
400
|
+
}
|
|
401
|
+
const dataItems = await this.blockSource.getBlocksData({ from, limit, onlyCheckpointed });
|
|
402
|
+
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
403
|
+
return (await Promise.all(
|
|
404
|
+
dataItems.map(data => blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))),
|
|
405
|
+
)) as BlockResponse<Opts>[];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Fetches checkpoint context for a set of blocks, deduplicating shared checkpoints. */
|
|
409
|
+
async #getCheckpointContextsForBlocks(
|
|
410
|
+
blocks: { checkpointNumber: CheckpointNumber }[],
|
|
411
|
+
): Promise<Map<CheckpointNumber, { l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined>> {
|
|
412
|
+
const unique = Array.from(new Set(blocks.map(b => b.checkpointNumber)));
|
|
413
|
+
const entries = await Promise.all(unique.map(async n => [n, await this.#getCheckpointContext(n)] as const));
|
|
414
|
+
return new Map(entries);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
public async getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
|
|
418
|
+
param: CheckpointParameter,
|
|
419
|
+
options: Opts = {} as Opts,
|
|
420
|
+
): Promise<CheckpointResponse<Opts> | undefined> {
|
|
421
|
+
const query = await this.resolveCheckpointParameter(param);
|
|
422
|
+
|
|
423
|
+
// Try the confirmed store first.
|
|
424
|
+
const confirmed = options.includeBlocks
|
|
425
|
+
? await this.blockSource.getCheckpoint(query)
|
|
426
|
+
: await this.blockSource.getCheckpointData(query);
|
|
427
|
+
if (confirmed) {
|
|
428
|
+
return (await (options.includeBlocks
|
|
429
|
+
? checkpointResponseFromPublishedCheckpoint(confirmed as PublishedCheckpoint, options)
|
|
430
|
+
: checkpointResponseFromCheckpointData(confirmed as CheckpointData, options))) as CheckpointResponse<Opts>;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Fall back to the proposed store.
|
|
434
|
+
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
435
|
+
if (proposed) {
|
|
436
|
+
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
437
|
+
throw new BadRequestError(
|
|
438
|
+
`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
const blocks = options.includeBlocks
|
|
442
|
+
? await this.blockSource.getBlocks({ from: proposed.startBlock, limit: proposed.blockCount })
|
|
443
|
+
: undefined;
|
|
444
|
+
return (await projectProposedToCheckpointResponse(proposed, options, blocks)) as CheckpointResponse<Opts>;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
public async getCheckpoints<Opts extends CheckpointIncludeOptions = {}>(
|
|
451
|
+
from: CheckpointNumber,
|
|
452
|
+
limit: number,
|
|
453
|
+
options: Opts = {} as Opts,
|
|
454
|
+
): Promise<CheckpointResponse<Opts>[]> {
|
|
455
|
+
if (options.includeBlocks) {
|
|
456
|
+
const checkpoints = await this.blockSource.getCheckpoints({ from, limit });
|
|
457
|
+
return (await Promise.all(
|
|
458
|
+
checkpoints.map(cp => checkpointResponseFromPublishedCheckpoint(cp, options)),
|
|
459
|
+
)) as CheckpointResponse<Opts>[];
|
|
460
|
+
}
|
|
461
|
+
const datas = await this.blockSource.getCheckpointsData({ from, limit });
|
|
462
|
+
return datas.map(d => checkpointResponseFromCheckpointData(d, options)) as CheckpointResponse<Opts>[];
|
|
175
463
|
}
|
|
176
464
|
|
|
177
465
|
/**
|
|
@@ -186,33 +474,46 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
186
474
|
logger?: Logger;
|
|
187
475
|
publisher?: SequencerPublisher;
|
|
188
476
|
dateProvider?: DateProvider;
|
|
189
|
-
|
|
190
|
-
|
|
477
|
+
p2pClientDeps?: P2PClientDeps;
|
|
478
|
+
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
479
|
+
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
191
480
|
} = {},
|
|
192
481
|
options: {
|
|
193
|
-
|
|
482
|
+
genesis?: GenesisData;
|
|
194
483
|
dontStartSequencer?: boolean;
|
|
484
|
+
dontStartProverNode?: boolean;
|
|
195
485
|
} = {},
|
|
196
486
|
): Promise<AztecNodeService> {
|
|
197
487
|
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
198
488
|
const log = deps.logger ?? createLogger('node');
|
|
199
|
-
const packageVersion = getPackageVersion()
|
|
489
|
+
const packageVersion = getPackageVersion();
|
|
200
490
|
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
201
491
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
202
|
-
const blobSinkClient =
|
|
203
|
-
deps.blobSinkClient ?? createBlobSinkClient(config, { logger: createLogger('node:blob-sink:client') });
|
|
204
492
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
205
493
|
|
|
206
|
-
// Build a key store from file if given or from environment otherwise
|
|
494
|
+
// Build a key store from file if given or from environment otherwise.
|
|
495
|
+
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
207
496
|
let keyStoreManager: KeystoreManager | undefined;
|
|
208
497
|
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
209
498
|
if (keyStoreProvided) {
|
|
210
499
|
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
211
500
|
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
212
501
|
} else {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
502
|
+
const rawKeyStores: KeyStore[] = [];
|
|
503
|
+
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
504
|
+
if (validatorKeyStore) {
|
|
505
|
+
rawKeyStores.push(validatorKeyStore);
|
|
506
|
+
}
|
|
507
|
+
if (config.enableProverNode) {
|
|
508
|
+
const proverKeyStore = createKeyStoreForProver(config);
|
|
509
|
+
if (proverKeyStore) {
|
|
510
|
+
rawKeyStores.push(proverKeyStore);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (rawKeyStores.length > 0) {
|
|
514
|
+
keyStoreManager = new KeystoreManager(
|
|
515
|
+
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
516
|
+
);
|
|
216
517
|
}
|
|
217
518
|
}
|
|
218
519
|
|
|
@@ -223,12 +524,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
223
524
|
if (keyStoreManager === undefined) {
|
|
224
525
|
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
225
526
|
}
|
|
226
|
-
if (!keyStoreProvided) {
|
|
227
|
-
log.warn(
|
|
228
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
229
|
-
);
|
|
527
|
+
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
528
|
+
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
230
529
|
}
|
|
231
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager);
|
|
530
|
+
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
232
531
|
}
|
|
233
532
|
|
|
234
533
|
// validate that the actual chain id matches that specified in configuration
|
|
@@ -240,24 +539,24 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
240
539
|
|
|
241
540
|
const publicClient = createPublicClient({
|
|
242
541
|
chain: ethereumChain.chainInfo,
|
|
243
|
-
transport:
|
|
542
|
+
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
244
543
|
pollingInterval: config.viemPollingIntervalMS,
|
|
245
544
|
});
|
|
246
545
|
|
|
247
546
|
const l1ContractsAddresses = await RegistryContract.collectAddresses(
|
|
248
547
|
publicClient,
|
|
249
|
-
config.
|
|
548
|
+
config.registryAddress,
|
|
250
549
|
config.rollupVersion ?? 'canonical',
|
|
251
550
|
);
|
|
252
551
|
|
|
253
|
-
|
|
254
|
-
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
552
|
+
Object.assign(config, l1ContractsAddresses);
|
|
255
553
|
|
|
256
|
-
const rollupContract = new RollupContract(publicClient, config.
|
|
257
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
554
|
+
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
555
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
258
556
|
rollupContract.getL1GenesisTime(),
|
|
259
557
|
rollupContract.getSlotDuration(),
|
|
260
558
|
rollupContract.getVersion(),
|
|
559
|
+
rollupContract.getManaLimit().then(Number),
|
|
261
560
|
] as const);
|
|
262
561
|
|
|
263
562
|
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
@@ -268,219 +567,447 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
268
567
|
);
|
|
269
568
|
}
|
|
270
569
|
|
|
570
|
+
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
571
|
+
|
|
271
572
|
// attempt snapshot sync if possible
|
|
272
573
|
await trySnapshotSync(config, log);
|
|
273
574
|
|
|
274
|
-
const epochCache = await EpochCache.create(config.
|
|
575
|
+
const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
|
|
275
576
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
577
|
+
// Track started resources so we can clean up on partial failure during node creation.
|
|
578
|
+
const started: { stop?(): Promise<void> | void }[] = [];
|
|
579
|
+
try {
|
|
580
|
+
// Default the orphan-prune grace window from the block build duration when unset, so the archiver
|
|
581
|
+
// waits roughly one build slot for a proposed checkpoint to arrive before pruning a block-only tip.
|
|
582
|
+
config.orphanProposedBlockPruneGraceSeconds ??=
|
|
583
|
+
config.blockDurationMs !== undefined ? Math.ceil(config.blockDurationMs / 1000) : MIN_EXECUTION_TIME;
|
|
584
|
+
|
|
585
|
+
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
586
|
+
const nativeWs = await createWorldState(config, options.genesis);
|
|
587
|
+
const initialHeader = nativeWs.getInitialHeader();
|
|
588
|
+
const initialBlockHash = await initialHeader.hash();
|
|
589
|
+
const archiver = await createArchiver(
|
|
590
|
+
config,
|
|
591
|
+
{ blobClient, epochCache, telemetry, dateProvider },
|
|
592
|
+
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
593
|
+
initialHeader,
|
|
594
|
+
initialBlockHash,
|
|
595
|
+
);
|
|
596
|
+
started.push(archiver);
|
|
597
|
+
|
|
598
|
+
// The synchronizer takes ownership of the native world-state from here
|
|
599
|
+
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
600
|
+
started.push(worldStateSynchronizer);
|
|
601
|
+
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
602
|
+
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
603
|
+
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
604
|
+
if (useRealVerifiers) {
|
|
605
|
+
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
606
|
+
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
607
|
+
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
608
|
+
} else {
|
|
609
|
+
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
610
|
+
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
611
|
+
}
|
|
612
|
+
started.push(peerProofVerifier, rpcProofVerifier);
|
|
281
613
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
archiver,
|
|
286
|
-
options.prefilledPublicData,
|
|
287
|
-
telemetry,
|
|
288
|
-
);
|
|
289
|
-
const circuitVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier();
|
|
290
|
-
if (!config.realProofs) {
|
|
291
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
292
|
-
}
|
|
293
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
294
|
-
|
|
295
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
296
|
-
const p2pClient = await createP2PClient(
|
|
297
|
-
P2PClientType.Full,
|
|
298
|
-
config,
|
|
299
|
-
archiver,
|
|
300
|
-
proofVerifier,
|
|
301
|
-
worldStateSynchronizer,
|
|
302
|
-
epochCache,
|
|
303
|
-
packageVersion,
|
|
304
|
-
dateProvider,
|
|
305
|
-
telemetry,
|
|
306
|
-
deps.p2pClientDeps,
|
|
307
|
-
);
|
|
614
|
+
let debugLogStore: DebugLogStore;
|
|
615
|
+
if (!config.realProofs) {
|
|
616
|
+
log.warn(`Aztec node is accepting fake proofs`);
|
|
308
617
|
|
|
309
|
-
|
|
310
|
-
|
|
618
|
+
debugLogStore = new InMemoryDebugLogStore();
|
|
619
|
+
log.info(
|
|
620
|
+
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
621
|
+
);
|
|
622
|
+
} else {
|
|
623
|
+
debugLogStore = new NullDebugLogStore();
|
|
624
|
+
}
|
|
311
625
|
|
|
312
|
-
|
|
626
|
+
const globalVariableBuilderConfig = {
|
|
627
|
+
rollupAddress: config.rollupAddress,
|
|
628
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
629
|
+
rollupVersion: BigInt(config.rollupVersion),
|
|
630
|
+
l1GenesisTime,
|
|
631
|
+
slotDuration: Number(slotDuration),
|
|
632
|
+
};
|
|
313
633
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
worldStateSynchronizer,
|
|
317
|
-
archiver,
|
|
318
|
-
dateProvider,
|
|
319
|
-
telemetry,
|
|
320
|
-
);
|
|
634
|
+
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
635
|
+
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
321
636
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
// Create validator client if required
|
|
326
|
-
const validatorClient = createValidatorClient(config, {
|
|
327
|
-
p2pClient,
|
|
328
|
-
telemetry,
|
|
329
|
-
dateProvider,
|
|
330
|
-
epochCache,
|
|
331
|
-
blockBuilder,
|
|
332
|
-
blockSource: archiver,
|
|
333
|
-
l1ToL2MessageSource: archiver,
|
|
334
|
-
keyStoreManager,
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
338
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
339
|
-
// like attestations or auths will fail.
|
|
340
|
-
if (validatorClient) {
|
|
341
|
-
watchers.push(validatorClient);
|
|
342
|
-
if (!options.dontStartSequencer) {
|
|
343
|
-
await validatorClient.registerHandlers();
|
|
637
|
+
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
638
|
+
if (proverOnly) {
|
|
639
|
+
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
344
640
|
}
|
|
345
|
-
}
|
|
346
641
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
642
|
+
// create the tx pool and the p2p client, which will need the l2 block source
|
|
643
|
+
const p2pClient = await createP2PClient(
|
|
644
|
+
config,
|
|
645
|
+
archiver,
|
|
646
|
+
peerProofVerifier,
|
|
647
|
+
worldStateSynchronizer,
|
|
353
648
|
epochCache,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
p2pClient,
|
|
649
|
+
feeProvider,
|
|
650
|
+
packageVersion,
|
|
357
651
|
dateProvider,
|
|
358
652
|
telemetry,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
653
|
+
deps.p2pClientDeps,
|
|
654
|
+
initialBlockHash,
|
|
655
|
+
);
|
|
656
|
+
started.push(p2pClient);
|
|
657
|
+
|
|
658
|
+
// We'll accumulate sentinel watchers here
|
|
659
|
+
const watchers: Watcher[] = [];
|
|
660
|
+
|
|
661
|
+
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
662
|
+
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
663
|
+
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
664
|
+
{
|
|
665
|
+
...config,
|
|
666
|
+
l1GenesisTime,
|
|
667
|
+
slotDuration: Number(slotDuration),
|
|
668
|
+
rollupManaLimit,
|
|
669
|
+
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
670
|
+
},
|
|
671
|
+
worldStateSynchronizer,
|
|
672
|
+
archiver,
|
|
673
|
+
dateProvider,
|
|
674
|
+
telemetry,
|
|
675
|
+
);
|
|
364
676
|
|
|
365
|
-
|
|
366
|
-
|
|
677
|
+
let validatorClient: ValidatorClient | undefined;
|
|
678
|
+
|
|
679
|
+
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
680
|
+
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
681
|
+
|
|
682
|
+
if (!config.disableValidator) {
|
|
683
|
+
// Create validator client if required
|
|
684
|
+
validatorClient = await createValidatorClient(config, {
|
|
685
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
686
|
+
worldState: worldStateSynchronizer,
|
|
687
|
+
p2pClient,
|
|
688
|
+
telemetry,
|
|
689
|
+
dateProvider,
|
|
690
|
+
epochCache,
|
|
691
|
+
blockSource: archiver,
|
|
692
|
+
l1ToL2MessageSource: archiver,
|
|
693
|
+
keyStoreManager,
|
|
694
|
+
blobClient,
|
|
695
|
+
reexecutionTracker,
|
|
696
|
+
slashingProtectionDb: deps.slashingProtectionDb,
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
700
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
701
|
+
// like attestations or auths will fail.
|
|
702
|
+
if (validatorClient) {
|
|
703
|
+
watchers.push(validatorClient);
|
|
704
|
+
|
|
705
|
+
const vc = validatorClient;
|
|
706
|
+
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
707
|
+
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
708
|
+
|
|
709
|
+
if (!options.dontStartSequencer) {
|
|
710
|
+
await validatorClient.registerHandlers();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
367
714
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
715
|
+
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
716
|
+
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
717
|
+
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
718
|
+
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
719
|
+
if (!validatorClient) {
|
|
720
|
+
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
721
|
+
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
722
|
+
createProposalHandler(config, {
|
|
723
|
+
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
724
|
+
worldState: worldStateSynchronizer,
|
|
725
|
+
epochCache,
|
|
726
|
+
blockSource: archiver,
|
|
727
|
+
l1ToL2MessageSource: archiver,
|
|
728
|
+
p2pClient,
|
|
729
|
+
blobClient,
|
|
730
|
+
dateProvider,
|
|
731
|
+
telemetry,
|
|
732
|
+
reexecutionTracker,
|
|
733
|
+
}).register(p2pClient, reexecute, archiver);
|
|
734
|
+
}
|
|
372
735
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
736
|
+
// Start world state and wait for it to sync to the archiver.
|
|
737
|
+
await worldStateSynchronizer.start();
|
|
738
|
+
|
|
739
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
740
|
+
await p2pClient.start();
|
|
741
|
+
|
|
742
|
+
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
743
|
+
let dataWithholdingWatcher: DataWithholdingWatcher | undefined;
|
|
744
|
+
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
745
|
+
let attestedInvalidProposalWatcher: AttestedInvalidProposalWatcher | undefined;
|
|
746
|
+
let broadcastedInvalidCheckpointProposalWatcher: BroadcastedInvalidCheckpointProposalWatcher | undefined;
|
|
747
|
+
let checkpointEquivocationWatcher: CheckpointEquivocationWatcher | undefined;
|
|
748
|
+
|
|
749
|
+
if (!proverOnly) {
|
|
750
|
+
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
751
|
+
if (validatorsSentinel) {
|
|
752
|
+
watchers.push(validatorsSentinel);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
dataWithholdingWatcher = new DataWithholdingWatcher(
|
|
756
|
+
epochCache,
|
|
757
|
+
archiver,
|
|
758
|
+
p2pClient.getTxProvider(),
|
|
759
|
+
p2pClient,
|
|
760
|
+
reexecutionTracker,
|
|
761
|
+
{ chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
|
|
762
|
+
config,
|
|
763
|
+
);
|
|
764
|
+
watchers.push(dataWithholdingWatcher);
|
|
385
765
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
766
|
+
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(
|
|
767
|
+
p2pClient,
|
|
768
|
+
archiver,
|
|
769
|
+
epochCache,
|
|
770
|
+
config,
|
|
771
|
+
);
|
|
772
|
+
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
773
|
+
|
|
774
|
+
if (validatorClient) {
|
|
775
|
+
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(
|
|
776
|
+
p2pClient,
|
|
777
|
+
validatorClient,
|
|
778
|
+
archiver,
|
|
779
|
+
epochCache,
|
|
780
|
+
config,
|
|
781
|
+
{ log: log.createChild('attested-invalid-proposal-watcher') },
|
|
782
|
+
);
|
|
783
|
+
watchers.push(attestedInvalidProposalWatcher);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
787
|
+
watchers.push(checkpointEquivocationWatcher);
|
|
788
|
+
|
|
789
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
790
|
+
watchers.push(attestationsBlockWatcher);
|
|
791
|
+
}
|
|
392
792
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
793
|
+
const watchersToStart = compactArray([
|
|
794
|
+
validatorsSentinel,
|
|
795
|
+
dataWithholdingWatcher,
|
|
796
|
+
attestationsBlockWatcher,
|
|
797
|
+
broadcastedInvalidCheckpointProposalWatcher,
|
|
798
|
+
attestedInvalidProposalWatcher,
|
|
799
|
+
checkpointEquivocationWatcher,
|
|
800
|
+
]);
|
|
801
|
+
const startedWatchers: Watcher[] = [];
|
|
802
|
+
const stopStartedWatchers = async () => {
|
|
803
|
+
for (const watcher of startedWatchers) {
|
|
804
|
+
await tryStop(watcher);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
404
807
|
|
|
405
|
-
|
|
808
|
+
// Start p2p-related services once the archiver has completed sync
|
|
809
|
+
void archiver
|
|
810
|
+
.waitForInitialSync()
|
|
811
|
+
.then(async () => {
|
|
812
|
+
for (const watcher of watchersToStart) {
|
|
813
|
+
await watcher.start();
|
|
814
|
+
startedWatchers.push(watcher);
|
|
815
|
+
}
|
|
816
|
+
log.info(`All p2p services started`);
|
|
817
|
+
})
|
|
818
|
+
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
819
|
+
started.push({ stop: stopStartedWatchers });
|
|
820
|
+
|
|
821
|
+
// Validator enabled, create/start relevant service
|
|
822
|
+
let sequencer: SequencerClient | undefined;
|
|
823
|
+
let automineSequencer: AutomineSequencer | undefined;
|
|
824
|
+
let slasherClient: SlasherClientInterface | undefined;
|
|
825
|
+
if (!config.disableValidator && validatorClient) {
|
|
826
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
827
|
+
// as they are executed when the node is selected as proposer.
|
|
828
|
+
const validatorAddresses = keyStoreManager
|
|
829
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
830
|
+
: [];
|
|
831
|
+
|
|
832
|
+
slasherClient = await createSlasher(
|
|
833
|
+
config,
|
|
834
|
+
pickL1ContractAddresses(config),
|
|
835
|
+
getPublicClient(config),
|
|
836
|
+
watchers,
|
|
837
|
+
dateProvider,
|
|
838
|
+
epochCache,
|
|
839
|
+
validatorAddresses,
|
|
840
|
+
undefined, // logger
|
|
841
|
+
);
|
|
842
|
+
await slasherClient.start();
|
|
843
|
+
started.push(slasherClient);
|
|
844
|
+
|
|
845
|
+
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
846
|
+
? await createForwarderL1TxUtilsFromSigners(
|
|
847
|
+
publicClient,
|
|
848
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
849
|
+
config.sequencerPublisherForwarderAddress,
|
|
850
|
+
{ ...config, scope: 'sequencer' },
|
|
851
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
852
|
+
)
|
|
853
|
+
: await createL1TxUtilsFromSigners(
|
|
854
|
+
publicClient,
|
|
855
|
+
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
856
|
+
{ ...config, scope: 'sequencer' },
|
|
857
|
+
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
861
|
+
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
862
|
+
let funderL1TxUtils: L1TxUtils | undefined;
|
|
863
|
+
if (fundingSigner) {
|
|
864
|
+
const [funder] = await createL1TxUtilsFromSigners(
|
|
865
|
+
publicClient,
|
|
866
|
+
[fundingSigner],
|
|
867
|
+
{ ...config, scope: 'sequencer' },
|
|
868
|
+
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
869
|
+
);
|
|
870
|
+
funderL1TxUtils = funder;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// Create and start the sequencer client
|
|
874
|
+
const checkpointsBuilder = new CheckpointsBuilder(
|
|
875
|
+
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
876
|
+
worldStateSynchronizer,
|
|
877
|
+
archiver,
|
|
878
|
+
dateProvider,
|
|
879
|
+
telemetry,
|
|
880
|
+
debugLogStore,
|
|
881
|
+
);
|
|
406
882
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
883
|
+
if (config.useAutomineSequencer) {
|
|
884
|
+
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
885
|
+
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
886
|
+
automineSequencer = await createAutomineSequencer({
|
|
887
|
+
config,
|
|
888
|
+
l1TxUtils,
|
|
889
|
+
funderL1TxUtils,
|
|
890
|
+
publicClient,
|
|
891
|
+
rollupContract,
|
|
892
|
+
epochCache,
|
|
893
|
+
blobClient,
|
|
894
|
+
telemetry,
|
|
895
|
+
dateProvider,
|
|
896
|
+
keyStoreManager: keyStoreManager!,
|
|
897
|
+
validatorClient,
|
|
898
|
+
checkpointsBuilder,
|
|
899
|
+
globalVariableBuilder,
|
|
900
|
+
worldStateSynchronizer,
|
|
901
|
+
archiver,
|
|
902
|
+
p2pClient,
|
|
903
|
+
l1Constants: {
|
|
904
|
+
l1GenesisTime,
|
|
905
|
+
slotDuration: Number(slotDuration),
|
|
906
|
+
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
907
|
+
rollupManaLimit,
|
|
908
|
+
},
|
|
909
|
+
log,
|
|
910
|
+
});
|
|
911
|
+
} else {
|
|
912
|
+
sequencer = await SequencerClient.new(config, {
|
|
913
|
+
...deps,
|
|
914
|
+
epochCache,
|
|
915
|
+
l1TxUtils,
|
|
916
|
+
funderL1TxUtils,
|
|
917
|
+
validatorClient,
|
|
918
|
+
p2pClient,
|
|
919
|
+
worldStateSynchronizer,
|
|
920
|
+
slasherClient,
|
|
921
|
+
checkpointsBuilder,
|
|
922
|
+
l2BlockSource: archiver,
|
|
923
|
+
l1ToL2MessageSource: archiver,
|
|
924
|
+
telemetry,
|
|
925
|
+
dateProvider,
|
|
926
|
+
blobClient,
|
|
927
|
+
nodeKeyStore: keyStoreManager!,
|
|
928
|
+
globalVariableBuilder,
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
}
|
|
410
932
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
933
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
934
|
+
await sequencer.start();
|
|
935
|
+
started.push(sequencer);
|
|
936
|
+
log.verbose(`Sequencer started`);
|
|
937
|
+
} else if (sequencer) {
|
|
938
|
+
log.warn(`Sequencer created but not started`);
|
|
939
|
+
}
|
|
417
940
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
validatorAddresses,
|
|
426
|
-
undefined, // logger
|
|
427
|
-
);
|
|
428
|
-
await slasherClient.start();
|
|
941
|
+
if (!options.dontStartSequencer && automineSequencer) {
|
|
942
|
+
await automineSequencer.start();
|
|
943
|
+
started.push({ stop: () => automineSequencer!.stop() });
|
|
944
|
+
log.verbose(`AutomineSequencer started`);
|
|
945
|
+
} else if (automineSequencer) {
|
|
946
|
+
log.warn(`AutomineSequencer created but not started`);
|
|
947
|
+
}
|
|
429
948
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
949
|
+
// Create prover node subsystem if enabled
|
|
950
|
+
let proverNode: ProverNode | undefined;
|
|
951
|
+
if (config.enableProverNode) {
|
|
952
|
+
proverNode = await createProverNode(config, {
|
|
953
|
+
...deps.proverNodeDeps,
|
|
954
|
+
telemetry,
|
|
955
|
+
dateProvider,
|
|
956
|
+
archiver,
|
|
957
|
+
worldStateSynchronizer,
|
|
958
|
+
p2pClient,
|
|
959
|
+
epochCache,
|
|
960
|
+
blobClient,
|
|
961
|
+
keyStoreManager,
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
if (!options.dontStartProverNode) {
|
|
965
|
+
await proverNode.start();
|
|
966
|
+
started.push(proverNode);
|
|
967
|
+
log.info(`Prover node subsystem started`);
|
|
968
|
+
} else {
|
|
969
|
+
log.info(`Prover node subsystem created but not started`);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
436
972
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
...deps,
|
|
440
|
-
epochCache,
|
|
441
|
-
l1TxUtils,
|
|
442
|
-
validatorClient,
|
|
973
|
+
const node = new AztecNodeService(
|
|
974
|
+
config,
|
|
443
975
|
p2pClient,
|
|
976
|
+
archiver,
|
|
977
|
+
archiver,
|
|
978
|
+
archiver,
|
|
979
|
+
archiver,
|
|
444
980
|
worldStateSynchronizer,
|
|
981
|
+
sequencer,
|
|
982
|
+
proverNode,
|
|
445
983
|
slasherClient,
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
984
|
+
validatorsSentinel,
|
|
985
|
+
stopStartedWatchers,
|
|
986
|
+
ethereumChain.chainInfo.id,
|
|
987
|
+
config.rollupVersion,
|
|
988
|
+
globalVariableBuilder,
|
|
989
|
+
feeProvider,
|
|
990
|
+
epochCache,
|
|
991
|
+
packageVersion,
|
|
992
|
+
peerProofVerifier,
|
|
993
|
+
rpcProofVerifier,
|
|
449
994
|
telemetry,
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
995
|
+
log,
|
|
996
|
+
blobClient,
|
|
997
|
+
validatorClient,
|
|
998
|
+
keyStoreManager,
|
|
999
|
+
debugLogStore,
|
|
1000
|
+
automineSequencer,
|
|
1001
|
+
);
|
|
455
1002
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
log.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
config,
|
|
465
|
-
p2pClient,
|
|
466
|
-
archiver,
|
|
467
|
-
archiver,
|
|
468
|
-
archiver,
|
|
469
|
-
archiver,
|
|
470
|
-
worldStateSynchronizer,
|
|
471
|
-
sequencer,
|
|
472
|
-
slasherClient,
|
|
473
|
-
validatorsSentinel,
|
|
474
|
-
epochPruneWatcher,
|
|
475
|
-
ethereumChain.chainInfo.id,
|
|
476
|
-
config.rollupVersion,
|
|
477
|
-
new GlobalVariableBuilder(config),
|
|
478
|
-
epochCache,
|
|
479
|
-
packageVersion,
|
|
480
|
-
proofVerifier,
|
|
481
|
-
telemetry,
|
|
482
|
-
log,
|
|
483
|
-
);
|
|
1003
|
+
return node;
|
|
1004
|
+
} catch (err) {
|
|
1005
|
+
log.error('Failed during node creation, stopping started resources', err);
|
|
1006
|
+
for (const resource of started.reverse()) {
|
|
1007
|
+
await tryStop(resource);
|
|
1008
|
+
}
|
|
1009
|
+
throw err;
|
|
1010
|
+
}
|
|
484
1011
|
}
|
|
485
1012
|
|
|
486
1013
|
/**
|
|
@@ -491,6 +1018,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
491
1018
|
return this.sequencer;
|
|
492
1019
|
}
|
|
493
1020
|
|
|
1021
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
|
|
1022
|
+
public getAutomineSequencer(): AutomineSequencer | undefined {
|
|
1023
|
+
return this.automineSequencer;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
1027
|
+
public getProverNode(): ProverNode | undefined {
|
|
1028
|
+
return this.proverNode;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
494
1031
|
public getBlockSource(): L2BlockSource {
|
|
495
1032
|
return this.blockSource;
|
|
496
1033
|
}
|
|
@@ -508,13 +1045,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
508
1045
|
* @returns - The currently deployed L1 contract addresses.
|
|
509
1046
|
*/
|
|
510
1047
|
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
|
|
511
|
-
return Promise.resolve(this.config
|
|
1048
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
512
1049
|
}
|
|
513
1050
|
|
|
514
1051
|
public getEncodedEnr(): Promise<string | undefined> {
|
|
515
1052
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
516
1053
|
}
|
|
517
1054
|
|
|
1055
|
+
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
1056
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
1057
|
+
}
|
|
1058
|
+
|
|
518
1059
|
/**
|
|
519
1060
|
* Method to determine if the node is ready to accept transactions.
|
|
520
1061
|
* @returns - Flag indicating the readiness for tx submission.
|
|
@@ -540,73 +1081,27 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
540
1081
|
enr,
|
|
541
1082
|
l1ContractAddresses: contractAddresses,
|
|
542
1083
|
protocolContractAddresses: protocolContractAddresses,
|
|
1084
|
+
realProofs: !!this.config.realProofs,
|
|
543
1085
|
};
|
|
544
1086
|
|
|
545
1087
|
return nodeInfo;
|
|
546
1088
|
}
|
|
547
1089
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
* @param number - The block number being requested.
|
|
551
|
-
* @returns The requested block.
|
|
552
|
-
*/
|
|
553
|
-
public async getBlock(number: L2BlockNumber): Promise<L2Block | undefined> {
|
|
554
|
-
const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
|
|
555
|
-
return await this.blockSource.getBlock(blockNumber);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Get a block specified by its hash.
|
|
560
|
-
* @param blockHash - The block hash being requested.
|
|
561
|
-
* @returns The requested block.
|
|
562
|
-
*/
|
|
563
|
-
public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
|
|
564
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
|
|
565
|
-
return publishedBlock?.block;
|
|
1090
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
1091
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
566
1092
|
}
|
|
567
1093
|
|
|
568
|
-
/**
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
* @returns The requested block.
|
|
572
|
-
*/
|
|
573
|
-
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
574
|
-
const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
|
|
575
|
-
return publishedBlock?.block;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
580
|
-
* @param from - The start of the range of blocks to return.
|
|
581
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
582
|
-
* @returns The blocks requested.
|
|
583
|
-
*/
|
|
584
|
-
public async getBlocks(from: number, limit: number): Promise<L2Block[]> {
|
|
585
|
-
return (await this.blockSource.getBlocks(from, limit)) ?? [];
|
|
1094
|
+
/** Returns predicted min fees for the current slot and next N slots. */
|
|
1095
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
1096
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
586
1097
|
}
|
|
587
1098
|
|
|
588
|
-
public async
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Method to fetch the current base fees.
|
|
594
|
-
* @returns The current base fees.
|
|
595
|
-
*/
|
|
596
|
-
public async getCurrentBaseFees(): Promise<GasFees> {
|
|
597
|
-
return await this.globalVariableBuilder.getCurrentBaseFees();
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
602
|
-
* @returns The block number.
|
|
603
|
-
*/
|
|
604
|
-
public async getBlockNumber(): Promise<number> {
|
|
605
|
-
return await this.blockSource.getBlockNumber();
|
|
606
|
-
}
|
|
1099
|
+
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
1100
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
1101
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
1102
|
+
}
|
|
607
1103
|
|
|
608
|
-
|
|
609
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
1104
|
+
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
610
1105
|
}
|
|
611
1106
|
|
|
612
1107
|
/**
|
|
@@ -641,43 +1136,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
641
1136
|
return this.contractDataSource.getContract(address);
|
|
642
1137
|
}
|
|
643
1138
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
* @param from - The block number from which to begin retrieving logs.
|
|
647
|
-
* @param limit - The maximum number of blocks to retrieve logs from.
|
|
648
|
-
* @returns An array of private logs from the specified range of blocks.
|
|
649
|
-
*/
|
|
650
|
-
public getPrivateLogs(from: number, limit: number): Promise<PrivateLog[]> {
|
|
651
|
-
return this.logsSource.getPrivateLogs(from, limit);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
/**
|
|
655
|
-
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
656
|
-
* @param tags - The tags to filter the logs by.
|
|
657
|
-
* @param logsPerTag - The maximum number of logs to return for each tag. By default no limit is set
|
|
658
|
-
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
659
|
-
* that tag.
|
|
660
|
-
*/
|
|
661
|
-
public getLogsByTags(tags: Fr[], logsPerTag?: number): Promise<TxScopedL2Log[][]> {
|
|
662
|
-
return this.logsSource.getLogsByTags(tags, logsPerTag);
|
|
1139
|
+
public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
1140
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
663
1141
|
}
|
|
664
1142
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
* @param filter - The filter to apply to the logs.
|
|
668
|
-
* @returns The requested logs.
|
|
669
|
-
*/
|
|
670
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
671
|
-
return this.logsSource.getPublicLogs(filter);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Gets contract class logs based on the provided filter.
|
|
676
|
-
* @param filter - The filter to apply to the logs.
|
|
677
|
-
* @returns The requested logs.
|
|
678
|
-
*/
|
|
679
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
680
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
1143
|
+
public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
|
|
1144
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
681
1145
|
}
|
|
682
1146
|
|
|
683
1147
|
/**
|
|
@@ -685,7 +1149,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
1149
|
* @param tx - The transaction to be submitted.
|
|
686
1150
|
*/
|
|
687
1151
|
public async sendTx(tx: Tx) {
|
|
688
|
-
await this
|
|
1152
|
+
await this.#sendTx(tx);
|
|
689
1153
|
}
|
|
690
1154
|
|
|
691
1155
|
async #sendTx(tx: Tx) {
|
|
@@ -700,27 +1164,48 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
700
1164
|
throw new Error(`Invalid tx: ${reason}`);
|
|
701
1165
|
}
|
|
702
1166
|
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
1167
|
+
try {
|
|
1168
|
+
await this.p2pClient!.sendTx(tx);
|
|
1169
|
+
} catch (err) {
|
|
1170
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
1171
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${(err as Error).message}`, { txHash });
|
|
1172
|
+
throw err;
|
|
1173
|
+
}
|
|
1174
|
+
const duration = timer.ms();
|
|
1175
|
+
this.metrics.receivedTx(duration, true);
|
|
1176
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
706
1177
|
}
|
|
707
1178
|
|
|
708
1179
|
public async getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
// and we would incorrectly return a TxReceipt with status DROPPED
|
|
714
|
-
if ((await this.p2pClient.getTxStatus(txHash)) === 'pending') {
|
|
715
|
-
txReceipt = new TxReceipt(txHash, TxStatus.PENDING, '');
|
|
716
|
-
}
|
|
1180
|
+
// Check the tx pool status first. If the tx is known to the pool (pending or mined), we'll use that
|
|
1181
|
+
// as a fallback if we don't find a settled receipt in the archiver.
|
|
1182
|
+
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1183
|
+
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
717
1184
|
|
|
1185
|
+
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
718
1186
|
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
1187
|
+
|
|
1188
|
+
let receipt: TxReceipt;
|
|
719
1189
|
if (settledTxReceipt) {
|
|
720
|
-
|
|
1190
|
+
receipt = settledTxReceipt;
|
|
1191
|
+
} else if (isKnownToPool) {
|
|
1192
|
+
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1193
|
+
// This handles race conditions between archiver and p2p, where the archiver
|
|
1194
|
+
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1195
|
+
receipt = new TxReceipt(txHash, TxStatus.PENDING, /*executionResult=*/ undefined, /*error=*/ undefined);
|
|
1196
|
+
} else {
|
|
1197
|
+
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1198
|
+
receipt = new TxReceipt(
|
|
1199
|
+
txHash,
|
|
1200
|
+
TxStatus.DROPPED,
|
|
1201
|
+
/*executionResult=*/ undefined,
|
|
1202
|
+
/*error=*/ 'Tx dropped by P2P node',
|
|
1203
|
+
);
|
|
721
1204
|
}
|
|
722
1205
|
|
|
723
|
-
|
|
1206
|
+
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1207
|
+
|
|
1208
|
+
return receipt;
|
|
724
1209
|
}
|
|
725
1210
|
|
|
726
1211
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -732,19 +1217,28 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
732
1217
|
*/
|
|
733
1218
|
public async stop() {
|
|
734
1219
|
this.log.info(`Stopping Aztec Node`);
|
|
735
|
-
await this.
|
|
736
|
-
await tryStop(this.validatorsSentinel);
|
|
737
|
-
await tryStop(this.epochPruneWatcher);
|
|
1220
|
+
await this.stopStartedWatchers();
|
|
738
1221
|
await tryStop(this.slasherClient);
|
|
739
|
-
await tryStop(this.
|
|
1222
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
740
1223
|
await tryStop(this.sequencer);
|
|
1224
|
+
await tryStop(this.automineSequencer);
|
|
1225
|
+
await tryStop(this.proverNode);
|
|
741
1226
|
await tryStop(this.p2pClient);
|
|
742
1227
|
await tryStop(this.worldStateSynchronizer);
|
|
743
1228
|
await tryStop(this.blockSource);
|
|
1229
|
+
await tryStop(this.blobClient);
|
|
744
1230
|
await tryStop(this.telemetry);
|
|
745
1231
|
this.log.info(`Stopped Aztec Node`);
|
|
746
1232
|
}
|
|
747
1233
|
|
|
1234
|
+
/**
|
|
1235
|
+
* Returns the blob client used by this node.
|
|
1236
|
+
* @internal - Exposed for testing purposes only.
|
|
1237
|
+
*/
|
|
1238
|
+
public getBlobClient(): BlobClientInterface | undefined {
|
|
1239
|
+
return this.blobClient;
|
|
1240
|
+
}
|
|
1241
|
+
|
|
748
1242
|
/**
|
|
749
1243
|
* Method to retrieve pending txs.
|
|
750
1244
|
* @param limit - The number of items to returns
|
|
@@ -777,121 +1271,99 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
777
1271
|
return compactArray(await Promise.all(txHashes.map(txHash => this.getTxByHash(txHash))));
|
|
778
1272
|
}
|
|
779
1273
|
|
|
780
|
-
/**
|
|
781
|
-
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
782
|
-
* the leaves were inserted.
|
|
783
|
-
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
784
|
-
* @param treeId - The tree to search in.
|
|
785
|
-
* @param leafValues - The values to search for.
|
|
786
|
-
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
787
|
-
*/
|
|
788
1274
|
public async findLeavesIndexes(
|
|
789
|
-
|
|
1275
|
+
referenceBlock: BlockParameter,
|
|
790
1276
|
treeId: MerkleTreeId,
|
|
791
1277
|
leafValues: Fr[],
|
|
792
|
-
): Promise<(
|
|
793
|
-
const committedDb = await this
|
|
1278
|
+
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
1279
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
794
1280
|
const maybeIndices = await committedDb.findLeafIndices(
|
|
795
1281
|
treeId,
|
|
796
1282
|
leafValues.map(x => x.toBuffer()),
|
|
797
1283
|
);
|
|
798
|
-
//
|
|
799
|
-
const
|
|
1284
|
+
// Filter out undefined values to query block numbers only for found leaves
|
|
1285
|
+
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
800
1286
|
|
|
801
|
-
// Now we find the block numbers for the indices
|
|
802
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId,
|
|
1287
|
+
// Now we find the block numbers for the defined indices
|
|
1288
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
803
1289
|
|
|
804
|
-
//
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
1290
|
+
// Build a map from leaf index to block number
|
|
1291
|
+
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1292
|
+
for (let i = 0; i < definedIndices.length; i++) {
|
|
1293
|
+
const blockNumber = blockNumbers[i];
|
|
1294
|
+
if (blockNumber === undefined) {
|
|
1295
|
+
throw new Error(
|
|
1296
|
+
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1297
|
+
);
|
|
808
1298
|
}
|
|
1299
|
+
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
809
1300
|
}
|
|
810
1301
|
|
|
811
1302
|
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
812
|
-
const uniqueBlockNumbers = [...new Set(
|
|
1303
|
+
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
813
1304
|
|
|
814
|
-
// Now we obtain the block hashes from the archive tree
|
|
815
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
1305
|
+
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
816
1306
|
const blockHashes = await Promise.all(
|
|
817
1307
|
uniqueBlockNumbers.map(blockNumber => {
|
|
818
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber
|
|
1308
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
819
1309
|
}),
|
|
820
1310
|
);
|
|
821
1311
|
|
|
822
|
-
//
|
|
1312
|
+
// Build a map from block number to block hash
|
|
1313
|
+
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
823
1314
|
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
824
|
-
|
|
1315
|
+
const blockHash = blockHashes[i];
|
|
1316
|
+
if (blockHash === undefined) {
|
|
825
1317
|
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
826
1318
|
}
|
|
1319
|
+
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
827
1320
|
}
|
|
828
1321
|
|
|
829
|
-
// Create
|
|
830
|
-
return maybeIndices.map(
|
|
1322
|
+
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1323
|
+
return maybeIndices.map(index => {
|
|
831
1324
|
if (index === undefined) {
|
|
832
1325
|
return undefined;
|
|
833
1326
|
}
|
|
834
|
-
const blockNumber =
|
|
1327
|
+
const blockNumber = indexToBlockNumber.get(index);
|
|
835
1328
|
if (blockNumber === undefined) {
|
|
836
|
-
|
|
1329
|
+
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
837
1330
|
}
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
return undefined;
|
|
1331
|
+
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1332
|
+
if (l2BlockHash === undefined) {
|
|
1333
|
+
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
842
1334
|
}
|
|
843
1335
|
return {
|
|
844
|
-
l2BlockNumber:
|
|
845
|
-
l2BlockHash
|
|
1336
|
+
l2BlockNumber: blockNumber,
|
|
1337
|
+
l2BlockHash,
|
|
846
1338
|
data: index,
|
|
847
1339
|
};
|
|
848
1340
|
});
|
|
849
1341
|
}
|
|
850
1342
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
855
|
-
* @returns The sibling path for the leaf index.
|
|
856
|
-
*/
|
|
857
|
-
public async getNullifierSiblingPath(
|
|
858
|
-
blockNumber: L2BlockNumber,
|
|
859
|
-
leafIndex: bigint,
|
|
860
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
861
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
862
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
/**
|
|
866
|
-
* Returns a sibling path for the given index in the data tree.
|
|
867
|
-
* @param blockNumber - The block number at which to get the data.
|
|
868
|
-
* @param leafIndex - The index of the leaf for which the sibling path is required.
|
|
869
|
-
* @returns The sibling path for the leaf index.
|
|
870
|
-
*/
|
|
871
|
-
public async getNoteHashSiblingPath(
|
|
872
|
-
blockNumber: L2BlockNumber,
|
|
873
|
-
leafIndex: bigint,
|
|
874
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
875
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
876
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
public async getArchiveMembershipWitness(
|
|
880
|
-
blockNumber: L2BlockNumber,
|
|
881
|
-
archive: Fr,
|
|
1343
|
+
public async getBlockHashMembershipWitness(
|
|
1344
|
+
referenceBlock: BlockParameter,
|
|
1345
|
+
blockHash: BlockHash,
|
|
882
1346
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
883
|
-
|
|
884
|
-
|
|
1347
|
+
// The Noir circuit checks the archive membership proof against `anchor_block_header.last_archive.root`,
|
|
1348
|
+
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1349
|
+
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1350
|
+
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1351
|
+
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1352
|
+
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1353
|
+
return undefined;
|
|
1354
|
+
}
|
|
1355
|
+
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1356
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
885
1357
|
return pathAndIndex === undefined
|
|
886
1358
|
? undefined
|
|
887
1359
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
888
1360
|
}
|
|
889
1361
|
|
|
890
1362
|
public async getNoteHashMembershipWitness(
|
|
891
|
-
|
|
1363
|
+
referenceBlock: BlockParameter,
|
|
892
1364
|
noteHash: Fr,
|
|
893
1365
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
894
|
-
const committedDb = await this
|
|
1366
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
895
1367
|
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
896
1368
|
MerkleTreeId.NOTE_HASH_TREE,
|
|
897
1369
|
[noteHash],
|
|
@@ -901,17 +1373,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
901
1373
|
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
902
1374
|
}
|
|
903
1375
|
|
|
904
|
-
/**
|
|
905
|
-
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
906
|
-
* @param blockNumber - The block number at which to get the data.
|
|
907
|
-
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
908
|
-
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
909
|
-
*/
|
|
910
1376
|
public async getL1ToL2MessageMembershipWitness(
|
|
911
|
-
|
|
1377
|
+
referenceBlock: BlockParameter,
|
|
912
1378
|
l1ToL2Message: Fr,
|
|
913
1379
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
914
|
-
const db = await this
|
|
1380
|
+
const db = await this.getWorldState(referenceBlock);
|
|
915
1381
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
916
1382
|
if (!witness) {
|
|
917
1383
|
return undefined;
|
|
@@ -921,70 +1387,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
921
1387
|
return [witness.index, witness.path];
|
|
922
1388
|
}
|
|
923
1389
|
|
|
924
|
-
public async
|
|
1390
|
+
public async getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
925
1391
|
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
926
|
-
return messageIndex ? InboxLeaf.
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
/**
|
|
930
|
-
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
931
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
932
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
933
|
-
*/
|
|
934
|
-
public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
935
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
936
|
-
return messageIndex !== undefined;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
/**
|
|
940
|
-
* Returns all the L2 to L1 messages in a block.
|
|
941
|
-
* @param blockNumber - The block number at which to get the data.
|
|
942
|
-
* @returns The L2 to L1 messages (undefined if the block number is not found).
|
|
943
|
-
*/
|
|
944
|
-
public async getL2ToL1Messages(blockNumber: L2BlockNumber): Promise<Fr[][] | undefined> {
|
|
945
|
-
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
946
|
-
return block?.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs);
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
/**
|
|
950
|
-
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
951
|
-
* @param blockNumber - The block number at which to get the data.
|
|
952
|
-
* @param leafIndex - Index of the leaf in the tree.
|
|
953
|
-
* @returns The sibling path.
|
|
954
|
-
*/
|
|
955
|
-
public async getArchiveSiblingPath(
|
|
956
|
-
blockNumber: L2BlockNumber,
|
|
957
|
-
leafIndex: bigint,
|
|
958
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
959
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
960
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
1392
|
+
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
961
1393
|
}
|
|
962
1394
|
|
|
963
1395
|
/**
|
|
964
|
-
* Returns
|
|
965
|
-
* @param
|
|
966
|
-
* @
|
|
967
|
-
* @returns The sibling path.
|
|
1396
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
1397
|
+
* @param epoch - The epoch at which to get the data.
|
|
1398
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
968
1399
|
*/
|
|
969
|
-
public async
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1400
|
+
public async getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
1401
|
+
const blocks = await this.blockSource.getBlocks({ epoch, onlyCheckpointed: true });
|
|
1402
|
+
const blocksInCheckpoints = chunkBy(blocks, block => block.header.globalVariables.slotNumber);
|
|
1403
|
+
return blocksInCheckpoints.map(slotBlocks =>
|
|
1404
|
+
slotBlocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1405
|
+
);
|
|
975
1406
|
}
|
|
976
1407
|
|
|
977
|
-
/**
|
|
978
|
-
* Returns a nullifier membership witness for a given nullifier at a given block.
|
|
979
|
-
* @param blockNumber - The block number at which to get the index.
|
|
980
|
-
* @param nullifier - Nullifier we try to find witness for.
|
|
981
|
-
* @returns The nullifier membership witness (if found).
|
|
982
|
-
*/
|
|
983
1408
|
public async getNullifierMembershipWitness(
|
|
984
|
-
|
|
1409
|
+
referenceBlock: BlockParameter,
|
|
985
1410
|
nullifier: Fr,
|
|
986
1411
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
987
|
-
const db = await this
|
|
1412
|
+
const db = await this.getWorldState(referenceBlock);
|
|
988
1413
|
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
989
1414
|
if (!witness) {
|
|
990
1415
|
return undefined;
|
|
@@ -999,32 +1424,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
999
1424
|
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
1000
1425
|
}
|
|
1001
1426
|
|
|
1002
|
-
/**
|
|
1003
|
-
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
1004
|
-
* @param blockNumber - The block number at which to get the index.
|
|
1005
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1006
|
-
* @returns The low nullifier membership witness (if found).
|
|
1007
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1008
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1009
|
-
* we are trying to prove non-inclusion for.
|
|
1010
|
-
*
|
|
1011
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1012
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1013
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1014
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1015
|
-
*/
|
|
1016
1427
|
public async getLowNullifierMembershipWitness(
|
|
1017
|
-
|
|
1428
|
+
referenceBlock: BlockParameter,
|
|
1018
1429
|
nullifier: Fr,
|
|
1019
1430
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1020
|
-
const committedDb = await this
|
|
1431
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1021
1432
|
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1022
1433
|
if (!findResult) {
|
|
1023
1434
|
return undefined;
|
|
1024
1435
|
}
|
|
1025
1436
|
const { index, alreadyPresent } = findResult;
|
|
1026
1437
|
if (alreadyPresent) {
|
|
1027
|
-
|
|
1438
|
+
throw new Error(
|
|
1439
|
+
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1440
|
+
);
|
|
1028
1441
|
}
|
|
1029
1442
|
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1030
1443
|
|
|
@@ -1032,8 +1445,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1032
1445
|
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
1033
1446
|
}
|
|
1034
1447
|
|
|
1035
|
-
async getPublicDataWitness(
|
|
1036
|
-
const committedDb = await this
|
|
1448
|
+
async getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
1449
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1037
1450
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1038
1451
|
if (!lowLeafResult) {
|
|
1039
1452
|
return undefined;
|
|
@@ -1047,19 +1460,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1047
1460
|
}
|
|
1048
1461
|
}
|
|
1049
1462
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
*
|
|
1053
|
-
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
|
|
1054
|
-
* Aztec's version of `eth_getStorageAt`.
|
|
1055
|
-
*
|
|
1056
|
-
* @param contract - Address of the contract to query.
|
|
1057
|
-
* @param slot - Slot to query.
|
|
1058
|
-
* @param blockNumber - The block number at which to get the data or 'latest'.
|
|
1059
|
-
* @returns Storage value at the given contract slot.
|
|
1060
|
-
*/
|
|
1061
|
-
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1062
|
-
const committedDb = await this.#getWorldState(blockNumber);
|
|
1463
|
+
public async getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1464
|
+
const committedDb = await this.getWorldState(referenceBlock);
|
|
1063
1465
|
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1064
1466
|
|
|
1065
1467
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
@@ -1073,42 +1475,20 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1073
1475
|
return preimage.leaf.value;
|
|
1074
1476
|
}
|
|
1075
1477
|
|
|
1076
|
-
/**
|
|
1077
|
-
* Returns the currently committed block header, or the initial header if no blocks have been produced.
|
|
1078
|
-
* @returns The current committed block header.
|
|
1079
|
-
*/
|
|
1080
|
-
public async getBlockHeader(blockNumber: L2BlockNumber = 'latest'): Promise<BlockHeader | undefined> {
|
|
1081
|
-
return blockNumber === 0 || (blockNumber === 'latest' && (await this.blockSource.getBlockNumber()) === 0)
|
|
1082
|
-
? this.worldStateSynchronizer.getCommitted().getInitialHeader()
|
|
1083
|
-
: this.blockSource.getBlockHeader(blockNumber);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
/**
|
|
1087
|
-
* Get a block header specified by its hash.
|
|
1088
|
-
* @param blockHash - The block hash being requested.
|
|
1089
|
-
* @returns The requested block header.
|
|
1090
|
-
*/
|
|
1091
|
-
public async getBlockHeaderByHash(blockHash: Fr): Promise<BlockHeader | undefined> {
|
|
1092
|
-
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
/**
|
|
1096
|
-
* Get a block header specified by its archive root.
|
|
1097
|
-
* @param archive - The archive root being requested.
|
|
1098
|
-
* @returns The requested block header.
|
|
1099
|
-
*/
|
|
1100
|
-
public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
1101
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
1478
|
/**
|
|
1105
1479
|
* Simulates the public part of a transaction with the current state.
|
|
1106
1480
|
* @param tx - The transaction to simulate.
|
|
1481
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
1482
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1107
1483
|
**/
|
|
1108
1484
|
@trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
|
|
1109
1485
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1110
1486
|
}))
|
|
1111
|
-
public async simulatePublicCalls(
|
|
1487
|
+
public async simulatePublicCalls(
|
|
1488
|
+
tx: Tx,
|
|
1489
|
+
skipFeeEnforcement = false,
|
|
1490
|
+
overrides?: SimulationOverrides,
|
|
1491
|
+
): Promise<PublicSimulationOutput> {
|
|
1112
1492
|
// Check total gas limit for simulation
|
|
1113
1493
|
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1114
1494
|
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
@@ -1124,7 +1504,9 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1124
1504
|
}
|
|
1125
1505
|
|
|
1126
1506
|
const txHash = tx.getTxHash();
|
|
1127
|
-
const
|
|
1507
|
+
const l2Tips = await this.blockSource.getL2Tips();
|
|
1508
|
+
const latestBlockNumber = l2Tips.proposed.number;
|
|
1509
|
+
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1128
1510
|
|
|
1129
1511
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1130
1512
|
const coinbase = EthAddress.ZERO;
|
|
@@ -1135,10 +1517,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1135
1517
|
coinbase,
|
|
1136
1518
|
feeRecipient,
|
|
1137
1519
|
);
|
|
1520
|
+
|
|
1138
1521
|
const publicProcessorFactory = new PublicProcessorFactory(
|
|
1139
1522
|
this.contractDataSource,
|
|
1140
1523
|
new DateProvider(),
|
|
1141
1524
|
this.telemetry,
|
|
1525
|
+
this.log.getBindings(),
|
|
1142
1526
|
);
|
|
1143
1527
|
|
|
1144
1528
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
@@ -1147,34 +1531,79 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1147
1531
|
blockNumber,
|
|
1148
1532
|
});
|
|
1149
1533
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1534
|
+
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1535
|
+
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1536
|
+
|
|
1537
|
+
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1538
|
+
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1539
|
+
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1540
|
+
// which means the next block would be the first block of the next checkpoint.
|
|
1541
|
+
const targetCheckpoint = CheckpointNumber(
|
|
1542
|
+
(l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1,
|
|
1543
|
+
);
|
|
1544
|
+
const nextCheckpointMessages: Fr[] | undefined =
|
|
1545
|
+
l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number
|
|
1546
|
+
? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch(err => {
|
|
1547
|
+
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1548
|
+
this.log.warn(
|
|
1549
|
+
`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`,
|
|
1550
|
+
);
|
|
1551
|
+
} else {
|
|
1552
|
+
this.log.error(
|
|
1553
|
+
`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`,
|
|
1554
|
+
err,
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
return undefined;
|
|
1558
|
+
})
|
|
1559
|
+
: undefined;
|
|
1560
|
+
|
|
1561
|
+
// 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
|
|
1562
|
+
await using merkleTreeFork = await this.worldStateSynchronizer.fork(latestBlockNumber);
|
|
1563
|
+
|
|
1564
|
+
if (nextCheckpointMessages !== undefined) {
|
|
1565
|
+
this.log.debug(
|
|
1566
|
+
`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`,
|
|
1567
|
+
{ checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1 },
|
|
1157
1568
|
);
|
|
1569
|
+
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1570
|
+
}
|
|
1571
|
+
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
1158
1572
|
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1573
|
+
const config = PublicSimulatorConfig.from({
|
|
1574
|
+
skipFeeEnforcement,
|
|
1575
|
+
collectDebugLogs: true,
|
|
1576
|
+
collectHints: false,
|
|
1577
|
+
collectCallMetadata: true,
|
|
1578
|
+
collectStatistics: false,
|
|
1579
|
+
collectionLimits: CollectionLimitsConfig.from({
|
|
1580
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1581
|
+
}),
|
|
1582
|
+
});
|
|
1166
1583
|
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1584
|
+
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1585
|
+
if (overrides?.contracts) {
|
|
1586
|
+
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance }) => instance));
|
|
1587
|
+
}
|
|
1588
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
1589
|
+
|
|
1590
|
+
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1591
|
+
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1592
|
+
// REFACTOR: Consider returning the error rather than throwing
|
|
1593
|
+
if (failedTxs.length) {
|
|
1594
|
+
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1595
|
+
throw failedTxs[0].error;
|
|
1177
1596
|
}
|
|
1597
|
+
|
|
1598
|
+
const [processedTx] = processedTxs;
|
|
1599
|
+
return new PublicSimulationOutput(
|
|
1600
|
+
processedTx.revertReason,
|
|
1601
|
+
processedTx.globalVariables,
|
|
1602
|
+
processedTx.txEffect,
|
|
1603
|
+
returns,
|
|
1604
|
+
processedTx.gasUsed,
|
|
1605
|
+
debugLogs,
|
|
1606
|
+
);
|
|
1178
1607
|
}
|
|
1179
1608
|
|
|
1180
1609
|
public async isValidTx(
|
|
@@ -1182,21 +1611,34 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1182
1611
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1183
1612
|
): Promise<TxValidationResult> {
|
|
1184
1613
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1185
|
-
const verifier = isSimulation ? undefined : this.
|
|
1614
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1186
1615
|
|
|
1187
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
1616
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1188
1617
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1189
|
-
const blockNumber = (await this.blockSource.getBlockNumber()) + 1;
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1618
|
+
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1619
|
+
const l1Constants = await this.blockSource.getL1Constants();
|
|
1620
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1621
|
+
db,
|
|
1622
|
+
this.contractDataSource,
|
|
1623
|
+
verifier,
|
|
1624
|
+
{
|
|
1625
|
+
timestamp: nextSlotTimestamp,
|
|
1626
|
+
blockNumber,
|
|
1627
|
+
l1ChainId: this.l1ChainId,
|
|
1628
|
+
rollupVersion: this.version,
|
|
1629
|
+
setupAllowList: [
|
|
1630
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
1631
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
1632
|
+
],
|
|
1633
|
+
gasFees: await this.getCurrentMinFees(),
|
|
1634
|
+
skipFeeEnforcement,
|
|
1635
|
+
txsPermitted: !this.config.disableTransactions,
|
|
1636
|
+
rollupManaLimit: l1Constants.rollupManaLimit,
|
|
1637
|
+
maxBlockL2Gas: this.config.validateMaxL2BlockGas,
|
|
1638
|
+
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
1639
|
+
},
|
|
1640
|
+
this.log.getBindings(),
|
|
1641
|
+
);
|
|
1200
1642
|
|
|
1201
1643
|
return await validator.validateTx(tx);
|
|
1202
1644
|
}
|
|
@@ -1209,7 +1651,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1209
1651
|
|
|
1210
1652
|
public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
|
|
1211
1653
|
const newConfig = { ...this.config, ...config };
|
|
1212
|
-
|
|
1654
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
1655
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
1656
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
1657
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
1658
|
+
// pauseSequencer() still considers it paused.
|
|
1659
|
+
const sequencerUpdate = { ...config };
|
|
1660
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
1661
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
1662
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
1663
|
+
}
|
|
1664
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
1665
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
1213
1666
|
this.slasherClient?.updateConfig(config);
|
|
1214
1667
|
this.validatorsSentinel?.updateConfig(config);
|
|
1215
1668
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1218,7 +1671,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1218
1671
|
archiver.updateConfig(config);
|
|
1219
1672
|
}
|
|
1220
1673
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1221
|
-
|
|
1674
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
1675
|
+
if (newConfig.realProofs) {
|
|
1676
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
1677
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
1678
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
1679
|
+
} else {
|
|
1680
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
1681
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
1682
|
+
}
|
|
1222
1683
|
}
|
|
1223
1684
|
|
|
1224
1685
|
this.config = newConfig;
|
|
@@ -1229,7 +1690,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1229
1690
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1230
1691
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1231
1692
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1232
|
-
multiCallEntrypoint:
|
|
1693
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
1233
1694
|
});
|
|
1234
1695
|
}
|
|
1235
1696
|
|
|
@@ -1243,8 +1704,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1243
1704
|
|
|
1244
1705
|
public getValidatorStats(
|
|
1245
1706
|
validatorAddress: EthAddress,
|
|
1246
|
-
fromSlot?:
|
|
1247
|
-
toSlot?:
|
|
1707
|
+
fromSlot?: SlotNumber,
|
|
1708
|
+
toSlot?: SlotNumber,
|
|
1248
1709
|
): Promise<SingleValidatorStats | undefined> {
|
|
1249
1710
|
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
1250
1711
|
}
|
|
@@ -1254,45 +1715,52 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1254
1715
|
// We break support for archiver running remotely to the node
|
|
1255
1716
|
const archiver = this.blockSource as Archiver;
|
|
1256
1717
|
if (!('backupTo' in archiver)) {
|
|
1718
|
+
this.metrics.recordSnapshotError();
|
|
1257
1719
|
throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
|
|
1258
1720
|
}
|
|
1259
1721
|
|
|
1260
1722
|
// Test that the archiver has done an initial sync.
|
|
1261
1723
|
if (!archiver.isInitialSyncComplete()) {
|
|
1724
|
+
this.metrics.recordSnapshotError();
|
|
1262
1725
|
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
1263
1726
|
}
|
|
1264
1727
|
|
|
1265
1728
|
// And it has an L2 block hash
|
|
1266
|
-
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.
|
|
1729
|
+
const l2BlockHash = await archiver.getL2Tips().then(tips => tips.proposed.hash);
|
|
1267
1730
|
if (!l2BlockHash) {
|
|
1731
|
+
this.metrics.recordSnapshotError();
|
|
1268
1732
|
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
1269
1733
|
}
|
|
1270
1734
|
|
|
1271
1735
|
if (this.isUploadingSnapshot) {
|
|
1736
|
+
this.metrics.recordSnapshotError();
|
|
1272
1737
|
throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
|
|
1273
1738
|
}
|
|
1274
1739
|
|
|
1275
1740
|
// Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
|
|
1276
1741
|
this.isUploadingSnapshot = true;
|
|
1742
|
+
const timer = new Timer();
|
|
1277
1743
|
void uploadSnapshot(location, this.blockSource as Archiver, this.worldStateSynchronizer, this.config, this.log)
|
|
1278
1744
|
.then(() => {
|
|
1279
1745
|
this.isUploadingSnapshot = false;
|
|
1746
|
+
this.metrics.recordSnapshot(timer.ms());
|
|
1280
1747
|
})
|
|
1281
1748
|
.catch(err => {
|
|
1282
1749
|
this.isUploadingSnapshot = false;
|
|
1750
|
+
this.metrics.recordSnapshotError();
|
|
1283
1751
|
this.log.error(`Error uploading snapshot: ${err}`);
|
|
1284
1752
|
});
|
|
1285
1753
|
|
|
1286
1754
|
return Promise.resolve();
|
|
1287
1755
|
}
|
|
1288
1756
|
|
|
1289
|
-
public async rollbackTo(targetBlock:
|
|
1757
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1290
1758
|
const archiver = this.blockSource as Archiver;
|
|
1291
1759
|
if (!('rollbackTo' in archiver)) {
|
|
1292
1760
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
1293
1761
|
}
|
|
1294
1762
|
|
|
1295
|
-
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.number);
|
|
1763
|
+
const finalizedBlock = await archiver.getL2Tips().then(tips => tips.finalized.block.number);
|
|
1296
1764
|
if (targetBlock < finalizedBlock) {
|
|
1297
1765
|
if (force) {
|
|
1298
1766
|
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
@@ -1316,9 +1784,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1316
1784
|
this.log.error(`Error during rollback`, err);
|
|
1317
1785
|
throw err;
|
|
1318
1786
|
} finally {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1787
|
+
if (resumeSync) {
|
|
1788
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
1789
|
+
this.worldStateSynchronizer.resumeSync();
|
|
1790
|
+
archiver.resume();
|
|
1791
|
+
} else {
|
|
1792
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
1793
|
+
}
|
|
1322
1794
|
}
|
|
1323
1795
|
}
|
|
1324
1796
|
|
|
@@ -1335,11 +1807,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1335
1807
|
return Promise.resolve();
|
|
1336
1808
|
}
|
|
1337
1809
|
|
|
1338
|
-
public
|
|
1339
|
-
if (
|
|
1340
|
-
|
|
1810
|
+
public pauseSequencer(): Promise<void> {
|
|
1811
|
+
if (this.automineSequencer) {
|
|
1812
|
+
this.automineSequencer.pause();
|
|
1813
|
+
return Promise.resolve();
|
|
1814
|
+
}
|
|
1815
|
+
if (this.sequencer) {
|
|
1816
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
1817
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
1818
|
+
this.sequencer.updateConfig({ minTxsPerBlock: Number.MAX_SAFE_INTEGER });
|
|
1819
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
1820
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock,
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
return Promise.resolve();
|
|
1824
|
+
}
|
|
1825
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
public resumeSequencer(): Promise<void> {
|
|
1829
|
+
if (this.automineSequencer) {
|
|
1830
|
+
this.automineSequencer.resume();
|
|
1831
|
+
return Promise.resolve();
|
|
1832
|
+
}
|
|
1833
|
+
if (this.sequencer) {
|
|
1834
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
1835
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
1836
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
1837
|
+
this.sequencer.updateConfig({ minTxsPerBlock: restored });
|
|
1838
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, { minTxsPerBlock: restored });
|
|
1839
|
+
}
|
|
1840
|
+
return Promise.resolve();
|
|
1341
1841
|
}
|
|
1342
|
-
|
|
1842
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1343
1843
|
}
|
|
1344
1844
|
|
|
1345
1845
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
@@ -1347,48 +1847,224 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1347
1847
|
throw new Error(`Slasher client not enabled`);
|
|
1348
1848
|
}
|
|
1349
1849
|
if (round === 'all') {
|
|
1350
|
-
return this.slasherClient.
|
|
1850
|
+
return this.slasherClient.getOffenses();
|
|
1351
1851
|
} else {
|
|
1352
1852
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1353
1853
|
}
|
|
1354
1854
|
}
|
|
1355
1855
|
|
|
1856
|
+
public async reloadKeystore(): Promise<void> {
|
|
1857
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
1858
|
+
throw new BadRequestError(
|
|
1859
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
1860
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
if (!this.validatorClient) {
|
|
1864
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
this.log.info('Reloading keystore from disk');
|
|
1868
|
+
|
|
1869
|
+
// Re-read and validate keystore files
|
|
1870
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
1871
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
1872
|
+
await newManager.validateSigners();
|
|
1873
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1874
|
+
|
|
1875
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1876
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1877
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1878
|
+
// would silently fail on every proposer slot.
|
|
1879
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1880
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1881
|
+
const availablePublishers = new Set(
|
|
1882
|
+
oldAdapter
|
|
1883
|
+
.getAttesterAddresses()
|
|
1884
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1885
|
+
);
|
|
1886
|
+
|
|
1887
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1888
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1889
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1890
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1891
|
+
throw new BadRequestError(
|
|
1892
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1893
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1894
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1895
|
+
`use an existing publisher key or restart the node.`,
|
|
1896
|
+
);
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Build adapters for old and new keystores to compute diff
|
|
1902
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1903
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1904
|
+
const oldAddresses = this.keyStoreManager
|
|
1905
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1906
|
+
: [];
|
|
1907
|
+
|
|
1908
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1909
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1910
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1911
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1912
|
+
|
|
1913
|
+
if (added.length > 0) {
|
|
1914
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1915
|
+
}
|
|
1916
|
+
if (removed.length > 0) {
|
|
1917
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1918
|
+
}
|
|
1919
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1920
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1924
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1925
|
+
|
|
1926
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1927
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1928
|
+
if (this.sequencer) {
|
|
1929
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1933
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1934
|
+
const slashValidatorsNever = unique(
|
|
1935
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1936
|
+
).map(EthAddress.fromString);
|
|
1937
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
this.keyStoreManager = newManager;
|
|
1941
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
public async mineBlock(): Promise<void> {
|
|
1945
|
+
if (this.automineSequencer) {
|
|
1946
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
if (!this.sequencer) {
|
|
1950
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1954
|
+
|
|
1955
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1956
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1957
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1958
|
+
|
|
1959
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1960
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1961
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1962
|
+
|
|
1963
|
+
try {
|
|
1964
|
+
// Trigger the sequencer to produce a block immediately
|
|
1965
|
+
void this.sequencer.trigger();
|
|
1966
|
+
|
|
1967
|
+
// Wait for the new L2 block to appear
|
|
1968
|
+
await retryUntil(
|
|
1969
|
+
async () => {
|
|
1970
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1971
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1972
|
+
},
|
|
1973
|
+
'mineBlock',
|
|
1974
|
+
timeoutSeconds,
|
|
1975
|
+
0.1,
|
|
1976
|
+
);
|
|
1977
|
+
} finally {
|
|
1978
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1356
1982
|
/**
|
|
1357
1983
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1358
|
-
* @param
|
|
1984
|
+
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1359
1985
|
* @returns An instance of a committed MerkleTreeOperations
|
|
1360
1986
|
*/
|
|
1361
|
-
async
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1987
|
+
protected async getWorldState(block: BlockParameter) {
|
|
1988
|
+
const query = this.normalizeBlockParameter(block);
|
|
1989
|
+
|
|
1990
|
+
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
1991
|
+
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
1992
|
+
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
1993
|
+
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
1994
|
+
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
1995
|
+
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
1996
|
+
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
1997
|
+
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
1998
|
+
|
|
1999
|
+
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1367
2000
|
try {
|
|
1368
2001
|
// Attempt to sync the world state if necessary
|
|
1369
|
-
blockSyncedTo = await this.#syncWorldState();
|
|
2002
|
+
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
1370
2003
|
} catch (err) {
|
|
1371
2004
|
this.log.error(`Error getting world state: ${err}`);
|
|
1372
2005
|
}
|
|
1373
2006
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
this.log.debug(`Using committed db for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2007
|
+
if ('tag' in query && query.tag === 'proposed') {
|
|
2008
|
+
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
1377
2009
|
return this.worldStateSynchronizer.getCommitted();
|
|
1378
|
-
} else if (blockNumber <= blockSyncedTo) {
|
|
1379
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1380
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1381
|
-
} else {
|
|
1382
|
-
throw new Error(`Block ${blockNumber} not yet synced`);
|
|
1383
2010
|
}
|
|
2011
|
+
|
|
2012
|
+
const blockNumber = anchorBlockNumber ?? (await this.resolveBlockNumber(query));
|
|
2013
|
+
|
|
2014
|
+
// Check it's within world state sync range
|
|
2015
|
+
if (blockNumber > blockSyncedTo) {
|
|
2016
|
+
throw new Error(
|
|
2017
|
+
`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`,
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2021
|
+
|
|
2022
|
+
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
2023
|
+
|
|
2024
|
+
// Double-check world-state synced to the same block hash as was requested.
|
|
2025
|
+
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2026
|
+
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2027
|
+
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2028
|
+
// the archiver when it resolves the hash query to block number 0.
|
|
2029
|
+
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
2030
|
+
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
2031
|
+
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
2032
|
+
throw new Error(
|
|
2033
|
+
`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.`,
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
return snapshot;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
/** Resolves any {@link BlockParameter} variant to a concrete block number. */
|
|
2042
|
+
protected async resolveBlockNumber(block: BlockParameter): Promise<BlockNumber> {
|
|
2043
|
+
const query = this.normalizeBlockParameter(block);
|
|
2044
|
+
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
2045
|
+
if (blockNumber === undefined) {
|
|
2046
|
+
if ('hash' in query) {
|
|
2047
|
+
throw new Error(
|
|
2048
|
+
`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.`,
|
|
2049
|
+
);
|
|
2050
|
+
}
|
|
2051
|
+
if ('archive' in query) {
|
|
2052
|
+
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
2053
|
+
}
|
|
2054
|
+
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
2055
|
+
}
|
|
2056
|
+
return blockNumber;
|
|
1384
2057
|
}
|
|
1385
2058
|
|
|
1386
2059
|
/**
|
|
1387
|
-
* Ensure
|
|
2060
|
+
* Ensure the world state is synced.
|
|
2061
|
+
* @param targetBlockNumber - Block to sync up to. Defaults to the latest block known to the archiver.
|
|
2062
|
+
* @param blockHash - If provided, the synchronizer verifies the block at `targetBlockNumber` matches this
|
|
2063
|
+
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
1388
2064
|
* @returns A promise that fulfils once the world state is synced
|
|
1389
2065
|
*/
|
|
1390
|
-
async #syncWorldState(): Promise<
|
|
1391
|
-
const
|
|
1392
|
-
return this.worldStateSynchronizer.syncImmediate(
|
|
2066
|
+
async #syncWorldState(targetBlockNumber?: BlockNumber, blockHash?: BlockHash): Promise<BlockNumber> {
|
|
2067
|
+
const target = targetBlockNumber ?? (await this.blockSource.getBlockNumber());
|
|
2068
|
+
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1393
2069
|
}
|
|
1394
2070
|
}
|