@aztec/aztec-node 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065
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 +23 -8
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +26 -8
- package/dest/aztec-node/node_metrics.d.ts +1 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +8 -4
- 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 +148 -146
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +490 -749
- 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 +6 -4
- package/dest/sentinel/factory.d.ts.map +1 -1
- package/dest/sentinel/factory.js +13 -6
- package/dest/sentinel/sentinel.d.ts +146 -22
- package/dest/sentinel/sentinel.d.ts.map +1 -1
- package/dest/sentinel/sentinel.js +266 -118
- package/dest/sentinel/store.d.ts +8 -8
- package/dest/sentinel/store.d.ts.map +1 -1
- package/dest/sentinel/store.js +33 -21
- package/dest/test/index.d.ts +3 -3
- package/dest/test/index.d.ts.map +1 -1
- package/package.json +28 -25
- package/src/aztec-node/block_response_helpers.ts +161 -0
- package/src/aztec-node/config.ts +55 -16
- package/src/aztec-node/node_metrics.ts +12 -5
- 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 +652 -993
- 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 +23 -13
- package/src/sentinel/sentinel.ts +316 -136
- package/src/sentinel/store.ts +35 -27
- package/src/test/index.ts +2 -2
package/src/aztec-node/server.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { Archiver
|
|
2
|
-
import { BBCircuitVerifier,
|
|
3
|
-
import {
|
|
1
|
+
import { Archiver } from '@aztec/archiver';
|
|
2
|
+
import { BBCircuitVerifier, BatchChonkVerifier, QueuedIVCVerifier } from '@aztec/bb-prover';
|
|
3
|
+
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
4
|
+
import type { BlobClientInterface } from '@aztec/blob-client/client';
|
|
5
|
+
import { ARCHIVE_HEIGHT, type L1_TO_L2_MSG_TREE_HEIGHT, type NOTE_HASH_TREE_HEIGHT } from '@aztec/constants';
|
|
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';
|
|
4
9
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from '@aztec/
|
|
11
|
-
import {
|
|
12
|
-
import { createEthereumChain } from '@aztec/ethereum/chain';
|
|
13
|
-
import { getPublicClient } from '@aztec/ethereum/client';
|
|
14
|
-
import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
|
|
15
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
16
|
-
import { BlockNumber, CheckpointNumber, EpochNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
17
|
-
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
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';
|
|
18
17
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
19
18
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
20
19
|
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
21
20
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
21
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
22
22
|
import { count } from '@aztec/foundation/string';
|
|
23
|
-
import {
|
|
23
|
+
import { Timer } from '@aztec/foundation/timer';
|
|
24
24
|
import { MembershipWitness, SiblingPath } from '@aztec/foundation/trees';
|
|
25
25
|
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
createForwarderL1TxUtilsFromEthSigner,
|
|
29
|
-
createL1TxUtilsWithBlobsFromEthSigner,
|
|
30
|
-
} from '@aztec/node-lib/factories';
|
|
31
|
-
import { type P2P, type P2PClientDeps, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
type SlasherClientInterface,
|
|
39
|
-
type Watcher,
|
|
40
|
-
createSlasher,
|
|
41
|
-
} from '@aztec/slasher';
|
|
42
|
-
import { CollectionLimitsConfig, PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
29
|
+
import type { ProverNode } from '@aztec/prover-node';
|
|
30
|
+
import { SequencerClient } from '@aztec/sequencer-client';
|
|
31
|
+
import { AutomineSequencer } from '@aztec/sequencer-client/automine';
|
|
32
|
+
import type { SlasherClientInterface } from '@aztec/slasher';
|
|
33
|
+
import { STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS } from '@aztec/standard-contracts/multi-call-entrypoint';
|
|
43
34
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
44
|
-
import {
|
|
45
|
-
|
|
35
|
+
import {
|
|
36
|
+
type BlockData,
|
|
37
|
+
BlockHash,
|
|
38
|
+
type BlockParameter,
|
|
39
|
+
type CheckpointsQuery,
|
|
40
|
+
type DataInBlock,
|
|
41
|
+
type L2BlockSource,
|
|
42
|
+
type L2BlockTag,
|
|
43
|
+
type L2Tips,
|
|
44
|
+
inspectBlockParameter,
|
|
45
|
+
} from '@aztec/stdlib/block';
|
|
46
46
|
import type {
|
|
47
47
|
ContractClassPublic,
|
|
48
48
|
ContractDataSource,
|
|
@@ -50,16 +50,25 @@ import type {
|
|
|
50
50
|
NodeInfo,
|
|
51
51
|
ProtocolContractAddresses,
|
|
52
52
|
} from '@aztec/stdlib/contract';
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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,
|
|
62
70
|
} from '@aztec/stdlib/interfaces/client';
|
|
71
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
63
72
|
import {
|
|
64
73
|
type AllowedElement,
|
|
65
74
|
type ClientProtocolCircuitVerifier,
|
|
@@ -69,24 +78,24 @@ import {
|
|
|
69
78
|
type WorldStateSynchronizer,
|
|
70
79
|
tryStop,
|
|
71
80
|
} from '@aztec/stdlib/interfaces/server';
|
|
72
|
-
import type {
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
import type {
|
|
76
|
-
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';
|
|
77
86
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
78
87
|
import {
|
|
79
|
-
type
|
|
88
|
+
type FeeProvider,
|
|
89
|
+
type GetTxReceiptOptions,
|
|
80
90
|
type GlobalVariableBuilder as GlobalVariableBuilderInterface,
|
|
81
91
|
type IndexedTxEffect,
|
|
82
92
|
PublicSimulationOutput,
|
|
93
|
+
type SimulationOverrides,
|
|
83
94
|
Tx,
|
|
84
95
|
type TxHash,
|
|
85
|
-
TxReceipt,
|
|
86
|
-
TxStatus,
|
|
96
|
+
type TxReceipt,
|
|
87
97
|
type TxValidationResult,
|
|
88
98
|
} from '@aztec/stdlib/tx';
|
|
89
|
-
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
90
99
|
import type { SingleValidatorStats, ValidatorsStats } from '@aztec/stdlib/validators';
|
|
91
100
|
import {
|
|
92
101
|
Attributes,
|
|
@@ -96,63 +105,175 @@ import {
|
|
|
96
105
|
getTelemetryClient,
|
|
97
106
|
trackSpan,
|
|
98
107
|
} from '@aztec/telemetry-client';
|
|
99
|
-
import {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
createBlockProposalHandler,
|
|
105
|
-
createValidatorClient,
|
|
106
|
-
createValidatorForAcceptingTxs,
|
|
107
|
-
} from '@aztec/validator-client';
|
|
108
|
-
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
109
|
-
|
|
110
|
-
import { createPublicClient, fallback, http } from 'viem';
|
|
111
|
-
|
|
112
|
-
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';
|
|
113
113
|
import { Sentinel } from '../sentinel/sentinel.js';
|
|
114
|
-
import {
|
|
114
|
+
import type { AztecNodeConfig } from './config.js';
|
|
115
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
|
+
}
|
|
116
153
|
|
|
117
154
|
/**
|
|
118
155
|
* The aztec node.
|
|
119
156
|
*/
|
|
120
|
-
export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
157
|
+
export class AztecNodeService implements AztecNode, AztecNodeAdmin, AztecNodeDebug, Traceable {
|
|
121
158
|
private metrics: NodeMetrics;
|
|
122
|
-
private initialHeaderHashPromise: Promise<L2BlockHash> | undefined = undefined;
|
|
123
|
-
|
|
124
159
|
// Prevent two snapshot operations to happen simultaneously
|
|
125
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;
|
|
126
167
|
|
|
127
168
|
public readonly tracer: Tracer;
|
|
128
169
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
+
});
|
|
153
262
|
|
|
154
263
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
155
|
-
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));
|
|
265
|
+
|
|
266
|
+
// A defensive check that protects us against introducing a bug in the complex node creation flow. We must
|
|
267
|
+
// never have debugLogStore enabled when not in test mode because then we would be accumulating debug logs in
|
|
268
|
+
// memory which could be a DoS vector on the sequencer (since no fees are paid for debug logs).
|
|
269
|
+
if (this.debugLogStore.isEnabled && this.config.realProofs) {
|
|
270
|
+
throw new Error('debugLogStore should never be enabled when realProofs are set');
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** @internal Exposed for testing — returns the RPC proof verifier. */
|
|
275
|
+
public getProofVerifier(): ClientProtocolCircuitVerifier {
|
|
276
|
+
return this.rpcProofVerifier;
|
|
156
277
|
}
|
|
157
278
|
|
|
158
279
|
public async getWorldStateSyncStatus(): Promise<WorldStateSyncStatus> {
|
|
@@ -160,342 +281,82 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
160
281
|
return status.syncSummary;
|
|
161
282
|
}
|
|
162
283
|
|
|
163
|
-
public
|
|
284
|
+
public getChainTips(): Promise<L2Tips> {
|
|
164
285
|
return this.blockSource.getL2Tips();
|
|
165
286
|
}
|
|
166
287
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
* @returns - A fully synced Aztec Node for use in development/testing.
|
|
171
|
-
*/
|
|
172
|
-
public static async createAndSync(
|
|
173
|
-
inputConfig: AztecNodeConfig,
|
|
174
|
-
deps: {
|
|
175
|
-
telemetry?: TelemetryClient;
|
|
176
|
-
logger?: Logger;
|
|
177
|
-
publisher?: SequencerPublisher;
|
|
178
|
-
dateProvider?: DateProvider;
|
|
179
|
-
p2pClientDeps?: P2PClientDeps<P2PClientType.Full>;
|
|
180
|
-
} = {},
|
|
181
|
-
options: {
|
|
182
|
-
prefilledPublicData?: PublicDataTreeLeaf[];
|
|
183
|
-
dontStartSequencer?: boolean;
|
|
184
|
-
} = {},
|
|
185
|
-
): Promise<AztecNodeService> {
|
|
186
|
-
const config = { ...inputConfig }; // Copy the config so we dont mutate the input object
|
|
187
|
-
const log = deps.logger ?? createLogger('node');
|
|
188
|
-
const packageVersion = getPackageVersion() ?? '';
|
|
189
|
-
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
190
|
-
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
191
|
-
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
192
|
-
|
|
193
|
-
// Build a key store from file if given or from environment otherwise
|
|
194
|
-
let keyStoreManager: KeystoreManager | undefined;
|
|
195
|
-
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
196
|
-
if (keyStoreProvided) {
|
|
197
|
-
const keyStores = loadKeystores(config.keyStoreDirectory!);
|
|
198
|
-
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
199
|
-
} else {
|
|
200
|
-
const keyStore = createKeyStoreForValidator(config);
|
|
201
|
-
if (keyStore) {
|
|
202
|
-
keyStoreManager = new KeystoreManager(keyStore);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
await keyStoreManager?.validateSigners();
|
|
207
|
-
|
|
208
|
-
// If we are a validator, verify our configuration before doing too much more.
|
|
209
|
-
if (!config.disableValidator) {
|
|
210
|
-
if (keyStoreManager === undefined) {
|
|
211
|
-
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
212
|
-
}
|
|
213
|
-
if (!keyStoreProvided) {
|
|
214
|
-
log.warn(
|
|
215
|
-
'KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS',
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// validate that the actual chain id matches that specified in configuration
|
|
222
|
-
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
223
|
-
throw new Error(
|
|
224
|
-
`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`,
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const publicClient = createPublicClient({
|
|
229
|
-
chain: ethereumChain.chainInfo,
|
|
230
|
-
transport: fallback(config.l1RpcUrls.map((url: string) => http(url, { batch: false }))),
|
|
231
|
-
pollingInterval: config.viemPollingIntervalMS,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
const l1ContractsAddresses = await RegistryContract.collectAddresses(
|
|
235
|
-
publicClient,
|
|
236
|
-
config.l1Contracts.registryAddress,
|
|
237
|
-
config.rollupVersion ?? 'canonical',
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
// Overwrite the passed in vars.
|
|
241
|
-
config.l1Contracts = { ...config.l1Contracts, ...l1ContractsAddresses };
|
|
242
|
-
|
|
243
|
-
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
244
|
-
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
245
|
-
rollupContract.getL1GenesisTime(),
|
|
246
|
-
rollupContract.getSlotDuration(),
|
|
247
|
-
rollupContract.getVersion(),
|
|
248
|
-
] as const);
|
|
249
|
-
|
|
250
|
-
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
251
|
-
|
|
252
|
-
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
253
|
-
log.warn(
|
|
254
|
-
`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const blobClient = await createBlobClientWithFileStores(config, createLogger('node:blob-client:client'));
|
|
259
|
-
|
|
260
|
-
// attempt snapshot sync if possible
|
|
261
|
-
await trySnapshotSync(config, log);
|
|
262
|
-
|
|
263
|
-
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, { dateProvider });
|
|
264
|
-
|
|
265
|
-
const archiver = await createArchiver(
|
|
266
|
-
config,
|
|
267
|
-
{ blobClient, epochCache, telemetry, dateProvider },
|
|
268
|
-
{ blockUntilSync: !config.skipArchiverInitialSync },
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
// now create the merkle trees and the world state synchronizer
|
|
272
|
-
const worldStateSynchronizer = await createWorldStateSynchronizer(
|
|
273
|
-
config,
|
|
274
|
-
archiver,
|
|
275
|
-
options.prefilledPublicData,
|
|
276
|
-
telemetry,
|
|
277
|
-
);
|
|
278
|
-
const circuitVerifier =
|
|
279
|
-
config.realProofs || config.debugForceTxProofVerification
|
|
280
|
-
? await BBCircuitVerifier.new(config)
|
|
281
|
-
: new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
282
|
-
if (!config.realProofs) {
|
|
283
|
-
log.warn(`Aztec node is accepting fake proofs`);
|
|
284
|
-
}
|
|
285
|
-
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
286
|
-
|
|
287
|
-
// create the tx pool and the p2p client, which will need the l2 block source
|
|
288
|
-
const p2pClient = await createP2PClient(
|
|
289
|
-
P2PClientType.Full,
|
|
290
|
-
config,
|
|
291
|
-
archiver,
|
|
292
|
-
proofVerifier,
|
|
293
|
-
worldStateSynchronizer,
|
|
294
|
-
epochCache,
|
|
295
|
-
packageVersion,
|
|
296
|
-
dateProvider,
|
|
297
|
-
telemetry,
|
|
298
|
-
deps.p2pClientDeps,
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
// We should really not be modifying the config object
|
|
302
|
-
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions());
|
|
303
|
-
|
|
304
|
-
// Create FullNodeCheckpointsBuilder for validator and non-validator block proposal handling
|
|
305
|
-
const validatorCheckpointsBuilder = new FullNodeCheckpointsBuilder(
|
|
306
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
307
|
-
worldStateSynchronizer,
|
|
308
|
-
archiver,
|
|
309
|
-
dateProvider,
|
|
310
|
-
telemetry,
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
// We'll accumulate sentinel watchers here
|
|
314
|
-
const watchers: Watcher[] = [];
|
|
315
|
-
|
|
316
|
-
// Create validator client if required
|
|
317
|
-
const validatorClient = await createValidatorClient(config, {
|
|
318
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
319
|
-
worldState: worldStateSynchronizer,
|
|
320
|
-
p2pClient,
|
|
321
|
-
telemetry,
|
|
322
|
-
dateProvider,
|
|
323
|
-
epochCache,
|
|
324
|
-
blockSource: archiver,
|
|
325
|
-
l1ToL2MessageSource: archiver,
|
|
326
|
-
keyStoreManager,
|
|
327
|
-
blobClient,
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
331
|
-
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
332
|
-
// like attestations or auths will fail.
|
|
333
|
-
if (validatorClient) {
|
|
334
|
-
watchers.push(validatorClient);
|
|
335
|
-
if (!options.dontStartSequencer) {
|
|
336
|
-
await validatorClient.registerHandlers();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
288
|
+
public getL1Constants(): Promise<L1RollupConstants> {
|
|
289
|
+
return this.blockSource.getL1Constants();
|
|
290
|
+
}
|
|
339
291
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
log.info('Setting up block proposal reexecution for monitoring');
|
|
344
|
-
createBlockProposalHandler(config, {
|
|
345
|
-
checkpointsBuilder: validatorCheckpointsBuilder,
|
|
346
|
-
worldState: worldStateSynchronizer,
|
|
347
|
-
epochCache,
|
|
348
|
-
blockSource: archiver,
|
|
349
|
-
l1ToL2MessageSource: archiver,
|
|
350
|
-
p2pClient,
|
|
351
|
-
dateProvider,
|
|
352
|
-
telemetry,
|
|
353
|
-
}).registerForReexecution(p2pClient);
|
|
354
|
-
}
|
|
292
|
+
public getSyncedL2SlotNumber() {
|
|
293
|
+
return this.blockSource.getSyncedL2SlotNumber();
|
|
294
|
+
}
|
|
355
295
|
|
|
356
|
-
|
|
357
|
-
|
|
296
|
+
public getSyncedL2EpochNumber() {
|
|
297
|
+
return this.blockSource.getSyncedL2EpochNumber();
|
|
298
|
+
}
|
|
358
299
|
|
|
359
|
-
|
|
360
|
-
|
|
300
|
+
public getSyncedL1Timestamp() {
|
|
301
|
+
return this.blockSource.getL1Timestamp();
|
|
302
|
+
}
|
|
361
303
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}
|
|
304
|
+
public getCheckpointsData(query: CheckpointsQuery) {
|
|
305
|
+
return this.blockSource.getCheckpointsData(query);
|
|
306
|
+
}
|
|
366
307
|
|
|
367
|
-
|
|
368
|
-
if (
|
|
369
|
-
|
|
370
|
-
archiver,
|
|
371
|
-
archiver,
|
|
372
|
-
epochCache,
|
|
373
|
-
p2pClient.getTxProvider(),
|
|
374
|
-
validatorCheckpointsBuilder,
|
|
375
|
-
config,
|
|
376
|
-
);
|
|
377
|
-
watchers.push(epochPruneWatcher);
|
|
308
|
+
public async getBlockNumber(tip?: L2BlockTag): Promise<BlockNumber> {
|
|
309
|
+
if (tip === undefined || tip === 'proposed') {
|
|
310
|
+
return this.blockSource.getBlockNumber();
|
|
378
311
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
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;
|
|
385
325
|
}
|
|
326
|
+
}
|
|
386
327
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
await epochPruneWatcher?.start();
|
|
394
|
-
await attestationsBlockWatcher?.start();
|
|
395
|
-
log.info(`All p2p services started`);
|
|
396
|
-
})
|
|
397
|
-
.catch(err => log.error('Failed to start p2p services after archiver sync', err));
|
|
398
|
-
|
|
399
|
-
// Validator enabled, create/start relevant service
|
|
400
|
-
let sequencer: SequencerClient | undefined;
|
|
401
|
-
let slasherClient: SlasherClientInterface | undefined;
|
|
402
|
-
if (!config.disableValidator && validatorClient) {
|
|
403
|
-
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
404
|
-
// as they are executed when the node is selected as proposer.
|
|
405
|
-
const validatorAddresses = keyStoreManager
|
|
406
|
-
? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses()
|
|
407
|
-
: [];
|
|
408
|
-
|
|
409
|
-
slasherClient = await createSlasher(
|
|
410
|
-
config,
|
|
411
|
-
config.l1Contracts,
|
|
412
|
-
getPublicClient(config),
|
|
413
|
-
watchers,
|
|
414
|
-
dateProvider,
|
|
415
|
-
epochCache,
|
|
416
|
-
validatorAddresses,
|
|
417
|
-
undefined, // logger
|
|
418
|
-
);
|
|
419
|
-
await slasherClient.start();
|
|
420
|
-
|
|
421
|
-
const l1TxUtils = config.publisherForwarderAddress
|
|
422
|
-
? await createForwarderL1TxUtilsFromEthSigner(
|
|
423
|
-
publicClient,
|
|
424
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
425
|
-
config.publisherForwarderAddress,
|
|
426
|
-
{ ...config, scope: 'sequencer' },
|
|
427
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
428
|
-
)
|
|
429
|
-
: await createL1TxUtilsWithBlobsFromEthSigner(
|
|
430
|
-
publicClient,
|
|
431
|
-
keyStoreManager!.createAllValidatorPublisherSigners(),
|
|
432
|
-
{ ...config, scope: 'sequencer' },
|
|
433
|
-
{ telemetry, logger: log.createChild('l1-tx-utils'), dateProvider },
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
// Create and start the sequencer client
|
|
437
|
-
const checkpointsBuilder = new CheckpointsBuilder(
|
|
438
|
-
{ ...config, l1GenesisTime, slotDuration: Number(slotDuration) },
|
|
439
|
-
worldStateSynchronizer,
|
|
440
|
-
archiver,
|
|
441
|
-
dateProvider,
|
|
442
|
-
telemetry,
|
|
443
|
-
);
|
|
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
|
+
}
|
|
444
334
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
l1TxUtils,
|
|
449
|
-
validatorClient,
|
|
450
|
-
p2pClient,
|
|
451
|
-
worldStateSynchronizer,
|
|
452
|
-
slasherClient,
|
|
453
|
-
checkpointsBuilder,
|
|
454
|
-
l2BlockSource: archiver,
|
|
455
|
-
l1ToL2MessageSource: archiver,
|
|
456
|
-
telemetry,
|
|
457
|
-
dateProvider,
|
|
458
|
-
blobClient,
|
|
459
|
-
nodeKeyStore: keyStoreManager!,
|
|
460
|
-
});
|
|
461
|
-
}
|
|
335
|
+
public getBlockData(param: BlockParameter): Promise<BlockData | undefined> {
|
|
336
|
+
return this.blockProvider.getBlockData(param);
|
|
337
|
+
}
|
|
462
338
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
+
}
|
|
469
346
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
+
}
|
|
476
353
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
archiver,
|
|
484
|
-
worldStateSynchronizer,
|
|
485
|
-
sequencer,
|
|
486
|
-
slasherClient,
|
|
487
|
-
validatorsSentinel,
|
|
488
|
-
epochPruneWatcher,
|
|
489
|
-
ethereumChain.chainInfo.id,
|
|
490
|
-
config.rollupVersion,
|
|
491
|
-
globalVariableBuilder,
|
|
492
|
-
epochCache,
|
|
493
|
-
packageVersion,
|
|
494
|
-
proofVerifier,
|
|
495
|
-
telemetry,
|
|
496
|
-
log,
|
|
497
|
-
blobClient,
|
|
498
|
-
);
|
|
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);
|
|
499
360
|
}
|
|
500
361
|
|
|
501
362
|
/**
|
|
@@ -506,6 +367,16 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
506
367
|
return this.sequencer;
|
|
507
368
|
}
|
|
508
369
|
|
|
370
|
+
/** Test-only: returns the AutomineSequencer when wired via `useAutomineSequencer`. */
|
|
371
|
+
public getAutomineSequencer(): AutomineSequencer | undefined {
|
|
372
|
+
return this.automineSequencer;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Returns the prover node subsystem, if enabled. */
|
|
376
|
+
public getProverNode(): ProverNode | undefined {
|
|
377
|
+
return this.proverNode;
|
|
378
|
+
}
|
|
379
|
+
|
|
509
380
|
public getBlockSource(): L2BlockSource {
|
|
510
381
|
return this.blockSource;
|
|
511
382
|
}
|
|
@@ -523,7 +394,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
523
394
|
* @returns - The currently deployed L1 contract addresses.
|
|
524
395
|
*/
|
|
525
396
|
public getL1ContractAddresses(): Promise<L1ContractAddresses> {
|
|
526
|
-
return Promise.resolve(this.config
|
|
397
|
+
return Promise.resolve(pickL1ContractAddresses(this.config));
|
|
527
398
|
}
|
|
528
399
|
|
|
529
400
|
public getEncodedEnr(): Promise<string | undefined> {
|
|
@@ -531,7 +402,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
531
402
|
}
|
|
532
403
|
|
|
533
404
|
public async getAllowedPublicSetup(): Promise<AllowedElement[]> {
|
|
534
|
-
return this.config.
|
|
405
|
+
return [...(await getDefaultAllowedSetupFunctions()), ...(this.config.txPublicSetupAllowListExtend ?? [])];
|
|
535
406
|
}
|
|
536
407
|
|
|
537
408
|
/**
|
|
@@ -543,14 +414,22 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
543
414
|
}
|
|
544
415
|
|
|
545
416
|
public async getNodeInfo(): Promise<NodeInfo> {
|
|
546
|
-
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] =
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
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);
|
|
554
433
|
|
|
555
434
|
const nodeInfo: NodeInfo = {
|
|
556
435
|
nodeVersion,
|
|
@@ -559,104 +438,30 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
559
438
|
enr,
|
|
560
439
|
l1ContractAddresses: contractAddresses,
|
|
561
440
|
protocolContractAddresses: protocolContractAddresses,
|
|
441
|
+
realProofs: !!this.config.realProofs,
|
|
442
|
+
txsLimits: { gas: { daGas: maxTxGas.daGas, l2Gas: maxTxGas.l2Gas } },
|
|
562
443
|
};
|
|
563
444
|
|
|
564
445
|
return nodeInfo;
|
|
565
446
|
}
|
|
566
447
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
* @param block - The block parameter (block number, block hash, or 'latest').
|
|
570
|
-
* @returns The requested block.
|
|
571
|
-
*/
|
|
572
|
-
public async getBlock(block: BlockParameter): Promise<L2Block | undefined> {
|
|
573
|
-
if (L2BlockHash.isL2BlockHash(block)) {
|
|
574
|
-
return this.getBlockByHash(Fr.fromBuffer(block.toBuffer()));
|
|
575
|
-
}
|
|
576
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
577
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
578
|
-
return this.buildInitialBlock();
|
|
579
|
-
}
|
|
580
|
-
return await this.blockSource.getL2Block(blockNumber);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* Get a block specified by its hash.
|
|
585
|
-
* @param blockHash - The block hash being requested.
|
|
586
|
-
* @returns The requested block.
|
|
587
|
-
*/
|
|
588
|
-
public async getBlockByHash(blockHash: Fr): Promise<L2Block | undefined> {
|
|
589
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
590
|
-
if (blockHash.equals(Fr.fromBuffer(initialBlockHash.toBuffer()))) {
|
|
591
|
-
return this.buildInitialBlock();
|
|
592
|
-
}
|
|
593
|
-
return await this.blockSource.getL2BlockByHash(blockHash);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
private buildInitialBlock(): L2Block {
|
|
597
|
-
const initialHeader = this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
598
|
-
return L2Block.empty(initialHeader);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Get a block specified by its archive root.
|
|
603
|
-
* @param archive - The archive root being requested.
|
|
604
|
-
* @returns The requested block.
|
|
605
|
-
*/
|
|
606
|
-
public async getBlockByArchive(archive: Fr): Promise<L2Block | undefined> {
|
|
607
|
-
return await this.blockSource.getL2BlockByArchive(archive);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
612
|
-
* @param from - The start of the range of blocks to return.
|
|
613
|
-
* @param limit - The maximum number of blocks to obtain.
|
|
614
|
-
* @returns The blocks requested.
|
|
615
|
-
*/
|
|
616
|
-
public async getBlocks(from: BlockNumber, limit: number): Promise<L2Block[]> {
|
|
617
|
-
return (await this.blockSource.getBlocks(from, BlockNumber(limit))) ?? [];
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
public async getCheckpoints(from: CheckpointNumber, limit: number): Promise<PublishedCheckpoint[]> {
|
|
621
|
-
return (await this.blockSource.getCheckpoints(from, limit)) ?? [];
|
|
448
|
+
public async getCurrentMinFees(): Promise<GasFees> {
|
|
449
|
+
return await this.feeProvider.getCurrentMinFees();
|
|
622
450
|
}
|
|
623
451
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Method to fetch the current min L2 fees.
|
|
630
|
-
* @returns The current min L2 fees.
|
|
631
|
-
*/
|
|
632
|
-
public async getCurrentMinFees(): Promise<GasFees> {
|
|
633
|
-
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);
|
|
634
455
|
}
|
|
635
456
|
|
|
636
457
|
public async getMaxPriorityFees(): Promise<GasFees> {
|
|
637
|
-
for await (const tx of this.p2pClient.iteratePendingTxs()) {
|
|
458
|
+
for await (const tx of this.p2pClient.iteratePendingTxs({ includeProof: false })) {
|
|
638
459
|
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
639
460
|
}
|
|
640
461
|
|
|
641
462
|
return GasFees.from({ feePerDaGas: 0n, feePerL2Gas: 0n });
|
|
642
463
|
}
|
|
643
464
|
|
|
644
|
-
/**
|
|
645
|
-
* Method to fetch the latest block number synchronized by the node.
|
|
646
|
-
* @returns The block number.
|
|
647
|
-
*/
|
|
648
|
-
public async getBlockNumber(): Promise<BlockNumber> {
|
|
649
|
-
return await this.blockSource.getBlockNumber();
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
public async getProvenBlockNumber(): Promise<BlockNumber> {
|
|
653
|
-
return await this.blockSource.getProvenBlockNumber();
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
public async getCheckpointedBlockNumber(): Promise<BlockNumber> {
|
|
657
|
-
return await this.blockSource.getCheckpointedL2BlockNumber();
|
|
658
|
-
}
|
|
659
|
-
|
|
660
465
|
/**
|
|
661
466
|
* Method to fetch the version of the package.
|
|
662
467
|
* @returns The node package version
|
|
@@ -685,67 +490,25 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
685
490
|
return this.contractDataSource.getContractClass(id);
|
|
686
491
|
}
|
|
687
492
|
|
|
688
|
-
public getContract(
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
if (referenceBlock) {
|
|
698
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
699
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
700
|
-
const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
|
|
701
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
702
|
-
if (!header) {
|
|
703
|
-
throw new Error(
|
|
704
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
705
|
-
);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
return this.logsSource.getPrivateLogsByTags(tags, page);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
public async getPublicLogsByTagsFromContract(
|
|
713
|
-
contractAddress: AztecAddress,
|
|
714
|
-
tags: Tag[],
|
|
715
|
-
page?: number,
|
|
716
|
-
referenceBlock?: L2BlockHash,
|
|
717
|
-
): Promise<TxScopedL2Log[][]> {
|
|
718
|
-
if (referenceBlock) {
|
|
719
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
720
|
-
if (!referenceBlock.equals(initialBlockHash)) {
|
|
721
|
-
const blockHashFr = Fr.fromBuffer(referenceBlock.toBuffer());
|
|
722
|
-
const header = await this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
723
|
-
if (!header) {
|
|
724
|
-
throw new Error(
|
|
725
|
-
`Block ${referenceBlock.toString()} not found in the node. This might indicate a reorg has occurred.`,
|
|
726
|
-
);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
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
|
+
);
|
|
729
502
|
}
|
|
730
|
-
return this.
|
|
503
|
+
return this.contractDataSource.getContract(address, blockData.header.globalVariables.timestamp);
|
|
731
504
|
}
|
|
732
505
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
* @param filter - The filter to apply to the logs.
|
|
736
|
-
* @returns The requested logs.
|
|
737
|
-
*/
|
|
738
|
-
getPublicLogs(filter: LogFilter): Promise<GetPublicLogsResponse> {
|
|
739
|
-
return this.logsSource.getPublicLogs(filter);
|
|
506
|
+
public getPrivateLogsByTags(query: PrivateLogsQuery): Promise<LogResult[][]> {
|
|
507
|
+
return this.logsSource.getPrivateLogsByTags(query);
|
|
740
508
|
}
|
|
741
509
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
* @param filter - The filter to apply to the logs.
|
|
745
|
-
* @returns The requested logs.
|
|
746
|
-
*/
|
|
747
|
-
getContractClassLogs(filter: LogFilter): Promise<GetContractClassLogsResponse> {
|
|
748
|
-
return this.logsSource.getContractClassLogs(filter);
|
|
510
|
+
public getPublicLogsByTags(query: PublicLogsQuery): Promise<LogResult[][]> {
|
|
511
|
+
return this.logsSource.getPublicLogsByTags(query);
|
|
749
512
|
}
|
|
750
513
|
|
|
751
514
|
/**
|
|
@@ -768,32 +531,23 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
768
531
|
throw new Error(`Invalid tx: ${reason}`);
|
|
769
532
|
}
|
|
770
533
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
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
|
+
}
|
|
541
|
+
const duration = timer.ms();
|
|
542
|
+
this.metrics.receivedTx(duration, true);
|
|
543
|
+
this.log.info(`Received tx ${txHash} in ${duration}ms`, { txHash });
|
|
774
544
|
}
|
|
775
545
|
|
|
776
|
-
public
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
// Then get the actual tx from the archiver, which tracks every tx in a mined block.
|
|
783
|
-
const settledTxReceipt = await this.blockSource.getSettledTxReceipt(txHash);
|
|
784
|
-
|
|
785
|
-
if (settledTxReceipt) {
|
|
786
|
-
// If the archiver has the receipt then return it.
|
|
787
|
-
return settledTxReceipt;
|
|
788
|
-
} else if (isKnownToPool) {
|
|
789
|
-
// If the tx is in the pool but not in the archiver, it's pending.
|
|
790
|
-
// This handles race conditions between archiver and p2p, where the archiver
|
|
791
|
-
// has pruned the block in which a tx was mined, but p2p has not caught up yet.
|
|
792
|
-
return new TxReceipt(txHash, TxStatus.PENDING, undefined, undefined);
|
|
793
|
-
} else {
|
|
794
|
-
// Otherwise, if we don't know the tx, we consider it dropped.
|
|
795
|
-
return new TxReceipt(txHash, TxStatus.DROPPED, undefined, 'Tx dropped by P2P node');
|
|
796
|
-
}
|
|
546
|
+
public getTxReceipt<TGetTxReceiptOptions extends GetTxReceiptOptions = {}>(
|
|
547
|
+
txHash: TxHash,
|
|
548
|
+
options?: TGetTxReceiptOptions,
|
|
549
|
+
): Promise<TxReceipt<TGetTxReceiptOptions>> {
|
|
550
|
+
return this.txReceiptBuilder.getTxReceipt(txHash, options);
|
|
797
551
|
}
|
|
798
552
|
|
|
799
553
|
public getTxEffect(txHash: TxHash): Promise<IndexedTxEffect | undefined> {
|
|
@@ -805,11 +559,12 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
805
559
|
*/
|
|
806
560
|
public async stop() {
|
|
807
561
|
this.log.info(`Stopping Aztec Node`);
|
|
808
|
-
await
|
|
809
|
-
await tryStop(this.epochPruneWatcher);
|
|
562
|
+
await this.stopStartedWatchers();
|
|
810
563
|
await tryStop(this.slasherClient);
|
|
811
|
-
await tryStop(this.
|
|
564
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
812
565
|
await tryStop(this.sequencer);
|
|
566
|
+
await tryStop(this.automineSequencer);
|
|
567
|
+
await tryStop(this.proverNode);
|
|
813
568
|
await tryStop(this.p2pClient);
|
|
814
569
|
await tryStop(this.worldStateSynchronizer);
|
|
815
570
|
await tryStop(this.blockSource);
|
|
@@ -832,398 +587,146 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
832
587
|
* @param after - The last known pending tx. Used for pagination
|
|
833
588
|
* @returns - The pending txs.
|
|
834
589
|
*/
|
|
835
|
-
public getPendingTxs(limit?: number, after?: TxHash): Promise<Tx[]> {
|
|
836
|
-
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);
|
|
837
592
|
}
|
|
838
593
|
|
|
839
594
|
public getPendingTxCount(): Promise<number> {
|
|
840
595
|
return this.p2pClient!.getPendingTxCount();
|
|
841
596
|
}
|
|
842
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
|
+
|
|
843
613
|
/**
|
|
844
|
-
* 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.
|
|
845
616
|
* @param txHash - The transaction hash to return.
|
|
617
|
+
* @param options - Options for the returned tx (eg whether to include its proof).
|
|
846
618
|
* @returns - The tx if it exists.
|
|
847
619
|
*/
|
|
848
|
-
public getTxByHash(txHash: TxHash): Promise<Tx | undefined> {
|
|
849
|
-
return
|
|
620
|
+
public getTxByHash(txHash: TxHash, options?: GetTxByHashOptions): Promise<Tx | undefined> {
|
|
621
|
+
return this.p2pClient!.getTxByHashFromPool(txHash, { includeProof: !!options?.includeProof });
|
|
850
622
|
}
|
|
851
623
|
|
|
852
624
|
/**
|
|
853
|
-
* 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.
|
|
854
627
|
* @param txHash - The transaction hash to return.
|
|
628
|
+
* @param options - Options for the returned txs (eg whether to include their proofs).
|
|
855
629
|
* @returns - The txs if it exists.
|
|
856
630
|
*/
|
|
857
|
-
public async getTxsByHash(txHashes: TxHash[]): Promise<Tx[]> {
|
|
858
|
-
|
|
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);
|
|
859
634
|
}
|
|
860
635
|
|
|
861
|
-
public
|
|
862
|
-
|
|
636
|
+
public findLeavesIndexes(
|
|
637
|
+
referenceBlock: BlockParameter,
|
|
863
638
|
treeId: MerkleTreeId,
|
|
864
639
|
leafValues: Fr[],
|
|
865
640
|
): Promise<(DataInBlock<bigint> | undefined)[]> {
|
|
866
|
-
|
|
867
|
-
const maybeIndices = await committedDb.findLeafIndices(
|
|
868
|
-
treeId,
|
|
869
|
-
leafValues.map(x => x.toBuffer()),
|
|
870
|
-
);
|
|
871
|
-
// We filter out undefined values
|
|
872
|
-
const indices = maybeIndices.filter(x => x !== undefined) as bigint[];
|
|
873
|
-
|
|
874
|
-
// Now we find the block numbers for the indices
|
|
875
|
-
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
|
|
876
|
-
|
|
877
|
-
// If any of the block numbers are undefined, we throw an error.
|
|
878
|
-
for (let i = 0; i < indices.length; i++) {
|
|
879
|
-
if (blockNumbers[i] === undefined) {
|
|
880
|
-
throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
885
|
-
const uniqueBlockNumbers = [...new Set(blockNumbers.filter(x => x !== undefined))];
|
|
886
|
-
|
|
887
|
-
// Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
|
|
888
|
-
// (note that block number corresponds to the leaf index in the archive tree).
|
|
889
|
-
const blockHashes = await Promise.all(
|
|
890
|
-
uniqueBlockNumbers.map(blockNumber => {
|
|
891
|
-
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, BigInt(blockNumber));
|
|
892
|
-
}),
|
|
893
|
-
);
|
|
894
|
-
|
|
895
|
-
// If any of the block hashes are undefined, we throw an error.
|
|
896
|
-
for (let i = 0; i < uniqueBlockNumbers.length; i++) {
|
|
897
|
-
if (blockHashes[i] === undefined) {
|
|
898
|
-
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
// Create DataInBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
903
|
-
return maybeIndices.map((index, i) => {
|
|
904
|
-
if (index === undefined) {
|
|
905
|
-
return undefined;
|
|
906
|
-
}
|
|
907
|
-
const blockNumber = blockNumbers[i];
|
|
908
|
-
if (blockNumber === undefined) {
|
|
909
|
-
return undefined;
|
|
910
|
-
}
|
|
911
|
-
const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
|
|
912
|
-
const blockHash = blockHashes[blockHashIndex];
|
|
913
|
-
if (!blockHash) {
|
|
914
|
-
return undefined;
|
|
915
|
-
}
|
|
916
|
-
return {
|
|
917
|
-
l2BlockNumber: BlockNumber(Number(blockNumber)),
|
|
918
|
-
l2BlockHash: L2BlockHash.fromField(blockHash),
|
|
919
|
-
data: index,
|
|
920
|
-
};
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
public async getNullifierSiblingPath(
|
|
925
|
-
block: BlockParameter,
|
|
926
|
-
leafIndex: bigint,
|
|
927
|
-
): Promise<SiblingPath<typeof NULLIFIER_TREE_HEIGHT>> {
|
|
928
|
-
const committedDb = await this.#getWorldState(block);
|
|
929
|
-
return committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, leafIndex);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
public async getNoteHashSiblingPath(
|
|
933
|
-
block: BlockParameter,
|
|
934
|
-
leafIndex: bigint,
|
|
935
|
-
): Promise<SiblingPath<typeof NOTE_HASH_TREE_HEIGHT>> {
|
|
936
|
-
const committedDb = await this.#getWorldState(block);
|
|
937
|
-
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
641
|
+
return this.worldStateQueries.findLeavesIndexes(referenceBlock, treeId, leafValues);
|
|
938
642
|
}
|
|
939
643
|
|
|
940
|
-
public
|
|
941
|
-
|
|
942
|
-
|
|
644
|
+
public getBlockHashMembershipWitness(
|
|
645
|
+
referenceBlock: BlockParameter,
|
|
646
|
+
blockHash: BlockHash,
|
|
943
647
|
): Promise<MembershipWitness<typeof ARCHIVE_HEIGHT> | undefined> {
|
|
944
|
-
|
|
945
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.ARCHIVE>(MerkleTreeId.ARCHIVE, [archive]);
|
|
946
|
-
return pathAndIndex === undefined
|
|
947
|
-
? undefined
|
|
948
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
648
|
+
return this.worldStateQueries.getBlockHashMembershipWitness(referenceBlock, blockHash);
|
|
949
649
|
}
|
|
950
650
|
|
|
951
|
-
public
|
|
952
|
-
|
|
651
|
+
public getNoteHashMembershipWitness(
|
|
652
|
+
referenceBlock: BlockParameter,
|
|
953
653
|
noteHash: Fr,
|
|
954
654
|
): Promise<MembershipWitness<typeof NOTE_HASH_TREE_HEIGHT> | undefined> {
|
|
955
|
-
|
|
956
|
-
const [pathAndIndex] = await committedDb.findSiblingPaths<MerkleTreeId.NOTE_HASH_TREE>(
|
|
957
|
-
MerkleTreeId.NOTE_HASH_TREE,
|
|
958
|
-
[noteHash],
|
|
959
|
-
);
|
|
960
|
-
return pathAndIndex === undefined
|
|
961
|
-
? undefined
|
|
962
|
-
: MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
655
|
+
return this.worldStateQueries.getNoteHashMembershipWitness(referenceBlock, noteHash);
|
|
963
656
|
}
|
|
964
657
|
|
|
965
|
-
public
|
|
966
|
-
|
|
658
|
+
public getL1ToL2MessageMembershipWitness(
|
|
659
|
+
referenceBlock: BlockParameter,
|
|
967
660
|
l1ToL2Message: Fr,
|
|
968
661
|
): Promise<[bigint, SiblingPath<typeof L1_TO_L2_MSG_TREE_HEIGHT>] | undefined> {
|
|
969
|
-
|
|
970
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [l1ToL2Message]);
|
|
971
|
-
if (!witness) {
|
|
972
|
-
return undefined;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// REFACTOR: Return a MembershipWitness object
|
|
976
|
-
return [witness.index, witness.path];
|
|
662
|
+
return this.worldStateQueries.getL1ToL2MessageMembershipWitness(referenceBlock, l1ToL2Message);
|
|
977
663
|
}
|
|
978
664
|
|
|
979
|
-
public
|
|
980
|
-
|
|
981
|
-
return messageIndex
|
|
982
|
-
? BlockNumber.fromCheckpointNumber(InboxLeaf.checkpointNumberFromIndex(messageIndex))
|
|
983
|
-
: undefined;
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
/**
|
|
987
|
-
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
988
|
-
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
989
|
-
* @returns Whether the message is synced and ready to be included in a block.
|
|
990
|
-
*/
|
|
991
|
-
public async isL1ToL2MessageSynced(l1ToL2Message: Fr): Promise<boolean> {
|
|
992
|
-
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
993
|
-
return messageIndex !== undefined;
|
|
665
|
+
public getL1ToL2MessageCheckpoint(l1ToL2Message: Fr): Promise<CheckpointNumber | undefined> {
|
|
666
|
+
return this.worldStateQueries.getL1ToL2MessageCheckpoint(l1ToL2Message);
|
|
994
667
|
}
|
|
995
668
|
|
|
996
669
|
/**
|
|
997
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
|
+
*
|
|
998
674
|
* @param epoch - The epoch at which to get the data.
|
|
999
675
|
* @returns The L2 to L1 messages (empty array if the epoch is not found).
|
|
1000
676
|
*/
|
|
1001
|
-
public
|
|
1002
|
-
|
|
1003
|
-
const checkpointedBlocks = await this.blockSource.getCheckpointedBlocksForEpoch(epoch);
|
|
1004
|
-
const blocksInCheckpoints: L2Block[][] = [];
|
|
1005
|
-
let previousSlotNumber = SlotNumber.ZERO;
|
|
1006
|
-
let checkpointIndex = -1;
|
|
1007
|
-
for (const checkpointedBlock of checkpointedBlocks) {
|
|
1008
|
-
const block = checkpointedBlock.block;
|
|
1009
|
-
const slotNumber = block.header.globalVariables.slotNumber;
|
|
1010
|
-
if (slotNumber !== previousSlotNumber) {
|
|
1011
|
-
checkpointIndex++;
|
|
1012
|
-
blocksInCheckpoints.push([]);
|
|
1013
|
-
previousSlotNumber = slotNumber;
|
|
1014
|
-
}
|
|
1015
|
-
blocksInCheckpoints[checkpointIndex].push(block);
|
|
1016
|
-
}
|
|
1017
|
-
return blocksInCheckpoints.map(blocks =>
|
|
1018
|
-
blocks.map(block => block.body.txEffects.map(txEffect => txEffect.l2ToL1Msgs)),
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
public async getArchiveSiblingPath(
|
|
1023
|
-
block: BlockParameter,
|
|
1024
|
-
leafIndex: bigint,
|
|
1025
|
-
): Promise<SiblingPath<typeof ARCHIVE_HEIGHT>> {
|
|
1026
|
-
const committedDb = await this.#getWorldState(block);
|
|
1027
|
-
return committedDb.getSiblingPath(MerkleTreeId.ARCHIVE, leafIndex);
|
|
677
|
+
public getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]> {
|
|
678
|
+
return this.worldStateQueries.getL2ToL1Messages(epoch);
|
|
1028
679
|
}
|
|
1029
680
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
681
|
+
/**
|
|
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}.
|
|
684
|
+
*/
|
|
685
|
+
public getL2ToL1MembershipWitness(
|
|
686
|
+
txHash: TxHash,
|
|
687
|
+
message: Fr,
|
|
688
|
+
messageIndexInTx?: number,
|
|
689
|
+
): Promise<L2ToL1MembershipWitness | undefined> {
|
|
690
|
+
return this.worldStateQueries.getL2ToL1MembershipWitness(txHash, message, messageIndexInTx);
|
|
1036
691
|
}
|
|
1037
692
|
|
|
1038
|
-
public
|
|
1039
|
-
|
|
693
|
+
public getNullifierMembershipWitness(
|
|
694
|
+
referenceBlock: BlockParameter,
|
|
1040
695
|
nullifier: Fr,
|
|
1041
696
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1042
|
-
|
|
1043
|
-
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()]);
|
|
1044
|
-
if (!witness) {
|
|
1045
|
-
return undefined;
|
|
1046
|
-
}
|
|
1047
|
-
|
|
1048
|
-
const { index, path } = witness;
|
|
1049
|
-
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
1050
|
-
if (!leafPreimage) {
|
|
1051
|
-
return undefined;
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
return new NullifierMembershipWitness(index, leafPreimage as NullifierLeafPreimage, path);
|
|
697
|
+
return this.worldStateQueries.getNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1055
698
|
}
|
|
1056
699
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
* @param block - The block parameter (block number, block hash, or 'latest') at which to get the data.
|
|
1060
|
-
* @param nullifier - Nullifier we try to find the low nullifier witness for.
|
|
1061
|
-
* @returns The low nullifier membership witness (if found).
|
|
1062
|
-
* @remarks Low nullifier witness can be used to perform a nullifier non-inclusion proof by leveraging the "linked
|
|
1063
|
-
* list structure" of leaves and proving that a lower nullifier is pointing to a bigger next value than the nullifier
|
|
1064
|
-
* we are trying to prove non-inclusion for.
|
|
1065
|
-
*
|
|
1066
|
-
* Note: This function returns the membership witness of the nullifier itself and not the low nullifier when
|
|
1067
|
-
* the nullifier already exists in the tree. This is because the `getPreviousValueIndex` function returns the
|
|
1068
|
-
* index of the nullifier itself when it already exists in the tree.
|
|
1069
|
-
* TODO: This is a confusing behavior and we should eventually address that.
|
|
1070
|
-
*/
|
|
1071
|
-
public async getLowNullifierMembershipWitness(
|
|
1072
|
-
block: BlockParameter,
|
|
700
|
+
public getLowNullifierMembershipWitness(
|
|
701
|
+
referenceBlock: BlockParameter,
|
|
1073
702
|
nullifier: Fr,
|
|
1074
703
|
): Promise<NullifierMembershipWitness | undefined> {
|
|
1075
|
-
|
|
1076
|
-
const findResult = await committedDb.getPreviousValueIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBigInt());
|
|
1077
|
-
if (!findResult) {
|
|
1078
|
-
return undefined;
|
|
1079
|
-
}
|
|
1080
|
-
const { index, alreadyPresent } = findResult;
|
|
1081
|
-
if (alreadyPresent) {
|
|
1082
|
-
this.log.warn(`Nullifier ${nullifier.toBigInt()} already exists in the tree`);
|
|
1083
|
-
}
|
|
1084
|
-
const preimageData = (await committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index))!;
|
|
1085
|
-
|
|
1086
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
1087
|
-
return new NullifierMembershipWitness(BigInt(index), preimageData as NullifierLeafPreimage, siblingPath);
|
|
704
|
+
return this.worldStateQueries.getLowNullifierMembershipWitness(referenceBlock, nullifier);
|
|
1088
705
|
}
|
|
1089
706
|
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1093
|
-
if (!lowLeafResult) {
|
|
1094
|
-
return undefined;
|
|
1095
|
-
} else {
|
|
1096
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1097
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1098
|
-
lowLeafResult.index,
|
|
1099
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1100
|
-
const path = await committedDb.getSiblingPath(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
1101
|
-
return new PublicDataWitness(lowLeafResult.index, preimage, path);
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
public async getPublicStorageAt(block: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
1106
|
-
const committedDb = await this.#getWorldState(block);
|
|
1107
|
-
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);
|
|
1108
|
-
|
|
1109
|
-
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
1110
|
-
if (!lowLeafResult || !lowLeafResult.alreadyPresent) {
|
|
1111
|
-
return Fr.ZERO;
|
|
1112
|
-
}
|
|
1113
|
-
const preimage = (await committedDb.getLeafPreimage(
|
|
1114
|
-
MerkleTreeId.PUBLIC_DATA_TREE,
|
|
1115
|
-
lowLeafResult.index,
|
|
1116
|
-
)) as PublicDataTreeLeafPreimage;
|
|
1117
|
-
return preimage.leaf.value;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
public async getBlockHeader(block: BlockParameter = 'latest'): Promise<BlockHeader | undefined> {
|
|
1121
|
-
if (L2BlockHash.isL2BlockHash(block)) {
|
|
1122
|
-
const initialBlockHash = await this.#getInitialHeaderHash();
|
|
1123
|
-
if (block.equals(initialBlockHash)) {
|
|
1124
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1125
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1126
|
-
}
|
|
1127
|
-
const blockHashFr = Fr.fromBuffer(block.toBuffer());
|
|
1128
|
-
return this.blockSource.getBlockHeaderByHash(blockHashFr);
|
|
1129
|
-
} else {
|
|
1130
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1131
|
-
const blockNumber = block === 'latest' ? await this.getBlockNumber() : (block as BlockNumber);
|
|
1132
|
-
if (blockNumber === BlockNumber.ZERO) {
|
|
1133
|
-
return this.worldStateSynchronizer.getCommitted().getInitialHeader();
|
|
1134
|
-
}
|
|
1135
|
-
return this.blockSource.getBlockHeader(block);
|
|
1136
|
-
}
|
|
707
|
+
public getPublicDataWitness(referenceBlock: BlockParameter, leafSlot: Fr): Promise<PublicDataWitness | undefined> {
|
|
708
|
+
return this.worldStateQueries.getPublicDataWitness(referenceBlock, leafSlot);
|
|
1137
709
|
}
|
|
1138
710
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
* @param archive - The archive root being requested.
|
|
1142
|
-
* @returns The requested block header.
|
|
1143
|
-
*/
|
|
1144
|
-
public async getBlockHeaderByArchive(archive: Fr): Promise<BlockHeader | undefined> {
|
|
1145
|
-
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
711
|
+
public getPublicStorageAt(referenceBlock: BlockParameter, contract: AztecAddress, slot: Fr): Promise<Fr> {
|
|
712
|
+
return this.worldStateQueries.getPublicStorageAt(referenceBlock, contract, slot);
|
|
1146
713
|
}
|
|
1147
714
|
|
|
1148
715
|
/**
|
|
1149
716
|
* Simulates the public part of a transaction with the current state.
|
|
1150
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.
|
|
1151
720
|
**/
|
|
1152
721
|
@trackSpan('AztecNodeService.simulatePublicCalls', (tx: Tx) => ({
|
|
1153
722
|
[Attributes.TX_HASH]: tx.getTxHash().toString(),
|
|
1154
723
|
}))
|
|
1155
|
-
public
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
throw new BadRequestError(
|
|
1162
|
-
`Transaction total gas limit ${
|
|
1163
|
-
txGasLimit + teardownGasLimit
|
|
1164
|
-
} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${
|
|
1165
|
-
this.config.rpcSimulatePublicMaxGasLimit
|
|
1166
|
-
} for simulation`,
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
const txHash = tx.getTxHash();
|
|
1171
|
-
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1172
|
-
|
|
1173
|
-
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
1174
|
-
const coinbase = EthAddress.ZERO;
|
|
1175
|
-
const feeRecipient = AztecAddress.ZERO;
|
|
1176
|
-
|
|
1177
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
|
|
1178
|
-
blockNumber,
|
|
1179
|
-
coinbase,
|
|
1180
|
-
feeRecipient,
|
|
1181
|
-
);
|
|
1182
|
-
const publicProcessorFactory = new PublicProcessorFactory(
|
|
1183
|
-
this.contractDataSource,
|
|
1184
|
-
new DateProvider(),
|
|
1185
|
-
this.telemetry,
|
|
1186
|
-
);
|
|
1187
|
-
|
|
1188
|
-
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
1189
|
-
globalVariables: newGlobalVariables.toInspect(),
|
|
1190
|
-
txHash,
|
|
1191
|
-
blockNumber,
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
1195
|
-
try {
|
|
1196
|
-
const config = PublicSimulatorConfig.from({
|
|
1197
|
-
skipFeeEnforcement,
|
|
1198
|
-
collectDebugLogs: true,
|
|
1199
|
-
collectHints: false,
|
|
1200
|
-
collectCallMetadata: true,
|
|
1201
|
-
collectStatistics: false,
|
|
1202
|
-
collectionLimits: CollectionLimitsConfig.from({
|
|
1203
|
-
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
1204
|
-
}),
|
|
1205
|
-
});
|
|
1206
|
-
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
1207
|
-
|
|
1208
|
-
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
1209
|
-
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([tx]);
|
|
1210
|
-
// REFACTOR: Consider returning the error rather than throwing
|
|
1211
|
-
if (failedTxs.length) {
|
|
1212
|
-
this.log.warn(`Simulated tx ${txHash} fails: ${failedTxs[0].error}`, { txHash });
|
|
1213
|
-
throw failedTxs[0].error;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
const [processedTx] = processedTxs;
|
|
1217
|
-
return new PublicSimulationOutput(
|
|
1218
|
-
processedTx.revertReason,
|
|
1219
|
-
processedTx.globalVariables,
|
|
1220
|
-
processedTx.txEffect,
|
|
1221
|
-
returns,
|
|
1222
|
-
processedTx.gasUsed,
|
|
1223
|
-
);
|
|
1224
|
-
} finally {
|
|
1225
|
-
await merkleTreeFork.close();
|
|
1226
|
-
}
|
|
724
|
+
public simulatePublicCalls(
|
|
725
|
+
tx: Tx,
|
|
726
|
+
skipFeeEnforcement = false,
|
|
727
|
+
overrides?: SimulationOverrides,
|
|
728
|
+
): Promise<PublicSimulationOutput> {
|
|
729
|
+
return this.nodePublicCallsSimulator.simulate(tx, skipFeeEnforcement, overrides);
|
|
1227
730
|
}
|
|
1228
731
|
|
|
1229
732
|
public async isValidTx(
|
|
@@ -1231,21 +734,37 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1231
734
|
{ isSimulation, skipFeeEnforcement }: { isSimulation?: boolean; skipFeeEnforcement?: boolean } = {},
|
|
1232
735
|
): Promise<TxValidationResult> {
|
|
1233
736
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
1234
|
-
const verifier = isSimulation ? undefined : this.
|
|
737
|
+
const verifier = isSimulation ? undefined : this.rpcProofVerifier;
|
|
1235
738
|
|
|
1236
|
-
// We accept transactions if they are not expired by the next slot (checked based on the
|
|
739
|
+
// We accept transactions if they are not expired by the next slot (checked based on the ExpirationTimestamp field)
|
|
1237
740
|
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
1238
741
|
const blockNumber = BlockNumber((await this.blockSource.getBlockNumber()) + 1);
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
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);
|
|
746
|
+
const validator = createTxValidatorForAcceptingTxsOverRPC(
|
|
747
|
+
db,
|
|
748
|
+
this.contractDataSource,
|
|
749
|
+
verifier,
|
|
750
|
+
{
|
|
751
|
+
timestamp: nextSlotTimestamp,
|
|
752
|
+
blockNumber,
|
|
753
|
+
l1ChainId: this.l1ChainId,
|
|
754
|
+
rollupVersion: this.version,
|
|
755
|
+
setupAllowList: [
|
|
756
|
+
...(await getDefaultAllowedSetupFunctions()),
|
|
757
|
+
...(this.config.txPublicSetupAllowListExtend ?? []),
|
|
758
|
+
],
|
|
759
|
+
gasFees: await this.getCurrentMinFees(),
|
|
760
|
+
skipFeeEnforcement,
|
|
761
|
+
isSimulation,
|
|
762
|
+
txsPermitted: !this.config.disableTransactions,
|
|
763
|
+
maxTxL2Gas: networkTxGasLimits.l2Gas,
|
|
764
|
+
maxTxDAGas: networkTxGasLimits.daGas,
|
|
765
|
+
},
|
|
766
|
+
this.log.getBindings(),
|
|
767
|
+
);
|
|
1249
768
|
|
|
1250
769
|
return await validator.validateTx(tx);
|
|
1251
770
|
}
|
|
@@ -1258,7 +777,18 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1258
777
|
|
|
1259
778
|
public async setConfig(config: Partial<AztecNodeAdminConfig>): Promise<void> {
|
|
1260
779
|
const newConfig = { ...this.config, ...config };
|
|
1261
|
-
|
|
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);
|
|
1262
792
|
this.slasherClient?.updateConfig(config);
|
|
1263
793
|
this.validatorsSentinel?.updateConfig(config);
|
|
1264
794
|
await this.p2pClient.updateP2PConfig(config);
|
|
@@ -1267,7 +797,15 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1267
797
|
archiver.updateConfig(config);
|
|
1268
798
|
}
|
|
1269
799
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
1270
|
-
|
|
800
|
+
await Promise.all([tryStop(this.peerProofVerifier), tryStop(this.rpcProofVerifier)]);
|
|
801
|
+
if (newConfig.realProofs) {
|
|
802
|
+
this.peerProofVerifier = await BatchChonkVerifier.new(newConfig, newConfig.bbChonkVerifyMaxBatch, 'peer');
|
|
803
|
+
const rpcVerifier = await BBCircuitVerifier.new(newConfig);
|
|
804
|
+
this.rpcProofVerifier = new QueuedIVCVerifier(rpcVerifier, newConfig.numConcurrentIVCVerifiers);
|
|
805
|
+
} else {
|
|
806
|
+
this.peerProofVerifier = new TestCircuitVerifier();
|
|
807
|
+
this.rpcProofVerifier = new TestCircuitVerifier();
|
|
808
|
+
}
|
|
1271
809
|
}
|
|
1272
810
|
|
|
1273
811
|
this.config = newConfig;
|
|
@@ -1278,7 +816,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1278
816
|
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
1279
817
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
1280
818
|
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
1281
|
-
multiCallEntrypoint:
|
|
819
|
+
multiCallEntrypoint: STANDARD_MULTI_CALL_ENTRYPOINT_ADDRESS,
|
|
1282
820
|
});
|
|
1283
821
|
}
|
|
1284
822
|
|
|
@@ -1342,7 +880,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1342
880
|
return Promise.resolve();
|
|
1343
881
|
}
|
|
1344
882
|
|
|
1345
|
-
public async rollbackTo(targetBlock: BlockNumber, force?: boolean): Promise<void> {
|
|
883
|
+
public async rollbackTo(targetBlock: BlockNumber, force?: boolean, resumeSync = true): Promise<void> {
|
|
1346
884
|
const archiver = this.blockSource as Archiver;
|
|
1347
885
|
if (!('rollbackTo' in archiver)) {
|
|
1348
886
|
throw new Error('Archiver implementation does not support rollbacks.');
|
|
@@ -1372,9 +910,13 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1372
910
|
this.log.error(`Error during rollback`, err);
|
|
1373
911
|
throw err;
|
|
1374
912
|
} finally {
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
+
}
|
|
1378
920
|
}
|
|
1379
921
|
}
|
|
1380
922
|
|
|
@@ -1391,11 +933,39 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1391
933
|
return Promise.resolve();
|
|
1392
934
|
}
|
|
1393
935
|
|
|
1394
|
-
public
|
|
1395
|
-
if (
|
|
1396
|
-
|
|
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();
|
|
1397
950
|
}
|
|
1398
|
-
|
|
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');
|
|
1399
969
|
}
|
|
1400
970
|
|
|
1401
971
|
public getSlashOffenses(round: bigint | 'all' | 'current'): Promise<Offense[]> {
|
|
@@ -1403,76 +973,165 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
|
|
|
1403
973
|
throw new Error(`Slasher client not enabled`);
|
|
1404
974
|
}
|
|
1405
975
|
if (round === 'all') {
|
|
1406
|
-
return this.slasherClient.
|
|
976
|
+
return this.slasherClient.getOffenses();
|
|
1407
977
|
} else {
|
|
1408
978
|
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1409
979
|
}
|
|
1410
980
|
}
|
|
1411
981
|
|
|
1412
|
-
|
|
1413
|
-
if (!this.
|
|
1414
|
-
|
|
982
|
+
public async reloadKeystore(): Promise<void> {
|
|
983
|
+
if (!this.config.keyStoreDirectory?.length) {
|
|
984
|
+
throw new BadRequestError(
|
|
985
|
+
'Cannot reload keystore: node is not using a file-based keystore. ' +
|
|
986
|
+
'Set KEY_STORE_DIRECTORY to use file-based keystores.',
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
if (!this.validatorClient) {
|
|
990
|
+
throw new BadRequestError('Cannot reload keystore: validator is not enabled.');
|
|
1415
991
|
}
|
|
1416
|
-
return this.initialHeaderHashPromise;
|
|
1417
|
-
}
|
|
1418
992
|
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
993
|
+
this.log.info('Reloading keystore from disk');
|
|
994
|
+
|
|
995
|
+
// Re-read and validate keystore files
|
|
996
|
+
const keyStores = loadKeystores(this.config.keyStoreDirectory);
|
|
997
|
+
const newManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
998
|
+
await newManager.validateSigners();
|
|
999
|
+
ValidatorClient.validateKeyStoreConfiguration(newManager, this.log);
|
|
1000
|
+
|
|
1001
|
+
// Validate that every validator's publisher keys overlap with the L1 signers
|
|
1002
|
+
// that were initialized at startup. Publishers cannot be hot-reloaded, so a
|
|
1003
|
+
// validator with a publisher key that doesn't match any existing L1 signer
|
|
1004
|
+
// would silently fail on every proposer slot.
|
|
1005
|
+
if (this.keyStoreManager && this.sequencer) {
|
|
1006
|
+
const oldAdapter = NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager);
|
|
1007
|
+
const availablePublishers = new Set(
|
|
1008
|
+
oldAdapter
|
|
1009
|
+
.getAttesterAddresses()
|
|
1010
|
+
.flatMap(a => oldAdapter.getPublisherAddresses(a).map(p => p.toString().toLowerCase())),
|
|
1011
|
+
);
|
|
1012
|
+
|
|
1013
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1014
|
+
for (const attester of newAdapter.getAttesterAddresses()) {
|
|
1015
|
+
const pubs = newAdapter.getPublisherAddresses(attester);
|
|
1016
|
+
if (pubs.length > 0 && !pubs.some(p => availablePublishers.has(p.toString().toLowerCase()))) {
|
|
1017
|
+
throw new BadRequestError(
|
|
1018
|
+
`Cannot reload keystore: validator ${attester} has publisher keys ` +
|
|
1019
|
+
`[${pubs.map(p => p.toString()).join(', ')}] but none match the L1 signers initialized at startup ` +
|
|
1020
|
+
`[${[...availablePublishers].join(', ')}]. Publishers cannot be hot-reloaded — ` +
|
|
1021
|
+
`use an existing publisher key or restart the node.`,
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1431
1025
|
}
|
|
1432
1026
|
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1027
|
+
// Build adapters for old and new keystores to compute diff
|
|
1028
|
+
const newAdapter = NodeKeystoreAdapter.fromKeyStoreManager(newManager);
|
|
1029
|
+
const newAddresses = newAdapter.getAttesterAddresses();
|
|
1030
|
+
const oldAddresses = this.keyStoreManager
|
|
1031
|
+
? NodeKeystoreAdapter.fromKeyStoreManager(this.keyStoreManager).getAttesterAddresses()
|
|
1032
|
+
: [];
|
|
1033
|
+
|
|
1034
|
+
const oldSet = new Set(oldAddresses.map(a => a.toString()));
|
|
1035
|
+
const newSet = new Set(newAddresses.map(a => a.toString()));
|
|
1036
|
+
const added = newAddresses.filter(a => !oldSet.has(a.toString()));
|
|
1037
|
+
const removed = oldAddresses.filter(a => !newSet.has(a.toString()));
|
|
1038
|
+
|
|
1039
|
+
if (added.length > 0) {
|
|
1040
|
+
this.log.info(`Keystore reload: adding attester keys: ${added.map(a => a.toString()).join(', ')}`);
|
|
1041
|
+
}
|
|
1042
|
+
if (removed.length > 0) {
|
|
1043
|
+
this.log.info(`Keystore reload: removing attester keys: ${removed.map(a => a.toString()).join(', ')}`);
|
|
1044
|
+
}
|
|
1045
|
+
if (added.length === 0 && removed.length === 0) {
|
|
1046
|
+
this.log.info('Keystore reload: attester keys unchanged');
|
|
1436
1047
|
}
|
|
1437
1048
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
if (block.equals(initialBlockHash)) {
|
|
1441
|
-
// Block source doesn't handle initial header so we need to handle the case separately.
|
|
1442
|
-
return this.worldStateSynchronizer.getSnapshot(BlockNumber.ZERO);
|
|
1443
|
-
}
|
|
1049
|
+
// Update the validator client (coinbase, feeRecipient, attester keys)
|
|
1050
|
+
this.validatorClient.reloadKeystore(newManager);
|
|
1444
1051
|
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
`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.`,
|
|
1450
|
-
);
|
|
1451
|
-
}
|
|
1452
|
-
const blockNumber = header.getBlockNumber();
|
|
1453
|
-
this.log.debug(`Using snapshot for block ${blockNumber}, world state synced upto ${blockSyncedTo}`);
|
|
1454
|
-
return this.worldStateSynchronizer.getSnapshot(blockNumber);
|
|
1052
|
+
// Update the publisher factory's keystore so newly-added validators
|
|
1053
|
+
// can be matched to existing publisher keys when proposing blocks.
|
|
1054
|
+
if (this.sequencer) {
|
|
1055
|
+
this.sequencer.updatePublisherNodeKeyStore(newAdapter);
|
|
1455
1056
|
}
|
|
1456
1057
|
|
|
1457
|
-
//
|
|
1458
|
-
{
|
|
1459
|
-
const
|
|
1058
|
+
// Update slasher's "don't-slash-self" list with new validator addresses
|
|
1059
|
+
if (this.slasherClient && !this.config.slashSelfAllowed) {
|
|
1060
|
+
const slashValidatorsNever = unique(
|
|
1061
|
+
[...(this.config.slashValidatorsNever ?? []), ...newAddresses].map(a => a.toString()),
|
|
1062
|
+
).map(EthAddress.fromString);
|
|
1063
|
+
this.slasherClient.updateConfig({ slashValidatorsNever });
|
|
1064
|
+
}
|
|
1460
1065
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1066
|
+
this.keyStoreManager = newManager;
|
|
1067
|
+
this.log.info('Keystore reloaded: coinbase, feeRecipient, and attester keys updated');
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
public async mineBlock(): Promise<void> {
|
|
1071
|
+
if (this.automineSequencer) {
|
|
1072
|
+
await this.automineSequencer.buildEmptyBlock();
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
if (!this.sequencer) {
|
|
1076
|
+
throw new BadRequestError('Cannot mine block: no sequencer is running');
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
const currentBlockNumber = await this.getBlockNumber();
|
|
1080
|
+
|
|
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);
|
|
1084
|
+
|
|
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 });
|
|
1088
|
+
|
|
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 });
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
public async prove(upToCheckpoint?: CheckpointNumber): Promise<CheckpointNumber> {
|
|
1109
|
+
if (!this.automineSequencer) {
|
|
1110
|
+
throw new BadRequestError('Cannot prove checkpoint: no automine sequencer is running');
|
|
1111
|
+
}
|
|
1112
|
+
return await this.automineSequencer.prove(upToCheckpoint);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
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');
|
|
1118
|
+
}
|
|
1119
|
+
await this.automineSequencer.warpTo(targetTimestamp);
|
|
1120
|
+
}
|
|
1464
1121
|
|
|
1465
|
-
|
|
1466
|
-
|
|
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');
|
|
1467
1125
|
}
|
|
1126
|
+
await this.automineSequencer.warpBy(duration);
|
|
1468
1127
|
}
|
|
1469
1128
|
|
|
1470
1129
|
/**
|
|
1471
|
-
*
|
|
1472
|
-
* @
|
|
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.
|
|
1473
1133
|
*/
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
return await this.worldStateSynchronizer.syncImmediate(blockSourceHeight);
|
|
1134
|
+
protected getWorldState(block: BlockParameter) {
|
|
1135
|
+
return this.worldStateQueries.getWorldState(block);
|
|
1477
1136
|
}
|
|
1478
1137
|
}
|