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