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