@aztec/aztec-node 0.0.0-test.1 → 0.0.1-commit.5476d83
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/config.d.ts +15 -10
- package/dest/aztec-node/config.d.ts.map +1 -1
- package/dest/aztec-node/config.js +75 -14
- package/dest/aztec-node/node_metrics.d.ts +5 -1
- package/dest/aztec-node/node_metrics.d.ts.map +1 -1
- package/dest/aztec-node/node_metrics.js +21 -0
- package/dest/aztec-node/server.d.ts +93 -52
- package/dest/aztec-node/server.d.ts.map +1 -1
- package/dest/aztec-node/server.js +535 -218
- package/dest/bin/index.d.ts +1 -1
- package/dest/bin/index.js +4 -2
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/sentinel/config.d.ts +8 -0
- package/dest/sentinel/config.d.ts.map +1 -0
- package/dest/sentinel/config.js +29 -0
- package/dest/sentinel/factory.d.ts +9 -0
- package/dest/sentinel/factory.d.ts.map +1 -0
- package/dest/sentinel/factory.js +17 -0
- package/dest/sentinel/index.d.ts +3 -0
- package/dest/sentinel/index.d.ts.map +1 -0
- package/dest/sentinel/index.js +1 -0
- package/dest/sentinel/sentinel.d.ts +92 -0
- package/dest/sentinel/sentinel.d.ts.map +1 -0
- package/dest/sentinel/sentinel.js +398 -0
- package/dest/sentinel/store.d.ts +35 -0
- package/dest/sentinel/store.d.ts.map +1 -0
- package/dest/sentinel/store.js +170 -0
- package/dest/test/index.d.ts +31 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/package.json +45 -34
- package/src/aztec-node/config.ts +128 -25
- package/src/aztec-node/node_metrics.ts +28 -0
- package/src/aztec-node/server.ts +695 -279
- package/src/bin/index.ts +4 -2
- package/src/index.ts +0 -1
- package/src/sentinel/config.ts +37 -0
- package/src/sentinel/factory.ts +36 -0
- package/src/sentinel/index.ts +8 -0
- package/src/sentinel/sentinel.ts +501 -0
- package/src/sentinel/store.ts +185 -0
- package/src/test/index.ts +32 -0
- package/dest/aztec-node/http_rpc_server.d.ts +0 -8
- package/dest/aztec-node/http_rpc_server.d.ts.map +0 -1
- package/dest/aztec-node/http_rpc_server.js +0 -9
- package/src/aztec-node/http_rpc_server.ts +0 -11
|
@@ -5,33 +5,45 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
}
|
|
7
7
|
import { createArchiver } from '@aztec/archiver';
|
|
8
|
-
import { BBCircuitVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
8
|
+
import { BBCircuitVerifier, QueuedIVCVerifier, TestCircuitVerifier } from '@aztec/bb-prover';
|
|
9
9
|
import { createBlobSinkClient } from '@aztec/blob-sink/client';
|
|
10
|
-
import { INITIAL_L2_BLOCK_NUM
|
|
10
|
+
import { INITIAL_L2_BLOCK_NUM } from '@aztec/constants';
|
|
11
11
|
import { EpochCache } from '@aztec/epoch-cache';
|
|
12
|
-
import { createEthereumChain } from '@aztec/ethereum';
|
|
13
|
-
import { compactArray } from '@aztec/foundation/collection';
|
|
12
|
+
import { RegistryContract, RollupContract, createEthereumChain, getPublicClient } from '@aztec/ethereum';
|
|
13
|
+
import { compactArray, pick } from '@aztec/foundation/collection';
|
|
14
14
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
15
15
|
import { Fr } from '@aztec/foundation/fields';
|
|
16
|
+
import { BadRequestError } from '@aztec/foundation/json-rpc';
|
|
16
17
|
import { createLogger } from '@aztec/foundation/log';
|
|
18
|
+
import { count } from '@aztec/foundation/string';
|
|
17
19
|
import { DateProvider, Timer } from '@aztec/foundation/timer';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
20
|
+
import { MembershipWitness } from '@aztec/foundation/trees';
|
|
21
|
+
import { KeystoreManager, loadKeystores, mergeKeystores } from '@aztec/node-keystore';
|
|
22
|
+
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
|
|
23
|
+
import { createL1TxUtilsWithBlobsFromEthSigner } from '@aztec/node-lib/factories';
|
|
24
|
+
import { createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
|
|
22
25
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
23
|
-
import { GlobalVariableBuilder, SequencerClient,
|
|
26
|
+
import { BlockBuilder, GlobalVariableBuilder, SequencerClient, createValidatorForAcceptingTxs } from '@aztec/sequencer-client';
|
|
24
27
|
import { PublicProcessorFactory } from '@aztec/simulator/server';
|
|
28
|
+
import { AttestationsBlockWatcher, EpochPruneWatcher, createSlasher } from '@aztec/slasher';
|
|
29
|
+
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
25
30
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import {
|
|
31
|
+
import { L2BlockHash } from '@aztec/stdlib/block';
|
|
32
|
+
import { GasFees } from '@aztec/stdlib/gas';
|
|
33
|
+
import { computePublicDataTreeLeafSlot } from '@aztec/stdlib/hash';
|
|
34
|
+
import { AztecNodeAdminConfigSchema } from '@aztec/stdlib/interfaces/client';
|
|
27
35
|
import { tryStop } from '@aztec/stdlib/interfaces/server';
|
|
36
|
+
import { InboxLeaf } from '@aztec/stdlib/messaging';
|
|
28
37
|
import { P2PClientType } from '@aztec/stdlib/p2p';
|
|
29
38
|
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
30
39
|
import { PublicSimulationOutput, TxReceipt, TxStatus } from '@aztec/stdlib/tx';
|
|
40
|
+
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
31
41
|
import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
|
|
32
|
-
import { createValidatorClient } from '@aztec/validator-client';
|
|
42
|
+
import { NodeKeystoreAdapter, ValidatorClient, createBlockProposalHandler, createValidatorClient } from '@aztec/validator-client';
|
|
33
43
|
import { createWorldStateSynchronizer } from '@aztec/world-state';
|
|
34
|
-
import {
|
|
44
|
+
import { createPublicClient, fallback, http } from 'viem';
|
|
45
|
+
import { createSentinel } from '../sentinel/factory.js';
|
|
46
|
+
import { createKeyStoreForValidator } from './config.js';
|
|
35
47
|
import { NodeMetrics } from './node_metrics.js';
|
|
36
48
|
/**
|
|
37
49
|
* The aztec node.
|
|
@@ -42,35 +54,44 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
42
54
|
logsSource;
|
|
43
55
|
contractDataSource;
|
|
44
56
|
l1ToL2MessageSource;
|
|
45
|
-
nullifierSource;
|
|
46
57
|
worldStateSynchronizer;
|
|
47
58
|
sequencer;
|
|
59
|
+
slasherClient;
|
|
60
|
+
validatorsSentinel;
|
|
61
|
+
epochPruneWatcher;
|
|
48
62
|
l1ChainId;
|
|
49
63
|
version;
|
|
50
64
|
globalVariableBuilder;
|
|
65
|
+
epochCache;
|
|
66
|
+
packageVersion;
|
|
51
67
|
proofVerifier;
|
|
52
68
|
telemetry;
|
|
53
69
|
log;
|
|
54
|
-
packageVersion;
|
|
55
70
|
metrics;
|
|
71
|
+
// Prevent two snapshot operations to happen simultaneously
|
|
72
|
+
isUploadingSnapshot;
|
|
56
73
|
tracer;
|
|
57
|
-
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource,
|
|
74
|
+
constructor(config, p2pClient, blockSource, logsSource, contractDataSource, l1ToL2MessageSource, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, l1ChainId, version, globalVariableBuilder, epochCache, packageVersion, proofVerifier, telemetry = getTelemetryClient(), log = createLogger('node')){
|
|
58
75
|
this.config = config;
|
|
59
76
|
this.p2pClient = p2pClient;
|
|
60
77
|
this.blockSource = blockSource;
|
|
61
78
|
this.logsSource = logsSource;
|
|
62
79
|
this.contractDataSource = contractDataSource;
|
|
63
80
|
this.l1ToL2MessageSource = l1ToL2MessageSource;
|
|
64
|
-
this.nullifierSource = nullifierSource;
|
|
65
81
|
this.worldStateSynchronizer = worldStateSynchronizer;
|
|
66
82
|
this.sequencer = sequencer;
|
|
83
|
+
this.slasherClient = slasherClient;
|
|
84
|
+
this.validatorsSentinel = validatorsSentinel;
|
|
85
|
+
this.epochPruneWatcher = epochPruneWatcher;
|
|
67
86
|
this.l1ChainId = l1ChainId;
|
|
68
87
|
this.version = version;
|
|
69
88
|
this.globalVariableBuilder = globalVariableBuilder;
|
|
89
|
+
this.epochCache = epochCache;
|
|
90
|
+
this.packageVersion = packageVersion;
|
|
70
91
|
this.proofVerifier = proofVerifier;
|
|
71
92
|
this.telemetry = telemetry;
|
|
72
93
|
this.log = log;
|
|
73
|
-
this.
|
|
94
|
+
this.isUploadingSnapshot = false;
|
|
74
95
|
this.metrics = new NodeMetrics(telemetry, 'AztecNodeService');
|
|
75
96
|
this.tracer = telemetry.getTracer('AztecNodeService');
|
|
76
97
|
this.log.info(`Aztec Node version: ${this.packageVersion}`);
|
|
@@ -87,59 +108,200 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
87
108
|
* initializes the Aztec Node, wait for component to sync.
|
|
88
109
|
* @param config - The configuration to be used by the aztec node.
|
|
89
110
|
* @returns - A fully synced Aztec Node for use in development/testing.
|
|
90
|
-
*/ static async createAndSync(
|
|
91
|
-
const
|
|
111
|
+
*/ static async createAndSync(inputConfig, deps = {}, options = {}) {
|
|
112
|
+
const config = {
|
|
113
|
+
...inputConfig
|
|
114
|
+
}; // Copy the config so we dont mutate the input object
|
|
92
115
|
const log = deps.logger ?? createLogger('node');
|
|
116
|
+
const packageVersion = getPackageVersion() ?? '';
|
|
117
|
+
const telemetry = deps.telemetry ?? getTelemetryClient();
|
|
93
118
|
const dateProvider = deps.dateProvider ?? new DateProvider();
|
|
94
|
-
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config
|
|
119
|
+
const blobSinkClient = deps.blobSinkClient ?? createBlobSinkClient(config, {
|
|
120
|
+
logger: createLogger('node:blob-sink:client')
|
|
121
|
+
});
|
|
95
122
|
const ethereumChain = createEthereumChain(config.l1RpcUrls, config.l1ChainId);
|
|
96
|
-
//
|
|
123
|
+
// Build a key store from file if given or from environment otherwise
|
|
124
|
+
let keyStoreManager;
|
|
125
|
+
const keyStoreProvided = config.keyStoreDirectory !== undefined && config.keyStoreDirectory.length > 0;
|
|
126
|
+
if (keyStoreProvided) {
|
|
127
|
+
const keyStores = loadKeystores(config.keyStoreDirectory);
|
|
128
|
+
keyStoreManager = new KeystoreManager(mergeKeystores(keyStores));
|
|
129
|
+
} else {
|
|
130
|
+
const keyStore = createKeyStoreForValidator(config);
|
|
131
|
+
if (keyStore) {
|
|
132
|
+
keyStoreManager = new KeystoreManager(keyStore);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
await keyStoreManager?.validateSigners();
|
|
136
|
+
// If we are a validator, verify our configuration before doing too much more.
|
|
137
|
+
if (!config.disableValidator) {
|
|
138
|
+
if (keyStoreManager === undefined) {
|
|
139
|
+
throw new Error('Failed to create key store, a requirement for running a validator');
|
|
140
|
+
}
|
|
141
|
+
if (!keyStoreProvided) {
|
|
142
|
+
log.warn('KEY STORE CREATED FROM ENVIRONMENT, IT IS RECOMMENDED TO USE A FILE-BASED KEY STORE IN PRODUCTION ENVIRONMENTS');
|
|
143
|
+
}
|
|
144
|
+
ValidatorClient.validateKeyStoreConfiguration(keyStoreManager, log);
|
|
145
|
+
}
|
|
146
|
+
// validate that the actual chain id matches that specified in configuration
|
|
97
147
|
if (config.l1ChainId !== ethereumChain.chainInfo.id) {
|
|
98
148
|
throw new Error(`RPC URL configured for chain id ${ethereumChain.chainInfo.id} but expected id ${config.l1ChainId}`);
|
|
99
149
|
}
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
150
|
+
const publicClient = createPublicClient({
|
|
151
|
+
chain: ethereumChain.chainInfo,
|
|
152
|
+
transport: fallback(config.l1RpcUrls.map((url)=>http(url))),
|
|
153
|
+
pollingInterval: config.viemPollingIntervalMS
|
|
154
|
+
});
|
|
155
|
+
const l1ContractsAddresses = await RegistryContract.collectAddresses(publicClient, config.l1Contracts.registryAddress, config.rollupVersion ?? 'canonical');
|
|
156
|
+
// Overwrite the passed in vars.
|
|
157
|
+
config.l1Contracts = {
|
|
158
|
+
...config.l1Contracts,
|
|
159
|
+
...l1ContractsAddresses
|
|
160
|
+
};
|
|
161
|
+
const rollupContract = new RollupContract(publicClient, config.l1Contracts.rollupAddress.toString());
|
|
162
|
+
const [l1GenesisTime, slotDuration, rollupVersionFromRollup] = await Promise.all([
|
|
163
|
+
rollupContract.getL1GenesisTime(),
|
|
164
|
+
rollupContract.getSlotDuration(),
|
|
165
|
+
rollupContract.getVersion()
|
|
166
|
+
]);
|
|
167
|
+
config.rollupVersion ??= Number(rollupVersionFromRollup);
|
|
168
|
+
if (config.rollupVersion !== Number(rollupVersionFromRollup)) {
|
|
169
|
+
log.warn(`Registry looked up and returned a rollup with version (${config.rollupVersion}), but this does not match with version detected from the rollup directly: (${rollupVersionFromRollup}).`);
|
|
170
|
+
}
|
|
171
|
+
// attempt snapshot sync if possible
|
|
172
|
+
await trySnapshotSync(config, log);
|
|
173
|
+
const epochCache = await EpochCache.create(config.l1Contracts.rollupAddress, config, {
|
|
174
|
+
dateProvider
|
|
175
|
+
});
|
|
176
|
+
const archiver = await createArchiver(config, {
|
|
177
|
+
blobSinkClient,
|
|
178
|
+
epochCache,
|
|
179
|
+
telemetry,
|
|
180
|
+
dateProvider
|
|
181
|
+
}, {
|
|
182
|
+
blockUntilSync: !config.skipArchiverInitialSync
|
|
183
|
+
});
|
|
103
184
|
// now create the merkle trees and the world state synchronizer
|
|
104
185
|
const worldStateSynchronizer = await createWorldStateSynchronizer(config, archiver, options.prefilledPublicData, telemetry);
|
|
105
|
-
const
|
|
186
|
+
const circuitVerifier = config.realProofs ? await BBCircuitVerifier.new(config) : new TestCircuitVerifier(config.proverTestVerificationDelayMs);
|
|
106
187
|
if (!config.realProofs) {
|
|
107
188
|
log.warn(`Aztec node is accepting fake proofs`);
|
|
108
189
|
}
|
|
109
|
-
const
|
|
110
|
-
dateProvider
|
|
111
|
-
});
|
|
190
|
+
const proofVerifier = new QueuedIVCVerifier(config, circuitVerifier);
|
|
112
191
|
// create the tx pool and the p2p client, which will need the l2 block source
|
|
113
|
-
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, telemetry);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
192
|
+
const p2pClient = await createP2PClient(P2PClientType.Full, config, archiver, proofVerifier, worldStateSynchronizer, epochCache, packageVersion, dateProvider, telemetry, deps.p2pClientDeps);
|
|
193
|
+
// We should really not be modifying the config object
|
|
194
|
+
config.txPublicSetupAllowList = config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
195
|
+
const blockBuilder = new BlockBuilder({
|
|
196
|
+
...config,
|
|
197
|
+
l1GenesisTime,
|
|
198
|
+
slotDuration: Number(slotDuration)
|
|
199
|
+
}, worldStateSynchronizer, archiver, dateProvider, telemetry);
|
|
200
|
+
// We'll accumulate sentinel watchers here
|
|
201
|
+
const watchers = [];
|
|
202
|
+
// Create validator client if required
|
|
122
203
|
const validatorClient = createValidatorClient(config, {
|
|
123
204
|
p2pClient,
|
|
124
205
|
telemetry,
|
|
125
206
|
dateProvider,
|
|
126
|
-
epochCache
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const sequencer = config.disableValidator ? undefined : await SequencerClient.new(config, {
|
|
130
|
-
...deps,
|
|
131
|
-
validatorClient,
|
|
132
|
-
p2pClient,
|
|
133
|
-
worldStateSynchronizer,
|
|
134
|
-
slasherClient,
|
|
135
|
-
contractDataSource: archiver,
|
|
136
|
-
l2BlockSource: archiver,
|
|
207
|
+
epochCache,
|
|
208
|
+
blockBuilder,
|
|
209
|
+
blockSource: archiver,
|
|
137
210
|
l1ToL2MessageSource: archiver,
|
|
138
|
-
|
|
139
|
-
dateProvider,
|
|
140
|
-
blobSinkClient
|
|
211
|
+
keyStoreManager
|
|
141
212
|
});
|
|
142
|
-
|
|
213
|
+
// If we have a validator client, register it as a source of offenses for the slasher,
|
|
214
|
+
// and have it register callbacks on the p2p client *before* we start it, otherwise messages
|
|
215
|
+
// like attestations or auths will fail.
|
|
216
|
+
if (validatorClient) {
|
|
217
|
+
watchers.push(validatorClient);
|
|
218
|
+
if (!options.dontStartSequencer) {
|
|
219
|
+
await validatorClient.registerHandlers();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// If there's no validator client but alwaysReexecuteBlockProposals is enabled,
|
|
223
|
+
// create a BlockProposalHandler to reexecute block proposals for monitoring
|
|
224
|
+
if (!validatorClient && config.alwaysReexecuteBlockProposals) {
|
|
225
|
+
log.info('Setting up block proposal reexecution for monitoring');
|
|
226
|
+
createBlockProposalHandler(config, {
|
|
227
|
+
blockBuilder,
|
|
228
|
+
epochCache,
|
|
229
|
+
blockSource: archiver,
|
|
230
|
+
l1ToL2MessageSource: archiver,
|
|
231
|
+
p2pClient,
|
|
232
|
+
dateProvider,
|
|
233
|
+
telemetry
|
|
234
|
+
}).registerForReexecution(p2pClient);
|
|
235
|
+
}
|
|
236
|
+
// Start world state and wait for it to sync to the archiver.
|
|
237
|
+
await worldStateSynchronizer.start();
|
|
238
|
+
// Start p2p. Note that it depends on world state to be running.
|
|
239
|
+
await p2pClient.start();
|
|
240
|
+
const validatorsSentinel = await createSentinel(epochCache, archiver, p2pClient, config);
|
|
241
|
+
if (validatorsSentinel && config.slashInactivityPenalty > 0n) {
|
|
242
|
+
watchers.push(validatorsSentinel);
|
|
243
|
+
}
|
|
244
|
+
let epochPruneWatcher;
|
|
245
|
+
if (config.slashPrunePenalty > 0n || config.slashDataWithholdingPenalty > 0n) {
|
|
246
|
+
epochPruneWatcher = new EpochPruneWatcher(archiver, archiver, epochCache, p2pClient.getTxProvider(), blockBuilder, config);
|
|
247
|
+
watchers.push(epochPruneWatcher);
|
|
248
|
+
}
|
|
249
|
+
// We assume we want to slash for invalid attestations unless all max penalties are set to 0
|
|
250
|
+
let attestationsBlockWatcher;
|
|
251
|
+
if (config.slashProposeInvalidAttestationsPenalty > 0n || config.slashAttestDescendantOfInvalidPenalty > 0n) {
|
|
252
|
+
attestationsBlockWatcher = new AttestationsBlockWatcher(archiver, epochCache, config);
|
|
253
|
+
watchers.push(attestationsBlockWatcher);
|
|
254
|
+
}
|
|
255
|
+
// Start p2p-related services once the archiver has completed sync
|
|
256
|
+
void archiver.waitForInitialSync().then(async ()=>{
|
|
257
|
+
await p2pClient.start();
|
|
258
|
+
await validatorsSentinel?.start();
|
|
259
|
+
await epochPruneWatcher?.start();
|
|
260
|
+
await attestationsBlockWatcher?.start();
|
|
261
|
+
log.info(`All p2p services started`);
|
|
262
|
+
}).catch((err)=>log.error('Failed to start p2p services after archiver sync', err));
|
|
263
|
+
// Validator enabled, create/start relevant service
|
|
264
|
+
let sequencer;
|
|
265
|
+
let slasherClient;
|
|
266
|
+
if (!config.disableValidator) {
|
|
267
|
+
// We create a slasher only if we have a sequencer, since all slashing actions go through the sequencer publisher
|
|
268
|
+
// as they are executed when the node is selected as proposer.
|
|
269
|
+
const validatorAddresses = keyStoreManager ? NodeKeystoreAdapter.fromKeyStoreManager(keyStoreManager).getAddresses() : [];
|
|
270
|
+
slasherClient = await createSlasher(config, config.l1Contracts, getPublicClient(config), watchers, dateProvider, epochCache, validatorAddresses, undefined);
|
|
271
|
+
await slasherClient.start();
|
|
272
|
+
const l1TxUtils = await createL1TxUtilsWithBlobsFromEthSigner(publicClient, keyStoreManager.createAllValidatorPublisherSigners(), {
|
|
273
|
+
...config,
|
|
274
|
+
scope: 'sequencer'
|
|
275
|
+
}, {
|
|
276
|
+
telemetry,
|
|
277
|
+
logger: log.createChild('l1-tx-utils'),
|
|
278
|
+
dateProvider
|
|
279
|
+
});
|
|
280
|
+
// Create and start the sequencer client
|
|
281
|
+
sequencer = await SequencerClient.new(config, {
|
|
282
|
+
...deps,
|
|
283
|
+
epochCache,
|
|
284
|
+
l1TxUtils,
|
|
285
|
+
validatorClient,
|
|
286
|
+
p2pClient,
|
|
287
|
+
worldStateSynchronizer,
|
|
288
|
+
slasherClient,
|
|
289
|
+
blockBuilder,
|
|
290
|
+
l2BlockSource: archiver,
|
|
291
|
+
l1ToL2MessageSource: archiver,
|
|
292
|
+
telemetry,
|
|
293
|
+
dateProvider,
|
|
294
|
+
blobSinkClient,
|
|
295
|
+
nodeKeyStore: keyStoreManager
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (!options.dontStartSequencer && sequencer) {
|
|
299
|
+
await sequencer.start();
|
|
300
|
+
log.verbose(`Sequencer started`);
|
|
301
|
+
} else if (sequencer) {
|
|
302
|
+
log.warn(`Sequencer created but not started`);
|
|
303
|
+
}
|
|
304
|
+
return new AztecNodeService(config, p2pClient, archiver, archiver, archiver, archiver, worldStateSynchronizer, sequencer, slasherClient, validatorsSentinel, epochPruneWatcher, ethereumChain.chainInfo.id, config.rollupVersion, new GlobalVariableBuilder(config), epochCache, packageVersion, proofVerifier, telemetry, log);
|
|
143
305
|
}
|
|
144
306
|
/**
|
|
145
307
|
* Returns the sequencer client instance.
|
|
@@ -165,6 +327,9 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
165
327
|
getEncodedEnr() {
|
|
166
328
|
return Promise.resolve(this.p2pClient.getEnr()?.encodeTxt());
|
|
167
329
|
}
|
|
330
|
+
async getAllowedPublicSetup() {
|
|
331
|
+
return this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions();
|
|
332
|
+
}
|
|
168
333
|
/**
|
|
169
334
|
* Method to determine if the node is ready to accept transactions.
|
|
170
335
|
* @returns - Flag indicating the readiness for tx submission.
|
|
@@ -172,7 +337,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
172
337
|
return Promise.resolve(this.p2pClient.isReady() ?? false);
|
|
173
338
|
}
|
|
174
339
|
async getNodeInfo() {
|
|
175
|
-
const [nodeVersion,
|
|
340
|
+
const [nodeVersion, rollupVersion, chainId, enr, contractAddresses, protocolContractAddresses] = await Promise.all([
|
|
176
341
|
this.getNodeVersion(),
|
|
177
342
|
this.getVersion(),
|
|
178
343
|
this.getChainId(),
|
|
@@ -183,7 +348,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
183
348
|
const nodeInfo = {
|
|
184
349
|
nodeVersion,
|
|
185
350
|
l1ChainId: chainId,
|
|
186
|
-
|
|
351
|
+
rollupVersion,
|
|
187
352
|
enr,
|
|
188
353
|
l1ContractAddresses: contractAddresses,
|
|
189
354
|
protocolContractAddresses: protocolContractAddresses
|
|
@@ -195,7 +360,24 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
195
360
|
* @param number - The block number being requested.
|
|
196
361
|
* @returns The requested block.
|
|
197
362
|
*/ async getBlock(number) {
|
|
198
|
-
|
|
363
|
+
const blockNumber = number === 'latest' ? await this.getBlockNumber() : number;
|
|
364
|
+
return await this.blockSource.getBlock(blockNumber);
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Get a block specified by its hash.
|
|
368
|
+
* @param blockHash - The block hash being requested.
|
|
369
|
+
* @returns The requested block.
|
|
370
|
+
*/ async getBlockByHash(blockHash) {
|
|
371
|
+
const publishedBlock = await this.blockSource.getPublishedBlockByHash(blockHash);
|
|
372
|
+
return publishedBlock?.block;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Get a block specified by its archive root.
|
|
376
|
+
* @param archive - The archive root being requested.
|
|
377
|
+
* @returns The requested block.
|
|
378
|
+
*/ async getBlockByArchive(archive) {
|
|
379
|
+
const publishedBlock = await this.blockSource.getPublishedBlockByArchive(archive);
|
|
380
|
+
return publishedBlock?.block;
|
|
199
381
|
}
|
|
200
382
|
/**
|
|
201
383
|
* Method to request blocks. Will attempt to return all requested blocks but will return only those available.
|
|
@@ -205,14 +387,26 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
205
387
|
*/ async getBlocks(from, limit) {
|
|
206
388
|
return await this.blockSource.getBlocks(from, limit) ?? [];
|
|
207
389
|
}
|
|
390
|
+
async getPublishedBlocks(from, limit) {
|
|
391
|
+
return await this.blockSource.getPublishedBlocks(from, limit) ?? [];
|
|
392
|
+
}
|
|
208
393
|
/**
|
|
209
394
|
* Method to fetch the current base fees.
|
|
210
395
|
* @returns The current base fees.
|
|
211
396
|
*/ async getCurrentBaseFees() {
|
|
212
397
|
return await this.globalVariableBuilder.getCurrentBaseFees();
|
|
213
398
|
}
|
|
399
|
+
async getMaxPriorityFees() {
|
|
400
|
+
for await (const tx of this.p2pClient.iteratePendingTxs()){
|
|
401
|
+
return tx.getGasSettings().maxPriorityFeesPerGas;
|
|
402
|
+
}
|
|
403
|
+
return GasFees.from({
|
|
404
|
+
feePerDaGas: 0n,
|
|
405
|
+
feePerL2Gas: 0n
|
|
406
|
+
});
|
|
407
|
+
}
|
|
214
408
|
/**
|
|
215
|
-
* Method to fetch the
|
|
409
|
+
* Method to fetch the latest block number synchronized by the node.
|
|
216
410
|
* @returns The block number.
|
|
217
411
|
*/ async getBlockNumber() {
|
|
218
412
|
return await this.blockSource.getBlockNumber();
|
|
@@ -238,25 +432,8 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
238
432
|
*/ getChainId() {
|
|
239
433
|
return Promise.resolve(this.l1ChainId);
|
|
240
434
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// TODO(#10007): Remove this check. This is needed only because we're manually registering
|
|
244
|
-
// some contracts in the archiver so they are available to all nodes (see `registerCommonContracts`
|
|
245
|
-
// in `archiver/src/factory.ts`), but we still want clients to send the registration tx in order
|
|
246
|
-
// to emit the corresponding nullifier, which is now being checked. Note that this method
|
|
247
|
-
// is only called by the PXE to check if a contract is publicly registered.
|
|
248
|
-
if (klazz) {
|
|
249
|
-
const classNullifier = await siloNullifier(AztecAddress.fromNumber(REGISTERER_CONTRACT_ADDRESS), id);
|
|
250
|
-
const worldState = await this.#getWorldState('latest');
|
|
251
|
-
const [index] = await worldState.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [
|
|
252
|
-
classNullifier.toBuffer()
|
|
253
|
-
]);
|
|
254
|
-
this.log.debug(`Registration nullifier ${classNullifier} for contract class ${id} found at index ${index}`);
|
|
255
|
-
if (index === undefined) {
|
|
256
|
-
return undefined;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return klazz;
|
|
435
|
+
getContractClass(id) {
|
|
436
|
+
return this.contractDataSource.getContractClass(id);
|
|
260
437
|
}
|
|
261
438
|
getContract(address) {
|
|
262
439
|
return this.contractDataSource.getContract(address);
|
|
@@ -272,10 +449,11 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
272
449
|
/**
|
|
273
450
|
* Gets all logs that match any of the received tags (i.e. logs with their first field equal to a tag).
|
|
274
451
|
* @param tags - The tags to filter the logs by.
|
|
452
|
+
* @param logsPerTag - The maximum number of logs to return for each tag. By default no limit is set
|
|
275
453
|
* @returns For each received tag, an array of matching logs is returned. An empty array implies no logs match
|
|
276
454
|
* that tag.
|
|
277
|
-
*/ getLogsByTags(tags) {
|
|
278
|
-
return this.logsSource.getLogsByTags(tags);
|
|
455
|
+
*/ getLogsByTags(tags, logsPerTag) {
|
|
456
|
+
return this.logsSource.getLogsByTags(tags, logsPerTag);
|
|
279
457
|
}
|
|
280
458
|
/**
|
|
281
459
|
* Gets public logs based on the provided filter.
|
|
@@ -295,18 +473,19 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
295
473
|
* Method to submit a transaction to the p2p pool.
|
|
296
474
|
* @param tx - The transaction to be submitted.
|
|
297
475
|
*/ async sendTx(tx) {
|
|
476
|
+
await this.#sendTx(tx);
|
|
477
|
+
}
|
|
478
|
+
async #sendTx(tx) {
|
|
298
479
|
const timer = new Timer();
|
|
299
|
-
const txHash =
|
|
480
|
+
const txHash = tx.getTxHash().toString();
|
|
300
481
|
const valid = await this.isValidTx(tx);
|
|
301
482
|
if (valid.result !== 'valid') {
|
|
302
483
|
const reason = valid.reason.join(', ');
|
|
303
484
|
this.metrics.receivedTx(timer.ms(), false);
|
|
304
|
-
this.log.warn(`
|
|
485
|
+
this.log.warn(`Received invalid tx ${txHash}: ${reason}`, {
|
|
305
486
|
txHash
|
|
306
487
|
});
|
|
307
|
-
|
|
308
|
-
// throw new Error(`Invalid tx: ${reason}`);
|
|
309
|
-
return;
|
|
488
|
+
throw new Error(`Invalid tx: ${reason}`);
|
|
310
489
|
}
|
|
311
490
|
await this.p2pClient.sendTx(tx);
|
|
312
491
|
this.metrics.receivedTx(timer.ms(), true);
|
|
@@ -334,63 +513,98 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
334
513
|
/**
|
|
335
514
|
* Method to stop the aztec node.
|
|
336
515
|
*/ async stop() {
|
|
337
|
-
this.log.info(`Stopping`);
|
|
338
|
-
await this.
|
|
339
|
-
await this.
|
|
340
|
-
await this.
|
|
516
|
+
this.log.info(`Stopping Aztec Node`);
|
|
517
|
+
await tryStop(this.validatorsSentinel);
|
|
518
|
+
await tryStop(this.epochPruneWatcher);
|
|
519
|
+
await tryStop(this.slasherClient);
|
|
520
|
+
await tryStop(this.proofVerifier);
|
|
521
|
+
await tryStop(this.sequencer);
|
|
522
|
+
await tryStop(this.p2pClient);
|
|
523
|
+
await tryStop(this.worldStateSynchronizer);
|
|
341
524
|
await tryStop(this.blockSource);
|
|
342
|
-
await this.telemetry
|
|
343
|
-
this.log.info(`Stopped`);
|
|
525
|
+
await tryStop(this.telemetry);
|
|
526
|
+
this.log.info(`Stopped Aztec Node`);
|
|
344
527
|
}
|
|
345
528
|
/**
|
|
346
529
|
* Method to retrieve pending txs.
|
|
530
|
+
* @param limit - The number of items to returns
|
|
531
|
+
* @param after - The last known pending tx. Used for pagination
|
|
347
532
|
* @returns - The pending txs.
|
|
348
|
-
*/ getPendingTxs() {
|
|
349
|
-
return this.p2pClient.getPendingTxs();
|
|
533
|
+
*/ getPendingTxs(limit, after) {
|
|
534
|
+
return this.p2pClient.getPendingTxs(limit, after);
|
|
350
535
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return pendingTxs.length;
|
|
536
|
+
getPendingTxCount() {
|
|
537
|
+
return this.p2pClient.getPendingTxCount();
|
|
354
538
|
}
|
|
355
539
|
/**
|
|
356
|
-
* Method to retrieve a single tx from the mempool or
|
|
540
|
+
* Method to retrieve a single tx from the mempool or unfinalized chain.
|
|
357
541
|
* @param txHash - The transaction hash to return.
|
|
358
542
|
* @returns - The tx if it exists.
|
|
359
543
|
*/ getTxByHash(txHash) {
|
|
360
544
|
return Promise.resolve(this.p2pClient.getTxByHashFromPool(txHash));
|
|
361
545
|
}
|
|
362
546
|
/**
|
|
363
|
-
* Method to retrieve txs from the mempool or
|
|
547
|
+
* Method to retrieve txs from the mempool or unfinalized chain.
|
|
364
548
|
* @param txHash - The transaction hash to return.
|
|
365
549
|
* @returns - The txs if it exists.
|
|
366
550
|
*/ async getTxsByHash(txHashes) {
|
|
367
551
|
return compactArray(await Promise.all(txHashes.map((txHash)=>this.getTxByHash(txHash))));
|
|
368
552
|
}
|
|
369
553
|
/**
|
|
370
|
-
* Find the indexes of the given leaves in the given tree
|
|
371
|
-
*
|
|
554
|
+
* Find the indexes of the given leaves in the given tree along with a block metadata pointing to the block in which
|
|
555
|
+
* the leaves were inserted.
|
|
556
|
+
* @param blockNumber - The block number at which to get the data or 'latest' for latest data.
|
|
372
557
|
* @param treeId - The tree to search in.
|
|
373
|
-
* @param
|
|
374
|
-
* @returns The
|
|
558
|
+
* @param leafValues - The values to search for.
|
|
559
|
+
* @returns The indices of leaves and the block metadata of a block in which the leaves were inserted.
|
|
375
560
|
*/ async findLeavesIndexes(blockNumber, treeId, leafValues) {
|
|
376
561
|
const committedDb = await this.#getWorldState(blockNumber);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return await committedDb.getBlockNumbersForLeafIndices(treeId, leafIndices);
|
|
388
|
-
}
|
|
389
|
-
async findNullifiersIndexesWithBlock(blockNumber, nullifiers) {
|
|
390
|
-
if (blockNumber === 'latest') {
|
|
391
|
-
blockNumber = await this.getBlockNumber();
|
|
562
|
+
const maybeIndices = await committedDb.findLeafIndices(treeId, leafValues.map((x)=>x.toBuffer()));
|
|
563
|
+
// We filter out undefined values
|
|
564
|
+
const indices = maybeIndices.filter((x)=>x !== undefined);
|
|
565
|
+
// Now we find the block numbers for the indices
|
|
566
|
+
const blockNumbers = await committedDb.getBlockNumbersForLeafIndices(treeId, indices);
|
|
567
|
+
// If any of the block numbers are undefined, we throw an error.
|
|
568
|
+
for(let i = 0; i < indices.length; i++){
|
|
569
|
+
if (blockNumbers[i] === undefined) {
|
|
570
|
+
throw new Error(`Block number is undefined for leaf index ${indices[i]} in tree ${MerkleTreeId[treeId]}`);
|
|
571
|
+
}
|
|
392
572
|
}
|
|
393
|
-
|
|
573
|
+
// Get unique block numbers in order to optimize num calls to getLeafValue function.
|
|
574
|
+
const uniqueBlockNumbers = [
|
|
575
|
+
...new Set(blockNumbers.filter((x)=>x !== undefined))
|
|
576
|
+
];
|
|
577
|
+
// Now we obtain the block hashes from the archive tree by calling await `committedDb.getLeafValue(treeId, index)`
|
|
578
|
+
// (note that block number corresponds to the leaf index in the archive tree).
|
|
579
|
+
const blockHashes = await Promise.all(uniqueBlockNumbers.map((blockNumber)=>{
|
|
580
|
+
return committedDb.getLeafValue(MerkleTreeId.ARCHIVE, blockNumber);
|
|
581
|
+
}));
|
|
582
|
+
// If any of the block hashes are undefined, we throw an error.
|
|
583
|
+
for(let i = 0; i < uniqueBlockNumbers.length; i++){
|
|
584
|
+
if (blockHashes[i] === undefined) {
|
|
585
|
+
throw new Error(`Block hash is undefined for block number ${uniqueBlockNumbers[i]}`);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
// Create InBlock objects by combining indices, blockNumbers and blockHashes and return them.
|
|
589
|
+
return maybeIndices.map((index, i)=>{
|
|
590
|
+
if (index === undefined) {
|
|
591
|
+
return undefined;
|
|
592
|
+
}
|
|
593
|
+
const blockNumber = blockNumbers[i];
|
|
594
|
+
if (blockNumber === undefined) {
|
|
595
|
+
return undefined;
|
|
596
|
+
}
|
|
597
|
+
const blockHashIndex = uniqueBlockNumbers.indexOf(blockNumber);
|
|
598
|
+
const blockHash = blockHashes[blockHashIndex];
|
|
599
|
+
if (!blockHash) {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
l2BlockNumber: Number(blockNumber),
|
|
604
|
+
l2BlockHash: L2BlockHash.fromField(blockHash),
|
|
605
|
+
data: index
|
|
606
|
+
};
|
|
607
|
+
});
|
|
394
608
|
}
|
|
395
609
|
/**
|
|
396
610
|
* Returns a sibling path for the given index in the nullifier tree.
|
|
@@ -410,90 +624,58 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
410
624
|
const committedDb = await this.#getWorldState(blockNumber);
|
|
411
625
|
return committedDb.getSiblingPath(MerkleTreeId.NOTE_HASH_TREE, leafIndex);
|
|
412
626
|
}
|
|
627
|
+
async getArchiveMembershipWitness(blockNumber, archive) {
|
|
628
|
+
const committedDb = await this.#getWorldState(blockNumber);
|
|
629
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.ARCHIVE, [
|
|
630
|
+
archive
|
|
631
|
+
]);
|
|
632
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
633
|
+
}
|
|
634
|
+
async getNoteHashMembershipWitness(blockNumber, noteHash) {
|
|
635
|
+
const committedDb = await this.#getWorldState(blockNumber);
|
|
636
|
+
const [pathAndIndex] = await committedDb.findSiblingPaths(MerkleTreeId.NOTE_HASH_TREE, [
|
|
637
|
+
noteHash
|
|
638
|
+
]);
|
|
639
|
+
return pathAndIndex === undefined ? undefined : MembershipWitness.fromSiblingPath(pathAndIndex.index, pathAndIndex.path);
|
|
640
|
+
}
|
|
413
641
|
/**
|
|
414
642
|
* Returns the index and a sibling path for a leaf in the committed l1 to l2 data tree.
|
|
415
643
|
* @param blockNumber - The block number at which to get the data.
|
|
416
644
|
* @param l1ToL2Message - The l1ToL2Message to get the index / sibling path for.
|
|
417
645
|
* @returns A tuple of the index and the sibling path of the L1ToL2Message (undefined if not found).
|
|
418
646
|
*/ async getL1ToL2MessageMembershipWitness(blockNumber, l1ToL2Message) {
|
|
419
|
-
const
|
|
420
|
-
|
|
647
|
+
const db = await this.#getWorldState(blockNumber);
|
|
648
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, [
|
|
649
|
+
l1ToL2Message
|
|
650
|
+
]);
|
|
651
|
+
if (!witness) {
|
|
421
652
|
return undefined;
|
|
422
653
|
}
|
|
423
|
-
|
|
424
|
-
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, index);
|
|
654
|
+
// REFACTOR: Return a MembershipWitness object
|
|
425
655
|
return [
|
|
426
|
-
index,
|
|
427
|
-
|
|
656
|
+
witness.index,
|
|
657
|
+
witness.path
|
|
428
658
|
];
|
|
429
659
|
}
|
|
660
|
+
async getL1ToL2MessageBlock(l1ToL2Message) {
|
|
661
|
+
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
662
|
+
return messageIndex ? InboxLeaf.l2BlockFromIndex(messageIndex) : undefined;
|
|
663
|
+
}
|
|
430
664
|
/**
|
|
431
665
|
* Returns whether an L1 to L2 message is synced by archiver and if it's ready to be included in a block.
|
|
432
666
|
* @param l1ToL2Message - The L1 to L2 message to check.
|
|
433
667
|
* @returns Whether the message is synced and ready to be included in a block.
|
|
434
668
|
*/ async isL1ToL2MessageSynced(l1ToL2Message) {
|
|
435
|
-
|
|
669
|
+
const messageIndex = await this.l1ToL2MessageSource.getL1ToL2MessageIndex(l1ToL2Message);
|
|
670
|
+
return messageIndex !== undefined;
|
|
436
671
|
}
|
|
437
672
|
/**
|
|
438
|
-
* Returns the
|
|
439
|
-
* @remarks This tree is considered ephemeral because it is created on-demand by: taking all the l2ToL1 messages
|
|
440
|
-
* in a single block, and then using them to make a variable depth append-only tree with these messages as leaves.
|
|
441
|
-
* The tree is discarded immediately after calculating what we need from it.
|
|
442
|
-
* TODO: Handle the case where two messages in the same tx have the same hash.
|
|
673
|
+
* Returns all the L2 to L1 messages in a block.
|
|
443
674
|
* @param blockNumber - The block number at which to get the data.
|
|
444
|
-
* @
|
|
445
|
-
|
|
446
|
-
*/ async getL2ToL1MessageMembershipWitness(blockNumber, l2ToL1Message) {
|
|
675
|
+
* @returns The L2 to L1 messages (undefined if the block number is not found).
|
|
676
|
+
*/ async getL2ToL1Messages(blockNumber) {
|
|
447
677
|
const block = await this.blockSource.getBlock(blockNumber === 'latest' ? await this.getBlockNumber() : blockNumber);
|
|
448
|
-
|
|
449
|
-
throw new Error('Block is not defined');
|
|
450
|
-
}
|
|
451
|
-
const l2ToL1Messages = block.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
|
|
452
|
-
// Find index of message
|
|
453
|
-
let indexOfMsgInSubtree = -1;
|
|
454
|
-
const indexOfMsgTx = l2ToL1Messages.findIndex((msgs)=>{
|
|
455
|
-
const idx = msgs.findIndex((msg)=>msg.equals(l2ToL1Message));
|
|
456
|
-
indexOfMsgInSubtree = Math.max(indexOfMsgInSubtree, idx);
|
|
457
|
-
return idx !== -1;
|
|
458
|
-
});
|
|
459
|
-
if (indexOfMsgTx === -1) {
|
|
460
|
-
throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
|
|
461
|
-
}
|
|
462
|
-
const tempStores = [];
|
|
463
|
-
// Construct message subtrees
|
|
464
|
-
const l2toL1Subtrees = await Promise.all(l2ToL1Messages.map(async (msgs, i)=>{
|
|
465
|
-
const store = openTmpStore(true);
|
|
466
|
-
tempStores.push(store);
|
|
467
|
-
const treeHeight = msgs.length <= 1 ? 1 : Math.ceil(Math.log2(msgs.length));
|
|
468
|
-
const tree = new StandardTree(store, new SHA256Trunc(), `temp_msgs_subtrees_${i}`, treeHeight, 0n, Fr);
|
|
469
|
-
await tree.appendLeaves(msgs);
|
|
470
|
-
return tree;
|
|
471
|
-
}));
|
|
472
|
-
// path of the input msg from leaf -> first out hash calculated in base rolllup
|
|
473
|
-
const subtreePathOfL2ToL1Message = await l2toL1Subtrees[indexOfMsgTx].getSiblingPath(BigInt(indexOfMsgInSubtree), true);
|
|
474
|
-
const numTxs = block.body.txEffects.length;
|
|
475
|
-
if (numTxs === 1) {
|
|
476
|
-
return [
|
|
477
|
-
BigInt(indexOfMsgInSubtree),
|
|
478
|
-
subtreePathOfL2ToL1Message
|
|
479
|
-
];
|
|
480
|
-
}
|
|
481
|
-
const l2toL1SubtreeRoots = l2toL1Subtrees.map((t)=>Fr.fromBuffer(t.getRoot(true)));
|
|
482
|
-
const maxTreeHeight = Math.ceil(Math.log2(l2toL1SubtreeRoots.length));
|
|
483
|
-
// The root of this tree is the out_hash calculated in Noir => we truncate to match Noir's SHA
|
|
484
|
-
const outHashTree = new UnbalancedTree(new SHA256Trunc(), 'temp_outhash_sibling_path', maxTreeHeight, Fr);
|
|
485
|
-
await outHashTree.appendLeaves(l2toL1SubtreeRoots);
|
|
486
|
-
const pathOfTxInOutHashTree = await outHashTree.getSiblingPath(l2toL1SubtreeRoots[indexOfMsgTx].toBigInt());
|
|
487
|
-
// Append subtree path to out hash tree path
|
|
488
|
-
const mergedPath = subtreePathOfL2ToL1Message.toBufferArray().concat(pathOfTxInOutHashTree.toBufferArray());
|
|
489
|
-
// Append binary index of subtree path to binary index of out hash tree path
|
|
490
|
-
const mergedIndex = parseInt(indexOfMsgTx.toString(2).concat(indexOfMsgInSubtree.toString(2).padStart(l2toL1Subtrees[indexOfMsgTx].getDepth(), '0')), 2);
|
|
491
|
-
// clear the tmp stores
|
|
492
|
-
await Promise.all(tempStores.map((store)=>store.delete()));
|
|
493
|
-
return [
|
|
494
|
-
BigInt(mergedIndex),
|
|
495
|
-
new SiblingPath(mergedPath.length, mergedPath)
|
|
496
|
-
];
|
|
678
|
+
return block?.body.txEffects.map((txEffect)=>txEffect.l2ToL1Msgs);
|
|
497
679
|
}
|
|
498
680
|
/**
|
|
499
681
|
* Returns a sibling path for a leaf in the committed blocks tree.
|
|
@@ -520,22 +702,18 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
520
702
|
* @returns The nullifier membership witness (if found).
|
|
521
703
|
*/ async getNullifierMembershipWitness(blockNumber, nullifier) {
|
|
522
704
|
const db = await this.#getWorldState(blockNumber);
|
|
523
|
-
const
|
|
705
|
+
const [witness] = await db.findSiblingPaths(MerkleTreeId.NULLIFIER_TREE, [
|
|
524
706
|
nullifier.toBuffer()
|
|
525
|
-
])
|
|
526
|
-
if (!
|
|
707
|
+
]);
|
|
708
|
+
if (!witness) {
|
|
527
709
|
return undefined;
|
|
528
710
|
}
|
|
529
|
-
const
|
|
530
|
-
const
|
|
531
|
-
const [leafPreimage, siblingPath] = await Promise.all([
|
|
532
|
-
leafPreimagePromise,
|
|
533
|
-
siblingPathPromise
|
|
534
|
-
]);
|
|
711
|
+
const { index, path } = witness;
|
|
712
|
+
const leafPreimage = await db.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index);
|
|
535
713
|
if (!leafPreimage) {
|
|
536
714
|
return undefined;
|
|
537
715
|
}
|
|
538
|
-
return new NullifierMembershipWitness(
|
|
716
|
+
return new NullifierMembershipWitness(index, leafPreimage, path);
|
|
539
717
|
}
|
|
540
718
|
/**
|
|
541
719
|
* Returns a low nullifier membership witness for a given nullifier at a given block.
|
|
@@ -564,7 +742,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
564
742
|
const siblingPath = await committedDb.getSiblingPath(MerkleTreeId.NULLIFIER_TREE, BigInt(index));
|
|
565
743
|
return new NullifierMembershipWitness(BigInt(index), preimageData, siblingPath);
|
|
566
744
|
}
|
|
567
|
-
async
|
|
745
|
+
async getPublicDataWitness(blockNumber, leafSlot) {
|
|
568
746
|
const committedDb = await this.#getWorldState(blockNumber);
|
|
569
747
|
const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt());
|
|
570
748
|
if (!lowLeafResult) {
|
|
@@ -593,7 +771,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
593
771
|
return Fr.ZERO;
|
|
594
772
|
}
|
|
595
773
|
const preimage = await committedDb.getLeafPreimage(MerkleTreeId.PUBLIC_DATA_TREE, lowLeafResult.index);
|
|
596
|
-
return preimage.value;
|
|
774
|
+
return preimage.leaf.value;
|
|
597
775
|
}
|
|
598
776
|
/**
|
|
599
777
|
* Returns the currently committed block header, or the initial header if no blocks have been produced.
|
|
@@ -602,26 +780,55 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
602
780
|
return blockNumber === 0 || blockNumber === 'latest' && await this.blockSource.getBlockNumber() === 0 ? this.worldStateSynchronizer.getCommitted().getInitialHeader() : this.blockSource.getBlockHeader(blockNumber);
|
|
603
781
|
}
|
|
604
782
|
/**
|
|
783
|
+
* Get a block header specified by its hash.
|
|
784
|
+
* @param blockHash - The block hash being requested.
|
|
785
|
+
* @returns The requested block header.
|
|
786
|
+
*/ async getBlockHeaderByHash(blockHash) {
|
|
787
|
+
return await this.blockSource.getBlockHeaderByHash(blockHash);
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Get a block header specified by its archive root.
|
|
791
|
+
* @param archive - The archive root being requested.
|
|
792
|
+
* @returns The requested block header.
|
|
793
|
+
*/ async getBlockHeaderByArchive(archive) {
|
|
794
|
+
return await this.blockSource.getBlockHeaderByArchive(archive);
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
605
797
|
* Simulates the public part of a transaction with the current state.
|
|
606
798
|
* @param tx - The transaction to simulate.
|
|
607
799
|
**/ async simulatePublicCalls(tx, skipFeeEnforcement = false) {
|
|
608
|
-
|
|
800
|
+
// Check total gas limit for simulation
|
|
801
|
+
const gasSettings = tx.data.constants.txContext.gasSettings;
|
|
802
|
+
const txGasLimit = gasSettings.gasLimits.l2Gas;
|
|
803
|
+
const teardownGasLimit = gasSettings.teardownGasLimits.l2Gas;
|
|
804
|
+
if (txGasLimit + teardownGasLimit > this.config.rpcSimulatePublicMaxGasLimit) {
|
|
805
|
+
throw new BadRequestError(`Transaction total gas limit ${txGasLimit + teardownGasLimit} (${txGasLimit} + ${teardownGasLimit}) exceeds maximum gas limit ${this.config.rpcSimulatePublicMaxGasLimit} for simulation`);
|
|
806
|
+
}
|
|
807
|
+
const txHash = tx.getTxHash();
|
|
609
808
|
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
610
809
|
// If sequencer is not initialized, we just set these values to zero for simulation.
|
|
611
|
-
const coinbase =
|
|
612
|
-
const feeRecipient =
|
|
613
|
-
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(
|
|
810
|
+
const coinbase = EthAddress.ZERO;
|
|
811
|
+
const feeRecipient = AztecAddress.ZERO;
|
|
812
|
+
const newGlobalVariables = await this.globalVariableBuilder.buildGlobalVariables(blockNumber, coinbase, feeRecipient);
|
|
614
813
|
const publicProcessorFactory = new PublicProcessorFactory(this.contractDataSource, new DateProvider(), this.telemetry);
|
|
615
|
-
const fork = await this.worldStateSynchronizer.fork();
|
|
616
814
|
this.log.verbose(`Simulating public calls for tx ${txHash}`, {
|
|
617
815
|
globalVariables: newGlobalVariables.toInspect(),
|
|
618
816
|
txHash,
|
|
619
817
|
blockNumber
|
|
620
818
|
});
|
|
819
|
+
const merkleTreeFork = await this.worldStateSynchronizer.fork();
|
|
621
820
|
try {
|
|
622
|
-
const
|
|
821
|
+
const config = PublicSimulatorConfig.from({
|
|
822
|
+
skipFeeEnforcement,
|
|
823
|
+
collectDebugLogs: true,
|
|
824
|
+
collectHints: false,
|
|
825
|
+
collectCallMetadata: true,
|
|
826
|
+
maxDebugLogMemoryReads: this.config.rpcSimulatePublicMaxDebugLogMemoryReads,
|
|
827
|
+
collectStatistics: false
|
|
828
|
+
});
|
|
829
|
+
const processor = publicProcessorFactory.create(merkleTreeFork, newGlobalVariables, config);
|
|
623
830
|
// REFACTOR: Consider merging ProcessReturnValues into ProcessedTx
|
|
624
|
-
const [processedTxs, failedTxs, returns] = await processor.process([
|
|
831
|
+
const [processedTxs, failedTxs, _usedTxs, returns] = await processor.process([
|
|
625
832
|
tx
|
|
626
833
|
]);
|
|
627
834
|
// REFACTOR: Consider returning the error rather than throwing
|
|
@@ -632,30 +839,47 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
632
839
|
throw failedTxs[0].error;
|
|
633
840
|
}
|
|
634
841
|
const [processedTx] = processedTxs;
|
|
635
|
-
return new PublicSimulationOutput(processedTx.revertReason, processedTx.
|
|
842
|
+
return new PublicSimulationOutput(processedTx.revertReason, processedTx.globalVariables, processedTx.txEffect, returns, processedTx.gasUsed);
|
|
636
843
|
} finally{
|
|
637
|
-
await
|
|
844
|
+
await merkleTreeFork.close();
|
|
638
845
|
}
|
|
639
846
|
}
|
|
640
847
|
async isValidTx(tx, { isSimulation, skipFeeEnforcement } = {}) {
|
|
641
|
-
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
642
848
|
const db = this.worldStateSynchronizer.getCommitted();
|
|
643
849
|
const verifier = isSimulation ? undefined : this.proofVerifier;
|
|
850
|
+
// We accept transactions if they are not expired by the next slot (checked based on the IncludeByTimestamp field)
|
|
851
|
+
const { ts: nextSlotTimestamp } = this.epochCache.getEpochAndSlotInNextL1Slot();
|
|
852
|
+
const blockNumber = await this.blockSource.getBlockNumber() + 1;
|
|
644
853
|
const validator = createValidatorForAcceptingTxs(db, this.contractDataSource, verifier, {
|
|
854
|
+
timestamp: nextSlotTimestamp,
|
|
645
855
|
blockNumber,
|
|
646
856
|
l1ChainId: this.l1ChainId,
|
|
647
|
-
|
|
857
|
+
rollupVersion: this.version,
|
|
858
|
+
setupAllowList: this.config.txPublicSetupAllowList ?? await getDefaultAllowedSetupFunctions(),
|
|
648
859
|
gasFees: await this.getCurrentBaseFees(),
|
|
649
|
-
skipFeeEnforcement
|
|
860
|
+
skipFeeEnforcement,
|
|
861
|
+
txsPermitted: !this.config.disableTransactions
|
|
650
862
|
});
|
|
651
863
|
return await validator.validateTx(tx);
|
|
652
864
|
}
|
|
865
|
+
getConfig() {
|
|
866
|
+
const schema = AztecNodeAdminConfigSchema;
|
|
867
|
+
const keys = schema.keyof().options;
|
|
868
|
+
return Promise.resolve(pick(this.config, ...keys));
|
|
869
|
+
}
|
|
653
870
|
async setConfig(config) {
|
|
654
871
|
const newConfig = {
|
|
655
872
|
...this.config,
|
|
656
873
|
...config
|
|
657
874
|
};
|
|
658
|
-
|
|
875
|
+
this.sequencer?.updateConfig(config);
|
|
876
|
+
this.slasherClient?.updateConfig(config);
|
|
877
|
+
this.validatorsSentinel?.updateConfig(config);
|
|
878
|
+
await this.p2pClient.updateP2PConfig(config);
|
|
879
|
+
const archiver = this.blockSource;
|
|
880
|
+
if ('updateConfig' in archiver) {
|
|
881
|
+
archiver.updateConfig(config);
|
|
882
|
+
}
|
|
659
883
|
if (newConfig.realProofs !== this.config.realProofs) {
|
|
660
884
|
this.proofVerifier = config.realProofs ? await BBCircuitVerifier.new(newConfig) : new TestCircuitVerifier();
|
|
661
885
|
}
|
|
@@ -663,27 +887,120 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
663
887
|
}
|
|
664
888
|
getProtocolContractAddresses() {
|
|
665
889
|
return Promise.resolve({
|
|
666
|
-
|
|
890
|
+
classRegistry: ProtocolContractAddress.ContractClassRegistry,
|
|
667
891
|
feeJuice: ProtocolContractAddress.FeeJuice,
|
|
668
|
-
|
|
892
|
+
instanceRegistry: ProtocolContractAddress.ContractInstanceRegistry,
|
|
669
893
|
multiCallEntrypoint: ProtocolContractAddress.MultiCallEntrypoint
|
|
670
894
|
});
|
|
671
895
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
896
|
+
registerContractFunctionSignatures(signatures) {
|
|
897
|
+
return this.contractDataSource.registerContractFunctionSignatures(signatures);
|
|
898
|
+
}
|
|
899
|
+
getValidatorsStats() {
|
|
900
|
+
return this.validatorsSentinel?.computeStats() ?? Promise.resolve({
|
|
901
|
+
stats: {},
|
|
902
|
+
slotWindow: 0
|
|
903
|
+
});
|
|
676
904
|
}
|
|
677
|
-
|
|
678
|
-
return this.
|
|
905
|
+
getValidatorStats(validatorAddress, fromSlot, toSlot) {
|
|
906
|
+
return this.validatorsSentinel?.getValidatorStats(validatorAddress, fromSlot, toSlot) ?? Promise.resolve(undefined);
|
|
679
907
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
908
|
+
async startSnapshotUpload(location) {
|
|
909
|
+
// Note that we are forcefully casting the blocksource as an archiver
|
|
910
|
+
// We break support for archiver running remotely to the node
|
|
911
|
+
const archiver = this.blockSource;
|
|
912
|
+
if (!('backupTo' in archiver)) {
|
|
913
|
+
this.metrics.recordSnapshotError();
|
|
914
|
+
throw new Error('Archiver implementation does not support backups. Cannot generate snapshot.');
|
|
915
|
+
}
|
|
916
|
+
// Test that the archiver has done an initial sync.
|
|
917
|
+
if (!archiver.isInitialSyncComplete()) {
|
|
918
|
+
this.metrics.recordSnapshotError();
|
|
919
|
+
throw new Error(`Archiver initial sync not complete. Cannot start snapshot.`);
|
|
920
|
+
}
|
|
921
|
+
// And it has an L2 block hash
|
|
922
|
+
const l2BlockHash = await archiver.getL2Tips().then((tips)=>tips.latest.hash);
|
|
923
|
+
if (!l2BlockHash) {
|
|
924
|
+
this.metrics.recordSnapshotError();
|
|
925
|
+
throw new Error(`Archiver has no latest L2 block hash downloaded. Cannot start snapshot.`);
|
|
926
|
+
}
|
|
927
|
+
if (this.isUploadingSnapshot) {
|
|
928
|
+
this.metrics.recordSnapshotError();
|
|
929
|
+
throw new Error(`Snapshot upload already in progress. Cannot start another one until complete.`);
|
|
683
930
|
}
|
|
684
|
-
|
|
931
|
+
// Do not wait for the upload to be complete to return to the caller, but flag that an operation is in progress
|
|
932
|
+
this.isUploadingSnapshot = true;
|
|
933
|
+
const timer = new Timer();
|
|
934
|
+
void uploadSnapshot(location, this.blockSource, this.worldStateSynchronizer, this.config, this.log).then(()=>{
|
|
935
|
+
this.isUploadingSnapshot = false;
|
|
936
|
+
this.metrics.recordSnapshot(timer.ms());
|
|
937
|
+
}).catch((err)=>{
|
|
938
|
+
this.isUploadingSnapshot = false;
|
|
939
|
+
this.metrics.recordSnapshotError();
|
|
940
|
+
this.log.error(`Error uploading snapshot: ${err}`);
|
|
941
|
+
});
|
|
685
942
|
return Promise.resolve();
|
|
686
943
|
}
|
|
944
|
+
async rollbackTo(targetBlock, force) {
|
|
945
|
+
const archiver = this.blockSource;
|
|
946
|
+
if (!('rollbackTo' in archiver)) {
|
|
947
|
+
throw new Error('Archiver implementation does not support rollbacks.');
|
|
948
|
+
}
|
|
949
|
+
const finalizedBlock = await archiver.getL2Tips().then((tips)=>tips.finalized.number);
|
|
950
|
+
if (targetBlock < finalizedBlock) {
|
|
951
|
+
if (force) {
|
|
952
|
+
this.log.warn(`Clearing world state database to allow rolling back behind finalized block ${finalizedBlock}`);
|
|
953
|
+
await this.worldStateSynchronizer.clear();
|
|
954
|
+
await this.p2pClient.clear();
|
|
955
|
+
} else {
|
|
956
|
+
throw new Error(`Cannot rollback to block ${targetBlock} as it is before finalized ${finalizedBlock}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
try {
|
|
960
|
+
this.log.info(`Pausing archiver and world state sync to start rollback`);
|
|
961
|
+
await archiver.stop();
|
|
962
|
+
await this.worldStateSynchronizer.stopSync();
|
|
963
|
+
const currentBlock = await archiver.getBlockNumber();
|
|
964
|
+
const blocksToUnwind = currentBlock - targetBlock;
|
|
965
|
+
this.log.info(`Unwinding ${count(blocksToUnwind, 'block')} from L2 block ${currentBlock} to ${targetBlock}`);
|
|
966
|
+
await archiver.rollbackTo(targetBlock);
|
|
967
|
+
this.log.info(`Unwinding complete.`);
|
|
968
|
+
} catch (err) {
|
|
969
|
+
this.log.error(`Error during rollback`, err);
|
|
970
|
+
throw err;
|
|
971
|
+
} finally{
|
|
972
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
973
|
+
this.worldStateSynchronizer.resumeSync();
|
|
974
|
+
archiver.resume();
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
async pauseSync() {
|
|
978
|
+
this.log.info(`Pausing archiver and world state sync`);
|
|
979
|
+
await this.blockSource.stop();
|
|
980
|
+
await this.worldStateSynchronizer.stopSync();
|
|
981
|
+
}
|
|
982
|
+
resumeSync() {
|
|
983
|
+
this.log.info(`Resuming world state and archiver sync.`);
|
|
984
|
+
this.worldStateSynchronizer.resumeSync();
|
|
985
|
+
this.blockSource.resume();
|
|
986
|
+
return Promise.resolve();
|
|
987
|
+
}
|
|
988
|
+
getSlashPayloads() {
|
|
989
|
+
if (!this.slasherClient) {
|
|
990
|
+
throw new Error(`Slasher client not enabled`);
|
|
991
|
+
}
|
|
992
|
+
return this.slasherClient.getSlashPayloads();
|
|
993
|
+
}
|
|
994
|
+
getSlashOffenses(round) {
|
|
995
|
+
if (!this.slasherClient) {
|
|
996
|
+
throw new Error(`Slasher client not enabled`);
|
|
997
|
+
}
|
|
998
|
+
if (round === 'all') {
|
|
999
|
+
return this.slasherClient.getPendingOffenses();
|
|
1000
|
+
} else {
|
|
1001
|
+
return this.slasherClient.gatherOffensesForRound(round === 'current' ? undefined : BigInt(round));
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
687
1004
|
/**
|
|
688
1005
|
* Returns an instance of MerkleTreeOperations having first ensured the world state is fully synched
|
|
689
1006
|
* @param blockNumber - The block number at which to get the data.
|
|
@@ -719,7 +1036,7 @@ import { NodeMetrics } from './node_metrics.js';
|
|
|
719
1036
|
}
|
|
720
1037
|
}
|
|
721
1038
|
_ts_decorate([
|
|
722
|
-
trackSpan('AztecNodeService.simulatePublicCalls',
|
|
723
|
-
[Attributes.TX_HASH]:
|
|
1039
|
+
trackSpan('AztecNodeService.simulatePublicCalls', (tx)=>({
|
|
1040
|
+
[Attributes.TX_HASH]: tx.getTxHash().toString()
|
|
724
1041
|
}))
|
|
725
1042
|
], AztecNodeService.prototype, "simulatePublicCalls", null);
|