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