@aztec/aztec-node 5.0.0-rc.1 → 5.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/aztec-node/config.d.ts +3 -1
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +5 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts +90 -0
- package/dest/aztec-node/node_public_calls_simulator.d.ts.map +1 -0
- package/dest/aztec-node/node_public_calls_simulator.js +346 -0
- package/dest/aztec-node/server.d.ts +68 -65
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +153 -1161
- package/dest/bin/index.js +2 -2
- package/dest/factory.d.ts +33 -0
- package/dest/factory.d.ts.map +1 -0
- package/dest/factory.js +496 -0
- package/dest/index.d.ts +2 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +1 -0
- package/dest/modules/block_parameter.d.ts +25 -0
- package/dest/modules/block_parameter.d.ts.map +1 -0
- package/dest/modules/block_parameter.js +100 -0
- package/dest/modules/node_block_provider.d.ts +19 -0
- package/dest/modules/node_block_provider.d.ts.map +1 -0
- package/dest/modules/node_block_provider.js +112 -0
- package/dest/modules/node_tx_receipt.d.ts +24 -0
- package/dest/modules/node_tx_receipt.d.ts.map +1 -0
- package/dest/modules/node_tx_receipt.js +70 -0
- package/dest/modules/node_world_state_queries.d.ts +61 -0
- package/dest/modules/node_world_state_queries.d.ts.map +1 -0
- package/dest/modules/node_world_state_queries.js +257 -0
- package/dest/sentinel/factory.d.ts +3 -3
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +8 -1
- package/dest/sentinel/sentinel.d.ts +21 -21
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +27 -47
- package/package.json +28 -27
- package/src/aztec-node/config.ts +7 -0
- package/src/aztec-node/node_public_calls_simulator.ts +383 -0
- package/src/aztec-node/server.ts +221 -1342
- package/src/bin/index.ts +7 -2
- package/src/factory.ts +656 -0
- package/src/index.ts +1 -0
- package/src/modules/block_parameter.ts +93 -0
- package/src/modules/node_block_provider.ts +149 -0
- package/src/modules/node_tx_receipt.ts +115 -0
- package/src/modules/node_world_state_queries.ts +360 -0
- package/src/sentinel/README.md +3 -3
- package/src/sentinel/factory.ts +15 -3
- package/src/sentinel/sentinel.ts +34 -72
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { Archiver
|
|
1
|
+
import { Archiver } from '@aztec/archiver';
|
|
2
2
|
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
3
|
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
4
|
-
import {
|
|
5
|
-
import { Blob } from '@aztec/blob-lib';
|
|
4
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
6
5
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { getPublicClient, makeL1HttpTransport } from '@aztec/ethereum/client';
|
|
10
|
-
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
6
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
11
8
|
import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
12
|
-
import type { L1TxUtils } from '@aztec/ethereum/l1-tx-utils';
|
|
13
9
|
import {
|
|
14
10
|
BlockNumber,
|
|
15
11
|
CheckpointNumber,
|
|
@@ -17,69 +13,36 @@ import {
|
|
|
17
13
|
EpochNumber,
|
|
18
14
|
SlotNumber,
|
|
19
15
|
} from '@aztec/foundation/branded-types';
|
|
20
|
-
import {
|
|
16
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
21
17
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
22
18
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
23
19
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
24
20
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
25
21
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
26
22
|
import { count } from '@aztec/foundation/string';
|
|
27
|
-
import {
|
|
23
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
28
24
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import { createForwarderL1TxUtilsFromSigners, createL1TxUtilsFromSigners } from '@aztec/node-lib/factories';
|
|
33
|
-
import {
|
|
34
|
-
type P2P,
|
|
35
|
-
type P2PClientDeps,
|
|
36
|
-
createP2PClient,
|
|
37
|
-
createTxValidatorForAcceptingTxsOverRPC,
|
|
38
|
-
getDefaultAllowedSetupFunctions,
|
|
39
|
-
} from '@aztec/p2p';
|
|
25
|
+
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
26
|
+
import { uploadSnapshot } from '@aztec/node-lib/actions';
|
|
27
|
+
import { type P2P, createTxValidatorForAcceptingTxsOverRPC, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
40
28
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
GlobalVariableBuilder,
|
|
46
|
-
SequencerClient,
|
|
47
|
-
type SequencerPublisher,
|
|
48
|
-
} from '@aztec/sequencer-client';
|
|
49
|
-
import { AutomineSequencer, createAutomineSequencer } from '@aztec/sequencer-client/automine';
|
|
50
|
-
import { PublicContractsDB, PublicProcessorFactory } from '@aztec/simulator/server';
|
|
51
|
-
import {
|
|
52
|
-
AttestationsBlockWatcher,
|
|
53
|
-
AttestedInvalidProposalWatcher,
|
|
54
|
-
BroadcastedInvalidCheckpointProposalWatcher,
|
|
55
|
-
CheckpointEquivocationWatcher,
|
|
56
|
-
DataWithholdingWatcher,
|
|
57
|
-
type SlasherClientInterface,
|
|
58
|
-
type Watcher,
|
|
59
|
-
createSlasher,
|
|
60
|
-
} from '@aztec/slasher';
|
|
29
|
+
import type { ProverNode } from '@aztec/prover-node';
|
|
30
|
+
import { SequencerClient } from '@aztec/sequencer-client';
|
|
31
|
+
import { AutomineSequencer } from '@aztec/sequencer-client/automine';
|
|
32
|
+
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
61
33
|
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
62
|
-
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
63
34
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
64
35
|
import {
|
|
65
36
|
type BlockData,
|
|
66
37
|
BlockHash,
|
|
67
38
|
type BlockParameter,
|
|
68
|
-
BlockTag,
|
|
69
39
|
type CheckpointsQuery,
|
|
70
|
-
type CommitteeAttestation,
|
|
71
40
|
type DataInBlock,
|
|
72
41
|
type L2BlockSource,
|
|
42
|
+
type L2BlockTag,
|
|
73
43
|
type L2Tips,
|
|
74
|
-
type NormalizedBlockParameter,
|
|
75
44
|
inspectBlockParameter,
|
|
76
45
|
} from '@aztec/stdlib/block';
|
|
77
|
-
import {
|
|
78
|
-
type CheckpointData,
|
|
79
|
-
CheckpointReexecutionTracker,
|
|
80
|
-
L1PublishedData,
|
|
81
|
-
type PublishedCheckpoint,
|
|
82
|
-
} from '@aztec/stdlib/checkpoint';
|
|
83
46
|
import type {
|
|
84
47
|
ContractClassPublic,
|
|
85
48
|
ContractDataSource,
|
|
@@ -87,9 +50,7 @@ import type {
|
|
|
87
50
|
NodeInfo,
|
|
88
51
|
ProtocolContractAddresses,
|
|
89
52
|
} from '@aztec/stdlib/contract';
|
|
90
|
-
import { getEpochAtSlot } from '@aztec/stdlib/epoch-helpers';
|
|
91
53
|
import { GasFees, type ManaUsageEstimate, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
92
|
-
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
93
54
|
import type {
|
|
94
55
|
AztecNode,
|
|
95
56
|
AztecNodeAdmin,
|
|
@@ -98,11 +59,10 @@ import type {
|
|
|
98
59
|
BlockIncludeOptions,
|
|
99
60
|
BlockResponse,
|
|
100
61
|
BlocksIncludeOptions,
|
|
101
|
-
ChainTip,
|
|
102
|
-
ChainTips,
|
|
103
62
|
CheckpointIncludeOptions,
|
|
104
63
|
CheckpointParameter,
|
|
105
64
|
CheckpointResponse,
|
|
65
|
+
CheckpointTag,
|
|
106
66
|
GetTxByHashOptions,
|
|
107
67
|
PeerInfo,
|
|
108
68
|
ProposalsForSlot,
|
|
@@ -118,38 +78,24 @@ import {
|
|
|
118
78
|
tryStop,
|
|
119
79
|
} from '@aztec/stdlib/interfaces/server';
|
|
120
80
|
import type { DebugLogStore, LogResult, PrivateLogsQuery, PublicLogsQuery } from '@aztec/stdlib/logs';
|
|
121
|
-
import {
|
|
122
|
-
import {
|
|
123
|
-
InboxLeaf,
|
|
124
|
-
type L1ToL2MessageSource,
|
|
125
|
-
type L2ToL1MembershipWitness,
|
|
126
|
-
appendL1ToL2MessagesToTree,
|
|
127
|
-
} from '@aztec/stdlib/messaging';
|
|
81
|
+
import { NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
82
|
+
import type { L1ToL2MessageSource, L2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
128
83
|
import type { CheckpointAttestation } from '@aztec/stdlib/p2p';
|
|
129
84
|
import type { Offense } from '@aztec/stdlib/slashing';
|
|
130
|
-
import type { NullifierLeafPreimage, PublicDataTreeLeafPreimage } from '@aztec/stdlib/trees';
|
|
131
85
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
132
86
|
import {
|
|
133
|
-
DroppedTxReceipt,
|
|
134
87
|
type FeeProvider,
|
|
135
88
|
type GetTxReceiptOptions,
|
|
136
89
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
137
|
-
GlobalVariables,
|
|
138
90
|
type IndexedTxEffect,
|
|
139
|
-
MinedTxReceipt,
|
|
140
|
-
type MinedTxStatus,
|
|
141
|
-
PendingTxReceipt,
|
|
142
91
|
PublicSimulationOutput,
|
|
143
92
|
type SimulationOverrides,
|
|
144
93
|
Tx,
|
|
145
94
|
type TxHash,
|
|
146
95
|
type TxReceipt,
|
|
147
|
-
TxStatus,
|
|
148
96
|
type TxValidationResult,
|
|
149
97
|
} from '@aztec/stdlib/tx';
|
|
150
|
-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
151
98
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
152
|
-
import type { GenesisData } from '@aztec/stdlib/world-state';
|
|
153
99
|
import {
|
|
154
100
|
Attributes,
|
|
155
101
|
type TelemetryClient,
|
|
@@ -158,31 +104,51 @@ import {
|
|
|
158
104
|
getTelemetryClient,
|
|
159
105
|
trackSpan,
|
|
160
106
|
} from '@aztec/telemetry-client';
|
|
161
|
-
import {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
createProposalHandler,
|
|
167
|
-
createValidatorClient,
|
|
168
|
-
} from '@aztec/validator-client';
|
|
169
|
-
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
170
|
-
import { createWorldState, createWorldStateSynchronizer } from '@aztec/world-state';
|
|
171
|
-
|
|
172
|
-
import { createPublicClient } from 'viem';
|
|
173
|
-
|
|
174
|
-
import { createSentinel } from '../sentinel/factory.js';
|
|
107
|
+
import { NodeKeystoreAdapter, ValidatorClient } from '@aztec/validator-client';
|
|
108
|
+
|
|
109
|
+
import { NodeBlockProvider } from '../modules/node_block_provider.js';
|
|
110
|
+
import { NodeTxReceiptBuilder } from '../modules/node_tx_receipt.js';
|
|
111
|
+
import { NodeWorldStateQueries } from '../modules/node_world_state_queries.js';
|
|
175
112
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
176
|
-
import {
|
|
177
|
-
blockResponseFromBlockData,
|
|
178
|
-
blockResponseFromL2Block,
|
|
179
|
-
checkpointResponseFromCheckpointData,
|
|
180
|
-
checkpointResponseFromPublishedCheckpoint,
|
|
181
|
-
projectProposedToCheckpointResponse,
|
|
182
|
-
} from './block_response_helpers.js';
|
|
183
|
-
import { type AztecNodeConfig, createKeyStoreForValidator } from './config.js';
|
|
113
|
+
import type { AztecNodeConfig } from './config.js';
|
|
184
114
|
import { NodeMetrics } from './node_metrics.js';
|
|
185
|
-
import {
|
|
115
|
+
import { NodePublicCallsSimulator } from './node_public_calls_simulator.js';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Fully-constructed collaborators and settings an {@link AztecNodeService} owns. Built by `createAztecNodeService`
|
|
119
|
+
* (see `factory.ts`); passed as a single object so call sites name each dependency instead of relying on
|
|
120
|
+
* positional order.
|
|
121
|
+
*/
|
|
122
|
+
export interface AztecNodeServiceDeps {
|
|
123
|
+
config: AztecNodeConfig;
|
|
124
|
+
p2pClient: P2P;
|
|
125
|
+
blockSource: L2BlockSource & Partial<Service>;
|
|
126
|
+
logsSource: L2LogsSource;
|
|
127
|
+
contractDataSource: ContractDataSource;
|
|
128
|
+
l1ToL2MessageSource: L1ToL2MessageSource;
|
|
129
|
+
worldStateSynchronizer: WorldStateSynchronizer;
|
|
130
|
+
sequencer: SequencerClient | undefined;
|
|
131
|
+
proverNode: ProverNode | undefined;
|
|
132
|
+
slasherClient: SlasherClientInterface | undefined;
|
|
133
|
+
validatorsSentinel: Sentinel | undefined;
|
|
134
|
+
stopStartedWatchers: () => Promise<void>;
|
|
135
|
+
l1ChainId: number;
|
|
136
|
+
version: number;
|
|
137
|
+
globalVariableBuilder: GlobalVariableBuilderInterface;
|
|
138
|
+
rollupContract: RollupContract | undefined;
|
|
139
|
+
feeProvider: FeeProvider;
|
|
140
|
+
epochCache: EpochCacheInterface;
|
|
141
|
+
packageVersion: string;
|
|
142
|
+
peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
143
|
+
rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
144
|
+
telemetry?: TelemetryClient;
|
|
145
|
+
log?: Logger;
|
|
146
|
+
blobClient?: BlobClientInterface;
|
|
147
|
+
validatorClient?: ValidatorClient;
|
|
148
|
+
keyStoreManager?: KeystoreManager;
|
|
149
|
+
debugLogStore?: DebugLogStore;
|
|
150
|
+
automineSequencer?: AutomineSequencer;
|
|
151
|
+
}
|
|
186
152
|
|
|
187
153
|
/**
|
|
188
154
|
* The aztec node.
|
|
@@ -193,48 +159,113 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
193
159
|
private isUploadingSnapshot = false;
|
|
194
160
|
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
195
161
|
private sequencerPausedMinTxsPerBlock: number | undefined;
|
|
162
|
+
private readonly nodePublicCallsSimulator: NodePublicCallsSimulator;
|
|
163
|
+
private readonly worldStateQueries: NodeWorldStateQueries;
|
|
164
|
+
private readonly blockProvider: NodeBlockProvider;
|
|
165
|
+
private readonly txReceiptBuilder: NodeTxReceiptBuilder;
|
|
196
166
|
|
|
197
167
|
public readonly tracer: Tracer;
|
|
198
168
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
this.
|
|
169
|
+
protected config: AztecNodeConfig;
|
|
170
|
+
protected readonly p2pClient: P2P;
|
|
171
|
+
protected readonly blockSource: L2BlockSource & Partial<Service>;
|
|
172
|
+
protected readonly logsSource: L2LogsSource;
|
|
173
|
+
protected readonly contractDataSource: ContractDataSource;
|
|
174
|
+
protected readonly l1ToL2MessageSource: L1ToL2MessageSource;
|
|
175
|
+
protected readonly worldStateSynchronizer: WorldStateSynchronizer;
|
|
176
|
+
protected readonly sequencer: SequencerClient | undefined;
|
|
177
|
+
protected readonly proverNode: ProverNode | undefined;
|
|
178
|
+
protected readonly slasherClient: SlasherClientInterface | undefined;
|
|
179
|
+
protected readonly validatorsSentinel: Sentinel | undefined;
|
|
180
|
+
private readonly stopStartedWatchers: () => Promise<void>;
|
|
181
|
+
protected readonly l1ChainId: number;
|
|
182
|
+
protected readonly version: number;
|
|
183
|
+
protected readonly globalVariableBuilder: GlobalVariableBuilderInterface;
|
|
184
|
+
protected readonly rollupContract: RollupContract | undefined;
|
|
185
|
+
protected readonly feeProvider: FeeProvider;
|
|
186
|
+
protected readonly epochCache: EpochCacheInterface;
|
|
187
|
+
protected readonly packageVersion: string;
|
|
188
|
+
private peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
189
|
+
private rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
190
|
+
private telemetry: TelemetryClient;
|
|
191
|
+
private log: Logger;
|
|
192
|
+
private blobClient?: BlobClientInterface;
|
|
193
|
+
private validatorClient?: ValidatorClient;
|
|
194
|
+
private keyStoreManager?: KeystoreManager;
|
|
195
|
+
private debugLogStore: DebugLogStore;
|
|
196
|
+
private readonly automineSequencer?: AutomineSequencer;
|
|
197
|
+
|
|
198
|
+
constructor(deps: AztecNodeServiceDeps) {
|
|
199
|
+
this.config = deps.config;
|
|
200
|
+
this.p2pClient = deps.p2pClient;
|
|
201
|
+
this.blockSource = deps.blockSource;
|
|
202
|
+
this.logsSource = deps.logsSource;
|
|
203
|
+
this.contractDataSource = deps.contractDataSource;
|
|
204
|
+
this.l1ToL2MessageSource = deps.l1ToL2MessageSource;
|
|
205
|
+
this.worldStateSynchronizer = deps.worldStateSynchronizer;
|
|
206
|
+
this.sequencer = deps.sequencer;
|
|
207
|
+
this.proverNode = deps.proverNode;
|
|
208
|
+
this.slasherClient = deps.slasherClient;
|
|
209
|
+
this.validatorsSentinel = deps.validatorsSentinel;
|
|
210
|
+
this.stopStartedWatchers = deps.stopStartedWatchers;
|
|
211
|
+
this.l1ChainId = deps.l1ChainId;
|
|
212
|
+
this.version = deps.version;
|
|
213
|
+
this.globalVariableBuilder = deps.globalVariableBuilder;
|
|
214
|
+
this.rollupContract = deps.rollupContract;
|
|
215
|
+
this.feeProvider = deps.feeProvider;
|
|
216
|
+
this.epochCache = deps.epochCache;
|
|
217
|
+
this.packageVersion = deps.packageVersion;
|
|
218
|
+
this.peerProofVerifier = deps.peerProofVerifier;
|
|
219
|
+
this.rpcProofVerifier = deps.rpcProofVerifier;
|
|
220
|
+
this.telemetry = deps.telemetry ?? getTelemetryClient();
|
|
221
|
+
this.log = deps.log ?? createLogger('node');
|
|
222
|
+
this.blobClient = deps.blobClient;
|
|
223
|
+
this.validatorClient = deps.validatorClient;
|
|
224
|
+
this.keyStoreManager = deps.keyStoreManager;
|
|
225
|
+
this.debugLogStore = deps.debugLogStore ?? new NullDebugLogStore();
|
|
226
|
+
this.automineSequencer = deps.automineSequencer;
|
|
227
|
+
|
|
228
|
+
this.metrics = new NodeMetrics(this.telemetry, 'AztecNodeService');
|
|
229
|
+
this.tracer = this.telemetry.getTracer('AztecNodeService');
|
|
230
|
+
|
|
231
|
+
// The node never represents a proposer's payout addresses, so the simulator zeroes coinbase and
|
|
232
|
+
// fee recipient. The signature context only needs chain id + rollup address (see signature_utils).
|
|
233
|
+
this.nodePublicCallsSimulator = new NodePublicCallsSimulator({
|
|
234
|
+
blockSource: this.blockSource,
|
|
235
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
236
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
237
|
+
contractDataSource: this.contractDataSource,
|
|
238
|
+
globalVariableBuilder: this.globalVariableBuilder,
|
|
239
|
+
rollupContract: this.rollupContract,
|
|
240
|
+
epochCache: this.epochCache,
|
|
241
|
+
signatureContext: { chainId: this.l1ChainId, rollupAddress: this.config.rollupAddress },
|
|
242
|
+
config: this.config,
|
|
243
|
+
telemetry: this.telemetry,
|
|
244
|
+
log: this.log.createChild('public-calls-simulator'),
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
this.worldStateQueries = new NodeWorldStateQueries({
|
|
248
|
+
worldStateSynchronizer: this.worldStateSynchronizer,
|
|
249
|
+
blockSource: this.blockSource,
|
|
250
|
+
l1ToL2MessageSource: this.l1ToL2MessageSource,
|
|
251
|
+
log: this.log.createChild('world-state-queries'),
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
this.blockProvider = new NodeBlockProvider(this.blockSource);
|
|
255
|
+
|
|
256
|
+
this.txReceiptBuilder = new NodeTxReceiptBuilder({
|
|
257
|
+
p2pClient: this.p2pClient,
|
|
258
|
+
blockSource: this.blockSource,
|
|
259
|
+
debugLogStore: this.debugLogStore,
|
|
260
|
+
});
|
|
230
261
|
|
|
231
262
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
232
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, pickL1ContractAddresses(config));
|
|
263
|
+
this.log.info(`Aztec Node started on chain 0x${this.l1ChainId.toString(16)}`, pickL1ContractAddresses(this.config));
|
|
233
264
|
|
|
234
|
-
// A defensive check that protects us against introducing a bug in the complex
|
|
265
|
+
// A defensive check that protects us against introducing a bug in the complex node creation flow. We must
|
|
235
266
|
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
236
267
|
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
237
|
-
if (debugLogStore.isEnabled && config.realProofs) {
|
|
268
|
+
if (this.debugLogStore.isEnabled && this.config.realProofs) {
|
|
238
269
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
239
270
|
}
|
|
240
271
|
}
|
|
@@ -249,9 +280,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
249
280
|
return status.syncSummary;
|
|
250
281
|
}
|
|
251
282
|
|
|
252
|
-
public
|
|
253
|
-
|
|
254
|
-
return { proposed, checkpointed, proven, finalized };
|
|
283
|
+
public getChainTips(): Promise<L2Tips> {
|
|
284
|
+
return this.blockSource.getL2Tips();
|
|
255
285
|
}
|
|
256
286
|
|
|
257
287
|
public getL1Constants() {
|
|
@@ -274,21 +304,19 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
274
304
|
return this.blockSource.getCheckpointsData(query);
|
|
275
305
|
}
|
|
276
306
|
|
|
277
|
-
public async getBlockNumber(tip?:
|
|
307
|
+
public async getBlockNumber(tip?: L2BlockTag): Promise<BlockNumber> {
|
|
278
308
|
if (tip === undefined || tip === 'proposed') {
|
|
279
309
|
return this.blockSource.getBlockNumber();
|
|
280
310
|
}
|
|
281
311
|
return (await this.blockSource.getBlockNumber({ tag: tip })) ?? BlockNumber.ZERO;
|
|
282
312
|
}
|
|
283
313
|
|
|
284
|
-
public async getCheckpointNumber(tip?:
|
|
314
|
+
public async getCheckpointNumber(tip?: CheckpointTag): Promise<CheckpointNumber> {
|
|
285
315
|
const tips = await this.blockSource.getL2Tips();
|
|
286
316
|
switch (tip) {
|
|
287
317
|
case undefined:
|
|
288
318
|
case 'checkpointed':
|
|
289
319
|
return tips.checkpointed.checkpoint.number;
|
|
290
|
-
case 'proposed':
|
|
291
|
-
return tips.proposedCheckpoint.checkpoint.number;
|
|
292
320
|
case 'proven':
|
|
293
321
|
return tips.proven.checkpoint.number;
|
|
294
322
|
case 'finalized':
|
|
@@ -296,786 +324,38 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
296
324
|
}
|
|
297
325
|
}
|
|
298
326
|
|
|
299
|
-
|
|
300
|
-
return value === 'proposed' || value === 'checkpointed' || value === 'proven' || value === 'finalized';
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Normalizes a {@link BlockParameter} (which may be a bare value) into a
|
|
305
|
-
* {@link NormalizedBlockParameter} object form. Performs no chain-tip resolution — tag
|
|
306
|
-
* lookups are deferred to the underlying block source.
|
|
307
|
-
*/
|
|
308
|
-
private normalizeBlockParameter(param: BlockParameter): NormalizedBlockParameter {
|
|
309
|
-
if (BlockHash.isBlockHash(param)) {
|
|
310
|
-
return { hash: param };
|
|
311
|
-
}
|
|
312
|
-
if (typeof param === 'number') {
|
|
313
|
-
return { number: param as BlockNumber };
|
|
314
|
-
}
|
|
315
|
-
if (typeof param === 'string') {
|
|
316
|
-
if (this.isBlockTag(param)) {
|
|
317
|
-
return { tag: param === 'latest' ? 'proposed' : param };
|
|
318
|
-
}
|
|
319
|
-
throw new BadRequestError(`Invalid BlockParameter tag: ${param}`);
|
|
320
|
-
}
|
|
321
|
-
if (typeof param === 'object' && param !== null) {
|
|
322
|
-
if ('number' in param) {
|
|
323
|
-
return { number: param.number };
|
|
324
|
-
}
|
|
325
|
-
if ('hash' in param) {
|
|
326
|
-
return { hash: param.hash };
|
|
327
|
-
}
|
|
328
|
-
if ('archive' in param) {
|
|
329
|
-
return { archive: param.archive };
|
|
330
|
-
}
|
|
331
|
-
if ('tag' in param) {
|
|
332
|
-
if (this.isBlockTag(param.tag)) {
|
|
333
|
-
return { tag: param.tag };
|
|
334
|
-
}
|
|
335
|
-
throw new BadRequestError(`Invalid BlockParameter tag: ${param.tag}`);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
throw new BadRequestError(`Invalid BlockParameter: ${JSON.stringify(param)}`);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
private isBlockTag(value: string): value is BlockTag {
|
|
342
|
-
return BlockTag.includes(value as BlockTag);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* Resolves a {@link CheckpointParameter} into a concrete `{ number }` or `{ slot }` query.
|
|
347
|
-
*
|
|
348
|
-
* Tag-based parameters (`'proposed'`, `'checkpointed'`, `'proven'`, `'finalized'`) are
|
|
349
|
-
* translated up-front to the corresponding tip's checkpoint number via {@link L2BlockSource.getL2Tips}.
|
|
350
|
-
* After resolution the unified {@link getCheckpoint} flow can perform a single
|
|
351
|
-
* confirmed→proposed lookup against either store.
|
|
352
|
-
*/
|
|
353
|
-
private async resolveCheckpointParameter(
|
|
354
|
-
param: CheckpointParameter,
|
|
355
|
-
): Promise<{ number: CheckpointNumber } | { slot: SlotNumber }> {
|
|
356
|
-
if (typeof param === 'number') {
|
|
357
|
-
return { number: param as CheckpointNumber };
|
|
358
|
-
}
|
|
359
|
-
if (this.isChainTip(param)) {
|
|
360
|
-
const tips = await this.blockSource.getL2Tips();
|
|
361
|
-
switch (param) {
|
|
362
|
-
case 'proposed':
|
|
363
|
-
return { number: tips.proposedCheckpoint.checkpoint.number };
|
|
364
|
-
case 'checkpointed':
|
|
365
|
-
return { number: tips.checkpointed.checkpoint.number };
|
|
366
|
-
case 'proven':
|
|
367
|
-
return { number: tips.proven.checkpoint.number };
|
|
368
|
-
case 'finalized':
|
|
369
|
-
return { number: tips.finalized.checkpoint.number };
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (typeof param === 'object' && param !== null) {
|
|
373
|
-
if ('number' in param) {
|
|
374
|
-
return { number: param.number };
|
|
375
|
-
}
|
|
376
|
-
if ('slot' in param) {
|
|
377
|
-
return { slot: param.slot };
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
throw new BadRequestError(`Invalid CheckpointParameter: ${JSON.stringify(param)}`);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/** Fetches checkpoint-level L1 and attestation data for use as block response context. */
|
|
384
|
-
async #getCheckpointContext(
|
|
385
|
-
checkpointNumber: CheckpointNumber,
|
|
386
|
-
): Promise<{ l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined> {
|
|
387
|
-
const checkpoint = await this.blockSource.getCheckpointData({ number: checkpointNumber });
|
|
388
|
-
if (!checkpoint) {
|
|
389
|
-
return undefined;
|
|
390
|
-
}
|
|
391
|
-
return { l1: checkpoint.l1, attestations: checkpoint.attestations };
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
public async getBlock<Opts extends BlockIncludeOptions = {}>(
|
|
327
|
+
public getBlock<Opts extends BlockIncludeOptions = {}>(
|
|
395
328
|
param: BlockParameter,
|
|
396
329
|
options: Opts = {} as Opts,
|
|
397
330
|
): Promise<BlockResponse<Opts> | undefined> {
|
|
398
|
-
|
|
399
|
-
const wantTxs = !!options.includeTransactions;
|
|
400
|
-
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
401
|
-
|
|
402
|
-
if (wantTxs) {
|
|
403
|
-
const block = await this.blockSource.getBlock(query);
|
|
404
|
-
if (!block) {
|
|
405
|
-
return undefined;
|
|
406
|
-
}
|
|
407
|
-
const ctx = wantContext ? await this.#getCheckpointContext(block.checkpointNumber) : undefined;
|
|
408
|
-
return (await blockResponseFromL2Block(block, options, ctx)) as BlockResponse<Opts>;
|
|
409
|
-
}
|
|
410
|
-
const data = await this.blockSource.getBlockData(query);
|
|
411
|
-
if (!data) {
|
|
412
|
-
return undefined;
|
|
413
|
-
}
|
|
414
|
-
const ctx = wantContext ? await this.#getCheckpointContext(data.checkpointNumber) : undefined;
|
|
415
|
-
return blockResponseFromBlockData(data, options, ctx) as BlockResponse<Opts>;
|
|
331
|
+
return this.blockProvider.getBlock(param, options);
|
|
416
332
|
}
|
|
417
333
|
|
|
418
334
|
public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
|
|
419
|
-
|
|
420
|
-
return this.blockSource.getBlockData(query);
|
|
335
|
+
return this.blockProvider.getBlockData(param);
|
|
421
336
|
}
|
|
422
337
|
|
|
423
|
-
public
|
|
338
|
+
public getBlocks<Opts extends BlocksIncludeOptions = {}>(
|
|
424
339
|
from: BlockNumber,
|
|
425
340
|
limit: number,
|
|
426
341
|
options: Opts = {} as Opts,
|
|
427
342
|
): Promise<BlockResponse<Opts>[]> {
|
|
428
|
-
|
|
429
|
-
const wantContext = !!options.includeL1PublishInfo || !!options.includeAttestations;
|
|
430
|
-
const onlyCheckpointed = !!options.onlyCheckpointed;
|
|
431
|
-
if (wantTxs) {
|
|
432
|
-
const blocks = await this.blockSource.getBlocks({ from, limit, onlyCheckpointed });
|
|
433
|
-
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? blocks : []);
|
|
434
|
-
return (await Promise.all(
|
|
435
|
-
blocks.map(block => blockResponseFromL2Block(block, options, ctxByCheckpoint.get(block.checkpointNumber))),
|
|
436
|
-
)) as BlockResponse<Opts>[];
|
|
437
|
-
}
|
|
438
|
-
const dataItems = await this.blockSource.getBlocksData({ from, limit, onlyCheckpointed });
|
|
439
|
-
const ctxByCheckpoint = await this.#getCheckpointContextsForBlocks(wantContext ? dataItems : []);
|
|
440
|
-
return (await Promise.all(
|
|
441
|
-
dataItems.map(data => blockResponseFromBlockData(data, options, ctxByCheckpoint.get(data.checkpointNumber))),
|
|
442
|
-
)) as BlockResponse<Opts>[];
|
|
343
|
+
return this.blockProvider.getBlocks(from, limit, options);
|
|
443
344
|
}
|
|
444
345
|
|
|
445
|
-
|
|
446
|
-
async #getCheckpointContextsForBlocks(
|
|
447
|
-
blocks: { checkpointNumber: CheckpointNumber }[],
|
|
448
|
-
): Promise<Map<CheckpointNumber, { l1?: L1PublishedData; attestations?: CommitteeAttestation[] } | undefined>> {
|
|
449
|
-
const unique = Array.from(new Set(blocks.map(b => b.checkpointNumber)));
|
|
450
|
-
const entries = await Promise.all(unique.map(async n => [n, await this.#getCheckpointContext(n)] as const));
|
|
451
|
-
return new Map(entries);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
public async getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
|
|
346
|
+
public getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
|
|
455
347
|
param: CheckpointParameter,
|
|
456
348
|
options: Opts = {} as Opts,
|
|
457
349
|
): Promise<CheckpointResponse<Opts> | undefined> {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
// Try the confirmed store first.
|
|
461
|
-
const confirmed = options.includeBlocks
|
|
462
|
-
? await this.blockSource.getCheckpoint(query)
|
|
463
|
-
: await this.blockSource.getCheckpointData(query);
|
|
464
|
-
if (confirmed) {
|
|
465
|
-
return (await (options.includeBlocks
|
|
466
|
-
? checkpointResponseFromPublishedCheckpoint(confirmed as PublishedCheckpoint, options)
|
|
467
|
-
: checkpointResponseFromCheckpointData(confirmed as CheckpointData, options))) as CheckpointResponse<Opts>;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// Fall back to the proposed store.
|
|
471
|
-
const proposed = await this.blockSource.getProposedCheckpointData(query);
|
|
472
|
-
if (proposed) {
|
|
473
|
-
if (options.includeAttestations || options.includeL1PublishInfo) {
|
|
474
|
-
throw new BadRequestError(
|
|
475
|
-
`Options includeL1PublishInfo or includeAttestations cannot be satisfied for a proposed checkpoint`,
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
const blocks = options.includeBlocks
|
|
479
|
-
? await this.blockSource.getBlocks({ from: proposed.startBlock, limit: proposed.blockCount })
|
|
480
|
-
: undefined;
|
|
481
|
-
return (await projectProposedToCheckpointResponse(proposed, options, blocks)) as CheckpointResponse<Opts>;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
return undefined;
|
|
350
|
+
return this.blockProvider.getCheckpoint(param, options);
|
|
485
351
|
}
|
|
486
352
|
|
|
487
|
-
public
|
|
353
|
+
public getCheckpoints<Opts extends CheckpointIncludeOptions = {}>(
|
|
488
354
|
from: CheckpointNumber,
|
|
489
355
|
limit: number,
|
|
490
356
|
options: Opts = {} as Opts,
|
|
491
357
|
): Promise<CheckpointResponse<Opts>[]> {
|
|
492
|
-
|
|
493
|
-
const checkpoints = await this.blockSource.getCheckpoints({ from, limit });
|
|
494
|
-
return (await Promise.all(
|
|
495
|
-
checkpoints.map(cp => checkpointResponseFromPublishedCheckpoint(cp, options)),
|
|
496
|
-
)) as CheckpointResponse<Opts>[];
|
|
497
|
-
}
|
|
498
|
-
const datas = await this.blockSource.getCheckpointsData({ from, limit });
|
|
499
|
-
return datas.map(d => checkpointResponseFromCheckpointData(d, options)) as CheckpointResponse<Opts>[];
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* initializes the Aztec Node, wait for component to sync.
|
|
504
|
-
* @param config - The configuration to be used by the aztec node.
|
|
505
|
-
* @returns - A fully synced Aztec Node for use in development/testing.
|
|
506
|
-
*/
|
|
507
|
-
public static async createAndSync(
|
|
508
|
-
inputConfig: AztecNodeConfig,
|
|
509
|
-
deps: {
|
|
510
|
-
telemetry?: TelemetryClient;
|
|
511
|
-
logger?: Logger;
|
|
512
|
-
publisher?: SequencerPublisher;
|
|
513
|
-
dateProvider?: DateProvider;
|
|
514
|
-
p2pClientDeps?: P2PClientDeps;
|
|
515
|
-
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
516
|
-
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
517
|
-
} = {},
|
|
518
|
-
options: {
|
|
519
|
-
genesis?: GenesisData;
|
|
520
|
-
dontStartSequencer?: boolean;
|
|
521
|
-
dontStartProverNode?: boolean;
|
|
522
|
-
} = {},
|
|
523
|
-
): Promise<AztecNodeService> {
|
|
524
|
-
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
525
|
-
const log = deps.logger ?? createLogger('node');
|
|
526
|
-
const packageVersion = getPackageVersion();
|
|
527
|
-
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
528
|
-
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
529
|
-
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
530
|
-
|
|
531
|
-
// Build a key store from file if given or from environment otherwise.
|
|
532
|
-
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
533
|
-
let keyStoreManager: KeystoreManager | undefined;
|
|
534
|
-
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
535
|
-
if (keyStoreProvided) {
|
|
536
|
-
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
537
|
-
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
538
|
-
} else {
|
|
539
|
-
const rawKeyStores: KeyStore[] = [];
|
|
540
|
-
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
541
|
-
if (validatorKeyStore) {
|
|
542
|
-
rawKeyStores.push(validatorKeyStore);
|
|
543
|
-
}
|
|
544
|
-
if (config.enableProverNode) {
|
|
545
|
-
const proverKeyStore = createKeyStoreForProver(config);
|
|
546
|
-
if (proverKeyStore) {
|
|
547
|
-
rawKeyStores.push(proverKeyStore);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
if (rawKeyStores.length > 0) {
|
|
551
|
-
keyStoreManager = new KeystoreManager(
|
|
552
|
-
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
await keyStoreManager?.validateSigners();
|
|
558
|
-
|
|
559
|
-
// If we are a validator, verify our configuration before doing too much more.
|
|
560
|
-
if (!config.disableValidator) {
|
|
561
|
-
if (keyStoreManager === undefined) {
|
|
562
|
-
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
563
|
-
}
|
|
564
|
-
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
565
|
-
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
566
|
-
}
|
|
567
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// validate that the actual chain id matches that specified in configuration
|
|
571
|
-
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
572
|
-
throw new Error(
|
|
573
|
-
`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`,
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
const publicClient = createPublicClient({
|
|
578
|
-
chain: ethereumChain.chainInfo,
|
|
579
|
-
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
580
|
-
pollingInterval: config.viemPollingIntervalMS,
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(
|
|
584
|
-
publicClient,
|
|
585
|
-
config.registryAddress,
|
|
586
|
-
config.rollupVersion ?? 'canonical',
|
|
587
|
-
);
|
|
588
|
-
|
|
589
|
-
Object.assign(config, l1ContractsAddresses);
|
|
590
|
-
|
|
591
|
-
const rollupContract = new RollupContract(publicClient, config.rollupAddress.toString());
|
|
592
|
-
const [l1GenesisTime, slotDuration, epochDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
593
|
-
rollupContract.getL1GenesisTime(),
|
|
594
|
-
rollupContract.getSlotDuration(),
|
|
595
|
-
rollupContract.getEpochDuration(),
|
|
596
|
-
rollupContract.getVersion(),
|
|
597
|
-
rollupContract.getManaLimit().then(Number),
|
|
598
|
-
] as const);
|
|
599
|
-
|
|
600
|
-
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
601
|
-
|
|
602
|
-
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
603
|
-
log.warn(
|
|
604
|
-
`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
|
|
605
|
-
);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
609
|
-
|
|
610
|
-
// attempt snapshot sync if possible
|
|
611
|
-
await trySnapshotSync(config, log);
|
|
612
|
-
|
|
613
|
-
const epochCache = await EpochCache.create(config.rollupAddress, config, { dateProvider });
|
|
614
|
-
|
|
615
|
-
// Track started resources so we can clean up on partial failure during node creation.
|
|
616
|
-
const started: { stop?(): Promise<void> | void }[] = [];
|
|
617
|
-
try {
|
|
618
|
-
config.skipOrphanProposedBlockPruning ||= !!config.useAutomineSequencer;
|
|
619
|
-
|
|
620
|
-
AztecNodeService.checkConfigMatchesRollup(config, {
|
|
621
|
-
slotDuration: Number(slotDuration),
|
|
622
|
-
epochDuration: Number(epochDuration),
|
|
623
|
-
});
|
|
624
|
-
|
|
625
|
-
// Create world-state first so we can retrieve the initial header before constructing the archiver.
|
|
626
|
-
const nativeWs = await createWorldState(config, options.genesis);
|
|
627
|
-
const initialHeader = nativeWs.getInitialHeader();
|
|
628
|
-
const initialBlockHash = await initialHeader.hash();
|
|
629
|
-
const archiver = await createArchiver(
|
|
630
|
-
config,
|
|
631
|
-
{ blobClient, epochCache, telemetry, dateProvider },
|
|
632
|
-
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
633
|
-
initialHeader,
|
|
634
|
-
initialBlockHash,
|
|
635
|
-
);
|
|
636
|
-
started.push(archiver);
|
|
637
|
-
|
|
638
|
-
// The synchronizer takes ownership of the native world-state from here
|
|
639
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, nativeWs, telemetry);
|
|
640
|
-
started.push(worldStateSynchronizer);
|
|
641
|
-
const useRealVerifiers = config.realProofs || config.debugForceTxProofVerification;
|
|
642
|
-
let peerProofVerifier: ClientProtocolCircuitVerifier;
|
|
643
|
-
let rpcProofVerifier: ClientProtocolCircuitVerifier;
|
|
644
|
-
if (useRealVerifiers) {
|
|
645
|
-
peerProofVerifier = await BatchChonkVerifier.new(config, config.bbChonkVerifyMaxBatch, 'peer');
|
|
646
|
-
const rpcVerifier = await BBCircuitVerifier.new(config);
|
|
647
|
-
rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, config.numConcurrentIVCVerifiers);
|
|
648
|
-
} else {
|
|
649
|
-
peerProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
650
|
-
rpcProofVerifier = new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
651
|
-
}
|
|
652
|
-
started.push(peerProofVerifier, rpcProofVerifier);
|
|
653
|
-
|
|
654
|
-
let debugLogStore: DebugLogStore;
|
|
655
|
-
if (!config.realProofs) {
|
|
656
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
657
|
-
|
|
658
|
-
debugLogStore = new InMemoryDebugLogStore();
|
|
659
|
-
log.info(
|
|
660
|
-
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
661
|
-
);
|
|
662
|
-
} else {
|
|
663
|
-
debugLogStore = new NullDebugLogStore();
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
const globalVariableBuilderConfig = {
|
|
667
|
-
rollupAddress: config.rollupAddress,
|
|
668
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
669
|
-
rollupVersion: BigInt(config.rollupVersion),
|
|
670
|
-
l1GenesisTime,
|
|
671
|
-
slotDuration: Number(slotDuration),
|
|
672
|
-
};
|
|
673
|
-
|
|
674
|
-
const globalVariableBuilder = new GlobalVariableBuilder(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
675
|
-
const feeProvider = new FeeProviderImpl(dateProvider, publicClient, globalVariableBuilderConfig);
|
|
676
|
-
|
|
677
|
-
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
678
|
-
if (proverOnly) {
|
|
679
|
-
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
683
|
-
const p2pClient = await createP2PClient(
|
|
684
|
-
config,
|
|
685
|
-
archiver,
|
|
686
|
-
peerProofVerifier,
|
|
687
|
-
worldStateSynchronizer,
|
|
688
|
-
epochCache,
|
|
689
|
-
feeProvider,
|
|
690
|
-
packageVersion,
|
|
691
|
-
dateProvider,
|
|
692
|
-
telemetry,
|
|
693
|
-
deps.p2pClientDeps,
|
|
694
|
-
initialBlockHash,
|
|
695
|
-
);
|
|
696
|
-
started.push(p2pClient);
|
|
697
|
-
archiver.setCheckpointProposalPresence(p2pClient);
|
|
698
|
-
|
|
699
|
-
// We'll accumulate sentinel watchers here
|
|
700
|
-
const watchers: Watcher[] = [];
|
|
701
|
-
|
|
702
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
703
|
-
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
704
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
705
|
-
{
|
|
706
|
-
...config,
|
|
707
|
-
l1GenesisTime,
|
|
708
|
-
slotDuration: Number(slotDuration),
|
|
709
|
-
rollupManaLimit,
|
|
710
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
711
|
-
},
|
|
712
|
-
worldStateSynchronizer,
|
|
713
|
-
archiver,
|
|
714
|
-
dateProvider,
|
|
715
|
-
telemetry,
|
|
716
|
-
);
|
|
717
|
-
|
|
718
|
-
let validatorClient: ValidatorClient | undefined;
|
|
719
|
-
|
|
720
|
-
// Tracks successful checkpoint re-execution by a checkpoint proposal handler.
|
|
721
|
-
const reexecutionTracker = new CheckpointReexecutionTracker();
|
|
722
|
-
|
|
723
|
-
if (!config.disableValidator) {
|
|
724
|
-
// Create validator client if required
|
|
725
|
-
validatorClient = await createValidatorClient(config, {
|
|
726
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
727
|
-
worldState: worldStateSynchronizer,
|
|
728
|
-
p2pClient,
|
|
729
|
-
telemetry,
|
|
730
|
-
dateProvider,
|
|
731
|
-
epochCache,
|
|
732
|
-
blockSource: archiver,
|
|
733
|
-
l1ToL2MessageSource: archiver,
|
|
734
|
-
keyStoreManager,
|
|
735
|
-
blobClient,
|
|
736
|
-
reexecutionTracker,
|
|
737
|
-
slashingProtectionDb: deps.slashingProtectionDb,
|
|
738
|
-
});
|
|
739
|
-
|
|
740
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
741
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
742
|
-
// like attestations or auths will fail.
|
|
743
|
-
if (validatorClient) {
|
|
744
|
-
watchers.push(validatorClient);
|
|
745
|
-
|
|
746
|
-
const vc = validatorClient;
|
|
747
|
-
const getValidatorAddresses = () => vc.getValidatorAddresses().map(a => a.toString());
|
|
748
|
-
validatorClient.getProposalHandler().register(p2pClient, true, archiver, getValidatorAddresses);
|
|
749
|
-
|
|
750
|
-
if (!options.dontStartSequencer) {
|
|
751
|
-
await validatorClient.registerHandlers();
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// If there's no validator client, create a ProposalHandler to handle block and checkpoint proposals
|
|
757
|
-
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
758
|
-
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
759
|
-
// Checkpoint proposals rebuild blobs if the blob client can upload blobs.
|
|
760
|
-
if (!validatorClient) {
|
|
761
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
762
|
-
log.info(`Setting up proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
763
|
-
createProposalHandler(config, {
|
|
764
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
765
|
-
worldState: worldStateSynchronizer,
|
|
766
|
-
epochCache,
|
|
767
|
-
blockSource: archiver,
|
|
768
|
-
l1ToL2MessageSource: archiver,
|
|
769
|
-
p2pClient,
|
|
770
|
-
blobClient,
|
|
771
|
-
dateProvider,
|
|
772
|
-
telemetry,
|
|
773
|
-
reexecutionTracker,
|
|
774
|
-
}).register(p2pClient, reexecute, archiver);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
// Start world state and wait for it to sync to the archiver.
|
|
778
|
-
await worldStateSynchronizer.start();
|
|
779
|
-
|
|
780
|
-
// Start p2p. Note that it depends on world state to be running.
|
|
781
|
-
await p2pClient.start();
|
|
782
|
-
|
|
783
|
-
let validatorsSentinel: Awaited<ReturnType<typeof createSentinel>> | undefined;
|
|
784
|
-
let dataWithholdingWatcher: DataWithholdingWatcher | undefined;
|
|
785
|
-
let attestationsBlockWatcher: AttestationsBlockWatcher | undefined;
|
|
786
|
-
let attestedInvalidProposalWatcher: AttestedInvalidProposalWatcher | undefined;
|
|
787
|
-
let broadcastedInvalidCheckpointProposalWatcher: BroadcastedInvalidCheckpointProposalWatcher | undefined;
|
|
788
|
-
let checkpointEquivocationWatcher: CheckpointEquivocationWatcher | undefined;
|
|
789
|
-
|
|
790
|
-
if (!proverOnly) {
|
|
791
|
-
validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, reexecutionTracker, config);
|
|
792
|
-
if (validatorsSentinel) {
|
|
793
|
-
watchers.push(validatorsSentinel);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
dataWithholdingWatcher = new DataWithholdingWatcher(
|
|
797
|
-
epochCache,
|
|
798
|
-
archiver,
|
|
799
|
-
p2pClient.getTxProvider(),
|
|
800
|
-
p2pClient,
|
|
801
|
-
reexecutionTracker,
|
|
802
|
-
{ chainId: config.l1ChainId, rollupAddress: config.rollupAddress },
|
|
803
|
-
config,
|
|
804
|
-
);
|
|
805
|
-
watchers.push(dataWithholdingWatcher);
|
|
806
|
-
|
|
807
|
-
broadcastedInvalidCheckpointProposalWatcher = new BroadcastedInvalidCheckpointProposalWatcher(
|
|
808
|
-
p2pClient,
|
|
809
|
-
archiver,
|
|
810
|
-
epochCache,
|
|
811
|
-
config,
|
|
812
|
-
);
|
|
813
|
-
watchers.push(broadcastedInvalidCheckpointProposalWatcher);
|
|
814
|
-
|
|
815
|
-
if (validatorClient) {
|
|
816
|
-
attestedInvalidProposalWatcher = new AttestedInvalidProposalWatcher(
|
|
817
|
-
p2pClient,
|
|
818
|
-
validatorClient,
|
|
819
|
-
archiver,
|
|
820
|
-
epochCache,
|
|
821
|
-
config,
|
|
822
|
-
{ log: log.createChild('attested-invalid-proposal-watcher') },
|
|
823
|
-
);
|
|
824
|
-
watchers.push(attestedInvalidProposalWatcher);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
checkpointEquivocationWatcher = new CheckpointEquivocationWatcher(archiver, epochCache, config);
|
|
828
|
-
watchers.push(checkpointEquivocationWatcher);
|
|
829
|
-
|
|
830
|
-
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config, log.getBindings());
|
|
831
|
-
watchers.push(attestationsBlockWatcher);
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
const watchersToStart = compactArray([
|
|
835
|
-
validatorsSentinel,
|
|
836
|
-
dataWithholdingWatcher,
|
|
837
|
-
attestationsBlockWatcher,
|
|
838
|
-
broadcastedInvalidCheckpointProposalWatcher,
|
|
839
|
-
attestedInvalidProposalWatcher,
|
|
840
|
-
checkpointEquivocationWatcher,
|
|
841
|
-
]);
|
|
842
|
-
const startedWatchers: Watcher[] = [];
|
|
843
|
-
const stopStartedWatchers = async () => {
|
|
844
|
-
for (const watcher of startedWatchers) {
|
|
845
|
-
await tryStop(watcher);
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
|
|
849
|
-
// Start p2p-related services once the archiver has completed sync
|
|
850
|
-
void archiver
|
|
851
|
-
.waitForInitialSync()
|
|
852
|
-
.then(async () => {
|
|
853
|
-
for (const watcher of watchersToStart) {
|
|
854
|
-
await watcher.start();
|
|
855
|
-
startedWatchers.push(watcher);
|
|
856
|
-
}
|
|
857
|
-
log.info(`All p2p services started`);
|
|
858
|
-
})
|
|
859
|
-
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
860
|
-
started.push({ stop: stopStartedWatchers });
|
|
861
|
-
|
|
862
|
-
// Validator enabled, create/start relevant service
|
|
863
|
-
let sequencer: SequencerClient | undefined;
|
|
864
|
-
let automineSequencer: AutomineSequencer | undefined;
|
|
865
|
-
let slasherClient: SlasherClientInterface | undefined;
|
|
866
|
-
if (!config.disableValidator && validatorClient) {
|
|
867
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
868
|
-
// as they are executed when the node is selected as proposer.
|
|
869
|
-
const validatorAddresses = keyStoreManager
|
|
870
|
-
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
871
|
-
: [];
|
|
872
|
-
|
|
873
|
-
slasherClient = await createSlasher(
|
|
874
|
-
config,
|
|
875
|
-
pickL1ContractAddresses(config),
|
|
876
|
-
getPublicClient(config),
|
|
877
|
-
watchers,
|
|
878
|
-
dateProvider,
|
|
879
|
-
epochCache,
|
|
880
|
-
validatorAddresses,
|
|
881
|
-
undefined, // logger
|
|
882
|
-
);
|
|
883
|
-
await slasherClient.start();
|
|
884
|
-
started.push(slasherClient);
|
|
885
|
-
|
|
886
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
887
|
-
? await createForwarderL1TxUtilsFromSigners(
|
|
888
|
-
publicClient,
|
|
889
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
890
|
-
config.sequencerPublisherForwarderAddress,
|
|
891
|
-
{ ...config, scope: 'sequencer' },
|
|
892
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
893
|
-
)
|
|
894
|
-
: await createL1TxUtilsFromSigners(
|
|
895
|
-
publicClient,
|
|
896
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
897
|
-
{ ...config, scope: 'sequencer' },
|
|
898
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
899
|
-
);
|
|
900
|
-
|
|
901
|
-
// Create a funder L1TxUtils from the keystore funding account (if configured)
|
|
902
|
-
const fundingSigner = keyStoreManager?.createFundingSigner();
|
|
903
|
-
let funderL1TxUtils: L1TxUtils | undefined;
|
|
904
|
-
if (fundingSigner) {
|
|
905
|
-
const [funder] = await createL1TxUtilsFromSigners(
|
|
906
|
-
publicClient,
|
|
907
|
-
[fundingSigner],
|
|
908
|
-
{ ...config, scope: 'sequencer' },
|
|
909
|
-
{ telemetry, logger: log.createChild('l1-tx-utils:funder'), dateProvider },
|
|
910
|
-
);
|
|
911
|
-
funderL1TxUtils = funder;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
// Create and start the sequencer client
|
|
915
|
-
const checkpointsBuilder = new CheckpointsBuilder(
|
|
916
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
917
|
-
worldStateSynchronizer,
|
|
918
|
-
archiver,
|
|
919
|
-
dateProvider,
|
|
920
|
-
telemetry,
|
|
921
|
-
debugLogStore,
|
|
922
|
-
);
|
|
923
|
-
|
|
924
|
-
if (config.useAutomineSequencer) {
|
|
925
|
-
// Test-only path: deterministic, queue-driven sequencer for non-block-building e2e tests.
|
|
926
|
-
// See `AUTOMINE_E2E_OPTS` in `end-to-end/src/fixtures/fixtures.ts`.
|
|
927
|
-
automineSequencer = await createAutomineSequencer({
|
|
928
|
-
config,
|
|
929
|
-
l1TxUtils,
|
|
930
|
-
funderL1TxUtils,
|
|
931
|
-
publicClient,
|
|
932
|
-
rollupContract,
|
|
933
|
-
epochCache,
|
|
934
|
-
blobClient,
|
|
935
|
-
telemetry,
|
|
936
|
-
dateProvider,
|
|
937
|
-
keyStoreManager: keyStoreManager!,
|
|
938
|
-
validatorClient,
|
|
939
|
-
checkpointsBuilder,
|
|
940
|
-
globalVariableBuilder,
|
|
941
|
-
worldStateSynchronizer,
|
|
942
|
-
archiver,
|
|
943
|
-
p2pClient,
|
|
944
|
-
l1Constants: {
|
|
945
|
-
l1GenesisTime,
|
|
946
|
-
slotDuration: Number(slotDuration),
|
|
947
|
-
ethereumSlotDuration: config.ethereumSlotDuration,
|
|
948
|
-
rollupManaLimit,
|
|
949
|
-
},
|
|
950
|
-
autoSettle: config.automineEnableProveEpoch,
|
|
951
|
-
log,
|
|
952
|
-
});
|
|
953
|
-
} else {
|
|
954
|
-
sequencer = await SequencerClient.new(config, {
|
|
955
|
-
...deps,
|
|
956
|
-
epochCache,
|
|
957
|
-
l1TxUtils,
|
|
958
|
-
funderL1TxUtils,
|
|
959
|
-
validatorClient,
|
|
960
|
-
p2pClient,
|
|
961
|
-
worldStateSynchronizer,
|
|
962
|
-
slasherClient,
|
|
963
|
-
checkpointsBuilder,
|
|
964
|
-
l2BlockSource: archiver,
|
|
965
|
-
l1ToL2MessageSource: archiver,
|
|
966
|
-
telemetry,
|
|
967
|
-
dateProvider,
|
|
968
|
-
blobClient,
|
|
969
|
-
nodeKeyStore: keyStoreManager!,
|
|
970
|
-
globalVariableBuilder,
|
|
971
|
-
});
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
976
|
-
await sequencer.start();
|
|
977
|
-
started.push(sequencer);
|
|
978
|
-
log.verbose(`Sequencer started`);
|
|
979
|
-
} else if (sequencer) {
|
|
980
|
-
log.warn(`Sequencer created but not started`);
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
if (!options.dontStartSequencer && automineSequencer) {
|
|
984
|
-
await automineSequencer.start();
|
|
985
|
-
started.push({ stop: () => automineSequencer!.stop() });
|
|
986
|
-
log.verbose(`AutomineSequencer started`);
|
|
987
|
-
} else if (automineSequencer) {
|
|
988
|
-
log.warn(`AutomineSequencer created but not started`);
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
// Create prover node subsystem if enabled
|
|
992
|
-
let proverNode: ProverNode | undefined;
|
|
993
|
-
if (config.enableProverNode) {
|
|
994
|
-
proverNode = await createProverNode(config, {
|
|
995
|
-
...deps.proverNodeDeps,
|
|
996
|
-
telemetry,
|
|
997
|
-
dateProvider,
|
|
998
|
-
archiver,
|
|
999
|
-
worldStateSynchronizer,
|
|
1000
|
-
p2pClient,
|
|
1001
|
-
epochCache,
|
|
1002
|
-
blobClient,
|
|
1003
|
-
keyStoreManager,
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
if (!options.dontStartProverNode) {
|
|
1007
|
-
await proverNode.start();
|
|
1008
|
-
started.push(proverNode);
|
|
1009
|
-
log.info(`Prover node subsystem started`);
|
|
1010
|
-
} else {
|
|
1011
|
-
log.info(`Prover node subsystem created but not started`);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
const node = new AztecNodeService(
|
|
1016
|
-
config,
|
|
1017
|
-
p2pClient,
|
|
1018
|
-
archiver,
|
|
1019
|
-
archiver,
|
|
1020
|
-
archiver,
|
|
1021
|
-
archiver,
|
|
1022
|
-
worldStateSynchronizer,
|
|
1023
|
-
sequencer,
|
|
1024
|
-
proverNode,
|
|
1025
|
-
slasherClient,
|
|
1026
|
-
validatorsSentinel,
|
|
1027
|
-
stopStartedWatchers,
|
|
1028
|
-
ethereumChain.chainInfo.id,
|
|
1029
|
-
config.rollupVersion,
|
|
1030
|
-
globalVariableBuilder,
|
|
1031
|
-
feeProvider,
|
|
1032
|
-
epochCache,
|
|
1033
|
-
packageVersion,
|
|
1034
|
-
peerProofVerifier,
|
|
1035
|
-
rpcProofVerifier,
|
|
1036
|
-
telemetry,
|
|
1037
|
-
log,
|
|
1038
|
-
blobClient,
|
|
1039
|
-
validatorClient,
|
|
1040
|
-
keyStoreManager,
|
|
1041
|
-
debugLogStore,
|
|
1042
|
-
automineSequencer,
|
|
1043
|
-
);
|
|
1044
|
-
|
|
1045
|
-
return node;
|
|
1046
|
-
} catch (err) {
|
|
1047
|
-
log.error('Failed during node creation, stopping started resources', err);
|
|
1048
|
-
for (const resource of started.reverse()) {
|
|
1049
|
-
await tryStop(resource);
|
|
1050
|
-
}
|
|
1051
|
-
throw err;
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
/**
|
|
1056
|
-
* Verifies the node's configured L1 timing matches the rollup contract it is pointed at, for the fields the
|
|
1057
|
-
* node's own config carries. Each comparison is guarded against an undefined config value, so a config that
|
|
1058
|
-
* does not carry a field is not checked. Throws a single error listing every mismatch. Runs in the shared
|
|
1059
|
-
* startup path for every node role.
|
|
1060
|
-
*/
|
|
1061
|
-
private static checkConfigMatchesRollup(
|
|
1062
|
-
config: AztecNodeConfig,
|
|
1063
|
-
rollup: { slotDuration: number; epochDuration: number },
|
|
1064
|
-
): void {
|
|
1065
|
-
const mismatches: string[] = [];
|
|
1066
|
-
if (config.aztecSlotDuration !== undefined && config.aztecSlotDuration !== rollup.slotDuration) {
|
|
1067
|
-
mismatches.push(`aztecSlotDuration is ${config.aztecSlotDuration} but the rollup reports ${rollup.slotDuration}`);
|
|
1068
|
-
}
|
|
1069
|
-
if (config.aztecEpochDuration !== undefined && config.aztecEpochDuration !== rollup.epochDuration) {
|
|
1070
|
-
mismatches.push(
|
|
1071
|
-
`aztecEpochDuration is ${config.aztecEpochDuration} but the rollup reports ${rollup.epochDuration}`,
|
|
1072
|
-
);
|
|
1073
|
-
}
|
|
1074
|
-
if (mismatches.length > 0) {
|
|
1075
|
-
throw new Error(
|
|
1076
|
-
`The node's configured L1 timing does not match the rollup contract it is pointed at: ${mismatches.join('; ')}`,
|
|
1077
|
-
);
|
|
1078
|
-
}
|
|
358
|
+
return this.blockProvider.getCheckpoints(from, limit, options);
|
|
1079
359
|
}
|
|
1080
360
|
|
|
1081
361
|
/**
|
|
@@ -1209,8 +489,17 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1209
489
|
return this.contractDataSource.getContractClass(id);
|
|
1210
490
|
}
|
|
1211
491
|
|
|
1212
|
-
public getContract(
|
|
1213
|
-
|
|
492
|
+
public async getContract(
|
|
493
|
+
address: AztecAddress,
|
|
494
|
+
referenceBlock: BlockParameter = 'latest',
|
|
495
|
+
): Promise<ContractInstanceWithAddress | undefined> {
|
|
496
|
+
const blockData = await this.getBlockData(referenceBlock);
|
|
497
|
+
if (!blockData) {
|
|
498
|
+
throw new Error(
|
|
499
|
+
`Reference block ${inspectBlockParameter(referenceBlock)} not found when querying contract ${address}. If the node API has been queried with an anchor block hash, possibly a reorg has occurred.`,
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
return this.contractDataSource.getContract(address, blockData.header.globalVariables.timestamp);
|
|
1214
503
|
}
|
|
1215
504
|
|
|
1216
505
|
public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
@@ -1253,78 +542,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1253
542
|
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
1254
543
|
}
|
|
1255
544
|
|
|
1256
|
-
public
|
|
545
|
+
public getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
|
|
1257
546
|
txHash: TxHash,
|
|
1258
547
|
options?: TGetTxReceiptOptions,
|
|
1259
548
|
): Promise<TxReceipt<TGetTxReceiptOptions>> {
|
|
1260
|
-
|
|
1261
|
-
// as a fallback if we don't find a mined tx effect in the archiver.
|
|
1262
|
-
const txPoolStatus = await this.p2pClient.getTxStatus(txHash);
|
|
1263
|
-
const isKnownToPool = txPoolStatus === 'pending' || txPoolStatus === 'mined';
|
|
1264
|
-
|
|
1265
|
-
// Then get the raw tx effect from the archiver, which tracks every tx in a mined block.
|
|
1266
|
-
const indexed = await this.blockSource.getTxEffect(txHash);
|
|
1267
|
-
|
|
1268
|
-
let receipt: TxReceipt;
|
|
1269
|
-
if (indexed) {
|
|
1270
|
-
receipt = await this.#assembleMinedReceipt(indexed, options);
|
|
1271
|
-
} else if (isKnownToPool) {
|
|
1272
|
-
// If the tx is in the pool but not in the archiver, it's pending.
|
|
1273
|
-
// This handles race conditions between archiver and p2p, where the archiver
|
|
1274
|
-
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
1275
|
-
let tx: Tx | undefined;
|
|
1276
|
-
if (options?.includePendingTx) {
|
|
1277
|
-
// The tx may have left the pool since we checked its status (mined or dropped); in that case we
|
|
1278
|
-
// leave `tx` unset and still return a pending receipt.
|
|
1279
|
-
tx = await this.p2pClient.getTxByHashFromPool(txHash, { includeProof: !!options.includeProof });
|
|
1280
|
-
}
|
|
1281
|
-
receipt = new PendingTxReceipt(txHash, tx);
|
|
1282
|
-
} else {
|
|
1283
|
-
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
1284
|
-
receipt = new DroppedTxReceipt(txHash, 'Tx dropped by P2P node');
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
1288
|
-
|
|
1289
|
-
return receipt;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
/**
|
|
1293
|
-
* Assembles a {@link MinedTxReceipt} from a raw {@link IndexedTxEffect}, deriving the finalization status from the
|
|
1294
|
-
* cached L2 tips and the epoch from the block's slot number.
|
|
1295
|
-
*/
|
|
1296
|
-
async #assembleMinedReceipt(indexed: IndexedTxEffect, options?: GetTxReceiptOptions): Promise<MinedTxReceipt> {
|
|
1297
|
-
const blockNumber = indexed.l2BlockNumber;
|
|
1298
|
-
const [tips, l1Constants] = await Promise.all([this.blockSource.getL2Tips(), this.blockSource.getL1Constants()]);
|
|
1299
|
-
|
|
1300
|
-
const status = this.#deriveMinedStatus(blockNumber, tips);
|
|
1301
|
-
const epochNumber = getEpochAtSlot(indexed.slotNumber, l1Constants);
|
|
1302
|
-
|
|
1303
|
-
return new MinedTxReceipt(
|
|
1304
|
-
indexed.data.txHash,
|
|
1305
|
-
status,
|
|
1306
|
-
MinedTxReceipt.executionResultFromRevertCode(indexed.data.revertCode),
|
|
1307
|
-
indexed.data.transactionFee.toBigInt(),
|
|
1308
|
-
indexed.l2BlockHash,
|
|
1309
|
-
blockNumber,
|
|
1310
|
-
indexed.slotNumber,
|
|
1311
|
-
indexed.txIndexInBlock,
|
|
1312
|
-
epochNumber,
|
|
1313
|
-
options?.includeTxEffect ? indexed.data : undefined,
|
|
1314
|
-
/*debugLogs=*/ undefined,
|
|
1315
|
-
);
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
#deriveMinedStatus(blockNumber: BlockNumber, tips: L2Tips): MinedTxStatus {
|
|
1319
|
-
if (blockNumber <= tips.finalized.block.number) {
|
|
1320
|
-
return TxStatus.FINALIZED;
|
|
1321
|
-
} else if (blockNumber <= tips.proven.block.number) {
|
|
1322
|
-
return TxStatus.PROVEN;
|
|
1323
|
-
} else if (blockNumber <= tips.checkpointed.block.number) {
|
|
1324
|
-
return TxStatus.CHECKPOINTED;
|
|
1325
|
-
} else {
|
|
1326
|
-
return TxStatus.PROPOSED;
|
|
1327
|
-
}
|
|
549
|
+
return this.txReceiptBuilder.getTxReceipt(txHash, options);
|
|
1328
550
|
}
|
|
1329
551
|
|
|
1330
552
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -1410,125 +632,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1410
632
|
return compactArray(txs);
|
|
1411
633
|
}
|
|
1412
634
|
|
|
1413
|
-
public
|
|
635
|
+
public findLeavesIndexes(
|
|
1414
636
|
referenceBlock: BlockParameter,
|
|
1415
637
|
treeId: MerkleTreeId,
|
|
1416
638
|
leafValues: Fr[],
|
|
1417
639
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
1418
|
-
|
|
1419
|
-
const maybeIndices = await committedDb.findLeafIndices(
|
|
1420
|
-
treeId,
|
|
1421
|
-
leafValues.map(x => x.toBuffer()),
|
|
1422
|
-
);
|
|
1423
|
-
// Filter out undefined values to query block numbers only for found leaves
|
|
1424
|
-
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
1425
|
-
|
|
1426
|
-
// Now we find the block numbers for the defined indices
|
|
1427
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
1428
|
-
|
|
1429
|
-
// Build a map from leaf index to block number
|
|
1430
|
-
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
1431
|
-
for (let i = 0; i < definedIndices.length; i++) {
|
|
1432
|
-
const blockNumber = blockNumbers[i];
|
|
1433
|
-
if (blockNumber === undefined) {
|
|
1434
|
-
throw new Error(
|
|
1435
|
-
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1442
|
-
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
1443
|
-
|
|
1444
|
-
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1445
|
-
const blockHashes = await Promise.all(
|
|
1446
|
-
uniqueBlockNumbers.map(blockNumber => {
|
|
1447
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1448
|
-
}),
|
|
1449
|
-
);
|
|
1450
|
-
|
|
1451
|
-
// Build a map from block number to block hash
|
|
1452
|
-
const blockNumberToHash = new Map<BlockNumber, BlockHash>();
|
|
1453
|
-
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1454
|
-
const blockHash = blockHashes[i];
|
|
1455
|
-
if (blockHash === undefined) {
|
|
1456
|
-
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1457
|
-
}
|
|
1458
|
-
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1462
|
-
return maybeIndices.map(index => {
|
|
1463
|
-
if (index === undefined) {
|
|
1464
|
-
return undefined;
|
|
1465
|
-
}
|
|
1466
|
-
const blockNumber = indexToBlockNumber.get(index);
|
|
1467
|
-
if (blockNumber === undefined) {
|
|
1468
|
-
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1469
|
-
}
|
|
1470
|
-
const l2BlockHash = blockNumberToHash.get(blockNumber);
|
|
1471
|
-
if (l2BlockHash === undefined) {
|
|
1472
|
-
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1473
|
-
}
|
|
1474
|
-
return {
|
|
1475
|
-
l2BlockNumber: blockNumber,
|
|
1476
|
-
l2BlockHash,
|
|
1477
|
-
data: index,
|
|
1478
|
-
};
|
|
1479
|
-
});
|
|
640
|
+
return this.worldStateQueries.findLeavesIndexes(referenceBlock, treeId, leafValues);
|
|
1480
641
|
}
|
|
1481
642
|
|
|
1482
|
-
public
|
|
643
|
+
public getBlockHashMembershipWitness(
|
|
1483
644
|
referenceBlock: BlockParameter,
|
|
1484
645
|
blockHash: BlockHash,
|
|
1485
646
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1486
|
-
|
|
1487
|
-
// which is the archive tree root BEFORE the anchor block was added (i.e. the state after block N-1).
|
|
1488
|
-
// So we need the world state at block N-1, not block N, to produce a sibling path matching that root.
|
|
1489
|
-
const referenceBlockNumber = await this.resolveBlockNumber(referenceBlock);
|
|
1490
|
-
if (referenceBlockNumber === BlockNumber.ZERO) {
|
|
1491
|
-
// Block 0 (the initial block) has an empty archive, so no membership witness can exist.
|
|
1492
|
-
return undefined;
|
|
1493
|
-
}
|
|
1494
|
-
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1495
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1496
|
-
return pathAndIndex === undefined
|
|
1497
|
-
? undefined
|
|
1498
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
647
|
+
return this.worldStateQueries.getBlockHashMembershipWitness(referenceBlock, blockHash);
|
|
1499
648
|
}
|
|
1500
649
|
|
|
1501
|
-
public
|
|
650
|
+
public getNoteHashMembershipWitness(
|
|
1502
651
|
referenceBlock: BlockParameter,
|
|
1503
652
|
noteHash: Fr,
|
|
1504
653
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1505
|
-
|
|
1506
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1507
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
1508
|
-
[noteHash],
|
|
1509
|
-
);
|
|
1510
|
-
return pathAndIndex === undefined
|
|
1511
|
-
? undefined
|
|
1512
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
654
|
+
return this.worldStateQueries.getNoteHashMembershipWitness(referenceBlock, noteHash);
|
|
1513
655
|
}
|
|
1514
656
|
|
|
1515
|
-
public
|
|
657
|
+
public getL1ToL2MessageMembershipWitness(
|
|
1516
658
|
referenceBlock: BlockParameter,
|
|
1517
659
|
l1ToL2Message: Fr,
|
|
1518
660
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1519
|
-
|
|
1520
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1521
|
-
if (!witness) {
|
|
1522
|
-
return undefined;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// REFACTOR: Return a MembershipWitness object
|
|
1526
|
-
return [witness.index, witness.path];
|
|
661
|
+
return this.worldStateQueries.getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message);
|
|
1527
662
|
}
|
|
1528
663
|
|
|
1529
|
-
public
|
|
1530
|
-
|
|
1531
|
-
return messageIndex !== undefined ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
664
|
+
public getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
665
|
+
return this.worldStateQueries.getL1ToL2MessageCheckpoint(l1ToL2Message);
|
|
1532
666
|
}
|
|
1533
667
|
|
|
1534
668
|
/**
|
|
@@ -1539,12 +673,8 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1539
673
|
* @param epoch - The epoch at which to get the data.
|
|
1540
674
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1541
675
|
*/
|
|
1542
|
-
public
|
|
1543
|
-
|
|
1544
|
-
const blocksInCheckpoints = chunkBy(blocks, block => block.header.globalVariables.slotNumber);
|
|
1545
|
-
return blocksInCheckpoints.map(slotBlocks =>
|
|
1546
|
-
slotBlocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1547
|
-
);
|
|
676
|
+
public getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
677
|
+
return this.worldStateQueries.getL2ToL1Messages(epoch);
|
|
1548
678
|
}
|
|
1549
679
|
|
|
1550
680
|
/**
|
|
@@ -1556,77 +686,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1556
686
|
message: Fr,
|
|
1557
687
|
messageIndexInTx?: number,
|
|
1558
688
|
): Promise<L2ToL1MembershipWitness | undefined> {
|
|
1559
|
-
return this.
|
|
689
|
+
return this.worldStateQueries.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1560
690
|
}
|
|
1561
691
|
|
|
1562
|
-
public
|
|
692
|
+
public getNullifierMembershipWitness(
|
|
1563
693
|
referenceBlock: BlockParameter,
|
|
1564
694
|
nullifier: Fr,
|
|
1565
695
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1566
|
-
|
|
1567
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1568
|
-
if (!witness) {
|
|
1569
|
-
return undefined;
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
const { index, path } = witness;
|
|
1573
|
-
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1574
|
-
if (!leafPreimage) {
|
|
1575
|
-
return undefined;
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
696
|
+
return this.worldStateQueries.getNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1579
697
|
}
|
|
1580
698
|
|
|
1581
|
-
public
|
|
699
|
+
public getLowNullifierMembershipWitness(
|
|
1582
700
|
referenceBlock: BlockParameter,
|
|
1583
701
|
nullifier: Fr,
|
|
1584
702
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1585
|
-
|
|
1586
|
-
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1587
|
-
if (!findResult) {
|
|
1588
|
-
return undefined;
|
|
1589
|
-
}
|
|
1590
|
-
const { index, alreadyPresent } = findResult;
|
|
1591
|
-
if (alreadyPresent) {
|
|
1592
|
-
throw new Error(
|
|
1593
|
-
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1594
|
-
);
|
|
1595
|
-
}
|
|
1596
|
-
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1597
|
-
|
|
1598
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1599
|
-
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
703
|
+
return this.worldStateQueries.getLowNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1600
704
|
}
|
|
1601
705
|
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1605
|
-
if (!lowLeafResult) {
|
|
1606
|
-
return undefined;
|
|
1607
|
-
} else {
|
|
1608
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1609
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1610
|
-
lowLeafResult.index,
|
|
1611
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1612
|
-
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1613
|
-
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1614
|
-
}
|
|
706
|
+
public getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
707
|
+
return this.worldStateQueries.getPublicDataWitness(referenceBlock, leafSlot);
|
|
1615
708
|
}
|
|
1616
709
|
|
|
1617
|
-
public
|
|
1618
|
-
|
|
1619
|
-
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1620
|
-
|
|
1621
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1622
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
1623
|
-
return Fr.ZERO;
|
|
1624
|
-
}
|
|
1625
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1626
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1627
|
-
lowLeafResult.index,
|
|
1628
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1629
|
-
return preimage.leaf.value;
|
|
710
|
+
public getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
711
|
+
return this.worldStateQueries.getPublicStorageAt(referenceBlock, contract, slot);
|
|
1630
712
|
}
|
|
1631
713
|
|
|
1632
714
|
/**
|
|
@@ -1638,149 +720,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
1638
720
|
@trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
|
|
1639
721
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1640
722
|
}))
|
|
1641
|
-
public
|
|
723
|
+
public simulatePublicCalls(
|
|
1642
724
|
tx: Tx,
|
|
1643
725
|
skipFeeEnforcement = false,
|
|
1644
726
|
overrides?: SimulationOverrides,
|
|
1645
727
|
): Promise<PublicSimulationOutput> {
|
|
1646
|
-
|
|
1647
|
-
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
1648
|
-
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
1649
|
-
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
1650
|
-
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
1651
|
-
throw new BadRequestError(
|
|
1652
|
-
`Transaction total gas limit ${
|
|
1653
|
-
txGasLimit + teardownGasLimit
|
|
1654
|
-
} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${
|
|
1655
|
-
this.config.rpcSimulatePublicMaxGasLimit
|
|
1656
|
-
} for simulation`,
|
|
1657
|
-
);
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
const txHash = tx.getTxHash();
|
|
1661
|
-
const l2Tips = await this.blockSource.getL2Tips();
|
|
1662
|
-
const latestBlockNumber = l2Tips.proposed.number;
|
|
1663
|
-
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1664
|
-
|
|
1665
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1666
|
-
const coinbase = EthAddress.ZERO;
|
|
1667
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1668
|
-
|
|
1669
|
-
// Define the slot for simulation as the max of the next L1 timestamp slot, the slot after the proposed
|
|
1670
|
-
// checkpoint, and the latest proposed block's slot.
|
|
1671
|
-
const proposedCheckpointBlockData = await this.blockSource.getBlockData({
|
|
1672
|
-
number: l2Tips.proposedCheckpoint.block.number,
|
|
1673
|
-
});
|
|
1674
|
-
const proposedCheckpointSlot = proposedCheckpointBlockData?.header.getSlot();
|
|
1675
|
-
let slotAfterProposedCheckpoint: SlotNumber | undefined;
|
|
1676
|
-
if (proposedCheckpointSlot !== undefined) {
|
|
1677
|
-
slotAfterProposedCheckpoint = SlotNumber.fromBigInt(BigInt(proposedCheckpointSlot) + 1n);
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
let latestProposedBlockSlot: SlotNumber | undefined;
|
|
1681
|
-
if (l2Tips.proposed.number > l2Tips.proposedCheckpoint.block.number) {
|
|
1682
|
-
latestProposedBlockSlot = (
|
|
1683
|
-
await this.blockSource.getBlockData({ number: l2Tips.proposed.number })
|
|
1684
|
-
)?.header.getSlot();
|
|
1685
|
-
}
|
|
1686
|
-
const slotFromNextL1Timestamp = this.epochCache.getEpochAndSlotInNextL1Slot().slot;
|
|
1687
|
-
const targetSlot = SlotNumber(
|
|
1688
|
-
Math.max(...compactArray([slotFromNextL1Timestamp, slotAfterProposedCheckpoint, latestProposedBlockSlot])),
|
|
1689
|
-
);
|
|
1690
|
-
|
|
1691
|
-
const checkpointGlobalVariables = await this.globalVariableBuilder.buildCheckpointGlobalVariables(
|
|
1692
|
-
coinbase,
|
|
1693
|
-
feeRecipient,
|
|
1694
|
-
targetSlot,
|
|
1695
|
-
);
|
|
1696
|
-
const newGlobalVariables = GlobalVariables.from({ blockNumber, ...checkpointGlobalVariables });
|
|
1697
|
-
|
|
1698
|
-
const publicProcessorFactory = new PublicProcessorFactory(
|
|
1699
|
-
this.contractDataSource,
|
|
1700
|
-
new DateProvider(),
|
|
1701
|
-
this.telemetry,
|
|
1702
|
-
this.log.getBindings(),
|
|
1703
|
-
);
|
|
1704
|
-
|
|
1705
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1706
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1707
|
-
txHash,
|
|
1708
|
-
blockNumber,
|
|
1709
|
-
});
|
|
1710
|
-
|
|
1711
|
-
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1712
|
-
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1713
|
-
|
|
1714
|
-
// If we detect the next block would start a new checkpoint, then insert L1-to-L2 messages into
|
|
1715
|
-
// the world state tree so simulation can take them into account. We detect if the next block would
|
|
1716
|
-
// start a new checkpoint by checking if the proposed checkpoint's block number matches the latest block number,
|
|
1717
|
-
// which means the next block would be the first block of the next checkpoint.
|
|
1718
|
-
const targetCheckpoint = CheckpointNumber(
|
|
1719
|
-
(l2Tips.proposedCheckpoint.checkpoint.number ?? CheckpointNumber.ZERO) + 1,
|
|
1720
|
-
);
|
|
1721
|
-
const nextCheckpointMessages: Fr[] | undefined =
|
|
1722
|
-
l2Tips.proposedCheckpoint.block.number === l2Tips.proposed.number
|
|
1723
|
-
? await this.l1ToL2MessageSource.getL1ToL2Messages(targetCheckpoint).catch(err => {
|
|
1724
|
-
if (isErrorClass(err, L1ToL2MessagesNotReadyError)) {
|
|
1725
|
-
this.log.warn(
|
|
1726
|
-
`L1-to-L2 messages for checkpoint ${targetCheckpoint} are not ready yet (simulating without them)`,
|
|
1727
|
-
);
|
|
1728
|
-
} else {
|
|
1729
|
-
this.log.error(
|
|
1730
|
-
`Failed to get L1-to-L2 messages for checkpoint ${targetCheckpoint} (simulating without them)`,
|
|
1731
|
-
err,
|
|
1732
|
-
);
|
|
1733
|
-
}
|
|
1734
|
-
return undefined;
|
|
1735
|
-
})
|
|
1736
|
-
: undefined;
|
|
1737
|
-
|
|
1738
|
-
// 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
|
|
1739
|
-
await using merkleTreeFork = await this.worldStateSynchronizer.fork(latestBlockNumber);
|
|
1740
|
-
|
|
1741
|
-
if (nextCheckpointMessages !== undefined) {
|
|
1742
|
-
this.log.debug(
|
|
1743
|
-
`Appending ${nextCheckpointMessages.length} L1-to-L2 messages to the world state tree for the next checkpoint`,
|
|
1744
|
-
{ checkpointNumber: l2Tips.proposedCheckpoint.checkpoint.number + 1 },
|
|
1745
|
-
);
|
|
1746
|
-
await appendL1ToL2MessagesToTree(merkleTreeFork, nextCheckpointMessages);
|
|
1747
|
-
}
|
|
1748
|
-
await applyPublicDataOverrides(merkleTreeFork, overrides?.publicStorage);
|
|
1749
|
-
|
|
1750
|
-
const config = PublicSimulatorConfig.from({
|
|
1751
|
-
skipFeeEnforcement,
|
|
1752
|
-
collectDebugLogs: true,
|
|
1753
|
-
collectHints: false,
|
|
1754
|
-
collectCallMetadata: true,
|
|
1755
|
-
collectStatistics: false,
|
|
1756
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1757
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1758
|
-
}),
|
|
1759
|
-
});
|
|
1760
|
-
|
|
1761
|
-
const contractsDB = new PublicContractsDB(this.contractDataSource, this.log.getBindings());
|
|
1762
|
-
if (overrides?.contracts) {
|
|
1763
|
-
contractsDB.addContracts(Object.values(overrides.contracts).map(({ instance }) => instance));
|
|
1764
|
-
}
|
|
1765
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config, contractsDB);
|
|
1766
|
-
|
|
1767
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1768
|
-
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1769
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1770
|
-
if (failedTxs.length) {
|
|
1771
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1772
|
-
throw failedTxs[0].error;
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
const [processedTx] = processedTxs;
|
|
1776
|
-
return new PublicSimulationOutput(
|
|
1777
|
-
processedTx.revertReason,
|
|
1778
|
-
processedTx.globalVariables,
|
|
1779
|
-
processedTx.txEffect,
|
|
1780
|
-
returns,
|
|
1781
|
-
processedTx.gasUsed,
|
|
1782
|
-
debugLogs,
|
|
1783
|
-
);
|
|
728
|
+
return this.nodePublicCallsSimulator.simulate(tx, skipFeeEnforcement, overrides);
|
|
1784
729
|
}
|
|
1785
730
|
|
|
1786
731
|
public async isValidTx(
|
|
@@ -2166,92 +1111,26 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDeb
|
|
|
2166
1111
|
return await this.automineSequencer.prove(upToCheckpoint);
|
|
2167
1112
|
}
|
|
2168
1113
|
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
* @returns An instance of a committed MerkleTreeOperations
|
|
2173
|
-
*/
|
|
2174
|
-
protected async getWorldState(block: BlockParameter) {
|
|
2175
|
-
const query = this.normalizeBlockParameter(block);
|
|
2176
|
-
|
|
2177
|
-
// When the request anchors on a specific block hash, resolve it against the archiver up front and
|
|
2178
|
-
// drive the world-state sync to that exact block number and hash. Resolving against the archiver
|
|
2179
|
-
// first fails fast with a clear reorg error if the hash is unknown, and passing the hash to the
|
|
2180
|
-
// synchronizer makes the sync reorg-aware: it barriers until the archive-tree commit for that block
|
|
2181
|
-
// has landed and verifies it matches the requested fork, instead of syncing to bare latest height
|
|
2182
|
-
// and then racing the snapshot read below against an in-flight archive-tree write.
|
|
2183
|
-
const requestedHash = 'hash' in query ? query.hash : undefined;
|
|
2184
|
-
const anchorBlockNumber = requestedHash !== undefined ? await this.resolveBlockNumber(query) : undefined;
|
|
2185
|
-
|
|
2186
|
-
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
2187
|
-
try {
|
|
2188
|
-
// Attempt to sync the world state if necessary
|
|
2189
|
-
blockSyncedTo = await this.#syncWorldState(anchorBlockNumber, requestedHash);
|
|
2190
|
-
} catch (err) {
|
|
2191
|
-
this.log.error(`Error getting world state: ${err}`);
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
if ('tag' in query && query.tag === 'proposed') {
|
|
2195
|
-
this.log.debug(`Using committed db for latest block, world state synced upto ${blockSyncedTo}`);
|
|
2196
|
-
return this.worldStateSynchronizer.getCommitted();
|
|
2197
|
-
}
|
|
2198
|
-
|
|
2199
|
-
const blockNumber = anchorBlockNumber ?? (await this.resolveBlockNumber(query));
|
|
2200
|
-
|
|
2201
|
-
// Check it's within world state sync range
|
|
2202
|
-
if (blockNumber > blockSyncedTo) {
|
|
2203
|
-
throw new Error(
|
|
2204
|
-
`Queried block ${inspectBlockParameter(block)} not yet synced by the node (node is synced upto ${blockSyncedTo}).`,
|
|
2205
|
-
);
|
|
2206
|
-
}
|
|
2207
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
2208
|
-
|
|
2209
|
-
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
2210
|
-
|
|
2211
|
-
// Double-check world-state synced to the same block hash as was requested.
|
|
2212
|
-
// Block 0 is skipped: the snapshot returned by `getSnapshot(0)` is the *pre*-genesis archive
|
|
2213
|
-
// (size 0), so leaf 0 is not yet inserted from that snapshot's view even though block 0's hash
|
|
2214
|
-
// does live at archive index 0 in the committed tree. The genesis hash is already validated by
|
|
2215
|
-
// the archiver when it resolves the hash query to block number 0.
|
|
2216
|
-
if (requestedHash !== undefined && blockNumber !== BlockNumber.ZERO) {
|
|
2217
|
-
const blockHash = await snapshot.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
2218
|
-
if (!blockHash || !requestedHash.equals(blockHash)) {
|
|
2219
|
-
throw new Error(
|
|
2220
|
-
`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.`,
|
|
2221
|
-
);
|
|
2222
|
-
}
|
|
1114
|
+
public async warpL2TimeAtLeastTo(targetTimestamp: number): Promise<void> {
|
|
1115
|
+
if (!this.automineSequencer) {
|
|
1116
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
2223
1117
|
}
|
|
2224
|
-
|
|
2225
|
-
return snapshot;
|
|
1118
|
+
await this.automineSequencer.warpTo(targetTimestamp);
|
|
2226
1119
|
}
|
|
2227
1120
|
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
const blockNumber = await this.blockSource.getBlockNumber(query);
|
|
2232
|
-
if (blockNumber === undefined) {
|
|
2233
|
-
if ('hash' in query) {
|
|
2234
|
-
throw new Error(
|
|
2235
|
-
`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.`,
|
|
2236
|
-
);
|
|
2237
|
-
}
|
|
2238
|
-
if ('archive' in query) {
|
|
2239
|
-
throw new Error(`Block with archive ${query.archive.toString()} not found.`);
|
|
2240
|
-
}
|
|
2241
|
-
throw new Error(`Block not found for ${inspectBlockParameter(block)}.`);
|
|
1121
|
+
public async warpL2TimeAtLeastBy(duration: number): Promise<void> {
|
|
1122
|
+
if (!this.automineSequencer) {
|
|
1123
|
+
throw new BadRequestError('Cannot warp L2 time: no automine sequencer is running');
|
|
2242
1124
|
}
|
|
2243
|
-
|
|
1125
|
+
await this.automineSequencer.warpBy(duration);
|
|
2244
1126
|
}
|
|
2245
1127
|
|
|
2246
1128
|
/**
|
|
2247
|
-
*
|
|
2248
|
-
* @
|
|
2249
|
-
*
|
|
2250
|
-
* hash, resyncing (and so detecting reorgs) if it does not yet match or has been reorged away.
|
|
2251
|
-
* @returns A promise that fulfils once the world state is synced
|
|
1129
|
+
* Returns a committed world-state view at `block`, driving sync first. Delegates to
|
|
1130
|
+
* {@link NodeWorldStateQueries.getWorldState}; kept as a protected method so subclasses and tests can
|
|
1131
|
+
* exercise the node's block-resolution and reorg-aware sync behavior.
|
|
2252
1132
|
*/
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
return await this.worldStateSynchronizer.syncImmediate(target, blockHash);
|
|
1133
|
+
protected getWorldState(block: BlockParameter) {
|
|
1134
|
+
return this.worldStateQueries.getWorldState(block);
|
|
2256
1135
|
}
|
|
2257
1136
|
}
|