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