@aztec/aztec-node 5.0.0-private.20260319 → 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/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 +16 -4
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +15 -5
- 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/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/register_node_rpc_handlers.d.ts +10 -0
- package/dest/aztec-node/register_node_rpc_handlers.d.ts.map +1 -0
- package/dest/aztec-node/register_node_rpc_handlers.js +31 -0
- package/dest/aztec-node/server.d.ts +128 -134
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +393 -820
- package/dest/bin/index.js +15 -10
- 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 +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +2 -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/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 +12 -5
- package/dest/sentinel/sentinel.d.ts +145 -21
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +227 -105
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +25 -17
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -26
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +30 -7
- package/src/aztec-node/node_public_calls_simulator.ts +383 -0
- package/src/aztec-node/public_data_overrides.ts +35 -0
- package/src/aztec-node/register_node_rpc_handlers.ts +29 -0
- package/src/aztec-node/server.ts +514 -1070
- package/src/bin/index.ts +19 -12
- package/src/factory.ts +656 -0
- package/src/index.ts +2 -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 +103 -0
- package/src/sentinel/config.ts +18 -6
- package/src/sentinel/factory.ts +21 -6
- package/src/sentinel/sentinel.ts +277 -130
- package/src/sentinel/store.ts +26 -18
- package/src/test/index.ts +2 -2
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,55 +1,48 @@
|
|
|
1
|
-
import { Archiver
|
|
2
|
-
import { BBCircuitVerifier,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Archiver } from '@aztec/archiver';
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
4
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
5
5
|
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
import type { EpochCacheInterface } from '@aztec/epoch-cache';
|
|
7
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
8
|
+
import { type L1ContractAddresses, pickL1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
9
|
+
import {
|
|
10
|
+
BlockNumber,
|
|
11
|
+
CheckpointNumber,
|
|
12
|
+
type CheckpointProposalHash,
|
|
13
|
+
EpochNumber,
|
|
14
|
+
SlotNumber,
|
|
15
|
+
} from '@aztec/foundation/branded-types';
|
|
16
|
+
import { compactArray, pick, unique } from '@aztec/foundation/collection';
|
|
13
17
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
14
18
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
19
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
16
20
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
21
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
22
|
import { count } from '@aztec/foundation/string';
|
|
18
|
-
import {
|
|
23
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
19
24
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
type P2P,
|
|
25
|
-
type P2PClientDeps,
|
|
26
|
-
createP2PClient,
|
|
27
|
-
createTxValidatorForAcceptingTxsOverRPC,
|
|
28
|
-
getDefaultAllowedSetupFunctions,
|
|
29
|
-
} 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';
|
|
30
28
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
AttestationsBlockWatcher,
|
|
37
|
-
EpochPruneWatcher,
|
|
38
|
-
type SlasherClientInterface,
|
|
39
|
-
type Watcher,
|
|
40
|
-
createSlasher,
|
|
41
|
-
} from '@aztec/slasher';
|
|
42
|
-
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
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';
|
|
33
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
43
34
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
35
|
import {
|
|
45
36
|
type BlockData,
|
|
46
37
|
BlockHash,
|
|
47
38
|
type BlockParameter,
|
|
39
|
+
type CheckpointsQuery,
|
|
48
40
|
type DataInBlock,
|
|
49
|
-
L2Block,
|
|
50
41
|
type L2BlockSource,
|
|
42
|
+
type L2BlockTag,
|
|
43
|
+
type L2Tips,
|
|
44
|
+
inspectBlockParameter,
|
|
51
45
|
} from '@aztec/stdlib/block';
|
|
52
|
-
import type { PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
53
46
|
import type {
|
|
54
47
|
ContractClassPublic,
|
|
55
48
|
ContractDataSource,
|
|
@@ -57,16 +50,24 @@ import type {
|
|
|
57
50
|
NodeInfo,
|
|
58
51
|
ProtocolContractAddresses,
|
|
59
52
|
} from '@aztec/stdlib/contract';
|
|
60
|
-
import { GasFees } from '@aztec/stdlib/gas';
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
import { GasFees, type ManaUsageEstimate, getNetworkTxGasLimits } from '@aztec/stdlib/gas';
|
|
54
|
+
import type {
|
|
55
|
+
AztecNode,
|
|
56
|
+
AztecNodeAdmin,
|
|
57
|
+
AztecNodeAdminConfig,
|
|
58
|
+
AztecNodeDebug,
|
|
59
|
+
BlockIncludeOptions,
|
|
60
|
+
BlockResponse,
|
|
61
|
+
BlocksIncludeOptions,
|
|
62
|
+
CheckpointIncludeOptions,
|
|
63
|
+
CheckpointParameter,
|
|
64
|
+
CheckpointResponse,
|
|
65
|
+
CheckpointTag,
|
|
66
|
+
GetTxByHashOptions,
|
|
67
|
+
PeerInfo,
|
|
68
|
+
ProposalsForSlot,
|
|
69
69
|
} from '@aztec/stdlib/interfaces/client';
|
|
70
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
70
71
|
import {
|
|
71
72
|
type AllowedElement,
|
|
72
73
|
type ClientProtocolCircuitVerifier,
|
|
@@ -76,24 +77,24 @@ import {
|
|
|
76
77
|
type WorldStateSynchronizer,
|
|
77
78
|
tryStop,
|
|
78
79
|
} from '@aztec/stdlib/interfaces/server';
|
|
79
|
-
import type { DebugLogStore,
|
|
80
|
-
import {
|
|
81
|
-
import {
|
|
82
|
-
import type {
|
|
83
|
-
import type {
|
|
80
|
+
import type { DebugLogStore, LogResult, PrivateLogsQuery, PublicLogsQuery } from '@aztec/stdlib/logs';
|
|
81
|
+
import { NullDebugLogStore } from '@aztec/stdlib/logs';
|
|
82
|
+
import type { L1ToL2MessageSource, L2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
83
|
+
import type { CheckpointAttestation } from '@aztec/stdlib/p2p';
|
|
84
|
+
import type { Offense } from '@aztec/stdlib/slashing';
|
|
84
85
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
85
86
|
import {
|
|
86
|
-
type
|
|
87
|
+
type FeeProvider,
|
|
88
|
+
type GetTxReceiptOptions,
|
|
87
89
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
88
90
|
type IndexedTxEffect,
|
|
89
91
|
PublicSimulationOutput,
|
|
92
|
+
type SimulationOverrides,
|
|
90
93
|
Tx,
|
|
91
94
|
type TxHash,
|
|
92
|
-
TxReceipt,
|
|
93
|
-
TxStatus,
|
|
95
|
+
type TxReceipt,
|
|
94
96
|
type TxValidationResult,
|
|
95
97
|
} from '@aztec/stdlib/tx';
|
|
96
|
-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
97
98
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
98
99
|
import {
|
|
99
100
|
Attributes,
|
|
@@ -103,491 +104,258 @@ import {
|
|
|
103
104
|
getTelemetryClient,
|
|
104
105
|
trackSpan,
|
|
105
106
|
} from '@aztec/telemetry-client';
|
|
106
|
-
import {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
createBlockProposalHandler,
|
|
112
|
-
createValidatorClient,
|
|
113
|
-
} from '@aztec/validator-client';
|
|
114
|
-
import type { SlashingProtectionDatabase } from '@aztec/validator-ha-signer/types';
|
|
115
|
-
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
116
|
-
|
|
117
|
-
import { createPublicClient } from 'viem';
|
|
118
|
-
|
|
119
|
-
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';
|
|
120
112
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
121
|
-
import {
|
|
113
|
+
import type { AztecNodeConfig } from './config.js';
|
|
122
114
|
import { NodeMetrics } from './node_metrics.js';
|
|
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
|
+
}
|
|
123
152
|
|
|
124
153
|
/**
|
|
125
154
|
* The aztec node.
|
|
126
155
|
*/
|
|
127
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
156
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
128
157
|
private metrics: NodeMetrics;
|
|
129
|
-
private initialHeaderHashPromise: Promise<BlockHash> | undefined = undefined;
|
|
130
|
-
|
|
131
158
|
// Prevent two snapshot operations to happen simultaneously
|
|
132
159
|
private isUploadingSnapshot = false;
|
|
160
|
+
// Saved minTxsPerBlock used by `pauseSequencer` to restore production-sequencer config on resume.
|
|
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;
|
|
133
166
|
|
|
134
167
|
public readonly tracer: Tracer;
|
|
135
168
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
});
|
|
164
261
|
|
|
165
262
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
166
|
-
this.log.info(`Aztec Node started on chain 0x${l1ChainId.toString(16)}`, config
|
|
263
|
+
this.log.info(`Aztec Node started on chain 0x${this.l1ChainId.toString(16)}`, pickL1ContractAddresses(this.config));
|
|
167
264
|
|
|
168
|
-
// 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
|
|
169
266
|
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
170
267
|
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
171
|
-
if (debugLogStore.isEnabled && config.realProofs) {
|
|
268
|
+
if (this.debugLogStore.isEnabled && this.config.realProofs) {
|
|
172
269
|
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
173
270
|
}
|
|
174
271
|
}
|
|
175
272
|
|
|
273
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
274
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
275
|
+
return this.rpcProofVerifier;
|
|
276
|
+
}
|
|
277
|
+
|
|
176
278
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
177
279
|
const status = await this.worldStateSynchronizer.status();
|
|
178
280
|
return status.syncSummary;
|
|
179
281
|
}
|
|
180
282
|
|
|
181
|
-
public
|
|
283
|
+
public getChainTips(): Promise<L2Tips> {
|
|
182
284
|
return this.blockSource.getL2Tips();
|
|
183
285
|
}
|
|
184
286
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
* @returns - A fully synced Aztec Node for use in development/testing.
|
|
189
|
-
*/
|
|
190
|
-
public static async createAndSync(
|
|
191
|
-
inputConfig: AztecNodeConfig,
|
|
192
|
-
deps: {
|
|
193
|
-
telemetry?: TelemetryClient;
|
|
194
|
-
logger?: Logger;
|
|
195
|
-
publisher?: SequencerPublisher;
|
|
196
|
-
dateProvider?: DateProvider;
|
|
197
|
-
p2pClientDeps?: P2PClientDeps;
|
|
198
|
-
proverNodeDeps?: Partial<ProverNodeDeps>;
|
|
199
|
-
slashingProtectionDb?: SlashingProtectionDatabase;
|
|
200
|
-
} = {},
|
|
201
|
-
options: {
|
|
202
|
-
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
203
|
-
dontStartSequencer?: boolean;
|
|
204
|
-
dontStartProverNode?: boolean;
|
|
205
|
-
} = {},
|
|
206
|
-
): Promise<AztecNodeService> {
|
|
207
|
-
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
208
|
-
const log = deps.logger ?? createLogger('node');
|
|
209
|
-
const packageVersion = getPackageVersion() ?? '';
|
|
210
|
-
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
211
|
-
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
212
|
-
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
213
|
-
|
|
214
|
-
// Build a key store from file if given or from environment otherwise.
|
|
215
|
-
// We keep the raw KeyStore available so we can merge with prover keys if enableProverNode is set.
|
|
216
|
-
let keyStoreManager: KeystoreManager | undefined;
|
|
217
|
-
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
218
|
-
if (keyStoreProvided) {
|
|
219
|
-
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
220
|
-
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
221
|
-
} else {
|
|
222
|
-
const rawKeyStores: KeyStore[] = [];
|
|
223
|
-
const validatorKeyStore = createKeyStoreForValidator(config);
|
|
224
|
-
if (validatorKeyStore) {
|
|
225
|
-
rawKeyStores.push(validatorKeyStore);
|
|
226
|
-
}
|
|
227
|
-
if (config.enableProverNode) {
|
|
228
|
-
const proverKeyStore = createKeyStoreForProver(config);
|
|
229
|
-
if (proverKeyStore) {
|
|
230
|
-
rawKeyStores.push(proverKeyStore);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (rawKeyStores.length > 0) {
|
|
234
|
-
keyStoreManager = new KeystoreManager(
|
|
235
|
-
rawKeyStores.length === 1 ? rawKeyStores[0] : mergeKeystores(rawKeyStores),
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
await keyStoreManager?.validateSigners();
|
|
241
|
-
|
|
242
|
-
// If we are a validator, verify our configuration before doing too much more.
|
|
243
|
-
if (!config.disableValidator) {
|
|
244
|
-
if (keyStoreManager === undefined) {
|
|
245
|
-
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
246
|
-
}
|
|
247
|
-
if (!keyStoreProvided && process.env.NODE_ENV !== 'test') {
|
|
248
|
-
log.warn("Keystore created from env: it's recommended to use a file-based key store for production");
|
|
249
|
-
}
|
|
250
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// validate that the actual chain id matches that specified in configuration
|
|
254
|
-
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const publicClient = createPublicClient({
|
|
261
|
-
chain: ethereumChain.chainInfo,
|
|
262
|
-
transport: makeL1HttpTransport(config.l1RpcUrls, { timeout: config.l1HttpTimeoutMS }),
|
|
263
|
-
pollingInterval: config.viemPollingIntervalMS,
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(
|
|
267
|
-
publicClient,
|
|
268
|
-
config.l1Contracts.registryAddress,
|
|
269
|
-
config.rollupVersion ?? 'canonical',
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
// Overwrite the passed in vars.
|
|
273
|
-
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
274
|
-
|
|
275
|
-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
276
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup, rollupManaLimit] = await Promise.all([
|
|
277
|
-
rollupContract.getL1GenesisTime(),
|
|
278
|
-
rollupContract.getSlotDuration(),
|
|
279
|
-
rollupContract.getVersion(),
|
|
280
|
-
rollupContract.getManaLimit().then(Number),
|
|
281
|
-
] as const);
|
|
282
|
-
|
|
283
|
-
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
284
|
-
|
|
285
|
-
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
286
|
-
log.warn(
|
|
287
|
-
`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const blobClient = await createBlobClientWithFileStores(config, log.createChild('blob-client'));
|
|
292
|
-
|
|
293
|
-
// attempt snapshot sync if possible
|
|
294
|
-
await trySnapshotSync(config, log);
|
|
295
|
-
|
|
296
|
-
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
|
|
297
|
-
|
|
298
|
-
const archiver = await createArchiver(
|
|
299
|
-
config,
|
|
300
|
-
{ blobClient, epochCache, telemetry, dateProvider },
|
|
301
|
-
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
// now create the merkle trees and the world state synchronizer
|
|
305
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(
|
|
306
|
-
config,
|
|
307
|
-
archiver,
|
|
308
|
-
options.prefilledPublicData,
|
|
309
|
-
telemetry,
|
|
310
|
-
);
|
|
311
|
-
const circuitVerifier =
|
|
312
|
-
config.realProofs || config.debugForceTxProofVerification
|
|
313
|
-
? await BBCircuitVerifier.new(config)
|
|
314
|
-
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
315
|
-
|
|
316
|
-
let debugLogStore: DebugLogStore;
|
|
317
|
-
if (!config.realProofs) {
|
|
318
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
319
|
-
|
|
320
|
-
debugLogStore = new InMemoryDebugLogStore();
|
|
321
|
-
log.info(
|
|
322
|
-
'Aztec node started in test mode (realProofs set to false) hence debug logs from public functions will be collected and served',
|
|
323
|
-
);
|
|
324
|
-
} else {
|
|
325
|
-
debugLogStore = new NullDebugLogStore();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
329
|
-
|
|
330
|
-
const proverOnly = config.enableProverNode && config.disableValidator;
|
|
331
|
-
if (proverOnly) {
|
|
332
|
-
log.info('Starting in prover-only mode: skipping validator, sequencer, sentinel, and slasher subsystems');
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
336
|
-
const p2pClient = await createP2PClient(
|
|
337
|
-
config,
|
|
338
|
-
archiver,
|
|
339
|
-
proofVerifier,
|
|
340
|
-
worldStateSynchronizer,
|
|
341
|
-
epochCache,
|
|
342
|
-
packageVersion,
|
|
343
|
-
dateProvider,
|
|
344
|
-
telemetry,
|
|
345
|
-
deps.p2pClientDeps,
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// We'll accumulate sentinel watchers here
|
|
349
|
-
const watchers: Watcher[] = [];
|
|
350
|
-
|
|
351
|
-
// Create FullNodeCheckpointsBuilder for block proposal handling and tx validation.
|
|
352
|
-
// Override maxTxsPerCheckpoint with the validator-specific limit if set.
|
|
353
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
354
|
-
{
|
|
355
|
-
...config,
|
|
356
|
-
l1GenesisTime,
|
|
357
|
-
slotDuration: Number(slotDuration),
|
|
358
|
-
rollupManaLimit,
|
|
359
|
-
maxTxsPerCheckpoint: config.validateMaxTxsPerCheckpoint,
|
|
360
|
-
},
|
|
361
|
-
worldStateSynchronizer,
|
|
362
|
-
archiver,
|
|
363
|
-
dateProvider,
|
|
364
|
-
telemetry,
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
let validatorClient: ValidatorClient | undefined;
|
|
368
|
-
|
|
369
|
-
if (!proverOnly) {
|
|
370
|
-
// Create validator client if required
|
|
371
|
-
validatorClient = await createValidatorClient(config, {
|
|
372
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
373
|
-
worldState: worldStateSynchronizer,
|
|
374
|
-
p2pClient,
|
|
375
|
-
telemetry,
|
|
376
|
-
dateProvider,
|
|
377
|
-
epochCache,
|
|
378
|
-
blockSource: archiver,
|
|
379
|
-
l1ToL2MessageSource: archiver,
|
|
380
|
-
keyStoreManager,
|
|
381
|
-
blobClient,
|
|
382
|
-
slashingProtectionDb: deps.slashingProtectionDb,
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
386
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
387
|
-
// like attestations or auths will fail.
|
|
388
|
-
if (validatorClient) {
|
|
389
|
-
watchers.push(validatorClient);
|
|
390
|
-
if (!options.dontStartSequencer) {
|
|
391
|
-
await validatorClient.registerHandlers();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// If there's no validator client, create a BlockProposalHandler to handle block proposals
|
|
397
|
-
// for monitoring or reexecution. Reexecution (default) allows us to follow the pending chain,
|
|
398
|
-
// while non-reexecution is used for validating the proposals and collecting their txs.
|
|
399
|
-
if (!validatorClient) {
|
|
400
|
-
const reexecute = !!config.alwaysReexecuteBlockProposals;
|
|
401
|
-
log.info(`Setting up block proposal handler` + (reexecute ? ' with reexecution of proposals' : ''));
|
|
402
|
-
createBlockProposalHandler(config, {
|
|
403
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
404
|
-
worldState: worldStateSynchronizer,
|
|
405
|
-
epochCache,
|
|
406
|
-
blockSource: archiver,
|
|
407
|
-
l1ToL2MessageSource: archiver,
|
|
408
|
-
p2pClient,
|
|
409
|
-
dateProvider,
|
|
410
|
-
telemetry,
|
|
411
|
-
}).register(p2pClient, reexecute);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Start world state and wait for it to sync to the archiver.
|
|
415
|
-
await worldStateSynchronizer.start();
|
|
287
|
+
public getL1Constants() {
|
|
288
|
+
return this.blockSource.getL1Constants();
|
|
289
|
+
}
|
|
416
290
|
|
|
417
|
-
|
|
418
|
-
|
|
291
|
+
public getSyncedL2SlotNumber() {
|
|
292
|
+
return this.blockSource.getSyncedL2SlotNumber();
|
|
293
|
+
}
|
|
419
294
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
295
|
+
public getSyncedL2EpochNumber() {
|
|
296
|
+
return this.blockSource.getSyncedL2EpochNumber();
|
|
297
|
+
}
|
|
423
298
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
watchers.push(validatorsSentinel);
|
|
428
|
-
}
|
|
299
|
+
public getSyncedL1Timestamp() {
|
|
300
|
+
return this.blockSource.getL1Timestamp();
|
|
301
|
+
}
|
|
429
302
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
archiver,
|
|
434
|
-
epochCache,
|
|
435
|
-
p2pClient.getTxProvider(),
|
|
436
|
-
validatorCheckpointsBuilder,
|
|
437
|
-
config,
|
|
438
|
-
);
|
|
439
|
-
watchers.push(epochPruneWatcher);
|
|
440
|
-
}
|
|
303
|
+
public getCheckpointsData(query: CheckpointsQuery) {
|
|
304
|
+
return this.blockSource.getCheckpointsData(query);
|
|
305
|
+
}
|
|
441
306
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
watchers.push(attestationsBlockWatcher);
|
|
446
|
-
}
|
|
307
|
+
public async getBlockNumber(tip?: L2BlockTag): Promise<BlockNumber> {
|
|
308
|
+
if (tip === undefined || tip === 'proposed') {
|
|
309
|
+
return this.blockSource.getBlockNumber();
|
|
447
310
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
// Validator enabled, create/start relevant service
|
|
462
|
-
let sequencer: SequencerClient | undefined;
|
|
463
|
-
let slasherClient: SlasherClientInterface | undefined;
|
|
464
|
-
if (!config.disableValidator && validatorClient) {
|
|
465
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
466
|
-
// as they are executed when the node is selected as proposer.
|
|
467
|
-
const validatorAddresses = keyStoreManager
|
|
468
|
-
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
469
|
-
: [];
|
|
470
|
-
|
|
471
|
-
slasherClient = await createSlasher(
|
|
472
|
-
config,
|
|
473
|
-
config.l1Contracts,
|
|
474
|
-
getPublicClient(config),
|
|
475
|
-
watchers,
|
|
476
|
-
dateProvider,
|
|
477
|
-
epochCache,
|
|
478
|
-
validatorAddresses,
|
|
479
|
-
undefined, // logger
|
|
480
|
-
);
|
|
481
|
-
await slasherClient.start();
|
|
482
|
-
|
|
483
|
-
const l1TxUtils = config.sequencerPublisherForwarderAddress
|
|
484
|
-
? await createForwarderL1TxUtilsFromSigners(
|
|
485
|
-
publicClient,
|
|
486
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
487
|
-
config.sequencerPublisherForwarderAddress,
|
|
488
|
-
{ ...config, scope: 'sequencer' },
|
|
489
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
490
|
-
)
|
|
491
|
-
: await createL1TxUtilsFromSigners(
|
|
492
|
-
publicClient,
|
|
493
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
494
|
-
{ ...config, scope: 'sequencer' },
|
|
495
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider, kzg: Blob.getViemKzgInstance() },
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
// Create and start the sequencer client
|
|
499
|
-
const checkpointsBuilder = new CheckpointsBuilder(
|
|
500
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration), rollupManaLimit },
|
|
501
|
-
worldStateSynchronizer,
|
|
502
|
-
archiver,
|
|
503
|
-
dateProvider,
|
|
504
|
-
telemetry,
|
|
505
|
-
debugLogStore,
|
|
506
|
-
);
|
|
507
|
-
|
|
508
|
-
sequencer = await SequencerClient.new(config, {
|
|
509
|
-
...deps,
|
|
510
|
-
epochCache,
|
|
511
|
-
l1TxUtils,
|
|
512
|
-
validatorClient,
|
|
513
|
-
p2pClient,
|
|
514
|
-
worldStateSynchronizer,
|
|
515
|
-
slasherClient,
|
|
516
|
-
checkpointsBuilder,
|
|
517
|
-
l2BlockSource: archiver,
|
|
518
|
-
l1ToL2MessageSource: archiver,
|
|
519
|
-
telemetry,
|
|
520
|
-
dateProvider,
|
|
521
|
-
blobClient,
|
|
522
|
-
nodeKeyStore: keyStoreManager!,
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (!options.dontStartSequencer && sequencer) {
|
|
527
|
-
await sequencer.start();
|
|
528
|
-
log.verbose(`Sequencer started`);
|
|
529
|
-
} else if (sequencer) {
|
|
530
|
-
log.warn(`Sequencer created but not started`);
|
|
311
|
+
return (await this.blockSource.getBlockNumber({ tag: tip })) ?? BlockNumber.ZERO;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public async getCheckpointNumber(tip?: CheckpointTag): Promise<CheckpointNumber> {
|
|
315
|
+
const tips = await this.blockSource.getL2Tips();
|
|
316
|
+
switch (tip) {
|
|
317
|
+
case undefined:
|
|
318
|
+
case 'checkpointed':
|
|
319
|
+
return tips.checkpointed.checkpoint.number;
|
|
320
|
+
case 'proven':
|
|
321
|
+
return tips.proven.checkpoint.number;
|
|
322
|
+
case 'finalized':
|
|
323
|
+
return tips.finalized.checkpoint.number;
|
|
531
324
|
}
|
|
325
|
+
}
|
|
532
326
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
dateProvider,
|
|
540
|
-
archiver,
|
|
541
|
-
worldStateSynchronizer,
|
|
542
|
-
p2pClient,
|
|
543
|
-
epochCache,
|
|
544
|
-
blobClient,
|
|
545
|
-
keyStoreManager,
|
|
546
|
-
});
|
|
327
|
+
public getBlock<Opts extends BlockIncludeOptions = {}>(
|
|
328
|
+
param: BlockParameter,
|
|
329
|
+
options: Opts = {} as Opts,
|
|
330
|
+
): Promise<BlockResponse<Opts> | undefined> {
|
|
331
|
+
return this.blockProvider.getBlock(param, options);
|
|
332
|
+
}
|
|
547
333
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
} else {
|
|
552
|
-
log.info(`Prover node subsystem created but not started`);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
334
|
+
public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
|
|
335
|
+
return this.blockProvider.getBlockData(param);
|
|
336
|
+
}
|
|
555
337
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
338
|
+
public getBlocks<Opts extends BlocksIncludeOptions = {}>(
|
|
339
|
+
from: BlockNumber,
|
|
340
|
+
limit: number,
|
|
341
|
+
options: Opts = {} as Opts,
|
|
342
|
+
): Promise<BlockResponse<Opts>[]> {
|
|
343
|
+
return this.blockProvider.getBlocks(from, limit, options);
|
|
344
|
+
}
|
|
562
345
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
archiver,
|
|
570
|
-
worldStateSynchronizer,
|
|
571
|
-
sequencer,
|
|
572
|
-
proverNode,
|
|
573
|
-
slasherClient,
|
|
574
|
-
validatorsSentinel,
|
|
575
|
-
epochPruneWatcher,
|
|
576
|
-
ethereumChain.chainInfo.id,
|
|
577
|
-
config.rollupVersion,
|
|
578
|
-
globalVariableBuilder,
|
|
579
|
-
epochCache,
|
|
580
|
-
packageVersion,
|
|
581
|
-
proofVerifier,
|
|
582
|
-
telemetry,
|
|
583
|
-
log,
|
|
584
|
-
blobClient,
|
|
585
|
-
validatorClient,
|
|
586
|
-
keyStoreManager,
|
|
587
|
-
debugLogStore,
|
|
588
|
-
);
|
|
346
|
+
public getCheckpoint<Opts extends CheckpointIncludeOptions = {}>(
|
|
347
|
+
param: CheckpointParameter,
|
|
348
|
+
options: Opts = {} as Opts,
|
|
349
|
+
): Promise<CheckpointResponse<Opts> | undefined> {
|
|
350
|
+
return this.blockProvider.getCheckpoint(param, options);
|
|
351
|
+
}
|
|
589
352
|
|
|
590
|
-
|
|
353
|
+
public getCheckpoints<Opts extends CheckpointIncludeOptions = {}>(
|
|
354
|
+
from: CheckpointNumber,
|
|
355
|
+
limit: number,
|
|
356
|
+
options: Opts = {} as Opts,
|
|
357
|
+
): Promise<CheckpointResponse<Opts>[]> {
|
|
358
|
+
return this.blockProvider.getCheckpoints(from, limit, options);
|
|
591
359
|
}
|
|
592
360
|
|
|
593
361
|
/**
|
|
@@ -598,6 +366,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
598
366
|
return this.sequencer;
|
|
599
367
|
}
|
|
600
368
|
|
|
369
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
|
|
370
|
+
public getAutomineSequencer(): AutomineSequencer | undefined {
|
|
371
|
+
return this.automineSequencer;
|
|
372
|
+
}
|
|
373
|
+
|
|
601
374
|
/** Returns the prover node subsystem, if enabled. */
|
|
602
375
|
public getProverNode(): ProverNode | undefined {
|
|
603
376
|
return this.proverNode;
|
|
@@ -620,7 +393,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
620
393
|
* @returns - The currently deployed L1 contract addresses.
|
|
621
394
|
*/
|
|
622
395
|
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
|
|
623
|
-
return Promise.resolve(this.config
|
|
396
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
624
397
|
}
|
|
625
398
|
|
|
626
399
|
public getEncodedEnr(): Promise<string | undefined> {
|
|
@@ -640,14 +413,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
640
413
|
}
|
|
641
414
|
|
|
642
415
|
public async getNodeInfo(): Promise<NodeInfo> {
|
|
643
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] =
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
416
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses, l1Constants] =
|
|
417
|
+
await Promise.all([
|
|
418
|
+
this.getNodeVersion(),
|
|
419
|
+
this.getVersion(),
|
|
420
|
+
this.getChainId(),
|
|
421
|
+
this.getEncodedEnr(),
|
|
422
|
+
this.getL1ContractAddresses(),
|
|
423
|
+
this.getProtocolContractAddresses(),
|
|
424
|
+
this.blockSource.getL1Constants(),
|
|
425
|
+
]);
|
|
426
|
+
|
|
427
|
+
// Gas limits a single tx may declare on this network, derived from network-wide constants only (the
|
|
428
|
+
// timetable's blocks-per-checkpoint and the network-minimum per-block multipliers) — never this node's
|
|
429
|
+
// local caps or configured multipliers, which can make the node stricter at block-building time but
|
|
430
|
+
// cannot define what the network accepts for relay. Clients read txsLimits to set fallback gas limits.
|
|
431
|
+
const maxTxGas = getNetworkTxGasLimits(this.config, l1Constants);
|
|
651
432
|
|
|
652
433
|
const nodeInfo: NodeInfo = {
|
|
653
434
|
nodeVersion,
|
|
@@ -657,112 +438,29 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
657
438
|
l1ContractAddresses: contractAddresses,
|
|
658
439
|
protocolContractAddresses: protocolContractAddresses,
|
|
659
440
|
realProofs: !!this.config.realProofs,
|
|
441
|
+
txsLimits: { gas: { daGas: maxTxGas.daGas, l2Gas: maxTxGas.l2Gas } },
|
|
660
442
|
};
|
|
661
443
|
|
|
662
444
|
return nodeInfo;
|
|
663
445
|
}
|
|
664
446
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
668
|
-
* @returns The requested block.
|
|
669
|
-
*/
|
|
670
|
-
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
671
|
-
if (BlockHash.isBlockHash(block)) {
|
|
672
|
-
return this.getBlockByHash(block);
|
|
673
|
-
}
|
|
674
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
675
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
676
|
-
return this.buildInitialBlock();
|
|
677
|
-
}
|
|
678
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Get a block specified by its hash.
|
|
683
|
-
* @param blockHash - The block hash being requested.
|
|
684
|
-
* @returns The requested block.
|
|
685
|
-
*/
|
|
686
|
-
public async getBlockByHash(blockHash: BlockHash): Promise<L2Block | undefined> {
|
|
687
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
688
|
-
if (blockHash.equals(initialBlockHash)) {
|
|
689
|
-
return this.buildInitialBlock();
|
|
690
|
-
}
|
|
691
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
private buildInitialBlock(): L2Block {
|
|
695
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
696
|
-
return L2Block.empty(initialHeader);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Get a block specified by its archive root.
|
|
701
|
-
* @param archive - The archive root being requested.
|
|
702
|
-
* @returns The requested block.
|
|
703
|
-
*/
|
|
704
|
-
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
705
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
710
|
-
* @param from - The start of the range of blocks to return.
|
|
711
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
712
|
-
* @returns The blocks requested.
|
|
713
|
-
*/
|
|
714
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
715
|
-
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
719
|
-
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
public async getCheckpointedBlocks(from: BlockNumber, limit: number) {
|
|
723
|
-
return (await this.blockSource.getCheckpointedBlocks(from, limit)) ?? [];
|
|
447
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
448
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
724
449
|
}
|
|
725
450
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
/**
|
|
731
|
-
* Method to fetch the current min L2 fees.
|
|
732
|
-
* @returns The current min L2 fees.
|
|
733
|
-
*/
|
|
734
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
735
|
-
return await this.globalVariableBuilder.getCurrentMinFees();
|
|
451
|
+
/** Returns predicted min fees for the current slot and next N slots. */
|
|
452
|
+
public async getPredictedMinFees(manaUsage?: ManaUsageEstimate): Promise<GasFees[]> {
|
|
453
|
+
return await this.feeProvider.getPredictedMinFees(manaUsage);
|
|
736
454
|
}
|
|
737
455
|
|
|
738
456
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
739
|
-
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
457
|
+
for await (const tx of this.p2pClient.iteratePendingTxs({ includeProof: false })) {
|
|
740
458
|
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
741
459
|
}
|
|
742
460
|
|
|
743
461
|
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
744
462
|
}
|
|
745
463
|
|
|
746
|
-
/**
|
|
747
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
748
|
-
* @returns The block number.
|
|
749
|
-
*/
|
|
750
|
-
public async getBlockNumber(): Promise<BlockNumber> {
|
|
751
|
-
return await this.blockSource.getBlockNumber();
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
755
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
759
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
public getCheckpointNumber(): Promise<CheckpointNumber> {
|
|
763
|
-
return this.blockSource.getCheckpointNumber();
|
|
764
|
-
}
|
|
765
|
-
|
|
766
464
|
/**
|
|
767
465
|
* Method to fetch the version of the package.
|
|
768
466
|
* @returns The node package version
|
|
@@ -791,73 +489,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
791
489
|
return this.contractDataSource.getContractClass(id);
|
|
792
490
|
}
|
|
793
491
|
|
|
794
|
-
public getContract(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
let upToBlockNumber: BlockNumber | undefined;
|
|
804
|
-
if (referenceBlock) {
|
|
805
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
806
|
-
if (referenceBlock.equals(initialBlockHash)) {
|
|
807
|
-
upToBlockNumber = BlockNumber(0);
|
|
808
|
-
} else {
|
|
809
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
810
|
-
if (!header) {
|
|
811
|
-
throw new Error(
|
|
812
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
upToBlockNumber = header.globalVariables.blockNumber;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return this.logsSource.getPrivateLogsByTags(tags, page, upToBlockNumber);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
public async getPublicLogsByTagsFromContract(
|
|
822
|
-
contractAddress: AztecAddress,
|
|
823
|
-
tags: Tag[],
|
|
824
|
-
page?: number,
|
|
825
|
-
referenceBlock?: BlockHash,
|
|
826
|
-
): Promise<TxScopedL2Log[][]> {
|
|
827
|
-
let upToBlockNumber: BlockNumber | undefined;
|
|
828
|
-
if (referenceBlock) {
|
|
829
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
830
|
-
if (referenceBlock.equals(initialBlockHash)) {
|
|
831
|
-
upToBlockNumber = BlockNumber(0);
|
|
832
|
-
} else {
|
|
833
|
-
const header = await this.blockSource.getBlockHeaderByHash(referenceBlock);
|
|
834
|
-
if (!header) {
|
|
835
|
-
throw new Error(
|
|
836
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
upToBlockNumber = header.globalVariables.blockNumber;
|
|
840
|
-
}
|
|
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
|
+
);
|
|
841
501
|
}
|
|
842
|
-
return this.
|
|
502
|
+
return this.contractDataSource.getContract(address, blockData.header.globalVariables.timestamp);
|
|
843
503
|
}
|
|
844
504
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
* @param filter - The filter to apply to the logs.
|
|
848
|
-
* @returns The requested logs.
|
|
849
|
-
*/
|
|
850
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
851
|
-
return this.logsSource.getPublicLogs(filter);
|
|
505
|
+
public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
506
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
852
507
|
}
|
|
853
508
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
* @param filter - The filter to apply to the logs.
|
|
857
|
-
* @returns The requested logs.
|
|
858
|
-
*/
|
|
859
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
860
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
509
|
+
public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
|
|
510
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
861
511
|
}
|
|
862
512
|
|
|
863
513
|
/**
|
|
@@ -880,37 +530,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
880
530
|
throw new Error(`Invalid tx: ${reason}`);
|
|
881
531
|
}
|
|
882
532
|
|
|
883
|
-
|
|
533
|
+
try {
|
|
534
|
+
await this.p2pClient!.sendTx(tx);
|
|
535
|
+
} catch (err) {
|
|
536
|
+
this.metrics.receivedTx(timer.ms(), false);
|
|
537
|
+
this.log.warn(`Mempool rejected tx ${txHash}: ${(err as Error).message}`, { txHash });
|
|
538
|
+
throw err;
|
|
539
|
+
}
|
|
884
540
|
const duration = timer.ms();
|
|
885
541
|
this.metrics.receivedTx(duration, true);
|
|
886
542
|
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
887
543
|
}
|
|
888
544
|
|
|
889
|
-
public
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
896
|
-
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
897
|
-
|
|
898
|
-
let receipt: TxReceipt;
|
|
899
|
-
if (settledTxReceipt) {
|
|
900
|
-
receipt = settledTxReceipt;
|
|
901
|
-
} else if (isKnownToPool) {
|
|
902
|
-
// If the tx is in the pool but not in the archiver, it's pending.
|
|
903
|
-
// This handles race conditions between archiver and p2p, where the archiver
|
|
904
|
-
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
905
|
-
receipt = new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
906
|
-
} else {
|
|
907
|
-
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
908
|
-
receipt = new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
this.debugLogStore.decorateReceiptWithLogs(txHash.toString(), receipt);
|
|
912
|
-
|
|
913
|
-
return receipt;
|
|
545
|
+
public getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
|
|
546
|
+
txHash: TxHash,
|
|
547
|
+
options?: TGetTxReceiptOptions,
|
|
548
|
+
): Promise<TxReceipt<TGetTxReceiptOptions>> {
|
|
549
|
+
return this.txReceiptBuilder.getTxReceipt(txHash, options);
|
|
914
550
|
}
|
|
915
551
|
|
|
916
552
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -922,11 +558,11 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
922
558
|
*/
|
|
923
559
|
public async stop() {
|
|
924
560
|
this.log.info(`Stopping Aztec Node`);
|
|
925
|
-
await
|
|
926
|
-
await tryStop(this.epochPruneWatcher);
|
|
561
|
+
await this.stopStartedWatchers();
|
|
927
562
|
await tryStop(this.slasherClient);
|
|
928
|
-
await tryStop(this.
|
|
563
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
929
564
|
await tryStop(this.sequencer);
|
|
565
|
+
await tryStop(this.automineSequencer);
|
|
930
566
|
await tryStop(this.proverNode);
|
|
931
567
|
await tryStop(this.p2pClient);
|
|
932
568
|
await tryStop(this.worldStateSynchronizer);
|
|
@@ -950,364 +586,146 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
950
586
|
* @param after - The last known pending tx. Used for pagination
|
|
951
587
|
* @returns - The pending txs.
|
|
952
588
|
*/
|
|
953
|
-
public getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
954
|
-
return this.p2pClient!.getPendingTxs(limit, after);
|
|
589
|
+
public getPendingTxs(limit?: number, after?: TxHash, options?: GetTxByHashOptions): Promise<Tx[]> {
|
|
590
|
+
return this.p2pClient!.getPendingTxs(limit, after, options);
|
|
955
591
|
}
|
|
956
592
|
|
|
957
593
|
public getPendingTxCount(): Promise<number> {
|
|
958
594
|
return this.p2pClient!.getPendingTxCount();
|
|
959
595
|
}
|
|
960
596
|
|
|
597
|
+
public getPeers(includePending?: boolean): Promise<PeerInfo[]> {
|
|
598
|
+
return this.p2pClient!.getPeers(includePending);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
public getCheckpointAttestationsForSlot(
|
|
602
|
+
slot: SlotNumber,
|
|
603
|
+
proposalPayloadHash?: CheckpointProposalHash,
|
|
604
|
+
): Promise<CheckpointAttestation[]> {
|
|
605
|
+
return this.p2pClient!.getCheckpointAttestationsForSlot(slot, proposalPayloadHash);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
public getProposalsForSlot(slot: SlotNumber): Promise<ProposalsForSlot> {
|
|
609
|
+
return this.p2pClient!.getProposalsForSlot(slot);
|
|
610
|
+
}
|
|
611
|
+
|
|
961
612
|
/**
|
|
962
|
-
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
613
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain. The tx's proof is only loaded and returned
|
|
614
|
+
* when `includeProof` is set.
|
|
963
615
|
* @param txHash - The transaction hash to return.
|
|
616
|
+
* @param options - Options for the returned tx (eg whether to include its proof).
|
|
964
617
|
* @returns - The tx if it exists.
|
|
965
618
|
*/
|
|
966
|
-
public getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
967
|
-
return
|
|
619
|
+
public getTxByHash(txHash: TxHash, options?: GetTxByHashOptions): Promise<Tx | undefined> {
|
|
620
|
+
return this.p2pClient!.getTxByHashFromPool(txHash, { includeProof: !!options?.includeProof });
|
|
968
621
|
}
|
|
969
622
|
|
|
970
623
|
/**
|
|
971
|
-
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
624
|
+
* Method to retrieve txs from the mempool or unfinalized chain. The txs' proofs are only loaded and returned when
|
|
625
|
+
* `includeProof` is set.
|
|
972
626
|
* @param txHash - The transaction hash to return.
|
|
627
|
+
* @param options - Options for the returned txs (eg whether to include their proofs).
|
|
973
628
|
* @returns - The txs if it exists.
|
|
974
629
|
*/
|
|
975
|
-
public async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
|
|
976
|
-
|
|
630
|
+
public async getTxsByHash(txHashes: TxHash[], options?: GetTxByHashOptions): Promise<Tx[]> {
|
|
631
|
+
const txs = await this.p2pClient!.getTxsByHashFromPool(txHashes, { includeProof: !!options?.includeProof });
|
|
632
|
+
return compactArray(txs);
|
|
977
633
|
}
|
|
978
634
|
|
|
979
|
-
public
|
|
635
|
+
public findLeavesIndexes(
|
|
980
636
|
referenceBlock: BlockParameter,
|
|
981
637
|
treeId: MerkleTreeId,
|
|
982
638
|
leafValues: Fr[],
|
|
983
639
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
984
|
-
|
|
985
|
-
const maybeIndices = await committedDb.findLeafIndices(
|
|
986
|
-
treeId,
|
|
987
|
-
leafValues.map(x => x.toBuffer()),
|
|
988
|
-
);
|
|
989
|
-
// Filter out undefined values to query block numbers only for found leaves
|
|
990
|
-
const definedIndices = maybeIndices.filter(x => x !== undefined);
|
|
991
|
-
|
|
992
|
-
// Now we find the block numbers for the defined indices
|
|
993
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, definedIndices);
|
|
994
|
-
|
|
995
|
-
// Build a map from leaf index to block number
|
|
996
|
-
const indexToBlockNumber = new Map<bigint, BlockNumber>();
|
|
997
|
-
for (let i = 0; i < definedIndices.length; i++) {
|
|
998
|
-
const blockNumber = blockNumbers[i];
|
|
999
|
-
if (blockNumber === undefined) {
|
|
1000
|
-
throw new Error(
|
|
1001
|
-
`Block number is undefined for leaf index ${definedIndices[i]} in tree ${MerkleTreeId[treeId]}`,
|
|
1002
|
-
);
|
|
1003
|
-
}
|
|
1004
|
-
indexToBlockNumber.set(definedIndices[i], blockNumber);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
1008
|
-
const uniqueBlockNumbers = [...new Set(indexToBlockNumber.values())];
|
|
1009
|
-
|
|
1010
|
-
// Now we obtain the block hashes from the archive tree (block number = leaf index in archive tree).
|
|
1011
|
-
const blockHashes = await Promise.all(
|
|
1012
|
-
uniqueBlockNumbers.map(blockNumber => {
|
|
1013
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
1014
|
-
}),
|
|
1015
|
-
);
|
|
1016
|
-
|
|
1017
|
-
// Build a map from block number to block hash
|
|
1018
|
-
const blockNumberToHash = new Map<BlockNumber, Fr>();
|
|
1019
|
-
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
1020
|
-
const blockHash = blockHashes[i];
|
|
1021
|
-
if (blockHash === undefined) {
|
|
1022
|
-
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
1023
|
-
}
|
|
1024
|
-
blockNumberToHash.set(uniqueBlockNumbers[i], blockHash);
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
1028
|
-
return maybeIndices.map(index => {
|
|
1029
|
-
if (index === undefined) {
|
|
1030
|
-
return undefined;
|
|
1031
|
-
}
|
|
1032
|
-
const blockNumber = indexToBlockNumber.get(index);
|
|
1033
|
-
if (blockNumber === undefined) {
|
|
1034
|
-
throw new Error(`Block number not found for leaf index ${index} in tree ${MerkleTreeId[treeId]}`);
|
|
1035
|
-
}
|
|
1036
|
-
const blockHash = blockNumberToHash.get(blockNumber);
|
|
1037
|
-
if (blockHash === undefined) {
|
|
1038
|
-
throw new Error(`Block hash not found for block number ${blockNumber}`);
|
|
1039
|
-
}
|
|
1040
|
-
return {
|
|
1041
|
-
l2BlockNumber: blockNumber,
|
|
1042
|
-
l2BlockHash: new BlockHash(blockHash),
|
|
1043
|
-
data: index,
|
|
1044
|
-
};
|
|
1045
|
-
});
|
|
640
|
+
return this.worldStateQueries.findLeavesIndexes(referenceBlock, treeId, leafValues);
|
|
1046
641
|
}
|
|
1047
642
|
|
|
1048
|
-
public
|
|
643
|
+
public getBlockHashMembershipWitness(
|
|
1049
644
|
referenceBlock: BlockParameter,
|
|
1050
645
|
blockHash: BlockHash,
|
|
1051
646
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
const committedDb = await this.getWorldState(BlockNumber(referenceBlockNumber - 1));
|
|
1057
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [blockHash]);
|
|
1058
|
-
return pathAndIndex === undefined
|
|
1059
|
-
? undefined
|
|
1060
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
public async getNoteHashMembershipWitness(
|
|
647
|
+
return this.worldStateQueries.getBlockHashMembershipWitness(referenceBlock, blockHash);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
public getNoteHashMembershipWitness(
|
|
1064
651
|
referenceBlock: BlockParameter,
|
|
1065
652
|
noteHash: Fr,
|
|
1066
653
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
1067
|
-
|
|
1068
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
1069
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
1070
|
-
[noteHash],
|
|
1071
|
-
);
|
|
1072
|
-
return pathAndIndex === undefined
|
|
1073
|
-
? undefined
|
|
1074
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
654
|
+
return this.worldStateQueries.getNoteHashMembershipWitness(referenceBlock, noteHash);
|
|
1075
655
|
}
|
|
1076
656
|
|
|
1077
|
-
public
|
|
657
|
+
public getL1ToL2MessageMembershipWitness(
|
|
1078
658
|
referenceBlock: BlockParameter,
|
|
1079
659
|
l1ToL2Message: Fr,
|
|
1080
660
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
1081
|
-
|
|
1082
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
1083
|
-
if (!witness) {
|
|
1084
|
-
return undefined;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
// REFACTOR: Return a MembershipWitness object
|
|
1088
|
-
return [witness.index, witness.path];
|
|
661
|
+
return this.worldStateQueries.getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message);
|
|
1089
662
|
}
|
|
1090
663
|
|
|
1091
|
-
public
|
|
1092
|
-
|
|
1093
|
-
return messageIndex ? InboxLeaf.checkpointNumberFromIndex(messageIndex) : undefined;
|
|
664
|
+
public getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
665
|
+
return this.worldStateQueries.getL1ToL2MessageCheckpoint(l1ToL2Message);
|
|
1094
666
|
}
|
|
1095
667
|
|
|
1096
668
|
/**
|
|
1097
|
-
* Returns
|
|
1098
|
-
*
|
|
1099
|
-
* @
|
|
669
|
+
* Returns all the L2 to L1 messages in an epoch.
|
|
670
|
+
*
|
|
671
|
+
* @deprecated Use {@link getL2ToL1MembershipWitness} to get an L2-to-L1 message witness directly.
|
|
672
|
+
*
|
|
673
|
+
* @param epoch - The epoch at which to get the data.
|
|
674
|
+
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1100
675
|
*/
|
|
1101
|
-
public
|
|
1102
|
-
|
|
1103
|
-
return messageIndex !== undefined;
|
|
676
|
+
public getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
677
|
+
return this.worldStateQueries.getL2ToL1Messages(epoch);
|
|
1104
678
|
}
|
|
1105
679
|
|
|
1106
680
|
/**
|
|
1107
|
-
* Returns
|
|
1108
|
-
*
|
|
1109
|
-
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
681
|
+
* Returns the L2-to-L1 membership witness for a message in `txHash`. Passthrough to the
|
|
682
|
+
* archiver's locally-cached resolver — see {@link Archiver.getL2ToL1MembershipWitness}.
|
|
1110
683
|
*/
|
|
1111
|
-
public
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
);
|
|
1117
|
-
return blocksInCheckpoints.map(blocks =>
|
|
1118
|
-
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1119
|
-
);
|
|
684
|
+
public getL2ToL1MembershipWitness(
|
|
685
|
+
txHash: TxHash,
|
|
686
|
+
message: Fr,
|
|
687
|
+
messageIndexInTx?: number,
|
|
688
|
+
): Promise<L2ToL1MembershipWitness | undefined> {
|
|
689
|
+
return this.worldStateQueries.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1120
690
|
}
|
|
1121
691
|
|
|
1122
|
-
public
|
|
692
|
+
public getNullifierMembershipWitness(
|
|
1123
693
|
referenceBlock: BlockParameter,
|
|
1124
694
|
nullifier: Fr,
|
|
1125
695
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1126
|
-
|
|
1127
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1128
|
-
if (!witness) {
|
|
1129
|
-
return undefined;
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
const { index, path } = witness;
|
|
1133
|
-
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1134
|
-
if (!leafPreimage) {
|
|
1135
|
-
return undefined;
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
696
|
+
return this.worldStateQueries.getNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1139
697
|
}
|
|
1140
698
|
|
|
1141
|
-
public
|
|
699
|
+
public getLowNullifierMembershipWitness(
|
|
1142
700
|
referenceBlock: BlockParameter,
|
|
1143
701
|
nullifier: Fr,
|
|
1144
702
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1145
|
-
|
|
1146
|
-
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1147
|
-
if (!findResult) {
|
|
1148
|
-
return undefined;
|
|
1149
|
-
}
|
|
1150
|
-
const { index, alreadyPresent } = findResult;
|
|
1151
|
-
if (alreadyPresent) {
|
|
1152
|
-
throw new Error(
|
|
1153
|
-
`Cannot prove nullifier non-inclusion: nullifier ${nullifier.toBigInt()} already exists in the tree`,
|
|
1154
|
-
);
|
|
1155
|
-
}
|
|
1156
|
-
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1157
|
-
|
|
1158
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1159
|
-
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
703
|
+
return this.worldStateQueries.getLowNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1160
704
|
}
|
|
1161
705
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1165
|
-
if (!lowLeafResult) {
|
|
1166
|
-
return undefined;
|
|
1167
|
-
} else {
|
|
1168
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1169
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1170
|
-
lowLeafResult.index,
|
|
1171
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1172
|
-
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1173
|
-
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1174
|
-
}
|
|
706
|
+
public getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
707
|
+
return this.worldStateQueries.getPublicDataWitness(referenceBlock, leafSlot);
|
|
1175
708
|
}
|
|
1176
709
|
|
|
1177
|
-
public
|
|
1178
|
-
|
|
1179
|
-
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1180
|
-
|
|
1181
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1182
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
1183
|
-
return Fr.ZERO;
|
|
1184
|
-
}
|
|
1185
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1186
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1187
|
-
lowLeafResult.index,
|
|
1188
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1189
|
-
return preimage.leaf.value;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1193
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1194
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1195
|
-
if (block.equals(initialBlockHash)) {
|
|
1196
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1197
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1198
|
-
}
|
|
1199
|
-
return this.blockSource.getBlockHeaderByHash(block);
|
|
1200
|
-
} else {
|
|
1201
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1202
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1203
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1204
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1205
|
-
}
|
|
1206
|
-
return this.blockSource.getBlockHeader(block);
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
/**
|
|
1211
|
-
* Get a block header specified by its archive root.
|
|
1212
|
-
* @param archive - The archive root being requested.
|
|
1213
|
-
* @returns The requested block header.
|
|
1214
|
-
*/
|
|
1215
|
-
public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
1216
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
public getBlockData(number: BlockNumber): Promise<BlockData | undefined> {
|
|
1220
|
-
return this.blockSource.getBlockData(number);
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
public getBlockDataByArchive(archive: Fr): Promise<BlockData | undefined> {
|
|
1224
|
-
return this.blockSource.getBlockDataByArchive(archive);
|
|
710
|
+
public getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
711
|
+
return this.worldStateQueries.getPublicStorageAt(referenceBlock, contract, slot);
|
|
1225
712
|
}
|
|
1226
713
|
|
|
1227
714
|
/**
|
|
1228
715
|
* Simulates the public part of a transaction with the current state.
|
|
1229
716
|
* @param tx - The transaction to simulate.
|
|
717
|
+
* @param skipFeeEnforcement - If true, fee enforcement is skipped.
|
|
718
|
+
* @param overrides - Optional pre-simulation overrides applied to the ephemeral fork and contract DB.
|
|
1230
719
|
**/
|
|
1231
720
|
@trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
|
|
1232
721
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1233
722
|
}))
|
|
1234
|
-
public
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
throw new BadRequestError(
|
|
1241
|
-
`Transaction total gas limit ${
|
|
1242
|
-
txGasLimit + teardownGasLimit
|
|
1243
|
-
} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${
|
|
1244
|
-
this.config.rpcSimulatePublicMaxGasLimit
|
|
1245
|
-
} for simulation`,
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
const txHash = tx.getTxHash();
|
|
1250
|
-
const latestBlockNumber = await this.blockSource.getBlockNumber();
|
|
1251
|
-
const blockNumber = BlockNumber.add(latestBlockNumber, 1);
|
|
1252
|
-
|
|
1253
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1254
|
-
const coinbase = EthAddress.ZERO;
|
|
1255
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1256
|
-
|
|
1257
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
|
|
1258
|
-
blockNumber,
|
|
1259
|
-
coinbase,
|
|
1260
|
-
feeRecipient,
|
|
1261
|
-
);
|
|
1262
|
-
const publicProcessorFactory = new PublicProcessorFactory(
|
|
1263
|
-
this.contractDataSource,
|
|
1264
|
-
new DateProvider(),
|
|
1265
|
-
this.telemetry,
|
|
1266
|
-
this.log.getBindings(),
|
|
1267
|
-
);
|
|
1268
|
-
|
|
1269
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1270
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1271
|
-
txHash,
|
|
1272
|
-
blockNumber,
|
|
1273
|
-
});
|
|
1274
|
-
|
|
1275
|
-
// Ensure world-state has caught up with the latest block we loaded from the archiver
|
|
1276
|
-
await this.worldStateSynchronizer.syncImmediate(latestBlockNumber);
|
|
1277
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1278
|
-
try {
|
|
1279
|
-
const config = PublicSimulatorConfig.from({
|
|
1280
|
-
skipFeeEnforcement,
|
|
1281
|
-
collectDebugLogs: true,
|
|
1282
|
-
collectHints: false,
|
|
1283
|
-
collectCallMetadata: true,
|
|
1284
|
-
collectStatistics: false,
|
|
1285
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1286
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1287
|
-
}),
|
|
1288
|
-
});
|
|
1289
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1290
|
-
|
|
1291
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1292
|
-
const [processedTxs, failedTxs, _usedTxs, returns, debugLogs] = await processor.process([tx]);
|
|
1293
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1294
|
-
if (failedTxs.length) {
|
|
1295
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1296
|
-
throw failedTxs[0].error;
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
const [processedTx] = processedTxs;
|
|
1300
|
-
return new PublicSimulationOutput(
|
|
1301
|
-
processedTx.revertReason,
|
|
1302
|
-
processedTx.globalVariables,
|
|
1303
|
-
processedTx.txEffect,
|
|
1304
|
-
returns,
|
|
1305
|
-
processedTx.gasUsed,
|
|
1306
|
-
debugLogs,
|
|
1307
|
-
);
|
|
1308
|
-
} finally {
|
|
1309
|
-
await merkleTreeFork.close();
|
|
1310
|
-
}
|
|
723
|
+
public simulatePublicCalls(
|
|
724
|
+
tx: Tx,
|
|
725
|
+
skipFeeEnforcement = false,
|
|
726
|
+
overrides?: SimulationOverrides,
|
|
727
|
+
): Promise<PublicSimulationOutput> {
|
|
728
|
+
return this.nodePublicCallsSimulator.simulate(tx, skipFeeEnforcement, overrides);
|
|
1311
729
|
}
|
|
1312
730
|
|
|
1313
731
|
public async isValidTx(
|
|
@@ -1315,12 +733,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1315
733
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1316
734
|
): Promise<TxValidationResult> {
|
|
1317
735
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1318
|
-
const verifier = isSimulation ? undefined : this.
|
|
736
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1319
737
|
|
|
1320
738
|
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1321
739
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1322
740
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1323
741
|
const l1Constants = await this.blockSource.getL1Constants();
|
|
742
|
+
// Enforce the same network admission limit the node advertises in getNodeInfo (network-wide, not this
|
|
743
|
+
// node's local caps), so a tx the wallet sized against txsLimits is not rejected here.
|
|
744
|
+
const networkTxGasLimits = getNetworkTxGasLimits(this.config, l1Constants);
|
|
1324
745
|
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
1325
746
|
db,
|
|
1326
747
|
this.contractDataSource,
|
|
@@ -1336,10 +757,10 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1336
757
|
],
|
|
1337
758
|
gasFees: await this.getCurrentMinFees(),
|
|
1338
759
|
skipFeeEnforcement,
|
|
760
|
+
isSimulation,
|
|
1339
761
|
txsPermitted: !this.config.disableTransactions,
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
maxBlockDAGas: this.config.validateMaxDABlockGas,
|
|
762
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
763
|
+
maxTxDAGas: networkTxGasLimits.daGas,
|
|
1343
764
|
},
|
|
1344
765
|
this.log.getBindings(),
|
|
1345
766
|
);
|
|
@@ -1355,7 +776,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1355
776
|
|
|
1356
777
|
public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
|
|
1357
778
|
const newConfig = { ...this.config, ...config };
|
|
1358
|
-
|
|
779
|
+
// If the sequencer is currently paused via pauseSequencer(), record the caller's desired
|
|
780
|
+
// minTxsPerBlock as the restore value (so resumeSequencer applies it) and keep the freeze
|
|
781
|
+
// (MAX_SAFE_INTEGER) applied to the underlying sequencer. Without this guard, forwarding
|
|
782
|
+
// the new minTxsPerBlock to the sequencer would silently unpause block production while
|
|
783
|
+
// pauseSequencer() still considers it paused.
|
|
784
|
+
const sequencerUpdate = { ...config };
|
|
785
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined && sequencerUpdate.minTxsPerBlock !== undefined) {
|
|
786
|
+
this.sequencerPausedMinTxsPerBlock = sequencerUpdate.minTxsPerBlock;
|
|
787
|
+
delete sequencerUpdate.minTxsPerBlock;
|
|
788
|
+
}
|
|
789
|
+
this.sequencer?.updateConfig(sequencerUpdate);
|
|
790
|
+
this.automineSequencer?.updateConfig(sequencerUpdate);
|
|
1359
791
|
this.slasherClient?.updateConfig(config);
|
|
1360
792
|
this.validatorsSentinel?.updateConfig(config);
|
|
1361
793
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1364,7 +796,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1364
796
|
archiver.updateConfig(config);
|
|
1365
797
|
}
|
|
1366
798
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1367
|
-
|
|
799
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
800
|
+
if (newConfig.realProofs) {
|
|
801
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
802
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
803
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
804
|
+
} else {
|
|
805
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
806
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
807
|
+
}
|
|
1368
808
|
}
|
|
1369
809
|
|
|
1370
810
|
this.config = newConfig;
|
|
@@ -1375,7 +815,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1375
815
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1376
816
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1377
817
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1378
|
-
multiCallEntrypoint:
|
|
818
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
1379
819
|
});
|
|
1380
820
|
}
|
|
1381
821
|
|
|
@@ -1439,7 +879,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1439
879
|
return Promise.resolve();
|
|
1440
880
|
}
|
|
1441
881
|
|
|
1442
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
882
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1443
883
|
const archiver = this.blockSource as Archiver;
|
|
1444
884
|
if (!('rollbackTo' in archiver)) {
|
|
1445
885
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1469,9 +909,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1469
909
|
this.log.error(`Error during rollback`, err);
|
|
1470
910
|
throw err;
|
|
1471
911
|
} finally {
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
912
|
+
if (resumeSync) {
|
|
913
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
914
|
+
this.worldStateSynchronizer.resumeSync();
|
|
915
|
+
archiver.resume();
|
|
916
|
+
} else {
|
|
917
|
+
this.log.info(`Sync left paused after rollback (resumeSync=false).`);
|
|
918
|
+
}
|
|
1475
919
|
}
|
|
1476
920
|
}
|
|
1477
921
|
|
|
@@ -1488,11 +932,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1488
932
|
return Promise.resolve();
|
|
1489
933
|
}
|
|
1490
934
|
|
|
1491
|
-
public
|
|
1492
|
-
if (
|
|
1493
|
-
|
|
935
|
+
public pauseSequencer(): Promise<void> {
|
|
936
|
+
if (this.automineSequencer) {
|
|
937
|
+
this.automineSequencer.pause();
|
|
938
|
+
return Promise.resolve();
|
|
939
|
+
}
|
|
940
|
+
if (this.sequencer) {
|
|
941
|
+
if (this.sequencerPausedMinTxsPerBlock === undefined) {
|
|
942
|
+
this.sequencerPausedMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock ?? 0;
|
|
943
|
+
this.sequencer.updateConfig({ minTxsPerBlock: Number.MAX_SAFE_INTEGER });
|
|
944
|
+
this.log.info(`Sequencer paused (minTxsPerBlock set to MAX_SAFE_INTEGER)`, {
|
|
945
|
+
previousMinTxsPerBlock: this.sequencerPausedMinTxsPerBlock,
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
return Promise.resolve();
|
|
1494
949
|
}
|
|
1495
|
-
|
|
950
|
+
throw new BadRequestError('Cannot pause sequencer: no sequencer is running');
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
public resumeSequencer(): Promise<void> {
|
|
954
|
+
if (this.automineSequencer) {
|
|
955
|
+
this.automineSequencer.resume();
|
|
956
|
+
return Promise.resolve();
|
|
957
|
+
}
|
|
958
|
+
if (this.sequencer) {
|
|
959
|
+
if (this.sequencerPausedMinTxsPerBlock !== undefined) {
|
|
960
|
+
const restored = this.sequencerPausedMinTxsPerBlock;
|
|
961
|
+
this.sequencerPausedMinTxsPerBlock = undefined;
|
|
962
|
+
this.sequencer.updateConfig({ minTxsPerBlock: restored });
|
|
963
|
+
this.log.info(`Sequencer resumed (minTxsPerBlock restored)`, { minTxsPerBlock: restored });
|
|
964
|
+
}
|
|
965
|
+
return Promise.resolve();
|
|
966
|
+
}
|
|
967
|
+
throw new BadRequestError('Cannot resume sequencer: no sequencer is running');
|
|
1496
968
|
}
|
|
1497
969
|
|
|
1498
970
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
@@ -1500,7 +972,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1500
972
|
throw new Error(`Slasher client not enabled`);
|
|
1501
973
|
}
|
|
1502
974
|
if (round === 'all') {
|
|
1503
|
-
return this.slasherClient.
|
|
975
|
+
return this.slasherClient.getOffenses();
|
|
1504
976
|
} else {
|
|
1505
977
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1506
978
|
}
|
|
@@ -1594,99 +1066,71 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1594
1066
|
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1595
1067
|
}
|
|
1596
1068
|
|
|
1597
|
-
|
|
1598
|
-
if (
|
|
1599
|
-
|
|
1069
|
+
public async mineBlock(): Promise<void> {
|
|
1070
|
+
if (this.automineSequencer) {
|
|
1071
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
1072
|
+
return;
|
|
1600
1073
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
/**
|
|
1605
|
-
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
1606
|
-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1607
|
-
* @returns An instance of a committed MerkleTreeOperations
|
|
1608
|
-
*/
|
|
1609
|
-
protected async getWorldState(block: BlockParameter) {
|
|
1610
|
-
let blockSyncedTo: BlockNumber = BlockNumber.ZERO;
|
|
1611
|
-
try {
|
|
1612
|
-
// Attempt to sync the world state if necessary
|
|
1613
|
-
blockSyncedTo = await this.#syncWorldState();
|
|
1614
|
-
} catch (err) {
|
|
1615
|
-
this.log.error(`Error getting world state: ${err}`);
|
|
1074
|
+
if (!this.sequencer) {
|
|
1075
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1616
1076
|
}
|
|
1617
1077
|
|
|
1618
|
-
|
|
1619
|
-
this.log.debug(`Using committed db for block 'latest', world state synced upto ${blockSyncedTo}`);
|
|
1620
|
-
return this.worldStateSynchronizer.getCommitted();
|
|
1621
|
-
}
|
|
1078
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1622
1079
|
|
|
1623
|
-
//
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1627
|
-
if (block.equals(initialBlockHash)) {
|
|
1628
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1629
|
-
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1630
|
-
}
|
|
1080
|
+
// Use slot duration + 50% buffer as the timeout so this works on running networks too
|
|
1081
|
+
const { slotDuration } = await this.blockSource.getL1Constants();
|
|
1082
|
+
const timeoutSeconds = Math.ceil(slotDuration * 1.5);
|
|
1631
1083
|
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
`Block hash ${block.toString()} not found when querying world state. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1636
|
-
);
|
|
1637
|
-
}
|
|
1084
|
+
// Temporarily set minTxsPerBlock to 0 so the sequencer produces a block even with no txs
|
|
1085
|
+
const originalMinTxsPerBlock = this.sequencer.getSequencer().getConfig().minTxsPerBlock;
|
|
1086
|
+
this.sequencer.updateConfig({ minTxsPerBlock: 0 });
|
|
1638
1087
|
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1088
|
+
try {
|
|
1089
|
+
// Trigger the sequencer to produce a block immediately
|
|
1090
|
+
void this.sequencer.trigger();
|
|
1091
|
+
|
|
1092
|
+
// Wait for the new L2 block to appear
|
|
1093
|
+
await retryUntil(
|
|
1094
|
+
async () => {
|
|
1095
|
+
const newBlockNumber = await this.getBlockNumber();
|
|
1096
|
+
return newBlockNumber > currentBlockNumber ? true : undefined;
|
|
1097
|
+
},
|
|
1098
|
+
'mineBlock',
|
|
1099
|
+
timeoutSeconds,
|
|
1100
|
+
0.1,
|
|
1101
|
+
);
|
|
1102
|
+
} finally {
|
|
1103
|
+
this.sequencer.updateConfig({ minTxsPerBlock: originalMinTxsPerBlock });
|
|
1642
1104
|
}
|
|
1105
|
+
}
|
|
1643
1106
|
|
|
1644
|
-
|
|
1645
|
-
if (
|
|
1646
|
-
throw new
|
|
1107
|
+
public async prove(upToCheckpoint?: CheckpointNumber): Promise<CheckpointNumber> {
|
|
1108
|
+
if (!this.automineSequencer) {
|
|
1109
|
+
throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
|
|
1647
1110
|
}
|
|
1648
|
-
this.
|
|
1649
|
-
|
|
1650
|
-
const snapshot = this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1111
|
+
return await this.automineSequencer.prove(upToCheckpoint);
|
|
1112
|
+
}
|
|
1651
1113
|
|
|
1652
|
-
|
|
1653
|
-
if (
|
|
1654
|
-
|
|
1655
|
-
if (!blockHash || !new BlockHash(blockHash).equals(block)) {
|
|
1656
|
-
throw new Error(
|
|
1657
|
-
`Block hash ${block.toString()} not found in world state at block number ${blockNumber}. If the node API has been queried with anchor block hash possibly a reorg has occurred.`,
|
|
1658
|
-
);
|
|
1659
|
-
}
|
|
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');
|
|
1660
1117
|
}
|
|
1661
|
-
|
|
1662
|
-
return snapshot;
|
|
1118
|
+
await this.automineSequencer.warpTo(targetTimestamp);
|
|
1663
1119
|
}
|
|
1664
1120
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
return BlockNumber(await this.blockSource.getBlockNumber());
|
|
1669
|
-
}
|
|
1670
|
-
if (BlockHash.isBlockHash(block)) {
|
|
1671
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1672
|
-
if (block.equals(initialBlockHash)) {
|
|
1673
|
-
return BlockNumber.ZERO;
|
|
1674
|
-
}
|
|
1675
|
-
const header = await this.blockSource.getBlockHeaderByHash(block);
|
|
1676
|
-
if (!header) {
|
|
1677
|
-
throw new Error(`Block hash ${block.toString()} not found.`);
|
|
1678
|
-
}
|
|
1679
|
-
return header.getBlockNumber();
|
|
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');
|
|
1680
1124
|
}
|
|
1681
|
-
|
|
1125
|
+
await this.automineSequencer.warpBy(duration);
|
|
1682
1126
|
}
|
|
1683
1127
|
|
|
1684
1128
|
/**
|
|
1685
|
-
*
|
|
1686
|
-
* @
|
|
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.
|
|
1687
1132
|
*/
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1133
|
+
protected getWorldState(block: BlockParameter) {
|
|
1134
|
+
return this.worldStateQueries.getWorldState(block);
|
|
1691
1135
|
}
|
|
1692
1136
|
}
|